]>
git.ipfire.org Git - thirdparty/glibc.git/blob - 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.
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 <http://www.gnu.org/licenses/>. */
22 # include <dl-sysdep.h>
30 #else /* __ASSEMBLER__ */
31 # include <tcb-offsets.h>
32 #endif /* __ASSEMBLER__ */
37 /* Get system call information. */
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
44 /* We use the multiple_threads field in the pthread struct */
45 #define TLS_MULTIPLE_THREADS_IN_TCB 1
47 /* Get the thread descriptor definition. */
48 # include <nptl/descr.h>
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
56 uintptr_t pointer_guard
;
57 uintptr_t stack_guard
;
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
65 /* Alignment requirements for the initial TCB. */
66 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
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
72 /* Alignment requirements for the TCB. */
73 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
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)))
80 /* Return the thread descriptor (tp) for the current thread. */
81 register void *__thread_pointer
asm ("tp");
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
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)
92 /* Install new dtv for current thread. */
93 # define INSTALL_NEW_DTV(dtv) (THREAD_DTV() = (dtv))
95 /* Return dtv of given thread descriptor. */
96 # define GET_DTV(tcbp) (((tcbhead_t *) (tcbp))[-1].dtv)
98 /* Code to initially initialize the thread pointer (tp). */
99 # define TLS_INIT_TP(tcbp) \
100 (__thread_pointer = (char *)(tcbp) + TLS_TCB_OFFSET, NULL)
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
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)
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))
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)
119 /* Read member of the thread descriptor directly. */
120 # define THREAD_GETMEM(descr, member) (descr->member)
122 /* Same as THREAD_GETMEM, but the member offset can be non-constant. */
123 # define THREAD_GETMEM_NC(descr, member, idx) \
126 /* Set member of the thread descriptor directly. */
127 # define THREAD_SETMEM(descr, member, value) \
128 (descr->member = (value))
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))
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)
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())
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
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() \
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); \
172 #define THREAD_GSCOPE_SET_FLAG() \
175 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
176 atomic_write_barrier (); \
179 #define THREAD_GSCOPE_WAIT() \
180 GL(dl_wait_lookup_done) ()
182 #endif /* __ASSEMBLER__ */