]>
sourceware.org Git - glibc.git/blob - sysdeps/sh/nptl/tls.h
aadd5be0227f8d6e1ba2b7d1c6186ad3ee7429b3
1 /* Definition for thread-local data handling. NPTL/SH version.
2 Copyright (C) 2003-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
22 # include <dl-sysdep.h>
36 uintptr_t pointer_guard
;
39 # define TLS_MULTIPLE_THREADS_IN_TCB 1
41 #else /* __ASSEMBLER__ */
42 # include <tcb-offsets.h>
43 #endif /* __ASSEMBLER__ */
48 /* Get system call information. */
51 /* This is the size of the initial TCB. */
52 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
54 /* Alignment requirements for the initial TCB. */
55 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
57 /* This is the size of the TCB. */
58 # define TLS_TCB_SIZE sizeof (tcbhead_t)
60 /* This is the size we need before TCB. */
61 # define TLS_PRE_TCB_SIZE sizeof (struct pthread)
63 /* Alignment requirements for the TCB. */
64 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
66 /* The TLS blocks start right after the TCB. */
67 # define TLS_DTV_AT_TP 1
68 # define TLS_TCB_AT_TP 0
70 /* Get the thread descriptor definition. */
71 # include <nptl/descr.h>
73 /* Install the dtv pointer. The pointer passed is to the element with
74 index -1 which contain the length. */
75 # define INSTALL_DTV(tcbp, dtvp) \
76 ((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1
78 /* Install new dtv for current thread. */
79 # define INSTALL_NEW_DTV(dtv) \
80 ({ tcbhead_t *__tcbp; \
81 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
82 __tcbp->dtv = (dtv);})
84 /* Return dtv of given thread descriptor. */
85 # define GET_DTV(tcbp) \
86 (((tcbhead_t *) (tcbp))->dtv)
88 /* Code to initially initialize the thread pointer. This might need
89 special attention since 'errno' is not yet available and if the
90 operation can cause a failure 'errno' must not be touched. */
91 # define TLS_INIT_TP(tcbp) \
92 ({ __asm __volatile ("ldc %0,gbr" : : "r" (tcbp)); NULL; })
94 # define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd) + 1
96 /* Return the address of the dtv for the current thread. */
97 # define THREAD_DTV() \
98 ({ tcbhead_t *__tcbp; \
99 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
102 /* Return the thread descriptor for the current thread.
103 The contained asm must *not* be marked volatile since otherwise
105 struct pthread *self = thread_self();
106 do not get optimized away. */
107 # define THREAD_SELF \
108 ({ struct pthread *__self; \
109 __asm ("stc gbr,%0" : "=r" (__self)); \
112 /* Magic for libthread_db to know how to do THREAD_SELF. */
113 # define DB_THREAD_SELF \
114 REGISTER (32, 32, REG_GBR * 4, -sizeof (struct pthread))
116 # include <tcb-access.h>
118 #define THREAD_GET_POINTER_GUARD() \
119 ({ tcbhead_t *__tcbp; \
120 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
121 __tcbp->pointer_guard;})
122 #define THREAD_SET_POINTER_GUARD(value) \
123 ({ tcbhead_t *__tcbp; \
124 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
125 __tcbp->pointer_guard = (value);})
126 #define THREAD_COPY_POINTER_GUARD(descr) \
127 ({ tcbhead_t *__tcbp; \
128 __asm __volatile ("stc gbr,%0" : "=r" (__tcbp)); \
129 ((tcbhead_t *) (descr + 1))->pointer_guard = __tcbp->pointer_guard;})
131 /* Get and set the global scope generation counter in struct pthread. */
132 #define THREAD_GSCOPE_FLAG_UNUSED 0
133 #define THREAD_GSCOPE_FLAG_USED 1
134 #define THREAD_GSCOPE_FLAG_WAIT 2
135 #define THREAD_GSCOPE_RESET_FLAG() \
138 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
139 THREAD_GSCOPE_FLAG_UNUSED); \
140 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
141 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
144 #define THREAD_GSCOPE_SET_FLAG() \
147 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
148 atomic_write_barrier (); \
152 #endif /* __ASSEMBLER__ */
This page took 0.043586 seconds and 4 git commands to generate.