Update copyright notices with scripts/update-copyrights
[glibc.git] / nptl / sysdeps / s390 / tls.h
blobd81019e4d3aee4265e23439c9bf6f785ee1af1f2
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 /* Get the thread descriptor definition. */
77 # include <nptl/descr.h>
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)
84 /* Alignment requirements for the initial TCB. */
85 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
87 /* This is the size of the TCB. */
88 # define TLS_TCB_SIZE sizeof (struct pthread)
90 /* Alignment requirements for the TCB. */
91 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
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
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
103 /* Install new dtv for current thread. */
104 # define INSTALL_NEW_DTV(dtv) \
105 (((tcbhead_t *) __builtin_thread_pointer ())->dtv = (dtv))
107 /* Return dtv of given thread descriptor. */
108 # define GET_DTV(descr) \
109 (((tcbhead_t *) (descr))->dtv)
111 #if defined NEED_DL_SYSINFO && defined SHARED
112 # define INIT_SYSINFO \
113 _head->sysinfo = GLRO(dl_sysinfo)
114 #else
115 # define INIT_SYSINFO
116 #endif
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; \
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; \
131 __builtin_set_thread_pointer (_thrdescr); \
132 NULL; \
135 /* Return the address of the dtv for the current thread. */
136 # define THREAD_DTV() \
137 (((tcbhead_t *) __builtin_thread_pointer ())->dtv)
139 /* Return the thread descriptor for the current thread. */
140 # define THREAD_SELF ((struct pthread *) __builtin_thread_pointer ())
142 /* Magic for libthread_db to know how to do THREAD_SELF. */
143 # define DB_THREAD_SELF REGISTER (32, 32, 18 * 4, 0) \
144 REGISTER (64, __WORDSIZE, 18 * 8, 0)
146 /* Access to data in the thread descriptor is easy. */
147 #define THREAD_GETMEM(descr, member) \
148 descr->member
149 #define THREAD_GETMEM_NC(descr, member, idx) \
150 descr->member[idx]
151 #define THREAD_SETMEM(descr, member, value) \
152 descr->member = (value)
153 #define THREAD_SETMEM_NC(descr, member, idx, value) \
154 descr->member[idx] = (value)
156 /* Set the stack guard field in TCB head. */
157 #define THREAD_SET_STACK_GUARD(value) \
158 do \
160 __asm __volatile ("" : : : "a0", "a1"); \
161 THREAD_SETMEM (THREAD_SELF, header.stack_guard, value); \
163 while (0)
164 #define THREAD_COPY_STACK_GUARD(descr) \
165 ((descr)->header.stack_guard \
166 = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
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)
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) \
185 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
187 while (0)
188 #define THREAD_GSCOPE_SET_FLAG() \
189 do \
191 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
192 atomic_write_barrier (); \
194 while (0)
195 #define THREAD_GSCOPE_WAIT() \
196 GL(dl_wait_lookup_done) ()
198 #endif /* __ASSEMBLER__ */
200 #endif /* tls.h */