Changes and additions migrated from cvs.devel.redhat.com:/cvs/devel/glibc to fedora...
[glibc.git] / linuxthreads / sysdeps / s390 / tls.h
blobf420195bd285b1548389d66fe9374dd519ebd544
1 /* Definitions for thread-local data handling. linuxthreads/s390 version.
2 Copyright (C) 2002, 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 #ifndef __ASSEMBLER__
25 # include <pt-machine.h>
26 # include <stddef.h>
28 /* Type for the dtv. */
29 typedef union dtv
31 size_t counter;
32 void *pointer;
33 } dtv_t;
35 typedef struct
37 void *tcb; /* Pointer to the TCB. Not necessary the
38 thread descriptor used by libpthread. */
39 dtv_t *dtv;
40 void *self; /* Pointer to the thread descriptor. */
41 int multiple_threads;
42 } tcbhead_t;
44 #else /* __ASSEMBLER__ */
45 # include <tcb-offsets.h>
46 #endif /* __ASSEMBLER__ */
48 /* TLS is always supported if the tools support it. There are no
49 kernel dependencies. To avoid bothering with the TLS support code
50 at all, use configure --without-tls.
52 We need USE_TLS to be consistently defined, for ldsodefs.h
53 conditionals. */
55 #ifdef HAVE_TLS_SUPPORT
57 /* Signal that TLS support is available. */
58 # define USE_TLS 1
60 # ifndef __ASSEMBLER__
61 /* Get system call information. */
62 # include <sysdep.h>
65 /* Get the thread descriptor definition. */
66 # include <linuxthreads/descr.h>
68 /* This is the size of the initial TCB. */
69 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
71 /* Alignment requirements for the initial TCB. */
72 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
74 /* This is the size of the TCB. */
75 # ifndef IS_IN_rtld
76 # define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
77 # else
78 # include <nptl-struct-pthread.h>
79 # define TLS_TCB_SIZE \
80 (sizeof (struct _pthread_descr_struct) > NPTL_STRUCT_PTHREAD_SIZE \
81 ? sizeof (struct _pthread_descr_struct) : NPTL_STRUCT_PTHREAD_SIZE)
82 # endif
84 /* Alignment requirements for the TCB. */
85 # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
87 /* The TCB can have any size and the memory following the address the
88 thread pointer points to is unspecified. Allocate the TCB there. */
89 # define TLS_TCB_AT_TP 1
92 /* Install the dtv pointer. The pointer passed is to the element with
93 index -1 which contain the length. */
94 # define INSTALL_DTV(descr, dtvp) \
95 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
97 /* Install new dtv for current thread. */
98 # define INSTALL_NEW_DTV(dtv) \
99 (((tcbhead_t *) __builtin_thread_pointer ())->dtv = (dtv))
101 /* Return dtv of given thread descriptor. */
102 # define GET_DTV(descr) \
103 (((tcbhead_t *) (descr))->dtv)
105 /* Code to initially initialize the thread pointer. This might need
106 special attention since 'errno' is not yet available and if the
107 operation can cause a failure 'errno' must not be touched.
109 The value of this macro is null if successful, or an error string. */
110 # define TLS_INIT_TP(descr, secondcall) \
111 ({ \
112 void *_descr = (descr); \
113 tcbhead_t *head = _descr; \
115 head->tcb = _descr; \
116 /* For now the thread descriptor is at the same address. */ \
117 head->self = _descr; \
119 __builtin_set_thread_pointer (_descr); \
120 NULL; \
123 /* Return the address of the dtv for the current thread. */
124 # define THREAD_DTV() \
125 (((tcbhead_t *) __builtin_thread_pointer ())->dtv)
127 # endif /* __ASSEMBLER__ */
129 #else /* HAVE_TLS_SUPPORT && (FLOATING_STACKS || !IS_IN_libpthread) */
131 # ifndef __ASSEMBLER__
133 /* Get the thread descriptor definition. */
134 # include <linuxthreads/descr.h>
136 # define NONTLS_INIT_TP \
137 do { \
138 static const tcbhead_t nontls_init_tp \
139 = { .multiple_threads = 0 }; \
140 INIT_THREAD_SELF (&nontls_init_tp, 0); \
141 } while (0)
143 # endif /* __ASSEMBLER__ */
145 #endif /* HAVE_TLS_SUPPORT && (FLOATING_STACKS || !IS_IN_libpthread) */
147 #endif /* tls.h */