Source-Changes-HG archive

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

[src/trunk]: src/sys/sys Fix another left-over from last year's [pgoyette-com...



details:   https://anonhg.NetBSD.org/src/rev/bcc423bf5b25
branches:  trunk
changeset: 969971:bcc423bf5b25
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sun Mar 08 00:53:12 2020 +0000

description:
Fix another left-over from last year's [pgoyette-compat] work.  This
allows recognition of the oosyscall sequence for amd64.

Fixes PR kern/55038

XXX pullup-9

diffstat:

 sys/arch/amd64/amd64/trap.c        |  43 ++++++---------------
 sys/compat/netbsd32/netbsd32_mod.c |  73 ++++++++++++++++++++++++++++++++++++-
 sys/sys/compat_stub.h              |   9 ++++-
 3 files changed, 92 insertions(+), 33 deletions(-)

diffs (225 lines):

diff -r d5b68f967275 -r bcc423bf5b25 sys/arch/amd64/amd64/trap.c
--- a/sys/arch/amd64/amd64/trap.c       Sun Mar 08 00:31:19 2020 +0000
+++ b/sys/arch/amd64/amd64/trap.c       Sun Mar 08 00:53:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.125 2019/11/21 19:23:58 ad Exp $    */
+/*     $NetBSD: trap.c,v 1.126 2020/03/08 00:53:12 pgoyette Exp $      */
 
 /*
  * Copyright (c) 1998, 2000, 2017 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.125 2019/11/21 19:23:58 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.126 2020/03/08 00:53:12 pgoyette Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -83,14 +83,11 @@
 #include <sys/syscall.h>
 #include <sys/cpu.h>
 #include <sys/ucontext.h>
+#include <sys/module_hook.h>
+#include <sys/compat_stub.h>
 
 #include <uvm/uvm_extern.h>
 
-#ifdef COMPAT_NETBSD32
-#include <sys/exec.h>
-#include <compat/netbsd32/netbsd32_exec.h>
-#endif
-
 #include <machine/cpufunc.h>
 #include <x86/fpu.h>
 #include <x86/dbregs.h>
@@ -118,6 +115,11 @@
 dtrace_doubletrap_func_t dtrace_doubletrap_func = NULL;
 #endif
 
+/*
+ * Module hook for amd64_oosyscall
+ */
+struct amd64_oosyscall_hook_t amd64_oosyscall_hook;
+
 void nmitrap(struct trapframe *);
 void doubletrap(struct trapframe *);
 void trap(struct trapframe *);
@@ -342,32 +344,13 @@
                goto we_re_toast;
 
        case T_PROTFLT|T_USER:          /* protection fault */
