nptl stack size

Matthieu CASTET matthieu.castet@parrot.com
Thu Jul 31 12:14:00 GMT 2008


Matthieu CASTET a écrit :
> 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 ?
> 
I attach a small testcase.

It output [1].
It show that the guardsize is allocated on the stack.
For me it violate posix assertion "the implementation allocates extra 
memory at the overflow end of the stack as a buffer against stack 
overflow of the stack pointer".
Also it show the thread have a smaller stack than stacksize. It seems to 
violate posix "The stacksize attribute shall define the minimum stack 
size (in bytes) ".


Does somebody know why nptl implementation does that ?

Matthieu

[1]
default stack and guard size
stacksize 8388608, guardsize 4096
creating thread 0x80486d4
done with status 0 Success
stack start at 0xb7e713d4
small stack size
stacksize 16384, guardsize 4096
creating thread 0x80486d4
done with status 0 Success
stack start at 0xb7fdc3d4
trying to set a guardsize bigger than the stacksize
the implementation allocates extra memory at the overflow end of the 
stack as a buffer against stack overflow of the stack pointer
stacksize 16384, guardsize 16384
creating thread 0x80486d4
done with status 22 Invalid argument
default stack size and guard size like previous test
stacksize 8388608, guardsize 16384
creating thread 0x80486d4
done with status 0 Success
stack start at 0xb7e713d4
doing allocation on the stack with default stack size
stacksize 8388608, guardsize 4096
creating thread 0x80486df
done with status 0 Success
stack start at 0xb7e6d438
trying to use near all the stack
The stacksize attribute shall define the minimum stack size (in bytes) 
allocated for the created threads stack.
stacksize 16384, guardsize 4096
creating thread 0x80486df
Erreur de segmentation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: text/x-csrc
Size: 2431 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-help/attachments/20080731/fb5c0cc2/attachment.bin>


More information about the Libc-help mailing list