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