Source-Changes-HG archive

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

[src/pgoyette-compat]: src/sys Work in progress - get the arch-specific netbs...



details:   https://anonhg.NetBSD.org/src/rev/37836963d4d2
branches:  pgoyette-compat
changeset: 830701:37836963d4d2
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Fri Sep 14 05:37:08 2018 +0000

description:
Work in progress - get the arch-specific netbsd32_machdep.c code to
build as a module.

XXX Doesn't work when the code is built-in to the kernel.

diffstat:

 sys/arch/amd64/amd64/netbsd32_machdep.c    |  186 ++-----------------
 sys/arch/amd64/amd64/netbsd32_machdep_13.c |  146 ++++++++++++++++
 sys/arch/amd64/amd64/netbsd32_machdep_16.c |  262 +++++++++++++++++++++++++++++
 sys/compat/netbsd32/netbsd32_compat_16.c   |   20 +-
 sys/compat/netbsd32/netbsd32_mod.c         |   25 ++-
 sys/modules/compat_netbsd32/Makefile       |    7 +-
 sys/modules/compat_netbsd32_13/Makefile    |    7 +-
 sys/modules/compat_netbsd32_16/Makefile    |    9 +-
 8 files changed, 490 insertions(+), 172 deletions(-)

diffs (truncated from 847 to 300 lines):

diff -r 5f16cdadeb2d -r 37836963d4d2 sys/arch/amd64/amd64/netbsd32_machdep.c
--- a/sys/arch/amd64/amd64/netbsd32_machdep.c   Fri Sep 14 01:21:34 2018 +0000
+++ b/sys/arch/amd64/amd64/netbsd32_machdep.c   Fri Sep 14 05:37:08 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_machdep.c,v 1.115.2.1 2018/07/28 04:37:26 pgoyette Exp $      */
+/*     $NetBSD: netbsd32_machdep.c,v 1.115.2.2 2018/09/14 05:37:08 pgoyette Exp $      */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.115.2.1 2018/07/28 04:37:26 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.115.2.2 2018/09/14 05:37:08 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -101,7 +101,12 @@
 #define x86_64_set_mtrr32(x, y, z)     ENOSYS
 #endif
 
