| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: kern_syscall.c,v 1.20 2020/05/23 23:42:43 ad Exp $ */ | | 1 | /* $NetBSD: kern_syscall.c,v 1.21 2020/08/31 19:51:30 christos 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. |
| @@ -20,27 +20,27 @@ | | | @@ -20,27 +20,27 @@ |
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 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __KERNEL_RCSID(0, "$NetBSD: kern_syscall.c,v 1.20 2020/05/23 23:42:43 ad Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: kern_syscall.c,v 1.21 2020/08/31 19:51:30 christos Exp $"); |
34 | | | 34 | |
35 | #ifdef _KERNEL_OPT | | 35 | #ifdef _KERNEL_OPT |
36 | #include "opt_modular.h" | | 36 | #include "opt_modular.h" |
37 | #include "opt_syscall_debug.h" | | 37 | #include "opt_syscall_debug.h" |
38 | #include "opt_ktrace.h" | | 38 | #include "opt_ktrace.h" |
39 | #include "opt_ptrace.h" | | 39 | #include "opt_ptrace.h" |
40 | #include "opt_dtrace.h" | | 40 | #include "opt_dtrace.h" |
41 | #endif | | 41 | #endif |
42 | | | 42 | |
43 | /* XXX To get syscall prototypes. */ | | 43 | /* XXX To get syscall prototypes. */ |
44 | #define SYSVSHM | | 44 | #define SYSVSHM |
45 | #define SYSVSEM | | 45 | #define SYSVSEM |
46 | #define SYSVMSG | | 46 | #define SYSVMSG |
| @@ -226,42 +226,47 @@ trace_is_enabled(struct proc *p) | | | @@ -226,42 +226,47 @@ trace_is_enabled(struct proc *p) |
226 | | | 226 | |
227 | return (false); | | 227 | return (false); |
228 | } | | 228 | } |
229 | | | 229 | |
230 | /* | | 230 | /* |
231 | * Start trace of particular system call. If process is being traced, | | 231 | * Start trace of particular system call. If process is being traced, |
232 | * this routine is called by MD syscall dispatch code just before | | 232 | * this routine is called by MD syscall dispatch code just before |
233 | * a system call is actually executed. | | 233 | * a system call is actually executed. |
234 | */ | | 234 | */ |
235 | int | | 235 | int |
236 | trace_enter(register_t code, const struct sysent *sy, const void *args) | | 236 | trace_enter(register_t code, const struct sysent *sy, const void *args) |
237 | { | | 237 | { |
238 | int error = 0; | | 238 | int error = 0; |
| | | 239 | #if defined(PTRACE) || defined(KDTRACE_HOOKS) |
| | | 240 | struct proc *p = curlwp->l_proc; |
| | | 241 | #endif |
239 | | | 242 | |
240 | #ifdef KDTRACE_HOOKS | | 243 | #ifdef KDTRACE_HOOKS |
241 | if (sy->sy_entry) { | | 244 | if (sy->sy_entry) { |
242 | struct emul *e = curlwp->l_proc->p_emul; | | 245 | struct emul *e = p->p_emul; |
243 | (*e->e_dtrace_syscall)(sy->sy_entry, code, sy, args, NULL, 0); | | 246 | if (e->e_dtrace_syscall) |
| | | 247 | (*e->e_dtrace_syscall)(sy->sy_entry, code, sy, args, |
| | | 248 | NULL, 0); |
244 | } | | 249 | } |
245 | #endif | | 250 | #endif |
246 | | | 251 | |
247 | #ifdef SYSCALL_DEBUG | | 252 | #ifdef SYSCALL_DEBUG |
248 | scdebug_call(code, args); | | 253 | scdebug_call(code, args); |
249 | #endif /* SYSCALL_DEBUG */ | | 254 | #endif /* SYSCALL_DEBUG */ |
250 | | | 255 | |
251 | ktrsyscall(code, args, sy->sy_narg); | | 256 | ktrsyscall(code, args, sy->sy_narg); |
252 | | | 257 | |
253 | #ifdef PTRACE | | 258 | #ifdef PTRACE |
254 | if ((curlwp->l_proc->p_slflag & (PSL_SYSCALL|PSL_TRACED)) == | | 259 | if ((p->p_slflag & (PSL_SYSCALL|PSL_TRACED)) == |
255 | (PSL_SYSCALL|PSL_TRACED)) { | | 260 | (PSL_SYSCALL|PSL_TRACED)) { |
256 | proc_stoptrace(TRAP_SCE, code, args, NULL, 0); | | 261 | proc_stoptrace(TRAP_SCE, code, args, NULL, 0); |
257 | if (curlwp->l_proc->p_slflag & PSL_SYSCALLEMU) { | | 262 | if (curlwp->l_proc->p_slflag & PSL_SYSCALLEMU) { |
258 | /* tracer will emulate syscall for us */ | | 263 | /* tracer will emulate syscall for us */ |
259 | error = EJUSTRETURN; | | 264 | error = EJUSTRETURN; |
260 | } | | 265 | } |
261 | } | | 266 | } |
262 | #endif | | 267 | #endif |
263 | return error; | | 268 | return error; |
264 | } | | 269 | } |
265 | | | 270 | |
266 | /* | | 271 | /* |
267 | * End trace of particular system call. If process is being traced, | | 272 | * End trace of particular system call. If process is being traced, |
| @@ -270,28 +275,30 @@ trace_enter(register_t code, const struc | | | @@ -270,28 +275,30 @@ trace_enter(register_t code, const struc |
270 | * MD caller guarantees the passed 'code' is within the supported | | 275 | * MD caller guarantees the passed 'code' is within the supported |
271 | * system call number range for emulation the process runs under. | | 276 | * system call number range for emulation the process runs under. |
272 | */ | | 277 | */ |
273 | void | | 278 | void |
274 | trace_exit(register_t code, const struct sysent *sy, const void *args, | | 279 | trace_exit(register_t code, const struct sysent *sy, const void *args, |
275 | register_t rval[], int error) | | 280 | register_t rval[], int error) |
276 | { | | 281 | { |
277 | #if defined(PTRACE) || defined(KDTRACE_HOOKS) | | 282 | #if defined(PTRACE) || defined(KDTRACE_HOOKS) |
278 | struct proc *p = curlwp->l_proc; | | 283 | struct proc *p = curlwp->l_proc; |
279 | #endif | | 284 | #endif |
280 | | | 285 | |
281 | #ifdef KDTRACE_HOOKS | | 286 | #ifdef KDTRACE_HOOKS |
282 | if (sy->sy_return) { | | 287 | if (sy->sy_return) { |
283 | (*p->p_emul->e_dtrace_syscall)(sy->sy_return, code, sy, args, | | 288 | struct emul *e = p->p_emul; |
284 | rval, error); | | 289 | if (e->e_dtrace_syscall) |
| | | 290 | (*p->p_emul->e_dtrace_syscall)(sy->sy_return, code, sy, |
| | | 291 | args, rval, error); |
285 | } | | 292 | } |
286 | #endif | | 293 | #endif |
287 | | | 294 | |
288 | #ifdef SYSCALL_DEBUG | | 295 | #ifdef SYSCALL_DEBUG |
289 | scdebug_ret(code, error, rval); | | 296 | scdebug_ret(code, error, rval); |
290 | #endif /* SYSCALL_DEBUG */ | | 297 | #endif /* SYSCALL_DEBUG */ |
291 | | | 298 | |
292 | ktrsysret(code, error, rval); | | 299 | ktrsysret(code, error, rval); |
293 | | | 300 | |
294 | #ifdef PTRACE | | 301 | #ifdef PTRACE |
295 | if ((p->p_slflag & (PSL_SYSCALL|PSL_TRACED|PSL_SYSCALLEMU)) == | | 302 | if ((p->p_slflag & (PSL_SYSCALL|PSL_TRACED|PSL_SYSCALLEMU)) == |
296 | (PSL_SYSCALL|PSL_TRACED)) { | | 303 | (PSL_SYSCALL|PSL_TRACED)) { |
297 | proc_stoptrace(TRAP_SCX, code, args, rval, error); | | 304 | proc_stoptrace(TRAP_SCX, code, args, rval, error); |