From d03511f48f49fcb9bec4305586c26ab5d0063022 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Fri, 21 May 2021 22:35:00 +0200 Subject: 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 --- sysdeps/nptl/pthread_early_init.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'sysdeps') 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 #include #include +#include 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 -- cgit 1.4.1