]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/libpthread/linuxthreads/sysdeps/arm/tls.h
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / libpthread / linuxthreads / sysdeps / arm / tls.h
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.
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, see
17    <http://www.gnu.org/licenses/>.  */
18
19 #ifndef _TLS_H
20 #define _TLS_H
21
22 #ifndef __ASSEMBLER__
23
24 # include <stdbool.h>
25 # include <pt-machine.h>
26 # include <stddef.h>
27
28 /* Type for the dtv.  */
29 typedef union dtv
30 {
31   size_t counter;
32   struct
33   {
34     void *val;
35     bool is_static;
36   } pointer;
37 } dtv_t;
38
39 typedef struct
40 {
41   dtv_t *dtv;
42
43   /* Reserved for the thread implementation.  Unused in LinuxThreads.  */
44   void *private;
45 } tcbhead_t;
46 #endif
47
48
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.
53
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).  */
57
58 /* LinuxThreads can only support TLS if both floating stacks and support
59    from the tools are available.
60
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.
65
66    Currently nothing defines FLOATING_STACKS.  We could assume this based on
67    kernel version once the TLS patches are available in kernel.org.
68
69    To avoid bothering with the TLS support code at all, use configure
70    --without-tls.  */
71
72 #if defined HAVE_TLS_SUPPORT \
73     && (defined FLOATING_STACKS || !defined IS_IN_libpthread)
74
75 /* Signal that TLS support is available.  */
76 # define USE_TLS        1
77
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
80    check.  */
81 #ifndef FLOATING_STACKS
82 # define INCLUDE_TLS_PADDING    1
83 #endif
84
85 # ifndef __ASSEMBLER__
86 /* Get system call information.  */
87 #  include <sysdep.h>
88
89 /* This is the size of the initial TCB.  */
90 #  define TLS_INIT_TCB_SIZE     sizeof (tcbhead_t)
91
92 /* Alignment requirements for the initial TCB.  */
93 #  define TLS_INIT_TCB_ALIGN    __alignof__ (tcbhead_t)
94
95 /* This is the size of the TCB.  */
96 #  define TLS_TCB_SIZE          sizeof (tcbhead_t)
97
98 /* Alignment requirements for the TCB.  */
99 #  define TLS_TCB_ALIGN         __alignof__ (tcbhead_t)
100
101 /* This is the size we need before TCB.  */
102 #  define TLS_PRE_TCB_SIZE      sizeof (struct _pthread_descr_struct)
103
104 /* The DTV is allocated at the TP; the TCB is placed elsewhere.  */
105 #  define TLS_DTV_AT_TP 1
106
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)
111
112 /* Install new dtv for current thread.  */
113 #  define INSTALL_NEW_DTV(DTV) \
114   (((tcbhead_t *)__builtin_thread_pointer ())->dtv = (DTV))
115
116 /* Return dtv of given thread descriptor.  */
117 #  define GET_DTV(TCBP) \
118   (((tcbhead_t *) (TCBP))->dtv)
119
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);                                       \
125      long result_var;                                                   \
126      result_var = INTERNAL_SYSCALL_ARM (set_tls, err, 1, (TCBP));       \
127      INTERNAL_SYSCALL_ERROR_P (result_var, err)                         \
128        ? "unknown error" : NULL; })
129
130 /* Return the address of the dtv for the current thread.  */
131 #  define THREAD_DTV() \
132   (((tcbhead_t *)__builtin_thread_pointer ())->dtv)
133
134 /* Return the thread descriptor for the current thread.  */
135 #  undef THREAD_SELF
136 #  define THREAD_SELF \
137   ((pthread_descr)__builtin_thread_pointer () - 1)
138
139 #  undef INIT_THREAD_SELF
140 #  define INIT_THREAD_SELF(DESCR, NR) \
141   TLS_INIT_TP ((struct _pthread_descr_struct *)(DESCR) + 1, 0)
142
143 /* Get the thread descriptor definition.  */
144 #  include <linuxthreads/descr.h>
145
146 /* ??? Generic bits of LinuxThreads may call these macros with
147    DESCR set to NULL.  We are expected to be able to reference
148    the "current" value.
149
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.  */
154
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))
163
164 /* Initializing the thread pointer will generate a SIGILL if the syscall
165    is not available.  */
166 #define TLS_INIT_TP_EXPENSIVE 1
167
168 # endif /* HAVE_TLS_SUPPORT */
169 #endif /* __ASSEMBLER__ */
170
171 #endif  /* tls.h */