]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/s390/nptl/tls.h
220bdfffb3b88852b10b5e5afbd63fd6f15986fc
[thirdparty/glibc.git] / sysdeps / s390 / nptl / tls.h
1 /* Definition for thread-local data handling. NPTL/s390 version.
2 Copyright (C) 2003-2018 Free Software Foundation, Inc.
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
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #ifndef _TLS_H
20 #define _TLS_H 1
21
22 #include <dl-sysdep.h>
23 #ifndef __ASSEMBLER__
24 # include <stdbool.h>
25 # include <stddef.h>
26 # include <stdint.h>
27 # include <stdlib.h>
28 # include <list.h>
29 # include <kernel-features.h>
30 # include <dl-dtv.h>
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;
39 uintptr_t sysinfo;
40 uintptr_t stack_guard;
41 int gscope_flag;
42 int __glibc_reserved1;
43 /* GCC split stack support. */
44 void *__private_ss;
45 } tcbhead_t;
46
47 # ifndef __s390x__
48 # define TLS_MULTIPLE_THREADS_IN_TCB 1
49 # endif
50
51 #else /* __ASSEMBLER__ */
52 # include <tcb-offsets.h>
53 #endif
54
55
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
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)
68
69 /* Alignment requirements for the initial TCB. */
70 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
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
81 # define TLS_DTV_AT_TP 0
82
83 /* Get the thread descriptor definition. */
84 # include <nptl/descr.h>
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 \
102 _head->sysinfo = GLRO(dl_sysinfo)
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. */
110 # define TLS_INIT_TP(thrdescr) \
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
124 /* Value passed to 'clone' for initialization of the thread register. */
125 # define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd)
126
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
134 /* Magic for libthread_db to know how to do THREAD_SELF. */
135 # define DB_THREAD_SELF REGISTER (32, 32, 18 * 4, 0) \
136 REGISTER (64, __WORDSIZE, 18 * 8, 0)
137
138 /* Access to data in the thread descriptor is easy. */
139 #define THREAD_GETMEM(descr, member) \
140 descr->member
141 #define THREAD_GETMEM_NC(descr, member, idx) \
142 descr->member[idx]
143 #define THREAD_SETMEM(descr, member, value) \
144 descr->member = (value)
145 #define THREAD_SETMEM_NC(descr, member, idx, value) \
146 descr->member[idx] = (value)
147
148 /* Set the stack guard field in TCB head. */
149 #define THREAD_SET_STACK_GUARD(value) \
150 do \
151 { \
152 __asm__ __volatile__ ("" : : : "a0", "a1"); \
153 THREAD_SETMEM (THREAD_SELF, header.stack_guard, value); \
154 } \
155 while (0)
156 #define THREAD_COPY_STACK_GUARD(descr) \
157 ((descr)->header.stack_guard \
158 = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
159
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)
164 #define THREAD_SET_POINTER_GUARD(value) ((void) (value))
165 #define THREAD_COPY_POINTER_GUARD(descr)
166
167 /* Get and set the global scope generation counter in struct pthread. */
168 #define THREAD_GSCOPE_IN_TCB 1
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) \
178 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
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
191 #endif /* __ASSEMBLER__ */
192
193 #endif /* tls.h */