.
[glibc.git] / nptl / sysdeps / s390 / tls.h
blob8e8f86d64ea45ba6a0a309916a832581ee0e147c
1 /* Definition for thread-local data handling. NPTL/s390 version.
2 Copyright (C) 2003, 2004, 2005, 2007 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _TLS_H
21 #define _TLS_H 1
23 #include <dl-sysdep.h>
24 #ifndef __ASSEMBLER__
25 # include <stdbool.h>
26 # include <stddef.h>
27 # include <stdint.h>
28 # include <stdlib.h>
29 # include <list.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 } tcbhead_t;
56 # ifndef __s390x__
57 # define TLS_MULTIPLE_THREADS_IN_TCB 1
58 # endif
60 #else /* __ASSEMBLER__ */
61 # include <tcb-offsets.h>
62 #endif
65 /* We require TLS support in the tools. */
66 #ifndef HAVE_TLS_SUPPORT
67 # error "TLS support is required."
68 #endif
70 /* Signal that TLS support is available. */
71 #define USE_TLS 1
73 /* Alignment requirement for the stack. For IA-32 this is governed by
74 the SSE memory functions. */
75 #define STACK_ALIGN 16
77 #ifndef __ASSEMBLER__
78 /* Get system call information. */
79 # include <sysdep.h>
81 /* Get the thread descriptor definition. */
82 # include <nptl/descr.h>
84 /* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
85 because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
86 struct pthread even when not linked with -lpthread. */
87 # define TLS_INIT_TCB_SIZE sizeof (struct pthread)
89 /* Alignment requirements for the initial TCB. */
90 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
92 /* This is the size of the TCB. */
93 # define TLS_TCB_SIZE sizeof (struct pthread)
95 /* Alignment requirements for the TCB. */
96 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
98 /* The TCB can have any size and the memory following the address the
99 thread pointer points to is unspecified. Allocate the TCB there. */
100 # define TLS_TCB_AT_TP 1
103 /* Install the dtv pointer. The pointer passed is to the element with
104 index -1 which contain the length. */
105 # define INSTALL_DTV(descr, dtvp) \
106 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
108 /* Install new dtv for current thread. */
109 # define INSTALL_NEW_DTV(dtv) \
110 (((tcbhead_t *) __builtin_thread_pointer ())->dtv = (dtv))
112 /* Return dtv of given thread descriptor. */
113 # define GET_DTV(descr) \
114 (((tcbhead_t *) (descr))->dtv)
116 #if defined NEED_DL_SYSINFO && defined SHARED
117 # define INIT_SYSINFO \
118 _head->sysinfo = GLRO(dl_sysinfo)
119 #else
120 # define INIT_SYSINFO
121 #endif
123 /* Code to initially initialize the thread pointer. This might need
124 special attention since 'errno' is not yet available and if the
125 operation can cause a failure 'errno' must not be touched. */
126 # define TLS_INIT_TP(thrdescr, secondcall) \
127 ({ void *_thrdescr = (thrdescr); \
128 tcbhead_t *_head = _thrdescr; \
130 _head->tcb = _thrdescr; \
131 /* For now the thread descriptor is at the same address. */ \
132 _head->self = _thrdescr; \
133 /* New syscall handling support. */ \
134 INIT_SYSINFO; \
136 __builtin_set_thread_pointer (_thrdescr); \
137 NULL; \
140 /* Return the address of the dtv for the current thread. */
141 # define THREAD_DTV() \
142 (((tcbhead_t *) __builtin_thread_pointer ())->dtv)
144 /* Return the thread descriptor for the current thread. */
145 # define THREAD_SELF ((struct pthread *) __builtin_thread_pointer ())
147 /* Magic for libthread_db to know how to do THREAD_SELF. */
148 # define DB_THREAD_SELF REGISTER (32, 32, 18 * 4, 0) \
149 REGISTER (64, __WORDSIZE, 18 * 8, 0)
151 /* Access to data in the thread descriptor is easy. */
152 #define THREAD_GETMEM(descr, member) \
153 descr->member
154 #define THREAD_GETMEM_NC(descr, member, idx) \
155 descr->member[idx]
156 #define THREAD_SETMEM(descr, member, value) \
157 descr->member = (value)
158 #define THREAD_SETMEM_NC(descr, member, idx, value) \
159 descr->member[idx] = (value)
161 /* Set the stack guard field in TCB head. */
162 #define THREAD_SET_STACK_GUARD(value) \
163 THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
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); \
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 */