S390: Quash unused variable warning due to no-op THREAD_SET_POINTER_GUARD.
[glibc.git] / sysdeps / s390 / nptl / tls.h
blobbc0db4a1f986ce47812e1e9878add9d0b276a295
1 /* Definition for thread-local data handling. NPTL/s390 version.
2 Copyright (C) 2003-2014 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>
32 /* Type for the dtv. */
33 typedef union dtv
35 size_t counter;
36 struct
38 void *val;
39 bool is_static;
40 } pointer;
41 } dtv_t;
44 typedef struct
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;
51 uintptr_t sysinfo;
52 uintptr_t stack_guard;
53 int gscope_flag;
54 #ifndef __ASSUME_PRIVATE_FUTEX
55 int private_futex;
56 #endif
57 } tcbhead_t;
59 # ifndef __s390x__
60 # define TLS_MULTIPLE_THREADS_IN_TCB 1
61 # endif
63 #else /* __ASSEMBLER__ */
64 # include <tcb-offsets.h>
65 #endif
68 /* Alignment requirement for the stack. For IA-32 this is governed by
69 the SSE memory functions. */
70 #define STACK_ALIGN 16
72 #ifndef __ASSEMBLER__
73 /* Get system call information. */
74 # include <sysdep.h>
76 /* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
77 because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
78 struct pthread even when not linked with -lpthread. */
79 # define TLS_INIT_TCB_SIZE sizeof (struct pthread)
81 /* Alignment requirements for the initial TCB. */
82 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
84 /* This is the size of the TCB. */
85 # define TLS_TCB_SIZE sizeof (struct pthread)
87 /* Alignment requirements for the TCB. */
88 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
90 /* The TCB can have any size and the memory following the address the
91 thread pointer points to is unspecified. Allocate the TCB there. */
92 # define TLS_TCB_AT_TP 1
93 # define TLS_DTV_AT_TP 0
95 /* Get the thread descriptor definition. */
96 # include <nptl/descr.h>
99 /* Install the dtv pointer. The pointer passed is to the element with
100 index -1 which contain the length. */
101 # define INSTALL_DTV(descr, dtvp) \
102 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
104 /* Install new dtv for current thread. */
105 # define INSTALL_NEW_DTV(dtv) \
106 (((tcbhead_t *) __builtin_thread_pointer ())->dtv = (dtv))
108 /* Return dtv of given thread descriptor. */
109 # define GET_DTV(descr) \
110 (((tcbhead_t *) (descr))->dtv)
112 #if defined NEED_DL_SYSINFO && defined SHARED
113 # define INIT_SYSINFO \
114 _head->sysinfo = GLRO(dl_sysinfo)
115 #else
116 # define INIT_SYSINFO
117 #endif
119 /* Code to initially initialize the thread pointer. This might need
120 special attention since 'errno' is not yet available and if the
121 operation can cause a failure 'errno' must not be touched. */
122 # define TLS_INIT_TP(thrdescr) \
123 ({ void *_thrdescr = (thrdescr); \
124 tcbhead_t *_head = _thrdescr; \
126 _head->tcb = _thrdescr; \
127 /* For now the thread descriptor is at the same address. */ \
128 _head->self = _thrdescr; \
129 /* New syscall handling support. */ \
130 INIT_SYSINFO; \
132 __builtin_set_thread_pointer (_thrdescr); \
133 NULL; \
136 /* Value passed to 'clone' for initialization of the thread register. */
137 # define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd)
139 /* Return the address of the dtv for the current thread. */
140 # define THREAD_DTV() \
141 (((tcbhead_t *) __builtin_thread_pointer ())->dtv)
143 /* Return the thread descriptor for the current thread. */
144 # define THREAD_SELF ((struct pthread *) __builtin_thread_pointer ())
146 /* Magic for libthread_db to know how to do THREAD_SELF. */
147 # define DB_THREAD_SELF REGISTER (32, 32, 18 * 4, 0) \
148 REGISTER (64, __WORDSIZE, 18 * 8, 0)
150 /* Access to data in the thread descriptor is easy. */
151 #define THREAD_GETMEM(descr, member) \
152 descr->member
153 #define THREAD_GETMEM_NC(descr, member, idx) \
154 descr->member[idx]
155 #define THREAD_SETMEM(descr, member, value) \
156 descr->member = (value)
157 #define THREAD_SETMEM_NC(descr, member, idx, value) \
158 descr->member[idx] = (value)
160 /* Set the stack guard field in TCB head. */
161 #define THREAD_SET_STACK_GUARD(value) \
162 do \
164 __asm __volatile ("" : : : "a0", "a1"); \
165 THREAD_SETMEM (THREAD_SELF, header.stack_guard, value); \
167 while (0)
168 #define THREAD_COPY_STACK_GUARD(descr) \
169 ((descr)->header.stack_guard \
170 = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
172 /* s390 doesn't have HP_TIMING_*, so for the time being
173 use stack_guard as pointer_guard. */
174 #define THREAD_GET_POINTER_GUARD() \
175 THREAD_GETMEM (THREAD_SELF, header.stack_guard)
176 #define THREAD_SET_POINTER_GUARD(value) ((void) (value))
177 #define THREAD_COPY_POINTER_GUARD(descr)
179 /* Get and set the global scope generation counter in struct pthread. */
180 #define THREAD_GSCOPE_FLAG_UNUSED 0
181 #define THREAD_GSCOPE_FLAG_USED 1
182 #define THREAD_GSCOPE_FLAG_WAIT 2
183 #define THREAD_GSCOPE_RESET_FLAG() \
184 do \
185 { int __res \
186 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
187 THREAD_GSCOPE_FLAG_UNUSED); \
188 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
189 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
191 while (0)
192 #define THREAD_GSCOPE_SET_FLAG() \
193 do \
195 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
196 atomic_write_barrier (); \
198 while (0)
199 #define THREAD_GSCOPE_WAIT() \
200 GL(dl_wait_lookup_done) ()
202 #endif /* __ASSEMBLER__ */
204 #endif /* tls.h */