From 6239ef1d2931ef1c4cce25a02719c60f87f5c6f4 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Fri, 8 Oct 2010 00:44:53 +0000 Subject: [PATCH] Make a thread's address available via the kern proc sysctl, just like the process address. Add "tdaddr" keyword to ps(1) to display this thread address. Distilled from Sandvine's patch set by Mark Johnston. --- bin/ps/keyword.c | 2 ++ bin/ps/ps.1 | 2 ++ sys/kern/kern_proc.c | 1 + sys/sys/user.h | 3 ++- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c index 74165ce52fe0..561b087bf037 100644 --- a/bin/ps/keyword.c +++ b/bin/ps/keyword.c @@ -187,6 +187,8 @@ static VAR var[] = { UINT, UIDFMT, 0}, {"svuid", "SVUID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_svuid), UINT, UIDFMT, 0}, + {"tdaddr", "TDADDR", NULL, 0, kvar, NULL, sizeof(void *) * 2, + KOFF(ki_tdaddr), KPTR, "lx", 0}, {"tdev", "TDEV", NULL, 0, tdev, NULL, 5, 0, CHAR, NULL, 0}, {"tdnam", "TDNAM", NULL, LJUST, tdnam, NULL, COMMLEN, 0, CHAR, NULL, 0}, {"time", "TIME", NULL, USER, cputime, NULL, 9, 0, CHAR, NULL, 0}, diff --git a/bin/ps/ps.1 b/bin/ps/ps.1 index ba1cb18bddcd..2f52584e5128 100644 --- a/bin/ps/ps.1 +++ b/bin/ps/ps.1 @@ -591,6 +591,8 @@ symbolic process state (alias saved gid from a setgid executable .It Cm svuid saved UID from a setuid executable +.It Cm tdaddr +thread address .It Cm tdev control terminal device number .It Cm time diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 4899946a568b..286ba2e609f9 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -842,6 +842,7 @@ fill_kinfo_thread(struct thread *td, struct kinfo_proc *kp, int preferthread) struct proc *p; p = td->td_proc; + kp->ki_tdaddr = td; PROC_LOCK_ASSERT(p, MA_OWNED); thread_lock(td); diff --git a/sys/sys/user.h b/sys/sys/user.h index 50fc96d95e7f..b32ca04989b4 100644 --- a/sys/sys/user.h +++ b/sys/sys/user.h @@ -85,7 +85,7 @@ */ #define KI_NSPARE_INT 9 #define KI_NSPARE_LONG 12 -#define KI_NSPARE_PTR 7 +#define KI_NSPARE_PTR 6 #ifndef _KERNEL #ifndef KINFO_PROC_SIZE @@ -188,6 +188,7 @@ struct kinfo_proc { struct pcb *ki_pcb; /* kernel virtual addr of pcb */ void *ki_kstack; /* kernel virtual addr of stack */ void *ki_udata; /* User convenience pointer */ + struct thread *ki_tdaddr; /* address of thread */ /* * When adding new variables, take space for pointers from the * front of ki_spareptrs, and longs from the end of ki_sparelongs.