From 956d09353b3831c6d61a9eee9ce9572333b1e8ed Mon Sep 17 00:00:00 2001 From: kib Date: Fri, 10 Feb 2012 00:02:13 +0000 Subject: [PATCH] Mark the automatically attached child with PL_FLAG_CHILD in struct lwpinfo flags, for PT_FOLLOWFORK auto-attachment. In collaboration with: Dmitry Mikulin MFC after: 1 week --- sys/kern/kern_fork.c | 2 ++ sys/kern/sys_process.c | 2 ++ sys/sys/proc.h | 1 + sys/sys/ptrace.h | 1 + 4 files changed, 6 insertions(+) diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index 60639c9fcb84..e447c93215a1 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1035,7 +1035,9 @@ fork_return(struct thread *td, struct trapframe *frame) p->p_oppid = p->p_pptr->p_pid; proc_reparent(p, dbg); sx_xunlock(&proctree_lock); + td->td_dbgflags |= TDB_CHILD; ptracestop(td, SIGSTOP); + td->td_dbgflags &= ~TDB_CHILD; } else { /* * ... otherwise clear the request. diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index 451038036da0..2060efe6a337 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -1145,6 +1145,8 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data) pl->pl_flags |= PL_FLAG_FORKED; pl->pl_child_pid = td2->td_dbg_forked; } + if (td2->td_dbgflags & TDB_CHILD) + pl->pl_flags |= PL_FLAG_CHILD; pl->pl_sigmask = td2->td_sigmask; pl->pl_siglist = td2->td_siglist; strcpy(pl->pl_tdname, td2->td_name); diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 9ebfe836ead6..0245e88f9019 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -384,6 +384,7 @@ do { \ process */ #define TDB_STOPATFORK 0x00000080 /* Stop at the return from fork (child only) */ +#define TDB_CHILD 0x00000100 /* New child indicator for ptrace() */ /* * "Private" flags kept in td_pflags: diff --git a/sys/sys/ptrace.h b/sys/sys/ptrace.h index 2583d59466d0..8a02495e6ec1 100644 --- a/sys/sys/ptrace.h +++ b/sys/sys/ptrace.h @@ -107,6 +107,7 @@ struct ptrace_lwpinfo { #define PL_FLAG_EXEC 0x10 /* exec(2) succeeded */ #define PL_FLAG_SI 0x20 /* siginfo is valid */ #define PL_FLAG_FORKED 0x40 /* new child */ +#define PL_FLAG_CHILD 0x80 /* I am from child */ sigset_t pl_sigmask; /* LWP signal mask */ sigset_t pl_siglist; /* LWP pending signal */ struct __siginfo pl_siginfo; /* siginfo for signal */