blob: 81b41eb73cceb09bdc25bd41cbedc6cda2e2575c [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* Definitions for thread-local data handling. linuxthreads/IA-64 version.
2 Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
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
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. */
19
20#ifndef _TLS_H
21#define _TLS_H
22
23#ifndef __ASSEMBLER__
24
25# include <pt-machine.h>
26# include <stdbool.h>
27# include <stddef.h>
28
29/* Type for the dtv. */
30typedef union dtv
31{
32 size_t counter;
33 struct
34 {
35 void *val;
36 bool is_static;
37 } pointer;
38} dtv_t;
39
40#else /* __ASSEMBLER__ */
41# include <tcb-offsets.h>
42#endif /* __ASSEMBLER__ */
43
44#ifdef HAVE_TLS_SUPPORT
45
46/* Signal that TLS support is available. */
47# define USE_TLS 1
48
49# ifndef __ASSEMBLER__
50
51typedef struct
52{
53 dtv_t *dtv;
54 void *private;
55} tcbhead_t;
56
57/* This is the size of the initial TCB. */
58# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
59
60/* Alignment requirements for the initial TCB. */
61# define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
62
63/* This is the size of the TCB. */
64# define TLS_TCB_SIZE sizeof (tcbhead_t)
65
66/* This is the size we need before TCB. */
67# define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct)
68
69/* Alignment requirements for the TCB. */
70# define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
71
72/* The DTV is allocated at the TP; the TCB is placed elsewhere. */
73# define TLS_DTV_AT_TP 1
74
75/* Install the dtv pointer. The pointer passed is to the element with
76 index -1 which contain the length. */
77# define INSTALL_DTV(tcbp, dtvp) \
78 ((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1
79
80/* Install new dtv for current thread. */
81# define INSTALL_NEW_DTV(DTV) \
82 (((tcbhead_t *)__thread_self)->dtv = (DTV))
83
84/* Return dtv of given thread descriptor. */
85# define GET_DTV(tcbp) \
86 (((tcbhead_t *) (tcbp))->dtv)
87
88#if defined NEED_DL_SYSINFO
89# define INIT_SYSINFO \
90 (((tcbhead_t *) __thread_self)->private = (void *) GLRO(dl_sysinfo))
91#else
92# define INIT_SYSINFO 0
93#endif
94
95/* Code to initially initialize the thread pointer. This might need
96 special attention since 'errno' is not yet available and if the
97 operation can cause a failure 'errno' must not be touched. */
98# define TLS_INIT_TP(tcbp, secondcall) \
99 (__thread_self = (__typeof (__thread_self)) (tcbp), INIT_SYSINFO, NULL)
100
101/* Return the address of the dtv for the current thread. */
102# define THREAD_DTV() \
103 (((tcbhead_t *)__thread_self)->dtv)
104
105/* Return the thread descriptor for the current thread. */
106# undef THREAD_SELF
107# define THREAD_SELF (__thread_self - 1)
108
109# undef INIT_THREAD_SELF
110# define INIT_THREAD_SELF(descr, nr) \
111 (__thread_self = (struct _pthread_descr_struct *)(descr) + 1)
112
113# define TLS_MULTIPLE_THREADS_IN_TCB 1
114
115# endif
116
117#else
118
119# ifndef __ASSEMBLER__
120
121typedef struct
122{
123 void *tcb;
124 dtv_t *dtv;
125 void *self;
126 int multiple_threads;
127} tcbhead_t;
128
129# define NONTLS_INIT_TP \
130 do { \
131 static const tcbhead_t nontls_init_tp = { .multiple_threads = 0 }; \
132 __thread_self = (__typeof (__thread_self)) &nontls_init_tp; \
133 } while (0)
134
135#endif
136
137#endif /* USE_TLS */
138
139#endif /* tls.h */