Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/usermode Fix logic that checks if its the kernel or...
details: https://anonhg.NetBSD.org/src/rev/717d4828754c
branches: trunk
changeset: 772420:717d4828754c
user: reinoud <reinoud%NetBSD.org@localhost>
date: Tue Jan 03 10:53:46 2012 +0000
description:
Fix logic that checks if its the kernel or a userland process that causes the
trap. Signal sending still needs to be addressed.
diffstat:
sys/arch/usermode/include/machdep.h | 3 ++-
sys/arch/usermode/include/pcb.h | 3 ++-
sys/arch/usermode/usermode/machdep.c | 12 ++++++++++--
sys/arch/usermode/usermode/trap.c | 30 +++++++++++++++++-------------
4 files changed, 31 insertions(+), 17 deletions(-)
diffs (160 lines):
diff -r f8f6466c0a8f -r 717d4828754c sys/arch/usermode/include/machdep.h
--- a/sys/arch/usermode/include/machdep.h Tue Jan 03 07:36:02 2012 +0000
+++ b/sys/arch/usermode/include/machdep.h Tue Jan 03 10:53:46 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.h,v 1.6 2011/12/14 18:51:39 reinoud Exp $ */
+/* $NetBSD: machdep.h,v 1.7 2012/01/03 10:53:46 reinoud Exp $ */
/*-
* Copyright (c) 2011 Reinoud Zandijk <reinoud%netbsd.org@localhost>
@@ -35,6 +35,7 @@
int error, register_t *rval);
void md_syscall_inc_pc(ucontext_t *ucp, uint32_t opcode);
void md_syscall_dec_pc(ucontext_t *ucp, uint32_t opcode);
+register_t md_get_pc(ucontext_t *ucp);
/* handlers */
void syscall(void);
diff -r f8f6466c0a8f -r 717d4828754c sys/arch/usermode/include/pcb.h
--- a/sys/arch/usermode/include/pcb.h Tue Jan 03 07:36:02 2012 +0000
+++ b/sys/arch/usermode/include/pcb.h Tue Jan 03 10:53:46 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pcb.h,v 1.14 2011/12/12 15:04:51 reinoud Exp $ */
+/* $NetBSD: pcb.h,v 1.15 2012/01/03 10:53:46 reinoud Exp $ */
/*-
* Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -51,6 +51,7 @@
int pcb_errno; /* save/restore place */
vaddr_t pcb_fault_addr; /* save place for fault addr */
+ vaddr_t pcb_fault_pc; /* save place for fault PC */
};
#endif /* !_ARCH_USERMODE_INCLUDE_PCB_H */
diff -r f8f6466c0a8f -r 717d4828754c sys/arch/usermode/usermode/machdep.c
--- a/sys/arch/usermode/usermode/machdep.c Tue Jan 03 07:36:02 2012 +0000
+++ b/sys/arch/usermode/usermode/machdep.c Tue Jan 03 10:53:46 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.47 2011/12/29 21:22:49 jmcneill Exp $ */
+/* $NetBSD: machdep.c,v 1.48 2012/01/03 10:53:46 reinoud Exp $ */
/*-
* Copyright (c) 2011 Reinoud Zandijk <reinoud%netbsd.org@localhost>
@@ -37,7 +37,7 @@
#include "opt_memsize.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.47 2011/12/29 21:22:49 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.48 2012/01/03 10:53:46 reinoud Exp $");
#include <sys/types.h>
#include <sys/systm.h>
@@ -440,6 +440,14 @@
//dump_regs(reg);
}
+register_t
+md_get_pc(ucontext_t *ucp)
+{
+ register_t *reg = (register_t *) &ucp->uc_mcontext;
+
+ return reg[14]; /* EIP */
+}
+
int
md_syscall_check_opcode(ucontext_t *ucp)
{
diff -r f8f6466c0a8f -r 717d4828754c sys/arch/usermode/usermode/trap.c
--- a/sys/arch/usermode/usermode/trap.c Tue Jan 03 07:36:02 2012 +0000
+++ b/sys/arch/usermode/usermode/trap.c Tue Jan 03 10:53:46 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.49 2012/01/02 22:02:51 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.50 2012/01/03 10:53:46 reinoud Exp $ */
/*-
* Copyright (c) 2011 Reinoud Zandijk <reinoud%netbsd.org@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.49 2012/01/02 22:02:51 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.50 2012/01/03 10:53:46 reinoud Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -108,7 +108,7 @@
ucontext_t *uct = ctx;
struct lwp *l;
struct pcb *pcb;
- vaddr_t va;
+ vaddr_t va, pc;
assert((info->si_signo == SIGSEGV) || (info->si_signo == SIGBUS));
@@ -147,9 +147,13 @@
l = curlwp;
pcb = lwp_getpcb(l);
+ /* get address of faulted memory access and make it page aligned */
va = (vaddr_t) info->si_addr;
va = trunc_page(va);
+ /* get PC address of faulted memory instruction */
+ pc = md_get_pc(ctx);
+
#if 0 /* disabled for now, these checks need to move */
#ifdef DIAGNOSTIC
/* sanity */
@@ -169,6 +173,7 @@
/* remember our parameters */
// assert((void *) pcb->pcb_fault_addr == NULL);
pcb->pcb_fault_addr = va;
+ pcb->pcb_fault_pc = pc;
/* switch to the pagefault entry on return from signal */
memcpy(uct, &pcb->pcb_pagefault_ucp, sizeof(ucontext_t));
@@ -259,26 +264,25 @@
struct vmspace *vm;
struct vm_map *vm_map;
vm_prot_t atype;
- vaddr_t va;
+ vaddr_t va, pc;
void *onfault;
- int kmem, lwp_errno, rv;
+ int from_kernel, lwp_errno, rv;
l = curlwp;
pcb = lwp_getpcb(l);
p = l->l_proc;
vm = p->p_vmspace;
va = pcb->pcb_fault_addr;
+ pc = pcb->pcb_fault_pc;
lwp_errno = thunk_geterrno();
- kmem = 1;
- vm_map = kernel_map;
- if ((va >= VM_MIN_ADDRESS) && (va < VM_MAXUSER_ADDRESS)) {
- kmem = 0;
- vm_map = &vm->vm_map;
- }
+ vm_map = &vm->vm_map;
+ from_kernel = (pc >= VM_MIN_KERNEL_ADDRESS);
+ if (from_kernel && (va >= VM_MIN_KERNEL_ADDRESS))
+ vm_map = kernel_map;
- dprintf_debug("pagefault : va = %p\n", (void *) va);
+ dprintf_debug("pagefault : pc %p, va %p\n", (void *) pc, (void *) va);
/* can pmap handle it? on its own? (r/m) */
onfault = pcb->pcb_onfault;
@@ -300,7 +304,7 @@
dprintf_debug("uvm_fault returned error %d\n", rv);
/* something got wrong */
- if (kmem) {
+ if (from_kernel) {
/* copyin / copyout */
if (!onfault)
panic("kernel fault");
Home |
Main Index |
Thread Index |
Old Index