Define DEFAULT_STACK_PERMS.
[glibc.git] / sysdeps / hppa / linuxthreads / tls.h
blob3d33a18923b94eab167f8790d93faf5d4aacd607
1 /* Definition for thread-local data handling. linuxthreads/hppa version.
2 Copyright (C) 2005 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__
24 # include <pt-machine.h>
25 # include <stdbool.h>
26 # include <stddef.h>
28 /* Type for the dtv. */
29 typedef union dtv
31 size_t counter;
32 struct
34 void *val;
35 bool is_static;
36 } pointer;
37 } dtv_t;
39 #else /* __ASSEMBLER__ */
40 # include <tcb-offsets.h>
41 #endif /* __ASSEMBLER__ */
44 #if defined HAVE_TLS_SUPPORT
46 /* Signal that TLS support is available. */
47 # define USE_TLS 1
49 # ifndef __ASSEMBLER__
51 typedef struct
53 dtv_t *dtv;
54 void *private;
55 } tcbhead_t;
57 /* Include some syscall information for other headers */
58 # include <sysdep.h>
60 /* This is the size of the initial TCB. */
61 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
63 /* Alignment requirements for the initial TCB. */
64 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
66 /* This is the size of the TCB. */
67 # define TLS_TCB_SIZE sizeof (tcbhead_t)
69 /* This is the size we need before TCB. */
70 # define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct)
72 /* Alignment requirements for the TCB. */
73 # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
75 /* The TLS blocks start right after the TCB. */
76 # define TLS_DTV_AT_TP 1
78 /* Return the thread descriptor for the current thread. */
79 # undef THREAD_SELF
80 # define THREAD_SELF \
81 ({ struct _pthread_descr_struct *__self; \
82 __self = __get_cr27(); \
83 __self - 1; \
86 # undef INIT_THREAD_SELF
87 # define INIT_THREAD_SELF(descr, nr) \
88 ({ struct _pthread_descr_struct *__self = (void *)descr; \
89 __set_cr27(__self + 1); \
90 0; \
93 /* Access to data in the thread descriptor is easy. */
94 #define THREAD_GETMEM(descr, member) \
95 ((void) sizeof (descr), THREAD_SELF->member)
96 #define THREAD_GETMEM_NC(descr, member) \
97 ((void) sizeof (descr), THREAD_SELF->member)
98 #define THREAD_SETMEM(descr, member, value) \
99 ((void) sizeof (descr), THREAD_SELF->member = (value))
100 #define THREAD_SETMEM_NC(descr, member, value) \
101 ((void) sizeof (descr), THREAD_SELF->member = (value))
103 /* Install the dtv pointer. The pointer passed is to the element with
104 index -1 which contain the length. */
105 # define INSTALL_DTV(tcbp, dtvp) \
106 ((tcbhead_t *) (tcbp))->dtv = dtvp + 1
108 /* Install new dtv for current thread. */
109 # define INSTALL_NEW_DTV(dtv) \
110 ({ tcbhead_t *__tcbp = (tcbhead_t *)__get_cr27(); \
111 __tcbp->dtv = dtv; \
114 /* Return dtv of given thread descriptor. */
115 # define GET_DTV(tcbp) \
116 (((tcbhead_t *) (tcbp))->dtv)
118 /* Code to initially initialize the thread pointer. This might need
119 special attention since 'errno' is not yet available and if the
120 operation can cause a failure 'errno' must not be touched. */
121 # define TLS_INIT_TP(tcbp, secondcall) \
122 ({ __set_cr27(tcbp); 0; })
124 /* Return the address of the dtv for the current thread. */
125 # define THREAD_DTV() \
126 ({ tcbhead_t *__tcbp = (tcbhead_t *)__get_cr27(); \
127 __tcbp->dtv; \
130 # define TLS_MULTIPLE_THREADS_IN_TCB 1
132 /* Get the thread descriptor definition. This must be after the
133 the definition of THREAD_SELF for TLS. */
134 # include <linuxthreads/descr.h>
136 # endif /* __ASSEMBLER__ */
138 #else
140 # ifndef __ASSEMBLER__
142 typedef struct
144 void *tcb;
145 dtv_t *dtv;
146 void *self;
147 int multiple_threads;
148 } tcbhead_t;
150 /* Get the thread descriptor definition. */
151 # include <linuxthreads/descr.h>
153 # define NONTLS_INIT_TP \
154 do { \
155 static const tcbhead_t nontls_init_tp = { .multiple_threads = 0 }; \
156 INIT_THREAD_SELF(&nontls_init_tp, 0); \
157 } while (0)
159 # endif /* __ASSEMBLER__ */
161 #endif /* HAVE_TLS_SUPPORT */
163 #endif /* tls.h */