aboutsummaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2021-05-21 22:35:00 +0200
committerFlorian Weimer <fweimer@redhat.com>2021-05-21 22:35:00 +0200
commitd03511f48f49fcb9bec4305586c26ab5d0063022 (patch)
tree7608e5705c830e8c710e785e3bfc5a90e8986cb4 /sysdeps
parent2f69522d460611b1018e15df6c238dda2d8d6609 (diff)
downloadglibc-d03511f48f49fcb9bec4305586c26ab5d0063022.tar
glibc-d03511f48f49fcb9bec4305586c26ab5d0063022.tar.gz
glibc-d03511f48f49fcb9bec4305586c26ab5d0063022.tar.bz2
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 'sysdeps')
-rw-r--r--sysdeps/nptl/pthread_early_init.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/sysdeps/nptl/pthread_early_init.h b/sysdeps/nptl/pthread_early_init.h
index 2d15303dd9..5b49ce39c2 100644
--- a/sysdeps/nptl/pthread_early_init.h
+++ b/sysdeps/nptl/pthread_early_init.h
@@ -19,12 +19,40 @@
#ifndef _PTHREAD_EARLY_INIT_H
#define _PTHREAD_EARLY_INIT_H 1
+#include <nptl/nptl-stack.h>
#include <nptl/pthreadP.h>
#include <pthread_mutex_conf.h>
+#include <sys/resource.h>
static inline void
__pthread_early_init (void)
{
+ /* Determine the default allowed stack size. This is the size used
+ in case the user does not specify one. */
+ struct rlimit limit;
+ if (__getrlimit (RLIMIT_STACK, &limit) != 0
+ || limit.rlim_cur == RLIM_INFINITY)
+ /* The system limit is not usable. Use an architecture-specific
+ default. */
+ limit.rlim_cur = ARCH_STACK_DEFAULT_SIZE;
+ else if (limit.rlim_cur < PTHREAD_STACK_MIN)
+ /* The system limit is unusably small.
+ Use the minimal size acceptable. */
+ limit.rlim_cur = PTHREAD_STACK_MIN;
+
+ /* Make sure it meets the minimum size that allocate_stack
+ (allocatestack.c) will demand, which depends on the page size. */
+ const uintptr_t pagesz = GLRO(dl_pagesize);
+ const size_t minstack = (pagesz + __nptl_tls_static_size_for_stack ()
+ + MINIMAL_REST_STACK);
+ if (limit.rlim_cur < minstack)
+ limit.rlim_cur = minstack;
+
+ /* Round the resource limit up to page size. */
+ limit.rlim_cur = ALIGN_UP (limit.rlim_cur, pagesz);
+ __default_pthread_attr.internal.stacksize = limit.rlim_cur;
+ __default_pthread_attr.internal.guardsize = GLRO (dl_pagesize);
+
#if HAVE_TUNABLES
__pthread_tunables_init ();
#endif