(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / linuxthreads / sysdeps / powerpc / tls.h
blobf6eb48b434c607c1e7825875b705e344265b3bd1
1 /* Definitions for thread-local data handling. linuxthreads/PPC version.
2 Copyright (C) 2003 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
23 #ifndef __ASSEMBLER__
25 # include <pt-machine.h>
26 # include <stddef.h>
28 /* Type for the dtv. */
29 typedef union dtv
31 size_t counter;
32 void *pointer;
33 } dtv_t;
35 #else /* __ASSEMBLER__ */
36 # include <tcb-offsets.h>
37 #endif /* __ASSEMBLER__ */
39 #ifdef HAVE_TLS_SUPPORT
41 /* Signal that TLS support is available. */
42 # define USE_TLS 1
44 # ifndef __ASSEMBLER__
46 /* This layout is actually wholly private and not affected by the ABI.
47 Nor does it overlap the pthread data structure, so we need nothing
48 extra here at all. */
49 typedef struct
51 dtv_t *dtv;
52 } tcbhead_t;
54 /* This is the size of the initial TCB. */
55 # define TLS_INIT_TCB_SIZE 0
57 /* Alignment requirements for the initial TCB. */
58 # define TLS_INIT_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
60 /* This is the size of the TCB. */
61 # define TLS_TCB_SIZE 0
63 /* Alignment requirements for the TCB. */
64 # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
66 /* This is the size we need before TCB. */
67 # define TLS_PRE_TCB_SIZE \
68 (sizeof (struct _pthread_descr_struct) \
69 + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
71 /* The following assumes that TP (R2 or R13) is points to the end of the
72 TCB + 0x7000 (per the ABI). This implies that TCB address is
73 TP - 0x7000. As we define TLS_DTV_AT_TP we can
74 assume that the pthread_descr is allocated immediately ahead of the
75 TCB. This implies that the pthread_descr address is
76 TP - (TLS_PRE_TCB_SIZE + 0x7000). */
77 #define TLS_TCB_OFFSET 0x7000
79 /* The DTV is allocated at the TP; the TCB is placed elsewhere. */
80 /* This is not really true for powerpc64. We are following alpha
81 where the DTV pointer is first doubleword in the TCB. */
82 # define TLS_DTV_AT_TP 1
84 /* Install the dtv pointer. The pointer passed is to the element with
85 index -1 which contain the length. */
86 # define INSTALL_DTV(TCBP, DTVP) \
87 (((tcbhead_t *) (TCBP))[-1].dtv = (DTVP) + 1)
89 /* Install new dtv for current thread. */
90 # define INSTALL_NEW_DTV(DTV) (THREAD_DTV() = (DTV))
92 /* Return dtv of given thread descriptor. */
93 # define GET_DTV(TCBP) (((tcbhead_t *) (TCBP))[-1].dtv)
95 /* We still need this define so that tcb-offsets.sym can override it and
96 use THREAD_SELF to generate MULTIPLE_THREADS_OFFSET. */
97 # define __thread_register ((void *) __thread_self)
99 /* Code to initially initialize the thread pointer. This might need
100 special attention since 'errno' is not yet available and if the
101 operation can cause a failure 'errno' must not be touched.
103 The global register variable is declared in pt-machine.h with the
104 wrong type, so we need some extra casts to get the desired result.
105 This avoids a lvalue cast that gcc-3.4 does not like. */
106 # define TLS_INIT_TP(TCBP, SECONDCALL) \
107 (__thread_self = (struct _pthread_descr_struct *) \
108 ((void *) (TCBP) + TLS_TCB_OFFSET), NULL)
110 /* Return the address of the dtv for the current thread. */
111 # define THREAD_DTV() \
112 (((tcbhead_t *) ((void *) __thread_self - TLS_TCB_OFFSET))[-1].dtv)
114 /* Return the thread descriptor for the current thread. */
115 # undef THREAD_SELF
116 # define THREAD_SELF \
117 ((pthread_descr) (__thread_register \
118 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
120 # undef INIT_THREAD_SELF
121 # define INIT_THREAD_SELF(DESCR, NR) \
122 (__thread_self = (struct _pthread_descr_struct *)((void *) (DESCR) \
123 + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE))
125 /* Make sure we have the p_multiple_threads member in the thread structure.
126 See below. */
127 # define TLS_MULTIPLE_THREADS_IN_TCB 1
129 /* Get the thread descriptor definition. */
130 # include <linuxthreads/descr.h>
132 /* l_tls_offset == 0 is perfectly valid on PPC, so we have to use some
133 different value to mean unset l_tls_offset. */
134 # define NO_TLS_OFFSET -1
136 # endif /* __ASSEMBLER__ */
138 #elif !defined __ASSEMBLER__
140 /* This overlaps the start of the pthread_descr. System calls
141 and such use this to find the multiple_threads flag and need
142 to use the same offset relative to the thread register in both
143 single-threaded and multi-threaded code. */
144 typedef struct
146 void *tcb; /* Never used. */
147 dtv_t *dtv; /* Never used. */
148 void *self; /* Used only if multithreaded, and rarely. */
149 int multiple_threads; /* Only this member is really used. */
150 } tcbhead_t;
152 #define NONTLS_INIT_TP \
153 do { \
154 static const tcbhead_t nontls_init_tp = { .multiple_threads = 0 }; \
155 __thread_self = (__typeof (__thread_self)) &nontls_init_tp; \
156 } while (0)
158 #endif /* HAVE_TLS_SUPPORT */
160 #endif /* tls.h */