Changes and additions migrated from cvs.devel.redhat.com:/cvs/devel/glibc to fedora...
[glibc.git] / linuxthreads / sysdeps / alpha / tls.h
blob9e15318b792acb6bc8280fd87193411a481f8168
1 /* Definitions for thread-local data handling. linuxthreads/Alpha version.
2 Copyright (C) 2002, 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;
36 typedef struct
38 dtv_t *dtv;
40 /* Reserved for the thread implementation. Unused in LinuxThreads. */
41 void *private;
42 } tcbhead_t;
43 #endif
46 #ifdef HAVE_TLS_SUPPORT
48 /* Signal that TLS support is available. */
49 # define USE_TLS 1
51 # ifndef __ASSEMBLER__
52 /* Get system call information. */
53 # include <sysdep.h>
55 /* This is the size of the initial TCB. */
56 # define TLS_INIT_TCB_SIZE 0
58 /* Alignment requirements for the initial TCB. */
59 # define TLS_INIT_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
61 /* This is the size of the TCB. */
62 # define TLS_TCB_SIZE 0
64 /* Alignment requirements for the TCB. */
65 # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
67 /* This is the size we need before TCB. */
68 # ifndef IS_IN_rtld
69 # define TLS_PRE_TCB_SIZE \
70 (sizeof (struct _pthread_descr_struct) \
71 + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
72 # else
73 # include <nptl-struct-pthread.h>
74 # define TLS_PRE_TCB_SIZE \
75 ((sizeof (struct _pthread_descr_struct) > NPTL_STRUCT_PTHREAD_SIZE \
76 ? sizeof (struct _pthread_descr_struct) : NPTL_STRUCT_PTHREAD_SIZE) \
77 + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
78 # endif
80 /* The DTV is allocated at the TP; the TCB is placed elsewhere. */
81 # define TLS_DTV_AT_TP 1
83 /* The following assumes that TP (R2 or R13) points to the end of the
84 TCB + 0x7000 (per the ABI). This implies that TCB address is
85 TP - 0x7000. As we define TLS_DTV_AT_TP we can
86 assume that the pthread struct is allocated immediately ahead of the
87 TCB. This implies that the pthread_descr address is
88 TP - (TLS_PRE_TCB_SIZE + 0x7000). */
89 /* ??? PPC uses offset 0x7000; seems like a good idea for alpha too,
90 but binutils not yet changed to match. */
91 # define TLS_TCB_OFFSET 0
93 /* Install the dtv pointer. The pointer passed is to the element with
94 index -1 which contain the length. */
95 # define INSTALL_DTV(TCBP, DTVP) \
96 (((tcbhead_t *) (TCBP))[-1].dtv = (DTVP) + 1)
98 /* Install new dtv for current thread. */
99 # define INSTALL_NEW_DTV(DTV) \
100 (THREAD_DTV() = (DTV))
102 /* Return dtv of given thread descriptor. */
103 # define GET_DTV(TCBP) \
104 (((tcbhead_t *) (TCBP))[-1].dtv)
106 /* Code to initially initialize the thread pointer. This might need
107 special attention since 'errno' is not yet available and if the
108 operation can cause a failure 'errno' must not be touched. */
109 # define TLS_INIT_TP(TCBP, SECONDCALL) \
110 (__builtin_set_thread_pointer ((void *) (TCBP) + TLS_TCB_OFFSET), NULL)
112 /* Return the address of the dtv for the current thread. */
113 # define THREAD_DTV() \
114 (((tcbhead_t *) (__builtin_thread_pointer () - TLS_TCB_OFFSET))[-1].dtv)
116 /* Return the thread descriptor for the current thread. */
117 # undef THREAD_SELF
118 # define THREAD_SELF \
119 ((pthread_descr) (__builtin_thread_pointer () \
120 - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
122 # undef INIT_THREAD_SELF
123 # define INIT_THREAD_SELF(DESCR, NR) \
124 __builtin_set_thread_pointer ((char *)(DESCR) \
125 + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE)
127 /* Get the thread descriptor definition. */
128 # include <linuxthreads/descr.h>
130 /* ??? Generic bits of LinuxThreads may call these macros with
131 DESCR set to NULL. We are expected to be able to reference
132 the "current" value.
134 In our case, we'd really prefer to use DESCR, since lots of
135 PAL_code calls would be expensive. We can only trust that
136 the compiler does its job and unifies the multiple
137 __builtin_thread_pointer instances. */
139 #define THREAD_GETMEM(descr, member) \
140 ((void) sizeof (descr), THREAD_SELF->member)
141 #define THREAD_GETMEM_NC(descr, member) \
142 ((void) sizeof (descr), THREAD_SELF->member)
143 #define THREAD_SETMEM(descr, member, value) \
144 ((void) sizeof (descr), THREAD_SELF->member = (value))
145 #define THREAD_SETMEM_NC(descr, member, value) \
146 ((void) sizeof (descr), THREAD_SELF->member = (value))
148 # endif /* HAVE_TLS_SUPPORT */
149 #endif /* __ASSEMBLER__ */
151 #endif /* tls.h */