Module Name:    src
Committed By:   reinoud
Date:           Sun Sep  4 20:54:52 UTC 2011

Modified Files:
        src/sys/arch/usermode/dev: cpu.c
        src/sys/arch/usermode/include: pcb.h
        src/sys/arch/usermode/usermode: trap.c

Log Message:
Try to preserve errno over traps and on context switches


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/usermode/dev/cpu.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/usermode/include/pcb.h
cvs rdiff -u -r1.21 -r1.22 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/dev/cpu.c
diff -u src/sys/arch/usermode/dev/cpu.c:1.27 src/sys/arch/usermode/dev/cpu.c:1.28
--- src/sys/arch/usermode/dev/cpu.c:1.27	Sat Sep  3 19:06:49 2011
+++ src/sys/arch/usermode/dev/cpu.c	Sun Sep  4 20:54:52 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.27 2011/09/03 19:06:49 jmcneill Exp $ */
+/* $NetBSD: cpu.c,v 1.28 2011/09/04 20:54:52 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca>
@@ -29,7 +29,7 @@
 #include "opt_cpu.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.27 2011/09/03 19:06:49 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.28 2011/09/04 20:54:52 reinoud Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -186,13 +186,16 @@
 
 	ci->ci_stash = oldlwp;
 	curlwp = newlwp;
+
 	if (oldpcb) {
+		oldpcb->errno = thunk_geterrno();
 		if (thunk_swapcontext(&oldpcb->pcb_ucp, &newpcb->pcb_ucp))
 			panic("swapcontext failed");
 	} else {
 		if (thunk_setcontext(&newpcb->pcb_ucp))
 			panic("setcontext failed");
 	}
+	thunk_seterrno(newpcb->errno);
 
 #ifdef CPU_DEBUG
 	printf("cpu_switchto: returning %p (was %p)\n", ci->ci_stash, oldlwp);

Index: src/sys/arch/usermode/include/pcb.h
diff -u src/sys/arch/usermode/include/pcb.h:1.8 src/sys/arch/usermode/include/pcb.h:1.9
--- src/sys/arch/usermode/include/pcb.h:1.8	Fri Sep  2 16:09:01 2011
+++ src/sys/arch/usermode/include/pcb.h	Sun Sep  4 20:54:52 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: pcb.h,v 1.8 2011/09/02 16:09:01 reinoud Exp $ */
+/* $NetBSD: pcb.h,v 1.9 2011/09/04 20:54:52 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca>
@@ -37,6 +37,7 @@
  * XXX move to frame.h?
  */
 
+/* XXX unused XXX */
 typedef struct trapframe {
 	int		(*tf_syscall)(lwp_t *, struct trapframe *);
 	int		 tf_reason;		/* XXX unused */
@@ -49,7 +50,9 @@
 	ucontext_t	 pcb_userland_ucp;	/* userland switchframe */
 	bool		 pcb_needfree;
 	struct trapframe pcb_tf;
-	void *		 pcb_onfault;	/* on fault handler */
+	void *		 pcb_onfault;		/* on fault handler */
+
+	int		 errno;			/* save/restore place */
 };
 
 #endif /* !_ARCH_USERMODE_INCLUDE_PCB_H */

Index: src/sys/arch/usermode/usermode/trap.c
diff -u src/sys/arch/usermode/usermode/trap.c:1.21 src/sys/arch/usermode/usermode/trap.c:1.22
--- src/sys/arch/usermode/usermode/trap.c:1.21	Sun Sep  4 12:17:59 2011
+++ src/sys/arch/usermode/usermode/trap.c	Sun Sep  4 20:54:52 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.21 2011/09/04 12:17:59 jmcneill Exp $ */
+/* $NetBSD: trap.c,v 1.22 2011/09/04 20:54:52 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.21 2011/09/04 12:17:59 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.22 2011/09/04 20:54:52 reinoud Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -125,6 +125,7 @@
 		onfault = pcb->pcb_onfault;
 		vm = p->p_vmspace;
 
+		pcb->errno = thunk_geterrno();
 #if 0
 		va = (vaddr_t) info->si_addr;
 		printf("mem trap lwp = %p pid = %d lid = %d, va = %p\n",
@@ -215,10 +216,11 @@
 			/* XXX HOWTO see arm/arm/syscall.c illegal instruction signal */
 		}
 
-		if (recurse > 1)
-			printf("leaving trap recursion level %d\n", recurse);
-		recurse--;
+		thunk_seterrno(pcb->errno);
 	}
+	if (recurse > 1)
+		printf("leaving trap recursion level %d\n", recurse);
+	recurse--;
 }
 
 static void

Reply via email to