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