Index: sys/kern/subr_syscall.c =================================================================== --- sys/kern/subr_syscall.c +++ sys/kern/subr_syscall.c @@ -69,7 +69,9 @@ if (__predict_false(td->td_cowgen != p->p_cowgen)) thread_cow_update(td); traced = (p->p_flag & P_TRACED) != 0; - if (__predict_false(traced || td->td_dbgflags & TDB_USERWR)) { + // if we're not traced, we won't care about TDB_USERWR; debugger cannot + // attach and set it before we get to callp->sy_call(). + if (__predict_false(traced)) { PROC_LOCK(p); td->td_dbgflags &= ~TDB_USERWR; if (traced) @@ -90,25 +92,25 @@ goto retval; } - if (__predict_false((p->p_flag & P_TRACED) != 0)) { + if (__predict_false(traced)) { PROC_LOCK(p); if (p->p_ptevents & PTRACE_SCE) ptracestop((td), SIGTRAP, NULL); PROC_UNLOCK(p); - } - if (__predict_false((td->td_dbgflags & TDB_USERWR) != 0)) { - /* - * Reread syscall number and arguments if debugger - * modified registers or memory. - */ - error = (p->p_sysent->sv_fetch_syscall_args)(td); + if (__predict_false((td->td_dbgflags & TDB_USERWR) != 0)) { + /* + * Reread syscall number and arguments if debugger + * modified registers or memory. + */ + error = (p->p_sysent->sv_fetch_syscall_args)(td); #ifdef KTRACE - if (KTRPOINT(td, KTR_SYSCALL)) - ktrsyscall(sa->code, sa->narg, sa->args); + if (KTRPOINT(td, KTR_SYSCALL)) + ktrsyscall(sa->code, sa->narg, sa->args); #endif - if (error != 0) { - td->td_errno = error; - goto retval; + if (error != 0) { + td->td_errno = error; + goto retval; + } } }