Solaris fcntl CPU/Lock update

Pierre Belanger belanger at pobox.com
Wed Feb 5 05:02:25 GMT 2003


Hello all,

Andrew, true GDB is thread aware but I think last time I used
it (back in ~ 1998) I was writing a multi-threaded application
and I really remember like if it was yesterday: GDB was not
thread aware at that time. I'm glad to hear it's now thread
aware!

I found the following if it can help us debug this thing
with Jeff Mandel (the original poster).

Debugging multi-threaded applications with GDB...

http://www-es.fernuni-hagen.de/cgi-bin/info2html?(gdb)Threads

Like Andrew suggested -- I ran nm on libthread.so. I almost
felt off my chair!

 From libthread.so
[905]   |    111016|      84|FUNC |GLOB |0    |9      |usleep

There exists under Solaris a usleep in libthread.so !!!

Of course, as well in libc.so.

 From libc.so :
usleep [3265]  |    635736|      40|FUNC |WEAK |0    |9      |usleep

This here :

#0  <signal handler called>
#1  0xfecd9794 in __sigprocmask () from /usr/lib/libthread.so.1
#2  0xfecce148 in _sigon () from /usr/lib/libthread.so.1
#3  0xfecd05bc in thr_sigsetmask () from /usr/lib/libthread.so.1
#3  0xfecd05bc in thr_sigsetmask () from /usr/lib/libthread.so.1
#4  <signal handler called>
#5  0x65646974 in ?? ()
#6  0xfecdb1f0 in usleep () from /usr/lib/libthread.so.1

The "called signal handler" of "usleep" *in* libpthread.so.1
uses thr_sigsetmask and the above funtions, for the only
reason that some LDAP library needs libthread.so???

I can't go any further now, ho yes I can just before I was
going to hit send ;-)  Here's what I did:

After "Hello World" ...

int main (int argc, char **argv){usleep(1);}

Compiled using "gcc sleeping.c" and after I compiled using
"gcc sleeping.c -lthread". HAHA!!! Here's the results.


1) Without linking with libhread:


