1 /* Definition for thread-local data handling. NPTL/s390 version.
2 Copyright (C) 2003, 2004, 2005 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
;
56 # define TLS_MULTIPLE_THREADS_IN_TCB 1
59 #else /* __ASSEMBLER__ */
60 # include <tcb-offsets.h>
64 /* We require TLS support in the tools. */
65 #ifndef HAVE_TLS_SUPPORT
66 # error "TLS support is required."
69 /* Signal that TLS support is available. */
72 /* Alignment requirement for the stack. For IA-32 this is governed by
73 the SSE memory functions. */
74 #define STACK_ALIGN 16
77 /* Get system call information. */
80 /* Get the thread descriptor definition. */
81 # include <nptl/descr.h>
83 /* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
84 because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
85 struct pthread even when not linked with -lpthread. */
86 # define TLS_INIT_TCB_SIZE sizeof (struct pthread)
88 /* Alignment requirements for the initial TCB. */
89 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
91 /* This is the size of the TCB. */
92 # define TLS_TCB_SIZE sizeof (struct pthread)
94 /* Alignment requirements for the TCB. */
95 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
97 /* The TCB can have any size and the memory following the address the
98 thread pointer points to is unspecified. Allocate the TCB there. */
99 # define TLS_TCB_AT_TP 1
102 /* Install the dtv pointer. The pointer passed is to the element with
103 index -1 which contain the length. */
104 # define INSTALL_DTV(descr, dtvp) \
105 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
107 /* Install new dtv for current thread. */
108 # define INSTALL_NEW_DTV(dtv) \
109 (((tcbhead_t *) __builtin_thread_pointer ())->dtv = (dtv))
111 /* Return dtv of given thread descriptor. */
112 # define GET_DTV(descr) \
113 (((tcbhead_t *) (descr))->dtv)
115 #if defined NEED_DL_SYSINFO && defined SHARED
116 # define INIT_SYSINFO \
117 _head->sysinfo = GLRO(dl_sysinfo)
119 # define INIT_SYSINFO
122 /* Code to initially initialize the thread pointer. This might need
123 special attention since 'errno' is not yet available and if the
124 operation can cause a failure 'errno' must not be touched. */
125 # define TLS_INIT_TP(thrdescr, secondcall) \
126 ({ void *_thrdescr = (thrdescr); \
127 tcbhead_t *_head = _thrdescr; \
129 _head->tcb = _thrdescr; \
130 /* For now the thread descriptor is at the same address. */ \
131 _head->self = _thrdescr; \
132 /* New syscall handling support. */ \
135 __builtin_set_thread_pointer (_thrdescr); \
139 /* Return the address of the dtv for the current thread. */
140 # define THREAD_DTV() \
141 (((tcbhead_t *) __builtin_thread_pointer ())->dtv)
143 /* Return the thread descriptor for the current thread. */
144 # define THREAD_SELF ((struct pthread *) __builtin_thread_pointer ())
146 /* Magic for libthread_db to know how to do THREAD_SELF. */
147 # define DB_THREAD_SELF REGISTER (32, 32, 18 * 4, 0) \
148 REGISTER (64, __WORDSIZE, 18 * 8, 0)
150 /* Access to data in the thread descriptor is easy. */
151 #define THREAD_GETMEM(descr, member) \
153 #define THREAD_GETMEM_NC(descr, member, idx) \
155 #define THREAD_SETMEM(descr, member, value) \
156 descr->member = (value)
157 #define THREAD_SETMEM_NC(descr, member, idx, value) \
158 descr->member[idx] = (value)
160 /* Set the stack guard field in TCB head. */
161 #define THREAD_SET_STACK_GUARD(value) \
162 THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
163 #define THREAD_COPY_STACK_GUARD(descr) \
164 ((descr)->header.stack_guard \
165 = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
167 #endif /* __ASSEMBLER__ */