* elf/stackguard-macros.h (STACK_CHK_GUARD): Fix s390/s390x definition.
[glibc.git] / nptl / sysdeps / ia64 / tls.h
blobe3ad0681d66860aa650d0daa596dfbbe52e240ac
1 /* Definition for thread-local data handling. nptl/IA-64 version.
2 Copyright (C) 2003, 2004, 2005 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _TLS_H
21 #define _TLS_H 1
23 #include <dl-sysdep.h>
24 #ifndef __ASSEMBLER__
25 # include <stdbool.h>
26 # include <stddef.h>
27 # include <stdint.h>
28 # include <stdlib.h>
29 # include <list.h>
32 /* Type for the dtv. */
33 typedef union dtv
35 size_t counter;
36 struct
38 void *val;
39 bool is_static;
40 } pointer;
41 } dtv_t;
44 typedef struct
46 dtv_t *dtv;
47 void *private;
48 } tcbhead_t;
50 register struct pthread *__thread_self __asm__("r13");
52 # define TLS_MULTIPLE_THREADS_IN_TCB 1
54 #else /* __ASSEMBLER__ */
55 # include <tcb-offsets.h>
56 #endif
59 /* We require TLS support in the tools. */
60 #ifndef HAVE_TLS_SUPPORT
61 # error "TLS support is required."
62 #endif
64 /* Signal that TLS support is available. */
65 #define USE_TLS 1
67 /* Alignment requirement for the stack. */
68 #define STACK_ALIGN 16
70 #ifndef __ASSEMBLER__
71 /* Get system call information. */
72 # include <sysdep.h>
74 /* This is the size of the initial TCB. */
75 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
77 /* Alignment requirements for the initial TCB. */
78 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
80 /* This is the size of the TCB. */
81 # define TLS_TCB_SIZE sizeof (tcbhead_t)
83 /* This is the size we need before TCB.
84 If there is not any room for uintptr_t stack_guard in struct pthread's
85 final padding, we need to put struct pthread 16 byte slower. */
86 # define TLS_PRE_TCB_SIZE \
87 (sizeof (struct pthread) \
88 + (PTHREAD_STRUCT_END_PADDING < sizeof (uintptr_t) \
89 ? ((sizeof (uintptr_t) + __alignof__ (struct pthread) - 1)\
90 & ~(__alignof__ (struct pthread) - 1)) \
91 : 0))
93 /* Alignment requirements for the TCB. */
94 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
96 /* The DTV is allocated at the TP; the TCB is placed elsewhere. */
97 # define TLS_DTV_AT_TP 1
99 /* Get the thread descriptor definition. */
100 # include <nptl/descr.h>
102 /* Install the dtv pointer. The pointer passed is to the element with
103 index -1 which contain the length. */
104 # define INSTALL_DTV(descr, dtvp) \
105 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
107 /* Install new dtv for current thread. */
108 # define INSTALL_NEW_DTV(DTV) \
109 (((tcbhead_t *)__thread_self)->dtv = (DTV))
111 /* Return dtv of given thread descriptor. */
112 # define GET_DTV(descr) \
113 (((tcbhead_t *) (descr))->dtv)
115 #define THREAD_SELF_SYSINFO (((tcbhead_t *) __thread_self)->private)
116 #define THREAD_SYSINFO(pd) \
117 (((tcbhead_t *) ((char *) (pd) + TLS_PRE_TCB_SIZE))->private)
119 #if defined NEED_DL_SYSINFO
120 # define INIT_SYSINFO THREAD_SELF_SYSINFO = (void *) GLRO(dl_sysinfo)
121 #else
122 # define INIT_SYSINFO NULL
123 #endif
125 /* Code to initially initialize the thread pointer. This might need
126 special attention since 'errno' is not yet available and if the
127 operation can cause a failure 'errno' must not be touched. */
128 # define TLS_INIT_TP(thrdescr, secondcall) \
129 (__thread_self = (thrdescr), INIT_SYSINFO, NULL)
131 /* Return the address of the dtv for the current thread. */
132 # define THREAD_DTV() \
133 (((tcbhead_t *)__thread_self)->dtv)
135 /* Return the thread descriptor for the current thread. */
136 # define THREAD_SELF \
137 ((struct pthread *) ((char *) __thread_self - TLS_PRE_TCB_SIZE))
139 /* Magic for libthread_db to know how to do THREAD_SELF. */
140 # define DB_THREAD_SELF REGISTER (64, 64, 13 * 8, -TLS_PRE_TCB_SIZE)
142 /* Access to data in the thread descriptor is easy. */
143 #define THREAD_GETMEM(descr, member) \
144 descr->member
145 #define THREAD_GETMEM_NC(descr, member, idx) \
146 descr->member[idx]
147 #define THREAD_SETMEM(descr, member, value) \
148 descr->member = (value)
149 #define THREAD_SETMEM_NC(descr, member, idx, value) \
150 descr->member[idx] = (value)
152 /* Set the stack guard field in TCB head. */
153 #define THREAD_SET_STACK_GUARD(value) \
154 (((uintptr_t *) __thread_self)[-1] = (value))
155 #define THREAD_COPY_STACK_GUARD(descr) \
156 (((uintptr_t *) ((char *) (descr) + TLS_PRE_TCB_SIZE))[-1] \
157 = ((uintptr_t *) __thread_self)[-1])
159 #endif /* __ASSEMBLER__ */
161 #endif /* tls.h */