]> sourceware.org Git - glibc.git/blame - sysdeps/mips/nptl/tls.h
Remove TLS_TCB_ALIGN and TLS_INIT_TCB_ALIGN
[glibc.git] / sysdeps / mips / nptl / tls.h
CommitLineData
e36da2da 1/* Definition for thread-local data handling. NPTL/MIPS version.
2b778ceb 2 Copyright (C) 2005-2021 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 16 License along with the GNU C Library. If not, see
5a82c748 17 <https://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>
aca1daef
FW
28# include <dl-dtv.h>
29
7498d767
AB
30/* Get system call information. */
31# include <sysdep.h>
e36da2da 32
43301bd3
MR
33#ifdef __mips16
34/* MIPS16 uses GCC builtin to access the TP. */
35# define READ_THREAD_POINTER() (__builtin_thread_pointer ())
36#else
e36da2da 37/* Note: rd must be $v1 to be ABI-conformant. */
fcb78a55 38# if defined (__mips_isa_rev) && __mips_isa_rev >= 2
7498d767
AB
39# define READ_THREAD_POINTER() \
40 ({ void *__result; \
41 asm volatile ("rdhwr\t%0, $29" : "=v" (__result)); \
42 __result; })
43# else
44# define READ_THREAD_POINTER() \
45 ({ void *__result; \
46 asm volatile (".set\tpush\n\t.set\tmips32r2\n\t" \
47 "rdhwr\t%0, $29\n\t.set\tpop" : "=v" (__result)); \
48 __result; })
49# endif
43301bd3 50#endif
e36da2da
AJ
51
52#else /* __ASSEMBLER__ */
53# include <tcb-offsets.h>
54
7498d767
AB
55# if __mips_isa_rev >= 2
56# define READ_THREAD_POINTER(rd) rdhwr rd, $29
57# else
58# define READ_THREAD_POINTER(rd) \
59 .set push; \
60 .set mips32r2; \
61 rdhwr rd, $29; \
62 .set pop
63# endif
e36da2da
AJ
64#endif /* __ASSEMBLER__ */
65
66
e36da2da
AJ
67#ifndef __ASSEMBLER__
68
e36da2da
AJ
69/* The TP points to the start of the thread blocks. */
70# define TLS_DTV_AT_TP 1
498a2233 71# define TLS_TCB_AT_TP 0
e36da2da
AJ
72
73/* Get the thread descriptor definition. */
74# include <nptl/descr.h>
75
76typedef struct
77{
78 dtv_t *dtv;
79 void *private;
80} tcbhead_t;
81
82/* This is the size of the initial TCB. Because our TCB is before the thread
83 pointer, we don't need this. */
84# define TLS_INIT_TCB_SIZE 0
85
e36da2da
AJ
86/* This is the size of the TCB. Because our TCB is before the thread
87 pointer, we don't need this. */
88# define TLS_TCB_SIZE 0
89
e36da2da
AJ
90/* This is the size we need before TCB - actually, it includes the TCB. */
91# define TLS_PRE_TCB_SIZE \
92 (sizeof (struct pthread) \
627f5ede
FW
93 + ((sizeof (tcbhead_t) + __alignof (struct pthread) - 1) \
94 & ~(__alignof (struct pthread) - 1)))
e36da2da
AJ
95
96/* The thread pointer (in hardware register $29) points to the end of
97 the TCB + 0x7000, as for PowerPC. The pthread_descr structure is
98 immediately in front of the TCB. */
99# define TLS_TCB_OFFSET 0x7000
100
101/* Install the dtv pointer. The pointer passed is to the element with
102 index -1 which contain the length. */
103# define INSTALL_DTV(tcbp, dtvp) \
104 (((tcbhead_t *) (tcbp))[-1].dtv = (dtvp) + 1)
105
106/* Install new dtv for current thread. */
107# define INSTALL_NEW_DTV(dtv) \
108 (THREAD_DTV() = (dtv))
109
110/* Return dtv of given thread descriptor. */
111# define GET_DTV(tcbp) \
112 (((tcbhead_t *) (tcbp))[-1].dtv)
113
114/* Code to initially initialize the thread pointer. This might need
115 special attention since 'errno' is not yet available and if the
116 operation can cause a failure 'errno' must not be touched. */
774f9285 117# define TLS_INIT_TP(tcbp) \
bc2eb932
AZ
118 ({ long int result_var; \
119 result_var = INTERNAL_SYSCALL_CALL (set_thread_area, \
e36da2da 120 (char *) (tcbp) + TLS_TCB_OFFSET); \
bc2eb932 121 INTERNAL_SYSCALL_ERROR_P (result_var) \
e36da2da
AJ
122 ? "unknown error" : NULL; })
123
50f0a637
RM
124/* Value passed to 'clone' for initialization of the thread register. */
125# define TLS_DEFINE_INIT_TP(tp, pd) \
126 void *tp = (void *) (pd) + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE
127
e36da2da
AJ
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. */
ce2248ab 142# include <tcb-access.h>
e36da2da
AJ
143
144/* l_tls_offset == 0 is perfectly valid on MIPS, so we have to use some
145 different value to mean unset l_tls_offset. */
146# define NO_TLS_OFFSET -1
147
30efab51
DJ
148/* Get and set the global scope generation counter in struct pthread. */
149#define THREAD_GSCOPE_FLAG_UNUSED 0
150#define THREAD_GSCOPE_FLAG_USED 1
151#define THREAD_GSCOPE_FLAG_WAIT 2
152#define THREAD_GSCOPE_RESET_FLAG() \
153 do \
154 { int __res \
155 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
156 THREAD_GSCOPE_FLAG_UNUSED); \
157 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
8c276674 158 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
30efab51
DJ
159 } \
160 while (0)
161#define THREAD_GSCOPE_SET_FLAG() \
162 do \
163 { \
164 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
165 atomic_write_barrier (); \
166 } \
167 while (0)
30efab51 168
e36da2da
AJ
169#endif /* __ASSEMBLER__ */
170
171#endif /* tls.h */
This page took 0.353579 seconds and 5 git commands to generate.