]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ia64/nptl/tls.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / ia64 / nptl / tls.h
1 /* Definition for thread-local data handling. nptl/IA-64 version.
2 Copyright (C) 2003-2019 Free Software Foundation, Inc.
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
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 #ifndef __ASSEMBLER__
24 # include <stdbool.h>
25 # include <stddef.h>
26 # include <stdint.h>
27 # include <stdlib.h>
28 # include <list.h>
29 # include <dl-dtv.h>
30
31 typedef struct
32 {
33 dtv_t *dtv;
34 void *__private;
35 } tcbhead_t;
36
37 register struct pthread *__thread_self __asm__("r13");
38
39 # define TLS_MULTIPLE_THREADS_IN_TCB 1
40
41 #else /* __ASSEMBLER__ */
42 # include <tcb-offsets.h>
43 #endif
44
45
46 /* Alignment requirement for the stack. */
47 #define STACK_ALIGN 16
48
49 #ifndef __ASSEMBLER__
50 /* Get system call information. */
51 # include <sysdep.h>
52
53 /* This is the size of the initial TCB. */
54 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
55
56 /* Alignment requirements for the initial TCB. */
57 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
58
59 /* This is the size of the TCB. */
60 # define TLS_TCB_SIZE sizeof (tcbhead_t)
61
62 /* This is the size we need before TCB.
63 If there is not any room for uintptr_t stack_guard and
64 uintptr_t pointer_guard in struct pthread's final padding,
65 we need to put struct pthread 16 byte slower. */
66 # define TLS_PRE_TCB_SIZE \
67 (sizeof (struct pthread) \
68 + (PTHREAD_STRUCT_END_PADDING < 2 * sizeof (uintptr_t) \
69 ? ((2 * sizeof (uintptr_t) + __alignof__ (struct pthread) - 1) \
70 & ~(__alignof__ (struct pthread) - 1)) \
71 : 0))
72
73 /* Alignment requirements for the TCB. */
74 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
75
76 /* The DTV is allocated at the TP; the TCB is placed elsewhere. */
77 # define TLS_DTV_AT_TP 1
78 # define TLS_TCB_AT_TP 0
79
80 /* Get the thread descriptor definition. */
81 # include <nptl/descr.h>
82
83 /* Install the dtv pointer. The pointer passed is to the element with
84 index -1 which contain the length. */
85 # define INSTALL_DTV(descr, dtvp) \
86 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
87
88 /* Install new dtv for current thread. */
89 # define INSTALL_NEW_DTV(DTV) \
90 (((tcbhead_t *)__thread_self)->dtv = (DTV))
91
92 /* Return dtv of given thread descriptor. */
93 # define GET_DTV(descr) \
94 (((tcbhead_t *) (descr))->dtv)
95
96 #define THREAD_SELF_SYSINFO (((tcbhead_t *) __thread_self)->__private)
97 #define THREAD_SYSINFO(pd) \
98 (((tcbhead_t *) ((char *) (pd) + TLS_PRE_TCB_SIZE))->__private)
99
100 #ifdef NEED_DL_SYSINFO
101 # define INIT_SYSINFO THREAD_SELF_SYSINFO = (void *) GLRO(dl_sysinfo)
102 # define SETUP_THREAD_SYSINFO(pd) \
103 (THREAD_SYSINFO (pd) = THREAD_SELF_SYSINFO)
104 # define CHECK_THREAD_SYSINFO(pd) \
105 assert (THREAD_SYSINFO (pd) == THREAD_SELF_SYSINFO)
106 #else
107 # define INIT_SYSINFO NULL
108 #endif
109
110 /* Code to initially initialize the thread pointer. This might need
111 special attention since 'errno' is not yet available and if the
112 operation can cause a failure 'errno' must not be touched. */
113 # define TLS_INIT_TP(thrdescr) \
114 (__thread_self = (thrdescr), INIT_SYSINFO, NULL)
115
116 /* Value passed to 'clone2' for initialization of the thread register. */
117 # define TLS_DEFINE_INIT_TP(tp, pd) \
118 void *tp = (char *) (pd) + TLS_PRE_TCB_SIZE
119
120 /* Return the address of the dtv for the current thread. */
121 # define THREAD_DTV() \
122 (((tcbhead_t *)__thread_self)->dtv)
123
124 /* Return the thread descriptor for the current thread. */
125 # define THREAD_SELF \
126 ((struct pthread *) ((char *) __thread_self - TLS_PRE_TCB_SIZE))
127
128 /* Magic for libthread_db to know how to do THREAD_SELF. */
129 # define DB_THREAD_SELF REGISTER (64, 64, 13 * 8, -TLS_PRE_TCB_SIZE)
130
131 /* Access to data in the thread descriptor is easy. */
132 #define THREAD_GETMEM(descr, member) \
133 descr->member
134 #define THREAD_GETMEM_NC(descr, member, idx) \
135 descr->member[idx]
136 #define THREAD_SETMEM(descr, member, value) \
137 descr->member = (value)
138 #define THREAD_SETMEM_NC(descr, member, idx, value) \
139 descr->member[idx] = (value)
140
141 /* Set the stack guard field in TCB head. */
142 #define THREAD_SET_STACK_GUARD(value) \
143 (((uintptr_t *) __thread_self)[-1] = (value))
144 #define THREAD_COPY_STACK_GUARD(descr) \
145 (((uintptr_t *) ((char *) (descr) + TLS_PRE_TCB_SIZE))[-1] \
146 = ((uintptr_t *) __thread_self)[-1])
147
148 /* Set the pointer guard field in TCB head. */
149 #define THREAD_GET_POINTER_GUARD() \
150 (((uintptr_t *) __thread_self)[-2])
151 #define THREAD_SET_POINTER_GUARD(value) \
152 (((uintptr_t *) __thread_self)[-2] = (value))
153 #define THREAD_COPY_POINTER_GUARD(descr) \
154 (((uintptr_t *) ((char *) (descr) + TLS_PRE_TCB_SIZE))[-2] \
155 = THREAD_GET_POINTER_GUARD ())
156
157 /* Get and set the global scope generation counter in struct pthread. */
158 #define THREAD_GSCOPE_IN_TCB 1
159 #define THREAD_GSCOPE_FLAG_UNUSED 0
160 #define THREAD_GSCOPE_FLAG_USED 1
161 #define THREAD_GSCOPE_FLAG_WAIT 2
162 #define THREAD_GSCOPE_RESET_FLAG() \
163 do \
164 { int __res \
165 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
166 THREAD_GSCOPE_FLAG_UNUSED); \
167 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
168 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
169 } \
170 while (0)
171 #define THREAD_GSCOPE_SET_FLAG() \
172 do \
173 { \
174 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
175 atomic_write_barrier (); \
176 } \
177 while (0)
178 #define THREAD_GSCOPE_WAIT() \
179 GL(dl_wait_lookup_done) ()
180
181 #endif /* __ASSEMBLER__ */
182
183 #endif /* tls.h */