]>
sourceware.org Git - glibc.git/blob - sysdeps/ia64/nptl/tls.h
44951da24bf5fc99ef14b78ef967c44a5c94f93b
1 /* Definition for thread-local data handling. nptl/IA-64 version.
2 Copyright (C) 2003-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>
37 register struct pthread
*__thread_self
__asm__("r13");
39 # define TLS_MULTIPLE_THREADS_IN_TCB 1
41 #else /* __ASSEMBLER__ */
42 # include <tcb-offsets.h>
46 /* Alignment requirement for the stack. */
47 #define STACK_ALIGN 16
50 /* Get system call information. */
53 /* This is the size of the initial TCB. */
54 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
56 /* Alignment requirements for the initial TCB. */
57 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
59 /* This is the size of the TCB. */
60 # define TLS_TCB_SIZE sizeof (tcbhead_t)
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)) \
73 /* Alignment requirements for the TCB. */
74 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
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
80 /* Get the thread descriptor definition. */
81 # include <nptl/descr.h>
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
88 /* Install new dtv for current thread. */
89 # define INSTALL_NEW_DTV(DTV) \
90 (((tcbhead_t *)__thread_self)->dtv = (DTV))
92 /* Return dtv of given thread descriptor. */
93 # define GET_DTV(descr) \
94 (((tcbhead_t *) (descr))->dtv)
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)
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)
107 # define INIT_SYSINFO NULL
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)
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
120 /* Return the address of the dtv for the current thread. */
121 # define THREAD_DTV() \
122 (((tcbhead_t *)__thread_self)->dtv)
124 /* Return the thread descriptor for the current thread. */
125 # define THREAD_SELF \
126 ((struct pthread *) ((char *) __thread_self - TLS_PRE_TCB_SIZE))
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)
131 # include <tcb-access.h>
133 /* Set the stack guard field in TCB head. */
134 #define THREAD_SET_STACK_GUARD(value) \
135 (((uintptr_t *) __thread_self)[-1] = (value))
136 #define THREAD_COPY_STACK_GUARD(descr) \
137 (((uintptr_t *) ((char *) (descr) + TLS_PRE_TCB_SIZE))[-1] \
138 = ((uintptr_t *) __thread_self)[-1])
140 /* Set the pointer guard field in TCB head. */
141 #define THREAD_GET_POINTER_GUARD() \
142 (((uintptr_t *) __thread_self)[-2])
143 #define THREAD_SET_POINTER_GUARD(value) \
144 (((uintptr_t *) __thread_self)[-2] = (value))
145 #define THREAD_COPY_POINTER_GUARD(descr) \
146 (((uintptr_t *) ((char *) (descr) + TLS_PRE_TCB_SIZE))[-2] \
147 = THREAD_GET_POINTER_GUARD ())
149 /* Get and set the global scope generation counter in struct pthread. */
150 #define THREAD_GSCOPE_FLAG_UNUSED 0
151 #define THREAD_GSCOPE_FLAG_USED 1
152 #define THREAD_GSCOPE_FLAG_WAIT 2
153 #define THREAD_GSCOPE_RESET_FLAG() \
156 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
157 THREAD_GSCOPE_FLAG_UNUSED); \
158 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
159 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
162 #define THREAD_GSCOPE_SET_FLAG() \
165 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
166 atomic_write_barrier (); \
170 #endif /* __ASSEMBLER__ */
This page took 0.041456 seconds and 4 git commands to generate.