This is the mail archive of the libc-alpha@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] |
[Resent because a coworker pointed out that the actual patch and other attachments enclosed in the last copy was base64 encoded, and that wasn't the preferred patch submission format. Sorry!] 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.
Attachment:
guardsize.patch
Description: Text document
Attachment:
tst-stack4.out.BROKEN
Description: Text document
Attachment:
tst-stack4.out.FIXED
Description: Text document
Attachment:
tst-stack4.out.SOLARIS
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |