]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/m68k/nptl/tls.h
m68k: remove use of USE_TLS
[thirdparty/glibc.git] / sysdeps / m68k / nptl / tls.h
1 /* Definition for thread-local data handling. NPTL/m68k version.
2 Copyright (C) 2010 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Maxim Kuvyrkov <maxim@codesourcery.com>, 2010.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21 #ifndef _TLS_H
22 #define _TLS_H 1
23
24 #include <dl-sysdep.h>
25
26 #ifndef __ASSEMBLER__
27 # include <stdbool.h>
28 # include <stddef.h>
29 # include <stdint.h>
30
31 /* Type for the dtv. */
32 typedef union dtv
33 {
34 size_t counter;
35 struct
36 {
37 void *val;
38 bool is_static;
39 } pointer;
40 } dtv_t;
41
42 #else /* __ASSEMBLER__ */
43 # include <tcb-offsets.h>
44 #endif /* __ASSEMBLER__ */
45
46 #ifndef __ASSEMBLER__
47
48 /* Get system call information. */
49 # include <sysdep.h>
50
51 /* The TP points to the start of the thread blocks. */
52 # define TLS_DTV_AT_TP 1
53
54 /* Get the thread descriptor definition. */
55 # include <nptl/descr.h>
56
57 typedef struct
58 {
59 dtv_t *dtv;
60 void *private;
61 } tcbhead_t;
62
63 /* This is the size of the initial TCB. Because our TCB is before the thread
64 pointer, we don't need this. */
65 # define TLS_INIT_TCB_SIZE 0
66
67 /* Alignment requirements for the initial TCB. */
68 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
69
70 /* This is the size of the TCB. Because our TCB is before the thread
71 pointer, we don't need this. */
72 # define TLS_TCB_SIZE 0
73
74 /* Alignment requirements for the TCB. */
75 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
76
77 /* This is the size we need before TCB - actually, it includes the TCB. */
78 # define TLS_PRE_TCB_SIZE \
79 (sizeof (struct pthread) \
80 + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
81
82 /* The thread pointer (TP) points to the end of the
83 TCB + 0x7000, as for PowerPC and MIPS. This implies that TCB address is
84 TP - 0x7000. As we define TLS_DTV_AT_TP we can
85 assume that the pthread struct is allocated immediately ahead of the
86 TCB. This implies that the pthread_descr address is
87 TP - (TLS_PRE_TCB_SIZE + 0x7000). */
88 # define TLS_TCB_OFFSET 0x7000
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(tcbp, dtvp) \
93 ((tcbhead_t *) (tcbp))[-1].dtv = dtvp + 1
94
95 /* Install new dtv for current thread. */
96 # define INSTALL_NEW_DTV(dtv) \
97 (THREAD_DTV () = (dtv))
98
99 /* Return dtv of given thread descriptor. */
100 # define GET_DTV(tcbp) \
101 (((tcbhead_t *) (tcbp))[-1].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 # define TLS_INIT_TP(tcbp, secondcall) \
107 ({ \
108 INTERNAL_SYSCALL_DECL (err); \
109 int _sys_result; \
110 \
111 _sys_result = INTERNAL_SYSCALL (set_thread_area, err, 1, \
112 ((void *) (tcbp)) + TLS_TCB_OFFSET); \
113 INTERNAL_SYSCALL_ERROR_P (_sys_result, err) ? "unknown error" : NULL; })
114
115 extern void * __m68k_read_tp (void);
116
117 /* Return the address of the dtv for the current thread. */
118 # define THREAD_DTV() \
119 (((tcbhead_t *) (__m68k_read_tp () - TLS_TCB_OFFSET))[-1].dtv)
120
121 /* Return the thread descriptor for the current thread. */
122 # define THREAD_SELF \
123 ((struct pthread *) (__m68k_read_tp () - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
124
125 /* Magic for libthread_db to know how to do THREAD_SELF. */
126 # define DB_THREAD_SELF \
127 CONST_THREAD_AREA (32, TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE)
128
129 /* Access to data in the thread descriptor is easy. */
130 # define THREAD_GETMEM(descr, member) \
131 descr->member
132 # define THREAD_GETMEM_NC(descr, member, idx) \
133 descr->member[idx]
134 # define THREAD_SETMEM(descr, member, value) \
135 descr->member = (value)
136 # define THREAD_SETMEM_NC(descr, member, idx, value) \
137 descr->member[idx] = (value)
138
139 /* l_tls_offset == 0 is perfectly valid on M68K, so we have to use some
140 different value to mean unset l_tls_offset. */
141 # define NO_TLS_OFFSET -1
142
143 /* Get and set the global scope generation counter in struct pthread. */
144 #define THREAD_GSCOPE_FLAG_UNUSED 0
145 #define THREAD_GSCOPE_FLAG_USED 1
146 #define THREAD_GSCOPE_FLAG_WAIT 2
147 #define THREAD_GSCOPE_RESET_FLAG() \
148 do \
149 { int __res \
150 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
151 THREAD_GSCOPE_FLAG_UNUSED); \
152 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
153 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
154 } \
155 while (0)
156 #define THREAD_GSCOPE_SET_FLAG() \
157 do \
158 { \
159 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
160 atomic_write_barrier (); \
161 } \
162 while (0)
163 #define THREAD_GSCOPE_WAIT() \
164 GL(dl_wait_lookup_done) ()
165
166 #endif /* __ASSEMBLER__ */
167
168 #endif /* tls.h */