Updated to fedora-glibc-20041126T1318
[glibc/history.git] / nptl / sysdeps / s390 / tls.h
blobc9b991df32d278a93adac465904f402dee5c31a5
1 /* Definition for thread-local data handling. NPTL/s390 version.
2 Copyright (C) 2003, 2004 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 1
23 #include <dl-sysdep.h>
24 #ifndef __ASSEMBLER__
25 # include <stddef.h>
26 # include <stdint.h>
27 # include <stdlib.h>
28 # include <list.h>
31 /* Type for the dtv. */
32 typedef union dtv
34 size_t counter;
35 void *pointer;
36 } dtv_t;
39 typedef struct
41 void *tcb; /* Pointer to the TCB. Not necessary the
42 thread descriptor used by libpthread. */
43 dtv_t *dtv;
44 void *self; /* Pointer to the thread descriptor. */
45 int multiple_threads;
46 # ifdef NEED_DL_SYSINFO
47 uintptr_t sysinfo;
48 # endif
49 } tcbhead_t;
51 # ifndef __s390x__
52 # define TLS_MULTIPLE_THREADS_IN_TCB 1
53 # endif
55 #else /* __ASSEMBLER__ */
56 # include <tcb-offsets.h>
57 #endif
60 /* We require TLS support in the tools. */
61 #ifndef HAVE_TLS_SUPPORT
62 # error "TLS support is required."
63 #endif
65 /* Signal that TLS support is available. */
66 #define USE_TLS 1
68 /* Alignment requirement for the stack. For IA-32 this is governed by
69 the SSE memory functions. */
70 #define STACK_ALIGN 16
72 #ifndef __ASSEMBLER__
73 /* Get system call information. */
74 # include <sysdep.h>
76 /* Get the thread descriptor definition. */
77 # include <nptl/descr.h>
79 /* This is the size of the initial TCB. */
80 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
82 /* Alignment requirements for the initial TCB. */
83 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
85 /* This is the size of the TCB. */
86 # define TLS_TCB_SIZE sizeof (struct pthread)
88 /* Alignment requirements for the TCB. */
89 # define TLS_TCB_ALIGN __alignof__ (struct pthread)
91 /* The TCB can have any size and the memory following the address the
92 thread pointer points to is unspecified. Allocate the TCB there. */
93 # define TLS_TCB_AT_TP 1
96 /* Install the dtv pointer. The pointer passed is to the element with
97 index -1 which contain the length. */
98 # define INSTALL_DTV(descr, dtvp) \
99 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
101 /* Install new dtv for current thread. */
102 # define INSTALL_NEW_DTV(dtv) \
103 (((tcbhead_t *) __builtin_thread_pointer ())->dtv = (dtv))
105 /* Return dtv of given thread descriptor. */
106 # define GET_DTV(descr) \
107 (((tcbhead_t *) (descr))->dtv)
109 #if defined NEED_DL_SYSINFO && defined SHARED
110 # define INIT_SYSINFO \
111 _head->sysinfo = GLRO(dl_sysinfo)
112 #else
113 # define INIT_SYSINFO
114 #endif
116 /* Code to initially initialize the thread pointer. This might need
117 special attention since 'errno' is not yet available and if the
118 operation can cause a failure 'errno' must not be touched. */
119 # define TLS_INIT_TP(thrdescr, secondcall) \
120 ({ void *_thrdescr = (thrdescr); \
121 tcbhead_t *_head = _thrdescr; \
123 _head->tcb = _thrdescr; \
124 /* For now the thread descriptor is at the same address. */ \
125 _head->self = _thrdescr; \
126 /* New syscall handling support. */ \
127 INIT_SYSINFO; \
129 __builtin_set_thread_pointer (_thrdescr); \
130 NULL; \
133 /* Return the address of the dtv for the current thread. */
134 # define THREAD_DTV() \
135 (((tcbhead_t *) __builtin_thread_pointer ())->dtv)
137 /* Return the thread descriptor for the current thread. */
138 # define THREAD_SELF ((struct pthread *) __builtin_thread_pointer ())
140 /* Magic for libthread_db to know how to do THREAD_SELF. */
141 # define DB_THREAD_SELF REGISTER (32, 32, 18 * 4, 0) \
142 REGISTER (64, __WORDSIZE, 18 * 8, 0)
144 /* Access to data in the thread descriptor is easy. */
145 #define THREAD_GETMEM(descr, member) \
146 descr->member
147 #define THREAD_GETMEM_NC(descr, member, idx) \
148 descr->member[idx]
149 #define THREAD_SETMEM(descr, member, value) \
150 descr->member = (value)
151 #define THREAD_SETMEM_NC(descr, member, idx, value) \
152 descr->member[idx] = (value)
154 #endif /* __ASSEMBLER__ */
156 #endif /* tls.h */