about summary refs log tree commit diff
path: root/htl/cancellation.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2022-07-28 22:01:49 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2022-08-02 00:00:03 +0200
commit70ff58ced45edf0e3483eddbb61203037bdfdaaa (patch)
treee13a7e5d61fe5b6048df5ece378f78c65c1ef41b /htl/cancellation.c
parentc622ac1b8662908b595ec1a19e401ad6a629f52c (diff)
downloadglibc-70ff58ced45edf0e3483eddbb61203037bdfdaaa.tar.gz
glibc-70ff58ced45edf0e3483eddbb61203037bdfdaaa.tar.xz
glibc-70ff58ced45edf0e3483eddbb61203037bdfdaaa.zip
htl: Let pthread_self and cancellability called early
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.
Diffstat (limited to 'htl/cancellation.c')
-rw-r--r--htl/cancellation.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/htl/cancellation.c b/htl/cancellation.c
index a5d5d2ac04..7d38944718 100644
--- a/htl/cancellation.c
+++ b/htl/cancellation.c
@@ -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);