| 55 | #include <security/audit/audit.h> |
| 56 | |
| 57 | static inline void |
| 58 | syscallenter(struct thread *td) |
| 59 | { |
| 60 | struct proc *p; |
| 61 | struct syscall_args *sa; |
| 62 | struct sysent *se; |
| 63 | int error, traced; |
| 64 | bool sy_thr_static; |
| 65 | |
| 66 | VM_CNT_INC(v_syscall); |
| 67 | p = td->td_proc; |
| 68 | sa = &td->td_sa; |
| 69 | |
| 70 | td->td_pticks = 0; |
| 71 | if (__predict_false(td->td_cowgen != p->p_cowgen)) |
| 72 | thread_cow_update(td); |
| 73 | traced = (p->p_flag & P_TRACED) != 0; |
| 74 | if (__predict_false(traced || td->td_dbgflags & TDB_USERWR)) { |
| 75 | PROC_LOCK(p); |
| 76 | td->td_dbgflags &= ~TDB_USERWR; |
| 77 | if (traced) |
| 78 | td->td_dbgflags |= TDB_SCE; |
| 79 | PROC_UNLOCK(p); |
| 80 | } |
| 81 | error = (p->p_sysent->sv_fetch_syscall_args)(td); |
| 82 | se = sa->callp; |
| 83 | #ifdef KTRACE |
| 84 | if (KTRPOINT(td, KTR_SYSCALL)) |
| 85 | ktrsyscall(sa->code, se->sy_narg, sa->args); |
| 86 | #endif |
| 87 | KTR_START4(KTR_SYSC, "syscall", syscallname(p, sa->code), |
| 88 | (uintptr_t)td, "pid:%d", td->td_proc->p_pid, "arg0:%p", sa->args[0], |
| 89 | "arg1:%p", sa->args[1], "arg2:%p", sa->args[2]); |
| 90 | |
| 91 | if (__predict_false(error != 0)) { |
| 92 | td->td_errno = error; |
| 93 | goto retval; |
| 94 | } |
| 95 | |
| 96 | if (__predict_false(traced)) { |
| 97 | PROC_LOCK(p); |
| 98 | if (p->p_ptevents & PTRACE_SCE) |
| 99 | ptracestop((td), SIGTRAP, NULL); |
| 100 | PROC_UNLOCK(p); |
| 101 | |
| 102 | if ((td->td_dbgflags & TDB_USERWR) != 0) { |
| 103 | /* |
| 104 | * Reread syscall number and arguments if debugger |
| 105 | * modified registers or memory. |
| 106 | */ |
| 107 | error = (p->p_sysent->sv_fetch_syscall_args)(td); |
| 108 | se = sa->callp; |
| 109 | #ifdef KTRACE |
| 110 | if (KTRPOINT(td, KTR_SYSCALL)) |
| 111 | ktrsyscall(sa->code, se->sy_narg, sa->args); |
| 112 | #endif |
| 113 | if (error != 0) { |
| 114 | td->td_errno = error; |
no test coverage detected