i386: Regenerate libm-test-ulps for for gcc 7 on i686
[glibc.git] / sysdeps / sparc / nptl / tls.h
blobd8548f3573886079c5dc9dee2c74b287ede76461
1 /* Definitions for thread-local data handling. NPTL/sparc version.
2 Copyright (C) 2003-2018 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>
30 # include <dl-dtv.h>
32 typedef struct
34 void *tcb; /* Pointer to the TCB. Not necessary the
35 thread descriptor used by libpthread. */
36 dtv_t *dtv;
37 void *self;
38 int multiple_threads;
39 #if __WORDSIZE == 64
40 int gscope_flag;
41 #endif
42 uintptr_t sysinfo;
43 uintptr_t stack_guard;
44 uintptr_t pointer_guard;
45 #if __WORDSIZE != 64
46 int gscope_flag;
47 #endif
48 #ifndef __ASSUME_PRIVATE_FUTEX
49 int private_futex;
50 #endif
51 } tcbhead_t;
53 #else /* __ASSEMBLER__ */
54 # include <tcb-offsets.h>
55 #endif /* __ASSEMBLER__ */
58 #ifndef __ASSEMBLER__
59 /* Get system call information. */
60 # include <sysdep.h>
62 register struct pthread *__thread_self __asm__("%g7");
64 /* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
65 because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
66 struct pthread even when not linked with -lpthread. */
67 # define TLS_INIT_TCB_SIZE sizeof (struct pthread)
69 /* Alignment requirements for the initial TCB. */
70 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
72 /* This is the size of the TCB. */
73 # define TLS_TCB_SIZE sizeof (struct pthread)
75 /* Alignment requirements for the TCB. */
76 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
78 /* The TCB can have any size and the memory following the address the
79 thread pointer points to is unspecified. Allocate the TCB there. */
80 # define TLS_TCB_AT_TP 1
81 # define TLS_DTV_AT_TP 0
83 /* Get the thread descriptor definition. */
84 # include <nptl/descr.h>
86 /* Install the dtv pointer. The pointer passed is to the element with
87 index -1 which contain the length. */
88 # define INSTALL_DTV(descr, dtvp) \
89 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
91 /* Install new dtv for current thread. */
92 # define INSTALL_NEW_DTV(DTV) \
93 (((tcbhead_t *) __thread_self)->dtv = (DTV))
95 /* Return dtv of given thread descriptor. */
96 # define GET_DTV(descr) \
97 (((tcbhead_t *) (descr))->dtv)
99 /* Code to initially initialize the thread pointer. */
100 # define TLS_INIT_TP(descr) \
101 (__thread_self = (__typeof (__thread_self)) (descr), NULL)
103 /* Value passed to 'clone' for initialization of the thread register. */
104 # define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd)
106 /* Return the address of the dtv for the current thread. */
107 # define THREAD_DTV() \
108 (((tcbhead_t *) __thread_self)->dtv)
110 /* Return the thread descriptor for the current thread. */
111 #define THREAD_SELF __thread_self
113 /* Magic for libthread_db to know how to do THREAD_SELF. */
114 # define DB_THREAD_SELF \
115 REGISTER (32, 32, 10 * 4, 0) \
116 REGISTER (64, __WORDSIZE, (6 * 8) + (__WORDSIZE==64?0:4), 0)
118 /* Access to data in the thread descriptor is easy. */
119 #define THREAD_GETMEM(descr, member) \
120 descr->member
121 #define THREAD_GETMEM_NC(descr, member, idx) \
122 descr->member[idx]
123 #define THREAD_SETMEM(descr, member, value) \
124 descr->member = (value)
125 #define THREAD_SETMEM_NC(descr, member, idx, value) \
126 descr->member[idx] = (value)
128 /* Set the stack guard field in TCB head. */
129 #define THREAD_SET_STACK_GUARD(value) \
130 THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
131 # define THREAD_COPY_STACK_GUARD(descr) \
132 ((descr)->header.stack_guard \
133 = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
135 /* Get/set the stack guard field in TCB head. */
136 #define THREAD_GET_POINTER_GUARD() \
137 THREAD_GETMEM (THREAD_SELF, header.pointer_guard)
138 #define THREAD_SET_POINTER_GUARD(value) \
139 THREAD_SETMEM (THREAD_SELF, header.pointer_guard, value)
140 # define THREAD_COPY_POINTER_GUARD(descr) \
141 ((descr)->header.pointer_guard = THREAD_GET_POINTER_GUARD ())
143 /* Get and set the global scope generation counter in struct pthread. */
144 #define THREAD_GSCOPE_FLAG_UNUSED 0
145 #define THREAD_GSCOPE_FLAG_USED 1
146 #define THREAD_GSCOPE_FLAG_WAIT 2
147 #define THREAD_GSCOPE_RESET_FLAG() \
148 do \
149 { int __res \
150 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
151 THREAD_GSCOPE_FLAG_UNUSED); \
152 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
153 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
155 while (0)
156 #define THREAD_GSCOPE_SET_FLAG() \
157 do \
159 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
160 atomic_write_barrier (); \
162 while (0)
163 #define THREAD_GSCOPE_WAIT() \
164 GL(dl_wait_lookup_done) ()
166 #endif /* !ASSEMBLER */
168 #endif /* tls.h */