]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl/sysdeps/powerpc/tls.h
* sysdeps/gnu/Makefile: Make sure the correct errlist.c file is
[thirdparty/glibc.git] / nptl / sysdeps / powerpc / tls.h
CommitLineData
f3c13160 1/* Definition for thread-local data handling. NPTL/PowerPC version.
9dcafc55 2 Copyright (C) 2003, 2005 Free Software Foundation, Inc.
f3c13160
RM
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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20#ifndef _TLS_H
21#define _TLS_H 1
22
23# include <dl-sysdep.h>
24
25#ifndef __ASSEMBLER__
9dcafc55 26# include <stdbool.h>
f3c13160
RM
27# include <stddef.h>
28# include <stdint.h>
29
30/* Type for the dtv. */
31typedef union dtv
32{
33 size_t counter;
9dcafc55
UD
34 struct
35 {
36 void *val;
37 bool is_static;
38 } pointer;
f3c13160
RM
39} dtv_t;
40
41#else /* __ASSEMBLER__ */
42# include <tcb-offsets.h>
43#endif /* __ASSEMBLER__ */
44
45
46/* We require TLS support in the tools. */
47#ifndef HAVE_TLS_SUPPORT
48# error "TLS support is required."
49#endif
50
51/* Signal that TLS support is available. */
52# define USE_TLS 1
53
54#ifndef __ASSEMBLER__
55
56/* Get system call information. */
57# include <sysdep.h>
58
59/* The TP points to the start of the thread blocks. */
60# define TLS_DTV_AT_TP 1
61
94659495
RM
62/* We use the multiple_threads field in the pthread struct */
63#define TLS_MULTIPLE_THREADS_IN_TCB 1
f3c13160
RM
64
65/* Get the thread descriptor definition. */
66# include <nptl/descr.h>
67
35f1e827
UD
68/* The stack_guard is accessed directly by GCC -fstack-protector code,
69 so it is a part of public ABI. The dtv field is private. */
f3c13160
RM
70typedef struct
71{
35f1e827 72 uintptr_t stack_guard;
f3c13160
RM
73 dtv_t *dtv;
74} tcbhead_t;
75
76/* This is the size of the initial TCB. */
299601a1 77# define TLS_INIT_TCB_SIZE 0
f3c13160
RM
78
79/* Alignment requirements for the initial TCB. */
299601a1 80# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
f3c13160
RM
81
82/* This is the size of the TCB. */
299601a1 83# define TLS_TCB_SIZE 0
f3c13160
RM
84
85/* Alignment requirements for the TCB. */
299601a1 86# define TLS_TCB_ALIGN __alignof__ (struct pthread)
f3c13160
RM
87
88/* This is the size we need before TCB. */
468777e1
UD
89# define TLS_PRE_TCB_SIZE \
90 (sizeof (struct pthread) \
91 + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
f3c13160
RM
92
93# ifndef __powerpc64__
94/* Register r2 (tp) is reserved by the ABI as "thread pointer". */
95register void *__thread_register __asm__ ("r2");
96# define PT_THREAD_POINTER PT_R2
97# else
98/* Register r13 (tp) is reserved by the ABI as "thread pointer". */
99register void *__thread_register __asm__ ("r13");
100# define PT_THREAD_POINTER PT_R13
101# endif
102
103/* The following assumes that TP (R2 or R13) points to the end of the
104 TCB + 0x7000 (per the ABI). This implies that TCB address is
299601a1 105 TP - 0x7000. As we define TLS_DTV_AT_TP we can
f3c13160
RM
106 assume that the pthread struct is allocated immediately ahead of the
107 TCB. This implies that the pthread_descr address is
299601a1 108 TP - (TLS_PRE_TCB_SIZE + 0x7000). */
f3c13160
RM
109# define TLS_TCB_OFFSET 0x7000
110
111/* Install the dtv pointer. The pointer passed is to the element with
112 index -1 which contain the length. */
113# define INSTALL_DTV(tcbp, dtvp) \
299601a1 114 ((tcbhead_t *) (tcbp))[-1].dtv = dtvp + 1
f3c13160
RM
115
116/* Install new dtv for current thread. */
117# define INSTALL_NEW_DTV(dtv) (THREAD_DTV() = (dtv))
118
119/* Return dtv of given thread descriptor. */
299601a1 120# define GET_DTV(tcbp) (((tcbhead_t *) (tcbp))[-1].dtv)
f3c13160
RM
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. */
125# define TLS_INIT_TP(tcbp, secondcall) \
299601a1 126 (__thread_register = (void *) (tcbp) + TLS_TCB_OFFSET, NULL)
f3c13160
RM
127
128/* Return the address of the dtv for the current thread. */
129# define THREAD_DTV() \
35f1e827 130 (((tcbhead_t *) (__thread_register - TLS_TCB_OFFSET))[-1].dtv)
f3c13160
RM
131
132/* Return the thread descriptor for the current thread. */
133# define THREAD_SELF \
134 ((struct pthread *) (__thread_register \
299601a1 135 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
f3c13160 136
7f08f55a
RM
137/* Magic for libthread_db to know how to do THREAD_SELF. */
138# define DB_THREAD_SELF \
35f1e827 139 REGISTER (32, 32, PT_THREAD_POINTER * 4, \
7f08f55a 140 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE) \
35f1e827 141 REGISTER (64, 64, PT_THREAD_POINTER * 8, \
7f08f55a
RM
142 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)
143
f3c13160
RM
144/* Read member of the thread descriptor directly. */
145# define THREAD_GETMEM(descr, member) ((void)(descr), (THREAD_SELF)->member)
146
147/* Same as THREAD_GETMEM, but the member offset can be non-constant. */
148# define THREAD_GETMEM_NC(descr, member, idx) \
149 ((void)(descr), (THREAD_SELF)->member[idx])
150
151/* Set member of the thread descriptor directly. */
152# define THREAD_SETMEM(descr, member, value) \
153 ((void)(descr), (THREAD_SELF)->member = (value))
154
155/* Same as THREAD_SETMEM, but the member offset can be non-constant. */
156# define THREAD_SETMEM_NC(descr, member, idx, value) \
157 ((void)(descr), (THREAD_SELF)->member[idx] = (value))
158
35f1e827
UD
159/* Set the stack guard field in TCB head. */
160# define THREAD_SET_STACK_GUARD(value) \
161 (((tcbhead_t *) ((char *) __thread_register \
162 - TLS_TCB_OFFSET))[-1].stack_guard = (value))
163# define THREAD_COPY_STACK_GUARD(descr) \
164 (((tcbhead_t *) ((char *) (descr) \
165 + TLS_PRE_TCB_SIZE))[-1].stack_guard \
166 = ((tcbhead_t *) ((char *) __thread_register \
167 - TLS_TCB_OFFSET))[-1].stack_guard)
168
299601a1
UD
169/* l_tls_offset == 0 is perfectly valid on PPC, so we have to use some
170 different value to mean unset l_tls_offset. */
171# define NO_TLS_OFFSET -1
172
f3c13160
RM
173#endif /* __ASSEMBLER__ */
174
175#endif /* tls.h */