(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / linuxthreads / sysdeps / s390 / tls.h
blob41a83a72fbbd4d0da5e2173656c60973bd5cbf2e
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 # define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
77 /* Alignment requirements for the TCB. */
78 # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
80 /* The TCB can have any size and the memory following the address the
81 thread pointer points to is unspecified. Allocate the TCB there. */
82 # define TLS_TCB_AT_TP 1
85 /* Install the dtv pointer. The pointer passed is to the element with
86 index -1 which contain the length. */
87 # define INSTALL_DTV(descr, dtvp) \
88 ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
90 /* Install new dtv for current thread. */
91 # define INSTALL_NEW_DTV(dtv) \
92 (((tcbhead_t *) __builtin_thread_pointer ())->dtv = (dtv))
94 /* Return dtv of given thread descriptor. */
95 # define GET_DTV(descr) \
96 (((tcbhead_t *) (descr))->dtv)
98 /* Code to initially initialize the thread pointer. This might need
99 special attention since 'errno' is not yet available and if the
100 operation can cause a failure 'errno' must not be touched.
102 The value of this macro is null if successful, or an error string. */
103 # define TLS_INIT_TP(descr, secondcall) \
104 ({ \
105 void *_descr = (descr); \
106 tcbhead_t *head = _descr; \
108 head->tcb = _descr; \
109 /* For now the thread descriptor is at the same address. */ \
110 head->self = _descr; \
112 __builtin_set_thread_pointer (_descr); \
113 NULL; \
116 /* Return the address of the dtv for the current thread. */
117 # define THREAD_DTV() \
118 (((tcbhead_t *) __builtin_thread_pointer ())->dtv)
120 # endif /* __ASSEMBLER__ */
122 #else /* HAVE_TLS_SUPPORT && (FLOATING_STACKS || !IS_IN_libpthread) */
124 # ifndef __ASSEMBLER__
126 /* Get the thread descriptor definition. */
127 # include <linuxthreads/descr.h>
129 # define NONTLS_INIT_TP \
130 do { \
131 static const tcbhead_t nontls_init_tp \
132 = { .multiple_threads = 0 }; \
133 INIT_THREAD_SELF (&nontls_init_tp, 0); \
134 } while (0)
136 # endif /* __ASSEMBLER__ */
138 #endif /* HAVE_TLS_SUPPORT && (FLOATING_STACKS || !IS_IN_libpthread) */
140 #endif /* tls.h */