]>
Commit | Line | Data |
---|---|---|
f3c13160 | 1 | /* Definition for thread-local data handling. NPTL/PowerPC version. |
2b778ceb | 2 | Copyright (C) 2003-2021 Free Software Foundation, Inc. |
f3c13160 RM |
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 | |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
f3c13160 RM |
18 | |
19 | #ifndef _TLS_H | |
20 | #define _TLS_H 1 | |
21 | ||
22 | # include <dl-sysdep.h> | |
23 | ||
24 | #ifndef __ASSEMBLER__ | |
9dcafc55 | 25 | # include <stdbool.h> |
f3c13160 RM |
26 | # include <stddef.h> |
27 | # include <stdint.h> | |
aca1daef | 28 | # include <dl-dtv.h> |
f3c13160 RM |
29 | |
30 | #else /* __ASSEMBLER__ */ | |
31 | # include <tcb-offsets.h> | |
1e0a7fd0 MC |
32 | # define __ASSEMBLY__ |
33 | # include <asm/ptrace.h> | |
f3c13160 RM |
34 | #endif /* __ASSEMBLER__ */ |
35 | ||
1e0a7fd0 MC |
36 | #ifndef __powerpc64__ |
37 | /* Register r2 (tp) is reserved by the ABI as "thread pointer". */ | |
38 | # define PT_THREAD_POINTER PT_R2 | |
39 | # ifndef __ASSEMBLER__ | |
40 | register void *__thread_register __asm__ ("r2"); | |
41 | # endif | |
42 | ||
43 | #else /* __powerpc64__ */ | |
44 | /* Register r13 (tp) is reserved by the ABI as "thread pointer". */ | |
45 | # define PT_THREAD_POINTER PT_R13 | |
46 | # ifndef __ASSEMBLER__ | |
47 | register void *__thread_register __asm__ ("r13"); | |
48 | # endif | |
49 | #endif /* __powerpc64__ */ | |
f3c13160 | 50 | |
f3c13160 RM |
51 | #ifndef __ASSEMBLER__ |
52 | ||
67385a01 CES |
53 | # include <hwcapinfo.h> |
54 | ||
f3c13160 RM |
55 | /* Get system call information. */ |
56 | # include <sysdep.h> | |
57 | ||
58 | /* The TP points to the start of the thread blocks. */ | |
59 | # define TLS_DTV_AT_TP 1 | |
498a2233 | 60 | # define TLS_TCB_AT_TP 0 |
f3c13160 | 61 | |
94659495 RM |
62 | /* We use the multiple_threads field in the pthread struct */ |
63 | #define TLS_MULTIPLE_THREADS_IN_TCB 1 | |
f3c13160 RM |
64 | |
65 | /* Get the thread descriptor definition. */ | |
66 | # include <nptl/descr.h> | |
67 | ||
498a2233 | 68 | |
35f1e827 | 69 | /* The stack_guard is accessed directly by GCC -fstack-protector code, |
991fa82b UD |
70 | so it is a part of public ABI. The dtv and pointer_guard fields |
71 | are private. */ | |
f3c13160 RM |
72 | typedef struct |
73 | { | |
67385a01 CES |
74 | /* Reservation for HWCAP data. To be accessed by GCC in |
75 | __builtin_cpu_supports(), so it is a part of public ABI. */ | |
76 | uint64_t hwcap; | |
77 | /* Reservation for AT_PLATFORM data. To be accessed by GCC in | |
78 | __builtin_cpu_is(), so it is a part of public ABI. Since there | |
79 | are different ABIs for 32 and 64 bit, we put this field in a | |
80 | previously empty padding space for powerpc64. */ | |
81 | #ifndef __powerpc64__ | |
82 | /* Padding to maintain alignment. */ | |
83 | uint32_t padding; | |
84 | uint32_t at_platform; | |
85 | #endif | |
f0458cf4 | 86 | uint32_t __unused; |
67385a01 CES |
87 | /* Reservation for AT_PLATFORM data - powerpc64. */ |
88 | #ifdef __powerpc64__ | |
89 | uint32_t at_platform; | |
90 | #endif | |
5b9bf191 AZ |
91 | /* Reservation for Dynamic System Optimizer ABI. */ |
92 | uintptr_t dso_slot2; | |
93 | uintptr_t dso_slot1; | |
94 | /* Reservation for tar register (ISA 2.07). */ | |
95 | uintptr_t tar_save; | |
b525166b UW |
96 | /* GCC split stack support. */ |
97 | void *__private_ss; | |
e55a9b25 AZ |
98 | /* Reservation for the Event-Based Branching ABI. */ |
99 | uintptr_t ebb_handler; | |
100 | uintptr_t ebb_ctx_pointer; | |
101 | uintptr_t ebb_reserved1; | |
102 | uintptr_t ebb_reserved2; | |
00c2b3b9 | 103 | uintptr_t pointer_guard; |
35f1e827 | 104 | uintptr_t stack_guard; |
f3c13160 RM |
105 | dtv_t *dtv; |
106 | } tcbhead_t; | |
107 | ||
108 | /* This is the size of the initial TCB. */ | |
299601a1 | 109 | # define TLS_INIT_TCB_SIZE 0 |
f3c13160 RM |
110 | |
111 | /* Alignment requirements for the initial TCB. */ | |
299601a1 | 112 | # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread) |
f3c13160 RM |
113 | |
114 | /* This is the size of the TCB. */ | |
299601a1 | 115 | # define TLS_TCB_SIZE 0 |
f3c13160 RM |
116 | |
117 | /* Alignment requirements for the TCB. */ | |
299601a1 | 118 | # define TLS_TCB_ALIGN __alignof__ (struct pthread) |
f3c13160 RM |
119 | |
120 | /* This is the size we need before TCB. */ | |
468777e1 UD |
121 | # define TLS_PRE_TCB_SIZE \ |
122 | (sizeof (struct pthread) \ | |
123 | + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1))) | |
f3c13160 | 124 | |
f3c13160 RM |
125 | /* The following assumes that TP (R2 or R13) points to the end of the |
126 | TCB + 0x7000 (per the ABI). This implies that TCB address is | |
299601a1 | 127 | TP - 0x7000. As we define TLS_DTV_AT_TP we can |
f3c13160 RM |
128 | assume that the pthread struct is allocated immediately ahead of the |
129 | TCB. This implies that the pthread_descr address is | |
299601a1 | 130 | TP - (TLS_PRE_TCB_SIZE + 0x7000). */ |
f3c13160 RM |
131 | # define TLS_TCB_OFFSET 0x7000 |
132 | ||
133 | /* Install the dtv pointer. The pointer passed is to the element with | |
134 | index -1 which contain the length. */ | |
135 | # define INSTALL_DTV(tcbp, dtvp) \ | |
299601a1 | 136 | ((tcbhead_t *) (tcbp))[-1].dtv = dtvp + 1 |
f3c13160 RM |
137 | |
138 | /* Install new dtv for current thread. */ | |
139 | # define INSTALL_NEW_DTV(dtv) (THREAD_DTV() = (dtv)) | |
140 | ||
141 | /* Return dtv of given thread descriptor. */ | |
299601a1 | 142 | # define GET_DTV(tcbp) (((tcbhead_t *) (tcbp))[-1].dtv) |
f3c13160 RM |
143 | |
144 | /* Code to initially initialize the thread pointer. This might need | |
145 | special attention since 'errno' is not yet available and if the | |
146 | operation can cause a failure 'errno' must not be touched. */ | |
774f9285 | 147 | # define TLS_INIT_TP(tcbp) \ |
56cf2763 AZ |
148 | ({ \ |
149 | __thread_register = (void *) (tcbp) + TLS_TCB_OFFSET; \ | |
67385a01 CES |
150 | THREAD_SET_HWCAP (__tcb_hwcap); \ |
151 | THREAD_SET_AT_PLATFORM (__tcb_platform); \ | |
56cf2763 AZ |
152 | NULL; \ |
153 | }) | |
f3c13160 | 154 | |
f12b4814 RM |
155 | /* Value passed to 'clone' for initialization of the thread register. */ |
156 | # define TLS_DEFINE_INIT_TP(tp, pd) \ | |
56cf2763 | 157 | void *tp = (void *) (pd) + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE; \ |
67385a01 CES |
158 | (((tcbhead_t *) ((char *) tp - TLS_TCB_OFFSET))[-1].hwcap) = \ |
159 | THREAD_GET_HWCAP (); \ | |
160 | (((tcbhead_t *) ((char *) tp - TLS_TCB_OFFSET))[-1].at_platform) = \ | |
161 | THREAD_GET_AT_PLATFORM (); | |
f12b4814 | 162 | |
f3c13160 RM |
163 | /* Return the address of the dtv for the current thread. */ |
164 | # define THREAD_DTV() \ | |
35f1e827 | 165 | (((tcbhead_t *) (__thread_register - TLS_TCB_OFFSET))[-1].dtv) |
f3c13160 RM |
166 | |
167 | /* Return the thread descriptor for the current thread. */ | |
168 | # define THREAD_SELF \ | |
169 | ((struct pthread *) (__thread_register \ | |
299601a1 | 170 | - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)) |
f3c13160 | 171 | |
7f08f55a RM |
172 | /* Magic for libthread_db to know how to do THREAD_SELF. */ |
173 | # define DB_THREAD_SELF \ | |
35f1e827 | 174 | REGISTER (32, 32, PT_THREAD_POINTER * 4, \ |
7f08f55a | 175 | - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE) \ |
35f1e827 | 176 | REGISTER (64, 64, PT_THREAD_POINTER * 8, \ |
7f08f55a RM |
177 | - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE) |
178 | ||
f3c13160 RM |
179 | /* Read member of the thread descriptor directly. */ |
180 | # define THREAD_GETMEM(descr, member) ((void)(descr), (THREAD_SELF)->member) | |
181 | ||
182 | /* Same as THREAD_GETMEM, but the member offset can be non-constant. */ | |
183 | # define THREAD_GETMEM_NC(descr, member, idx) \ | |
184 | ((void)(descr), (THREAD_SELF)->member[idx]) | |
185 | ||
186 | /* Set member of the thread descriptor directly. */ | |
187 | # define THREAD_SETMEM(descr, member, value) \ | |
188 | ((void)(descr), (THREAD_SELF)->member = (value)) | |
189 | ||
190 | /* Same as THREAD_SETMEM, but the member offset can be non-constant. */ | |
191 | # define THREAD_SETMEM_NC(descr, member, idx, value) \ | |
192 | ((void)(descr), (THREAD_SELF)->member[idx] = (value)) | |
193 | ||
35f1e827 UD |
194 | /* Set the stack guard field in TCB head. */ |
195 | # define THREAD_SET_STACK_GUARD(value) \ | |
196 | (((tcbhead_t *) ((char *) __thread_register \ | |
197 | - TLS_TCB_OFFSET))[-1].stack_guard = (value)) | |
198 | # define THREAD_COPY_STACK_GUARD(descr) \ | |
199 | (((tcbhead_t *) ((char *) (descr) \ | |
200 | + TLS_PRE_TCB_SIZE))[-1].stack_guard \ | |
201 | = ((tcbhead_t *) ((char *) __thread_register \ | |
202 | - TLS_TCB_OFFSET))[-1].stack_guard) | |
203 | ||
00c2b3b9 UD |
204 | /* Set the stack guard field in TCB head. */ |
205 | # define THREAD_GET_POINTER_GUARD() \ | |
206 | (((tcbhead_t *) ((char *) __thread_register \ | |
207 | - TLS_TCB_OFFSET))[-1].pointer_guard) | |
208 | # define THREAD_SET_POINTER_GUARD(value) \ | |
209 | (THREAD_GET_POINTER_GUARD () = (value)) | |
210 | # define THREAD_COPY_POINTER_GUARD(descr) \ | |
211 | (((tcbhead_t *) ((char *) (descr) \ | |
212 | + TLS_PRE_TCB_SIZE))[-1].pointer_guard \ | |
213 | = THREAD_GET_POINTER_GUARD()) | |
56cf2763 | 214 | |
67385a01 CES |
215 | /* hwcap field in TCB head. */ |
216 | # define THREAD_GET_HWCAP() \ | |
217 | (((tcbhead_t *) ((char *) __thread_register \ | |
218 | - TLS_TCB_OFFSET))[-1].hwcap) | |
219 | # define THREAD_SET_HWCAP(value) \ | |
220 | (THREAD_GET_HWCAP () = (value)) | |
221 | ||
222 | /* at_platform field in TCB head. */ | |
223 | # define THREAD_GET_AT_PLATFORM() \ | |
224 | (((tcbhead_t *) ((char *) __thread_register \ | |
225 | - TLS_TCB_OFFSET))[-1].at_platform) | |
226 | # define THREAD_SET_AT_PLATFORM(value) \ | |
227 | (THREAD_GET_AT_PLATFORM () = (value)) | |
00c2b3b9 | 228 | |
299601a1 UD |
229 | /* l_tls_offset == 0 is perfectly valid on PPC, so we have to use some |
230 | different value to mean unset l_tls_offset. */ | |
231 | # define NO_TLS_OFFSET -1 | |
232 | ||
991fa82b | 233 | /* Get and set the global scope generation counter in struct pthread. */ |
a5df0318 | 234 | #define THREAD_GSCOPE_IN_TCB 1 |
0a54ab53 UD |
235 | #define THREAD_GSCOPE_FLAG_UNUSED 0 |
236 | #define THREAD_GSCOPE_FLAG_USED 1 | |
237 | #define THREAD_GSCOPE_FLAG_WAIT 2 | |
0a54ab53 UD |
238 | #define THREAD_GSCOPE_RESET_FLAG() \ |
239 | do \ | |
240 | { int __res \ | |
991fa82b | 241 | = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \ |
0a54ab53 UD |
242 | THREAD_GSCOPE_FLAG_UNUSED); \ |
243 | if (__res == THREAD_GSCOPE_FLAG_WAIT) \ | |
085a4412 | 244 | lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \ |
0a54ab53 UD |
245 | } \ |
246 | while (0) | |
247 | #define THREAD_GSCOPE_SET_FLAG() \ | |
991fa82b UD |
248 | do \ |
249 | { \ | |
250 | THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \ | |
251 | atomic_write_barrier (); \ | |
252 | } \ | |
253 | while (0) | |
0a54ab53 | 254 | |
f3c13160 RM |
255 | #endif /* __ASSEMBLER__ */ |
256 | ||
257 | #endif /* tls.h */ |