git: ecc662c749b1 - main - PT_ATTACH: do not interrupt interruptible sleeps

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Thu, 17 Apr 2025 20:45:05 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=ecc662c749b11434c63a0d3578fc40df6b4798ec

commit ecc662c749b11434c63a0d3578fc40df6b4798ec
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-04-16 00:09:44 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-04-17 20:33:47 +0000

    PT_ATTACH: do not interrupt interruptible sleeps
    
    Handle the first SIGSTOP from the PT_ATTACH specially: instead of waking
    up some thread in the target process, execute sig_suspend_threads() in
    the debugger. This is equivalent to the action of the xthread, except
    that all threads are suspended without interruption.
    
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      2 weeks
    Differential revision:  https://reviews.freebsd.org/D49678
---
 sys/kern/kern_sig.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 520577961c3a..ba3b04ac6e22 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -2365,6 +2365,15 @@ tdsendsignal(struct proc *p, struct thread *td, int sig, ksiginfo_t *ksi)
 	if (prop & SIGPROP_CONT)
 		sigqueue_delete_stopmask_proc(p);
 	else if (prop & SIGPROP_STOP) {
+		if ((p->p_flag & P_TRACED) != 0 &&
+		    (p->p_flag2 & P2_PTRACE_FSTP) != 0) {
+			td->td_dbgflags |= TDB_FSTP;
+			PROC_SLOCK(p);
+			sig_handle_first_stop(td, p, sig, true);
+			PROC_SUNLOCK(p);
+			return (0);
+		}
+
 		/*
 		 * If sending a tty stop signal to a member of an orphaned
 		 * process group, discard the signal here if the action
@@ -3345,7 +3354,8 @@ issignal(struct thread *td)
 			}
 		}
 
-		if ((p->p_flag & (P_TRACED | P_PPTRACE)) == P_TRACED &&
+		if (false &&
+		    (p->p_flag & (P_TRACED | P_PPTRACE)) == P_TRACED &&
 		    (p->p_flag2 & P2_PTRACE_FSTP) != 0 &&
 		    SIGISMEMBER(sigpending, SIGSTOP)) {
 			/*