1 /* Definitions for thread-local data handling. NPTL/sparc version.
2 Copyright (C) 2003, 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>
31 /* Type for the dtv. */
44 void *tcb; /* Pointer to the TCB. Not necessary the
45 thread descriptor used by libpthread. */
53 uintptr_t stack_guard;
54 uintptr_t pointer_guard;
60 #else /* __ASSEMBLER__ */
61 # include <tcb-offsets.h>
62 #endif /* __ASSEMBLER__ */
64 /* We require TLS support in the tools. */
65 #ifndef HAVE_TLS_SUPPORT
66 # error "TLS support is required."
70 /* Get system call information. */
73 /* Get the thread descriptor definition. */
74 # include <nptl/descr.h>
76 register struct pthread *__thread_self __asm__("%g7");
78 /* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
79 because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
80 struct pthread even when not linked with -lpthread. */
81 # define TLS_INIT_TCB_SIZE sizeof (struct pthread)
83 /* Alignment requirements for the initial TCB. */
84 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
86 /* This is the size of the TCB. */
87 # define TLS_TCB_SIZE sizeof (struct pthread)
89 /* Alignment requirements for the TCB. */
90 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
92 /* The TCB can have any size and the memory following the address the
93 thread pointer points to is unspecified. Allocate the TCB there. */
94 # define TLS_TCB_AT_TP 1
96 /* Install the dtv pointer. The pointer passed is to the element with
97 index -1 which contain the length. */
98 # define INSTALL_DTV(descr, dtvp) \
99 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
101 /* Install new dtv for current thread. */
102 # define INSTALL_NEW_DTV(DTV) \
103 (((tcbhead_t *) __thread_self)->dtv = (DTV))
105 /* Return dtv of given thread descriptor. */
106 # define GET_DTV(descr) \
107 (((tcbhead_t *) (descr))->dtv)
109 /* Code to initially initialize the thread pointer. */
110 # define TLS_INIT_TP(descr, secondcall) \
111 (__thread_self = (__typeof (__thread_self)) (descr), NULL)
113 /* Return the address of the dtv for the current thread. */
114 # define THREAD_DTV() \
115 (((tcbhead_t *) __thread_self)->dtv)
117 /* Return the thread descriptor for the current thread. */
118 #define THREAD_SELF __thread_self
120 /* Magic for libthread_db to know how to do THREAD_SELF. */
121 # define DB_THREAD_SELF_INCLUDE <sys/ucontext.h>
122 # define DB_THREAD_SELF \
123 REGISTER (32, 32, REG_G7 * 4, 0) REGISTER (64, 64, REG_G7 * 8, 0)
125 /* Access to data in the thread descriptor is easy. */
126 #define THREAD_GETMEM(descr, member) \
128 #define THREAD_GETMEM_NC(descr, member, idx) \
130 #define THREAD_SETMEM(descr, member, value) \
131 descr->member = (value)
132 #define THREAD_SETMEM_NC(descr, member, idx, value) \
133 descr->member[idx] = (value)
135 /* Set the stack guard field in TCB head. */
136 #define THREAD_SET_STACK_GUARD(value) \
137 THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
138 # define THREAD_COPY_STACK_GUARD(descr) \
139 ((descr)->header.stack_guard \
140 = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
142 /* Get/set the stack guard field in TCB head. */
143 #define THREAD_GET_POINTER_GUARD() \
144 THREAD_GETMEM (THREAD_SELF, header.pointer_guard)
145 #define THREAD_SET_POINTER_GUARD(value) \
146 THREAD_SETMEM (THREAD_SELF, header.pointer_guard, value)
147 # define THREAD_COPY_POINTER_GUARD(descr) \
148 ((descr)->header.pointer_guard = THREAD_GET_POINTER_GUARD ())
150 /* Get and set the global scope generation counter in struct pthread. */
151 #define THREAD_GSCOPE_FLAG_UNUSED 0
152 #define THREAD_GSCOPE_FLAG_USED 1
153 #define THREAD_GSCOPE_FLAG_WAIT 2
154 #define THREAD_GSCOPE_RESET_FLAG() \
157 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
158 THREAD_GSCOPE_FLAG_UNUSED); \
159 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
160 lll_private_futex_wake (&THREAD_SELF->header.gscope_flag, 1); \
163 #define THREAD_GSCOPE_SET_FLAG() \
166 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
167 atomic_write_barrier (); \
170 #define THREAD_GSCOPE_WAIT() \
171 GL(dl_wait_lookup_done) ()
173 #endif /* !ASSEMBLER */