diff options
author | Florian Weimer <fweimer@redhat.com> | 2021-05-21 22:35:00 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2021-05-21 22:35:00 +0200 |
commit | d03511f48f49fcb9bec4305586c26ab5d0063022 (patch) | |
tree | 7608e5705c830e8c710e785e3bfc5a90e8986cb4 /nptl/allocatestack.c | |
parent | 2f69522d460611b1018e15df6c238dda2d8d6609 (diff) | |
download | glibc-d03511f48f49fcb9bec4305586c26ab5d0063022.tar.gz glibc-d03511f48f49fcb9bec4305586c26ab5d0063022.tar.xz glibc-d03511f48f49fcb9bec4305586c26ab5d0063022.zip |
nptl: Eliminate the __static_tls_size, __static_tls_align_m1 variables
Use the __nptl_tls_static_size_for_stack inline function instead, and the GLRO (dl_tls_static_align) value directly. The computation of GLRO (dl_tls_static_align) in _dl_determine_tlsoffset ensures that the alignment is at least TLS_TCB_ALIGN, which at least STACK_ALIGN (see allocate_stack). Therefore, the additional rounding-up step is removed. ALso move the initialization of the default stack size from __pthread_initialize_minimal_internal to __pthread_early_init. This introduces an extra system call during single-threaded startup, but this simplifies the initialization sequence. No locking is needed around the writes to __default_pthread_attr because the process is single-threaded at this point. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'nptl/allocatestack.c')
-rw-r--r-- | nptl/allocatestack.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c index c0a5c4d96d..dc81a2ca73 100644 --- a/nptl/allocatestack.c +++ b/nptl/allocatestack.c @@ -254,6 +254,8 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, struct pthread *pd; size_t size; size_t pagesize_m1 = __getpagesize () - 1; + size_t tls_static_size_for_stack = __nptl_tls_static_size_for_stack (); + size_t tls_static_align_m1 = GLRO (dl_tls_static_align) - 1; assert (powerof2 (pagesize_m1 + 1)); assert (TCB_ALIGNMENT >= STACK_ALIGN); @@ -284,17 +286,18 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, /* If the user also specified the size of the stack make sure it is large enough. */ if (attr->stacksize != 0 - && attr->stacksize < (__static_tls_size + MINIMAL_REST_STACK)) + && attr->stacksize < (tls_static_size_for_stack + + MINIMAL_REST_STACK)) return EINVAL; /* Adjust stack size for alignment of the TLS block. */ #if TLS_TCB_AT_TP adj = ((uintptr_t) stackaddr - TLS_TCB_SIZE) - & __static_tls_align_m1; + & tls_static_align_m1; assert (size > adj + TLS_TCB_SIZE); #elif TLS_DTV_AT_TP - adj = ((uintptr_t) stackaddr - __static_tls_size) - & __static_tls_align_m1; + adj = ((uintptr_t) stackaddr - tls_static_size_for_stack) + & tls_static_align_m1; assert (size > adj); #endif @@ -307,7 +310,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, - TLS_TCB_SIZE - adj); #elif TLS_DTV_AT_TP pd = (struct pthread *) (((uintptr_t) stackaddr - - __static_tls_size - adj) + - tls_static_size_for_stack - adj) - TLS_PRE_TCB_SIZE); #endif @@ -366,7 +369,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, | ((GL(dl_stack_flags) & PF_X) ? PROT_EXEC : 0)); /* Adjust the stack size for alignment. */ - size &= ~__static_tls_align_m1; + size &= ~tls_static_align_m1; assert (size != 0); /* Make sure the size of the stack is enough for the guard and @@ -385,7 +388,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, /* Arithmetic overflow. */ return EINVAL; size += guardsize; - if (__builtin_expect (size < ((guardsize + __static_tls_size + if (__builtin_expect (size < ((guardsize + tls_static_size_for_stack + MINIMAL_REST_STACK + pagesize_m1) & ~pagesize_m1), 0)) @@ -414,11 +417,11 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, #if TLS_TCB_AT_TP pd = (struct pthread *) ((((uintptr_t) mem + size) - TLS_TCB_SIZE) - & ~__static_tls_align_m1); + & ~tls_static_align_m1); #elif TLS_DTV_AT_TP pd = (struct pthread *) ((((uintptr_t) mem + size - - __static_tls_size) - & ~__static_tls_align_m1) + - tls_static_size_for_stack) + & ~tls_static_align_m1) - TLS_PRE_TCB_SIZE); #endif @@ -602,7 +605,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, # if TLS_TCB_AT_TP /* The stack begins before the TCB and the static TLS block. */ - stacktop = ((char *) (pd + 1) - __static_tls_size); + stacktop = ((char *) (pd + 1) - tls_static_size_for_stack); # elif TLS_DTV_AT_TP stacktop = (char *) (pd - 1); # endif |