Index: sys/amd64/amd64/trap.c =================================================================== --- sys/amd64/amd64/trap.c +++ sys/amd64/amd64/trap.c @@ -829,16 +829,18 @@ } int -cpu_fetch_syscall_args(struct thread *td, struct syscall_args *sa) +cpu_fetch_syscall_args(struct thread *td) { struct proc *p; struct trapframe *frame; register_t *argp; + struct syscall_args *sa; caddr_t params; int reg, regcnt, error; p = td->td_proc; frame = td->td_frame; + sa = &td->td_sa; reg = 0; regcnt = 6; @@ -889,7 +891,6 @@ void amd64_syscall(struct thread *td, int traced) { - struct syscall_args sa; int error; ksiginfo_t ksi; @@ -899,7 +900,7 @@ /* NOT REACHED */ } #endif - error = syscallenter(td, &sa); + error = syscallenter(td); /* * Traced syscall. @@ -915,15 +916,16 @@ KASSERT(PCB_USER_FPU(td->td_pcb), ("System call %s returning with kernel FPU ctx leaked", - syscallname(td->td_proc, sa.code))); + syscallname(td->td_proc, td->td_sa.code))); KASSERT(td->td_pcb->pcb_save == get_pcb_user_save_td(td), ("System call %s returning with mangled pcb_save", - syscallname(td->td_proc, sa.code))); + syscallname(td->td_proc, td->td_sa.code))); KASSERT(td->td_md.md_invl_gen.gen == 0, ("System call %s returning with leaked invl_gen %lu", - syscallname(td->td_proc, sa.code), td->td_md.md_invl_gen.gen)); + syscallname(td->td_proc, td->td_sa.code), + td->td_md.md_invl_gen.gen)); - syscallret(td, error, &sa); + syscallret(td, error); /* * If the user-supplied value of %rip is not a canonical Index: sys/amd64/cloudabi32/cloudabi32_sysvec.c =================================================================== --- sys/amd64/cloudabi32/cloudabi32_sysvec.c +++ sys/amd64/cloudabi32/cloudabi32_sysvec.c @@ -90,11 +90,15 @@ } static int -cloudabi32_fetch_syscall_args(struct thread *td, struct syscall_args *sa) +cloudabi32_fetch_syscall_args(struct thread *td) { - struct trapframe *frame = td->td_frame; + struct trapframe *frame; + struct syscall_args *sa; int error; + frame = td->td_frame; + sa = &td->td_sa; + /* Obtain system call number. */ sa->code = frame->tf_rax; if (sa->code >= CLOUDABI32_SYS_MAXSYSCALL) Index: sys/amd64/cloudabi64/cloudabi64_sysvec.c =================================================================== --- sys/amd64/cloudabi64/cloudabi64_sysvec.c +++ sys/amd64/cloudabi64/cloudabi64_sysvec.c @@ -87,9 +87,13 @@ } static int -cloudabi64_fetch_syscall_args(struct thread *td, struct syscall_args *sa) +cloudabi64_fetch_syscall_args(struct thread *td) { - struct trapframe *frame = td->td_frame; + struct trapframe *frame; + struct syscall_args *sa; + + frame = td->td_frame; + sa = &td->td_sa; /* Obtain system call number. */ sa->code = frame->tf_rax; Index: sys/amd64/ia32/ia32_syscall.c =================================================================== --- sys/amd64/ia32/ia32_syscall.c +++ sys/amd64/ia32/ia32_syscall.c @@ -105,16 +105,18 @@ } int -ia32_fetch_syscall_args(struct thread *td, struct syscall_args *sa) +ia32_fetch_syscall_args(struct thread *td) { struct proc *p; struct trapframe *frame; + struct syscall_args *sa; caddr_t params; u_int32_t args[8], tmp; int error, i; p = td->td_proc; frame = td->td_frame; + sa = &td->td_sa; params = (caddr_t)frame->tf_rsp + sizeof(u_int32_t); sa->code = frame->tf_rax; @@ -175,7 +177,6 @@ ia32_syscall(struct trapframe *frame) { struct thread *td; - struct syscall_args sa; register_t orig_tf_rflags; int error; ksiginfo_t ksi; @@ -184,7 +185,7 @@ td = curthread; td->td_frame = frame; - error = syscallenter(td, &sa); + error = syscallenter(td); /* * Traced syscall. @@ -198,7 +199,7 @@ trapsignal(td, &ksi); } - syscallret(td, error, &sa); + syscallret(td, error); } static void Index: sys/amd64/linux/linux_sysvec.c =================================================================== --- sys/amd64/linux/linux_sysvec.c +++ sys/amd64/linux/linux_sysvec.c @@ -126,7 +126,7 @@ static void linux_vdso_install(void *param); static void linux_vdso_deinstall(void *param); static void linux_set_syscall_retval(struct thread *td, int error); -static int linux_fetch_syscall_args(struct thread *td, struct syscall_args *sa); +static int linux_fetch_syscall_args(struct thread *td); static void linux_exec_setregs(struct thread *td, struct image_params *imgp, u_long stack); static int linux_vsyscall(struct thread *td); @@ -217,13 +217,15 @@ } static int -linux_fetch_syscall_args(struct thread *td, struct syscall_args *sa) +linux_fetch_syscall_args(struct thread *td) { struct proc *p; struct trapframe *frame; + struct syscall_args *sa; p = td->td_proc; frame = td->td_frame; + sa = &td->td_sa; sa->args[0] = frame->tf_rdi; sa->args[1] = frame->tf_rsi; Index: sys/amd64/linux32/linux32_sysvec.c =================================================================== --- sys/amd64/linux32/linux32_sysvec.c +++ sys/amd64/linux32/linux32_sysvec.c @@ -725,13 +725,15 @@ } static int -linux32_fetch_syscall_args(struct thread *td, struct syscall_args *sa) +linux32_fetch_syscall_args(struct thread *td) { struct proc *p; struct trapframe *frame; + struct syscall_args *sa; p = td->td_proc; frame = td->td_frame; + sa = &td->td_sa; sa->args[0] = frame->tf_rbx; sa->args[1] = frame->tf_rcx; Index: sys/compat/ia32/ia32_util.h =================================================================== --- sys/compat/ia32/ia32_util.h +++ sys/compat/ia32/ia32_util.h @@ -50,7 +50,7 @@ #define IA32_MAXVMEM 0 /* Unlimited */ struct syscall_args; -int ia32_fetch_syscall_args(struct thread *td, struct syscall_args *sa); +int ia32_fetch_syscall_args(struct thread *td); void ia32_set_syscall_retval(struct thread *, int); void ia32_fixlimit(struct rlimit *rl, int which); Index: sys/i386/cloudabi32/cloudabi32_sysvec.c =================================================================== --- sys/i386/cloudabi32/cloudabi32_sysvec.c +++ sys/i386/cloudabi32/cloudabi32_sysvec.c @@ -85,11 +85,15 @@ } static int -cloudabi32_fetch_syscall_args(struct thread *td, struct syscall_args *sa) +cloudabi32_fetch_syscall_args(struct thread *td) { - struct trapframe *frame = td->td_frame; + struct trapframe *frame; + struct syscall_args *sa; int error; + frame = td->td_frame; + sa = &td->td_sa; + /* Obtain system call number. */ sa->code = frame->tf_eax; if (sa->code >= CLOUDABI32_SYS_MAXSYSCALL) Index: sys/i386/i386/trap.c =================================================================== --- sys/i386/i386/trap.c +++ sys/i386/i386/trap.c @@ -1012,16 +1012,18 @@ } int -cpu_fetch_syscall_args(struct thread *td, struct syscall_args *sa) +cpu_fetch_syscall_args(struct thread *td) { struct proc *p; struct trapframe *frame; + struct syscall_args *sa; caddr_t params; long tmp; int error; p = td->td_proc; frame = td->td_frame; + sa = &td->td_sa; params = (caddr_t)frame->tf_esp + sizeof(int); sa->code = frame->tf_eax; @@ -1082,7 +1084,6 @@ syscall(struct trapframe *frame) { struct thread *td; - struct syscall_args sa; register_t orig_tf_eflags; int error; ksiginfo_t ksi; @@ -1099,7 +1100,7 @@ td = curthread; td->td_frame = frame; - error = syscallenter(td, &sa); + error = syscallenter(td); /* * Traced syscall. @@ -1115,10 +1116,10 @@ KASSERT(PCB_USER_FPU(td->td_pcb), ("System call %s returning with kernel FPU ctx leaked", - syscallname(td->td_proc, sa.code))); + syscallname(td->td_proc, td->td_sa.code))); KASSERT(td->td_pcb->pcb_save == get_pcb_user_save_td(td), ("System call %s returning with mangled pcb_save", - syscallname(td->td_proc, sa.code))); + syscallname(td->td_proc, td->td_sa.code))); - syscallret(td, error, &sa); + syscallret(td, error); } Index: sys/i386/linux/linux_sysvec.c =================================================================== --- sys/i386/linux/linux_sysvec.c +++ sys/i386/linux/linux_sysvec.c @@ -850,13 +850,15 @@ } static int -linux_fetch_syscall_args(struct thread *td, struct syscall_args *sa) +linux_fetch_syscall_args(struct thread *td) { struct proc *p; struct trapframe *frame; + struct syscall_args *sa; p = td->td_proc; frame = td->td_frame; + sa = &td->td_sa; sa->code = frame->tf_eax; sa->args[0] = frame->tf_ebx; Index: sys/kern/init_main.c =================================================================== --- sys/kern/init_main.c +++ sys/kern/init_main.c @@ -360,8 +360,7 @@ #endif static int -null_fetch_syscall_args(struct thread *td __unused, - struct syscall_args *sa __unused) +null_fetch_syscall_args(struct thread *td __unused) { panic("null_fetch_syscall_args"); Index: sys/kern/kern_fork.c =================================================================== --- sys/kern/kern_fork.c +++ sys/kern/kern_fork.c @@ -1099,7 +1099,7 @@ */ PROC_LOCK(p); td->td_dbgflags |= TDB_SCX; - _STOPEVENT(p, S_SCX, td->td_dbg_sc_code); + _STOPEVENT(p, S_SCX, td->td_sa.code); if ((p->p_ptevents & PTRACE_SCX) != 0 || (td->td_dbgflags & TDB_BORN) != 0) ptracestop(td, SIGTRAP, NULL); Index: sys/kern/kern_sig.c =================================================================== --- sys/kern/kern_sig.c +++ sys/kern/kern_sig.c @@ -150,6 +150,10 @@ SYSCTL_INT(_kern_sigqueue, OID_AUTO, alloc_fail, CTLFLAG_RD, &signal_alloc_fail, 0, "signals failed to be allocated"); +static int kern_lognosys = 0; +SYSCTL_INT(_kern, OID_AUTO, lognosys, CTLFLAG_RWTUN, &kern_lognosys, 0, + "Log invalid syscalls"); + SYSINIT(signal, SI_SUB_P1003_1B, SI_ORDER_FIRST+3, sigqueue_start, NULL); /* @@ -3568,11 +3572,16 @@ int nosys(struct thread *td, struct nosys_args *args) { - struct proc *p = td->td_proc; + struct proc *p; + + p = td->td_proc; PROC_LOCK(p); tdsignal(td, SIGSYS); PROC_UNLOCK(p); + if (kern_lognosys) + uprintf("pid %d comm %s: nosys %d\n", p->p_pid, p->p_comm, + td->td_sa.code); return (ENOSYS); } Index: sys/kern/kern_thread.c =================================================================== --- sys/kern/kern_thread.c +++ sys/kern/kern_thread.c @@ -80,9 +80,9 @@ "struct thread KBI td_flags"); _Static_assert(offsetof(struct thread, td_pflags) == 0xfc, "struct thread KBI td_pflags"); -_Static_assert(offsetof(struct thread, td_frame) == 0x410, +_Static_assert(offsetof(struct thread, td_frame) == 0x408, "struct thread KBI td_frame"); -_Static_assert(offsetof(struct thread, td_emuldata) == 0x4b8, +_Static_assert(offsetof(struct thread, td_emuldata) == 0x4b0, "struct thread KBI td_emuldata"); _Static_assert(offsetof(struct proc, p_flag) == 0xb0, "struct proc KBI p_flag"); @@ -100,9 +100,9 @@ "struct thread KBI td_flags"); _Static_assert(offsetof(struct thread, td_pflags) == 0xa4, "struct thread KBI td_pflags"); -_Static_assert(offsetof(struct thread, td_frame) == 0x2c8, +_Static_assert(offsetof(struct thread, td_frame) == 0x2c0, "struct thread KBI td_frame"); -_Static_assert(offsetof(struct thread, td_emuldata) == 0x314, +_Static_assert(offsetof(struct thread, td_emuldata) == 0x30c, "struct thread KBI td_emuldata"); _Static_assert(offsetof(struct proc, p_flag) == 0x68, "struct proc KBI p_flag"); Index: sys/kern/subr_syscall.c =================================================================== --- sys/kern/subr_syscall.c +++ sys/kern/subr_syscall.c @@ -53,13 +53,15 @@ #include static inline int -syscallenter(struct thread *td, struct syscall_args *sa) +syscallenter(struct thread *td) { struct proc *p; + struct syscall_args *sa; int error, traced; VM_CNT_INC(v_syscall); p = td->td_proc; + sa = &td->td_sa; td->td_pticks = 0; if (td->td_cowgen != p->p_cowgen) @@ -72,7 +74,7 @@ td->td_dbgflags |= TDB_SCE; PROC_UNLOCK(p); } - error = (p->p_sysent->sv_fetch_syscall_args)(td, sa); + error = (p->p_sysent->sv_fetch_syscall_args)(td); #ifdef KTRACE if (KTRPOINT(td, KTR_SYSCALL)) ktrsyscall(sa->code, sa->narg, sa->args); @@ -86,8 +88,6 @@ STOPEVENT(p, S_SCE, sa->narg); if (p->p_flag & P_TRACED) { PROC_LOCK(p); - td->td_dbg_sc_code = sa->code; - td->td_dbg_sc_narg = sa->narg; if (p->p_ptevents & PTRACE_SCE) ptracestop((td), SIGTRAP, NULL); PROC_UNLOCK(p); @@ -97,11 +97,7 @@ * Reread syscall number and arguments if * debugger modified registers or memory. */ - error = (p->p_sysent->sv_fetch_syscall_args)(td, sa); - PROC_LOCK(p); - td->td_dbg_sc_code = sa->code; - td->td_dbg_sc_narg = sa->narg; - PROC_UNLOCK(p); + error = (p->p_sysent->sv_fetch_syscall_args)(td); #ifdef KTRACE if (KTRPOINT(td, KTR_SYSCALL)) ktrsyscall(sa->code, sa->narg, sa->args); @@ -163,9 +159,10 @@ } static inline void -syscallret(struct thread *td, int error, struct syscall_args *sa) +syscallret(struct thread *td, int error) { struct proc *p, *p2; + struct syscall_args *sa; ksiginfo_t ksi; int traced, error1; @@ -173,6 +170,7 @@ ("fork() did not clear TDP_FORKING upon completion")); p = td->td_proc; + sa = &td->td_sa; if ((trap_enotcap || (p->p_flag2 & P2_TRAPCAP) != 0) && IN_CAPABILITY_MODE(td)) { error1 = (td->td_pflags & TDP_NERRNO) == 0 ? error : Index: sys/kern/sys_process.c =================================================================== --- sys/kern/sys_process.c +++ sys/kern/sys_process.c @@ -586,6 +586,7 @@ struct ptrace_lwpinfo32 pl32; struct ptrace_vm_entry32 pve32; #endif + char args[nitems(td->td_sa.args) * sizeof(register_t)]; int ptevents; } r; void *addr; @@ -606,6 +607,7 @@ case PT_GETFPREGS: case PT_GETDBREGS: case PT_LWPINFO: + case PT_GET_SC_ARGS: break; case PT_SETREGS: error = COPYIN(uap->addr, &r.reg, sizeof r.reg); @@ -663,6 +665,10 @@ /* NB: The size in uap->data is validated in kern_ptrace(). */ error = copyout(&r.pl, uap->addr, uap->data); break; + case PT_GET_SC_ARGS: + error = copyout(td->td_sa.args, uap->addr, MIN(uap->data, + sizeof(r.args))); + break; } return (error); @@ -739,6 +745,7 @@ case PT_GET_EVENT_MASK: case PT_SET_EVENT_MASK: case PT_DETACH: + case PT_GET_SC_ARGS: sx_xlock(&proctree_lock); proctree_locked = 1; break; @@ -1009,6 +1016,28 @@ p->p_pid, p->p_ptevents, tmp); p->p_ptevents = tmp; break; + + case PT_GET_SC_ARGS: + CTR1(KTR_PTRACE, "PT_GET_SC_ARGS: pid %d", p->p_pid); + if ((td2->td_dbgflags & (TDB_SCE | TDB_SCX)) == 0 +#ifdef COMPAT_FREEBSD32 + || !safe +#endif + ) { + error = EINVAL; + break; + } + bzero(addr, sizeof(td2->td_sa.args)); +#ifdef COMPAT_FREEBSD32 + if (wrap32) + for (num = 0; num < nitems(td2->td_sa.args); num++) + ((uint32_t *)addr)[num] = (uint32_t) + td2->td_sa.args[num]; + else +#endif + bcopy(td2->td_sa.args, addr, td2->td_sa.narg * + sizeof(register_t)); + break; case PT_STEP: case PT_CONTINUE: @@ -1347,8 +1376,8 @@ pl->pl_siglist = td2->td_siglist; strcpy(pl->pl_tdname, td2->td_name); if ((td2->td_dbgflags & (TDB_SCE | TDB_SCX)) != 0) { - pl->pl_syscall_code = td2->td_dbg_sc_code; - pl->pl_syscall_narg = td2->td_dbg_sc_narg; + pl->pl_syscall_code = td2->td_sa.code; + pl->pl_syscall_narg = td2->td_sa.narg; } else { pl->pl_syscall_code = 0; pl->pl_syscall_narg = 0; Index: sys/sys/proc.h =================================================================== --- sys/sys/proc.h +++ sys/sys/proc.h @@ -142,6 +142,7 @@ * j - locked by proc slock * k - only accessed by curthread * k*- only accessed by curthread and from an interrupt + * kx- only accessed by curthread and by debugger * l - the attaching proc or attaching proc parent * m - Giant * n - not locked, lazy @@ -296,8 +297,6 @@ u_char td_pri_class; /* (t) Scheduling class. */ u_char td_user_pri; /* (t) User pri from estcpu and nice. */ u_char td_base_user_pri; /* (t) Base user pri */ - u_int td_dbg_sc_code; /* (c) Syscall code to debugger. */ - u_int td_dbg_sc_narg; /* (c) Syscall arg count to debugger.*/ uintptr_t td_rb_list; /* (k) Robust list head. */ uintptr_t td_rbp_list; /* (k) Robust priv list head. */ uintptr_t td_rb_inact; /* (k) Current in-action mutex loc. */ @@ -342,6 +341,7 @@ int td_lastcpu; /* (t) Last cpu we were on. */ int td_oncpu; /* (t) Which cpu we are on. */ void *td_lkpi_task; /* LinuxKPI task struct pointer */ + struct syscall_args td_sa; /* (kx) */ }; struct thread0_storage { @@ -1053,7 +1053,7 @@ void cpu_exit(struct thread *); void exit1(struct thread *, int, int) __dead2; void cpu_copy_thread(struct thread *td, struct thread *td0); -int cpu_fetch_syscall_args(struct thread *td, struct syscall_args *sa); +int cpu_fetch_syscall_args(struct thread *td); void cpu_fork(struct thread *, struct proc *, struct thread *, int); void cpu_fork_kthread_handler(struct thread *, void (*)(void *), void *); void cpu_set_syscall_retval(struct thread *, int); Index: sys/sys/ptrace.h =================================================================== --- sys/sys/ptrace.h +++ sys/sys/ptrace.h @@ -69,6 +69,8 @@ #define PT_GET_EVENT_MASK 25 /* get mask of optional events */ #define PT_SET_EVENT_MASK 26 /* set mask of optional events */ +#define PT_GET_SC_ARGS 27 /* fetch syscall args */ + #define PT_GETREGS 33 /* get general-purpose registers */ #define PT_SETREGS 34 /* set general-purpose registers */ #define PT_GETFPREGS 35 /* get floating-point registers */ Index: sys/sys/sysent.h =================================================================== --- sys/sys/sysent.h +++ sys/sys/sysent.h @@ -119,8 +119,7 @@ u_long *sv_maxssiz; u_int sv_flags; void (*sv_set_syscall_retval)(struct thread *, int); - int (*sv_fetch_syscall_args)(struct thread *, struct - syscall_args *); + int (*sv_fetch_syscall_args)(struct thread *); const char **sv_syscallnames; vm_offset_t sv_timekeep_base; vm_offset_t sv_shared_page_base;