]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
htl: Move cleanup stack to variable shared between libc and pthread
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 14 Jun 2020 12:56:54 +0000 (12:56 +0000)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 14 Jun 2020 15:53:04 +0000 (15:53 +0000)
If libpthread gets loaded dynamically, the stack needs to already contain the
cleanup handlers of the main thread.

* htl/libc_pthread_init.c (__pthread_cleanup_stack): New per-thread variable.
* htl/Versions (libc): Add __pthread_cleanup_stack as private symbol.
* htl/pt-internal.h (struct __pthread): Remove cancelation_handlers
field.
(__pthread_cleanup_stack): Add variable declaration.
* htl/pt-alloc.c (initialize_pthread): Remove initialization of
cancelation_handlers field.
* htl/pt-cleanup.c (__pthread_get_cleanup_stack): Return the address of
__pthread_cleanup_stack instead of that of the cancelation_handlers
field.
* htl/forward.c: Include <pt-internal.h>.
(dummy_list): Remove variable.
(__pthread_get_cleanup_stack): Return the address of __pthread_cleanup_stack
instead of that of dummy_list.

htl/Versions
htl/forward.c
htl/libc_pthread_init.c
htl/pt-alloc.c
htl/pt-cleanup.c
htl/pt-internal.h

index fd9eefbaee6f6723cd8a9b06775b2f1b2699986f..832cc5d814b01921f99c69ce8850ec63b02b8ece 100644 (file)
@@ -29,6 +29,7 @@ libc {
   GLIBC_PRIVATE {
     __libc_alloca_cutoff;
     __libc_pthread_init;
+    __pthread_cleanup_stack;
   }
 }
 
index dfb7b79327fa3b92a47e59e4de7d4d992e4ff7a9..544e7da058c7c0e1eb5501529b23c85966f167f5 100644 (file)
@@ -23,6 +23,7 @@
 #include <pthread-functions.h>
 #include <libc-lock.h>
 #include <fork.h>
+#include <pt-internal.h>
 
 /* Pointers to the libc functions.  */
 struct pthread_functions __libc_pthread_functions attribute_hidden;
@@ -140,6 +141,5 @@ strong_alias (__pthread_setcancelstate, pthread_setcancelstate);
 
 FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0)
 
-struct __pthread_cancelation_handler *dummy_list;
 FORWARD2 (__pthread_get_cleanup_stack, struct __pthread_cancelation_handler **,
-         (void), (), return &dummy_list);
+         (void), (), return &__pthread_cleanup_stack);
index cee92f76ee104827bc9c8d8f32ab14cc536df025..f617c4e0bec8dc5c4e19cf069401d49b51678c9d 100644 (file)
@@ -19,6 +19,8 @@
 #include <string.h>
 #include <pthread-functions.h>
 
+__thread struct __pthread_cancelation_handler *__pthread_cleanup_stack;
+
 void
 __libc_pthread_init (const struct pthread_functions *functions)
 {
index d4426bb2e305d778ebead990fb37b090bfc20644..bf37aca7299362e88c3261880b4b9709cab63f68 100644 (file)
@@ -65,8 +65,6 @@ initialize_pthread (struct __pthread *new)
   new->state_lock = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER;
   new->state_cond = (pthread_cond_t) PTHREAD_COND_INITIALIZER;
 
-  new->cancelation_handlers = 0;
-
   memset (&new->res_state, '\0', sizeof (new->res_state));
 
   new->tcb = NULL;
index a9a7c95847af8d20caf8425b2cd5ea050b46da4d..7e6149bda928c0a5cc97fa6f20feaaf7aff17cba 100644 (file)
@@ -23,6 +23,6 @@
 struct __pthread_cancelation_handler **
 __pthread_get_cleanup_stack (void)
 {
-  return &_pthread_self ()->cancelation_handlers;
+  return &__pthread_cleanup_stack;
 }
 hidden_def(__pthread_get_cleanup_stack)
index 918c207c3ec589cc2badd0c014139f017f061790..e0baa6bcdadb0b38c2483d47e2761cbac36320a1 100644 (file)
@@ -81,7 +81,6 @@ struct __pthread
   int cancel_state;
   int cancel_type;
   int cancel_pending;
-  struct __pthread_cancelation_handler *cancelation_handlers;
 
   /* Thread stack.  */
   void *stackaddr;
@@ -197,6 +196,9 @@ extern pthread_rwlock_t __pthread_threads_lock;
 #ifndef _pthread_self
 extern struct __pthread *_pthread_self (void);
 #endif
+
+/* Stores the stack of cleanup handlers for the thread.  */
+extern __thread struct __pthread_cancelation_handler *__pthread_cleanup_stack;
 \f
 
 /* Initialize the pthreads library.  */