Fix powerpc software sqrtf (bug 17967).
[glibc.git] / sysdeps / sparc / nptl / tls.h
blob54bce7e950c3756a979d3afb7560e69bcc384e3c
1 /* Definitions for thread-local data handling. NPTL/sparc version.
2 Copyright (C) 2003-2015 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, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef _TLS_H
20 #define _TLS_H
22 #include <dl-sysdep.h>
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 <kernel-features.h>
31 /* Type for the dtv. */
32 typedef union dtv
34 size_t counter;
35 struct
37 void *val;
38 bool is_static;
39 } pointer;
40 } dtv_t;
42 typedef struct
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;
63 #else /* __ASSEMBLER__ */
64 # include <tcb-offsets.h>
65 #endif /* __ASSEMBLER__ */
68 #ifndef __ASSEMBLER__
69 /* Get system call information. */
70 # include <sysdep.h>
72 register struct pthread *__thread_self __asm__("%g7");
74 /* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
75 because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
76 struct pthread even when not linked with -lpthread. */
77 # define TLS_INIT_TCB_SIZE sizeof (struct pthread)
79 /* Alignment requirements for the initial TCB. */
80 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
82 /* This is the size of the TCB. */
83 # define TLS_TCB_SIZE sizeof (struct pthread)
85 /* Alignment requirements for the TCB. */
86 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
88 /* The TCB can have any size and the memory following the address the
89 thread pointer points to is unspecified. Allocate the TCB there. */
90 # define TLS_TCB_AT_TP 1
91 # define TLS_DTV_AT_TP 0
93 /* Get the thread descriptor definition. */
94 # include <nptl/descr.h>
96 /* Install the dtv pointer. The pointer passed is to the element with
97 index -1 which contain the length. */
98 # define INSTALL_DTV(descr, dtvp) \
99 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
101 /* Install new dtv for current thread. */
102 # define INSTALL_NEW_DTV(DTV) \
103 (((tcbhead_t *) __thread_self)->dtv = (DTV))
105 /* Return dtv of given thread descriptor. */
106 # define GET_DTV(descr) \
107 (((tcbhead_t *) (descr))->dtv)
109 /* Code to initially initialize the thread pointer. */
110 # define TLS_INIT_TP(descr) \
111 (__thread_self = (__typeof (__thread_self)) (descr), NULL)
113 /* Value passed to 'clone' for initialization of the thread register. */
114 # define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd)
116 /* Return the address of the dtv for the current thread. */
117 # define THREAD_DTV() \
118 (((tcbhead_t *) __thread_self)->dtv)
120 /* Return the thread descriptor for the current thread. */
121 #define THREAD_SELF __thread_self
123 /* Magic for libthread_db to know how to do THREAD_SELF. */
124 # define DB_THREAD_SELF \
125 REGISTER (32, 32, 10 * 4, 0) \
126 REGISTER (64, __WORDSIZE, (6 * 8) + (__WORDSIZE==64?0:4), 0)
128 /* Access to data in the thread descriptor is easy. */
129 #define THREAD_GETMEM(descr, member) \
130 descr->member
131 #define THREAD_GETMEM_NC(descr, member, idx) \
132 descr->member[idx]
133 #define THREAD_SETMEM(descr, member, value) \
134 descr->member = (value)
135 #define THREAD_SETMEM_NC(descr, member, idx, value) \
136 descr->member[idx] = (value)
138 /* Set the stack guard field in TCB head. */
139 #define THREAD_SET_STACK_GUARD(value) \
140 THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
141 # define THREAD_COPY_STACK_GUARD(descr) \
142 ((descr)->header.stack_guard \
143 = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
145 /* Get/set the stack guard field in TCB head. */
146 #define THREAD_GET_POINTER_GUARD() \
147 THREAD_GETMEM (THREAD_SELF, header.pointer_guard)
148 #define THREAD_SET_POINTER_GUARD(value) \
149 THREAD_SETMEM (THREAD_SELF, header.pointer_guard, value)
150 # define THREAD_COPY_POINTER_GUARD(descr) \
151 ((descr)->header.pointer_guard = THREAD_GET_POINTER_GUARD ())
153 /* Get and set the global scope generation counter in struct pthread. */
154 #define THREAD_GSCOPE_FLAG_UNUSED 0
155 #define THREAD_GSCOPE_FLAG_USED 1
156 #define THREAD_GSCOPE_FLAG_WAIT 2
157 #define THREAD_GSCOPE_RESET_FLAG() \
158 do \
159 { int __res \
160 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
161 THREAD_GSCOPE_FLAG_UNUSED); \
162 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
163 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
165 while (0)
166 #define THREAD_GSCOPE_SET_FLAG() \
167 do \
169 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
170 atomic_write_barrier (); \
172 while (0)
173 #define THREAD_GSCOPE_WAIT() \
174 GL(dl_wait_lookup_done) ()
176 #endif /* !ASSEMBLER */
178 #endif /* tls.h */