]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/tile/nptl/tls.h
Remove tilepro-*-linux-gnu support
[thirdparty/glibc.git] / sysdeps / tile / nptl / tls.h
1 /* Copyright (C) 2011-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
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
16 License along with the GNU C Library. If not, see
17 <http://www.gnu.org/licenses/>. */
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 # include <dl-dtv.h>
29
30 #else /* __ASSEMBLER__ */
31 # include <tcb-offsets.h>
32 #endif /* __ASSEMBLER__ */
33
34
35 #ifndef __ASSEMBLER__
36
37 /* Get system call information. */
38 # include <sysdep.h>
39
40 /* The TP points to the start of the thread blocks. */
41 # define TLS_DTV_AT_TP 1
42 # define TLS_TCB_AT_TP 0
43
44 /* We use the multiple_threads field in the pthread struct */
45 #define TLS_MULTIPLE_THREADS_IN_TCB 1
46
47 /* Get the thread descriptor definition. */
48 # include <nptl/descr.h>
49
50 /* The stack_guard is accessed directly by GCC -fstack-protector code,
51 so it is a part of public ABI. The dtv and pointer_guard fields
52 are private. */
53 typedef struct
54 {
55 void *feedback_data;
56 uintptr_t pointer_guard;
57 uintptr_t stack_guard;
58 dtv_t *dtv;
59 } tcbhead_t;
60
61 /* This is the size of the initial TCB. Because our TCB is before the thread
62 pointer, we don't need this. */
63 # define TLS_INIT_TCB_SIZE 0
64
65 /* Alignment requirements for the initial TCB. */
66 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
67
68 /* This is the size of the TCB. Because our TCB is before the thread
69 pointer, we don't need this. */
70 # define TLS_TCB_SIZE 0
71
72 /* Alignment requirements for the TCB. */
73 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
74
75 /* This is the size we need before TCB - actually, it includes the TCB. */
76 # define TLS_PRE_TCB_SIZE \
77 (sizeof (struct pthread) \
78 + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
79
80 /* Return the thread descriptor (tp) for the current thread. */
81 register void *__thread_pointer asm ("tp");
82
83 /* The thread pointer (in hardware register tp) points to the end of
84 the TCB. The pthread_descr structure is immediately in front of the TCB. */
85 # define TLS_TCB_OFFSET 0
86
87 /* Install the dtv pointer. The pointer passed is to the element with
88 index -1 which contain the length. */
89 # define INSTALL_DTV(tcbp, dtvp) \
90 (((tcbhead_t *) (tcbp))[-1].dtv = (dtvp) + 1)
91
92 /* Install new dtv for current thread. */
93 # define INSTALL_NEW_DTV(dtv) (THREAD_DTV() = (dtv))
94
95 /* Return dtv of given thread descriptor. */
96 # define GET_DTV(tcbp) (((tcbhead_t *) (tcbp))[-1].dtv)
97
98 /* Code to initially initialize the thread pointer (tp). */
99 # define TLS_INIT_TP(tcbp) \
100 (__thread_pointer = (char *)(tcbp) + TLS_TCB_OFFSET, NULL)
101
102 /* Value passed to 'clone' for initialization of the thread register. */
103 # define TLS_DEFINE_INIT_TP(tp, pd) \
104 void *tp = (void *) (pd) + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE
105
106 /* Return the address of the dtv for the current thread. */
107 # define THREAD_DTV() \
108 (((tcbhead_t *) (__thread_pointer - TLS_TCB_OFFSET))[-1].dtv)
109
110 /* Return the thread descriptor for the current thread. */
111 # define THREAD_SELF \
112 ((struct pthread *) (__thread_pointer \
113 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
114
115 /* Magic for libthread_db to know how to do THREAD_SELF. */
116 # define DB_THREAD_SELF \
117 REGISTER (64, 64, REG_TP * 8, - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)
118
119 /* Read member of the thread descriptor directly. */
120 # define THREAD_GETMEM(descr, member) (descr->member)
121
122 /* Same as THREAD_GETMEM, but the member offset can be non-constant. */
123 # define THREAD_GETMEM_NC(descr, member, idx) \
124 (descr->member[idx])
125
126 /* Set member of the thread descriptor directly. */
127 # define THREAD_SETMEM(descr, member, value) \
128 (descr->member = (value))
129
130 /* Same as THREAD_SETMEM, but the member offset can be non-constant. */
131 # define THREAD_SETMEM_NC(descr, member, idx, value) \
132 (descr->member[idx] = (value))
133
134 /* Set the stack guard field in TCB head. */
135 # define THREAD_SET_STACK_GUARD(value) \
136 (((tcbhead_t *) ((char *) __thread_pointer \
137 - TLS_TCB_OFFSET))[-1].stack_guard = (value))
138 # define THREAD_COPY_STACK_GUARD(descr) \
139 (((tcbhead_t *) ((char *) (descr) \
140 + TLS_PRE_TCB_SIZE))[-1].stack_guard \
141 = ((tcbhead_t *) ((char *) __thread_pointer \
142 - TLS_TCB_OFFSET))[-1].stack_guard)
143
144 /* Set the pointer guard field in TCB head. */
145 # define THREAD_GET_POINTER_GUARD() \
146 (((tcbhead_t *) ((char *) __thread_pointer \
147 - TLS_TCB_OFFSET))[-1].pointer_guard)
148 # define THREAD_SET_POINTER_GUARD(value) \
149 (THREAD_GET_POINTER_GUARD () = (value))
150 # define THREAD_COPY_POINTER_GUARD(descr) \
151 (((tcbhead_t *) ((char *) (descr) \
152 + TLS_PRE_TCB_SIZE))[-1].pointer_guard \
153 = THREAD_GET_POINTER_GUARD())
154
155 /* l_tls_offset == 0 is perfectly valid on Tile, so we have to use some
156 different value to mean unset l_tls_offset. */
157 # define NO_TLS_OFFSET -1
158
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); \
170 } \
171 while (0)
172 #define THREAD_GSCOPE_SET_FLAG() \
173 do \
174 { \
175 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
176 atomic_write_barrier (); \
177 } \
178 while (0)
179 #define THREAD_GSCOPE_WAIT() \
180 GL(dl_wait_lookup_done) ()
181
182 #endif /* __ASSEMBLER__ */
183
184 #endif /* tls.h */