1 /* Definition for thread-local data handling. NPTL/PowerPC 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
28 /* Type for the dtv. */
39 #else /* __ASSEMBLER__ */
40 # include <tcb-offsets.h>
41 #endif /* __ASSEMBLER__ */
43 /* We require TLS support in the tools. */
44 #define HAVE_TLS_SUPPORT 1
45 #define HAVE_TLS_MODEL_ATTRIBUTE 1
46 #define HAVE___THREAD 1
48 /* Signal that TLS support is available. */
51 /* We require TLS support in the tools. */
52 #ifndef HAVE_TLS_SUPPORT
53 # error "TLS support is required."
56 /* Signal that TLS support is available. */
61 /* Get system call information. */
62 //# include <sysdep.h>
64 /* The TP points to the start of the thread blocks. */
65 # define TLS_DTV_AT_TP 1
67 /* We use the multiple_threads field in the pthread struct */
68 #define TLS_MULTIPLE_THREADS_IN_TCB 1
70 /* Get the thread descriptor definition. */
71 # include <../../descr.h>
73 /* The stack_guard is accessed directly by GCC -fstack-protector code,
74 so it is a part of public ABI. The dtv and pointer_guard fields
78 uintptr_t pointer_guard;
79 uintptr_t stack_guard;
84 /* This is the size of the initial TCB. */
85 # define TLS_INIT_TCB_SIZE 0
87 /* Alignment requirements for the initial TCB. */
88 # define TLS_INIT_TCB_ALIGN __alignof__ (struct _pthread_descr_struct) //pthread)
90 /* This is the size of the TCB. */
91 # define TLS_TCB_SIZE 0
93 /* Alignment requirements for the TCB. */
94 # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct) //pthread)
96 /* This is the size we need before TCB. */
97 # define TLS_PRE_TCB_SIZE \
98 (sizeof (struct _pthread_descr_struct) \
99 + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
101 # ifndef __powerpc64__
102 /* Register r2 (tp) is reserved by the ABI as "thread pointer". */
103 register void *__thread_register __asm__ ("r2");
104 # define PT_THREAD_POINTER PT_R2
106 /* Register r13 (tp) is reserved by the ABI as "thread pointer". */
107 register void *__thread_register __asm__ ("r13");
108 # define PT_THREAD_POINTER PT_R13
111 /* The following assumes that TP (R2 or R13) points to the end of the
112 TCB + 0x7000 (per the ABI). This implies that TCB address is
113 TP - 0x7000. As we define TLS_DTV_AT_TP we can
114 assume that the pthread struct is allocated immediately ahead of the
115 TCB. This implies that the pthread_descr address is
116 TP - (TLS_PRE_TCB_SIZE + 0x7000). */
117 # define TLS_TCB_OFFSET 0x7000
119 /* Install the dtv pointer. The pointer passed is to the element with
120 index -1 which contain the length. */
121 # define INSTALL_DTV(tcbp, dtvp) \
122 ((tcbhead_t *) (tcbp))[-1].dtv = dtvp + 1
124 /* Install new dtv for current thread. */
125 # define INSTALL_NEW_DTV(dtv) (THREAD_DTV() = (dtv))
127 /* Return dtv of given thread descriptor. */
128 # define GET_DTV(tcbp) (((tcbhead_t *) (tcbp))[-1].dtv)
130 /* Code to initially initialize the thread pointer. This might need
131 special attention since 'errno' is not yet available and if the
132 operation can cause a failure 'errno' must not be touched. */
133 # define TLS_INIT_TP(tcbp, secondcall) \
134 (__thread_register = (void *) (tcbp) + TLS_TCB_OFFSET, NULL)
136 /* Return the address of the dtv for the current thread. */
137 # define THREAD_DTV() \
138 (((tcbhead_t *) (__thread_register - TLS_TCB_OFFSET))[-1].dtv)
140 /* Return the thread descriptor for the current thread. */
141 # define THREAD_SELF \
142 ((struct _pthread_descr_struct *) (__thread_register \
143 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
145 /* Magic for libthread_db to know how to do THREAD_SELF. */
146 # define DB_THREAD_SELF \
147 REGISTER (32, 32, PT_THREAD_POINTER * 4, \
148 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE) \
149 REGISTER (64, 64, PT_THREAD_POINTER * 8, \
150 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)
152 /* Read member of the thread descriptor directly. */
153 # define THREAD_GETMEM(descr, member) ((void)(descr), (THREAD_SELF)->member)
155 /* Same as THREAD_GETMEM, but the member offset can be non-constant. */
156 # define THREAD_GETMEM_NC(descr, member, idx) \
157 ((void)(descr), (THREAD_SELF)->member[idx])
159 /* Set member of the thread descriptor directly. */
160 # define THREAD_SETMEM(descr, member, value) \
161 ((void)(descr), (THREAD_SELF)->member = (value))
163 /* Same as THREAD_SETMEM, but the member offset can be non-constant. */
164 # define THREAD_SETMEM_NC(descr, member, idx, value) \
165 ((void)(descr), (THREAD_SELF)->member[idx] = (value))
167 /* Set the stack guard field in TCB head. */
168 # define THREAD_SET_STACK_GUARD(value) \
169 (((tcbhead_t *) ((char *) __thread_register \
170 - TLS_TCB_OFFSET))[-1].stack_guard = (value))
171 # define THREAD_COPY_STACK_GUARD(descr) \
172 (((tcbhead_t *) ((char *) (descr) \
173 + TLS_PRE_TCB_SIZE))[-1].stack_guard \
174 = ((tcbhead_t *) ((char *) __thread_register \
175 - TLS_TCB_OFFSET))[-1].stack_guard)
177 /* Set the stack guard field in TCB head. */
178 # define THREAD_GET_POINTER_GUARD() \
179 (((tcbhead_t *) ((char *) __thread_register \
180 - TLS_TCB_OFFSET))[-1].pointer_guard)
181 # define THREAD_SET_POINTER_GUARD(value) \
182 (THREAD_GET_POINTER_GUARD () = (value))
183 # define THREAD_COPY_POINTER_GUARD(descr) \
184 (((tcbhead_t *) ((char *) (descr) \
185 + TLS_PRE_TCB_SIZE))[-1].pointer_guard \
186 = THREAD_GET_POINTER_GUARD())
188 /* l_tls_offset == 0 is perfectly valid on PPC, so we have to use some
189 different value to mean unset l_tls_offset. */
190 # define NO_TLS_OFFSET -1
192 /* Get and set the global scope generation counter in struct pthread. */
193 #define THREAD_GSCOPE_FLAG_UNUSED 0
194 #define THREAD_GSCOPE_FLAG_USED 1
195 #define THREAD_GSCOPE_FLAG_WAIT 2
196 #define THREAD_GSCOPE_RESET_FLAG() \
199 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
200 THREAD_GSCOPE_FLAG_UNUSED); \
201 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
202 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
205 #define THREAD_GSCOPE_SET_FLAG() \
208 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
209 atomic_write_barrier (); \
212 #define THREAD_GSCOPE_WAIT() \
213 GL(dl_wait_lookup_done) ()
215 #endif /* __ASSEMBLER__ */