[PATCH] BZ 6973, 6976: Correct stack size and guard size computations for new threads
Siddhesh Poyarekar
siddhesh@redhat.com
Tue May 22 07:10:00 GMT 2012
Hi,
The POSIX specification requires that the stack allocated by the
implementation be at least equal to the size specified by the user in
pthread_attr_setstacksize. NPTL however gets the guard from within the
stack size, hence reducing the size. The specification says that
additional memory should be allocated at the overflow end of the stack:
"If a thread’s stack is created with guard protection, the
implementation allocates extra memory at the overflow end of the stack
as a buffer against stack overflow of the stack pointer."
Further, we currently align the stack size *down* instead of *up* to
__static_tls_align, again leading to the problem of allocating less
than the user request.
The implementation also has subtle problems like lying to the user
about the size of the guard size that is being used in an (inconsistent)
attempt to only give the user the amount of memory requested. This
should also be fixed.
The proposed patch allocates extra memory for guardsize and makes sure
that stack size is always greater than equal to the requested size. I
have also added a test case to verify this. I have verified that the
patch does not cause any regressions in the testsuite on x86_64.
So the behaviour with stack allocation now should be:
1) The guardsize will always be equal to the requested guardsize
rounded up to page size
2) The stacksize will be greater than or equal to the requested
stacksize.
Regards,
Siddhesh
nptl/ChangeLog:
2012-05-22 Siddhesh Poyarekar <siddhesh@redhat.com>
[BZ #6973]
[BZ #6976]
* Makefile (tests): Add new test case target.
* allocatestack.c (allocate_stack): Align request size upwards
to __static_tls_align. Allocate additional space for guard.
* descr.h (struct pthread): Mention that reported_guardsize is
unused.
* pthread_getattr_np.c (pthread_getattr_np): Use
pthread->guardsize value to return guardsize. Return stacksize
after reducing guardsize.
* tst-attr-stack.c: New test case.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: glibc-posix-stacksize.patch
Type: text/x-patch
Size: 10222 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20120522/2eec587c/attachment.bin>
More information about the Libc-alpha
mailing list