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.
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/>. */
19 #include <kernel-features.h>
22 #include <nptl/pthreadP.h>
25 #ifndef __ASSUME_SET_ROBUST_LIST
26 bool __nptl_set_robust_list_avail
__attribute__ ((nocommon
));
27 rtld_hidden_data_def (__nptl_set_robust_list_avail
)
30 bool __nptl_initial_report_events
__attribute__ ((nocommon
));
31 rtld_hidden_def (__nptl_initial_report_events
)
34 /* Dummy implementation. See __rtld_mutex_init. */
36 rtld_mutex_dummy (pthread_mutex_t
*lock
)
43 __tls_pre_init_tp (void)
45 /* The list data structures are not consistent until
47 INIT_LIST_HEAD (&GL (dl_stack_used
));
48 INIT_LIST_HEAD (&GL (dl_stack_user
));
49 INIT_LIST_HEAD (&GL (dl_stack_cache
));
52 ___rtld_mutex_lock
= rtld_mutex_dummy
;
53 ___rtld_mutex_unlock
= rtld_mutex_dummy
;
60 /* Set up thread stack list management. */
61 list_add (&THREAD_SELF
->list
, &GL (dl_stack_user
));
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);
69 /* Before initializing GL (dl_stack_user), the debugger could not
70 find us and had to set __nptl_initial_report_events. Propagate
72 THREAD_SETMEM (pd
, report_events
, __nptl_initial_report_events
);
74 /* Initialize the robust mutex data. */
76 #if __PTHREAD_MUTEX_HAVE_PREV
77 pd
->robust_prev
= &pd
->robust_head
;
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
))
87 #ifndef __ASSUME_SET_ROBUST_LIST
88 __nptl_set_robust_list_avail
= true;
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
);
98 THREAD_SETMEM (pd
, cancelstate
, PTHREAD_CANCEL_ENABLE
);
99 THREAD_SETMEM (pd
, canceltype
, PTHREAD_CANCEL_DEFERRED
);