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-9diff -r1.125 -r1.126 src/sys/arch/amd64/amd64/trap.c
(pgoyette)
--- src/sys/arch/amd64/amd64/trap.c 2019/11/21 19:23:58 1.125
+++ src/sys/arch/amd64/amd64/trap.c 2020/03/08 00:53:12 1.126
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: trap.c,v 1.125 2019/11/21 19:23:58 ad Exp $ */ | 1 | /* $NetBSD: trap.c,v 1.126 2020/03/08 00:53:12 pgoyette Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1998, 2000, 2017 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1998, 2000, 2017 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Charles M. Hannum, and by Maxime Villard. | 8 | * by Charles M. Hannum, and by Maxime Villard. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -54,53 +54,50 @@ | @@ -54,53 +54,50 @@ | |||
54 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 54 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
55 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 55 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
56 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 56 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
57 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 57 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
59 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 59 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
60 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 60 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
61 | * SUCH DAMAGE. | 61 | * SUCH DAMAGE. | |
62 | * | 62 | * | |
63 | * @(#)trap.c 7.4 (Berkeley) 5/13/91 | 63 | * @(#)trap.c 7.4 (Berkeley) 5/13/91 | |
64 | */ | 64 | */ | |
65 | 65 | |||
66 | #include <sys/cdefs.h> | 66 | #include <sys/cdefs.h> | |
67 | __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.125 2019/11/21 19:23:58 ad Exp $"); | 67 | __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.126 2020/03/08 00:53:12 pgoyette Exp $"); | |
68 | 68 | |||
69 | #include "opt_ddb.h" | 69 | #include "opt_ddb.h" | |
70 | #include "opt_kgdb.h" | 70 | #include "opt_kgdb.h" | |
71 | #include "opt_xen.h" | 71 | #include "opt_xen.h" | |
72 | #include "opt_dtrace.h" | 72 | #include "opt_dtrace.h" | |
73 | 73 | |||
74 | #include <sys/param.h> | 74 | #include <sys/param.h> | |
75 | #include <sys/systm.h> | 75 | #include <sys/systm.h> | |
76 | #include <sys/proc.h> | 76 | #include <sys/proc.h> | |
77 | #include <sys/acct.h> | 77 | #include <sys/acct.h> | |
78 | #include <sys/kauth.h> | 78 | #include <sys/kauth.h> | |
79 | #include <sys/kernel.h> | 79 | #include <sys/kernel.h> | |
80 | #include <sys/kmem.h> | 80 | #include <sys/kmem.h> | |
81 | #include <sys/ras.h> | 81 | #include <sys/ras.h> | |
82 | #include <sys/signal.h> | 82 | #include <sys/signal.h> | |
83 | #include <sys/syscall.h> | 83 | #include <sys/syscall.h> | |
84 | #include <sys/cpu.h> | 84 | #include <sys/cpu.h> | |
85 | #include <sys/ucontext.h> | 85 | #include <sys/ucontext.h> | |
86 | #include <sys/module_hook.h> | |||
87 | #include <sys/compat_stub.h> | |||
86 | 88 | |||
87 | #include <uvm/uvm_extern.h> | 89 | #include <uvm/uvm_extern.h> | |
88 | 90 | |||
89 | #ifdef COMPAT_NETBSD32 | |||
90 | #include <sys/exec.h> | |||
91 | #include <compat/netbsd32/netbsd32_exec.h> | |||
92 | #endif | |||
93 | ||||
94 | #include <machine/cpufunc.h> | 91 | #include <machine/cpufunc.h> | |
95 | #include <x86/fpu.h> | 92 | #include <x86/fpu.h> | |
96 | #include <x86/dbregs.h> | 93 | #include <x86/dbregs.h> | |
97 | #include <machine/psl.h> | 94 | #include <machine/psl.h> | |
98 | #include <machine/reg.h> | 95 | #include <machine/reg.h> | |
99 | #include <machine/trap.h> | 96 | #include <machine/trap.h> | |
100 | #include <machine/userret.h> | 97 | #include <machine/userret.h> | |
101 | #include <machine/db_machdep.h> | 98 | #include <machine/db_machdep.h> | |
102 | 99 | |||
103 | #include <x86/nmi.h> | 100 | #include <x86/nmi.h> | |
104 | 101 | |||
105 | #ifndef XENPV | 102 | #ifndef XENPV | |
106 | #include "isa.h" | 103 | #include "isa.h" | |
@@ -108,26 +105,31 @@ __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.1 | @@ -108,26 +105,31 @@ __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.1 | |||
108 | 105 | |||
109 | #include <sys/kgdb.h> | 106 | #include <sys/kgdb.h> | |
110 | 107 | |||
111 | #ifdef KDTRACE_HOOKS | 108 | #ifdef KDTRACE_HOOKS | |
112 | #include <sys/dtrace_bsd.h> | 109 | #include <sys/dtrace_bsd.h> | |
113 | /* | 110 | /* | |
114 | * This is a hook which is initialized by the dtrace module to handle traps | 111 | * This is a hook which is initialized by the dtrace module to handle traps | |
115 | * which might occur during DTrace probe execution. | 112 | * which might occur during DTrace probe execution. | |
116 | */ | 113 | */ | |
117 | dtrace_trap_func_t dtrace_trap_func = NULL; | 114 | dtrace_trap_func_t dtrace_trap_func = NULL; | |
118 | dtrace_doubletrap_func_t dtrace_doubletrap_func = NULL; | 115 | dtrace_doubletrap_func_t dtrace_doubletrap_func = NULL; | |
119 | #endif | 116 | #endif | |
120 | 117 | |||
118 | /* | |||
119 | * Module hook for amd64_oosyscall | |||
120 | */ | |||
121 | struct amd64_oosyscall_hook_t amd64_oosyscall_hook; | |||
122 | ||||
121 | void nmitrap(struct trapframe *); | 123 | void nmitrap(struct trapframe *); | |
122 | void doubletrap(struct trapframe *); | 124 | void doubletrap(struct trapframe *); | |
123 | void trap(struct trapframe *); | 125 | void trap(struct trapframe *); | |
124 | 126 | |||
125 | const char * const trap_type[] = { | 127 | const char * const trap_type[] = { | |
126 | "privileged instruction fault", /* 0 T_PRIVINFLT */ | 128 | "privileged instruction fault", /* 0 T_PRIVINFLT */ | |
127 | "breakpoint trap", /* 1 T_BPTFLT */ | 129 | "breakpoint trap", /* 1 T_BPTFLT */ | |
128 | "arithmetic trap", /* 2 T_ARITHTRAP */ | 130 | "arithmetic trap", /* 2 T_ARITHTRAP */ | |
129 | "asynchronous system trap", /* 3 T_ASTFLT */ | 131 | "asynchronous system trap", /* 3 T_ASTFLT */ | |
130 | "protection fault", /* 4 T_PROTFLT */ | 132 | "protection fault", /* 4 T_PROTFLT */ | |
131 | "trace trap", /* 5 T_TRCTRAP */ | 133 | "trace trap", /* 5 T_TRCTRAP */ | |
132 | "page fault", /* 6 T_PAGEFLT */ | 134 | "page fault", /* 6 T_PAGEFLT */ | |
133 | "alignment fault", /* 7 T_ALIGNFLT */ | 135 | "alignment fault", /* 7 T_ALIGNFLT */ | |
@@ -332,52 +334,33 @@ trap(struct trapframe *frame) | @@ -332,52 +334,33 @@ trap(struct trapframe *frame) | |||
332 | if (p == NULL) | 334 | if (p == NULL) | |
333 | goto we_re_toast; | 335 | goto we_re_toast; | |
334 | 336 | |||
335 | /* Check for copyin/copyout fault. */ | 337 | /* Check for copyin/copyout fault. */ | |
336 | onfault = onfault_handler(pcb, frame); | 338 | onfault = onfault_handler(pcb, frame); | |
337 | if (onfault != NULL) { | 339 | if (onfault != NULL) { | |
338 | onfault_restore(frame, onfault, EFAULT); | 340 | onfault_restore(frame, onfault, EFAULT); | |
339 | return; | 341 | return; | |
340 | } | 342 | } | |
341 | 343 | |||
342 | goto we_re_toast; | 344 | goto we_re_toast; | |
343 | 345 | |||
344 | case T_PROTFLT|T_USER: /* protection fault */ | 346 | case T_PROTFLT|T_USER: /* protection fault */ | |
345 | #if defined(COMPAT_NETBSD32) && defined(COMPAT_10) | 347 | { int hook_ret; | |
346 | 348 | |||
347 | /* | 349 | MODULE_HOOK_CALL(amd64_oosyscall_hook, (p, frame), | |
348 | * XXX This code currently not included in loadable module; it is | 350 | ENOSYS, hook_ret); | |
349 | * only included in built-in modules. | 351 | if (hook_ret == 0) | |
350 | */ | |||
351 | { | |||
352 | static const char lcall[7] = { 0x9a, 0, 0, 0, 0, 7, 0 }; | |||
353 | const size_t sz = sizeof(lcall); | |||
354 | char tmp[sizeof(lcall) /* Avoids VLA */]; | |||
355 | ||||
356 | /* Check for the oosyscall lcall instruction. */ | |||
357 | if (p->p_emul == &emul_netbsd32 && | |||
358 | frame->tf_rip < VM_MAXUSER_ADDRESS32 - sz && | |||
359 | copyin((void *)frame->tf_rip, tmp, sz) == 0 && | |||
360 | memcmp(tmp, lcall, sz) == 0) { | |||
361 | ||||
362 | /* Advance past the lcall. */ | |||
363 | frame->tf_rip += sz; | |||
364 | ||||
365 | /* Do the syscall. */ | |||
366 | p->p_md.md_syscall(frame); | |||
367 | goto out; | 352 | goto out; | |
368 | } | |||
369 | } | 353 | } | |
370 | #endif | |||
371 | /* FALLTHROUGH */ | 354 | /* FALLTHROUGH */ | |
372 | case T_TSSFLT|T_USER: | 355 | case T_TSSFLT|T_USER: | |
373 | case T_SEGNPFLT|T_USER: | 356 | case T_SEGNPFLT|T_USER: | |
374 | case T_STKFLT|T_USER: | 357 | case T_STKFLT|T_USER: | |
375 | case T_ALIGNFLT|T_USER: | 358 | case T_ALIGNFLT|T_USER: | |
376 | KSI_INIT_TRAP(&ksi); | 359 | KSI_INIT_TRAP(&ksi); | |
377 | ksi.ksi_trap = type & ~T_USER; | 360 | ksi.ksi_trap = type & ~T_USER; | |
378 | ksi.ksi_addr = (void *)frame->tf_rip; | 361 | ksi.ksi_addr = (void *)frame->tf_rip; | |
379 | switch (type) { | 362 | switch (type) { | |
380 | case T_SEGNPFLT|T_USER: | 363 | case T_SEGNPFLT|T_USER: | |
381 | case T_STKFLT|T_USER: | 364 | case T_STKFLT|T_USER: | |
382 | ksi.ksi_signo = SIGBUS; | 365 | ksi.ksi_signo = SIGBUS; | |
383 | ksi.ksi_code = BUS_ADRERR; | 366 | ksi.ksi_code = BUS_ADRERR; |
--- src/sys/compat/netbsd32/netbsd32_mod.c 2019/11/20 19:37:53 1.16
+++ src/sys/compat/netbsd32/netbsd32_mod.c 2020/03/08 00:53:12 1.17
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: netbsd32_mod.c,v 1.16 2019/11/20 19:37:53 pgoyette Exp $ */ | 1 | /* $NetBSD: netbsd32_mod.c,v 1.17 2020/03/08 00:53:12 pgoyette Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software developed for The NetBSD Foundation | 7 | * This code is derived from software developed for The NetBSD Foundation | |
8 | * by Andrew Doran. | 8 | * by Andrew Doran. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -19,42 +19,72 @@ | @@ -19,42 +19,72 @@ | |||
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | /* | |||
33 | * Copyright (c) 1998, 2000, 2017 The NetBSD Foundation, Inc. | |||
34 | * All rights reserved. | |||
35 | * | |||
36 | * This code is derived from software contributed to The NetBSD Foundation | |||
37 | * by Charles M. Hannum, and by Maxime Villard. | |||
38 | * | |||
39 | * Redistribution and use in source and binary forms, with or without | |||
40 | * modification, are permitted provided that the following conditions | |||
41 | * are met: | |||
42 | * 1. Redistributions of source code must retain the above copyright | |||
43 | * notice, this list of conditions and the following disclaimer. | |||
44 | * 2. Redistributions in binary form must reproduce the above copyright | |||
45 | * notice, this list of conditions and the following disclaimer in the | |||
46 | * documentation and/or other materials provided with the distribution. | |||
47 | * | |||
48 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | |||
49 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |||
50 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |||
51 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |||
52 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |||
53 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |||
54 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |||
55 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |||
56 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |||
57 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |||
58 | * POSSIBILITY OF SUCH DAMAGE. | |||
59 | */ | |||
60 | ||||
32 | #include <sys/cdefs.h> | 61 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: netbsd32_mod.c,v 1.16 2019/11/20 19:37:53 pgoyette Exp $"); | 62 | __KERNEL_RCSID(0, "$NetBSD: netbsd32_mod.c,v 1.17 2020/03/08 00:53:12 pgoyette Exp $"); | |
34 | 63 | |||
35 | #ifdef _KERNEL_OPT | 64 | #ifdef _KERNEL_OPT | |
36 | #include "opt_execfmt.h" | 65 | #include "opt_execfmt.h" | |
37 | #endif | 66 | #endif | |
38 | 67 | |||
39 | #ifndef ELFSIZE | 68 | #ifndef ELFSIZE | |
40 | #define ELFSIZE ARCH_ELFSIZE | 69 | #define ELFSIZE ARCH_ELFSIZE | |
41 | #endif | 70 | #endif | |
42 | 71 | |||
43 | #include <sys/param.h> | 72 | #include <sys/param.h> | |
44 | #include <sys/module.h> | 73 | #include <sys/module.h> | |
45 | #include <sys/exec.h> | 74 | #include <sys/exec.h> | |
46 | #include <sys/exec_elf.h> | 75 | #include <sys/exec_elf.h> | |
47 | #include <sys/module_hook.h> | 76 | #include <sys/module_hook.h> | |
77 | #include <sys/compat_stub.h> | |||
48 | 78 | |||
49 | #include <compat/netbsd32/netbsd32_sysctl.h> | 79 | #include <compat/netbsd32/netbsd32_sysctl.h> | |
50 | #include <compat/netbsd32/netbsd32_kern_proc.h> | 80 | #include <compat/netbsd32/netbsd32_kern_proc.h> | |
51 | #include <compat/netbsd32/netbsd32_exec.h> | 81 | #include <compat/netbsd32/netbsd32_exec.h> | |
52 | 82 | |||
53 | #define ELF32_AUXSIZE (howmany(ELF_AUX_ENTRIES * sizeof(Aux32Info), \ | 83 | #define ELF32_AUXSIZE (howmany(ELF_AUX_ENTRIES * sizeof(Aux32Info), \ | |
54 | sizeof(Elf32_Addr)) + MAXPATHLEN + ALIGN(1)) | 84 | sizeof(Elf32_Addr)) + MAXPATHLEN + ALIGN(1)) | |
55 | 85 | |||
56 | struct compat32_80_modctl_hook_t compat32_80_modctl_hook; | 86 | struct compat32_80_modctl_hook_t compat32_80_modctl_hook; | |
57 | 87 | |||
58 | # define DEPS1 "ksem,compat_util" | 88 | # define DEPS1 "ksem,compat_util" | |
59 | 89 | |||
60 | #if defined(EXEC_ELF32) | 90 | #if defined(EXEC_ELF32) | |
@@ -90,47 +120,86 @@ static struct execsw netbsd32_execsw[] = | @@ -90,47 +120,86 @@ static struct execsw netbsd32_execsw[] = | |||
90 | .elf_probe_func = netbsd32_elf32_probe, | 120 | .elf_probe_func = netbsd32_elf32_probe, | |
91 | }, | 121 | }, | |
92 | .es_emul = &emul_netbsd32, | 122 | .es_emul = &emul_netbsd32, | |
93 | .es_prio = EXECSW_PRIO_ANY, | 123 | .es_prio = EXECSW_PRIO_ANY, | |
94 | .es_arglen = ELF32_AUXSIZE, | 124 | .es_arglen = ELF32_AUXSIZE, | |
95 | .es_copyargs = netbsd32_elf32_copyargs, | 125 | .es_copyargs = netbsd32_elf32_copyargs, | |
96 | .es_setregs = NULL, | 126 | .es_setregs = NULL, | |
97 | .es_coredump = coredump_elf32, | 127 | .es_coredump = coredump_elf32, | |
98 | .es_setup_stack = exec_setup_stack, | 128 | .es_setup_stack = exec_setup_stack, | |
99 | }, | 129 | }, | |
100 | #endif | 130 | #endif | |
101 | }; | 131 | }; | |
102 | 132 | |||
133 | #if defined(__amd64__) | |||
134 | ||||
135 | /* This code was moved here, from $SRC/arch/amd64/amd64/trap.c */ | |||
136 | ||||
137 | static int | |||
138 | amd64_oosyscall_handle(struct proc *p, struct trapframe *frame) | |||
139 | { | |||
140 | ||||
141 | static const char lcall[7] = { 0x9a, 0, 0, 0, 0, 7, 0 }; | |||
142 | const size_t sz = sizeof(lcall); | |||
143 | char tmp[sizeof(lcall) /* Avoids VLA */]; | |||
144 | ||||
145 | /* Check for the oosyscall lcall instruction. */ | |||
146 | if (p->p_emul == &emul_netbsd32 && | |||
147 | frame->tf_rip < VM_MAXUSER_ADDRESS32 - sz && | |||
148 | copyin((void *)frame->tf_rip, tmp, sz) == 0 && | |||
149 | memcmp(tmp, lcall, sz) == 0) { | |||
150 | ||||
151 | /* Advance past the lcall. */ | |||
152 | frame->tf_rip += sz; | |||
153 | ||||
154 | /* Do the syscall */ | |||
155 | p->p_md.md_syscall(frame); | |||
156 | return 0; | |||
157 | } else | |||
158 | return EPASSTHROUGH; | |||
159 | } | |||
160 | #endif | |||
161 | ||||
103 | static int | 162 | static int | |
104 | compat_netbsd32_modcmd(modcmd_t cmd, void *arg) | 163 | compat_netbsd32_modcmd(modcmd_t cmd, void *arg) | |
105 | { | 164 | { | |
106 | int error; | 165 | int error; | |
107 | 166 | |||
108 | switch (cmd) { | 167 | switch (cmd) { | |
109 | case MODULE_CMD_INIT: | 168 | case MODULE_CMD_INIT: | |
110 | error = exec_add(netbsd32_execsw, | 169 | error = exec_add(netbsd32_execsw, | |
111 | __arraycount(netbsd32_execsw)); | 170 | __arraycount(netbsd32_execsw)); | |
112 | if (error == 0) { | 171 | if (error == 0) { | |
113 | netbsd32_sysctl_init(); | 172 | netbsd32_sysctl_init(); | |
114 | netbsd32_machdep_md_init(); | 173 | netbsd32_machdep_md_init(); | |
115 | netbsd32_kern_proc_32_init(); | 174 | netbsd32_kern_proc_32_init(); | |
175 | #if defined(__amd64__) | |||
176 | MODULE_HOOK_SET(amd64_oosyscall_hook, amd64_oosyscall_handle); | |||
177 | #endif | |||
116 | } | 178 | } | |
117 | return error; | 179 | return error; | |
118 | 180 | |||
119 | case MODULE_CMD_FINI: | 181 | case MODULE_CMD_FINI: | |
182 | #if defined(__amd64__) | |||
183 | MODULE_HOOK_UNSET(amd64_oosyscall_hook); | |||
184 | #endif | |||
120 | netbsd32_machdep_md_fini(); | 185 | netbsd32_machdep_md_fini(); | |
121 | netbsd32_sysctl_fini(); | 186 | netbsd32_sysctl_fini(); | |
122 | netbsd32_kern_proc_32_fini(); | 187 | netbsd32_kern_proc_32_fini(); | |
123 | 188 | |||
124 | error = exec_remove(netbsd32_execsw, | 189 | error = exec_remove(netbsd32_execsw, | |
125 | __arraycount(netbsd32_execsw)); | 190 | __arraycount(netbsd32_execsw)); | |
126 | if (error) { | 191 | if (error) { | |
127 | netbsd32_kern_proc_32_init(); | 192 | netbsd32_kern_proc_32_init(); | |
128 | netbsd32_sysctl_init(); | 193 | netbsd32_sysctl_init(); | |
129 | netbsd32_machdep_md_init(); | 194 | netbsd32_machdep_md_init(); | |
195 | #if defined(__amd64__) | |||
196 | MODULE_HOOK_SET(amd64_oosyscall_hook, | |||
197 | amd64_oosyscall_handle); | |||
198 | #endif | |||
130 | } | 199 | } | |
131 | return error; | 200 | return error; | |
132 | 201 | |||
133 | default: | 202 | default: | |
134 | return ENOTTY; | 203 | return ENOTTY; | |
135 | } | 204 | } | |
136 | } | 205 | } |
--- src/sys/sys/compat_stub.h 2019/11/20 19:37:54 1.22
+++ src/sys/sys/compat_stub.h 2020/03/08 00:53:13 1.23
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: compat_stub.h,v 1.22 2019/11/20 19:37:54 pgoyette Exp $ */ | 1 | /* $NetBSD: compat_stub.h,v 1.23 2020/03/08 00:53:13 pgoyette Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Paul Goyette | 8 | * by Paul Goyette | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -371,14 +371,21 @@ MODULE_HOOK(sendsig_sigcontext_16_hook, | @@ -371,14 +371,21 @@ MODULE_HOOK(sendsig_sigcontext_16_hook, | |||
371 | */ | 371 | */ | |
372 | 372 | |||
373 | struct uvm_coredump_state; | 373 | struct uvm_coredump_state; | |
374 | MODULE_HOOK(coredump_hook, int, (struct lwp *, const char *)); | 374 | MODULE_HOOK(coredump_hook, int, (struct lwp *, const char *)); | |
375 | MODULE_HOOK(coredump_offset_hook, off_t, (struct coredump_iostate *)); | 375 | MODULE_HOOK(coredump_offset_hook, off_t, (struct coredump_iostate *)); | |
376 | MODULE_HOOK(coredump_write_hook, int, | 376 | MODULE_HOOK(coredump_write_hook, int, | |
377 | (struct coredump_iostate *, enum uio_seg, const void *, size_t)); | 377 | (struct coredump_iostate *, enum uio_seg, const void *, size_t)); | |
378 | MODULE_HOOK(coredump_netbsd_hook, int, | 378 | MODULE_HOOK(coredump_netbsd_hook, int, | |
379 | (struct lwp *, struct coredump_iostate *)); | 379 | (struct lwp *, struct coredump_iostate *)); | |
380 | MODULE_HOOK(uvm_coredump_walkmap_hook, int, | 380 | MODULE_HOOK(uvm_coredump_walkmap_hook, int, | |
381 | (struct proc *, int (*)(struct uvm_coredump_state *), void *)); | 381 | (struct proc *, int (*)(struct uvm_coredump_state *), void *)); | |
382 | MODULE_HOOK(uvm_coredump_count_segs_hook, int, (struct proc *)); | 382 | MODULE_HOOK(uvm_coredump_count_segs_hook, int, (struct proc *)); | |
383 | 383 | |||
384 | /* | |||
385 | * Hook for amd64 handler for oosyscall for COMPAT_NETBSD32 && COMPAT_10) | |||
386 | */ | |||
387 | struct proc; | |||
388 | struct trapframe; | |||
389 | MODULE_HOOK(amd64_oosyscall_hook, int, (struct proc *, struct trapframe *)); | |||
390 | ||||
384 | #endif /* _SYS_COMPAT_STUB_H */ | 391 | #endif /* _SYS_COMPAT_STUB_H */ |