blob: f750f2d6f7d7cf6d3da655daa521712c267c11d9 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* Definitions for thread-local data handling. linuxthreads/s390 version.
2 Copyright (C) 2002, 2003, 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
40typedef struct
41{
42 void *tcb; /* Pointer to the TCB. Not necessary the
43 thread descriptor used by libpthread. */
44 dtv_t *dtv;
45 void *self; /* Pointer to the thread descriptor. */
46 int multiple_threads;
47} tcbhead_t;
48
49#else /* __ASSEMBLER__ */
50# include <tcb-offsets.h>
51#endif /* __ASSEMBLER__ */
52
53/* TLS is always supported if the tools support it. There are no
54 kernel dependencies. To avoid bothering with the TLS support code
55 at all, use configure --without-tls.
56
57 We need USE_TLS to be consistently defined, for ldsodefs.h
58 conditionals. */
59
60#ifdef HAVE_TLS_SUPPORT
61
62/* Signal that TLS support is available. */
63# define USE_TLS 1
64
65# ifndef __ASSEMBLER__
66/* Get system call information. */
67# include <sysdep.h>
68
69
70/* Get the thread descriptor definition. */
71# include <linuxthreads/descr.h>
72
73/* This is the size of the initial TCB. */
74# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
75
76/* Alignment requirements for the initial TCB. */
77# define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
78
79/* This is the size of the TCB. */
80# define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
81
82/* Alignment requirements for the TCB. */
83# define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
84
85/* The TCB can have any size and the memory following the address the
86 thread pointer points to is unspecified. Allocate the TCB there. */
87# define TLS_TCB_AT_TP 1
88
89
90/* Install the dtv pointer. The pointer passed is to the element with
91 index -1 which contain the length. */
92# define INSTALL_DTV(descr, dtvp) \
93 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
94
95/* Install new dtv for current thread. */
96# define INSTALL_NEW_DTV(dtv) \
97 (((tcbhead_t *) __builtin_thread_pointer ())->dtv = (dtv))
98
99/* Return dtv of given thread descriptor. */
100# define GET_DTV(descr) \
101 (((tcbhead_t *) (descr))->dtv)
102
103/* Code to initially initialize the thread pointer. This might need
104 special attention since 'errno' is not yet available and if the
105 operation can cause a failure 'errno' must not be touched.
106
107 The value of this macro is null if successful, or an error string. */
108# define TLS_INIT_TP(descr, secondcall) \
109 ({ \
110 void *_descr = (descr); \
111 tcbhead_t *head = _descr; \
112 \
113 head->tcb = _descr; \
114 /* For now the thread descriptor is at the same address. */ \
115 head->self = _descr; \
116 \
117 __builtin_set_thread_pointer (_descr); \
118 NULL; \
119 })
120
121/* Return the address of the dtv for the current thread. */
122# define THREAD_DTV() \
123 (((tcbhead_t *) __builtin_thread_pointer ())->dtv)
124
125# endif /* __ASSEMBLER__ */
126
127#else /* HAVE_TLS_SUPPORT && (FLOATING_STACKS || !IS_IN_libpthread) */
128
129# ifndef __ASSEMBLER__
130
131/* Get the thread descriptor definition. */
132# include <linuxthreads/descr.h>
133
134# define NONTLS_INIT_TP \
135 do { \
136 static const tcbhead_t nontls_init_tp \
137 = { .multiple_threads = 0 }; \
138 INIT_THREAD_SELF (&nontls_init_tp, 0); \
139 } while (0)
140
141# endif /* __ASSEMBLER__ */
142
143#endif /* HAVE_TLS_SUPPORT && (FLOATING_STACKS || !IS_IN_libpthread) */
144
145#endif /* tls.h */