Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/usermode Try to preserve errno over traps and on co...



details:   https://anonhg.NetBSD.org/src/rev/053b1aa6f7ca
branches:  trunk
changeset: 769251:053b1aa6f7ca
user:      reinoud <reinoud%NetBSD.org@localhost>
date:      Sun Sep 04 20:54:52 2011 +0000

description:
Try to preserve errno over traps and on context switches

diffstat:

 sys/arch/usermode/dev/cpu.c       |   7 +++++--
 sys/arch/usermode/include/pcb.h   |   7 +++++--
 sys/arch/usermode/usermode/trap.c |  12 +++++++-----
 3 files changed, 17 insertions(+), 9 deletions(-)

diffs (104 lines):

diff -r c84861cf8875 -r 053b1aa6f7ca sys/arch/usermode/dev/cpu.c
--- a/sys/arch/usermode/dev/cpu.c       Sun Sep 04 20:49:59 2011 +0000
+++ b/sys/arch/usermode/dev/cpu.c       Sun Sep 04 20:54:52 2011 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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);
diff -r c84861cf8875 -r 053b1aa6f7ca sys/arch/usermode/include/pcb.h
--- a/sys/arch/usermode/include/pcb.h   Sun Sep 04 20:49:59 2011 +0000
+++ b/sys/arch/usermode/include/pcb.h   Sun Sep 04 20:54:52 2011 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 */
diff -r c84861cf8875 -r 053b1aa6f7ca sys/arch/usermode/usermode/trap.c
--- a/sys/arch/usermode/usermode/trap.c Sun Sep 04 20:49:59 2011 +0000
+++ b/sys/arch/usermode/usermode/trap.c Sun Sep 04 20:54:52 2011 +0000
@@ -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 <reinoud%netbsd.org@localhost>
@@ -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



Home | Main Index | Thread Index | Old Index