-#if defined(COMPAT_NETBSD32) && defined(COMPAT_10)
-
-/*
- * XXX This code currently not included in loadable module;  it is
- * only included in built-in modules.
- */
-       {
-               static const char lcall[7] = { 0x9a, 0, 0, 0, 0, 7, 0 };
-               const size_t sz = sizeof(lcall);
-               char tmp[sizeof(lcall) /* Avoids VLA */];
+       {       int hook_ret;
 
-               /* Check for the oosyscall lcall instruction. */
-               if (p->p_emul == &emul_netbsd32 &&
-                   frame->tf_rip < VM_MAXUSER_ADDRESS32 - sz &&
-                   copyin((void *)frame->tf_rip, tmp, sz) == 0 &&
-                   memcmp(tmp, lcall, sz) == 0) {
-
-                       /* Advance past the lcall. */
-                       frame->tf_rip += sz;
-
-                       /* Do the syscall. */
-                       p->p_md.md_syscall(frame);
+               MODULE_HOOK_CALL(amd64_oosyscall_hook, (p, frame),
+                       ENOSYS, hook_ret);
+               if (hook_ret == 0)
                        goto out;
-               }
        }
-#endif
                /* FALLTHROUGH */
        case T_TSSFLT|T_USER:
        case T_SEGNPFLT|T_USER:
diff -r d5b68f967275 -r bcc423bf5b25 sys/compat/netbsd32/netbsd32_mod.c
--- a/sys/compat/netbsd32/netbsd32_mod.c        Sun Mar 08 00:31:19 2020 +0000
+++ b/sys/compat/netbsd32/netbsd32_mod.c        Sun Mar 08 00:53:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_mod.c,v 1.16 2019/11/20 19:37:53 pgoyette Exp $       */
+/*     $NetBSD: netbsd32_mod.c,v 1.17 2020/03/08 00:53:12 pgoyette Exp $       */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,8 +29,37 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+/*
+ * Copyright (c) 1998, 2000, 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum, and by Maxime Villard.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 THE FOUNDATION OR CONTRIBUTORS
+ * 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_mod.c,v 1.16 2019/11/20 19:37:53 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_mod.c,v 1.17 2020/03/08 00:53:12 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_execfmt.h"
@@ -45,6 +74,7 @@
 #include <sys/exec.h>
 #include <sys/exec_elf.h>
 #include <sys/module_hook.h>
+#include <sys/compat_stub.h>
 
 #include <compat/netbsd32/netbsd32_sysctl.h>
 #include <compat/netbsd32/netbsd32_kern_proc.h>
@@ -100,6 +130,35 @@
 #endif
 };
 
+#if defined(__amd64__)
+
+/* This code was moved here, from $SRC/arch/amd64/amd64/trap.c */
+
+static int
+amd64_oosyscall_handle(struct proc *p, struct trapframe *frame)
+{
+
+       static const char lcall[7] = { 0x9a, 0, 0, 0, 0, 7, 0 };
+       const size_t sz = sizeof(lcall);
+       char tmp[sizeof(lcall) /* Avoids VLA */];
+
+       /* Check for the oosyscall lcall instruction. */
+       if (p->p_emul == &emul_netbsd32 &&
+           frame->tf_rip < VM_MAXUSER_ADDRESS32 - sz &&
+           copyin((void *)frame->tf_rip, tmp, sz) == 0 &&
+           memcmp(tmp, lcall, sz) == 0) {
+
+               /* Advance past the lcall. */
+               frame->tf_rip += sz;
+
+               /* Do the syscall */
+               p->p_md.md_syscall(frame);
+               return 0;
+       } else
+               return EPASSTHROUGH;
+}
+#endif
+
 static int
 compat_netbsd32_modcmd(modcmd_t cmd, void *arg)
 {
@@ -113,10 +172,16 @@
                        netbsd32_sysctl_init();
                        netbsd32_machdep_md_init();
                        netbsd32_kern_proc_32_init();
+#if defined(__amd64__)
+               MODULE_HOOK_SET(amd64_oosyscall_hook, amd64_oosyscall_handle);
+#endif
                }
                return error;
 
        case MODULE_CMD_FINI:
+#if defined(__amd64__)
+               MODULE_HOOK_UNSET(amd64_oosyscall_hook);
+#endif
                netbsd32_machdep_md_fini();
                netbsd32_sysctl_fini();
                netbsd32_kern_proc_32_fini();
@@ -127,6 +192,10 @@
                        netbsd32_kern_proc_32_init();
                        netbsd32_sysctl_init();
                        netbsd32_machdep_md_init();
+#if defined(__amd64__)
+                       MODULE_HOOK_SET(amd64_oosyscall_hook,
+                           amd64_oosyscall_handle);
+#endif
                }
                return error;
 
diff -r d5b68f967275 -r bcc423bf5b25 sys/sys/compat_stub.h
--- a/sys/sys/compat_stub.h     Sun Mar 08 00:31:19 2020 +0000
+++ b/sys/sys/compat_stub.h     Sun Mar 08 00:53:12 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat_stub.h,v 1.22 2019/11/20 19:37:54 pgoyette Exp $        */
+/*     $NetBSD: compat_stub.h,v 1.23 2020/03/08 00:53:13 pgoyette Exp $        */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -381,4 +381,11 @@
     (struct proc *, int (*)(struct uvm_coredump_state *), void *));
 MODULE_HOOK(uvm_coredump_count_segs_hook, int, (struct proc *));
 
+/*
+ * Hook for amd64 handler for oosyscall for COMPAT_NETBSD32 && COMPAT_10)
+ */
+struct proc;
+struct trapframe;
+MODULE_HOOK(amd64_oosyscall_hook, int, (struct proc *, struct trapframe *));
+
 #endif /* _SYS_COMPAT_STUB_H */



Home | Main Index | Thread Index | Old Index