]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/m68k/nptl/tls.h
NPTL support for m68k/ColdFire
[thirdparty/glibc.git] / sysdeps / m68k / nptl / tls.h
CommitLineData
40111cb9
MK
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. */
32typedef 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/* Signal that TLS support is available. */
47#define USE_TLS 1
48
49#ifndef __ASSEMBLER__
50
51/* Get system call information. */
52# include <sysdep.h>
53
54/* The TP points to the start of the thread blocks. */
55# define TLS_DTV_AT_TP 1
56
57/* Get the thread descriptor definition. */
58# include <nptl/descr.h>
59
60typedef struct
61{
62 dtv_t *dtv;
63 void *private;
64} tcbhead_t;
65
66/* This is the size of the initial TCB. Because our TCB is before the thread
67 pointer, we don't need this. */
68# define TLS_INIT_TCB_SIZE 0
69
70/* Alignment requirements for the initial TCB. */
71# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
72
73/* This is the size of the TCB. Because our TCB is before the thread
74 pointer, we don't need this. */
75# define TLS_TCB_SIZE 0
76
77/* Alignment requirements for the TCB. */
78# define TLS_TCB_ALIGN __alignof__ (struct pthread)
79
80/* This is the size we need before TCB - actually, it includes the TCB. */
81# define TLS_PRE_TCB_SIZE \
82 (sizeof (struct pthread) \
83 + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
84
85/* The thread pointer (TP) points to the end of the
86 TCB + 0x7000, as for PowerPC and MIPS. This implies that TCB address is
87 TP - 0x7000. As we define TLS_DTV_AT_TP we can
88 assume that the pthread struct is allocated immediately ahead of the
89 TCB. This implies that the pthread_descr address is
90 TP - (TLS_PRE_TCB_SIZE + 0x7000). */
91# define TLS_TCB_OFFSET 0x7000
92
93/* Install the dtv pointer. The pointer passed is to the element with
94 index -1 which contain the length. */
95# define INSTALL_DTV(tcbp, dtvp) \
96 ((tcbhead_t *) (tcbp))[-1].dtv = dtvp + 1
97
98/* Install new dtv for current thread. */
99# define INSTALL_NEW_DTV(dtv) \
100 (THREAD_DTV () = (dtv))
101
102/* Return dtv of given thread descriptor. */
103# define GET_DTV(tcbp) \
104 (((tcbhead_t *) (tcbp))[-1].dtv)
105
106/* Code to initially initialize the thread pointer. This might need
107 special attention since 'errno' is not yet available and if the
108 operation can cause a failure 'errno' must not be touched. */
109# define TLS_INIT_TP(tcbp, secondcall) \
110 ({ \
111 INTERNAL_SYSCALL_DECL (err); \
112 int _sys_result; \
113 \
114 _sys_result = INTERNAL_SYSCALL (set_thread_area, err, 1, \
115 ((void *) (tcbp)) + TLS_TCB_OFFSET); \
116 INTERNAL_SYSCALL_ERROR_P (_sys_result, err) ? "unknown error" : NULL; })
117
118extern void * __m68k_read_tp (void);
119
120/* Return the address of the dtv for the current thread. */
121# define THREAD_DTV() \
122 (((tcbhead_t *) (__m68k_read_tp () - TLS_TCB_OFFSET))[-1].dtv)
123
124/* Return the thread descriptor for the current thread. */
125# define THREAD_SELF \
126 ((struct pthread *) (__m68k_read_tp () - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
127
128/* Magic for libthread_db to know how to do THREAD_SELF. */
129# define DB_THREAD_SELF \
130 CONST_THREAD_AREA (32, TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE)
131
132/* Access to data in the thread descriptor is easy. */
133# define THREAD_GETMEM(descr, member) \
134 descr->member
135# define THREAD_GETMEM_NC(descr, member, idx) \
136 descr->member[idx]
137# define THREAD_SETMEM(descr, member, value) \
138 descr->member = (value)
139# define THREAD_SETMEM_NC(descr, member, idx, value) \
140 descr->member[idx] = (value)
141
142/* l_tls_offset == 0 is perfectly valid on M68K, so we have to use some
143 different value to mean unset l_tls_offset. */
144# define NO_TLS_OFFSET -1
145
146/* Get and set the global scope generation counter in struct pthread. */
147#define THREAD_GSCOPE_FLAG_UNUSED 0
148#define THREAD_GSCOPE_FLAG_USED 1
149#define THREAD_GSCOPE_FLAG_WAIT 2
150#define THREAD_GSCOPE_RESET_FLAG() \
151 do \
152 { int __res \
153 = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
154 THREAD_GSCOPE_FLAG_UNUSED); \
155 if (__res == THREAD_GSCOPE_FLAG_WAIT) \
156 lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
157 } \
158 while (0)
159#define THREAD_GSCOPE_SET_FLAG() \
160 do \
161 { \
162 THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
163 atomic_write_barrier (); \
164 } \
165 while (0)
166#define THREAD_GSCOPE_WAIT() \
167 GL(dl_wait_lookup_done) ()
168
169#endif /* __ASSEMBLER__ */
170
171#endif /* tls.h */