Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Jan 2023 03:23:42 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: a0cfea8c38d6 - stable/13 - Add a thread debugging flag TDB_BOUNDARY
Message-ID:  <202301200323.30K3NgHW042533@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by kib:

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

commit a0cfea8c38d64bddd114804507e5f5a05892b2ca
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-12-01 00:29:35 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-01-20 03:20:40 +0000

    Add a thread debugging flag TDB_BOUNDARY
    
    Tested by:      pho
    
    (cherry picked from commit f0592b3c8dd8e172f0e7165c11371108d4d8838d)
---
 sys/kern/subr_syscall.c | 11 ++++++++---
 sys/kern/subr_trap.c    |  5 ++++-
 sys/sys/proc.h          |  3 ++-
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/sys/kern/subr_syscall.c b/sys/kern/subr_syscall.c
index 8507c5393c01..a61003ec7203 100644
--- a/sys/kern/subr_syscall.c
+++ b/sys/kern/subr_syscall.c
@@ -73,6 +73,7 @@ syscallenter(struct thread *td)
 	traced = (p->p_flag & P_TRACED) != 0;
 	if (__predict_false(traced || td->td_dbgflags & TDB_USERWR)) {
 		PROC_LOCK(p);
+		MPASS((td->td_dbgflags & TDB_BOUNDARY) == 0);
 		td->td_dbgflags &= ~TDB_USERWR;
 		if (traced)
 			td->td_dbgflags |= TDB_SCE;
@@ -201,7 +202,7 @@ syscallenter(struct thread *td)
 	    td->td_retval[1]);
 	if (__predict_false(traced)) {
 		PROC_LOCK(p);
-		td->td_dbgflags &= ~TDB_SCE;
+		td->td_dbgflags &= ~(TDB_SCE | TDB_BOUNDARY);
 		PROC_UNLOCK(p);
 	}
 	(p->p_sysent->sv_set_syscall_retval)(td, error);
@@ -281,9 +282,13 @@ syscallret(struct thread *td)
 		 */
 		if (traced &&
 		    ((td->td_dbgflags & (TDB_FORK | TDB_EXEC)) != 0 ||
-		    (p->p_ptevents & PTRACE_SCX) != 0))
+		    (p->p_ptevents & PTRACE_SCX) != 0)) {
+			MPASS((td->td_dbgflags & TDB_BOUNDARY) == 0);
+			td->td_dbgflags |= TDB_BOUNDARY;
 			ptracestop(td, SIGTRAP, NULL);
-		td->td_dbgflags &= ~(TDB_SCX | TDB_EXEC | TDB_FORK);
+		}
+		td->td_dbgflags &= ~(TDB_SCX | TDB_EXEC | TDB_FORK |
+		    TDB_BOUNDARY);
 		PROC_UNLOCK(p);
 	}
 
diff --git a/sys/kern/subr_trap.c b/sys/kern/subr_trap.c
index c2c27a4d40cb..be5041fe516f 100644
--- a/sys/kern/subr_trap.c
+++ b/sys/kern/subr_trap.c
@@ -214,7 +214,7 @@ ast(struct trapframe *framep)
 {
 	struct thread *td;
 	struct proc *p;
-	int flags, sig;
+	int flags, old_boundary, sig;
 	bool resched_sigs;
 
 	td = curthread;
@@ -330,12 +330,15 @@ ast(struct trapframe *framep)
 	    !SIGISEMPTY(p->p_siglist)) {
 		sigfastblock_fetch(td);
 		PROC_LOCK(p);
+		old_boundary = ~TDB_BOUNDARY | (td->td_dbgflags & TDB_BOUNDARY);
+		td->td_dbgflags |= TDB_BOUNDARY;
 		mtx_lock(&p->p_sigacts->ps_mtx);
 		while ((sig = cursig(td)) != 0) {
 			KASSERT(sig >= 0, ("sig %d", sig));
 			postsig(sig);
 		}
 		mtx_unlock(&p->p_sigacts->ps_mtx);
+		td->td_dbgflags &= old_boundary;
 		PROC_UNLOCK(p);
 		resched_sigs = true;
 	} else {
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index 861f81232927..4ba7522ab5f2 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -487,7 +487,8 @@ do {									\
 #define	TDB_FSTP	0x00001000 /* The thread is PT_ATTACH leader */
 #define	TDB_STEP	0x00002000 /* (x86) PSL_T set for PT_STEP */
 #define	TDB_SSWITCH	0x00004000 /* Suspended in ptracestop */
-#define	TDB_COREDUMPREQ	0x00008000 /* Coredump request */
+#define	TDB_BOUNDARY	0x00008000 /* ptracestop() at boundary */
+#define	TDB_COREDUMPREQ	0x00010000 /* Coredump request */
 
 /*
  * "Private" flags kept in td_pflags:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202301200323.30K3NgHW042533>