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)
33 /* Set up thread stack list management. */
34 INIT_LIST_HEAD (&GL (dl_stack_used));
35 INIT_LIST_HEAD (&GL (dl_stack_user));
36 list_add (&THREAD_SELF->list, &GL (dl_stack_user));
38 /* Early initialization of the TCB. */
39 struct pthread *pd = THREAD_SELF;
40 pd->tid = INTERNAL_SYSCALL_CALL (set_tid_address, &pd->tid);
41 THREAD_SETMEM (pd, specific[0], &pd->specific_1stblock[0]);
42 THREAD_SETMEM (pd, user_stack, true);
44 /* Initialize the robust mutex data. */
46 #if __PTHREAD_MUTEX_HAVE_PREV
47 pd->robust_prev = &pd->robust_head;
49 pd->robust_head.list = &pd->robust_head;
50 pd->robust_head.futex_offset = (offsetof (pthread_mutex_t, __data.__lock)
51 - offsetof (pthread_mutex_t,
52 __data.__list.__next));
53 int res = INTERNAL_SYSCALL_CALL (set_robust_list, &pd->robust_head,
54 sizeof (struct robust_list_head));
55 if (!INTERNAL_SYSCALL_ERROR_P (res))
57 #ifndef __ASSUME_SET_ROBUST_LIST
58 __nptl_set_robust_list_avail = true;
63 /* Set initial thread's stack block from 0 up to __libc_stack_end.
64 It will be bigger than it actually is, but for unwind.c/pt-longjmp.c
65 purposes this is good enough. */
66 THREAD_SETMEM (pd, stackblock_size, (size_t) __libc_stack_end);