Remove .cvsignore files
[glibc-ports.git] / sysdeps / mips / nptl / tls.h
blob20f9f96832e785dd02e6e75e2c9d871003ef6988
1 /* Definition for thread-local data handling. NPTL/MIPS version.
2 Copyright (C) 2005, 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
18 02111-1307 USA. */
20 #ifndef _TLS_H
21 #define _TLS_H 1
23 #include <dl-sysdep.h>
25 #ifndef __ASSEMBLER__
26 # include <stdbool.h>
27 # include <stddef.h>
28 # include <stdint.h>
30 /* Type for the dtv. */
31 typedef union dtv
33 size_t counter;
34 struct
36 void *val;
37 bool is_static;
38 } pointer;
39 } dtv_t;
41 /* Note: rd must be $v1 to be ABI-conformant. */
42 # define READ_THREAD_POINTER() \
43 ({ void *__result; \
44 asm volatile (".set\tpush\n\t.set\tmips32r2\n\t" \
45 "rdhwr\t%0, $29\n\t.set\tpop" : "=v" (__result)); \
46 __result; })
48 #else /* __ASSEMBLER__ */
49 # include <tcb-offsets.h>
51 # define READ_THREAD_POINTER(rd) \
52 .set push; \
53 .set mips32r2; \
54 rdhwr rd, $29; \
55 .set pop
56 #endif /* __ASSEMBLER__ */
59 /* We require TLS support in the tools. */
60 #ifndef HAVE_TLS_SUPPORT
61 # error "TLS support is required."
62 #endif
64 /* Signal that TLS support is available. */
65 #define USE_TLS 1
67 #ifndef __ASSEMBLER__
69 /* Get system call information. */
70 # include <sysdep.h>
72 /* The TP points to the start of the thread blocks. */
73 # define TLS_DTV_AT_TP 1
75 /* Get the thread descriptor definition. */
76 # include <nptl/descr.h>
78 typedef struct
80 dtv_t *dtv;
81 void *private;
82 } tcbhead_t;
84 /* This is the size of the initial TCB. Because our TCB is before the thread
85 pointer, we don't need this. */
86 # define TLS_INIT_TCB_SIZE 0
88 /* Alignment requirements for the initial TCB. */
89 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
91 /* This is the size of the TCB. Because our TCB is before the thread
92 pointer, we don't need this. */
93 # define TLS_TCB_SIZE 0
95 /* Alignment requirements for the TCB. */
96 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
98 /* This is the size we need before TCB - actually, it includes the TCB. */
99 # define TLS_PRE_TCB_SIZE \
100 (sizeof (struct pthread) \
101 + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
103 /* The thread pointer (in hardware register $29) points to the end of
104 the TCB + 0x7000, as for PowerPC. The pthread_descr structure is
105 immediately in front of the TCB. */
106 # define TLS_TCB_OFFSET 0x7000
108 /* Install the dtv pointer. The pointer passed is to the element with
109 index -1 which contain the length. */
110 # define INSTALL_DTV(tcbp, dtvp) \
111 (((tcbhead_t *) (tcbp))[-1].dtv = (dtvp) + 1)
113 /* Install new dtv for current thread. */
114 # define INSTALL_NEW_DTV(dtv) \
115 (THREAD_DTV() = (dtv))
117 /* Return dtv of given thread descriptor. */
118 # define GET_DTV(tcbp) \
119 (((tcbhead_t *) (tcbp))[-1].dtv)
121 /* Code to initially initialize the thread pointer. This might need
122 special attention since 'errno' is not yet available and if the
123 operation can cause a failure 'errno' must not be touched. */
124 # define TLS_INIT_TP(tcbp, secondcall) \
125 ({ INTERNAL_SYSCALL_DECL (err); \
126 long result_var; \
127 result_var = INTERNAL_SYSCALL (set_thread_area, err, 1, \
128 (char *) (tcbp) + TLS_TCB_OFFSET); \
129 INTERNAL_SYSCALL_ERROR_P (result_var, err) \
130 ? "unknown error" : NULL; })
132 /* Return the address of the dtv for the current thread. */
133 # define THREAD_DTV() \
134 (((tcbhead_t *) (READ_THREAD_POINTER () - TLS_TCB_OFFSET))[-1].dtv)
136 /* Return the thread descriptor for the current thread. */
137 # define THREAD_SELF \
138 ((struct pthread *) (READ_THREAD_POINTER () \
139 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
141 /* Magic for libthread_db to know how to do THREAD_SELF. */
142 # define DB_THREAD_SELF \
143 CONST_THREAD_AREA (32, TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE)
145 /* Access to data in the thread descriptor is easy. */
146 # define THREAD_GETMEM(descr, member) \
147 descr->member
148 # define THREAD_GETMEM_NC(descr, member, idx) \
149 descr->member[idx]
150 # define THREAD_SETMEM(descr, member, value) \
151 descr->member = (value)
152 # define THREAD_SETMEM_NC(descr, member, idx, value) \
153 descr->member[idx] = (value)
155 /* l_tls_offset == 0 is perfectly valid on MIPS, so we have to use some
156 different value to mean unset l_tls_offset. */
157 # define NO_TLS_OFFSET -1
159 /* Get and set the global scope generation counter in struct pthread. */
160 #define THREAD_GSCOPE_FLAG_UNUSED 0
161 #define THREAD_GSCOPE_FLAG_USED 1
162 #define THREAD_GSCOPE_FLAG_WAIT 2
163 #define THREAD_GSCOPE_RESET_FLAG() \
164 do \
165 { int __res \
166 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
167 THREAD_GSCOPE_FLAG_UNUSED); \
168 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
169 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
171 while (0)
172 #define THREAD_GSCOPE_SET_FLAG() \
173 do \
175 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
176 atomic_write_barrier (); \
178 while (0)
179 #define THREAD_GSCOPE_WAIT() \
180 GL(dl_wait_lookup_done) ()
182 #endif /* __ASSEMBLER__ */
184 #endif /* tls.h */