mfe_MU, miq_NI locales: Escape slashes in d_fmt [BZ #22403]
[glibc.git] / sysdeps / s390 / nptl / tls.h
blob7bc6c897b3fb9b99c271a52133aaeb5e802af2ee
1 /* Definition for thread-local data handling. NPTL/s390 version.
2 Copyright (C) 2003-2017 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 <http://www.gnu.org/licenses/>. */
19 #ifndef _TLS_H
20 #define _TLS_H 1
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>
32 typedef struct
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 #ifndef __ASSUME_PRIVATE_FUTEX
43 int private_futex;
44 #else
45 int __glibc_reserved1;
46 #endif
47 /* GCC split stack support. */
48 void *__private_ss;
49 } tcbhead_t;
51 # ifndef __s390x__
52 # define TLS_MULTIPLE_THREADS_IN_TCB 1
53 # endif
55 #else /* __ASSEMBLER__ */
56 # include <tcb-offsets.h>
57 #endif
60 /* Alignment requirement for the stack. For IA-32 this is governed by
61 the SSE memory functions. */
62 #define STACK_ALIGN 16
64 #ifndef __ASSEMBLER__
65 /* Get system call information. */
66 # include <sysdep.h>
68 /* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
69 because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
70 struct pthread even when not linked with -lpthread. */
71 # define TLS_INIT_TCB_SIZE sizeof (struct pthread)
73 /* Alignment requirements for the initial TCB. */
74 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
76 /* This is the size of the TCB. */
77 # define TLS_TCB_SIZE sizeof (struct pthread)
79 /* Alignment requirements for the TCB. */
80 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
82 /* The TCB can have any size and the memory following the address the
83 thread pointer points to is unspecified. Allocate the TCB there. */
84 # define TLS_TCB_AT_TP 1
85 # define TLS_DTV_AT_TP 0
87 /* Get the thread descriptor definition. */
88 # include <nptl/descr.h>
91 /* Install the dtv pointer. The pointer passed is to the element with
92 index -1 which contain the length. */
93 # define INSTALL_DTV(descr, dtvp) \
94 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
96 /* Install new dtv for current thread. */
97 # define INSTALL_NEW_DTV(dtv) \
98 (((tcbhead_t *) __builtin_thread_pointer ())->dtv = (dtv))
100 /* Return dtv of given thread descriptor. */
101 # define GET_DTV(descr) \
102 (((tcbhead_t *) (descr))->dtv)
104 #if defined NEED_DL_SYSINFO && defined SHARED
105 # define INIT_SYSINFO \
106 _head->sysinfo = GLRO(dl_sysinfo)
107 #else
108 # define INIT_SYSINFO
109 #endif
111 /* Code to initially initialize the thread pointer. This might need
112 special attention since 'errno' is not yet available and if the
113 operation can cause a failure 'errno' must not be touched. */
114 # define TLS_INIT_TP(thrdescr) \
115 ({ void *_thrdescr = (thrdescr); \
116 tcbhead_t *_head = _thrdescr; \
118 _head->tcb = _thrdescr; \
119 /* For now the thread descriptor is at the same address. */ \
120 _head->self = _thrdescr; \
121 /* New syscall handling support. */ \
122 INIT_SYSINFO; \
124 __builtin_set_thread_pointer (_thrdescr); \
125 NULL; \
128 /* Value passed to 'clone' for initialization of the thread register. */
129 # define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd)
131 /* Return the address of the dtv for the current thread. */
132 # define THREAD_DTV() \
133 (((tcbhead_t *) __builtin_thread_pointer ())->dtv)
135 /* Return the thread descriptor for the current thread. */
136 # define THREAD_SELF ((struct pthread *) __builtin_thread_pointer ())
138 /* Magic for libthread_db to know how to do THREAD_SELF. */
139 # define DB_THREAD_SELF REGISTER (32, 32, 18 * 4, 0) \
140 REGISTER (64, __WORDSIZE, 18 * 8, 0)
142 /* Access to data in the thread descriptor is easy. */
143 #define THREAD_GETMEM(descr, member) \
144 descr->member
145 #define THREAD_GETMEM_NC(descr, member, idx) \
146 descr->member[idx]
147 #define THREAD_SETMEM(descr, member, value) \
148 descr->member = (value)
149 #define THREAD_SETMEM_NC(descr, member, idx, value) \
150 descr->member[idx] = (value)
152 /* Set the stack guard field in TCB head. */
153 #define THREAD_SET_STACK_GUARD(value) \
154 do \
156 __asm__ __volatile__ ("" : : : "a0", "a1"); \
157 THREAD_SETMEM (THREAD_SELF, header.stack_guard, value); \
159 while (0)
160 #define THREAD_COPY_STACK_GUARD(descr) \
161 ((descr)->header.stack_guard \
162 = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
164 /* s390 doesn't have HP_TIMING_*, so for the time being
165 use stack_guard as pointer_guard. */
166 #define THREAD_GET_POINTER_GUARD() \
167 THREAD_GETMEM (THREAD_SELF, header.stack_guard)
168 #define THREAD_SET_POINTER_GUARD(value) ((void) (value))
169 #define THREAD_COPY_POINTER_GUARD(descr)
171 /* Get and set the global scope generation counter in struct pthread. */
172 #define THREAD_GSCOPE_FLAG_UNUSED 0
173 #define THREAD_GSCOPE_FLAG_USED 1
174 #define THREAD_GSCOPE_FLAG_WAIT 2
175 #define THREAD_GSCOPE_RESET_FLAG() \
176 do \
177 { int __res \
178 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
179 THREAD_GSCOPE_FLAG_UNUSED); \
180 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
181 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
183 while (0)
184 #define THREAD_GSCOPE_SET_FLAG() \
185 do \
187 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
188 atomic_write_barrier (); \
190 while (0)
191 #define THREAD_GSCOPE_WAIT() \
192 GL(dl_wait_lookup_done) ()
194 #endif /* __ASSEMBLER__ */
196 #endif /* tls.h */