This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

nptl stack size


Hi,

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 ?


Matthieu




[1]
      /* 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),
                0))

[2]
mmap2(NULL, 16384, PROT_READ|PROT_WRITE|PROT_EXEC,
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
clone(child_stack=0x403a1fe8,
flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID,



parent_tidptr=0x403a24d8, tls=0x403a2930, 1


[3]
http://www.opengroup.org/onlinepubs/009695399/functions/pthread_attr_getguardsize.html

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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]