diff options
author | kib <kib@FreeBSD.org> | 2012-04-23 20:56:05 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2012-04-23 20:56:05 +0000 |
commit | 0e86d1558cd0404c155a3149b8608b4e51070706 (patch) | |
tree | 383b512796c3eb8d63a882f5bb822eb0cb66afee /sys/kern/kern_proc.c | |
parent | 1f2cd3bf4763138d8ec50379e701611be6912c79 (diff) | |
download | FreeBSD-src-0e86d1558cd0404c155a3149b8608b4e51070706.zip FreeBSD-src-0e86d1558cd0404c155a3149b8608b4e51070706.tar.gz |
Allow for the process information sysctls to accept a thread id in addition
to the process id. It follows the ptrace(2) interface and allows debugging
libraries to use thread ids directly, without slow and verbose conversion
of thread id into pid.
The PGET_NOTID flag is provided to allow a specific sysctl to disallow
this behaviour. All current callers of pget(9) have useful semantic to
operate on tid and do not need this flag.
Reviewed by: jhb, trocini
MFC after: 1 week
Diffstat (limited to 'sys/kern/kern_proc.c')
-rw-r--r-- | sys/kern/kern_proc.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index e6c4c72..cf76576 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -309,6 +309,30 @@ pfind(pid) return (p); } +static struct proc * +pfind_tid(pid_t tid) +{ + struct proc *p; + struct thread *td; + + sx_slock(&allproc_lock); + FOREACH_PROC_IN_SYSTEM(p) { + PROC_LOCK(p); + if (p->p_state == PRS_NEW) { + PROC_UNLOCK(p); + continue; + } + FOREACH_THREAD_IN_PROC(p, td) { + if (td->td_tid == tid) + goto found; + } + PROC_UNLOCK(p); + } +found: + sx_sunlock(&allproc_lock); + return (p); +} + /* * Locate a process group by number. * The caller must hold proctree_lock. @@ -339,7 +363,12 @@ pget(pid_t pid, int flags, struct proc **pp) struct proc *p; int error; - p = pfind(pid); + if (pid <= PID_MAX) + p = pfind(pid); + else if ((flags & PGET_NOTID) == 0) + p = pfind_tid(pid); + else + p = NULL; if (p == NULL) return (ESRCH); if ((flags & PGET_CANSEE) != 0) { |