How would I determine the address of the ulwp_t structure
for the
current thread of a process from a 32-bit i386 executable
looking at a
32-bit executable? (This is in support of a fix for
6593259:
"libdtrace should prefer pid probes to
breakpoints".)
For example, if I compile the following code 64-bit snippet,
I can get
that address from 32-bit or 64-bit executables:
------------------------------------------------------------
--------------------
if ((Pr = Pgrab(pid, NULL, &gret)) == NULL) {
fprintf(stderr, "cannot control process
%dn", pid);
exit(1);
}
if ((lwp = &Pstatus(Pr)->pr_lwp) == NULL) {
fprintf(stderr, "Couldn't grab
pr_lwpn");
exit(1);
}
#if defined(__amd64)
if (Pstatus(Pr)->pr_dmodel == PR_MODEL_LP64) {
addr = lwp->pr_reg[REG_FSBASE];
} else {
addr = lwp->pr_reg[REG_GSBASE];
}
#else
#error "Need to figure this out"
#endif
printf("ulwp_t is 0x%lxn", addr);
------------------------------------------------------------
--------------------
But things don't seem to be as simple as that for the
32-bit/32-bit
case. From usr/src/uts/intel/dtrace/fasttrap_isa.c, we have
this code
for the i386 case (to get the address of the thread-local
scratch
space used for fasttrap probes, which is just after the
ul_self
pointer):
------------------------------------------------------------
--------------------
/*
* Compute the address of the ulwp_t and
step over the
* ul_self pointer. The method used to store
the user-land
* thread pointer is very different on 32-
and 64-bit
* kernels.
*/
[ ... ]
#elif defined(__i386)
addr =
USEGD_GETBASE(&lwp->lwp_pcb.pcb_gsdesc);
addr += sizeof (void *);
#endif
------------------------------------------------------------
--------------------
So we're using pcb_gsdesc, but it doesn't appear that this
is exposed
to userland via libproc (unless I've missed something.)
I've coded something similar to mdb's "::walk
ulwps" that suits my
purpose, but I'd rather be able to determine the ulwp_t for
the
current thread than walk that list. (I'm trying to match
%pc against
the thread-local scratch space, so I have a way of searching
that
list.)
(I haven't come up to speed on understanding the Intel
architecture
segmentation stuff, so I'm hoping someone can help out
here.)
Thanks,
Chad Mynhier
_______________________________________________
dtrace-discuss mailing list
dtrace-discuss opensolaris.org
|