/1:     execve("a.out", 0xFFBEFB0C, 0xFFBEFB14)  argc = 1
/1:     mmap(0x00000000, 8192, PROT_READ|PROT_WRITE|PROT_EXEC, 
MAP_PRIVATE|MAP_ANON, -1, 0) = 0xFF3A0000
/1:     resolvepath("/usr/lib/ld.so.1", "/usr/lib/ld.so.1", 1023) = 16
/1:     open("/var/ld/ld.config", O_RDONLY)             Err#2 ENOENT
/1:     stat("/usr/lib/libc.so.1", 0xFFBEF234)          = 0
/1:     open("/usr/lib/libc.so.1", O_RDONLY)            = 3
/1:     fstat(3, 0xFFBEF234)                            = 0
/1:     mmap(0x00000000, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 
0xFF390000
/1:     mmap(0x00000000, 802816, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) 
= 0xFF280000
/1:     mmap(0xFF33C000, 24748, PROT_READ|PROT_WRITE|PROT_EXEC, 
MAP_PRIVATE|MAP_FIXED, 3, 704512) = 0xFF33C000
/1:     munmap(0xFF32C000, 65536)                       = 0
/1:     memcntl(0xFF280000, 113448, MC_ADVISE, MADV_WILLNEED, 0, 0) = 0
/1:     close(3)                                        = 0
/1:     stat("/usr/lib/libdl.so.1", 0xFFBEF234)         = 0
/1:     open("/usr/lib/libdl.so.1", O_RDONLY)           = 3
/1:     fstat(3, 0xFFBEF234)                            = 0
/1:     mmap(0xFF390000, 8192, PROT_READ|PROT_EXEC, 
MAP_PRIVATE|MAP_FIXED, 3, 0) = 0xFF390000
/1:     close(3)                                        = 0
/1:     stat("/usr/platform/SUNW,Ultra-2/lib/libc_psr.so.1", 0xFFBEF0C4) = 0
/1:     open("/usr/platform/SUNW,Ultra-2/lib/libc_psr.so.1", O_RDONLY) = 3
/1:     fstat(3, 0xFFBEF0C4)                            = 0
/1:     mmap(0x00000000, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 
0xFF380000
/1:     mmap(0x00000000, 16384, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) 
= 0xFF370000
/1:     close(3)                                        = 0
/1:     munmap(0xFF380000, 8192)                        = 0
/1:     alarm(0)                                        = 0
/1:     setitimer(ITIMER_REAL, 0xFFBEFA28, 0xFFBEFA18)  = 0
/1:     sigaction(SIGALRM, 0xFFBEF928, 0xFFBEF9D8)      = 0
/1:     sigfillset(0xFF3428B8)                          = 0
/1:     sigprocmask(SIG_BLOCK, 0xFFBEF9C8, 0xFFBEF9B8)  = 0
/1:     setitimer(ITIMER_REAL, 0xFFBEFA28, 0x00000000)  = 0
/1:         Received signal #14, SIGALRM, in sigsuspend() [caught]
/1:     sigsuspend(0xFFBEF9A8)                          Err#4 EINTR
/1:     setcontext(0xFFBEF690)
/1:     sigaction(SIGALRM, 0xFFBEF928, 0x00000000)      = 0
/1:     sigprocmask(SIG_UNBLOCK, 0xFFBEF9C8, 0x00000000) = 0
/1:     setitimer(ITIMER_REAL, 0xFFBEFA18, 0x00000000)  = 0
/1:     llseek(0, 0, SEEK_CUR)                          = 38123
/1:     _exit(0)



2) Compiled with -lthread ... hard to beleive, 5 threads
    to make a simple "usleep(1)" system call!!!

/1:     execve("ta.out", 0xFFBEFB0C, 0xFFBEFB14)  argc = 1
/1:     mmap(0x00000000, 8192, PROT_READ|PROT_WRITE|PROT_EXEC, 
MAP_PRIVATE|MAP_ANON, -1, 0) = 0xFF3A0000
/1:     resolvepath("/usr/lib/ld.so.1", "/usr/lib/ld.so.1", 1023) = 16
/1:     open("/var/ld/ld.config", O_RDONLY)             Err#2 ENOENT
/1:     stat("/usr/lib/libthread.so.1", 0xFFBEF234)     = 0
/1:     open("/usr/lib/libthread.so.1", O_RDONLY)       = 3
/1:     fstat(3, 0xFFBEF234)                            = 0
/1:     mmap(0x00000000, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 
0xFF390000
/1:     mmap(0x00000000, 245760, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) 
= 0xFF350000
/1:     mmap(0xFF37E000, 6644, PROT_READ|PROT_WRITE|PROT_EXEC, 
MAP_PRIVATE|MAP_FIXED, 3, 122880) = 0xFF37E000
/1:     mmap(0xFF380000, 45704, PROT_READ|PROT_WRITE|PROT_EXEC, 
MAP_PRIVATE|MAP_FIXED|MAP_ANON, -1, 0) = 0xFF380000
/1:     munmap(0xFF36E000, 65536)                       = 0
/1:     memcntl(0xFF350000, 31224, MC_ADVISE, MADV_WILLNEED, 0, 0) = 0
/1:     close(3)                                        = 0
/1:     stat("/usr/lib/libc.so.1", 0xFFBEF234)          = 0
/1:     open("/usr/lib/libc.so.1", O_RDONLY)            = 3
/1:     fstat(3, 0xFFBEF234)                            = 0
/1:     mmap(0xFF390000, 8192, PROT_READ|PROT_EXEC, 
MAP_PRIVATE|MAP_FIXED, 3, 0) = 0xFF390000
/1:     mmap(0x00000000, 802816, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) 
= 0xFF280000
/1:     mmap(0xFF33C000, 24748, PROT_READ|PROT_WRITE|PROT_EXEC, 
MAP_PRIVATE|MAP_FIXED, 3, 704512) = 0xFF33C000
/1:     munmap(0xFF32C000, 65536)                       = 0
/1:     memcntl(0xFF280000, 113448, MC_ADVISE, MADV_WILLNEED, 0, 0) = 0
/1:     close(3)                                        = 0
/1:     stat("/usr/lib/libdl.so.1", 0xFFBEF234)         = 0
/1:     open("/usr/lib/libdl.so.1", O_RDONLY)           = 3
/1:     fstat(3, 0xFFBEF234)                            = 0
/1:     mmap(0xFF390000, 8192, PROT_READ|PROT_EXEC, 
MAP_PRIVATE|MAP_FIXED, 3, 0) = 0xFF390000
/1:     close(3)                                        = 0
/1:     stat("/usr/platform/SUNW,Ultra-2/lib/libc_psr.so.1", 0xFFBEF0C4) = 0
/1:     open("/usr/platform/SUNW,Ultra-2/lib/libc_psr.so.1", O_RDONLY) = 3
/1:     fstat(3, 0xFFBEF0C4)                            = 0
/1:     mmap(0x00000000, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 
0xFF270000
/1:     mmap(0x00000000, 16384, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) 
= 0xFF260000
/1:     close(3)                                        = 0
/1:     munmap(0xFF270000, 8192)                        = 0
/1:     lwp_self()                                      = 1
/1:     sigfillset(0xFF3428B8)                          = 0
/1:     brk(0x00020BC0)                                 = 0
/1:     sysconfig(_CONFIG_PAGESIZE)                     = 8192
/1:     sysconfig(_CONFIG_SEM_VALUE_MAX)                = 2147483647
/1:     getpid()                                        = 9195 [9194]
/1:     lwp_self()                                      = 1
/1:     getcontext(0xFFBEF5B0)
/1:     getrlimit(RLIMIT_STACK, 0xFFBEF5A8)             = 0
/1:     sigprocmask(SIG_SETMASK, 0x00000000, 0xFFBEF598) = 0
/1:     sigprocmask(SIG_SETMASK, 0xFF37EFE8, 0x00000000) = 0
/1:     sigaction(SIGLWP, 0xFF37F7E0, 0x00000000)       = 0
/1:     sigaction(SIGCANCEL, 0xFF37F7E0, 0x00000000)    = 0
/1:     sysconfig(_CONFIG_STACK_PROT)                   = 3
/1:     mmap(0x00000000, 8454144, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_NORESERVE|MAP_ANON, -1, 0) = 0xFE800000
/1:     mprotect(0xFE800000, 8192, PROT_NONE)           = 0
/1:     mprotect(0xFE902000, 8192, PROT_NONE)           = 0
/1:     mprotect(0xFEA04000, 8192, PROT_NONE)           = 0
/1:     mprotect(0xFEB06000, 8192, PROT_NONE)           = 0
/1:     mprotect(0xFEC08000, 8192, PROT_NONE)           = 0
/1:     mprotect(0xFED0A000, 8192, PROT_NONE)           = 0
/1:     mprotect(0xFEE0C000, 8192, PROT_NONE)           = 0
/1:     mprotect(0xFEF0E000, 8192, PROT_NONE)           = 0
/1:     lwp_create(0xFFBEF2D0, __LWP_ASLWP, 0xFF00FDB8) = 2
/2:     lwp_create()    (returning as new lwp ...)      = 0
/1:     door_create(0xFF366CB4, 0x00000000, 0x00000002) = 3
/1:     lwp_schedctl(SC_STATE|SC_BLOCK, 3, 0xFFBEF4D4)  = 0
/1:     door_info(3, 0xFF384A40)                        = 0
/1:     mmap(0x00000000, 24576, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_NORESERVE|MAP_ANON, -1, 0) = 0xFF250000
/1:     mprotect(0xFF250000, 8192, PROT_NONE)           = 0
/1:     lwp_create(0xFFBEF2B8, LWP_DETACHED|LWP_SUSPENDED, 0xFF255DB8) = 3
/3:     lwp_create()    (returning as new lwp ...)      = 0
/1:     lwp_continue(3)                                 = 0
/3:     lwp_schedctl(SC_STATE|SC_BLOCK, -1, 0xFF255CAC) = 0
/3:     lwp_schedctl(SC_DOOR, 0, 0x00000000)            = 4
/3:     door_bind(4)                                    = 0
/3:     close(4)                                        = 0
/1:     close(3)                                        = 0
/1:     sigaction(SIGWAITING, 0xFF37EE38, 0x00000000)   = 0
/3:     door_return(0x00000000, 0, 0x00000000, 0)       = 0
/2:     signotifywait()                                 = 32
/3:     mmap(0x00000000, 24576, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_NORESERVE|MAP_ANON, -1, 0) = 0xFF240000
/3:     mprotect(0xFF240000, 8192, PROT_NONE)           = 0
/1:     lwp_self()                                      = 1
/3:     lwp_create(0xFF2559D8, LWP_DETACHED|LWP_SUSPENDED, 0xFF245DB8) = 4
/4:     lwp_create()    (returning as new lwp ...)      = 0
/3:     lwp_continue(4)                                 = 0
/4:     lwp_schedctl(SC_STATE|SC_BLOCK, -1, 0xFF245CAC) = 0
/4:     lwp_schedctl(SC_DOOR, 0, 0x00000000)            = 3
/4:     door_bind(3)                                    = 0
/4:     close(3)                                        = 0
/3:     lwp_alarm(0)                                    = 0
/4:     door_return(0x00000000, 0, 0x00000000, 0)       = 0
/4:     mmap(0x00000000, 24576, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_NORESERVE|MAP_ANON, -1, 0) = 0xFF230000
/4:     mprotect(0xFF230000, 8192, PROT_NONE)           = 0
/4:     lwp_create(0xFF2459D8, LWP_DETACHED|LWP_SUSPENDED, 0xFF235DB8) = 5
/5:     lwp_create()    (returning as new lwp ...)      = 0
/4:     lwp_continue(5)                                 = 0
/5:     lwp_schedctl(SC_STATE|SC_BLOCK, -1, 0xFF235CAC) = 0
/5:     lwp_schedctl(SC_DOOR, 0, 0x00000000)            = 3
/5:     door_bind(3)                                    = 0
/5:     close(3)                                        = 0
/4:     sigaction(SIGWAITING, 0xFF37EE58, 0x00000000)   = 0
/3:     setitimer(ITIMER_REAL, 0xFFBEFA28, 0xFFBEFA18)  = 0
/3:     sigaction(SIGALRM, 0xFFBEF8A8, 0xFFBEF9D8)      = 0
/3:     setitimer(ITIMER_REAL, 0xFFBEFA28, 0x00000000)  = 0
/3:     sigprocmask(SIG_SETMASK, 0xFFBEF928, 0x00000000) = 0
/2:     lwp_sigredirect(0, SIGWAITING, 0x00000000)      Err#22 EINVAL
/3:         Received signal #14, SIGALRM, in sigsuspend() [caught]
/3:     sigsuspend(0xFFBEF9A8)                          Err#4 EINTR
/3:     sigprocmask(SIG_SETMASK, 0xFF37EFE8, 0x00000000) = 0
/3:     sigprocmask(SIG_SETMASK, 0xFF38AD68, 0x00000000) = 0
/3:     setcontext(0xFFBEF318)
/3:     sigprocmask(SIG_SETMASK, 0xFFBEF938, 0x00000000) = 0
/3:     sigaction(SIGALRM, 0xFFBEF8A8, 0x00000000)      = 0
/3:     setitimer(ITIMER_REAL, 0xFFBEFA18, 0x00000000)  = 0
/3:     llseek(0, 0, SEEK_CUR)                          = 34009
/3:     _exit(0)


What's "funny" libthread is being opened _before_ libc LOL.
So "usleep" from libthread has preference over libc since
it's opened before?

What if I compile the program using : -lc -lthread ?

Now what's happening in terms of signal in multi-thread
applications? Under Solaris, when there is a signal you
_never_ know (was like that in ~ 1998) which thread will
get the signal. So, the way it works ... a single thread
is created to trap every signals (usually the first
thread created by the application). Once this 1st thread
is created, before creating any other threads, the
application masks all signals ... so there's just one
thread that will take care of the signals. I wonder
if this has an impact over Samba? I don't think it
should unless there is a bug in libthread?

Jeff, are you at the latest libthread patch? If not,
see if there is a bug listed in there that could affect
Samba. Even if there's nothing listed -- I'd suggest
to install the latest libthread patch.

Now I'm looking back at the truss with the libthread, all
I can say besides that it looks "ugly" , I wish I'd know
how to print what's in each memory location to figure out
if the program is doing it the right way.

It might be a bug in "usleep" from libthread that has
a side effect on Samba.

The last 2 choices... open a ticket with Sun? or link
with OpenLDAP to see if you still have the same problem.
If the problem is gone once Samba is linked with
OpenLDAP, I'd say then that it's a libthread "usleep"
bug!

Regards,
Pierre B.




More information about the samba-technical mailing list