]> git.ipfire.org Git - thirdparty/glibc.git/blame - linuxthreads/sysdeps/powerpc/powerpc64/tls.h
linuxthreads/ChangeLog
[thirdparty/glibc.git] / linuxthreads / sysdeps / powerpc / powerpc64 / tls.h
CommitLineData
1d02f71f
RM
1/* Definitions for thread-local data handling. linuxthreads/PowerPC64 version.
2 Copyright (C) 2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20#ifndef _TLS_H
21#define _TLS_H
22
23#ifndef __ASSEMBLER__
24
25# include <pt-machine.h>
26# include <stddef.h>
27
28/* Type for the dtv. */
29typedef union dtv
30{
31 size_t counter;
32 void *pointer;
33} dtv_t;
34
35
36typedef struct
37{
38 dtv_t *dtv;
39
40 /* Reserved for the thread implementation. Unused in LinuxThreads. */
41 void *private;
42} tcbhead_t;
43#endif
44
45
46#ifdef HAVE_TLS_SUPPORT
47
48/* Signal that TLS support is available. */
49# define USE_TLS 1
50
51# ifndef __ASSEMBLER__
52/* Get system call information. */
53# include <sysdep.h>
54
55/* This is the size of the initial TCB. */
56# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
57
58/* Alignment requirements for the initial TCB. */
59# define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
60
61/* This is the size of the TCB. */
62# define TLS_TCB_SIZE sizeof (tcbhead_t)
63
64/* Alignment requirements for the TCB. */
65# define TLS_TCB_ALIGN __alignof__ (tcbhead_t)
66
67/* This is the size we need before TCB. */
68# define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct)
69
70/* the following assumes that TP (R13) is points to the end of the tcb
71 + 0x7000 (per the ABI). This implies that tcb address is
72 R13-(TLS_TCB_SIZE + 0x7000). As we define TLS_DTV_AT_TP we can
73 assume that the pthread_descr is allocate immediately ahead of the
74 tcb. This implies that the pthread_descr address is
75 R13-(TLS_PRE_TCB_SIZE + TLS_TCB_SIZE + 0x7000). */
76# define TLS_TCB_OFFSET 0x7000
77
78/* The DTV is allocated at the TP; the TCB is placed elsewhere. */
79/* This is not really true for powerpc64. We are following alpha
80 where the DTV pointer is first doubleword in the TCB. */
81# define TLS_DTV_AT_TP 1
82
83/* Install the dtv pointer. The pointer passed is to the element with
84 index -1 which contain the length. */
85# define INSTALL_DTV(TCBP, DTVP) \
86 (((tcbhead_t *) (TCBP))->dtv = (DTVP) + 1)
87
88/* Install new dtv for current thread. */
89# define INSTALL_NEW_DTV(DTV) (THREAD_DTV() = (DTV))
90
91/* Return dtv of given thread descriptor. */
92# define GET_DTV(TCBP) (((tcbhead_t *) (TCBP))->dtv)
93
94/* Code to initially initialize the thread pointer. This might need
95 special attention since 'errno' is not yet available and if the
96 operation can cause a failure 'errno' must not be touched. */
97# define TLS_INIT_TP(TCBP, SECONDCALL) \
98 (__thread_self = (uintptr_t) (TCBP) + TLS_TCB_OFFSET + TLS_TCB_SIZE, 0)
99
100/* Return the address of the dtv for the current thread. */
101# define THREAD_DTV() \
102 (((tcbhead_t *) (__thread_register - (TLS_TCB_OFFSET + TLS_TCB_SIZE)))->dtv)
103
104/* Return the thread descriptor for the current thread. */
105# undef THREAD_SELF
106# define THREAD_SELF \
107 ((pthread_descr) (__thread_register \
108 - (TLS_TCB_OFFSET + TLS_TCB_SIZE + TLS_PRE_TCB_SIZE)))
109
110# undef INIT_THREAD_SELF
111# define INIT_THREAD_SELF(DESCR, NR) \
112 (__thread_self = (pthread_descr) (((char *)(DESCR)) \
113 + (TLS_TCB_OFFSET + TLS_TCB_SIZE + TLS_PRE_TCB_SIZE)))
114
115/* Get the thread descriptor definition. */
116# include <linuxthreads/descr.h>
117
118/* Generic bits of LinuxThreads may call these macros with
119 DESCR set to NULL. We are expected to be able to reference
120 the "current" value. */
121
122#define THREAD_GETMEM(descr, member) \
123 ((void) sizeof (descr), THREAD_SELF->member)
124#define THREAD_GETMEM_NC(descr, member) \
125 ((void) sizeof (descr), THREAD_SELF->member)
126#define THREAD_SETMEM(descr, member, value) \
127 ((void) sizeof (descr), THREAD_SELF->member = (value))
128#define THREAD_SETMEM_NC(descr, member, value) \
129 ((void) sizeof (descr), THREAD_SELF->member = (value))
130
131# endif /* HAVE_TLS_SUPPORT */
132#endif /* __ASSEMBLER__ */
133
134#endif /* tls.h */