| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: kern_syscall.c,v 1.18 2019/05/06 08:05:03 kamil Exp $ */ | | 1 | /* $NetBSD: kern_syscall.c,v 1.18.2.1 2020/09/02 12:42:32 martin 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.18 2019/05/06 08:05:03 kamil Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: kern_syscall.c,v 1.18.2.1 2020/09/02 12:42:32 martin 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 |
| @@ -228,42 +228,47 @@ trace_is_enabled(struct proc *p) | | | @@ -228,42 +228,47 @@ trace_is_enabled(struct proc *p) |
228 | | | 228 | |
229 | return (false); | | 229 | return (false); |
230 | } | | 230 | } |
231 | | | 231 | |
232 | /* | | 232 | /* |
233 | * Start trace of particular system call. If process is being traced, | | 233 | * Start trace of particular system call. If process is being traced, |
234 | * this routine is called by MD syscall dispatch code just before | | 234 | * this routine is called by MD syscall dispatch code just before |
235 | * a system call is actually executed. | | 235 | * a system call is actually executed. |
236 | */ | | 236 | */ |
237 | int | | 237 | int |
238 | trace_enter(register_t code, const struct sysent *sy, const void *args) | | 238 | trace_enter(register_t code, const struct sysent *sy, const void *args) |
239 | { | | 239 | { |
240 | int error = 0; | | 240 | int error = 0; |
| | | 241 | #if defined(PTRACE) || defined(KDTRACE_HOOKS) |
| | | 242 | struct proc *p = curlwp->l_proc; |
| | | 243 | #endif |
241 | | | 244 | |
242 | #ifdef KDTRACE_HOOKS | | 245 | #ifdef KDTRACE_HOOKS |
243 | if (sy->sy_entry) { | | 246 | if (sy->sy_entry) { |
244 | struct emul *e = curlwp->l_proc->p_emul; | | 247 | struct emul *e = p->p_emul; |
245 | (*e->e_dtrace_syscall)(sy->sy_entry, code, sy, args, NULL, 0); | | 248 | if (e->e_dtrace_syscall) |
| | | 249 | (*e->e_dtrace_syscall)(sy->sy_entry, code, sy, args, |
| | | 250 | NULL, 0); |
246 | } | | 251 | } |
247 | #endif | | 252 | #endif |
248 | | | 253 | |
249 | #ifdef SYSCALL_DEBUG | | 254 | #ifdef SYSCALL_DEBUG |
250 | scdebug_call(code, args); | | 255 | scdebug_call(code, args); |
251 | #endif /* SYSCALL_DEBUG */ | | 256 | #endif /* SYSCALL_DEBUG */ |
252 | | | 257 | |
253 | ktrsyscall(code, args, sy->sy_narg); | | 258 | ktrsyscall(code, args, sy->sy_narg); |
254 | | | 259 | |
255 | #ifdef PTRACE | | 260 | #ifdef PTRACE |
256 | if ((curlwp->l_proc->p_slflag & (PSL_SYSCALL|PSL_TRACED)) == | | 261 | if ((p->p_slflag & (PSL_SYSCALL|PSL_TRACED)) == |
257 | (PSL_SYSCALL|PSL_TRACED)) { | | 262 | (PSL_SYSCALL|PSL_TRACED)) { |
258 | proc_stoptrace(TRAP_SCE, code, args, NULL, 0); | | 263 | proc_stoptrace(TRAP_SCE, code, args, NULL, 0); |
259 | if (curlwp->l_proc->p_slflag & PSL_SYSCALLEMU) { | | 264 | if (curlwp->l_proc->p_slflag & PSL_SYSCALLEMU) { |
260 | /* tracer will emulate syscall for us */ | | 265 | /* tracer will emulate syscall for us */ |
261 | error = EJUSTRETURN; | | 266 | error = EJUSTRETURN; |
262 | } | | 267 | } |
263 | } | | 268 | } |
264 | #endif | | 269 | #endif |
265 | return error; | | 270 | return error; |
266 | } | | 271 | } |
267 | | | 272 | |
268 | /* | | 273 | /* |
269 | * End trace of particular system call. If process is being traced, | | 274 | * End trace of particular system call. If process is being traced, |
| @@ -272,28 +277,30 @@ trace_enter(register_t code, const struc | | | @@ -272,28 +277,30 @@ trace_enter(register_t code, const struc |
272 | * MD caller guarantees the passed 'code' is within the supported | | 277 | * MD caller guarantees the passed 'code' is within the supported |
273 | * system call number range for emulation the process runs under. | | 278 | * system call number range for emulation the process runs under. |
274 | */ | | 279 | */ |
275 | void | | 280 | void |
276 | trace_exit(register_t code, const struct sysent *sy, const void *args, | | 281 | trace_exit(register_t code, const struct sysent *sy, const void *args, |
277 | register_t rval[], int error) | | 282 | register_t rval[], int error) |
278 | { | | 283 | { |
279 | #if defined(PTRACE) || defined(KDTRACE_HOOKS) | | 284 | #if defined(PTRACE) || defined(KDTRACE_HOOKS) |
280 | struct proc *p = curlwp->l_proc; | | 285 | struct proc *p = curlwp->l_proc; |
281 | #endif | | 286 | #endif |
282 | | | 287 | |
283 | #ifdef KDTRACE_HOOKS | | 288 | #ifdef KDTRACE_HOOKS |
284 | if (sy->sy_return) { | | 289 | if (sy->sy_return) { |
285 | (*p->p_emul->e_dtrace_syscall)(sy->sy_return, code, sy, args, | | 290 | struct emul *e = p->p_emul; |
286 | rval, error); | | 291 | if (e->e_dtrace_syscall) |
| | | 292 | (*p->p_emul->e_dtrace_syscall)(sy->sy_return, code, sy, |
| | | 293 | args, rval, error); |
287 | } | | 294 | } |
288 | #endif | | 295 | #endif |
289 | | | 296 | |
290 | #ifdef SYSCALL_DEBUG | | 297 | #ifdef SYSCALL_DEBUG |
291 | scdebug_ret(code, error, rval); | | 298 | scdebug_ret(code, error, rval); |
292 | #endif /* SYSCALL_DEBUG */ | | 299 | #endif /* SYSCALL_DEBUG */ |
293 | | | 300 | |
294 | ktrsysret(code, error, rval); | | 301 | ktrsysret(code, error, rval); |
295 | | | 302 | |
296 | #ifdef PTRACE | | 303 | #ifdef PTRACE |
297 | if ((p->p_slflag & (PSL_SYSCALL|PSL_TRACED|PSL_SYSCALLEMU)) == | | 304 | if ((p->p_slflag & (PSL_SYSCALL|PSL_TRACED|PSL_SYSCALLEMU)) == |
298 | (PSL_SYSCALL|PSL_TRACED)) { | | 305 | (PSL_SYSCALL|PSL_TRACED)) { |
299 | proc_stoptrace(TRAP_SCX, code, args, rval, error); | | 306 | proc_stoptrace(TRAP_SCX, code, args, rval, error); |