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