]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
htl: Let pthread_self and cancellability called early
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Thu, 28 Jul 2022 20:01:49 +0000 (22:01 +0200)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Mon, 1 Aug 2022 22:00:03 +0000 (00:00 +0200)
When applications redirect some functions they might get called before
libpthread is fully initialized.  They may still expected pthread_self
and cancellable functions to work, so cope with such calls in that
situation.

htl/cancellation.c
htl/pt-self.c

index a5d5d2ac04bc72afe50ff694da37369efeabe12c..7d389447182bbf25c2e91e2f2c74d41c75f37965 100644 (file)
@@ -25,6 +25,10 @@ int __pthread_enable_asynccancel (void)
   struct __pthread *p = _pthread_self ();
   int oldtype;
 
+  if (___pthread_self == NULL)
+    /* We are not initialized yet, we can't be cancelled anyway.  */
+    return PTHREAD_CANCEL_DEFERRED;
+
   __pthread_mutex_lock (&p->cancel_lock);
   oldtype = p->cancel_type;
   p->cancel_type = PTHREAD_CANCEL_ASYNCHRONOUS;
@@ -39,6 +43,10 @@ void __pthread_disable_asynccancel (int oldtype)
 {
   struct __pthread *p = _pthread_self ();
 
+  if (___pthread_self == NULL)
+    /* We are not initialized yet, we can't be cancelled anyway.  */
+    return;
+
   __pthread_mutex_lock (&p->cancel_lock);
   p->cancel_type = oldtype;
   __pthread_mutex_unlock (&p->cancel_lock);
index 6fd3c98b82586186c94a6f23777ddf428fb21591..e05ec69bf52f13edfcd492c293d30fa06a6f4fed 100644 (file)
 pthread_t
 __pthread_self (void)
 {
-  struct __pthread *self = _pthread_self ();
+  struct __pthread *self;
+
+  if (___pthread_self == NULL)
+    /* We are not initialized yet, we are the first thread.  */
+    return 1;
+
+  self = _pthread_self ();
   assert (self != NULL);
 
   return self->thread;