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