Updated to fedora-glibc-20060102T2114
[glibc.git] / nptl / sysdeps / sparc / tls.h
blob127bbf695f4d1e0b1f2510fbe84d4fcad942ccef
1 /* Definitions for thread-local data handling. NPTL/sparc version.
2 Copyright (C) 2003, 2005, 2006 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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. */
20 #ifndef _TLS_H
21 #define _TLS_H
23 #include <dl-sysdep.h>
24 #ifndef __ASSEMBLER__
25 # include <stdbool.h>
26 # include <stddef.h>
27 # include <stdint.h>
28 # include <stdlib.h>
29 # include <list.h>
31 /* Type for the dtv. */
32 typedef union dtv
34 size_t counter;
35 struct
37 void *val;
38 bool is_static;
39 } pointer;
40 } dtv_t;
42 typedef struct
44 void *tcb; /* Pointer to the TCB. Not necessary the
45 thread descriptor used by libpthread. */
46 dtv_t *dtv;
47 void *self;
48 int multiple_threads;
49 uintptr_t sysinfo;
50 uintptr_t stack_guard;
51 uintptr_t pointer_guard;
52 } tcbhead_t;
54 #else /* __ASSEMBLER__ */
55 # include <tcb-offsets.h>
56 #endif /* __ASSEMBLER__ */
58 /* We require TLS support in the tools. */
59 #ifndef HAVE_TLS_SUPPORT
60 # error "TLS support is required."
61 #endif
63 /* Signal that TLS support is available. */
64 #define USE_TLS 1
66 #ifndef __ASSEMBLER__
67 /* Get system call information. */
68 # include <sysdep.h>
70 /* Get the thread descriptor definition. */
71 # include <nptl/descr.h>
73 register struct pthread *__thread_self __asm__("%g7");
75 /* This is the size of the initial TCB. Can't be just sizeof (tcbhead_t),
76 because NPTL getpid, __libc_alloca_cutoff etc. need (almost) the whole
77 struct pthread even when not linked with -lpthread. */
78 # define TLS_INIT_TCB_SIZE sizeof (struct pthread)
80 /* Alignment requirements for the initial TCB. */
81 # define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread)
83 /* This is the size of the TCB. */
84 # define TLS_TCB_SIZE sizeof (struct pthread)
86 /* Alignment requirements for the TCB. */
87 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
89 /* The TCB can have any size and the memory following the address the
90 thread pointer points to is unspecified. Allocate the TCB there. */
91 # define TLS_TCB_AT_TP 1
93 /* Install the dtv pointer. The pointer passed is to the element with
94 index -1 which contain the length. */
95 # define INSTALL_DTV(descr, dtvp) \
96 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
98 /* Install new dtv for current thread. */
99 # define INSTALL_NEW_DTV(DTV) \
100 (((tcbhead_t *) __thread_self)->dtv = (DTV))
102 /* Return dtv of given thread descriptor. */
103 # define GET_DTV(descr) \
104 (((tcbhead_t *) (descr))->dtv)
106 /* Code to initially initialize the thread pointer. */
107 # define TLS_INIT_TP(descr, secondcall) \
108 (__thread_self = (__typeof (__thread_self)) (descr), NULL)
110 /* Return the address of the dtv for the current thread. */
111 # define THREAD_DTV() \
112 (((tcbhead_t *) __thread_self)->dtv)
114 /* Return the thread descriptor for the current thread. */
115 #define THREAD_SELF __thread_self
117 /* Magic for libthread_db to know how to do THREAD_SELF. */
118 # define DB_THREAD_SELF_INCLUDE <sys/ucontext.h>
119 # define DB_THREAD_SELF \
120 REGISTER (32, 32, REG_G7 * 4, 0) REGISTER (64, 64, REG_G7 * 8, 0)
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)
132 /* Set the stack guard field in TCB head. */
133 #define THREAD_SET_STACK_GUARD(value) \
134 THREAD_SETMEM (THREAD_SELF, header.stack_guard, value)
135 # define THREAD_COPY_STACK_GUARD(descr) \
136 ((descr)->header.stack_guard \
137 = THREAD_GETMEM (THREAD_SELF, header.stack_guard))
139 /* Get/set the stack guard field in TCB head. */
140 #define THREAD_GET_POINTER_GUARD() \
141 THREAD_GETMEM (THREAD_SELF, header.pointer_guard)
142 #define THREAD_SET_POINTER_GUARD(value) \
143 THREAD_SETMEM (THREAD_SELF, header.pointer_guard, value)
144 # define THREAD_COPY_POINTER_GUARD(descr) \
145 ((descr)->header.pointer_guard = THREAD_GET_POINTER_GUARD ())
147 #endif /* !ASSEMBLER */
149 #endif /* tls.h */