]>
Commit | Line | Data |
---|---|---|
33574c17 | 1 | /* System dependent pthreads code. Hurd version. |
2b778ceb | 2 | Copyright (C) 2000-2021 Free Software Foundation, Inc. |
33574c17 ST |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
ad2b41bf ST |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
33574c17 ST |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
ad2b41bf | 13 | Lesser General Public License for more details. |
33574c17 | 14 | |
ad2b41bf ST |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
33574c17 ST |
18 | |
19 | #include <assert.h> | |
20 | #include <stddef.h> | |
21 | #include <stdint.h> | |
22 | ||
23 | #include <mach.h> | |
24 | #include <mach/mig_support.h> | |
25 | ||
26 | #include <pt-internal.h> | |
f6fb29d2 | 27 | #include <pthreadP.h> |
33574c17 ST |
28 | |
29 | __thread struct __pthread *___pthread_self; | |
30 | ||
19a64d9f ST |
31 | static void |
32 | reset_pthread_total (void) | |
33 | { | |
34 | /* Only current thread remains */ | |
35 | __pthread_total = 1; | |
36 | } | |
37 | ||
33574c17 ST |
38 | /* This function is called from the Hurd-specific startup code. It |
39 | should return a new stack pointer for the main thread. The caller | |
40 | will switch to this new stack before doing anything serious. */ | |
9cec82de | 41 | static void |
33574c17 ST |
42 | _init_routine (void *stack) |
43 | { | |
44 | struct __pthread *thread; | |
45 | int err; | |
46 | pthread_attr_t attr, *attrp = 0; | |
47 | ||
166bb3ea | 48 | if (GL (dl_pthread_threads) != NULL) |
33574c17 | 49 | /* Already initialized */ |
9cec82de | 50 | return; |
33574c17 ST |
51 | |
52 | /* Initialize the library. */ | |
53 | ___pthread_init (); | |
54 | ||
55 | if (stack != NULL) | |
56 | { | |
57 | /* We are getting initialized due to dlopening a library using libpthread | |
58 | while the main program was not linked against libpthread. */ | |
59 | /* Avoid allocating another stack */ | |
60 | attrp = &attr; | |
f6fb29d2 ST |
61 | __pthread_attr_init (attrp); |
62 | __pthread_attr_setstack (attrp, stack, __vm_page_size); | |
33574c17 ST |
63 | } |
64 | ||
65 | /* Create the pthread structure for the main thread (i.e. us). */ | |
66 | err = __pthread_create_internal (&thread, attrp, 0, 0); | |
67 | assert_perror (err); | |
68 | ||
69 | /* XXX The caller copies the command line arguments and the environment | |
70 | to the new stack. Pretend it wasn't allocated so that it remains | |
71 | valid if the main thread terminates. */ | |
72 | thread->stack = 0; | |
af27fabe | 73 | thread->tcb = THREAD_SELF; |
33574c17 | 74 | |
34f168fb ST |
75 | #ifndef PAGESIZE |
76 | __pthread_default_attr.__guardsize = __vm_page_size; | |
77 | #endif | |
78 | ||
33574c17 ST |
79 | ___pthread_self = thread; |
80 | ||
81 | /* Decrease the number of threads, to take into account that the | |
82 | signal thread (which will be created by the glibc startup code | |
83 | when we return from here) shouldn't be seen as a user thread. */ | |
84 | __pthread_total--; | |
85 | ||
19a64d9f ST |
86 | __pthread_atfork (NULL, NULL, reset_pthread_total); |
87 | ||
af27fabe ST |
88 | GL(dl_init_static_tls) = &__pthread_init_static_tls; |
89 | ||
33574c17 ST |
90 | /* Make MiG code thread aware. */ |
91 | __mig_init (thread->stackaddr); | |
33574c17 ST |
92 | } |
93 | ||
9cec82de ST |
94 | void |
95 | __pthread_initialize_minimal (void) | |
33574c17 | 96 | { |
9cec82de | 97 | _init_routine (__libc_stack_end); |
33574c17 ST |
98 | } |
99 | ||
100 | #ifdef SHARED | |
101 | __attribute__ ((constructor)) | |
102 | static void | |
103 | dynamic_init_routine (void) | |
104 | { | |
105 | _init_routine (__libc_stack_end); | |
106 | } | |
107 | #endif |