blob: 7bc29800af1cce4a5bdbc742d1539981095620d2 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* Definition for thread-local data handling. linuxthreads/SH 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# include <pt-machine.h>
24
25#ifndef __ASSEMBLER__
26# include <stdbool.h>
27# include <stddef.h>
28# include <stdint.h>
29
30/* Type for the dtv. */
31typedef union dtv
32{
33 size_t counter;
34 void *pointer;
35} dtv_t;
36
37
38typedef struct
39{
40 void *tcb; /* Pointer to the TCB. Not necessary the
41 thread descriptor used by libpthread. */
42 dtv_t *dtv;
43 void *self; /* Pointer to the thread descriptor. */
44} tcbhead_t;
45
46
47/* We can support TLS only if the floating-stack support is available. */
48#if defined FLOATING_STACKS && defined HAVE_TLS_SUPPORT
49
50/* Get system call information. */
51# include <sysdep.h>
52
53/* Signal that TLS support is available. */
54//# define USE_TLS 1
55
56
57/* Get the thread descriptor definition. */
58# include <linuxthreads/descr.h>
59
60/* This is the size of the initial TCB. */
61# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
62
63/* Alignment requirements for the initial TCB. */
64# define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
65
66/* This is the size of the TCB. */
67# define TLS_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 TLS blocks start right after the TCB. */
73# define TLS_DTV_AT_TP 1
74
75
76/* Install the dtv pointer. The pointer passed is to the element with
77 index -1 which contain the length. */
78# define INSTALL_DTV(descr, dtvp) \
79 ((tcbhead_t *) (descr))->dtv = dtvp + 1
80
81/* Install new dtv for current thread. */
82# define INSTALL_NEW_DTV(dtv) \
83 ({ struct _pthread_descr_struct *__descr; \
84 THREAD_SETMEM (__descr, p_header.data.dtvp, (dtv)); })
85
86/* Return dtv of given thread descriptor. */
87# define GET_DTV(descr) \
88 (((tcbhead_t *) (descr))->dtv)
89
90/* Code to initially initialize the thread pointer. This might need
91 special attention since 'errno' is not yet available and if the
92 operation can cause a failure 'errno' must not be touched. */
93# define TLS_INIT_TP(descr, secondcall) \
94 ({ \
95 void *_descr = (descr); \
96 int result; \
97 tcbhead_t *head = _descr; \
98 \
99 head->tcb = _descr; \
100 /* For now the thread descriptor is at the same address. */ \
101 head->self = _descr; \
102 \
103 __asm__ ("ldc %0,gbr" : : "r" (_descr)); \
104 \
105 0; \
106 })
107
108
109/* Return the address of the dtv for the current thread. */
110# define THREAD_DTV() \
111 ({ struct _pthread_descr_struct *__descr; \
112 THREAD_GETMEM (__descr, p_header.data.dtvp); })
113
114#endif /* FLOATING_STACKS && HAVE_TLS_SUPPORT */
115#endif /* __ASSEMBLER__ */
116
117#endif /* tls.h */