2.9
[glibc/nacl-glibc.git] / nptl / sysdeps / s390 / tls.h
blob2b38ed4e7d63a369955ab8d9fc8bcff4ec30fda7
1 /* Definition for thread-local data handling. NPTL/s390 version.
2 Copyright (C) 2003, 2004, 2005, 2006, 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>
30 # include <kernel-features.h>
33 /* Type for the dtv. */
34 typedef union dtv
36 size_t counter;
37 struct
39 void *val;
40 bool is_static;
41 } pointer;
42 } dtv_t;
45 typedef struct
47 void *tcb; /* Pointer to the TCB. Not necessary the
48 thread descriptor used by libpthread. */
49 dtv_t *dtv;
50 void *self; /* Pointer to the thread descriptor. */
51 int multiple_threads;
52 uintptr_t sysinfo;
53 uintptr_t stack_guard;
54 int gscope_flag;
55 #ifndef __ASSUME_PRIVATE_FUTEX
56 int private_futex;
57 #endif
58 } tcbhead_t;
60 # ifndef __s390x__
61 # define TLS_MULTIPLE_THREADS_IN_TCB 1
62 # endif
64 #else /* __ASSEMBLER__ */
65 # include <tcb-offsets.h>
66 #endif
69 /* We require TLS support in the tools. */
70 #ifndef HAVE_TLS_SUPPORT
71 # error "TLS support is required."
72 #endif
74 /* Alignment requirement for the stack. For IA-32 this is governed by
75 the SSE memory functions. */
76 #define STACK_ALIGN 16
78 #ifndef __ASSEMBLER__
79 /* Get system call information. */
80 # include <sysdep.h>
82 /* Get the thread descriptor definition. */
83 # include <nptl/descr.h>
85 /* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
86 because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
87 struct pthread even when not linked with -lpthread. */
88 # define TLS_INIT_TCB_SIZE sizeof (struct pthread)
90 /* Alignment requirements for the initial TCB. */
91 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
93 /* This is the size of the TCB. */
94 # define TLS_TCB_SIZE sizeof (struct pthread)
96 /* Alignment requirements for the TCB. */
97 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
99 /* The TCB can have any size and the memory following the address the
100 thread pointer points to is unspecified. Allocate the TCB there. */
101 # define TLS_TCB_AT_TP 1
104 /* Install the dtv pointer. The pointer passed is to the element with
105 index -1 which contain the length. */
106 # define INSTALL_DTV(descr, dtvp) \
107 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
109 /* Install new dtv for current thread. */
110 # define INSTALL_NEW_DTV(dtv) \
111 (((tcbhead_t *) __builtin_thread_pointer ())->dtv = (dtv))
113 /* Return dtv of given thread descriptor. */
114 # define GET_DTV(descr) \
115 (((tcbhead_t *) (descr))->dtv)
117 #if defined NEED_DL_SYSINFO && defined SHARED
118 # define INIT_SYSINFO \
119 _head->sysinfo = GLRO(dl_sysinfo)
120 #else
121 # define INIT_SYSINFO
122 #endif
124 /* Code to initially initialize the thread pointer. This might need
125 special attention since 'errno' is not yet available and if the
126 operation can cause a failure 'errno' must not be touched. */
127 # define TLS_INIT_TP(thrdescr, secondcall) \
128 ({ void *_thrdescr = (thrdescr); \
129 tcbhead_t *_head = _thrdescr; \
131 _head->tcb = _thrdescr; \
132 /* For now the thread descriptor is at the same address. */ \
133 _head->self = _thrdescr; \
134 /* New syscall handling support. */ \
135 INIT_SYSINFO; \
137 __builtin_set_thread_pointer (_thrdescr); \
138 NULL; \
141 /* Return the address of the dtv for the current thread. */
142 # define THREAD_DTV() \
143 (((tcbhead_t *) __builtin_thread_pointer ())->dtv)
145 /* Return the thread descriptor for the current thread. */
146 # define THREAD_SELF ((struct pthread *) __builtin_thread_pointer ())
148 /* Magic for libthread_db to know how to do THREAD_SELF. */
149 # define DB_THREAD_SELF REGISTER (32, 32, 18 * 4, 0) \
150 REGISTER (64, __WORDSIZE, 18 * 8, 0)
152 /* Access to data in the thread descriptor is easy. */
153 #define THREAD_GETMEM(descr, member) \
154 descr->member
155 #define THREAD_GETMEM_NC(descr, member, idx) \
156 descr->member[idx]
157 #define THREAD_SETMEM(descr, member, value) \
158 descr->member = (value)
159 #define THREAD_SETMEM_NC(descr, member, idx, value) \
160 descr->member[idx] = (value)
162 /* Set the stack guard field in TCB head. */
163 #define THREAD_SET_STACK_GUARD(value) \
164 do \
166 __asm __volatile ("" : : : "a0", "a1"); \
167 THREAD_SETMEM (THREAD_SELF, header.stack_guard, value); \
169 while (0)
170 #define THREAD_COPY_STACK_GUARD(descr) \
171 ((descr)->header.stack_guard \
172 = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
174 /* s390 doesn't have HP_TIMING_*, so for the time being
175 use stack_guard as pointer_guard. */
176 #define THREAD_GET_POINTER_GUARD() \
177 THREAD_GETMEM (THREAD_SELF, header.stack_guard)
178 #define THREAD_SET_POINTER_GUARD(value)
179 #define THREAD_COPY_POINTER_GUARD(descr)
181 /* Get and set the global scope generation counter in struct pthread. */
182 #define THREAD_GSCOPE_FLAG_UNUSED 0
183 #define THREAD_GSCOPE_FLAG_USED 1
184 #define THREAD_GSCOPE_FLAG_WAIT 2
185 #define THREAD_GSCOPE_RESET_FLAG() \
186 do \
187 { int __res \
188 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
189 THREAD_GSCOPE_FLAG_UNUSED); \
190 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
191 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
193 while (0)
194 #define THREAD_GSCOPE_SET_FLAG() \
195 do \
197 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
198 atomic_write_barrier (); \
200 while (0)
201 #define THREAD_GSCOPE_WAIT() \
202 GL(dl_wait_lookup_done) ()
204 #endif /* __ASSEMBLER__ */
206 #endif /* tls.h */