]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/sparc/nptl/tls.h
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / sparc / nptl / tls.h
CommitLineData
cd2fbe58 1/* Definitions for thread-local data handling. NPTL/sparc version.
2b778ceb 2 Copyright (C) 2003-2021 Free Software Foundation, Inc.
cd2fbe58
UD
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
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
cd2fbe58
UD
18
19#ifndef _TLS_H
20#define _TLS_H
21
22#include <dl-sysdep.h>
23#ifndef __ASSEMBLER__
9dcafc55 24# include <stdbool.h>
cd2fbe58
UD
25# include <stddef.h>
26# include <stdint.h>
27# include <stdlib.h>
28# include <list.h>
558f0300 29# include <kernel-features.h>
aca1daef 30# include <dl-dtv.h>
cd2fbe58
UD
31
32typedef struct
33{
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;
ef0af159
JJ
39#if __WORDSIZE == 64
40 int gscope_flag;
41#endif
35f1e827
UD
42 uintptr_t sysinfo;
43 uintptr_t stack_guard;
305bb37e 44 uintptr_t pointer_guard;
ef0af159
JJ
45#if __WORDSIZE != 64
46 int gscope_flag;
47#endif
cd2fbe58
UD
48} tcbhead_t;
49
50#else /* __ASSEMBLER__ */
51# include <tcb-offsets.h>
52#endif /* __ASSEMBLER__ */
53
cd2fbe58 54
cd2fbe58
UD
55#ifndef __ASSEMBLER__
56/* Get system call information. */
57# include <sysdep.h>
58
cd2fbe58
UD
59register struct pthread *__thread_self __asm__("%g7");
60
f7d78e18
UD
61/* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
62 because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
63 struct pthread even when not linked with -lpthread. */
64# define TLS_INIT_TCB_SIZE sizeof (struct pthread)
cd2fbe58
UD
65
66/* Alignment requirements for the initial TCB. */
f7d78e18 67# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
cd2fbe58
UD
68
69/* This is the size of the TCB. */
70# define TLS_TCB_SIZE sizeof (struct pthread)
71
72/* Alignment requirements for the TCB. */
73# define TLS_TCB_ALIGN __alignof__ (struct pthread)
74
75/* The TCB can have any size and the memory following the address the
76 thread pointer points to is unspecified. Allocate the TCB there. */
77# define TLS_TCB_AT_TP 1
498a2233
RM
78# define TLS_DTV_AT_TP 0
79
80/* Get the thread descriptor definition. */
81# include <nptl/descr.h>
cd2fbe58
UD
82
83/* Install the dtv pointer. The pointer passed is to the element with
84 index -1 which contain the length. */
85# define INSTALL_DTV(descr, dtvp) \
86 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
87
88/* Install new dtv for current thread. */
89# define INSTALL_NEW_DTV(DTV) \
90 (((tcbhead_t *) __thread_self)->dtv = (DTV))
91
92/* Return dtv of given thread descriptor. */
93# define GET_DTV(descr) \
94 (((tcbhead_t *) (descr))->dtv)
95
96/* Code to initially initialize the thread pointer. */
774f9285 97# define TLS_INIT_TP(descr) \
cd2fbe58
UD
98 (__thread_self = (__typeof (__thread_self)) (descr), NULL)
99
b0725f43
RM
100/* Value passed to 'clone' for initialization of the thread register. */
101# define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd)
102
cd2fbe58
UD
103/* Return the address of the dtv for the current thread. */
104# define THREAD_DTV() \
105 (((tcbhead_t *) __thread_self)->dtv)
106
107/* Return the thread descriptor for the current thread. */
108#define THREAD_SELF __thread_self
109
7f08f55a 110/* Magic for libthread_db to know how to do THREAD_SELF. */
7f08f55a 111# define DB_THREAD_SELF \
f0762164
DM
112 REGISTER (32, 32, 10 * 4, 0) \
113 REGISTER (64, __WORDSIZE, (6 * 8) + (__WORDSIZE==64?0:4), 0)
7f08f55a 114
cd2fbe58
UD
115/* Access to data in the thread descriptor is easy. */
116#define THREAD_GETMEM(descr, member) \
117 descr->member
118#define THREAD_GETMEM_NC(descr, member, idx) \
119 descr->member[idx]
120#define THREAD_SETMEM(descr, member, value) \
121 descr->member = (value)
122#define THREAD_SETMEM_NC(descr, member, idx, value) \
123 descr->member[idx] = (value)
124
35f1e827
UD
125/* Set the stack guard field in TCB head. */
126#define THREAD_SET_STACK_GUARD(value) \
127 THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
128# define THREAD_COPY_STACK_GUARD(descr) \
129 ((descr)->header.stack_guard \
130 = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
131
305bb37e
UD
132/* Get/set the stack guard field in TCB head. */
133#define THREAD_GET_POINTER_GUARD() \
134 THREAD_GETMEM (THREAD_SELF, header.pointer_guard)
135#define THREAD_SET_POINTER_GUARD(value) \
136 THREAD_SETMEM (THREAD_SELF, header.pointer_guard, value)
137# define THREAD_COPY_POINTER_GUARD(descr) \
138 ((descr)->header.pointer_guard = THREAD_GET_POINTER_GUARD ())
139
991fa82b 140/* Get and set the global scope generation counter in struct pthread. */
a5df0318 141#define THREAD_GSCOPE_IN_TCB 1
991fa82b
UD
142#define THREAD_GSCOPE_FLAG_UNUSED 0
143#define THREAD_GSCOPE_FLAG_USED 1
144#define THREAD_GSCOPE_FLAG_WAIT 2
145#define THREAD_GSCOPE_RESET_FLAG() \
146 do \
147 { int __res \
148 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
149 THREAD_GSCOPE_FLAG_UNUSED); \
150 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
085a4412 151 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
991fa82b
UD
152 } \
153 while (0)
154#define THREAD_GSCOPE_SET_FLAG() \
155 do \
156 { \
157 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
158 atomic_write_barrier (); \
159 } \
160 while (0)
991fa82b 161
cd2fbe58
UD
162#endif /* !ASSEMBLER */
163
164#endif /* tls.h */