Module Name: src Committed By: christos Date: Mon Aug 31 19:51:30 UTC 2020
Modified Files: src/sys/kern: kern_syscall.c Log Message: PR/55629: Andreas Gustafsson: Don't crash when an emulation does not provide e_dtrace_syscall (like compat_netbsd32) To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/sys/kern/kern_syscall.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/kern_syscall.c diff -u src/sys/kern/kern_syscall.c:1.20 src/sys/kern/kern_syscall.c:1.21 --- src/sys/kern/kern_syscall.c:1.20 Sat May 23 19:42:43 2020 +++ src/sys/kern/kern_syscall.c Mon Aug 31 15:51:30 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_syscall.c,v 1.20 2020/05/23 23:42:43 ad Exp $ */ +/* $NetBSD: kern_syscall.c,v 1.21 2020/08/31 19:51:30 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_syscall.c,v 1.20 2020/05/23 23:42:43 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_syscall.c,v 1.21 2020/08/31 19:51:30 christos Exp $"); #ifdef _KERNEL_OPT #include "opt_modular.h" @@ -236,11 +236,16 @@ int trace_enter(register_t code, const struct sysent *sy, const void *args) { int error = 0; +#if defined(PTRACE) || defined(KDTRACE_HOOKS) + struct proc *p = curlwp->l_proc; +#endif #ifdef KDTRACE_HOOKS if (sy->sy_entry) { - struct emul *e = curlwp->l_proc->p_emul; - (*e->e_dtrace_syscall)(sy->sy_entry, code, sy, args, NULL, 0); + struct emul *e = p->p_emul; + if (e->e_dtrace_syscall) + (*e->e_dtrace_syscall)(sy->sy_entry, code, sy, args, + NULL, 0); } #endif @@ -251,7 +256,7 @@ trace_enter(register_t code, const struc ktrsyscall(code, args, sy->sy_narg); #ifdef PTRACE - if ((curlwp->l_proc->p_slflag & (PSL_SYSCALL|PSL_TRACED)) == + if ((p->p_slflag & (PSL_SYSCALL|PSL_TRACED)) == (PSL_SYSCALL|PSL_TRACED)) { proc_stoptrace(TRAP_SCE, code, args, NULL, 0); if (curlwp->l_proc->p_slflag & PSL_SYSCALLEMU) { @@ -280,8 +285,10 @@ trace_exit(register_t code, const struct #ifdef KDTRACE_HOOKS if (sy->sy_return) { - (*p->p_emul->e_dtrace_syscall)(sy->sy_return, code, sy, args, - rval, error); + struct emul *e = p->p_emul; + if (e->e_dtrace_syscall) + (*p->p_emul->e_dtrace_syscall)(sy->sy_return, code, sy, + args, rval, error); } #endif