-static int check_sigcontext32(struct lwp *, const struct netbsd32_sigcontext *);
+int check_sigcontext32(struct lwp *, const struct netbsd32_sigcontext *);
+
+void  netbsd32_buildcontext(struct lwp *l, struct trapframe *tf, void *fp,
+    sig_t catcher, int onstack);
+
+void netbsd32_sendsig_siginfo(const ksiginfo_t *, const sigset_t *);
 
 #ifdef EXEC_AOUT
 /*
@@ -160,7 +165,7 @@
        tf->tf_ss = LSEL(LUDATA32_SEL, SEL_UPL);
 }
 
-static void
+void
 netbsd32_buildcontext(struct lwp *l, struct trapframe *tf, void *fp,
     sig_t catcher, int onstack)
 {
@@ -197,96 +202,7 @@
        }
 }
 
-#ifdef COMPAT_16
-static void
-netbsd32_sendsig_sigcontext(const ksiginfo_t *ksi, const sigset_t *mask)
-{
-       struct lwp *l = curlwp;
-       struct proc *p = l->l_proc;
-       struct trapframe *tf;
-       int sig = ksi->ksi_signo;
-       sig_t catcher = SIGACTION(p, sig).sa_handler;
-       struct netbsd32_sigframe_sigcontext *fp, frame;
-       int onstack, error;
-       struct sigacts *ps = p->p_sigacts;
-
-       tf = l->l_md.md_regs;
-
-       /* Do we need to jump onto the signal stack? */
-       onstack =
-           (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
-           (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
-
-       /* Allocate space for the signal handler context. */
-       if (onstack)
-               fp = (struct netbsd32_sigframe_sigcontext *)
-                   ((char *)l->l_sigstk.ss_sp + l->l_sigstk.ss_size);
-       else
-               fp = (struct netbsd32_sigframe_sigcontext *)tf->tf_rsp;
-       fp--;
-
-       /* Build stack frame for signal trampoline. */
-       switch (ps->sa_sigdesc[sig].sd_vers) {
-       case 0:
-               frame.sf_ra = (uint32_t)(u_long)p->p_sigctx.ps_sigcode;
-               break;
-       case 1:
-               frame.sf_ra = (uint32_t)(u_long)ps->sa_sigdesc[sig].sd_tramp;
-               break;
-       default:
-               /* Don't know what trampoline version; kill it. */
-               sigexit(l, SIGILL);
-       }
-       frame.sf_signum = sig;
-       frame.sf_code = ksi->ksi_trap;
-       frame.sf_scp = (uint32_t)(u_long)&fp->sf_sc;
-
-       frame.sf_sc.sc_ds = tf->tf_ds & 0xFFFF;
-       frame.sf_sc.sc_es = tf->tf_es & 0xFFFF;
-       frame.sf_sc.sc_fs = tf->tf_fs & 0xFFFF;
-       frame.sf_sc.sc_gs = tf->tf_gs & 0xFFFF;
-
-       frame.sf_sc.sc_eflags = tf->tf_rflags;
-       frame.sf_sc.sc_edi = tf->tf_rdi;
-       frame.sf_sc.sc_esi = tf->tf_rsi;
-       frame.sf_sc.sc_ebp = tf->tf_rbp;
-       frame.sf_sc.sc_ebx = tf->tf_rbx;
-       frame.sf_sc.sc_edx = tf->tf_rdx;
-       frame.sf_sc.sc_ecx = tf->tf_rcx;
-       frame.sf_sc.sc_eax = tf->tf_rax;
-       frame.sf_sc.sc_eip = tf->tf_rip;
-       frame.sf_sc.sc_cs = tf->tf_cs & 0xFFFF;
-       frame.sf_sc.sc_esp = tf->tf_rsp;
-       frame.sf_sc.sc_ss = tf->tf_ss & 0xFFFF;
-       frame.sf_sc.sc_trapno = tf->tf_trapno;
-       frame.sf_sc.sc_err = tf->tf_err;
-
-       /* Save signal stack. */
-       frame.sf_sc.sc_onstack = l->l_sigstk.ss_flags & SS_ONSTACK;
-
-       /* Save signal mask. */
-       frame.sf_sc.sc_mask = *mask;
-
-       sendsig_reset(l, sig);
-
-       mutex_exit(p->p_lock);
-       error = copyout(&frame, fp, sizeof(frame));
-       mutex_enter(p->p_lock);
-
-       if (error != 0) {
-               /*
-                * Process has trashed its stack; give it an illegal
-                * instruction to halt it in its tracks.
-                */
-               sigexit(l, SIGILL);
-               /* NOTREACHED */
-       }
-
-       netbsd32_buildcontext(l, tf, fp, catcher, onstack);
-}
-#endif
-
-static void
+void
 netbsd32_sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask)
 {
        struct lwp *l = curlwp;
@@ -354,15 +270,13 @@
        netbsd32_buildcontext(l, tf, fp, catcher, onstack);
 }
 
+void (*vec_netbsd32_sendsig)(const ksiginfo_t *, const sigset_t *);
+
 void
 netbsd32_sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
 {
-#ifdef COMPAT_16
-       if (curproc->p_sigacts->sa_sigdesc[ksi->ksi_signo].sd_vers < 2)
-               netbsd32_sendsig_sigcontext(ksi, mask);
-       else
-#endif
-               netbsd32_sendsig_siginfo(ksi, mask);
+
+       (*vec_netbsd32_sendsig)(ksi, mask);
 }
 
 int
@@ -1023,7 +937,7 @@
  * These functions perform the needed checks.
  */
 
-static int
+int
 check_sigcontext32(struct lwp *l, const struct netbsd32_sigcontext *scp)
 {
        struct pmap *pmap = l->l_proc->p_vmspace->vm_map.pmap;
@@ -1111,66 +1025,20 @@
                return VM_DEFAULT_ADDRESS32_BOTTOMUP(base, sz);
 }
 
