Updated to fedora-glibc-20041130T0624
[glibc/history.git] / nptl / sysdeps / sparc / tls.h
blob8980f9fc0ccae70563ee90ca1b035234a0f7e82a
1 /* Definitions for thread-local data handling. NPTL/sparc version.
2 Copyright (C) 2003 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 <stddef.h>
26 # include <stdint.h>
27 # include <stdlib.h>
28 # include <list.h>
30 /* Type for the dtv. */
31 typedef union dtv
33 size_t counter;
34 void *pointer;
35 } dtv_t;
37 typedef struct
39 void *tcb; /* Pointer to the TCB. Not necessary the
40 thread descriptor used by libpthread. */
41 dtv_t *dtv;
42 void *self;
43 int multiple_threads;
44 } tcbhead_t;
46 #else /* __ASSEMBLER__ */
47 # include <tcb-offsets.h>
48 #endif /* __ASSEMBLER__ */
50 /* We require TLS support in the tools. */
51 #ifndef HAVE_TLS_SUPPORT
52 # error "TLS support is required."
53 #endif
55 /* Signal that TLS support is available. */
56 #define USE_TLS 1
58 #ifndef __ASSEMBLER__
59 /* Get system call information. */
60 # include <sysdep.h>
62 /* Get the thread descriptor definition. */
63 # include <nptl/descr.h>
65 register struct pthread *__thread_self __asm__("%g7");
67 /* This is the size of the initial TCB. */
68 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
70 /* Alignment requirements for the initial TCB. */
71 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
73 /* This is the size of the TCB. */
74 # define TLS_TCB_SIZE sizeof (struct pthread)
76 /* Alignment requirements for the TCB. */
77 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
79 /* The TCB can have any size and the memory following the address the
80 thread pointer points to is unspecified. Allocate the TCB there. */
81 # define TLS_TCB_AT_TP 1
83 /* Install the dtv pointer. The pointer passed is to the element with
84 index -1 which contain the length. */
85 # define INSTALL_DTV(descr, dtvp) \
86 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
88 /* Install new dtv for current thread. */
89 # define INSTALL_NEW_DTV(DTV) \
90 (((tcbhead_t *) __thread_self)->dtv = (DTV))
92 /* Return dtv of given thread descriptor. */
93 # define GET_DTV(descr) \
94 (((tcbhead_t *) (descr))->dtv)
96 /* Code to initially initialize the thread pointer. */
97 # define TLS_INIT_TP(descr, secondcall) \
98 (__thread_self = (__typeof (__thread_self)) (descr), NULL)
100 /* Return the address of the dtv for the current thread. */
101 # define THREAD_DTV() \
102 (((tcbhead_t *) __thread_self)->dtv)
104 /* Return the thread descriptor for the current thread. */
105 #define THREAD_SELF __thread_self
107 /* Magic for libthread_db to know how to do THREAD_SELF. */
108 # define DB_THREAD_SELF_INCLUDE <sys/ucontext.h>
109 # define DB_THREAD_SELF \
110 REGISTER (32, 32, REG_G7 * 4, 0) REGISTER (64, 64, REG_G7 * 8, 0)
112 /* Access to data in the thread descriptor is easy. */
113 #define THREAD_GETMEM(descr, member) \
114 descr->member
115 #define THREAD_GETMEM_NC(descr, member, idx) \
116 descr->member[idx]
117 #define THREAD_SETMEM(descr, member, value) \
118 descr->member = (value)
119 #define THREAD_SETMEM_NC(descr, member, idx, value) \
120 descr->member[idx] = (value)
122 #endif /* !ASSEMBLER */
124 #endif /* tls.h */