Changeset View
Standalone View
sys/kern/subr_syscall.c
| Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | syscallenter(struct thread *td) | ||||
| VM_CNT_INC(v_syscall); | VM_CNT_INC(v_syscall); | ||||
| p = td->td_proc; | p = td->td_proc; | ||||
| sa = &td->td_sa; | sa = &td->td_sa; | ||||
| td->td_pticks = 0; | td->td_pticks = 0; | ||||
| if (__predict_false(td->td_cowgen != atomic_load_int(&p->p_cowgen))) | if (__predict_false(td->td_cowgen != atomic_load_int(&p->p_cowgen))) | ||||
| thread_cow_update(td); | thread_cow_update(td); | ||||
| traced = (p->p_flag & P_TRACED) != 0; | traced = (p->p_flag & P_TRACED) != 0; | ||||
| if (__predict_false(traced || td->td_dbgflags & TDB_USERWR)) { | if (__predict_false(traced || (td->td_dbgflags & (TDB_USERWR | | ||||
| TDB_SET_SC_RET)) != 0)) { | |||||
markj: How is it possible to have `!traced && (td->td_dbgflags & TDB_SET_SC_RET) != 0`? | |||||
kibAuthorUnsubmitted Done Inline ActionsMight be it is not, but I did it out of caution. I can remove it, but the idea is to ensure that the flags affecting the previous syscall entry do not leak to the current. kib: Might be it is not, but I did it out of caution.
I can remove it, but the idea is to ensure… | |||||
| PROC_LOCK(p); | PROC_LOCK(p); | ||||
| MPASS((td->td_dbgflags & TDB_BOUNDARY) == 0); | MPASS((td->td_dbgflags & TDB_BOUNDARY) == 0); | ||||
| td->td_dbgflags &= ~TDB_USERWR; | td->td_dbgflags &= ~(TDB_USERWR | TDB_SET_SC_RET); | ||||
| if (traced) | if (traced) | ||||
| td->td_dbgflags |= TDB_SCE; | td->td_dbgflags |= TDB_SCE; | ||||
| PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
| } | } | ||||
| if ((td->td_pflags2 & TDP2_UEXTERR) != 0) | if ((td->td_pflags2 & TDP2_UEXTERR) != 0) | ||||
| td->td_pflags2 &= ~TDP2_EXTERR; | td->td_pflags2 &= ~TDP2_EXTERR; | ||||
| error = (p->p_sysent->sv_fetch_syscall_args)(td); | error = (p->p_sysent->sv_fetch_syscall_args)(td); | ||||
| se = sa->callp; | se = sa->callp; | ||||
| #ifdef KTRACE | #ifdef KTRACE | ||||
| if (KTRPOINT(td, KTR_SYSCALL)) | if (KTRPOINT(td, KTR_SYSCALL)) | ||||
| ktrsyscall(sa->code, se->sy_narg, sa->args); | ktrsyscall(sa->code, se->sy_narg, sa->args); | ||||
| #endif | #endif | ||||
| KTR_START4(KTR_SYSC, "syscall", syscallname(p, sa->code), | KTR_START4(KTR_SYSC, "syscall", syscallname(p, sa->code), | ||||
| (uintptr_t)td, "pid:%d", td->td_proc->p_pid, "arg0:%p", sa->args[0], | (uintptr_t)td, "pid:%d", td->td_proc->p_pid, "arg0:%p", sa->args[0], | ||||
| "arg1:%p", sa->args[1], "arg2:%p", sa->args[2]); | "arg1:%p", sa->args[1], "arg2:%p", sa->args[2]); | ||||
Not Done Inline ActionsIf TDB_SET_SC_RET is set, we will log the syscall via KTR and ktrace (but not dtrace) even though it is not executed. IMO it is better not to log anything in this case, i.e., we should skip this tracing. markj: If TDB_SET_SC_RET is set, we will log the syscall via KTR and ktrace (but not dtrace) even… | |||||
Done Inline ActionsTDB_SET_SC_RET is not set at this point, so KTR tracing goes due to the natural flow. But for ktrace records, I thought about it, and I want them both (enter/exit) recorded. When I do the ktrace, I want to see the traced program perception of the kernel actions, and this includes the fake syscalls. In fact, my use case is that I did 'ktrace -di capsicumised-truss -f sh -c 'date;date' and I want to see the values reported to the controlled process, sh in this case, by the tracer (truss). In principle I agree with the sentiment that a marker would be useful in the ktrace records that would flag the fake syscall results. kib: TDB_SET_SC_RET is not set at this point, so KTR tracing goes due to the natural flow.
But for… | |||||
| if (__predict_false(error != 0)) { | if (__predict_false(error != 0)) { | ||||
| td->td_errno = error; | td->td_errno = error; | ||||
| goto retval; | goto retval; | ||||
| } | } | ||||
| if (__predict_false(traced)) { | if (__predict_false(traced)) { | ||||
| PROC_LOCK(p); | PROC_LOCK(p); | ||||
| if (p->p_ptevents & PTRACE_SCE) | if (p->p_ptevents & PTRACE_SCE) | ||||
| ptracestop((td), SIGTRAP, NULL); | ptracestop((td), SIGTRAP, NULL); | ||||
| PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
| if ((td->td_dbgflags & TDB_USERWR) != 0) { | if ((td->td_dbgflags & TDB_SET_SC_RET) != 0) { | ||||
| error = td->td_errno; | |||||
| goto retval; | |||||
| } else if ((td->td_dbgflags & TDB_USERWR) != 0) { | |||||
| /* | /* | ||||
| * Reread syscall number and arguments if debugger | * Reread syscall number and arguments if debugger | ||||
| * modified registers or memory. | * modified registers or memory. | ||||
| */ | */ | ||||
| error = (p->p_sysent->sv_fetch_syscall_args)(td); | error = (p->p_sysent->sv_fetch_syscall_args)(td); | ||||
| se = sa->callp; | se = sa->callp; | ||||
| #ifdef KTRACE | #ifdef KTRACE | ||||
| if (KTRPOINT(td, KTR_SYSCALL)) | if (KTRPOINT(td, KTR_SYSCALL)) | ||||
| ▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | |||||
| retval: | retval: | ||||
| KTR_STOP4(KTR_SYSC, "syscall", syscallname(p, sa->code), | KTR_STOP4(KTR_SYSC, "syscall", syscallname(p, sa->code), | ||||
| (uintptr_t)td, "pid:%d", td->td_proc->p_pid, "error:%d", error, | (uintptr_t)td, "pid:%d", td->td_proc->p_pid, "error:%d", error, | ||||
| "retval0:%#lx", td->td_retval[0], "retval1:%#lx", | "retval0:%#lx", td->td_retval[0], "retval1:%#lx", | ||||
| td->td_retval[1]); | td->td_retval[1]); | ||||
| if (__predict_false(traced)) { | if (__predict_false(traced)) { | ||||
| PROC_LOCK(p); | PROC_LOCK(p); | ||||
| td->td_dbgflags &= ~(TDB_SCE | TDB_BOUNDARY); | td->td_dbgflags &= ~(TDB_SCE | TDB_BOUNDARY | TDB_SET_SC_RET); | ||||
| PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
| } | } | ||||
| (p->p_sysent->sv_set_syscall_retval)(td, error); | (p->p_sysent->sv_set_syscall_retval)(td, error); | ||||
| if (error != 0 && (td->td_pflags2 & TDP2_UEXTERR) != 0) | if (error != 0 && (td->td_pflags2 & TDP2_UEXTERR) != 0) | ||||
| exterr_copyout(td); | exterr_copyout(td); | ||||
| } | } | ||||
| static inline void | static inline void | ||||
| ▲ Show 20 Lines • Show All 82 Lines • Show Last 20 Lines | |||||
How is it possible to have !traced && (td->td_dbgflags & TDB_SET_SC_RET) != 0?