]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/powerpc/nptl/tls.h
1 /* Definition for thread-local data handling. NPTL/PowerPC version.
2 Copyright (C) 2003-2024 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/>. */
22 # include <dl-sysdep.h>
29 # include <thread_pointer.h>
31 #else /* __ASSEMBLER__ */
32 # include <tcb-offsets.h>
34 # include <asm/ptrace.h>
35 #endif /* __ASSEMBLER__ */
38 /* Register r2 (tp) is reserved by the ABI as "thread pointer". */
39 # define PT_THREAD_POINTER PT_R2
41 #else /* __powerpc64__ */
42 /* Register r13 (tp) is reserved by the ABI as "thread pointer". */
43 # define PT_THREAD_POINTER PT_R13
44 #endif /* __powerpc64__ */
48 /* Get system call information. */
51 /* The TP points to the start of the thread blocks. */
52 # define TLS_DTV_AT_TP 1
53 # define TLS_TCB_AT_TP 0
55 /* We use the multiple_threads field in the pthread struct */
56 #define TLS_MULTIPLE_THREADS_IN_TCB 1
58 /* Get the thread descriptor definition. */
59 # include <nptl/descr.h>
62 /* The stack_guard is accessed directly by GCC -fstack-protector code,
63 so it is a part of public ABI. The dtv and pointer_guard fields
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. */
70 /* Reservation for HWCAP data. To be accessed by GCC in
71 __builtin_cpu_supports(), so it is a part of public ABI. */
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. */
78 /* Padding to maintain alignment. */
83 /* Reservation for AT_PLATFORM data - powerpc64. */
87 /* Reservation for Dynamic System Optimizer ABI. */
90 /* Reservation for tar register (ISA 2.07). */
92 /* GCC split stack support. */
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
;
99 uintptr_t pointer_guard
;
100 uintptr_t stack_guard
;
104 # include <hwcapinfo.h>
106 /* This is the size of the initial TCB. */
107 # define TLS_INIT_TCB_SIZE 0
109 /* This is the size of the TCB. */
110 # define TLS_TCB_SIZE 0
112 /* This is the size we need before TCB. */
113 # define TLS_PRE_TCB_SIZE \
114 (sizeof (struct pthread) \
115 + ((sizeof (tcbhead_t) + __alignof (struct pthread) - 1) \
116 & ~(__alignof (struct pthread) - 1)))
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
120 TP - 0x7000. As we define TLS_DTV_AT_TP we can
121 assume that the pthread struct is allocated immediately ahead of the
122 TCB. This implies that the pthread_descr address is
123 TP - (TLS_PRE_TCB_SIZE + 0x7000). */
124 # define TLS_TCB_OFFSET 0x7000
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) \
129 ((tcbhead_t *) (tcbp))[-1].dtv = dtvp + 1
131 /* Install new dtv for current thread. */
132 # define INSTALL_NEW_DTV(dtv) (THREAD_DTV() = (dtv))
134 /* Return dtv of given thread descriptor. */
135 # define GET_DTV(tcbp) (((tcbhead_t *) (tcbp))[-1].dtv)
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. */
140 # define TLS_INIT_TP(tcbp) \
142 __thread_register = (void *) (tcbp) + TLS_TCB_OFFSET; \
143 THREAD_SET_HWCAP (__tcb.hwcap); \
144 THREAD_SET_HWCAP_EXTN (__tcb.hwcap_extn); \
145 THREAD_SET_AT_PLATFORM (__tcb.at_platform); \
149 /* Value passed to 'clone' for initialization of the thread register. */
150 # define TLS_DEFINE_INIT_TP(tp, pd) \
151 void *tp = (void *) (pd) + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE; \
152 (((tcbhead_t *) ((char *) tp - TLS_TCB_OFFSET))[-1].hwcap) = \
153 THREAD_GET_HWCAP (); \
154 (((tcbhead_t *) ((char *) tp - TLS_TCB_OFFSET))[-1].hwcap_extn) = \
155 THREAD_GET_HWCAP_EXTN (); \
156 (((tcbhead_t *) ((char *) tp - TLS_TCB_OFFSET))[-1].at_platform) = \
157 THREAD_GET_AT_PLATFORM ();
159 /* Return the address of the dtv for the current thread. */
160 # define THREAD_DTV() \
161 (((tcbhead_t *) (__thread_register - TLS_TCB_OFFSET))[-1].dtv)
163 /* Return the thread descriptor for the current thread. */
164 # define THREAD_SELF \
165 ((struct pthread *) (__thread_register \
166 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
168 /* Magic for libthread_db to know how to do THREAD_SELF. */
169 # define DB_THREAD_SELF \
170 REGISTER (32, 32, PT_THREAD_POINTER * 4, \
171 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE) \
172 REGISTER (64, 64, PT_THREAD_POINTER * 8, \
173 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)
175 # include <tcb-access.h>
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)
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())
198 /* hwcap & hwcap_extn fields in TCB head. */
199 # define THREAD_GET_HWCAP() \
200 (((tcbhead_t *) ((char *) __thread_register \
201 - TLS_TCB_OFFSET))[-1].hwcap)
202 # define THREAD_GET_HWCAP_EXTN() \
203 (((tcbhead_t *) ((char *) __thread_register \
204 - TLS_TCB_OFFSET))[-1].hwcap_extn)
205 # define THREAD_SET_HWCAP(value) \
206 (THREAD_GET_HWCAP () = (value))
207 # define THREAD_SET_HWCAP_EXTN(value) \
208 (THREAD_GET_HWCAP_EXTN () = (value))
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))
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
221 /* Get and set the global scope generation counter in struct pthread. */
222 #define THREAD_GSCOPE_FLAG_UNUSED 0
223 #define THREAD_GSCOPE_FLAG_USED 1
224 #define THREAD_GSCOPE_FLAG_WAIT 2
225 #define THREAD_GSCOPE_RESET_FLAG() \
228 = atomic_exchange_release (&THREAD_SELF->header.gscope_flag, \
229 THREAD_GSCOPE_FLAG_UNUSED); \
230 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
231 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
234 #define THREAD_GSCOPE_SET_FLAG() \
237 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
238 atomic_write_barrier (); \
242 #endif /* __ASSEMBLER__ */