From 53da64d1cf3694a132287d1ab6e9655031124e32 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Tue, 8 Aug 2023 12:19:29 +0200 Subject: 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. --- sysdeps/mach/hurd/htl/pt-sysdep.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'sysdeps/mach') diff --git a/sysdeps/mach/hurd/htl/pt-sysdep.c b/sysdeps/mach/hurd/htl/pt-sysdep.c index 55b1a86e00..030a7c7a9e 100644 --- a/sysdeps/mach/hurd/htl/pt-sysdep.c +++ b/sysdeps/mach/hurd/htl/pt-sysdep.c @@ -26,6 +26,10 @@ #include #include +/* 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 -- cgit 1.4.1