1 /* Definition for thread-local data handling. nptl/IA-64 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
23 #include <dl-sysdep.h>
32 /* Type for the dtv. */
50 register struct pthread
*__thread_self
__asm__("r13");
52 # define TLS_MULTIPLE_THREADS_IN_TCB 1
54 #else /* __ASSEMBLER__ */
55 # include <tcb-offsets.h>
59 /* We require TLS support in the tools. */
60 #ifndef HAVE_TLS_SUPPORT
61 # error "TLS support is required."
64 /* Signal that TLS support is available. */
67 /* Alignment requirement for the stack. */
68 #define STACK_ALIGN 16
71 /* Get system call information. */
74 /* This is the size of the initial TCB. */
75 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
77 /* Alignment requirements for the initial TCB. */
78 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
80 /* This is the size of the TCB. */
81 # define TLS_TCB_SIZE sizeof (tcbhead_t)
83 /* This is the size we need before TCB.
84 If there is not any room for uintptr_t stack_guard and
85 uintptr_t pointer_guard in struct pthread's final padding,
86 we need to put struct pthread 16 byte slower. */
87 # define TLS_PRE_TCB_SIZE \
88 (sizeof (struct pthread) \
89 + (PTHREAD_STRUCT_END_PADDING < 2 * sizeof (uintptr_t) \
90 ? ((2 * sizeof (uintptr_t) + __alignof__ (struct pthread) - 1) \
91 & ~(__alignof__ (struct pthread) - 1)) \
94 /* Alignment requirements for the TCB. */
95 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
97 /* The DTV is allocated at the TP; the TCB is placed elsewhere. */
98 # define TLS_DTV_AT_TP 1
100 /* Get the thread descriptor definition. */
101 # include <nptl/descr.h>
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 *)__thread_self)->dtv = (DTV))
112 /* Return dtv of given thread descriptor. */
113 # define GET_DTV(descr) \
114 (((tcbhead_t *) (descr))->dtv)
116 #define THREAD_SELF_SYSINFO (((tcbhead_t *) __thread_self)->__private)
117 #define THREAD_SYSINFO(pd) \
118 (((tcbhead_t *) ((char *) (pd) + TLS_PRE_TCB_SIZE))->__private)
120 #if defined NEED_DL_SYSINFO
121 # define INIT_SYSINFO THREAD_SELF_SYSINFO = (void *) GLRO(dl_sysinfo)
123 # define INIT_SYSINFO NULL
126 /* Code to initially initialize the thread pointer. This might need
127 special attention since 'errno' is not yet available and if the
128 operation can cause a failure 'errno' must not be touched. */
129 # define TLS_INIT_TP(thrdescr, secondcall) \
130 (__thread_self = (thrdescr), INIT_SYSINFO, NULL)
132 /* Return the address of the dtv for the current thread. */
133 # define THREAD_DTV() \
134 (((tcbhead_t *)__thread_self)->dtv)
136 /* Return the thread descriptor for the current thread. */
137 # define THREAD_SELF \
138 ((struct pthread *) ((char *) __thread_self - TLS_PRE_TCB_SIZE))
140 /* Magic for libthread_db to know how to do THREAD_SELF. */
141 # define DB_THREAD_SELF REGISTER (64, 64, 13 * 8, -TLS_PRE_TCB_SIZE)
143 /* Access to data in the thread descriptor is easy. */
144 #define THREAD_GETMEM(descr, member) \
146 #define THREAD_GETMEM_NC(descr, member, idx) \
148 #define THREAD_SETMEM(descr, member, value) \
149 descr->member = (value)
150 #define THREAD_SETMEM_NC(descr, member, idx, value) \
151 descr->member[idx] = (value)
153 /* Set the stack guard field in TCB head. */
154 #define THREAD_SET_STACK_GUARD(value) \
155 (((uintptr_t *) __thread_self)[-1] = (value))
156 #define THREAD_COPY_STACK_GUARD(descr) \
157 (((uintptr_t *) ((char *) (descr) + TLS_PRE_TCB_SIZE))[-1] \
158 = ((uintptr_t *) __thread_self)[-1])
160 /* Set the pointer guard field in TCB head. */
161 #define THREAD_GET_POINTER_GUARD() \
162 (((uintptr_t *) __thread_self)[-2])
163 #define THREAD_SET_POINTER_GUARD(value) \
164 (((uintptr_t *) __thread_self)[-2] = (value))
165 #define THREAD_COPY_POINTER_GUARD(descr) \
166 (((uintptr_t *) ((char *) (descr) + TLS_PRE_TCB_SIZE))[-2] \
167 = THREAD_GET_POINTER_GUARD ())
169 /* Get and set the global scope generation counter in struct pthread. */
170 #define THREAD_GSCOPE_FLAG_UNUSED 0
171 #define THREAD_GSCOPE_FLAG_USED 1
172 #define THREAD_GSCOPE_FLAG_WAIT 2
173 #define THREAD_GSCOPE_RESET_FLAG() \
176 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
177 THREAD_GSCOPE_FLAG_UNUSED); \
178 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
179 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1); \
182 #define THREAD_GSCOPE_SET_FLAG() \
185 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
186 atomic_write_barrier (); \
189 #define THREAD_GSCOPE_WAIT() \
190 GL(dl_wait_lookup_done) ()
192 #endif /* __ASSEMBLER__ */