Re: PR_GetThreadID() fails with SEGV

Jonathan Leighton <[email protected]> Thu, 25 Jun 2009 14:27:54 -0400
Newsgroups gmane.comp.mozilla.devel.nspr
Organization University of Delaware
Message-ID <[email protected]>
Julien R Pierre - Sun Microsystems wrote:
> Jon,
> 
> Jon Leighton wrote:
>> I'm using NSPR 4.8 on Solaris 5.10, and OpenSolaris 5.11, and if I 
>> call PR_GetThreadID(PR_GetCurrentThread()), it fails with SEGV.  The 
>> same code works fine on a number of other platforms.  Is there an 
>> issue with PR_GetThreadID() on Solaris/OpenSolaris, or something 
>> different I need to do?  Thanks for any help.
>>
>> - Jon
> 
> I just tried the following on Solaris 10 x86 (32 bits). I experienced no 
> problem.
> 
>         PRThread* prt = PR_GetCurrentThread();
>         PRUint32 tid;
>         tid = PR_GetThreadID(prt);
>         printf("Thread id : %d.\n", tid);
> 
> Please provide a crash stack. Even for a deprecated function, I would 
> not expect a crash. Are you passing a valid PRThread* pointer ?

Hi Julien -

I haven't yet tried to create a simple case where this fails, but where 
I ran into the problem was in NSPR 4.8's socket.c test code.  Line 501 is:

         DPRINTF(("TCP_Server: Created Serve_Client = 0x%lx\n", t));

If I replace "t" with "PR_GetThreadID(t)" I get a SEGV on line 1097 of 
ptthread.c.  I found this to happen in Solaris 5.10 and OpenSolaris 
5.11, but not in FreeBSD 7.2, Linux 2.6.28, or Mac OS X 10.5.6 (Intel). 
  Below is the output from dbx on Solarix 5.10.

- Jon

.
.
.
t@2 (l@2) signal SEGV (no mapping at the fault address) in 
PR_GetThreadID at line 1097 in file "ptthread.c"
  1097       return (PRUint32)thred->id;  /* and I don't know what they 
will do with it */
(dbx) where
current thread: t@2
=>[1] PR_GetThreadID(thred = 0xa), line 1097 in "ptthread.c"
   [2] TCP_Server(arg = 0x8068af0), line 501 in "socket.c"
   [3] _pt_root(arg = 0x806b408), line 228 in "ptthread.c"
   [4] _thr_setup(0xfea50200), at 0xfeea7055
   [5] _lwp_start(0x1, 0xfeb5efac, 0x8052a93, 0xa, 0x0, 0xfea50200), at 
0xfeea7340
(dbx)