-#ifdef COMPAT_13
-int
-compat_13_netbsd32_sigreturn(struct lwp *l, const struct compat_13_netbsd32_sigreturn_args *uap, register_t *retval)
-{
-       /* {
-               syscallarg(struct netbsd32_sigcontext13 *) sigcntxp;
-       } */
-       struct proc *p = l->l_proc;
-       struct netbsd32_sigcontext13 *scp, context;
-       struct trapframe *tf;
-       sigset_t mask;
-       int error;
+int netbsd32_amd64_init(int);
+int netbsd32_amd64_fini(int);
 
-       /*
-        * The trampoline code hands us the context.
-        * It is unsafe to keep track of it ourselves, in the event that a
-        * program jumps out of a signal handler.
-        */
-       scp = (struct netbsd32_sigcontext13 *)NETBSD32PTR64(SCARG(uap, sigcntxp));
-       if (copyin((void *)scp, &context, sizeof(*scp)) != 0)
-               return (EFAULT);
-
-       /* Restore register context. */
-       tf = l->l_md.md_regs;
-
-       /*
-        * Check for security violations.
-        */
-       error = check_sigcontext32(l, (const struct netbsd32_sigcontext *)&context);
-       if (error != 0)
-               return error;
+int
+netbsd32_amd64_init(int misc)
+{
 
-       tf->tf_gs = context.sc_gs & 0xFFFF;
-       tf->tf_fs = context.sc_fs & 0xFFFF;             
-       tf->tf_es = context.sc_es & 0xFFFF;
-       tf->tf_ds = context.sc_ds & 0xFFFF;
-       tf->tf_rflags = context.sc_eflags;
-       tf->tf_rdi = context.sc_edi;
-       tf->tf_rsi = context.sc_esi;
-       tf->tf_rbp = context.sc_ebp;
-       tf->tf_rbx = context.sc_ebx;
-       tf->tf_rdx = context.sc_edx;
-       tf->tf_rcx = context.sc_ecx;
-       tf->tf_rax = context.sc_eax;
-       tf->tf_rip = context.sc_eip;
-       tf->tf_cs = context.sc_cs & 0xFFFF;
-       tf->tf_rsp = context.sc_esp;
-       tf->tf_ss = context.sc_ss & 0xFFFF;
+       vec_netbsd32_sendsig = netbsd32_sendsig_siginfo;
+       return 0;
+}
 
-       mutex_enter(p->p_lock);
-       /* Restore signal stack. */
-       if (context.sc_onstack & SS_ONSTACK)
-               l->l_sigstk.ss_flags |= SS_ONSTACK;
-       else
-               l->l_sigstk.ss_flags &= ~SS_ONSTACK;
-       /* Restore signal mask. */
-       native_sigset13_to_sigset((sigset13_t *)&context.sc_mask, &mask);
-       (void) sigprocmask1(l, SIG_SETMASK, &mask, 0);
-       mutex_exit(p->p_lock);
+int
+netbsd32_amd64_fini(int misc)
+{
 
-       return (EJUSTRETURN);
+       return 0;
 }
-#endif
diff -r 5f16cdadeb2d -r 37836963d4d2 sys/arch/amd64/amd64/netbsd32_machdep_13.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/amd64/amd64/netbsd32_machdep_13.c        Fri Sep 14 05:37:08 2018 +0000
@@ -0,0 +1,146 @@
+/*     $NetBSD: netbsd32_machdep_13.c,v 1.1.2.1 2018/09/14 05:37:08 pgoyette Exp $     */
+
+/*
+ * Copyright (c) 2001 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Frank van der Linden for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed for the NetBSD Project by
+ *      Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ *    or promote products derived from this software without specific prior
+ *    written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep_13.c,v 1.1.2.1 2018/09/14 05:37:08 pgoyette Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_compat_netbsd.h"
+#include "opt_coredump.h"
+#include "opt_execfmt.h"
+#include "opt_user_ldt.h"
+#include "opt_mtrr.h"
+#endif
+
+#include <sys/param.h>



Home | Main Index | Thread Index | Old Index