(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / nptl / sysdeps / sh / tls.h
blobdb490ab7ee62b34231453be6188b83f547959c89
1 /* Definition for thread-local data handling. NPTL/SH 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 # include <dl-sysdep.h>
25 #ifndef __ASSEMBLER__
26 # include <stddef.h>
27 # include <stdint.h>
29 /* Type for the dtv. */
30 typedef union dtv
32 size_t counter;
33 void *pointer;
34 } dtv_t;
36 typedef struct
38 dtv_t *dtv;
39 void *private;
40 } tcbhead_t;
42 # define TLS_MULTIPLE_THREADS_IN_TCB 1
44 #else /* __ASSEMBLER__ */
45 # include <tcb-offsets.h>
46 #endif /* __ASSEMBLER__ */
49 /* We require TLS support in the tools. */
50 #ifndef HAVE_TLS_SUPPORT
51 # error "TLS support is required."
52 #endif
54 /* Signal that TLS support is available. */
55 # define USE_TLS 1
57 #ifndef __ASSEMBLER__
59 /* Get system call information. */
60 # include <sysdep.h>
62 /* This is the size of the initial TCB. */
63 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
65 /* Alignment requirements for the initial TCB. */
66 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
68 /* This is the size of the TCB. */
69 # define TLS_TCB_SIZE sizeof (tcbhead_t)
71 /* This is the size we need before TCB. */
72 # define TLS_PRE_TCB_SIZE sizeof (struct pthread)
74 /* Alignment requirements for the TCB. */
75 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
77 /* The TLS blocks start right after the TCB. */
78 # define TLS_DTV_AT_TP 1
80 /* Get the thread descriptor definition. */
81 # include <nptl/descr.h>
83 /* Install the dtv pointer. The pointer passed is to the element with
84 index -1 which contain the length. */
85 # define INSTALL_DTV(tcbp, dtvp) \
86 ((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1
88 /* Install new dtv for current thread. */
89 # define INSTALL_NEW_DTV(dtv) \
90 ({ tcbhead_t *__tcbp; \
91 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
92 __tcbp->dtv = (dtv);})
94 /* Return dtv of given thread descriptor. */
95 # define GET_DTV(tcbp) \
96 (((tcbhead_t *) (tcbp))->dtv)
98 /* Code to initially initialize the thread pointer. This might need
99 special attention since 'errno' is not yet available and if the
100 operation can cause a failure 'errno' must not be touched. */
101 # define TLS_INIT_TP(tcbp, secondcall) \
102 ({ __asm __volatile ("ldc %0,gbr" : : "r" (tcbp)); 0; })
104 /* Return the address of the dtv for the current thread. */
105 # define THREAD_DTV() \
106 ({ tcbhead_t *__tcbp; \
107 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
108 __tcbp->dtv;})
110 /* Return the thread descriptor for the current thread.
111 The contained asm must *not* be marked volatile since otherwise
112 assignments like
113 struct pthread *self = thread_self();
114 do not get optimized away. */
115 # define THREAD_SELF \
116 ({ struct pthread *__self; \
117 __asm ("stc gbr,%0" : "=r" (__self)); \
118 __self - 1;})
120 /* Magic for libthread_db to know how to do THREAD_SELF. */
121 # define DB_THREAD_SELF \
122 REGISTER (32, 32, REG_GBR * 4, -sizeof (struct pthread))
124 /* Read member of the thread descriptor directly. */
125 # define THREAD_GETMEM(descr, member) (descr->member)
127 /* Same as THREAD_GETMEM, but the member offset can be non-constant. */
128 # define THREAD_GETMEM_NC(descr, member, idx) (descr->member[idx])
130 /* Set member of the thread descriptor directly. */
131 # define THREAD_SETMEM(descr, member, value) \
132 descr->member = (value)
134 /* Same as THREAD_SETMEM, but the member offset can be non-constant. */
135 # define THREAD_SETMEM_NC(descr, member, idx, value) \
136 descr->member[idx] = (value)
138 #endif /* __ASSEMBLER__ */
140 #endif /* tls.h */