]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/nptl/dl-tls_init_tp.c
nptl: Move __nptl_initial_report_events into ld.so/startup code
[thirdparty/glibc.git] / sysdeps / nptl / dl-tls_init_tp.c
CommitLineData
90d7e7e5
FW
1/* Completion of TCB initialization after TLS_INIT_TP. NPTL version.
2 Copyright (C) 2020-2021 Free Software Foundation, Inc.
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
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.
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
13 Lesser General Public License for more details.
14
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/>. */
18
442e8a40 19#include <kernel-features.h>
90d7e7e5
FW
20#include <ldsodefs.h>
21#include <list.h>
442e8a40 22#include <nptl/pthreadP.h>
90d7e7e5
FW
23#include <tls.h>
24
442e8a40 25#ifndef __ASSUME_SET_ROBUST_LIST
65733961 26bool __nptl_set_robust_list_avail __attribute__ ((nocommon));
442e8a40
FW
27rtld_hidden_data_def (__nptl_set_robust_list_avail)
28#endif
29
a78e5979
FW
30bool __nptl_initial_report_events __attribute__ ((nocommon));
31rtld_hidden_def (__nptl_initial_report_events)
32
d017b0ab
FW
33#ifdef SHARED
34/* Dummy implementation. See __rtld_mutex_init. */
35static int
36rtld_mutex_dummy (pthread_mutex_t *lock)
37{
38 return 0;
39}
40#endif
41
90d7e7e5 42void
d017b0ab 43__tls_pre_init_tp (void)
90d7e7e5 44{
d017b0ab
FW
45 /* The list data structures are not consistent until
46 initialized. */
90d7e7e5
FW
47 INIT_LIST_HEAD (&GL (dl_stack_used));
48 INIT_LIST_HEAD (&GL (dl_stack_user));
9d124d81 49 INIT_LIST_HEAD (&GL (dl_stack_cache));
d017b0ab
FW
50
51#ifdef SHARED
52 ___rtld_mutex_lock = rtld_mutex_dummy;
53 ___rtld_mutex_unlock = rtld_mutex_dummy;
54#endif
55}
56
57void
58__tls_init_tp (void)
59{
60 /* Set up thread stack list management. */
90d7e7e5 61 list_add (&THREAD_SELF->list, &GL (dl_stack_user));
442e8a40
FW
62
63 /* Early initialization of the TCB. */
64 struct pthread *pd = THREAD_SELF;
65 pd->tid = INTERNAL_SYSCALL_CALL (set_tid_address, &pd->tid);
66 THREAD_SETMEM (pd, specific[0], &pd->specific_1stblock[0]);
67 THREAD_SETMEM (pd, user_stack, true);
68
a78e5979
FW
69 /* Before initializing GL (dl_stack_user), the debugger could not
70 find us and had to set __nptl_initial_report_events. Propagate
71 its setting. */
72 THREAD_SETMEM (pd, report_events, __nptl_initial_report_events);
73
442e8a40
FW
74 /* Initialize the robust mutex data. */
75 {
76#if __PTHREAD_MUTEX_HAVE_PREV
77 pd->robust_prev = &pd->robust_head;
78#endif
79 pd->robust_head.list = &pd->robust_head;
80 pd->robust_head.futex_offset = (offsetof (pthread_mutex_t, __data.__lock)
81 - offsetof (pthread_mutex_t,
82 __data.__list.__next));
83 int res = INTERNAL_SYSCALL_CALL (set_robust_list, &pd->robust_head,
84 sizeof (struct robust_list_head));
85 if (!INTERNAL_SYSCALL_ERROR_P (res))
86 {
87#ifndef __ASSUME_SET_ROBUST_LIST
88 __nptl_set_robust_list_avail = true;
89#endif
90 }
91 }
92
93 /* Set initial thread's stack block from 0 up to __libc_stack_end.
94 It will be bigger than it actually is, but for unwind.c/pt-longjmp.c
95 purposes this is good enough. */
96 THREAD_SETMEM (pd, stackblock_size, (size_t) __libc_stack_end);
90d7e7e5 97}