1 /* Definition for thread-local data handling. NPTL/SH 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>
30 /* Type for the dtv. */
44 uintptr_t pointer_guard
;
47 # define TLS_MULTIPLE_THREADS_IN_TCB 1
49 #else /* __ASSEMBLER__ */
50 # include <tcb-offsets.h>
51 #endif /* __ASSEMBLER__ */
54 /* We require TLS support in the tools. */
55 #ifndef HAVE_TLS_SUPPORT
56 # error "TLS support is required."
61 /* Get system call information. */
64 /* This is the size of the initial TCB. */
65 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
67 /* Alignment requirements for the initial TCB. */
68 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
70 /* This is the size of the TCB. */
71 # define TLS_TCB_SIZE sizeof (tcbhead_t)
73 /* This is the size we need before TCB. */
74 # define TLS_PRE_TCB_SIZE sizeof (struct pthread)
76 /* Alignment requirements for the TCB. */
77 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
79 /* The TLS blocks start right after the TCB. */
80 # define TLS_DTV_AT_TP 1
82 /* Get the thread descriptor definition. */
83 # include <nptl/descr.h>
85 /* Install the dtv pointer. The pointer passed is to the element with
86 index -1 which contain the length. */
87 # define INSTALL_DTV(tcbp, dtvp) \
88 ((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1
90 /* Install new dtv for current thread. */
91 # define INSTALL_NEW_DTV(dtv) \
92 ({ tcbhead_t *__tcbp; \
93 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
94 __tcbp->dtv = (dtv);})
96 /* Return dtv of given thread descriptor. */
97 # define GET_DTV(tcbp) \
98 (((tcbhead_t *) (tcbp))->dtv)
100 /* Code to initially initialize the thread pointer. This might need
101 special attention since 'errno' is not yet available and if the
102 operation can cause a failure 'errno' must not be touched. */
103 # define TLS_INIT_TP(tcbp, secondcall) \
104 ({ __asm __volatile ("ldc %0,gbr" : : "r" (tcbp)); 0; })
106 /* Return the address of the dtv for the current thread. */
107 # define THREAD_DTV() \
108 ({ tcbhead_t *__tcbp; \
109 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
112 /* Return the thread descriptor for the current thread.
113 The contained asm must *not* be marked volatile since otherwise
115 struct pthread *self = thread_self();
116 do not get optimized away. */
117 # define THREAD_SELF \
118 ({ struct pthread *__self; \
119 __asm ("stc gbr,%0" : "=r" (__self)); \
122 /* Magic for libthread_db to know how to do THREAD_SELF. */
123 # define DB_THREAD_SELF \
124 REGISTER (32, 32, REG_GBR * 4, -sizeof (struct pthread))
126 /* Read member of the thread descriptor directly. */
127 # define THREAD_GETMEM(descr, member) (descr->member)
129 /* Same as THREAD_GETMEM, but the member offset can be non-constant. */
130 # define THREAD_GETMEM_NC(descr, member, idx) (descr->member[idx])
132 /* Set member of the thread descriptor directly. */
133 # define THREAD_SETMEM(descr, member, value) \
134 descr->member = (value)
136 /* Same as THREAD_SETMEM, but the member offset can be non-constant. */
137 # define THREAD_SETMEM_NC(descr, member, idx, value) \
138 descr->member[idx] = (value)
140 #define THREAD_GET_POINTER_GUARD() \
141 ({ tcbhead_t *__tcbp; \
142 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
143 __tcbp->pointer_guard;})
144 #define THREAD_SET_POINTER_GUARD(value) \
145 ({ tcbhead_t *__tcbp; \
146 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
147 __tcbp->pointer_guard = (value);})
148 #define THREAD_COPY_POINTER_GUARD(descr) \
149 ({ tcbhead_t *__tcbp; \
150 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
151 ((tcbhead_t *) (descr + 1))->pointer_guard = __tcbp->pointer_guard;})
153 /* Get and set the global scope generation counter in struct pthread. */
154 #define THREAD_GSCOPE_FLAG_UNUSED 0
155 #define THREAD_GSCOPE_FLAG_USED 1
156 #define THREAD_GSCOPE_FLAG_WAIT 2
157 #define THREAD_GSCOPE_RESET_FLAG() \
160 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
161 THREAD_GSCOPE_FLAG_UNUSED); \
162 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
163 lll_private_futex_wake (&THREAD_SELF->header.gscope_flag, 1); \
166 #define THREAD_GSCOPE_SET_FLAG() \
169 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
170 atomic_write_barrier (); \
173 #define THREAD_GSCOPE_WAIT() \
174 GL(dl_wait_lookup_done) ()
176 #endif /* __ASSEMBLER__ */