]> git.ipfire.org Git - thirdparty/glibc.git/blame - ports/sysdeps/mips/nptl/tls.h
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / ports / sysdeps / mips / nptl / tls.h
CommitLineData
e36da2da 1/* Definition for thread-local data handling. NPTL/MIPS version.
d4697bc9 2 Copyright (C) 2005-2014 Free Software Foundation, Inc.
e36da2da
AJ
3 This file is part of the GNU C Library.
4
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.
9
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.
14
15 You should have received a copy of the GNU Lesser General Public
ab84e3ff
PE
16 License along with the GNU C Library. If not, see
17 <http://www.gnu.org/licenses/>. */
e36da2da
AJ
18
19#ifndef _TLS_H
20#define _TLS_H 1
21
22#include <dl-sysdep.h>
23
24#ifndef __ASSEMBLER__
25# include <stdbool.h>
26# include <stddef.h>
27# include <stdint.h>
28
29/* Type for the dtv. */
30typedef union dtv
31{
32 size_t counter;
33 struct
34 {
35 void *val;
36 bool is_static;
37 } pointer;
38} dtv_t;
39
43301bd3
MR
40#ifdef __mips16
41/* MIPS16 uses GCC builtin to access the TP. */
42# define READ_THREAD_POINTER() (__builtin_thread_pointer ())
43#else
e36da2da
AJ
44/* Note: rd must be $v1 to be ABI-conformant. */
45# define READ_THREAD_POINTER() \
46 ({ void *__result; \
47 asm volatile (".set\tpush\n\t.set\tmips32r2\n\t" \
48 "rdhwr\t%0, $29\n\t.set\tpop" : "=v" (__result)); \
49 __result; })
43301bd3 50#endif
e36da2da
AJ
51
52#else /* __ASSEMBLER__ */
53# include <tcb-offsets.h>
54
55# define READ_THREAD_POINTER(rd) \
56 .set push; \
57 .set mips32r2; \
58 rdhwr rd, $29; \
59 .set pop
60#endif /* __ASSEMBLER__ */
61
62
e36da2da
AJ
63#ifndef __ASSEMBLER__
64
65/* Get system call information. */
66# include <sysdep.h>
67
68/* The TP points to the start of the thread blocks. */
69# define TLS_DTV_AT_TP 1
70
71/* Get the thread descriptor definition. */
72# include <nptl/descr.h>
73
74typedef struct
75{
76 dtv_t *dtv;
77 void *private;
78} tcbhead_t;
79
80/* This is the size of the initial TCB. Because our TCB is before the thread
81 pointer, we don't need this. */
82# define TLS_INIT_TCB_SIZE 0
83
84/* Alignment requirements for the initial TCB. */
85# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
86
87/* This is the size of the TCB. Because our TCB is before the thread
88 pointer, we don't need this. */
89# define TLS_TCB_SIZE 0
90
91/* Alignment requirements for the TCB. */
92# define TLS_TCB_ALIGN __alignof__ (struct pthread)
93
94/* This is the size we need before TCB - actually, it includes the TCB. */
95# define TLS_PRE_TCB_SIZE \
96 (sizeof (struct pthread) \
97 + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
98
99/* The thread pointer (in hardware register $29) points to the end of
100 the TCB + 0x7000, as for PowerPC. The pthread_descr structure is
101 immediately in front of the TCB. */
102# define TLS_TCB_OFFSET 0x7000
103
104/* Install the dtv pointer. The pointer passed is to the element with
105 index -1 which contain the length. */
106# define INSTALL_DTV(tcbp, dtvp) \
107 (((tcbhead_t *) (tcbp))[-1].dtv = (dtvp) + 1)
108
109/* Install new dtv for current thread. */
110# define INSTALL_NEW_DTV(dtv) \
111 (THREAD_DTV() = (dtv))
112
113/* Return dtv of given thread descriptor. */
114# define GET_DTV(tcbp) \
115 (((tcbhead_t *) (tcbp))[-1].dtv)
116
117/* Code to initially initialize the thread pointer. This might need
118 special attention since 'errno' is not yet available and if the
119 operation can cause a failure 'errno' must not be touched. */
120# define TLS_INIT_TP(tcbp, secondcall) \
121 ({ INTERNAL_SYSCALL_DECL (err); \
122 long result_var; \
123 result_var = INTERNAL_SYSCALL (set_thread_area, err, 1, \
124 (char *) (tcbp) + TLS_TCB_OFFSET); \
125 INTERNAL_SYSCALL_ERROR_P (result_var, err) \
126 ? "unknown error" : NULL; })
127
128/* Return the address of the dtv for the current thread. */
129# define THREAD_DTV() \
130 (((tcbhead_t *) (READ_THREAD_POINTER () - TLS_TCB_OFFSET))[-1].dtv)
131
132/* Return the thread descriptor for the current thread. */
133# define THREAD_SELF \
134 ((struct pthread *) (READ_THREAD_POINTER () \
135 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
136
137/* Magic for libthread_db to know how to do THREAD_SELF. */
138# define DB_THREAD_SELF \
139 CONST_THREAD_AREA (32, TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE)
140
141/* Access to data in the thread descriptor is easy. */
142# define THREAD_GETMEM(descr, member) \
143 descr->member
144# define THREAD_GETMEM_NC(descr, member, idx) \
145 descr->member[idx]
146# define THREAD_SETMEM(descr, member, value) \
147 descr->member = (value)
148# define THREAD_SETMEM_NC(descr, member, idx, value) \
149 descr->member[idx] = (value)
150
151/* l_tls_offset == 0 is perfectly valid on MIPS, so we have to use some
152 different value to mean unset l_tls_offset. */
153# define NO_TLS_OFFSET -1
154
30efab51
DJ
155/* Get and set the global scope generation counter in struct pthread. */
156#define THREAD_GSCOPE_FLAG_UNUSED 0
157#define THREAD_GSCOPE_FLAG_USED 1
158#define THREAD_GSCOPE_FLAG_WAIT 2
159#define THREAD_GSCOPE_RESET_FLAG() \
160 do \
161 { int __res \
162 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
163 THREAD_GSCOPE_FLAG_UNUSED); \
164 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
8c276674 165 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
30efab51
DJ
166 } \
167 while (0)
168#define THREAD_GSCOPE_SET_FLAG() \
169 do \
170 { \
171 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
172 atomic_write_barrier (); \
173 } \
174 while (0)
175#define THREAD_GSCOPE_WAIT() \
176 GL(dl_wait_lookup_done) ()
177
e36da2da
AJ
178#endif /* __ASSEMBLER__ */
179
180#endif /* tls.h */