|
|
147e83 |
commit 630f4cc3aa019ede55976ea561f1a7af2f068639
|
|
|
147e83 |
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
|
|
|
147e83 |
Date: Wed Dec 6 13:05:50 2017 +0000
|
|
|
147e83 |
|
|
|
147e83 |
[BZ #22637] Fix stack guard size accounting
|
|
|
147e83 |
|
|
|
147e83 |
Previously if user requested S stack and G guard when creating a
|
|
|
147e83 |
thread, the total mapping was S and the actual available stack was
|
|
|
147e83 |
S - G - static_tls, which is not what the user requested.
|
|
|
147e83 |
|
|
|
147e83 |
This patch fixes the guard size accounting by pretending the user
|
|
|
147e83 |
requested S+G stack. This way all later logic works out except
|
|
|
147e83 |
when reporting the user requested stack size (pthread_getattr_np)
|
|
|
147e83 |
or when computing the minimal stack size (__pthread_get_minstack).
|
|
|
147e83 |
|
|
|
147e83 |
Normally this will increase thread stack allocations by one page.
|
|
|
147e83 |
TLS accounting is not affected, that will require a separate fix.
|
|
|
147e83 |
|
|
|
147e83 |
[BZ #22637]
|
|
|
147e83 |
* nptl/descr.h (stackblock, stackblock_size): Update comments.
|
|
|
147e83 |
* nptl/allocatestack.c (allocate_stack): Add guardsize to stacksize.
|
|
|
147e83 |
* nptl/nptl-init.c (__pthread_get_minstack): Remove guardsize from
|
|
|
147e83 |
stacksize.
|
|
|
147e83 |
* nptl/pthread_getattr_np.c (pthread_getattr_np): Likewise.
|
|
|
147e83 |
|
|
|
147e83 |
Index: glibc-2.17-c758a686/nptl/allocatestack.c
|
|
|
147e83 |
===================================================================
|
|
|
147e83 |
--- glibc-2.17-c758a686.orig/nptl/allocatestack.c
|
|
|
147e83 |
+++ glibc-2.17-c758a686/nptl/allocatestack.c
|
|
|
147e83 |
@@ -470,6 +470,10 @@ allocate_stack (const struct pthread_att
|
|
|
147e83 |
/* Make sure the size of the stack is enough for the guard and
|
|
|
147e83 |
eventually the thread descriptor. */
|
|
|
147e83 |
guardsize = (attr->guardsize + pagesize_m1) & ~pagesize_m1;
|
|
|
147e83 |
+ if (guardsize < attr->guardsize || size + guardsize < guardsize)
|
|
|
147e83 |
+ /* Arithmetic overflow. */
|
|
|
147e83 |
+ return EINVAL;
|
|
|
147e83 |
+ size += guardsize;
|
|
|
147e83 |
if (__builtin_expect (size < ((guardsize + __static_tls_size
|
|
|
147e83 |
+ MINIMAL_REST_STACK + pagesize_m1)
|
|
|
147e83 |
& ~pagesize_m1),
|
|
|
147e83 |
Index: glibc-2.17-c758a686/nptl/descr.h
|
|
|
147e83 |
===================================================================
|
|
|
147e83 |
--- glibc-2.17-c758a686.orig/nptl/descr.h
|
|
|
147e83 |
+++ glibc-2.17-c758a686/nptl/descr.h
|
|
|
147e83 |
@@ -366,9 +366,9 @@ struct pthread
|
|
|
147e83 |
struct _Unwind_Exception exc;
|
|
|
147e83 |
#endif
|
|
|
147e83 |
|
|
|
147e83 |
- /* If nonzero pointer to area allocated for the stack and its
|
|
|
147e83 |
- size. */
|
|
|
147e83 |
+ /* If nonzero, pointer to the area allocated for the stack and guard. */
|
|
|
147e83 |
void *stackblock;
|
|
|
147e83 |
+ /* Size of the stackblock area including the guard. */
|
|
|
147e83 |
size_t stackblock_size;
|
|
|
147e83 |
/* Size of the included guard area. */
|
|
|
147e83 |
size_t guardsize;
|
|
|
147e83 |
Index: glibc-2.17-c758a686/nptl/nptl-init.c
|
|
|
147e83 |
===================================================================
|
|
|
147e83 |
--- glibc-2.17-c758a686.orig/nptl/nptl-init.c
|
|
|
147e83 |
+++ glibc-2.17-c758a686/nptl/nptl-init.c
|
|
|
147e83 |
@@ -500,8 +500,5 @@ strong_alias (__pthread_initialize_minim
|
|
|
147e83 |
size_t
|
|
|
147e83 |
__pthread_get_minstack (const pthread_attr_t *attr)
|
|
|
147e83 |
{
|
|
|
147e83 |
- struct pthread_attr *iattr = (struct pthread_attr *) attr;
|
|
|
147e83 |
-
|
|
|
147e83 |
- return (GLRO(dl_pagesize) + __static_tls_size + PTHREAD_STACK_MIN
|
|
|
147e83 |
- + iattr->guardsize);
|
|
|
147e83 |
+ return GLRO(dl_pagesize) + __static_tls_size + PTHREAD_STACK_MIN;
|
|
|
147e83 |
}
|
|
|
147e83 |
Index: glibc-2.17-c758a686/nptl/pthread_getattr_np.c
|
|
|
147e83 |
===================================================================
|
|
|
147e83 |
--- glibc-2.17-c758a686.orig/nptl/pthread_getattr_np.c
|
|
|
147e83 |
+++ glibc-2.17-c758a686/nptl/pthread_getattr_np.c
|
|
|
147e83 |
@@ -59,8 +59,11 @@ pthread_getattr_np (thread_id, attr)
|
|
|
147e83 |
/* The sizes are subject to alignment. */
|
|
|
147e83 |
if (__builtin_expect (thread->stackblock != NULL, 1))
|
|
|
147e83 |
{
|
|
|
147e83 |
- iattr->stacksize = thread->stackblock_size;
|
|
|
147e83 |
- iattr->stackaddr = (char *) thread->stackblock + iattr->stacksize;
|
|
|
147e83 |
+ /* The stack size reported to the user should not include the
|
|
|
147e83 |
+ guard size. */
|
|
|
147e83 |
+ iattr->stacksize = thread->stackblock_size - thread->guardsize;
|
|
|
147e83 |
+ iattr->stackaddr = (char *) thread->stackblock
|
|
|
147e83 |
+ + thread->stackblock_size;
|
|
|
147e83 |
}
|
|
|
147e83 |
else
|
|
|
147e83 |
{
|