2.9
[glibc/nacl-glibc.git] / nptl / sysdeps / sparc / tls.h
blobdc1b3868c98a545428f7f8fee8d0a03736999d10
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.
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>
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 <kernel-features.h>
32 /* Type for the dtv. */
33 typedef union dtv
35 size_t counter;
36 struct
38 void *val;
39 bool is_static;
40 } pointer;
41 } dtv_t;
43 typedef struct
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;
64 #else /* __ASSEMBLER__ */
65 # include <tcb-offsets.h>
66 #endif /* __ASSEMBLER__ */
68 /* We require TLS support in the tools. */
69 #ifndef HAVE_TLS_SUPPORT
70 # error "TLS support is required."
71 #endif
73 #ifndef __ASSEMBLER__
74 /* Get system call information. */
75 # include <sysdep.h>
77 /* Get the thread descriptor definition. */
78 # include <nptl/descr.h>
80 register struct pthread *__thread_self __asm__("%g7");
82 /* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
83 because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
84 struct pthread even when not linked with -lpthread. */
85 # define TLS_INIT_TCB_SIZE sizeof (struct pthread)
87 /* Alignment requirements for the initial TCB. */
88 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
90 /* This is the size of the TCB. */
91 # define TLS_TCB_SIZE sizeof (struct pthread)
93 /* Alignment requirements for the TCB. */
94 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
96 /* The TCB can have any size and the memory following the address the
97 thread pointer points to is unspecified. Allocate the TCB there. */
98 # define TLS_TCB_AT_TP 1
100 /* Install the dtv pointer. The pointer passed is to the element with
101 index -1 which contain the length. */
102 # define INSTALL_DTV(descr, dtvp) \
103 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
105 /* Install new dtv for current thread. */
106 # define INSTALL_NEW_DTV(DTV) \
107 (((tcbhead_t *) __thread_self)->dtv = (DTV))
109 /* Return dtv of given thread descriptor. */
110 # define GET_DTV(descr) \
111 (((tcbhead_t *) (descr))->dtv)
113 /* Code to initially initialize the thread pointer. */
114 # define TLS_INIT_TP(descr, secondcall) \
115 (__thread_self = (__typeof (__thread_self)) (descr), NULL)
117 /* Return the address of the dtv for the current thread. */
118 # define THREAD_DTV() \
119 (((tcbhead_t *) __thread_self)->dtv)
121 /* Return the thread descriptor for the current thread. */
122 #define THREAD_SELF __thread_self
124 /* Magic for libthread_db to know how to do THREAD_SELF. */
125 # define DB_THREAD_SELF_INCLUDE <sys/ucontext.h>
126 # define DB_THREAD_SELF \
127 REGISTER (32, 32, REG_G7 * 4, 0) REGISTER (64, 64, REG_G7 * 8, 0)
129 /* Access to data in the thread descriptor is easy. */
130 #define THREAD_GETMEM(descr, member) \
131 descr->member
132 #define THREAD_GETMEM_NC(descr, member, idx) \
133 descr->member[idx]
134 #define THREAD_SETMEM(descr, member, value) \
135 descr->member = (value)
136 #define THREAD_SETMEM_NC(descr, member, idx, value) \
137 descr->member[idx] = (value)
139 /* Set the stack guard field in TCB head. */
140 #define THREAD_SET_STACK_GUARD(value) \
141 THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
142 # define THREAD_COPY_STACK_GUARD(descr) \
143 ((descr)->header.stack_guard \
144 = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
146 /* Get/set the stack guard field in TCB head. */
147 #define THREAD_GET_POINTER_GUARD() \
148 THREAD_GETMEM (THREAD_SELF, header.pointer_guard)
149 #define THREAD_SET_POINTER_GUARD(value) \
150 THREAD_SETMEM (THREAD_SELF, header.pointer_guard, value)
151 # define THREAD_COPY_POINTER_GUARD(descr) \
152 ((descr)->header.pointer_guard = THREAD_GET_POINTER_GUARD ())
154 /* Get and set the global scope generation counter in struct pthread. */
155 #define THREAD_GSCOPE_FLAG_UNUSED 0
156 #define THREAD_GSCOPE_FLAG_USED 1
157 #define THREAD_GSCOPE_FLAG_WAIT 2
158 #define THREAD_GSCOPE_RESET_FLAG() \
159 do \
160 { int __res \
161 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
162 THREAD_GSCOPE_FLAG_UNUSED); \
163 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
164 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
166 while (0)
167 #define THREAD_GSCOPE_SET_FLAG() \
168 do \
170 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
171 atomic_write_barrier (); \
173 while (0)
174 #define THREAD_GSCOPE_WAIT() \
175 GL(dl_wait_lookup_done) ()
177 #endif /* !ASSEMBLER */
179 #endif /* tls.h */