Fix /dev/kmem access and make vmstat(1) `work'. Not sure all the results are

indeed valid or correct but at least it shows them without coredumping or
coredumping the kernel.
This commit is contained in:
reinoud 2012-02-08 17:55:21 +00:00
parent b3085522af
commit 5cbe80301b
4 changed files with 35 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cpu.h,v 1.9 2012/01/19 12:14:49 reinoud Exp $ */
/* $NetBSD: cpu.h,v 1.10 2012/02/08 17:55:21 reinoud Exp $ */
/*-
* Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
@ -50,10 +50,10 @@ extern void cpu_need_resched(struct cpu_info *ci, int flags);
struct cpu_info {
device_t ci_dev;
struct cpu_data ci_data; /* MI per-cpu data */
device_t ci_dev; /* pointer to our device */
struct cpu_info *ci_self;
struct cpu_info *ci_next;
struct cpu_data ci_data;
u_int ci_cpuid;
int ci_want_resched;
int ci_idepth;

View File

@ -1,4 +1,4 @@
/* $NetBSD: types.h,v 1.7 2012/01/08 18:06:00 jmcneill Exp $ */
/* $NetBSD: types.h,v 1.8 2012/02/08 17:55:21 reinoud Exp $ */
/*-
* Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
@ -62,4 +62,7 @@ typedef volatile unsigned char __cpu_simple_lock_t;
#define __HAVE_OLD_DISKLABEL
#endif
#define __HAVE_CPU_DATA_FIRST
#define __HAVE_MM_MD_KERNACC
#endif /* !_ARCH_USERMODE_INCLUDE_TYPES_H */

View File

@ -1,4 +1,4 @@
/* $NetBSD: vmparam.h,v 1.15 2012/01/10 10:19:38 reinoud Exp $ */
/* $NetBSD: vmparam.h,v 1.16 2012/02/08 17:55:21 reinoud Exp $ */
/*-
* Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
@ -36,6 +36,7 @@
extern paddr_t kmem_k_start, kmem_k_end;
extern paddr_t kmem_kvm_start, kmem_kvm_end;
extern paddr_t kmem_kvm_cur_end;
extern paddr_t kmem_user_start, kmem_user_end;
#define VM_MIN_ADDRESS kmem_user_start

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.52 2012/01/15 10:30:21 jmcneill Exp $ */
/* $NetBSD: machdep.c,v 1.53 2012/02/08 17:55:21 reinoud Exp $ */
/*-
* Copyright (c) 2011 Reinoud Zandijk <reinoud@netbsd.org>
@ -37,7 +37,7 @@
#include "opt_memsize.h"
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.52 2012/01/15 10:30:21 jmcneill Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.53 2012/02/08 17:55:21 reinoud Exp $");
#include <sys/types.h>
#include <sys/systm.h>
@ -55,6 +55,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.52 2012/01/15 10:30:21 jmcneill Exp $"
#include <uvm/uvm_page.h>
#include <dev/mm.h>
#include <machine/vmparam.h>
#include <machine/machdep.h>
#include <machine/thunk.h>
@ -249,8 +250,30 @@ consinit(void)
}
int
mm_md_physacc(paddr_t pa, vm_prot_t prog)
mm_md_physacc(paddr_t pa, vm_prot_t prot)
{
// printf("%s: pa = %p, acc %d\n", __func__, (void *) pa, prot);
if (pa >= physmem * PAGE_SIZE)
return EFAULT;
return 0;
}
int
mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled)
{
const vaddr_t va = (vaddr_t)ptr;
extern void *end;
// printf("%s: ptr %p, acc %d\n", __func__, ptr, prot);
if (va < kmem_kvm_start)
return EFAULT;
if ((va >= kmem_kvm_cur_end) && (va < kmem_k_start))
return EFAULT;
if (va > (vaddr_t) end)
return EFAULT;
*handled = true;
return 0;
}