[PATCH] fix allocation of NPTL thread stack guard area
Chris Demetriou
cgd@google.com
Tue May 20 12:34:00 GMT 2008
I was doing something the other day that required me to set my
threads' stack and guard sizes. I was surprised to find that NPTL was
taking the guard area out of the requested stack size, rather than
tacking the guard area on to the end of the stack.
LinuxThreads allocated the guard area after the end of the requested
stack. I checked the Solaris 10 pthreads implementation, it does the
same.
My reading of POSIX.1-2001 pthread_attr_setguardsize says that that
behavior is right:
31274 The guardsize attribute controls the size of the guard area for
the created thread's stack. The
31275 guardsize attribute provides protection against overflow of the
stack pointer. If a thread's stack is
31276 created with guard protection, the implementation allocates
extra memory at the overflow end
31277 of the stack as a buffer against stack overflow of the stack pointer.
(Note specifically "allocates *extra* memory.") So, I'm thinking this
is a bug in NPTL.
I've attached a fix for this, along with a test case. I'm a bit
surprised (glad, though! 8-) that this was so easy to fix.
I've also included output from the new test before the allocatestack.c
change, output from a run after the change, and output from the
Solaris run.
This was tested on a CentOS 5 system (uname -msrv -> Linux
2.6.18-53.1.13.el5xen #1 SMP Tue Feb 12 13:33:07 EST 2008 x86_64),
full glibc tests before/after for 64-bit. It was also tested on
32-bit x86 using a ubuntu-based system + 32-bit headers.
The patch & test runs were made with glibc sources as of this evening.
(FYI, I've tried to make the test work on stack-grows-up systems, but
i don't have any way to test on them.)
chris
---
2008-05-19 Chris Demetriou <cgd@google.com>
* nptl/allocatestack.c (allocate_stack): Add guard page size to
requested stack size, per POSIX.1-2001.
* nptl/tst-stack4.c: New test for corrected guard page behavior.
* nptl/Makefile (tests): Add new test.
* nptl/TODO-testing: Remove note about need to test
pthread_attr_setguardsize.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: guardsize.patch
Type: text/x-patch
Size: 9262 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20080520/2135b89d/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tst-stack4.out.BROKEN
Type: application/octet-stream
Size: 731 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20080520/2135b89d/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tst-stack4.out.FIXED
Type: application/octet-stream
Size: 798 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20080520/2135b89d/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tst-stack4.out.SOLARIS
Type: application/octet-stream
Size: 872 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20080520/2135b89d/attachment-0002.obj>
More information about the Libc-alpha
mailing list