Update copyright notices with scripts/update-copyrights
[glibc.git] / ports / sysdeps / ia64 / nptl / tls.h
blob279d107d3928f17568341a580c274a1e74597575
1 /* Definition for thread-local data handling. nptl/IA-64 version.
2 Copyright (C) 2003-2014 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 <http://www.gnu.org/licenses/>. */
19 #ifndef _TLS_H
20 #define _TLS_H 1
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>
31 /* Type for the dtv. */
32 typedef union dtv
34 size_t counter;
35 struct
37 void *val;
38 bool is_static;
39 } pointer;
40 } dtv_t;
43 typedef struct
45 dtv_t *dtv;
46 void *__private;
47 } tcbhead_t;
49 register struct pthread *__thread_self __asm__("r13");
51 # define TLS_MULTIPLE_THREADS_IN_TCB 1
53 #else /* __ASSEMBLER__ */
54 # include <tcb-offsets.h>
55 #endif
58 /* Alignment requirement for the stack. */
59 #define STACK_ALIGN 16
61 #ifndef __ASSEMBLER__
62 /* Get system call information. */
63 # include <sysdep.h>
65 /* This is the size of the initial TCB. */
66 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
68 /* Alignment requirements for the initial TCB. */
69 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
71 /* This is the size of the TCB. */
72 # define TLS_TCB_SIZE sizeof (tcbhead_t)
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))
85 /* Alignment requirements for the TCB. */
86 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
88 /* The DTV is allocated at the TP; the TCB is placed elsewhere. */
89 # define TLS_DTV_AT_TP 1
91 /* Get the thread descriptor definition. */
92 # include <nptl/descr.h>
94 /* Install the dtv pointer. The pointer passed is to the element with
95 index -1 which contain the length. */
96 # define INSTALL_DTV(descr, dtvp) \
97 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
99 /* Install new dtv for current thread. */
100 # define INSTALL_NEW_DTV(DTV) \
101 (((tcbhead_t *)__thread_self)->dtv = (DTV))
103 /* Return dtv of given thread descriptor. */
104 # define GET_DTV(descr) \
105 (((tcbhead_t *) (descr))->dtv)
107 #define THREAD_SELF_SYSINFO (((tcbhead_t *) __thread_self)->__private)
108 #define THREAD_SYSINFO(pd) \
109 (((tcbhead_t *) ((char *) (pd) + TLS_PRE_TCB_SIZE))->__private)
111 #if defined NEED_DL_SYSINFO
112 # define INIT_SYSINFO THREAD_SELF_SYSINFO = (void *) GLRO(dl_sysinfo)
113 #else
114 # define INIT_SYSINFO NULL
115 #endif
117 /* Code to initially initialize the thread pointer. This might need
118 special attention since 'errno' is not yet available and if the
119 operation can cause a failure 'errno' must not be touched. */
120 # define TLS_INIT_TP(thrdescr, secondcall) \
121 (__thread_self = (thrdescr), INIT_SYSINFO, NULL)
123 /* Return the address of the dtv for the current thread. */
124 # define THREAD_DTV() \
125 (((tcbhead_t *)__thread_self)->dtv)
127 /* Return the thread descriptor for the current thread. */
128 # define THREAD_SELF \
129 ((struct pthread *) ((char *) __thread_self - TLS_PRE_TCB_SIZE))
131 /* Magic for libthread_db to know how to do THREAD_SELF. */
132 # define DB_THREAD_SELF REGISTER (64, 64, 13 * 8, -TLS_PRE_TCB_SIZE)
134 /* Access to data in the thread descriptor is easy. */
135 #define THREAD_GETMEM(descr, member) \
136 descr->member
137 #define THREAD_GETMEM_NC(descr, member, idx) \
138 descr->member[idx]
139 #define THREAD_SETMEM(descr, member, value) \
140 descr->member = (value)
141 #define THREAD_SETMEM_NC(descr, member, idx, value) \
142 descr->member[idx] = (value)
144 /* Set the stack guard field in TCB head. */
145 #define THREAD_SET_STACK_GUARD(value) \
146 (((uintptr_t *) __thread_self)[-1] = (value))
147 #define THREAD_COPY_STACK_GUARD(descr) \
148 (((uintptr_t *) ((char *) (descr) + TLS_PRE_TCB_SIZE))[-1] \
149 = ((uintptr_t *) __thread_self)[-1])
151 /* Set the pointer guard field in TCB head. */
152 #define THREAD_GET_POINTER_GUARD() \
153 (((uintptr_t *) __thread_self)[-2])
154 #define THREAD_SET_POINTER_GUARD(value) \
155 (((uintptr_t *) __thread_self)[-2] = (value))
156 #define THREAD_COPY_POINTER_GUARD(descr) \
157 (((uintptr_t *) ((char *) (descr) + TLS_PRE_TCB_SIZE))[-2] \
158 = THREAD_GET_POINTER_GUARD ())
160 /* Get and set the global scope generation counter in struct pthread. */
161 #define THREAD_GSCOPE_FLAG_UNUSED 0
162 #define THREAD_GSCOPE_FLAG_USED 1
163 #define THREAD_GSCOPE_FLAG_WAIT 2
164 #define THREAD_GSCOPE_RESET_FLAG() \
165 do \
166 { int __res \
167 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
168 THREAD_GSCOPE_FLAG_UNUSED); \
169 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
170 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
172 while (0)
173 #define THREAD_GSCOPE_SET_FLAG() \
174 do \
176 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
177 atomic_write_barrier (); \
179 while (0)
180 #define THREAD_GSCOPE_WAIT() \
181 GL(dl_wait_lookup_done) ()
183 #endif /* __ASSEMBLER__ */
185 #endif /* tls.h */