initial commit
[glibc.git] / debian / patches / hurd-i386 / git-htl-pthread-self-early.diff
1 Will be committed for 2.37
2
3 commit 302bf01641d0addebe2aea69b9924bd781f76d81
4 Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
5 Date: Thu Jul 28 22:01:49 2022 +0200
6
7 htl: Let pthread_self and cancellability called early
8
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
12 situation.
13
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 ();
20 int oldtype;
21
22 + if (___pthread_self == NULL)
23 + /* We are not initialized yet, we can't be cancelled anyway. */
24 + return PTHREAD_CANCEL_DEFERRED;
25 +
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)
30 {
31 struct __pthread *p = _pthread_self ();
32
33 + if (___pthread_self == NULL)
34 + /* We are not initialized yet, we can't be cancelled anyway. */
35 + return;
36 +
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
42 --- a/htl/pt-self.c
43 +++ b/htl/pt-self.c
44 @@ -24,7 +24,13 @@
45 pthread_t
46 __pthread_self (void)
47 {
48 - struct __pthread *self = _pthread_self ();
49 + struct __pthread *self;
50 +
51 + if (___pthread_self == NULL)
52 + /* We are not initialized yet, we are the first thread. */
53 + return 1;
54 +
55 + self = _pthread_self ();
56 assert (self != NULL);
57
58 return self->thread;