]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl/sysdeps/powerpc/tls.h
PowerPC64: Report overflow on @h and @ha relocations
[thirdparty/glibc.git] / nptl / sysdeps / powerpc / tls.h
CommitLineData
f3c13160 1/* Definition for thread-local data handling. NPTL/PowerPC version.
568035b7 2 Copyright (C) 2003-2013 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
PE
16 License along with the GNU C Library; if not, see
17 <http://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>
28
29/* Type for the dtv. */
30typedef union dtv
31{
32 size_t counter;
9dcafc55
UD
33 struct
34 {
35 void *val;
36 bool is_static;
37 } pointer;
f3c13160
RM
38} dtv_t;
39
40#else /* __ASSEMBLER__ */
41# include <tcb-offsets.h>
42#endif /* __ASSEMBLER__ */
43
44
f3c13160
RM
45#ifndef __ASSEMBLER__
46
47/* Get system call information. */
48# include <sysdep.h>
49
50/* The TP points to the start of the thread blocks. */
51# define TLS_DTV_AT_TP 1
52
94659495
RM
53/* We use the multiple_threads field in the pthread struct */
54#define TLS_MULTIPLE_THREADS_IN_TCB 1
f3c13160
RM
55
56/* Get the thread descriptor definition. */
57# include <nptl/descr.h>
58
35f1e827 59/* The stack_guard is accessed directly by GCC -fstack-protector code,
991fa82b
UD
60 so it is a part of public ABI. The dtv and pointer_guard fields
61 are private. */
f3c13160
RM
62typedef struct
63{
e55a9b25
AZ
64 /* Reservation for the Event-Based Branching ABI. */
65 uintptr_t ebb_handler;
66 uintptr_t ebb_ctx_pointer;
67 uintptr_t ebb_reserved1;
68 uintptr_t ebb_reserved2;
00c2b3b9 69 uintptr_t pointer_guard;
35f1e827 70 uintptr_t stack_guard;
f3c13160
RM
71 dtv_t *dtv;
72} tcbhead_t;
73
74/* This is the size of the initial TCB. */
299601a1 75# define TLS_INIT_TCB_SIZE 0
f3c13160
RM
76
77/* Alignment requirements for the initial TCB. */
299601a1 78# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
f3c13160
RM
79
80/* This is the size of the TCB. */
299601a1 81# define TLS_TCB_SIZE 0
f3c13160
RM
82
83/* Alignment requirements for the TCB. */
299601a1 84# define TLS_TCB_ALIGN __alignof__ (struct pthread)
f3c13160
RM
85
86/* This is the size we need before TCB. */
468777e1
UD
87# define TLS_PRE_TCB_SIZE \
88 (sizeof (struct pthread) \
89 + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
f3c13160
RM
90
91# ifndef __powerpc64__
92/* Register r2 (tp) is reserved by the ABI as "thread pointer". */
93register void *__thread_register __asm__ ("r2");
94# define PT_THREAD_POINTER PT_R2
95# else
96/* Register r13 (tp) is reserved by the ABI as "thread pointer". */
97register void *__thread_register __asm__ ("r13");
98# define PT_THREAD_POINTER PT_R13
99# endif
100
101/* The following assumes that TP (R2 or R13) points to the end of the
102 TCB + 0x7000 (per the ABI). This implies that TCB address is
299601a1 103 TP - 0x7000. As we define TLS_DTV_AT_TP we can
f3c13160
RM
104 assume that the pthread struct is allocated immediately ahead of the
105 TCB. This implies that the pthread_descr address is
299601a1 106 TP - (TLS_PRE_TCB_SIZE + 0x7000). */
f3c13160
RM
107# define TLS_TCB_OFFSET 0x7000
108
109/* Install the dtv pointer. The pointer passed is to the element with
110 index -1 which contain the length. */
111# define INSTALL_DTV(tcbp, dtvp) \
299601a1 112 ((tcbhead_t *) (tcbp))[-1].dtv = dtvp + 1
f3c13160
RM
113
114/* Install new dtv for current thread. */
115# define INSTALL_NEW_DTV(dtv) (THREAD_DTV() = (dtv))
116
117/* Return dtv of given thread descriptor. */
299601a1 118# define GET_DTV(tcbp) (((tcbhead_t *) (tcbp))[-1].dtv)
f3c13160
RM
119
120/* Code to initially initialize the thread pointer. This might need
121 special attention since 'errno' is not yet available and if the
122 operation can cause a failure 'errno' must not be touched. */
123# define TLS_INIT_TP(tcbp, secondcall) \
299601a1 124 (__thread_register = (void *) (tcbp) + TLS_TCB_OFFSET, NULL)
f3c13160
RM
125
126/* Return the address of the dtv for the current thread. */
127# define THREAD_DTV() \
35f1e827 128 (((tcbhead_t *) (__thread_register - TLS_TCB_OFFSET))[-1].dtv)
f3c13160
RM
129
130/* Return the thread descriptor for the current thread. */
131# define THREAD_SELF \
132 ((struct pthread *) (__thread_register \
299601a1 133 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
f3c13160 134
7f08f55a
RM
135/* Magic for libthread_db to know how to do THREAD_SELF. */
136# define DB_THREAD_SELF \
35f1e827 137 REGISTER (32, 32, PT_THREAD_POINTER * 4, \
7f08f55a 138 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE) \
35f1e827 139 REGISTER (64, 64, PT_THREAD_POINTER * 8, \
7f08f55a
RM
140 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)
141
f3c13160
RM
142/* Read member of the thread descriptor directly. */
143# define THREAD_GETMEM(descr, member) ((void)(descr), (THREAD_SELF)->member)
144
145/* Same as THREAD_GETMEM, but the member offset can be non-constant. */
146# define THREAD_GETMEM_NC(descr, member, idx) \
147 ((void)(descr), (THREAD_SELF)->member[idx])
148
149/* Set member of the thread descriptor directly. */
150# define THREAD_SETMEM(descr, member, value) \
151 ((void)(descr), (THREAD_SELF)->member = (value))
152
153/* Same as THREAD_SETMEM, but the member offset can be non-constant. */
154# define THREAD_SETMEM_NC(descr, member, idx, value) \
155 ((void)(descr), (THREAD_SELF)->member[idx] = (value))
156
35f1e827
UD
157/* Set the stack guard field in TCB head. */
158# define THREAD_SET_STACK_GUARD(value) \
159 (((tcbhead_t *) ((char *) __thread_register \
160 - TLS_TCB_OFFSET))[-1].stack_guard = (value))
161# define THREAD_COPY_STACK_GUARD(descr) \
162 (((tcbhead_t *) ((char *) (descr) \
163 + TLS_PRE_TCB_SIZE))[-1].stack_guard \
164 = ((tcbhead_t *) ((char *) __thread_register \
165 - TLS_TCB_OFFSET))[-1].stack_guard)
166
00c2b3b9
UD
167/* Set the stack guard field in TCB head. */
168# define THREAD_GET_POINTER_GUARD() \
169 (((tcbhead_t *) ((char *) __thread_register \
170 - TLS_TCB_OFFSET))[-1].pointer_guard)
171# define THREAD_SET_POINTER_GUARD(value) \
172 (THREAD_GET_POINTER_GUARD () = (value))
173# define THREAD_COPY_POINTER_GUARD(descr) \
174 (((tcbhead_t *) ((char *) (descr) \
175 + TLS_PRE_TCB_SIZE))[-1].pointer_guard \
176 = THREAD_GET_POINTER_GUARD())
177
299601a1
UD
178/* l_tls_offset == 0 is perfectly valid on PPC, so we have to use some
179 different value to mean unset l_tls_offset. */
180# define NO_TLS_OFFSET -1
181
991fa82b 182/* Get and set the global scope generation counter in struct pthread. */
0a54ab53
UD
183#define THREAD_GSCOPE_FLAG_UNUSED 0
184#define THREAD_GSCOPE_FLAG_USED 1
185#define THREAD_GSCOPE_FLAG_WAIT 2
0a54ab53
UD
186#define THREAD_GSCOPE_RESET_FLAG() \
187 do \
188 { int __res \
991fa82b 189 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
0a54ab53
UD
190 THREAD_GSCOPE_FLAG_UNUSED); \
191 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
085a4412 192 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
0a54ab53
UD
193 } \
194 while (0)
195#define THREAD_GSCOPE_SET_FLAG() \
991fa82b
UD
196 do \
197 { \
198 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
199 atomic_write_barrier (); \
200 } \
201 while (0)
0a54ab53
UD
202#define THREAD_GSCOPE_WAIT() \
203 GL(dl_wait_lookup_done) ()
204
f3c13160
RM
205#endif /* __ASSEMBLER__ */
206
207#endif /* tls.h */