]>
Commit | Line | Data |
---|---|---|
40111cb9 | 1 | /* Definition for thread-local data handling. NPTL/m68k version. |
bfff8b1b | 2 | Copyright (C) 2010-2017 Free Software Foundation, Inc. |
40111cb9 MK |
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 | |
ab84e3ff PE |
17 | License along with the GNU C Library. If not, see |
18 | <http://www.gnu.org/licenses/>. */ | |
40111cb9 MK |
19 | |
20 | #ifndef _TLS_H | |
21 | #define _TLS_H 1 | |
22 | ||
23 | #include <dl-sysdep.h> | |
24 | ||
25 | #ifndef __ASSEMBLER__ | |
26 | # include <stdbool.h> | |
27 | # include <stddef.h> | |
28 | # include <stdint.h> | |
aca1daef | 29 | # include <dl-dtv.h> |
40111cb9 MK |
30 | |
31 | #else /* __ASSEMBLER__ */ | |
32 | # include <tcb-offsets.h> | |
33 | #endif /* __ASSEMBLER__ */ | |
34 | ||
40111cb9 MK |
35 | #ifndef __ASSEMBLER__ |
36 | ||
37 | /* Get system call information. */ | |
38 | # include <sysdep.h> | |
39 | ||
40 | /* The TP points to the start of the thread blocks. */ | |
41 | # define TLS_DTV_AT_TP 1 | |
498a2233 | 42 | # define TLS_TCB_AT_TP 0 |
40111cb9 MK |
43 | |
44 | /* Get the thread descriptor definition. */ | |
45 | # include <nptl/descr.h> | |
46 | ||
47 | typedef struct | |
48 | { | |
49 | dtv_t *dtv; | |
50 | void *private; | |
51 | } tcbhead_t; | |
52 | ||
53 | /* This is the size of the initial TCB. Because our TCB is before the thread | |
54 | pointer, we don't need this. */ | |
55 | # define TLS_INIT_TCB_SIZE 0 | |
56 | ||
57 | /* Alignment requirements for the initial TCB. */ | |
58 | # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread) | |
59 | ||
60 | /* This is the size of the TCB. Because our TCB is before the thread | |
61 | pointer, we don't need this. */ | |
62 | # define TLS_TCB_SIZE 0 | |
63 | ||
64 | /* Alignment requirements for the TCB. */ | |
65 | # define TLS_TCB_ALIGN __alignof__ (struct pthread) | |
66 | ||
67 | /* This is the size we need before TCB - actually, it includes the TCB. */ | |
68 | # define TLS_PRE_TCB_SIZE \ | |
69 | (sizeof (struct pthread) \ | |
70 | + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1))) | |
71 | ||
72 | /* The thread pointer (TP) points to the end of the | |
73 | TCB + 0x7000, as for PowerPC and MIPS. This implies that TCB address is | |
74 | TP - 0x7000. As we define TLS_DTV_AT_TP we can | |
75 | assume that the pthread struct is allocated immediately ahead of the | |
76 | TCB. This implies that the pthread_descr address is | |
77 | TP - (TLS_PRE_TCB_SIZE + 0x7000). */ | |
78 | # define TLS_TCB_OFFSET 0x7000 | |
79 | ||
80 | /* Install the dtv pointer. The pointer passed is to the element with | |
81 | index -1 which contain the length. */ | |
82 | # define INSTALL_DTV(tcbp, dtvp) \ | |
83 | ((tcbhead_t *) (tcbp))[-1].dtv = dtvp + 1 | |
84 | ||
85 | /* Install new dtv for current thread. */ | |
86 | # define INSTALL_NEW_DTV(dtv) \ | |
87 | (THREAD_DTV () = (dtv)) | |
88 | ||
89 | /* Return dtv of given thread descriptor. */ | |
90 | # define GET_DTV(tcbp) \ | |
91 | (((tcbhead_t *) (tcbp))[-1].dtv) | |
92 | ||
93 | /* Code to initially initialize the thread pointer. This might need | |
94 | special attention since 'errno' is not yet available and if the | |
95 | operation can cause a failure 'errno' must not be touched. */ | |
774f9285 | 96 | # define TLS_INIT_TP(tcbp) \ |
40111cb9 MK |
97 | ({ \ |
98 | INTERNAL_SYSCALL_DECL (err); \ | |
99 | int _sys_result; \ | |
100 | \ | |
101 | _sys_result = INTERNAL_SYSCALL (set_thread_area, err, 1, \ | |
102 | ((void *) (tcbp)) + TLS_TCB_OFFSET); \ | |
103 | INTERNAL_SYSCALL_ERROR_P (_sys_result, err) ? "unknown error" : NULL; }) | |
104 | ||
d752f0cc RM |
105 | # define TLS_DEFINE_INIT_TP(tp, pd) \ |
106 | void *tp = (void *) (pd) + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE | |
107 | ||
40111cb9 MK |
108 | extern void * __m68k_read_tp (void); |
109 | ||
110 | /* Return the address of the dtv for the current thread. */ | |
111 | # define THREAD_DTV() \ | |
112 | (((tcbhead_t *) (__m68k_read_tp () - TLS_TCB_OFFSET))[-1].dtv) | |
113 | ||
114 | /* Return the thread descriptor for the current thread. */ | |
115 | # define THREAD_SELF \ | |
116 | ((struct pthread *) (__m68k_read_tp () - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE)) | |
117 | ||
118 | /* Magic for libthread_db to know how to do THREAD_SELF. */ | |
119 | # define DB_THREAD_SELF \ | |
120 | CONST_THREAD_AREA (32, TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE) | |
121 | ||
122 | /* Access to data in the thread descriptor is easy. */ | |
123 | # define THREAD_GETMEM(descr, member) \ | |
124 | descr->member | |
125 | # define THREAD_GETMEM_NC(descr, member, idx) \ | |
126 | descr->member[idx] | |
127 | # define THREAD_SETMEM(descr, member, value) \ | |
128 | descr->member = (value) | |
129 | # define THREAD_SETMEM_NC(descr, member, idx, value) \ | |
130 | descr->member[idx] = (value) | |
131 | ||
132 | /* l_tls_offset == 0 is perfectly valid on M68K, so we have to use some | |
133 | different value to mean unset l_tls_offset. */ | |
134 | # define NO_TLS_OFFSET -1 | |
135 | ||
136 | /* Get and set the global scope generation counter in struct pthread. */ | |
137 | #define THREAD_GSCOPE_FLAG_UNUSED 0 | |
138 | #define THREAD_GSCOPE_FLAG_USED 1 | |
139 | #define THREAD_GSCOPE_FLAG_WAIT 2 | |
140 | #define THREAD_GSCOPE_RESET_FLAG() \ | |
141 | do \ | |
142 | { int __res \ | |
143 | = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \ | |
144 | THREAD_GSCOPE_FLAG_UNUSED); \ | |
145 | if (__res == THREAD_GSCOPE_FLAG_WAIT) \ | |
146 | lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \ | |
147 | } \ | |
148 | while (0) | |
149 | #define THREAD_GSCOPE_SET_FLAG() \ | |
150 | do \ | |
151 | { \ | |
152 | THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \ | |
153 | atomic_write_barrier (); \ | |
154 | } \ | |
155 | while (0) | |
156 | #define THREAD_GSCOPE_WAIT() \ | |
157 | GL(dl_wait_lookup_done) () | |
158 | ||
159 | #endif /* __ASSEMBLER__ */ | |
160 | ||
161 | #endif /* tls.h */ |