]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libpthread/nptl/sysdeps/sparc/tls.h
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libpthread / nptl / sysdeps / sparc / tls.h
1 /* Definitions for thread-local data handling.  NPTL/sparc version.
2    Copyright (C) 2003, 2005, 2006, 2007 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 #ifndef __ASSEMBLER__
24 # include <stdbool.h>
25 # include <stddef.h>
26 # include <stdint.h>
27 # include <stdlib.h>
28 # include <list.h>
29 # include <bits/kernel-features.h>
30
31 /* Type for the dtv.  */
32 typedef union dtv
33 {
34   size_t counter;
35   struct
36   {
37     void *val;
38     bool is_static;
39   } pointer;
40 } dtv_t;
41
42 typedef struct
43 {
44   void *tcb;            /* Pointer to the TCB.  Not necessary the
45                            thread descriptor used by libpthread.  */
46   dtv_t *dtv;
47   void *self;
48   int multiple_threads;
49 #if __WORDSIZE == 64
50   int gscope_flag;
51 #endif
52   uintptr_t sysinfo;
53   uintptr_t stack_guard;
54   uintptr_t pointer_guard;
55 #if __WORDSIZE != 64
56   int gscope_flag;
57 #endif
58 #ifndef __ASSUME_PRIVATE_FUTEX
59   int private_futex;
60 #endif
61 } tcbhead_t;
62
63 #else /* __ASSEMBLER__ */
64 # include <tcb-offsets.h>
65 #endif /* __ASSEMBLER__ */
66
67 /* We require TLS support in the tools.  */
68 #define HAVE_TLS_SUPPORT
69 #define HAVE___THREAD 1
70 #define HAVE_TLS_MODEL_ATTRIBUTE 1
71
72 /* Signal that TLS support is available.  */
73 #define USE_TLS        1
74
75 #ifndef __ASSEMBLER__
76 /* Get system call information.  */
77 # include <sysdep.h>
78
79 /* Get the thread descriptor definition.  */
80 # include <descr.h>
81
82 register struct pthread *__thread_self __asm__("%g7");
83
84 /* This is the size of the initial TCB.  Can't be just sizeof (tcbhead_t),
85    because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
86    struct pthread even when not linked with -lpthread.  */
87 # define TLS_INIT_TCB_SIZE sizeof (struct pthread)
88
89 /* Alignment requirements for the initial TCB.  */
90 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
91
92 /* This is the size of the TCB.  */
93 # define TLS_TCB_SIZE sizeof (struct pthread)
94
95 /* Alignment requirements for the TCB.  */
96 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
97
98 /* The TCB can have any size and the memory following the address the
99    thread pointer points to is unspecified.  Allocate the TCB there.  */
100 # define TLS_TCB_AT_TP  1
101
102 /* Install the dtv pointer.  The pointer passed is to the element with
103    index -1 which contain the length.  */
104 # define INSTALL_DTV(descr, dtvp) \
105   ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
106
107 /* Install new dtv for current thread.  */
108 # define INSTALL_NEW_DTV(DTV) \
109   (((tcbhead_t *) __thread_self)->dtv = (DTV))
110
111 /* Return dtv of given thread descriptor.  */
112 # define GET_DTV(descr) \
113   (((tcbhead_t *) (descr))->dtv)
114
115 /* Code to initially initialize the thread pointer.  */
116 # define TLS_INIT_TP(descr, secondcall) \
117   (__thread_self = (__typeof (__thread_self)) (descr), NULL)
118
119 /* Return the address of the dtv for the current thread.  */
120 # define THREAD_DTV() \
121   (((tcbhead_t *) __thread_self)->dtv)
122
123 /* Return the thread descriptor for the current thread.  */
124 #define THREAD_SELF  __thread_self
125
126 /* Magic for libthread_db to know how to do THREAD_SELF.  */
127 # define DB_THREAD_SELF_INCLUDE <sys/ucontext.h>
128 # define DB_THREAD_SELF \
129   REGISTER (32, 32, REG_G7 * 4, 0) REGISTER (64, 64, REG_G7 * 8, 0)
130
131 /* Access to data in the thread descriptor is easy.  */
132 #define THREAD_GETMEM(descr, member) \
133   descr->member
134 #define THREAD_GETMEM_NC(descr, member, idx) \
135   descr->member[idx]
136 #define THREAD_SETMEM(descr, member, value) \
137   descr->member = (value)
138 #define THREAD_SETMEM_NC(descr, member, idx, value) \
139   descr->member[idx] = (value)
140
141 /* Set the stack guard field in TCB head.  */
142 #define THREAD_SET_STACK_GUARD(value) \
143   THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
144 # define THREAD_COPY_STACK_GUARD(descr) \
145   ((descr)->header.stack_guard \
146    = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
147
148 /* Get/set the stack guard field in TCB head.  */
149 #define THREAD_GET_POINTER_GUARD() \
150   THREAD_GETMEM (THREAD_SELF, header.pointer_guard)
151 #define THREAD_SET_POINTER_GUARD(value) \
152   THREAD_SETMEM (THREAD_SELF, header.pointer_guard, value)
153 # define THREAD_COPY_POINTER_GUARD(descr) \
154   ((descr)->header.pointer_guard = THREAD_GET_POINTER_GUARD ())
155
156 /* Get and set the global scope generation counter in struct pthread.  */
157 #define THREAD_GSCOPE_FLAG_UNUSED 0
158 #define THREAD_GSCOPE_FLAG_USED   1
159 #define THREAD_GSCOPE_FLAG_WAIT   2
160 #define THREAD_GSCOPE_RESET_FLAG() \
161   do                                                                         \
162     { int __res                                                              \
163         = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag,             \
164                                THREAD_GSCOPE_FLAG_UNUSED);                   \
165       if (__res == THREAD_GSCOPE_FLAG_WAIT)                                  \
166         lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE);   \
167     }                                                                        \
168   while (0)
169 #define THREAD_GSCOPE_SET_FLAG() \
170   do                                                                         \
171     {                                                                        \
172       THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED;             \
173       atomic_write_barrier ();                                               \
174     }                                                                        \
175   while (0)
176 #define THREAD_GSCOPE_WAIT() \
177   GL(dl_wait_lookup_done) ()
178
179 #endif /* !ASSEMBLER */
180
181 #endif  /* tls.h */