Move i386/amd64 common code (check_pa_acc()) to x86.
I didn't know what header to put the prototype in, so it's both in i386/mem.c and amd64/mem.c; probably can be moved later. Tested on amd64, assumed working on i386. :) yamt@ okay
This commit is contained in:
parent
048a21b75e
commit
eddfaaf54c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: mem.c,v 1.7 2006/07/23 22:06:04 ad Exp $ */
|
||||
/* $NetBSD: mem.c,v 1.8 2006/10/30 00:41:26 elad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1990, 1993
|
||||
@ -73,7 +73,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.7 2006/07/23 22:06:04 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.8 2006/10/30 00:41:26 elad Exp $");
|
||||
|
||||
#include "opt_compat_netbsd.h"
|
||||
|
||||
@ -115,6 +115,8 @@ const struct cdevsw mem_cdevsw = {
|
||||
nostop, notty, nopoll, mmmmap, nokqfilter
|
||||
};
|
||||
|
||||
int check_pa_acc(paddr_t, vm_prot_t);
|
||||
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
mmrw(dev, uio, flags)
|
||||
@ -155,6 +157,9 @@ mmrw(dev, uio, flags)
|
||||
v = uio->uio_offset;
|
||||
prot = uio->uio_rw == UIO_READ ? VM_PROT_READ :
|
||||
VM_PROT_WRITE;
|
||||
error = check_pa_acc(uio->uio_offset, prot);
|
||||
if (error)
|
||||
break;
|
||||
pmap_enter(pmap_kernel(), (vaddr_t)vmmap,
|
||||
trunc_page(v), prot, PMAP_WIRED|prot);
|
||||
o = uio->uio_offset & PGOFSET;
|
||||
@ -226,8 +231,6 @@ mmmmap(dev, off, prot)
|
||||
off_t off;
|
||||
int prot;
|
||||
{
|
||||
struct lwp *l = curlwp; /* XXX */
|
||||
|
||||
/*
|
||||
* /dev/mem is the only one that makes sense through this
|
||||
* interface. For /dev/kmem any physaddr we return here
|
||||
@ -239,8 +242,8 @@ mmmmap(dev, off, prot)
|
||||
if (minor(dev) != DEV_MEM)
|
||||
return (-1);
|
||||
|
||||
if (off > ctob(physmem) && kauth_authorize_generic(l->l_cred,
|
||||
KAUTH_GENERIC_ISSUSER, &l->l_acflag) != 0)
|
||||
if (check_pa_acc(off, prot) != 0)
|
||||
return (-1);
|
||||
|
||||
return (x86_btop(off));
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: mem.c,v 1.65 2006/10/12 04:31:03 thorpej Exp $ */
|
||||
/* $NetBSD: mem.c,v 1.66 2006/10/30 00:41:26 elad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1990, 1993
|
||||
@ -77,7 +77,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.65 2006/10/12 04:31:03 thorpej Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.66 2006/10/30 00:41:26 elad Exp $");
|
||||
|
||||
#include "opt_compat_netbsd.h"
|
||||
|
||||
@ -109,7 +109,7 @@ const struct cdevsw mem_cdevsw = {
|
||||
nostop, notty, nopoll, mmmmap, nokqfilter, D_OTHER,
|
||||
};
|
||||
|
||||
static int check_pa_acc(paddr_t, vm_prot_t);
|
||||
int check_pa_acc(paddr_t, vm_prot_t);
|
||||
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
@ -248,34 +248,3 @@ mmmmap(dev_t dev, off_t off, int prot)
|
||||
|
||||
return x86_btop(off);
|
||||
}
|
||||
|
||||
/* ---------------------------------------- */
|
||||
|
||||
#include <sys/kcore.h>
|
||||
|
||||
/*
|
||||
* check_pa_acc: check if given pa is accessible.
|
||||
*/
|
||||
|
||||
static int
|
||||
check_pa_acc(paddr_t pa, vm_prot_t prot __unused)
|
||||
{
|
||||
extern phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
|
||||
extern int mem_cluster_cnt;
|
||||
int i;
|
||||
|
||||
if (securelevel <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < mem_cluster_cnt; i++) {
|
||||
const phys_ram_seg_t *seg = &mem_clusters[i];
|
||||
paddr_t start = seg->start;
|
||||
|
||||
if (start <= pa && pa - start <= seg->size) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return EPERM;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: x86_machdep.c,v 1.1 2005/12/30 13:37:57 jmmv Exp $ */
|
||||
/* $NetBSD: x86_machdep.c,v 1.2 2006/10/30 00:41:26 elad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2005 The NetBSD Foundation, Inc.
|
||||
@ -37,12 +37,20 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.1 2005/12/30 13:37:57 jmmv Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.2 2006/10/30 00:41:26 elad Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kcore.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
#include <machine/bootinfo.h>
|
||||
#include <machine/vmparam.h>
|
||||
|
||||
#include <uvm/uvm_extern.h>
|
||||
|
||||
int check_pa_acc(paddr_t, vm_prot_t __unused);
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
@ -79,3 +87,29 @@ lookup_bootinfo(int type)
|
||||
|
||||
return found ? bic : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* check_pa_acc: check if given pa is accessible.
|
||||
*/
|
||||
int
|
||||
check_pa_acc(paddr_t pa, vm_prot_t prot __unused)
|
||||
{
|
||||
extern phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
|
||||
extern int mem_cluster_cnt;
|
||||
int i;
|
||||
|
||||
if (securelevel <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < mem_cluster_cnt; i++) {
|
||||
const phys_ram_seg_t *seg = &mem_clusters[i];
|
||||
paddr_t lstart = seg->start;
|
||||
|
||||
if (lstart <= pa && pa - lstart <= seg->size) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return EPERM;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user