(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / linuxthreads / sysdeps / sh / tls.h
blob17a247c6b6cf6526e27cdc49b28ba57247e1ea84
1 /* Definition for thread-local data handling. linuxthreads/SH 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 # include <dl-sysdep.h>
24 # include <pt-machine.h>
26 #ifndef __ASSEMBLER__
27 # include <stddef.h>
28 # include <stdint.h>
30 /* Type for the dtv. */
31 typedef union dtv
33 size_t counter;
34 void *pointer;
35 } dtv_t;
37 #else /* __ASSEMBLER__ */
38 # include <tcb-offsets.h>
39 #endif /* __ASSEMBLER__ */
42 /* We can support TLS only if the floating-stack support is available. */
43 #if defined HAVE_TLS_SUPPORT \
44 && (defined FLOATING_STACKS || !defined IS_IN_libpthread)
46 /* Signal that TLS support is available. */
47 # define USE_TLS 1
49 # ifndef __ASSEMBLER__
51 typedef struct
53 dtv_t *dtv;
54 void *private;
55 } tcbhead_t;
57 /* This is the size of the initial TCB. */
58 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
60 /* Alignment requirements for the initial TCB. */
61 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
63 /* This is the size of the TCB. */
64 # define TLS_TCB_SIZE sizeof (tcbhead_t)
66 /* This is the size we need before TCB. */
67 # define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct)
69 /* Alignment requirements for the TCB. */
70 # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
72 /* The TLS blocks start right after the TCB. */
73 # define TLS_DTV_AT_TP 1
75 /* Install the dtv pointer. The pointer passed is to the element with
76 index -1 which contain the length. */
77 # define INSTALL_DTV(tcbp, dtvp) \
78 ((tcbhead_t *) (tcbp))->dtv = dtvp + 1
80 /* Install new dtv for current thread. */
81 # define INSTALL_NEW_DTV(dtv) \
82 ({ tcbhead_t *__tcbp; \
83 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
84 __tcbp->dtv = (dtv);})
86 /* Return dtv of given thread descriptor. */
87 # define GET_DTV(tcbp) \
88 (((tcbhead_t *) (tcbp))->dtv)
90 /* Code to initially initialize the thread pointer. This might need
91 special attention since 'errno' is not yet available and if the
92 operation can cause a failure 'errno' must not be touched. */
93 # define TLS_INIT_TP(tcbp, secondcall) \
94 ({ __asm __volatile ("ldc %0,gbr" : : "r" (tcbp)); 0; })
96 /* Return the address of the dtv for the current thread. */
97 # define THREAD_DTV() \
98 ({ tcbhead_t *__tcbp; \
99 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
100 __tcbp->dtv;})
102 /* Return the thread descriptor for the current thread. */
103 # undef THREAD_SELF
104 # define THREAD_SELF \
105 ({ struct _pthread_descr_struct *__self; \
106 __asm ("stc gbr,%0" : "=r" (__self)); \
107 __self - 1;})
109 # undef INIT_THREAD_SELF
110 # define INIT_THREAD_SELF(descr, nr) \
111 ({ struct _pthread_descr_struct *__self = (void *) descr; \
112 __asm __volatile ("ldc %0,gbr" : : "r" (__self + 1)); \
113 0; })
115 # define TLS_MULTIPLE_THREADS_IN_TCB 1
117 /* Get the thread descriptor definition. This must be after the
118 the definition of THREAD_SELF for TLS. */
119 # include <linuxthreads/descr.h>
121 # endif /* __ASSEMBLER__ */
123 #else
125 # ifndef __ASSEMBLER__
127 typedef struct
129 void *tcb;
130 dtv_t *dtv;
131 void *self;
132 int multiple_threads;
133 } tcbhead_t;
135 /* Get the thread descriptor definition. */
136 # include <linuxthreads/descr.h>
138 # define NONTLS_INIT_TP \
139 do { \
140 static const tcbhead_t nontls_init_tp = { .multiple_threads = 0 }; \
141 __asm __volatile ("ldc %0,gbr" : : "r" (&nontls_init_tp)); \
142 } while (0)
144 # endif /* __ASSEMBLER__ */
146 #endif /* HAVE_TLS_SUPPORT && (FLOATING_STACKS || !IS_IN_libpthread) */
148 #endif /* tls.h */