ptrace(2): expand ability to fetch syscall parameters

(cherry picked from commit fd5bc306ff3d8f908f36703d6ab714322f9f3c75)
This commit is contained in:
Konstantin Belousov 2025-03-20 03:52:29 +02:00
parent c07ea8aefd
commit fdbf48835d
2 changed files with 11 additions and 5 deletions

View file

@ -345,6 +345,14 @@ ast_sig(struct thread *td, int tda)
* the postsig() loop was performed.
*/
sigfastblock_setpend(td, resched_sigs);
/*
* Clear td_sa.code: signal to ptrace that syscall arguments
* are unavailable after this point. This AST handler is the
* last chance for ptracestop() to signal the tracer before
* the tracee returns to userspace.
*/
td->td_sa.code = 0;
}
static void

View file

@ -1174,7 +1174,8 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
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
if (((td2->td_dbgflags & (TDB_SCE | TDB_SCX)) == 0 &&
td2->td_sa.code == 0)
#ifdef COMPAT_FREEBSD32
|| (wrap32 && !safe)
#endif
@ -1517,12 +1518,9 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data)
pl->pl_sigmask = td2->td_sigmask;
pl->pl_siglist = td2->td_siglist;
strcpy(pl->pl_tdname, td2->td_name);
if ((td2->td_dbgflags & (TDB_SCE | TDB_SCX)) != 0) {
if (td2->td_sa.code != 0) {
pl->pl_syscall_code = td2->td_sa.code;
pl->pl_syscall_narg = td2->td_sa.callp->sy_narg;
} else {
pl->pl_syscall_code = 0;
pl->pl_syscall_narg = 0;
}
CTR6(KTR_PTRACE,
"PT_LWPINFO: tid %d (pid %d) event %d flags %#x child pid %d syscall %d",