]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl/sysdeps/sparc/tls.h
PowerPC: remove wrong roundl implementation for PowerPC64
[thirdparty/glibc.git] / nptl / sysdeps / sparc / tls.h
CommitLineData
cd2fbe58 1/* Definitions for thread-local data handling. NPTL/sparc version.
d4697bc9 2 Copyright (C) 2003-2014 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
PE
16 License along with the GNU C Library; if not, see
17 <http://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>
cd2fbe58
UD
30
31/* Type for the dtv. */
32typedef union dtv
33{
34 size_t counter;
9dcafc55
UD
35 struct
36 {
37 void *val;
38 bool is_static;
39 } pointer;
cd2fbe58
UD
40} dtv_t;
41
42typedef struct
43{
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;
ef0af159
JJ
49#if __WORDSIZE == 64
50 int gscope_flag;
51#endif
35f1e827
UD
52 uintptr_t sysinfo;
53 uintptr_t stack_guard;
305bb37e 54 uintptr_t pointer_guard;
ef0af159
JJ
55#if __WORDSIZE != 64
56 int gscope_flag;
57#endif
558f0300
JJ
58#ifndef __ASSUME_PRIVATE_FUTEX
59 int private_futex;
60#endif
cd2fbe58
UD
61} tcbhead_t;
62
63#else /* __ASSEMBLER__ */
64# include <tcb-offsets.h>
65#endif /* __ASSEMBLER__ */
66
cd2fbe58 67
cd2fbe58
UD
68#ifndef __ASSEMBLER__
69/* Get system call information. */
70# include <sysdep.h>
71
72/* Get the thread descriptor definition. */
73# include <nptl/descr.h>
74
75register struct pthread *__thread_self __asm__("%g7");
76
f7d78e18
UD
77/* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
78 because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
79 struct pthread even when not linked with -lpthread. */
80# define TLS_INIT_TCB_SIZE sizeof (struct pthread)
cd2fbe58
UD
81
82/* Alignment requirements for the initial TCB. */
f7d78e18 83# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
cd2fbe58
UD
84
85/* This is the size of the TCB. */
86# define TLS_TCB_SIZE sizeof (struct pthread)
87
88/* Alignment requirements for the TCB. */
89# define TLS_TCB_ALIGN __alignof__ (struct pthread)
90
91/* The TCB can have any size and the memory following the address the
92 thread pointer points to is unspecified. Allocate the TCB there. */
93# define TLS_TCB_AT_TP 1
94
95/* Install the dtv pointer. The pointer passed is to the element with
96 index -1 which contain the length. */
97# define INSTALL_DTV(descr, dtvp) \
98 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
99
100/* Install new dtv for current thread. */
101# define INSTALL_NEW_DTV(DTV) \
102 (((tcbhead_t *) __thread_self)->dtv = (DTV))
103
104/* Return dtv of given thread descriptor. */
105# define GET_DTV(descr) \
106 (((tcbhead_t *) (descr))->dtv)
107
108/* Code to initially initialize the thread pointer. */
109# define TLS_INIT_TP(descr, secondcall) \
110 (__thread_self = (__typeof (__thread_self)) (descr), NULL)
111
112/* Return the address of the dtv for the current thread. */
113# define THREAD_DTV() \
114 (((tcbhead_t *) __thread_self)->dtv)
115
116/* Return the thread descriptor for the current thread. */
117#define THREAD_SELF __thread_self
118
7f08f55a 119/* Magic for libthread_db to know how to do THREAD_SELF. */
7f08f55a 120# define DB_THREAD_SELF \
f0762164
DM
121 REGISTER (32, 32, 10 * 4, 0) \
122 REGISTER (64, __WORDSIZE, (6 * 8) + (__WORDSIZE==64?0:4), 0)
7f08f55a 123
cd2fbe58
UD
124/* Access to data in the thread descriptor is easy. */
125#define THREAD_GETMEM(descr, member) \
126 descr->member
127#define THREAD_GETMEM_NC(descr, member, idx) \
128 descr->member[idx]
129#define THREAD_SETMEM(descr, member, value) \
130 descr->member = (value)
131#define THREAD_SETMEM_NC(descr, member, idx, value) \
132 descr->member[idx] = (value)
133
35f1e827
UD
134/* Set the stack guard field in TCB head. */
135#define THREAD_SET_STACK_GUARD(value) \
136 THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
137# define THREAD_COPY_STACK_GUARD(descr) \
138 ((descr)->header.stack_guard \
139 = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
140
305bb37e
UD
141/* Get/set the stack guard field in TCB head. */
142#define THREAD_GET_POINTER_GUARD() \
143 THREAD_GETMEM (THREAD_SELF, header.pointer_guard)
144#define THREAD_SET_POINTER_GUARD(value) \
145 THREAD_SETMEM (THREAD_SELF, header.pointer_guard, value)
146# define THREAD_COPY_POINTER_GUARD(descr) \
147 ((descr)->header.pointer_guard = THREAD_GET_POINTER_GUARD ())
148
991fa82b
UD
149/* Get and set the global scope generation counter in struct pthread. */
150#define THREAD_GSCOPE_FLAG_UNUSED 0
151#define THREAD_GSCOPE_FLAG_USED 1
152#define THREAD_GSCOPE_FLAG_WAIT 2
153#define THREAD_GSCOPE_RESET_FLAG() \
154 do \
155 { int __res \
156 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
157 THREAD_GSCOPE_FLAG_UNUSED); \
158 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
085a4412 159 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
991fa82b
UD
160 } \
161 while (0)
162#define THREAD_GSCOPE_SET_FLAG() \
163 do \
164 { \
165 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
166 atomic_write_barrier (); \
167 } \
168 while (0)
169#define THREAD_GSCOPE_WAIT() \
170 GL(dl_wait_lookup_done) ()
171
cd2fbe58
UD
172#endif /* !ASSEMBLER */
173
174#endif /* tls.h */