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/>. */
22 #include <dl-sysdep.h>
29 # include <kernel-features.h>
34 void *tcb
; /* Pointer to the TCB. Not necessary the
35 thread descriptor used by libpthread. */
37 void *self
; /* Pointer to the thread descriptor. */
40 uintptr_t stack_guard
;
42 #ifndef __ASSUME_PRIVATE_FUTEX
45 int __glibc_reserved1
;
47 /* GCC split stack support. */
52 # define TLS_MULTIPLE_THREADS_IN_TCB 1
55 #else /* __ASSEMBLER__ */
56 # include <tcb-offsets.h>
60 /* Alignment requirement for the stack. For IA-32 this is governed by
61 the SSE memory functions. */
62 #define STACK_ALIGN 16
65 /* Get system call information. */
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)
108 # define INIT_SYSINFO
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. */ \
124 __builtin_set_thread_pointer (_thrdescr); \
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) \
145 #define THREAD_GETMEM_NC(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) \
156 __asm__ __volatile__ ("" : : : "a0", "a1"); \
157 THREAD_SETMEM (THREAD_SELF, header.stack_guard, value); \
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() \
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); \
184 #define THREAD_GSCOPE_SET_FLAG() \
187 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
188 atomic_write_barrier (); \
191 #define THREAD_GSCOPE_WAIT() \
192 GL(dl_wait_lookup_done) ()
194 #endif /* __ASSEMBLER__ */