1 /* Definition for thread-local data handling. NPTL/s390 version.
2 Copyright (C) 2003, 2004, 2005, 2006 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
23 #include <dl-sysdep.h>
32 /* Type for the dtv. */
46 void *tcb
; /* Pointer to the TCB. Not necessary the
47 thread descriptor used by libpthread. */
49 void *self
; /* Pointer to the thread descriptor. */
52 uintptr_t stack_guard
;
57 # define TLS_MULTIPLE_THREADS_IN_TCB 1
60 #else /* __ASSEMBLER__ */
61 # include <tcb-offsets.h>
65 /* We require TLS support in the tools. */
66 #ifndef HAVE_TLS_SUPPORT
67 # error "TLS support is required."
70 /* Alignment requirement for the stack. For IA-32 this is governed by
71 the SSE memory functions. */
72 #define STACK_ALIGN 16
75 /* Get system call information. */
78 /* Get the thread descriptor definition. */
79 # include <nptl/descr.h>
81 /* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
82 because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
83 struct pthread even when not linked with -lpthread. */
84 # define TLS_INIT_TCB_SIZE sizeof (struct pthread)
86 /* Alignment requirements for the initial TCB. */
87 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
89 /* This is the size of the TCB. */
90 # define TLS_TCB_SIZE sizeof (struct pthread)
92 /* Alignment requirements for the TCB. */
93 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
95 /* The TCB can have any size and the memory following the address the
96 thread pointer points to is unspecified. Allocate the TCB there. */
97 # define TLS_TCB_AT_TP 1
100 /* Install the dtv pointer. The pointer passed is to the element with
101 index -1 which contain the length. */
102 # define INSTALL_DTV(descr, dtvp) \
103 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
105 /* Install new dtv for current thread. */
106 # define INSTALL_NEW_DTV(dtv) \
107 (((tcbhead_t *) __builtin_thread_pointer ())->dtv = (dtv))
109 /* Return dtv of given thread descriptor. */
110 # define GET_DTV(descr) \
111 (((tcbhead_t *) (descr))->dtv)
113 #if defined NEED_DL_SYSINFO && defined SHARED
114 # define INIT_SYSINFO \
115 _head->sysinfo = GLRO(dl_sysinfo)
117 # define INIT_SYSINFO
120 /* Code to initially initialize the thread pointer. This might need
121 special attention since 'errno' is not yet available and if the
122 operation can cause a failure 'errno' must not be touched. */
123 # define TLS_INIT_TP(thrdescr, secondcall) \
124 ({ void *_thrdescr = (thrdescr); \
125 tcbhead_t *_head = _thrdescr; \
127 _head->tcb = _thrdescr; \
128 /* For now the thread descriptor is at the same address. */ \
129 _head->self = _thrdescr; \
130 /* New syscall handling support. */ \
133 __builtin_set_thread_pointer (_thrdescr); \
137 /* Return the address of the dtv for the current thread. */
138 # define THREAD_DTV() \
139 (((tcbhead_t *) __builtin_thread_pointer ())->dtv)
141 /* Return the thread descriptor for the current thread. */
142 # define THREAD_SELF ((struct pthread *) __builtin_thread_pointer ())
144 /* Magic for libthread_db to know how to do THREAD_SELF. */
145 # define DB_THREAD_SELF REGISTER (32, 32, 18 * 4, 0) \
146 REGISTER (64, __WORDSIZE, 18 * 8, 0)
148 /* Access to data in the thread descriptor is easy. */
149 #define THREAD_GETMEM(descr, member) \
151 #define THREAD_GETMEM_NC(descr, member, idx) \
153 #define THREAD_SETMEM(descr, member, value) \
154 descr->member = (value)
155 #define THREAD_SETMEM_NC(descr, member, idx, value) \
156 descr->member[idx] = (value)
158 /* Set the stack guard field in TCB head. */
159 #define THREAD_SET_STACK_GUARD(value) \
160 THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
161 #define THREAD_COPY_STACK_GUARD(descr) \
162 ((descr)->header.stack_guard \
163 = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
165 /* s390 doesn't have HP_TIMING_*, so for the time being
166 use stack_guard as pointer_guard. */
167 #define THREAD_GET_POINTER_GUARD() \
168 THREAD_GETMEM (THREAD_SELF, header.stack_guard)
169 #define THREAD_SET_POINTER_GUARD(value)
170 #define THREAD_COPY_POINTER_GUARD(descr)
172 /* Get and set the global scope generation counter in struct pthread. */
173 #define THREAD_GSCOPE_FLAG_UNUSED 0
174 #define THREAD_GSCOPE_FLAG_USED 1
175 #define THREAD_GSCOPE_FLAG_WAIT 2
176 #define THREAD_GSCOPE_RESET_FLAG() \
179 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
180 THREAD_GSCOPE_FLAG_UNUSED); \
181 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
182 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1); \
185 #define THREAD_GSCOPE_SET_FLAG() \
188 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
189 atomic_write_barrier (); \
192 #define THREAD_GSCOPE_WAIT() \
193 GL(dl_wait_lookup_done) ()
195 #endif /* __ASSEMBLER__ */