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