1 /* System dependent pthreads code. Hurd version.
2 Copyright (C) 2000-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
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.
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
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
24 #include <mach/mig_support.h>
26 #include <pt-internal.h>
30 reset_pthread_total (void)
32 /* Only current thread remains */
36 /* This function is called from the Hurd-specific startup code. It
37 should return a new stack pointer for the main thread. The caller
38 will switch to this new stack before doing anything serious. */
40 _init_routine (void *stack
)
42 struct __pthread
*thread
;
44 pthread_attr_t attr
, *attrp
= 0;
46 if (GL (dl_pthread_threads
) != NULL
)
47 /* Already initialized */
50 /* Initialize the library. */
55 /* We are getting initialized due to dlopening a library using libpthread
56 while the main program was not linked against libpthread. */
57 /* Avoid allocating another stack */
59 __pthread_attr_init (attrp
);
60 __pthread_attr_setstack (attrp
, stack
, __vm_page_size
);
63 /* Create the pthread structure for the main thread (i.e. us). */
64 err
= __pthread_create_internal (&thread
, attrp
, 0, 0);
67 /* XXX The caller copies the command line arguments and the environment
68 to the new stack. Pretend it wasn't allocated so that it remains
69 valid if the main thread terminates. */
71 thread
->tcb
= THREAD_SELF
;
74 __pthread_default_attr
.__guardsize
= __vm_page_size
;
77 ___pthread_self
= thread
;
79 /* Decrease the number of threads, to take into account that the
80 signal thread (which will be created by the glibc startup code
81 when we return from here) shouldn't be seen as a user thread. */
84 __pthread_atfork (NULL
, NULL
, reset_pthread_total
);
86 GL(dl_init_static_tls
) = &__pthread_init_static_tls
;
88 /* Make MiG code thread aware. */
89 __mig_init (thread
->stackaddr
);
93 __pthread_initialize_minimal (void)
95 _init_routine (__libc_stack_end
);
99 __attribute__ ((constructor
))
101 dynamic_init_routine (void)
103 _init_routine (__libc_stack_end
);