Remove support in configure for unsupported architectures
[glibc.git] / nptl / descr.h
blobe57e29e31174b760defd98efcdf4e210c3fa2b42
1 /* Copyright (C) 2002-2006, 2007, 2008, 2009 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
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 _DESCR_H
21 #define _DESCR_H 1
23 #include <limits.h>
24 #include <sched.h>
25 #include <setjmp.h>
26 #include <stdbool.h>
27 #include <sys/types.h>
28 #include <hp-timing.h>
29 #define __need_list_t
30 #include <list.h>
31 #include <lowlevellock.h>
32 #include <pthreaddef.h>
33 #include <dl-sysdep.h>
34 #include "../nptl_db/thread_db.h"
35 #include <tls.h>
36 #ifdef HAVE_FORCED_UNWIND
37 # include <unwind.h>
38 #endif
39 #define __need_res_state
40 #include <resolv.h>
41 #include <kernel-features.h>
43 #ifndef TCB_ALIGNMENT
44 # define TCB_ALIGNMENT sizeof (double)
45 #endif
48 /* We keep thread specific data in a special data structure, a two-level
49 array. The top-level array contains pointers to dynamically allocated
50 arrays of a certain number of data pointers. So we can implement a
51 sparse array. Each dynamic second-level array has
52 PTHREAD_KEY_2NDLEVEL_SIZE
53 entries. This value shouldn't be too large. */
54 #define PTHREAD_KEY_2NDLEVEL_SIZE 32
56 /* We need to address PTHREAD_KEYS_MAX key with PTHREAD_KEY_2NDLEVEL_SIZE
57 keys in each subarray. */
58 #define PTHREAD_KEY_1STLEVEL_SIZE \
59 ((PTHREAD_KEYS_MAX + PTHREAD_KEY_2NDLEVEL_SIZE - 1) \
60 / PTHREAD_KEY_2NDLEVEL_SIZE)
65 /* Internal version of the buffer to store cancellation handler
66 information. */
67 struct pthread_unwind_buf
69 struct
71 __jmp_buf jmp_buf;
72 int mask_was_saved;
73 } cancel_jmp_buf[1];
75 union
77 /* This is the placeholder of the public version. */
78 void *pad[4];
80 struct
82 /* Pointer to the previous cleanup buffer. */
83 struct pthread_unwind_buf *prev;
85 /* Backward compatibility: state of the old-style cleanup
86 handler at the time of the previous new-style cleanup handler
87 installment. */
88 struct _pthread_cleanup_buffer *cleanup;
90 /* Cancellation type before the push call. */
91 int canceltype;
92 } data;
93 } priv;
97 /* Opcodes and data types for communication with the signal handler to
98 change user/group IDs. */
99 struct xid_command
101 int syscall_no;
102 long int id[3];
103 volatile int cntr;
107 /* Data structure used by the kernel to find robust futexes. */
108 struct robust_list_head
110 void *list;
111 long int futex_offset;
112 void *list_op_pending;
116 /* Data strcture used to handle thread priority protection. */
117 struct priority_protection_data
119 int priomax;
120 unsigned int priomap[];
124 /* Thread descriptor data structure. */
125 struct pthread
127 union
129 #if !TLS_DTV_AT_TP
130 /* This overlaps the TCB as used for TLS without threads (see tls.h). */
131 tcbhead_t header;
132 #else
133 struct
135 int multiple_threads;
136 int gscope_flag;
137 # ifndef __ASSUME_PRIVATE_FUTEX
138 int private_futex;
139 # endif
140 } header;
141 #endif
143 /* This extra padding has no special purpose, and this structure layout
144 is private and subject to change without affecting the official ABI.
145 We just have it here in case it might be convenient for some
146 implementation-specific instrumentation hack or suchlike. */
147 void *__padding[24];
150 /* This descriptor's link on the `stack_used' or `__stack_user' list. */
151 list_t list;
153 /* Thread ID - which is also a 'is this thread descriptor (and
154 therefore stack) used' flag. */
155 pid_t tid;
157 /* Process ID - thread group ID in kernel speak. */
158 pid_t pid;
160 /* List of robust mutexes the thread is holding. */
161 #ifdef __PTHREAD_MUTEX_HAVE_PREV
162 void *robust_prev;
163 struct robust_list_head robust_head;
165 /* The list above is strange. It is basically a double linked list
166 but the pointer to the next/previous element of the list points
167 in the middle of the object, the __next element. Whenever
168 casting to __pthread_list_t we need to adjust the pointer
169 first. */
170 # define QUEUE_PTR_ADJUST (offsetof (__pthread_list_t, __next))
172 # define ENQUEUE_MUTEX_BOTH(mutex, val) \
173 do { \
174 __pthread_list_t *next = (__pthread_list_t *) \
175 ((((uintptr_t) THREAD_GETMEM (THREAD_SELF, robust_head.list)) & ~1ul) \
176 - QUEUE_PTR_ADJUST); \
177 next->__prev = (void *) &mutex->__data.__list.__next; \
178 mutex->__data.__list.__next = THREAD_GETMEM (THREAD_SELF, \
179 robust_head.list); \
180 mutex->__data.__list.__prev = (void *) &THREAD_SELF->robust_head; \
181 THREAD_SETMEM (THREAD_SELF, robust_head.list, \
182 (void *) (((uintptr_t) &mutex->__data.__list.__next) \
183 | val)); \
184 } while (0)
185 # define DEQUEUE_MUTEX(mutex) \
186 do { \
187 __pthread_list_t *next = (__pthread_list_t *) \
188 ((char *) (((uintptr_t) mutex->__data.__list.__next) & ~1ul) \
189 - QUEUE_PTR_ADJUST); \
190 next->__prev = mutex->__data.__list.__prev; \
191 __pthread_list_t *prev = (__pthread_list_t *) \
192 ((char *) (((uintptr_t) mutex->__data.__list.__prev) & ~1ul) \
193 - QUEUE_PTR_ADJUST); \
194 prev->__next = mutex->__data.__list.__next; \
195 mutex->__data.__list.__prev = NULL; \
196 mutex->__data.__list.__next = NULL; \
197 } while (0)
198 #else
199 union
201 __pthread_slist_t robust_list;
202 struct robust_list_head robust_head;
205 # define ENQUEUE_MUTEX_BOTH(mutex, val) \
206 do { \
207 mutex->__data.__list.__next \
208 = THREAD_GETMEM (THREAD_SELF, robust_list.__next); \
209 THREAD_SETMEM (THREAD_SELF, robust_list.__next, \
210 (void *) (((uintptr_t) &mutex->__data.__list) | val)); \
211 } while (0)
212 # define DEQUEUE_MUTEX(mutex) \
213 do { \
214 __pthread_slist_t *runp = (__pthread_slist_t *) \
215 (((uintptr_t) THREAD_GETMEM (THREAD_SELF, robust_list.__next)) & ~1ul); \
216 if (runp == &mutex->__data.__list) \
217 THREAD_SETMEM (THREAD_SELF, robust_list.__next, runp->__next); \
218 else \
220 __pthread_slist_t *next = (__pthread_slist_t *) \
221 (((uintptr_t) runp->__next) & ~1ul); \
222 while (next != &mutex->__data.__list) \
224 runp = next; \
225 next = (__pthread_slist_t *) (((uintptr_t) runp->__next) & ~1ul); \
228 runp->__next = next->__next; \
229 mutex->__data.__list.__next = NULL; \
231 } while (0)
232 #endif
233 #define ENQUEUE_MUTEX(mutex) ENQUEUE_MUTEX_BOTH (mutex, 0)
234 #define ENQUEUE_MUTEX_PI(mutex) ENQUEUE_MUTEX_BOTH (mutex, 1)
236 /* List of cleanup buffers. */
237 struct _pthread_cleanup_buffer *cleanup;
239 /* Unwind information. */
240 struct pthread_unwind_buf *cleanup_jmp_buf;
241 #define HAVE_CLEANUP_JMP_BUF
243 /* Flags determining processing of cancellation. */
244 int cancelhandling;
245 /* Bit set if cancellation is disabled. */
246 #define CANCELSTATE_BIT 0
247 #define CANCELSTATE_BITMASK (0x01 << CANCELSTATE_BIT)
248 /* Bit set if asynchronous cancellation mode is selected. */
249 #define CANCELTYPE_BIT 1
250 #define CANCELTYPE_BITMASK (0x01 << CANCELTYPE_BIT)
251 /* Bit set if canceling has been initiated. */
252 #define CANCELING_BIT 2
253 #define CANCELING_BITMASK (0x01 << CANCELING_BIT)
254 /* Bit set if canceled. */
255 #define CANCELED_BIT 3
256 #define CANCELED_BITMASK (0x01 << CANCELED_BIT)
257 /* Bit set if thread is exiting. */
258 #define EXITING_BIT 4
259 #define EXITING_BITMASK (0x01 << EXITING_BIT)
260 /* Bit set if thread terminated and TCB is freed. */
261 #define TERMINATED_BIT 5
262 #define TERMINATED_BITMASK (0x01 << TERMINATED_BIT)
263 /* Bit set if thread is supposed to change XID. */
264 #define SETXID_BIT 6
265 #define SETXID_BITMASK (0x01 << SETXID_BIT)
266 /* Mask for the rest. Helps the compiler to optimize. */
267 #define CANCEL_RESTMASK 0xffffff80
269 #define CANCEL_ENABLED_AND_CANCELED(value) \
270 (((value) & (CANCELSTATE_BITMASK | CANCELED_BITMASK | EXITING_BITMASK \
271 | CANCEL_RESTMASK | TERMINATED_BITMASK)) == CANCELED_BITMASK)
272 #define CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS(value) \
273 (((value) & (CANCELSTATE_BITMASK | CANCELTYPE_BITMASK | CANCELED_BITMASK \
274 | EXITING_BITMASK | CANCEL_RESTMASK | TERMINATED_BITMASK)) \
275 == (CANCELTYPE_BITMASK | CANCELED_BITMASK))
277 /* Flags. Including those copied from the thread attribute. */
278 int flags;
280 /* We allocate one block of references here. This should be enough
281 to avoid allocating any memory dynamically for most applications. */
282 struct pthread_key_data
284 /* Sequence number. We use uintptr_t to not require padding on
285 32- and 64-bit machines. On 64-bit machines it helps to avoid
286 wrapping, too. */
287 uintptr_t seq;
289 /* Data pointer. */
290 void *data;
291 } specific_1stblock[PTHREAD_KEY_2NDLEVEL_SIZE];
293 /* Two-level array for the thread-specific data. */
294 struct pthread_key_data *specific[PTHREAD_KEY_1STLEVEL_SIZE];
296 /* Flag which is set when specific data is set. */
297 bool specific_used;
299 /* True if events must be reported. */
300 bool report_events;
302 /* True if the user provided the stack. */
303 bool user_stack;
305 /* True if thread must stop at startup time. */
306 bool stopped_start;
308 /* The parent's cancel handling at the time of the pthread_create
309 call. This might be needed to undo the effects of a cancellation. */
310 int parent_cancelhandling;
312 /* Lock to synchronize access to the descriptor. */
313 int lock;
315 /* Lock for synchronizing setxid calls. */
316 int setxid_futex;
318 #if HP_TIMING_AVAIL
319 /* Offset of the CPU clock at start thread start time. */
320 hp_timing_t cpuclock_offset;
321 #endif
323 /* If the thread waits to join another one the ID of the latter is
324 stored here.
326 In case a thread is detached this field contains a pointer of the
327 TCB if the thread itself. This is something which cannot happen
328 in normal operation. */
329 struct pthread *joinid;
330 /* Check whether a thread is detached. */
331 #define IS_DETACHED(pd) ((pd)->joinid == (pd))
333 /* The result of the thread function. */
334 void *result;
336 /* Scheduling parameters for the new thread. */
337 struct sched_param schedparam;
338 int schedpolicy;
340 /* Start position of the code to be executed and the argument passed
341 to the function. */
342 void *(*start_routine) (void *);
343 void *arg;
345 /* Debug state. */
346 td_eventbuf_t eventbuf;
347 /* Next descriptor with a pending event. */
348 struct pthread *nextevent;
350 #ifdef HAVE_FORCED_UNWIND
351 /* Machine-specific unwind info. */
352 struct _Unwind_Exception exc;
353 #endif
355 /* If nonzero pointer to area allocated for the stack and its
356 size. */
357 void *stackblock;
358 size_t stackblock_size;
359 /* Size of the included guard area. */
360 size_t guardsize;
361 /* This is what the user specified and what we will report. */
362 size_t reported_guardsize;
364 /* Thread Priority Protection data. */
365 struct priority_protection_data *tpp;
367 /* Resolver state. */
368 struct __res_state res;
370 /* This member must be last. */
371 char end_padding[];
373 #define PTHREAD_STRUCT_END_PADDING \
374 (sizeof (struct pthread) - offsetof (struct pthread, end_padding))
375 } __attribute ((aligned (TCB_ALIGNMENT)));
378 #endif /* descr.h */