diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2023-08-08 12:19:29 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2023-08-08 12:19:29 +0200 |
commit | 53da64d1cf3694a132287d1ab6e9655031124e32 (patch) | |
tree | 348cdf0a18887d4a606e30ee10d76217cfe33092 /sysdeps/mach | |
parent | 644aa127b9b42a899a12b6ccc6644bc035c231e3 (diff) | |
download | glibc-53da64d1cf3694a132287d1ab6e9655031124e32.zip glibc-53da64d1cf3694a132287d1ab6e9655031124e32.tar.gz glibc-53da64d1cf3694a132287d1ab6e9655031124e32.tar.bz2 |
htl: Initialize ___pthread_self early
When using jemalloc, malloc() needs to use TSD, while libpthread
initialization needs malloc(). Having ___pthread_self set early to some
static storage allows TSD to work early, thus allowing jemalloc and
libpthread to initialize together.
This incidentaly simplifies __pthread_enable/disable_asynccancel and
__pthread_self, now that ___pthread_self is always initialized.
Diffstat (limited to 'sysdeps/mach')
-rw-r--r-- | sysdeps/mach/hurd/htl/pt-sysdep.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/sysdeps/mach/hurd/htl/pt-sysdep.c b/sysdeps/mach/hurd/htl/pt-sysdep.c index 55b1a86..030a7c7 100644 --- a/sysdeps/mach/hurd/htl/pt-sysdep.c +++ b/sysdeps/mach/hurd/htl/pt-sysdep.c @@ -26,6 +26,10 @@ #include <pt-internal.h> #include <pthreadP.h> +/* Initial thread structure used temporarily during initialization, so various + * functions can already work at least basically. */ +static struct __pthread init_thread; + static void reset_pthread_total (void) { @@ -47,6 +51,10 @@ _init_routine (void *stack) /* Already initialized */ return; + /* Initialize early thread structure. */ + init_thread.thread = 1; + ___pthread_self = &init_thread; + /* Initialize the library. */ ___pthread_init (); @@ -74,6 +82,12 @@ _init_routine (void *stack) __pthread_default_attr.__guardsize = __vm_page_size; #endif + /* Copy over the thread-specific state */ + assert (!init_thread.thread_specifics); + memcpy (&thread->static_thread_specifics, + &init_thread.static_thread_specifics, + sizeof (thread->static_thread_specifics)); + ___pthread_self = thread; /* Decrease the number of threads, to take into account that the |