Module Name:    src
Committed By:   martin
Date:           Sun Mar  8 10:54:43 UTC 2020

Modified Files:
        src/sys/arch/amd64/amd64 [netbsd-9]: trap.c
        src/sys/compat/netbsd32 [netbsd-9]: netbsd32_mod.c
        src/sys/sys [netbsd-9]: compat_stub.h

Log Message:
Pull up following revision(s) (requested by pgoyette in ticket #762):

        sys/arch/amd64/amd64/trap.c: revision 1.126
        sys/compat/netbsd32/netbsd32_mod.c: revision 1.17
        sys/compat/netbsd32/netbsd32_mod.c: revision 1.18
        sys/sys/compat_stub.h: revision 1.23

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

 -

fix indentation.  NFCI


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.121.2.1 src/sys/arch/amd64/amd64/trap.c
cvs rdiff -u -r1.15 -r1.15.4.1 src/sys/compat/netbsd32/netbsd32_mod.c
cvs rdiff -u -r1.18.2.2 -r1.18.2.3 src/sys/sys/compat_stub.h

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/amd64/amd64/trap.c
diff -u src/sys/arch/amd64/amd64/trap.c:1.121 src/sys/arch/amd64/amd64/trap.c:1.121.2.1
--- src/sys/arch/amd64/amd64/trap.c:1.121	Sat Jul 13 17:03:01 2019
+++ src/sys/arch/amd64/amd64/trap.c	Sun Mar  8 10:54:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.121 2019/07/13 17:03:01 mlelstv Exp $	*/
+/*	$NetBSD: trap.c,v 1.121.2.1 2020/03/08 10:54:43 martin 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.121 2019/07/13 17:03:01 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.121.2.1 2020/03/08 10:54:43 martin Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -83,14 +83,11 @@ __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.1
 #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>
@@ -121,6 +118,11 @@ dtrace_trap_func_t	dtrace_trap_func = NU
 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 *);
@@ -350,32 +352,12 @@ trap(struct trapframe *frame)
 		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[sz];
-
-		/* 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;
+	{	int hook_ret;
 
-			/* Do the syscall. */
-			p->p_md.md_syscall(frame);
-			goto out;
-		}
+		MODULE_HOOK_CALL(amd64_oosyscall_hook, (p, frame),
+			ENOSYS, hook_ret);
+		if (hook_ret == 0)
 	}
-#endif
 		/* FALLTHROUGH */
 	case T_TSSFLT|T_USER:
 	case T_SEGNPFLT|T_USER:

Index: src/sys/compat/netbsd32/netbsd32_mod.c
diff -u src/sys/compat/netbsd32/netbsd32_mod.c:1.15 src/sys/compat/netbsd32/netbsd32_mod.c:1.15.4.1
--- src/sys/compat/netbsd32/netbsd32_mod.c:1.15	Sun Jan 27 02:08:40 2019
+++ src/sys/compat/netbsd32/netbsd32_mod.c	Sun Mar  8 10:54:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_mod.c,v 1.15 2019/01/27 02:08:40 pgoyette Exp $	*/
+/*	$NetBSD: netbsd32_mod.c,v 1.15.4.1 2020/03/08 10:54:43 martin 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.15 2019/01/27 02:08:40 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_mod.c,v 1.15.4.1 2020/03/08 10:54:43 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_execfmt.h"
@@ -45,6 +74,7 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_mod
 #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 @@ static struct execsw netbsd32_execsw[] =
 #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,17 @@ compat_netbsd32_modcmd(modcmd_t cmd, voi
 			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 +193,10 @@ compat_netbsd32_modcmd(modcmd_t cmd, voi
 			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;
 

Index: src/sys/sys/compat_stub.h
diff -u src/sys/sys/compat_stub.h:1.18.2.2 src/sys/sys/compat_stub.h:1.18.2.3
--- src/sys/sys/compat_stub.h:1.18.2.2	Mon Nov 11 17:11:07 2019
+++ src/sys/sys/compat_stub.h	Sun Mar  8 10:54:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_stub.h,v 1.18.2.2 2019/11/11 17:11:07 martin Exp $	*/
+/*	$NetBSD: compat_stub.h,v 1.18.2.3 2020/03/08 10:54:43 martin Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -371,4 +371,11 @@ MODULE_HOOK(sendsig_sigcontext_16_hook, 
  */
 MODULE_HOOK(coredump_hook, int, (struct lwp *, const char *));
 
+/*
+ * 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 */

Reply via email to