]>
sourceware.org Git - glibc.git/blob - sysdeps/mips/nptl/tls.h
1 /* Definition for thread-local data handling. NPTL/MIPS version.
2 Copyright (C) 2005-2021 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, see
17 <https://www.gnu.org/licenses/>. */
22 #include <dl-sysdep.h>
30 /* Get system call information. */
34 /* MIPS16 uses GCC builtin to access the TP. */
35 # define READ_THREAD_POINTER() (__builtin_thread_pointer ())
37 /* Note: rd must be $v1 to be ABI-conformant. */
38 # if defined (__mips_isa_rev) && __mips_isa_rev >= 2
39 # define READ_THREAD_POINTER() \
41 asm volatile ("rdhwr\t%0, $29" : "=v" (__result)); \
44 # define READ_THREAD_POINTER() \
46 asm volatile (".set\tpush\n\t.set\tmips32r2\n\t" \
47 "rdhwr\t%0, $29\n\t.set\tpop" : "=v" (__result)); \
52 #else /* __ASSEMBLER__ */
53 # include <tcb-offsets.h>
55 # if __mips_isa_rev >= 2
56 # define READ_THREAD_POINTER(rd) rdhwr rd, $29
58 # define READ_THREAD_POINTER(rd) \
64 #endif /* __ASSEMBLER__ */
69 /* The TP points to the start of the thread blocks. */
70 # define TLS_DTV_AT_TP 1
71 # define TLS_TCB_AT_TP 0
73 /* Get the thread descriptor definition. */
74 # include <nptl/descr.h>
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
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
90 /* This is the size we need before TCB - actually, it includes the TCB. */
91 # define TLS_PRE_TCB_SIZE \
92 (sizeof (struct pthread) \
93 + ((sizeof (tcbhead_t) + __alignof (struct pthread) - 1) \
94 & ~(__alignof (struct pthread) - 1)))
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
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)
106 /* Install new dtv for current thread. */
107 # define INSTALL_NEW_DTV(dtv) \
108 (THREAD_DTV() = (dtv))
110 /* Return dtv of given thread descriptor. */
111 # define GET_DTV(tcbp) \
112 (((tcbhead_t *) (tcbp))[-1].dtv)
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. */
117 # define TLS_INIT_TP(tcbp) \
118 ({ long int result_var; \
119 result_var = INTERNAL_SYSCALL_CALL (set_thread_area, \
120 (char *) (tcbp) + TLS_TCB_OFFSET); \
121 INTERNAL_SYSCALL_ERROR_P (result_var) \
122 ? "unknown error" : NULL; })
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
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)
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))
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)
141 /* Access to data in the thread descriptor is easy. */
142 # include <tcb-access.h>
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
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() \
155 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
156 THREAD_GSCOPE_FLAG_UNUSED); \
157 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
158 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
161 #define THREAD_GSCOPE_SET_FLAG() \
164 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
165 atomic_write_barrier (); \
169 #endif /* __ASSEMBLER__ */
This page took 0.044255 seconds and 5 git commands to generate.