Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/amd64/amd64 Keep fs/gs the same for the signal cont...



details:   https://anonhg.NetBSD.org/src/rev/d55d77e20386
branches:  trunk
changeset: 828298:d55d77e20386
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Dec 07 16:22:22 2017 +0000

description:
Keep fs/gs the same for the signal context; otherwise calling things
like __lwp_getprivate_fast() from a signal handler (that uses %gs) die.

Merge context building code.

diffstat:

 sys/arch/amd64/amd64/netbsd32_machdep.c |  101 ++++++++++++-------------------
 1 files changed, 41 insertions(+), 60 deletions(-)

diffs (136 lines):

diff -r 991642dd014c -r d55d77e20386 sys/arch/amd64/amd64/netbsd32_machdep.c
--- a/sys/arch/amd64/amd64/netbsd32_machdep.c   Thu Dec 07 15:21:34 2017 +0000
+++ b/sys/arch/amd64/amd64/netbsd32_machdep.c   Thu Dec 07 16:22:22 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_machdep.c,v 1.113 2017/12/02 15:36:24 maxv Exp $      */
+/*     $NetBSD: netbsd32_machdep.c,v 1.114 2017/12/07 16:22:22 christos Exp $  */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.113 2017/12/02 15:36:24 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.114 2017/12/07 16:22:22 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -164,6 +164,43 @@
        tf->tf_ss = LSEL(LUDATA32_SEL, SEL_UPL);
 }
 
+static void
+netbsd32_buildcontext(struct lwp *l, struct trapframe *tf, void *fp,
+    sig_t catcher, int onstack)
+{
+       /*
+        * Build context to run handler in.
+        */
+       tf->tf_ds = GSEL(GUDATA32_SEL, SEL_UPL);
+       tf->tf_es = GSEL(GUDATA32_SEL, SEL_UPL);
+#if 0
+       tf->tf_fs = GSEL(GUDATA32_SEL, SEL_UPL);
+       tf->tf_gs = GSEL(GUDATA32_SEL, SEL_UPL);
+#endif
+
+       /* Ensure FP state is sane. */
+       fpu_save_area_reset(l);
+
+       tf->tf_rip = (uint64_t)catcher;
+       tf->tf_cs = GSEL(GUCODE32_SEL, SEL_UPL);
+       tf->tf_rflags &= ~PSL_CLEARSIG;
+       tf->tf_rsp = (uint64_t)fp;
+       tf->tf_ss = GSEL(GUDATA32_SEL, SEL_UPL);
+
+       /* Remember that we're now on the signal stack. */
+       if (onstack)
+               l->l_sigstk.ss_flags |= SS_ONSTACK;
+       if ((vaddr_t)catcher >= VM_MAXUSER_ADDRESS32) {
+               /*
+                * process has given an invalid address for the
+                * handler. Stop it, but do not do it before so
+                * we can return the right info to userland (or in core dump)
+                */
+               sigexit(l, SIGILL);
+               /* NOTREACHED */
+       }
+}
+
 #ifdef COMPAT_16
 static void
 netbsd32_sendsig_sigcontext(const ksiginfo_t *ksi, const sigset_t *mask)
@@ -249,35 +286,7 @@
                /* NOTREACHED */
        }
 
-       /*
-        * Build context to run handler in.
-        */
-       tf->tf_ds = GSEL(GUDATA32_SEL, SEL_UPL);
-       tf->tf_es = GSEL(GUDATA32_SEL, SEL_UPL);
-       tf->tf_fs = GSEL(GUDATA32_SEL, SEL_UPL);
-       tf->tf_gs = GSEL(GUDATA32_SEL, SEL_UPL);
-
-       /* Ensure FP state is sane. */
-       fpu_save_area_reset(l);
-
-       tf->tf_rip = (uint64_t)catcher;
-       tf->tf_cs = GSEL(GUCODE32_SEL, SEL_UPL);
-       tf->tf_rflags &= ~PSL_CLEARSIG;
-       tf->tf_rsp = (uint64_t)fp;
-       tf->tf_ss = GSEL(GUDATA32_SEL, SEL_UPL);
-
-       /* Remember that we're now on the signal stack. */
-       if (onstack)
-               l->l_sigstk.ss_flags |= SS_ONSTACK;
-       if ((vaddr_t)catcher >= VM_MAXUSER_ADDRESS32) {
-               /*
-                * process has given an invalid address for the
-                * handler. Stop it, but do not do it before so
-                * we can return the right info to userland (or in core dump)
-                */
-               sigexit(l, SIGILL);
-               /* NOTREACHED */
-       }
+       netbsd32_buildcontext(l, tf, fp, catcher, onstack);
 }
 #endif
 
@@ -346,35 +355,7 @@
                /* NOTREACHED */
        }
 
-       /*
-        * Build context to run handler in.
-        */
-       tf->tf_ds = GSEL(GUDATA32_SEL, SEL_UPL);
-       tf->tf_es = GSEL(GUDATA32_SEL, SEL_UPL);
-       tf->tf_fs = GSEL(GUDATA32_SEL, SEL_UPL);
-       tf->tf_gs = GSEL(GUDATA32_SEL, SEL_UPL);
-
-       tf->tf_rip = (uint64_t)catcher;
-       tf->tf_cs = GSEL(GUCODE32_SEL, SEL_UPL);
-       tf->tf_rflags &= ~PSL_CLEARSIG;
-       tf->tf_rsp = (uint64_t)fp;
-       tf->tf_ss = GSEL(GUDATA32_SEL, SEL_UPL);
-
-       /* Ensure FP state is sane. */
-       fpu_save_area_reset(l);
-
-       /* Remember that we're now on the signal stack. */
-       if (onstack)
-               l->l_sigstk.ss_flags |= SS_ONSTACK;
-       if ((vaddr_t)catcher >= VM_MAXUSER_ADDRESS32) {
-               /*
-                * process has given an invalid address for the
-                * handler. Stop it, but do not do it before so
-                * we can return the right info to userland (or in core dump)
-                */
-               sigexit(l, SIGILL);
-               /* NOTREACHED */
-       }
+       netbsd32_buildcontext(l, tf, fp, catcher, onstack);
 }
 
 void



Home | Main Index | Thread Index | Old Index