]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/m68k/nptl/tls.h
1 /* Definition for thread-local data handling. NPTL/m68k version.
2 Copyright (C) 2010-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Maxim Kuvyrkov <maxim@codesourcery.com>, 2010.
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.
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.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library. If not, see
18 <http://www.gnu.org/licenses/>. */
23 #include <dl-sysdep.h>
31 #else /* __ASSEMBLER__ */
32 # include <tcb-offsets.h>
33 #endif /* __ASSEMBLER__ */
37 /* Get system call information. */
40 /* The TP points to the start of the thread blocks. */
41 # define TLS_DTV_AT_TP 1
42 # define TLS_TCB_AT_TP 0
44 /* Get the thread descriptor definition. */
45 # include <nptl/descr.h>
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
57 /* Alignment requirements for the initial TCB. */
58 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
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
64 /* Alignment requirements for the TCB. */
65 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
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)))
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
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
85 /* Install new dtv for current thread. */
86 # define INSTALL_NEW_DTV(dtv) \
87 (THREAD_DTV () = (dtv))
89 /* Return dtv of given thread descriptor. */
90 # define GET_DTV(tcbp) \
91 (((tcbhead_t *) (tcbp))[-1].dtv)
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. */
96 # define TLS_INIT_TP(tcbp) \
98 INTERNAL_SYSCALL_DECL (err); \
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; })
105 # define TLS_DEFINE_INIT_TP(tp, pd) \
106 void *tp = (void *) (pd) + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE
108 extern void * __m68k_read_tp (void);
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)
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))
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)
122 /* Access to data in the thread descriptor is easy. */
123 # define THREAD_GETMEM(descr, member) \
125 # define THREAD_GETMEM_NC(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)
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
136 /* Get and set the global scope generation counter in struct pthread. */
137 #define THREAD_GSCOPE_IN_TCB 1
138 #define THREAD_GSCOPE_FLAG_UNUSED 0
139 #define THREAD_GSCOPE_FLAG_USED 1
140 #define THREAD_GSCOPE_FLAG_WAIT 2
141 #define THREAD_GSCOPE_RESET_FLAG() \
144 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
145 THREAD_GSCOPE_FLAG_UNUSED); \
146 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
147 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
150 #define THREAD_GSCOPE_SET_FLAG() \
153 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
154 atomic_write_barrier (); \
157 #define THREAD_GSCOPE_WAIT() \
158 GL(dl_wait_lookup_done) ()
160 #endif /* __ASSEMBLER__ */