Module Name:    src
Committed By:   reinoud
Date:           Sat Aug 27 18:01:37 UTC 2011

Modified Files:
        src/sys/arch/usermode/usermode: trap.c

Log Message:
Implement trap recursion detection and fix small one-off error in range
checks for kernel space


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/usermode/usermode/trap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/usermode/usermode/trap.c
diff -u src/sys/arch/usermode/usermode/trap.c:1.6 src/sys/arch/usermode/usermode/trap.c:1.7
--- src/sys/arch/usermode/usermode/trap.c:1.6	Thu Aug 25 19:06:03 2011
+++ src/sys/arch/usermode/usermode/trap.c	Sat Aug 27 18:01:37 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.6 2011/08/25 19:06:03 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.7 2011/08/27 18:01:37 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.6 2011/08/25 19:06:03 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.7 2011/08/27 18:01:37 reinoud Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -83,8 +83,12 @@
 	vaddr_t va;
 	vaddr_t onfault;
 	int kmem, rv;
+	static volatile int recurse = 0;
 
+	recurse++;
 	aprint_debug("trap\n");
+	if (recurse > 1)
+		printf("enter trap recursion level %d\n", recurse);
 	if ((info->si_signo == SIGSEGV) || (info->si_signo == SIGBUS)) {
 		l = curlwp;
 		p = l->l_proc;
@@ -121,7 +125,7 @@
 
 		kmem = 1;
 		vm_map = kernel_map;
-		if ((va >= VM_MIN_ADDRESS) && (va <= VM_MAXUSER_ADDRESS)) {
+		if ((va >= VM_MIN_ADDRESS) && (va < VM_MAXUSER_ADDRESS)) {
 			kmem = 0;
 			vm_map = &vm->vm_map;
 		}
@@ -146,11 +150,14 @@
 				memset(tf, 0, sizeof(struct trapframe));
 				tf->tf_pc = onfault;
 				tf->tf_out[0] = (rv == EACCES) ? EFAULT : rv;
+				recurse--;
 				return;
 			}
 			panic("should deliver a trap to the process");
 		}
-
+		if (recurse > 1)
+			printf("leaving trap recursion level %d\n", recurse);
+		recurse--;
 	}
 }
 

Reply via email to