Update.
[platform/upstream/glibc.git] / nptl / sysdeps / sh / tls.h
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.
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, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #ifndef _TLS_H
21 #define _TLS_H
22
23 # include <dl-sysdep.h>
24
25 #ifndef __ASSEMBLER__
26 # include <stddef.h>
27 # include <stdint.h>
28
29 /* Type for the dtv.  */
30 typedef union dtv
31 {
32   size_t counter;
33   void *pointer;
34 } dtv_t;
35
36 typedef struct
37 {
38   dtv_t *dtv;
39   void *private;
40 } tcbhead_t;
41
42 # define TLS_MULTIPLE_THREADS_IN_TCB 1
43
44 #else /* __ASSEMBLER__ */
45 # include <tcb-offsets.h>
46 #endif /* __ASSEMBLER__ */
47
48
49 /* We require TLS support in the tools.  */
50 #ifndef HAVE_TLS_SUPPORT
51 # error "TLS support is required."
52 #endif
53
54 /* Signal that TLS support is available.  */
55 # define USE_TLS        1
56
57 #ifndef __ASSEMBLER__
58
59 /* Get system call information.  */
60 # include <sysdep.h>
61
62 /* This is the size of the initial TCB.  */
63 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
64
65 /* Alignment requirements for the initial TCB.  */
66 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
67
68 /* This is the size of the TCB.  */
69 # define TLS_TCB_SIZE sizeof (tcbhead_t)
70
71 /* This is the size we need before TCB.  */
72 # define TLS_PRE_TCB_SIZE sizeof (struct pthread)
73
74 /* Alignment requirements for the TCB.  */
75 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
76
77 /* The TLS blocks start right after the TCB.  */
78 # define TLS_DTV_AT_TP  1
79
80 /* Get the thread descriptor definition.  */
81 # include <nptl/descr.h>
82
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
87
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);})
93
94 /* Return dtv of given thread descriptor.  */
95 # define GET_DTV(tcbp) \
96   (((tcbhead_t *) (tcbp))->dtv)
97
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; })
103
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;})
109
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;})
119
120 /* Identifier for the current thread.  THREAD_SELF is usable but
121    sometimes more expensive than necessary as in this case.  */
122 # define THREAD_ID \
123   ({ struct pthread *__self;                                                  \
124      __asm ("stc gbr,%0" : "=r" (__self));                                    \
125      __self;})
126
127 /* Read member of the thread descriptor directly.  */
128 # define THREAD_GETMEM(descr, member) (descr->member)
129
130 /* Same as THREAD_GETMEM, but the member offset can be non-constant.  */
131 # define THREAD_GETMEM_NC(descr, member, idx) (descr->member[idx])
132
133 /* Set member of the thread descriptor directly.  */
134 # define THREAD_SETMEM(descr, member, value) \
135     descr->member = (value)
136
137 /* Same as THREAD_SETMEM, but the member offset can be non-constant.  */
138 # define THREAD_SETMEM_NC(descr, member, idx, value) \
139     descr->member[idx] = (value)
140
141 #endif /* __ASSEMBLER__ */
142
143 #endif  /* tls.h */