]> sourceware.org Git - glibc.git/commitdiff
hurd: Fix pthread_self() without libpthread
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Wed, 17 Jul 2024 12:06:25 +0000 (14:06 +0200)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Wed, 17 Jul 2024 12:14:21 +0000 (14:14 +0200)
5476f8cd2e68 ("htl: move pthread_self info libc.") moved the htl
pthread_self() function from libpthread to libc, replacing the previous libc
stub that just returns 0. And 53da64d1cf36 ("htl: Initialize ___pthread_self
early") added initialization code which is needed before being able to
call pthread_self. It is currently in libpthread, and thus never called
before programs can call pthread_self from libc, which then segfaults
when accessing _pthread_self()->thread.

This moves the initialization to libc itself, as initialized variables, so
pthread_self can always be called fine.

htl/Versions
sysdeps/mach/hurd/htl/pt-pthread_self.c
sysdeps/mach/hurd/htl/pt-sysdep.c
sysdeps/mach/hurd/htl/pt-sysdep.h

index e1524117a0666696eeccf05823a14c0a21acba69..69b79b4f1b78491d497142fba9106b1e7eb7b561 100644 (file)
@@ -38,6 +38,7 @@ libc {
     __pthread_cleanup_stack;
     __pthread_total;
     ___pthread_self;
+    __pthread_init_thread;
   }
 }
 
index 04fa283aab91f9d1c22de88b7517a4f8b0c1ed6d..08ef2e4956d52fd9912263dd67d2ba47fa955f1b 100644 (file)
    <https://www.gnu.org/licenses/>.  */
 
 #include <pt-sysdep.h>
+#include <pt-internal.h>
 
-__thread struct __pthread *___pthread_self;
+/* Initial thread structure used before libpthread is initialized, so various
+ * functions can already work at least basically.  */
+struct __pthread __pthread_init_thread = {
+       .thread = 1,
+};
+
+__thread struct __pthread *___pthread_self = &__pthread_init_thread;
 libc_hidden_tls_def (___pthread_self)
index 5372cbf77f555d05b742c5aa7509e422e6321232..f5c1c246ebf48a85674f78e0574c3eae3782c37d 100644 (file)
 #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)
 {
@@ -51,10 +47,6 @@ _init_routine (void *stack)
     /* Already initialized */
     return;
 
-  /* Initialize early thread structure.  */
-  init_thread.thread = 1;
-  ___pthread_self = &init_thread;
-
   /* Initialize the library.  */
   ___pthread_init ();
 
@@ -116,9 +108,9 @@ _init_routine (void *stack)
 #endif
 
   /* Copy over the thread-specific state */
-  assert (!init_thread.thread_specifics);
+  assert (!__pthread_init_thread.thread_specifics);
   memcpy (&thread->static_thread_specifics,
-          &init_thread.static_thread_specifics,
+          &__pthread_init_thread.static_thread_specifics,
           sizeof (thread->static_thread_specifics));
 
   ___pthread_self = thread;
index 09d9547a8eb32fa55fffecec1c1a2ba44baac92c..ef7f5096118471d0fe21b7f2378a156d45445172 100644 (file)
@@ -34,6 +34,8 @@
 
 extern __thread struct __pthread *___pthread_self;
 libc_hidden_tls_proto (___pthread_self)
+extern struct __pthread ___pthread_init_thread;
+libc_hidden_proto (___pthread_init_thread)
 
 #ifdef DEBUG
 #define _pthread_self()                                            \
This page took 0.038086 seconds and 5 git commands to generate.