]>
Commit | Line | Data |
---|---|---|
763c0490 | 1 | /* Definition for thread-local data handling. NPTL/s390 version. |
04277e02 | 2 | Copyright (C) 2003-2019 Free Software Foundation, Inc. |
a88c9263 UD |
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/>. */ | |
a88c9263 UD |
18 | |
19 | #ifndef _TLS_H | |
20 | #define _TLS_H 1 | |
21 | ||
22 | #include <dl-sysdep.h> | |
23 | #ifndef __ASSEMBLER__ | |
9dcafc55 | 24 | # include <stdbool.h> |
a88c9263 UD |
25 | # include <stddef.h> |
26 | # include <stdint.h> | |
27 | # include <stdlib.h> | |
28 | # include <list.h> | |
991fa82b | 29 | # include <kernel-features.h> |
aca1daef | 30 | # include <dl-dtv.h> |
a88c9263 UD |
31 | |
32 | typedef struct | |
33 | { | |
34 | void *tcb; /* Pointer to the TCB. Not necessary the | |
35 | thread descriptor used by libpthread. */ | |
36 | dtv_t *dtv; | |
37 | void *self; /* Pointer to the thread descriptor. */ | |
38 | int multiple_threads; | |
a88c9263 | 39 | uintptr_t sysinfo; |
35f1e827 | 40 | uintptr_t stack_guard; |
991fa82b | 41 | int gscope_flag; |
a4b5177c | 42 | int __glibc_reserved1; |
a4b5177c MK |
43 | /* GCC split stack support. */ |
44 | void *__private_ss; | |
a88c9263 UD |
45 | } tcbhead_t; |
46 | ||
100a7100 RM |
47 | # ifndef __s390x__ |
48 | # define TLS_MULTIPLE_THREADS_IN_TCB 1 | |
49 | # endif | |
d4f64e1a | 50 | |
a88c9263 UD |
51 | #else /* __ASSEMBLER__ */ |
52 | # include <tcb-offsets.h> | |
53 | #endif | |
54 | ||
55 | ||
a88c9263 UD |
56 | /* Alignment requirement for the stack. For IA-32 this is governed by |
57 | the SSE memory functions. */ | |
58 | #define STACK_ALIGN 16 | |
59 | ||
60 | #ifndef __ASSEMBLER__ | |
61 | /* Get system call information. */ | |
62 | # include <sysdep.h> | |
63 | ||
f7d78e18 UD |
64 | /* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t), |
65 | because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole | |
66 | struct pthread even when not linked with -lpthread. */ | |
67 | # define TLS_INIT_TCB_SIZE sizeof (struct pthread) | |
a88c9263 UD |
68 | |
69 | /* Alignment requirements for the initial TCB. */ | |
f7d78e18 | 70 | # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread) |
a88c9263 UD |
71 | |
72 | /* This is the size of the TCB. */ | |
73 | # define TLS_TCB_SIZE sizeof (struct pthread) | |
74 | ||
75 | /* Alignment requirements for the TCB. */ | |
76 | # define TLS_TCB_ALIGN __alignof__ (struct pthread) | |
77 | ||
78 | /* The TCB can have any size and the memory following the address the | |
79 | thread pointer points to is unspecified. Allocate the TCB there. */ | |
80 | # define TLS_TCB_AT_TP 1 | |
498a2233 RM |
81 | # define TLS_DTV_AT_TP 0 |
82 | ||
83 | /* Get the thread descriptor definition. */ | |
84 | # include <nptl/descr.h> | |
a88c9263 UD |
85 | |
86 | ||
87 | /* Install the dtv pointer. The pointer passed is to the element with | |
88 | index -1 which contain the length. */ | |
89 | # define INSTALL_DTV(descr, dtvp) \ | |
90 | ((tcbhead_t *) (descr))->dtv = (dtvp) + 1 | |
91 | ||
92 | /* Install new dtv for current thread. */ | |
93 | # define INSTALL_NEW_DTV(dtv) \ | |
94 | (((tcbhead_t *) __builtin_thread_pointer ())->dtv = (dtv)) | |
95 | ||
96 | /* Return dtv of given thread descriptor. */ | |
97 | # define GET_DTV(descr) \ | |
98 | (((tcbhead_t *) (descr))->dtv) | |
99 | ||
100 | #if defined NEED_DL_SYSINFO && defined SHARED | |
101 | # define INIT_SYSINFO \ | |
8acb4b81 | 102 | _head->sysinfo = GLRO(dl_sysinfo) |
a88c9263 UD |
103 | #else |
104 | # define INIT_SYSINFO | |
105 | #endif | |
106 | ||
107 | /* Code to initially initialize the thread pointer. This might need | |
108 | special attention since 'errno' is not yet available and if the | |
109 | operation can cause a failure 'errno' must not be touched. */ | |
774f9285 | 110 | # define TLS_INIT_TP(thrdescr) \ |
a88c9263 UD |
111 | ({ void *_thrdescr = (thrdescr); \ |
112 | tcbhead_t *_head = _thrdescr; \ | |
113 | \ | |
114 | _head->tcb = _thrdescr; \ | |
115 | /* For now the thread descriptor is at the same address. */ \ | |
116 | _head->self = _thrdescr; \ | |
117 | /* New syscall handling support. */ \ | |
118 | INIT_SYSINFO; \ | |
119 | \ | |
120 | __builtin_set_thread_pointer (_thrdescr); \ | |
121 | NULL; \ | |
122 | }) | |
123 | ||
d3996c79 RM |
124 | /* Value passed to 'clone' for initialization of the thread register. */ |
125 | # define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd) | |
126 | ||
a88c9263 UD |
127 | /* Return the address of the dtv for the current thread. */ |
128 | # define THREAD_DTV() \ | |
129 | (((tcbhead_t *) __builtin_thread_pointer ())->dtv) | |
130 | ||
131 | /* Return the thread descriptor for the current thread. */ | |
132 | # define THREAD_SELF ((struct pthread *) __builtin_thread_pointer ()) | |
133 | ||
7f08f55a | 134 | /* Magic for libthread_db to know how to do THREAD_SELF. */ |
763c0490 RM |
135 | # define DB_THREAD_SELF REGISTER (32, 32, 18 * 4, 0) \ |
136 | REGISTER (64, __WORDSIZE, 18 * 8, 0) | |
7f08f55a | 137 | |
a88c9263 UD |
138 | /* Access to data in the thread descriptor is easy. */ |
139 | #define THREAD_GETMEM(descr, member) \ | |
dac0f772 | 140 | descr->member |
a88c9263 | 141 | #define THREAD_GETMEM_NC(descr, member, idx) \ |
dac0f772 | 142 | descr->member[idx] |
a88c9263 | 143 | #define THREAD_SETMEM(descr, member, value) \ |
dac0f772 | 144 | descr->member = (value) |
a88c9263 | 145 | #define THREAD_SETMEM_NC(descr, member, idx, value) \ |
dac0f772 | 146 | descr->member[idx] = (value) |
a88c9263 | 147 | |
35f1e827 UD |
148 | /* Set the stack guard field in TCB head. */ |
149 | #define THREAD_SET_STACK_GUARD(value) \ | |
31cf3942 | 150 | do \ |
208bc836 | 151 | { \ |
31cf3942 | 152 | __asm__ __volatile__ ("" : : : "a0", "a1"); \ |
208bc836 UD |
153 | THREAD_SETMEM (THREAD_SELF, header.stack_guard, value); \ |
154 | } \ | |
155 | while (0) | |
35f1e827 UD |
156 | #define THREAD_COPY_STACK_GUARD(descr) \ |
157 | ((descr)->header.stack_guard \ | |
158 | = THREAD_GETMEM (THREAD_SELF, header.stack_guard)) | |
159 | ||
00c2b3b9 UD |
160 | /* s390 doesn't have HP_TIMING_*, so for the time being |
161 | use stack_guard as pointer_guard. */ | |
162 | #define THREAD_GET_POINTER_GUARD() \ | |
163 | THREAD_GETMEM (THREAD_SELF, header.stack_guard) | |
4d614fe5 | 164 | #define THREAD_SET_POINTER_GUARD(value) ((void) (value)) |
00c2b3b9 UD |
165 | #define THREAD_COPY_POINTER_GUARD(descr) |
166 | ||
991fa82b | 167 | /* Get and set the global scope generation counter in struct pthread. */ |
a5df0318 | 168 | #define THREAD_GSCOPE_IN_TCB 1 |
991fa82b UD |
169 | #define THREAD_GSCOPE_FLAG_UNUSED 0 |
170 | #define THREAD_GSCOPE_FLAG_USED 1 | |
171 | #define THREAD_GSCOPE_FLAG_WAIT 2 | |
172 | #define THREAD_GSCOPE_RESET_FLAG() \ | |
173 | do \ | |
174 | { int __res \ | |
175 | = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \ | |
176 | THREAD_GSCOPE_FLAG_UNUSED); \ | |
177 | if (__res == THREAD_GSCOPE_FLAG_WAIT) \ | |
085a4412 | 178 | lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \ |
991fa82b UD |
179 | } \ |
180 | while (0) | |
181 | #define THREAD_GSCOPE_SET_FLAG() \ | |
182 | do \ | |
183 | { \ | |
184 | THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \ | |
185 | atomic_write_barrier (); \ | |
186 | } \ | |
187 | while (0) | |
188 | #define THREAD_GSCOPE_WAIT() \ | |
189 | GL(dl_wait_lookup_done) () | |
190 | ||
a88c9263 UD |
191 | #endif /* __ASSEMBLER__ */ |
192 | ||
193 | #endif /* tls.h */ |