Updated to fedora-glibc-20061029T2155
[glibc.git] / nptl / sysdeps / sh / tls.h
blobd9aa1073b8d6079623cce51707be690cd29303bb
1 /* Definition for thread-local data handling. NPTL/SH version.
2 Copyright (C) 2003, 2005, 2006 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 <stdbool.h>
27 # include <stddef.h>
28 # include <stdint.h>
30 /* Type for the dtv. */
31 typedef union dtv
33 size_t counter;
34 struct
36 void *val;
37 bool is_static;
38 } pointer;
39 } dtv_t;
41 typedef struct
43 dtv_t *dtv;
44 uintptr_t pointer_guard;
45 } tcbhead_t;
47 # define TLS_MULTIPLE_THREADS_IN_TCB 1
49 #else /* __ASSEMBLER__ */
50 # include <tcb-offsets.h>
51 #endif /* __ASSEMBLER__ */
54 /* We require TLS support in the tools. */
55 #ifndef HAVE_TLS_SUPPORT
56 # error "TLS support is required."
57 #endif
59 #ifndef __ASSEMBLER__
61 /* Get system call information. */
62 # include <sysdep.h>
64 /* This is the size of the initial TCB. */
65 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
67 /* Alignment requirements for the initial TCB. */
68 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
70 /* This is the size of the TCB. */
71 # define TLS_TCB_SIZE sizeof (tcbhead_t)
73 /* This is the size we need before TCB. */
74 # define TLS_PRE_TCB_SIZE sizeof (struct pthread)
76 /* Alignment requirements for the TCB. */
77 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
79 /* The TLS blocks start right after the TCB. */
80 # define TLS_DTV_AT_TP 1
82 /* Get the thread descriptor definition. */
83 # include <nptl/descr.h>
85 /* Install the dtv pointer. The pointer passed is to the element with
86 index -1 which contain the length. */
87 # define INSTALL_DTV(tcbp, dtvp) \
88 ((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1
90 /* Install new dtv for current thread. */
91 # define INSTALL_NEW_DTV(dtv) \
92 ({ tcbhead_t *__tcbp; \
93 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
94 __tcbp->dtv = (dtv);})
96 /* Return dtv of given thread descriptor. */
97 # define GET_DTV(tcbp) \
98 (((tcbhead_t *) (tcbp))->dtv)
100 /* Code to initially initialize the thread pointer. This might need
101 special attention since 'errno' is not yet available and if the
102 operation can cause a failure 'errno' must not be touched. */
103 # define TLS_INIT_TP(tcbp, secondcall) \
104 ({ __asm __volatile ("ldc %0,gbr" : : "r" (tcbp)); 0; })
106 /* Return the address of the dtv for the current thread. */
107 # define THREAD_DTV() \
108 ({ tcbhead_t *__tcbp; \
109 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
110 __tcbp->dtv;})
112 /* Return the thread descriptor for the current thread.
113 The contained asm must *not* be marked volatile since otherwise
114 assignments like
115 struct pthread *self = thread_self();
116 do not get optimized away. */
117 # define THREAD_SELF \
118 ({ struct pthread *__self; \
119 __asm ("stc gbr,%0" : "=r" (__self)); \
120 __self - 1;})
122 /* Magic for libthread_db to know how to do THREAD_SELF. */
123 # define DB_THREAD_SELF \
124 REGISTER (32, 32, REG_GBR * 4, -sizeof (struct pthread))
126 /* Read member of the thread descriptor directly. */
127 # define THREAD_GETMEM(descr, member) (descr->member)
129 /* Same as THREAD_GETMEM, but the member offset can be non-constant. */
130 # define THREAD_GETMEM_NC(descr, member, idx) (descr->member[idx])
132 /* Set member of the thread descriptor directly. */
133 # define THREAD_SETMEM(descr, member, value) \
134 descr->member = (value)
136 /* Same as THREAD_SETMEM, but the member offset can be non-constant. */
137 # define THREAD_SETMEM_NC(descr, member, idx, value) \
138 descr->member[idx] = (value)
140 #define THREAD_GET_POINTER_GUARD() \
141 ({ tcbhead_t *__tcbp; \
142 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
143 __tcbp->pointer_guard;})
144 #define THREAD_SET_POINTER_GUARD(value) \
145 ({ tcbhead_t *__tcbp; \
146 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
147 __tcbp->pointer_guard = (value);})
148 #define THREAD_COPY_POINTER_GUARD(descr) \
149 ({ tcbhead_t *__tcbp; \
150 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
151 ((tcbhead_t *) (descr + 1))->pointer_guard = __tcbp->pointer_guard;})
153 #endif /* __ASSEMBLER__ */
155 #endif /* tls.h */