Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/subr_syscall.c
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | |||||
#ifdef KTRACE | #ifdef KTRACE | ||||
if (KTRPOINT(td, KTR_SYSCALL)) | if (KTRPOINT(td, KTR_SYSCALL)) | ||||
ktrsyscall(sa->code, sa->narg, sa->args); | ktrsyscall(sa->code, sa->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]); | ||||
if (error == 0) { | if (error) | ||||
goto retval; | |||||
STOPEVENT(p, S_SCE, sa->narg); | STOPEVENT(p, S_SCE, sa->narg); | ||||
if (p->p_flag & P_TRACED) { | if (p->p_flag & P_TRACED) { | ||||
kib: I would use the opportunity and style the flags checks, (p_flag & P_TRACED) != 0 etc. | |||||
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) { | if (td->td_dbgflags & TDB_USERWR) { | ||||
/* | /* | ||||
* Reread syscall number and arguments if | * Reread syscall number and arguments if debugger | ||||
* 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); | ||||
#ifdef KTRACE | #ifdef KTRACE | ||||
if (KTRPOINT(td, KTR_SYSCALL)) | if (KTRPOINT(td, KTR_SYSCALL)) | ||||
ktrsyscall(sa->code, sa->narg, sa->args); | ktrsyscall(sa->code, sa->narg, sa->args); | ||||
#endif | #endif | ||||
if (error != 0) | if (error != 0) | ||||
goto retval; | goto retval; | ||||
} | } | ||||
#ifdef CAPABILITY_MODE | #ifdef CAPABILITY_MODE | ||||
/* | /* | ||||
* In capability mode, we only allow access to system calls | * In capability mode, we only allow access to system calls | ||||
* flagged with SYF_CAPENABLED. | * flagged with SYF_CAPENABLED. | ||||
*/ | */ | ||||
if (IN_CAPABILITY_MODE(td) && | if (IN_CAPABILITY_MODE(td) && | ||||
!(sa->callp->sy_flags & SYF_CAPENABLED)) { | !(sa->callp->sy_flags & SYF_CAPENABLED)) { | ||||
error = ECAPMODE; | error = ECAPMODE; | ||||
goto retval; | goto retval; | ||||
} | } | ||||
#endif | #endif | ||||
error = syscall_thread_enter(td, sa->callp); | error = syscall_thread_enter(td, sa->callp); | ||||
if (error != 0) | if (error != 0) | ||||
goto retval; | goto retval; | ||||
#ifdef KDTRACE_HOOKS | #ifdef KDTRACE_HOOKS | ||||
/* Give the syscall:::entry DTrace probe a chance to fire. */ | /* Give the syscall:::entry DTrace probe a chance to fire. */ | ||||
if (__predict_false(systrace_enabled && | if (__predict_false(systrace_enabled && sa->callp->sy_entry != 0)) | ||||
sa->callp->sy_entry != 0)) | |||||
(*systrace_probe_func)(sa, SYSTRACE_ENTRY, 0); | (*systrace_probe_func)(sa, SYSTRACE_ENTRY, 0); | ||||
#endif | #endif | ||||
AUDIT_SYSCALL_ENTER(sa->code, td); | AUDIT_SYSCALL_ENTER(sa->code, td); | ||||
error = (sa->callp->sy_call)(td, sa->args); | error = (sa->callp->sy_call)(td, sa->args); | ||||
AUDIT_SYSCALL_EXIT(error, td); | AUDIT_SYSCALL_EXIT(error, td); | ||||
/* Save the latest error return value. */ | /* Save the latest error return value. */ | ||||
if ((td->td_pflags & TDP_NERRNO) == 0) | if ((td->td_pflags & TDP_NERRNO) == 0) | ||||
td->td_errno = error; | td->td_errno = error; | ||||
#ifdef KDTRACE_HOOKS | #ifdef KDTRACE_HOOKS | ||||
/* Give the syscall:::return DTrace probe a chance to fire. */ | /* Give the syscall:::return DTrace probe a chance to fire. */ | ||||
if (__predict_false(systrace_enabled && | if (__predict_false(systrace_enabled && sa->callp->sy_return != 0)) | ||||
sa->callp->sy_return != 0)) | |||||
(*systrace_probe_func)(sa, SYSTRACE_RETURN, | (*systrace_probe_func)(sa, SYSTRACE_RETURN, | ||||
error ? -1 : td->td_retval[0]); | error ? -1 : td->td_retval[0]); | ||||
#endif | #endif | ||||
syscall_thread_exit(td, sa->callp); | syscall_thread_exit(td, sa->callp); | ||||
} | |||||
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 (traced) { | if (traced) { | ||||
PROC_LOCK(p); | PROC_LOCK(p); | ||||
td->td_dbgflags &= ~TDB_SCE; | td->td_dbgflags &= ~TDB_SCE; | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |
I would use the opportunity and style the flags checks, (p_flag & P_TRACED) != 0 etc.