1 Will be committed for 2.37
3 commit 302bf01641d0addebe2aea69b9924bd781f76d81
4 Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
5 Date: Thu Jul 28 22:01:49 2022 +0200
7 htl: Let pthread_self and cancellability called early
9 When applications redirect some functions they might get called before
10 libpthread is fully initialized. They may still expected pthread_self
11 and cancellable functions to work, so cope with such calls in that
14 diff --git a/htl/cancellation.c b/htl/cancellation.c
15 index a5d5d2ac04..7d38944718 100644
16 --- a/htl/cancellation.c
17 +++ b/htl/cancellation.c
18 @@ -25,6 +25,10 @@ int __pthread_enable_asynccancel (void)
19 struct __pthread *p = _pthread_self ();
22 + if (___pthread_self == NULL)
23 + /* We are not initialized yet, we can't be cancelled anyway. */
24 + return PTHREAD_CANCEL_DEFERRED;
26 __pthread_mutex_lock (&p->cancel_lock);
27 oldtype = p->cancel_type;
28 p->cancel_type = PTHREAD_CANCEL_ASYNCHRONOUS;
29 @@ -39,6 +43,10 @@ void __pthread_disable_asynccancel (int oldtype)
31 struct __pthread *p = _pthread_self ();
33 + if (___pthread_self == NULL)
34 + /* We are not initialized yet, we can't be cancelled anyway. */
37 __pthread_mutex_lock (&p->cancel_lock);
38 p->cancel_type = oldtype;
39 __pthread_mutex_unlock (&p->cancel_lock);
40 diff --git a/htl/pt-self.c b/htl/pt-self.c
41 index 6fd3c98b82..e05ec69bf5 100644
48 - struct __pthread *self = _pthread_self ();
49 + struct __pthread *self;
51 + if (___pthread_self == NULL)
52 + /* We are not initialized yet, we are the first thread. */
55 + self = _pthread_self ();
56 assert (self != NULL);