1 /* Definitions for thread-local data handling. linuxthreads/ARM version.
2 Copyright (C) 2004 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/>. */
25 # include <pt-machine.h>
28 /* Type for the dtv. */
43 /* Reserved for the thread implementation. Unused in LinuxThreads. */
49 /* We can support TLS only if the floating-stack support is available.
50 However, we want to compile in the support and test at runtime whether
51 the running kernel can support it or not. To avoid bothering with the
52 TLS support code at all, use configure --without-tls.
54 We need USE_TLS to be consistently defined, for ldsodefs.h conditionals.
55 But some of the code below can cause problems in building libpthread
56 (e.g. useldt.h will defined FLOATING_STACKS when it shouldn't). */
58 /* LinuxThreads can only support TLS if both floating stacks and support
59 from the tools are available.
61 We have to define USE_TLS consistently, or ldsodefs.h will lay out types
62 differently between an NPTL build and a LinuxThreads build. It can be set
63 for libc.so and not libpthread.so, but only if we provide appropriate padding
64 in the _pthread_descr_struct.
66 Currently nothing defines FLOATING_STACKS. We could assume this based on
67 kernel version once the TLS patches are available in kernel.org.
69 To avoid bothering with the TLS support code at all, use configure
72 #if defined HAVE_TLS_SUPPORT \
73 && (defined FLOATING_STACKS || !defined IS_IN_libpthread)
75 /* Signal that TLS support is available. */
78 /* Include padding in _pthread_descr_struct so that libc can find p_errno,
79 if libpthread will only include the padding because of the !IS_IN_libpthread
81 #ifndef FLOATING_STACKS
82 # define INCLUDE_TLS_PADDING 1
85 # ifndef __ASSEMBLER__
86 /* Get system call information. */
89 /* This is the size of the initial TCB. */
90 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
92 /* Alignment requirements for the initial TCB. */
93 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
95 /* This is the size of the TCB. */
96 # define TLS_TCB_SIZE sizeof (tcbhead_t)
98 /* Alignment requirements for the TCB. */
99 # define TLS_TCB_ALIGN __alignof__ (tcbhead_t)
101 /* This is the size we need before TCB. */
102 # define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct)
104 /* The DTV is allocated at the TP; the TCB is placed elsewhere. */
105 # define TLS_DTV_AT_TP 1
107 /* Install the dtv pointer. The pointer passed is to the element with
108 index -1 which contain the length. */
109 # define INSTALL_DTV(TCBP, DTVP) \
110 (((tcbhead_t *) (TCBP))->dtv = (DTVP) + 1)
112 /* Install new dtv for current thread. */
113 # define INSTALL_NEW_DTV(DTV) \
114 (((tcbhead_t *)__builtin_thread_pointer ())->dtv = (DTV))
116 /* Return dtv of given thread descriptor. */
117 # define GET_DTV(TCBP) \
118 (((tcbhead_t *) (TCBP))->dtv)
120 /* Code to initially initialize the thread pointer. This might need
121 special attention since 'errno' is not yet available and if the
122 operation can cause a failure 'errno' must not be touched. */
123 # define TLS_INIT_TP(TCBP, SECONDCALL) \
124 ({ INTERNAL_SYSCALL_DECL (err); \
126 result_var = INTERNAL_SYSCALL_ARM (set_tls, err, 1, (TCBP)); \
127 INTERNAL_SYSCALL_ERROR_P (result_var, err) \
128 ? "unknown error" : NULL; })
130 /* Return the address of the dtv for the current thread. */
131 # define THREAD_DTV() \
132 (((tcbhead_t *)__builtin_thread_pointer ())->dtv)
134 /* Return the thread descriptor for the current thread. */
136 # define THREAD_SELF \
137 ((pthread_descr)__builtin_thread_pointer () - 1)
139 # undef INIT_THREAD_SELF
140 # define INIT_THREAD_SELF(DESCR, NR) \
141 TLS_INIT_TP ((struct _pthread_descr_struct *)(DESCR) + 1, 0)
143 /* Get the thread descriptor definition. */
144 # include <linuxthreads/descr.h>
146 /* ??? Generic bits of LinuxThreads may call these macros with
147 DESCR set to NULL. We are expected to be able to reference
150 In our case, we'd really prefer to use DESCR, since lots of
151 PAL_code calls would be expensive. We can only trust that
152 the compiler does its job and unifies the multiple
153 __builtin_thread_pointer instances. */
155 #define THREAD_GETMEM(descr, member) \
156 ((void) sizeof (descr), THREAD_SELF->member)
157 #define THREAD_GETMEM_NC(descr, member) \
158 ((void) sizeof (descr), THREAD_SELF->member)
159 #define THREAD_SETMEM(descr, member, value) \
160 ((void) sizeof (descr), THREAD_SELF->member = (value))
161 #define THREAD_SETMEM_NC(descr, member, value) \
162 ((void) sizeof (descr), THREAD_SELF->member = (value))
164 /* Initializing the thread pointer will generate a SIGILL if the syscall
166 #define TLS_INIT_TP_EXPENSIVE 1
168 # endif /* HAVE_TLS_SUPPORT */
169 #endif /* __ASSEMBLER__ */