nptl stack size

Matthieu CASTET
Tue Jul 29 14:46:00 GMT 2008


after looking at how nptl allocate stack I am a bit confused.
It seems that for nptl the stacksize attribute is the size of the stack
+ the size of the guard + the size of the thread descriptor [1].
This can be see by strace [2]. We allocate 16K with mmap, we use 4K for
the guard and 0x4039f000+16384-0x403a1fe8 for some thread descriptor
data. There is less than 8K for the application

But when looking to posix specification, I understand that
pthread_attr_setstacksize set the stack for the application and that the
guard size is extra memory [3].

Why nptl doesn't allocate extra stack size for that ?


       /* Make sure the size of the stack is enough for the guard and
      eventually the thread descriptor.  */
       guardsize = (attr->guardsize + pagesize_m1) & ~pagesize_m1;
       if (__builtin_expect (size < ((guardsize + __static_tls_size
                      + MINIMAL_REST_STACK + pagesize_m1)
                     & ~pagesize_m1),

MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x4039f000
mprotect(0x4039f000, 4096, PROT_NONE)   = 0
sched_get_priority_min(SCHED_RR)        = 1
sched_get_priority_max(SCHED_RR)        = 99

parent_tidptr=0x403a24d8, tls=0x403a2930, 1


If a thread's stack is created with guard protection, the implementation
allocates *extra memory* at the overflow end of the stack

More information about the Libc-help mailing list