]>
Commit | Line | Data |
---|---|---|
bfff8b1b | 1 | /* Copyright (C) 2002-2017 Free Software Foundation, Inc. |
76a50749 UD |
2 | This file is part of the GNU C Library. |
3 | Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
76a50749 UD |
18 | |
19 | #ifndef _PTHREADP_H | |
20 | #define _PTHREADP_H 1 | |
21 | ||
22 | #include <pthread.h> | |
23 | #include <setjmp.h> | |
b758b9cb | 24 | #include <stdbool.h> |
76a50749 UD |
25 | #include <sys/syscall.h> |
26 | #include "descr.h" | |
27 | #include <tls.h> | |
28 | #include <lowlevellock.h> | |
29 | #include <stackinfo.h> | |
30 | #include <internaltypes.h> | |
73e9ae88 | 31 | #include <pthread-functions.h> |
86246935 | 32 | #include <atomic.h> |
0f6699ea | 33 | #include <kernel-features.h> |
da1304bc | 34 | #include <errno.h> |
23fe486b RM |
35 | #include <nptl-signals.h> |
36 | ||
76a50749 | 37 | |
a1b5424f UD |
38 | /* Atomic operations on TLS memory. */ |
39 | #ifndef THREAD_ATOMIC_CMPXCHG_VAL | |
40 | # define THREAD_ATOMIC_CMPXCHG_VAL(descr, member, new, old) \ | |
41 | atomic_compare_and_exchange_val_acq (&(descr)->member, new, old) | |
42 | #endif | |
43 | ||
44 | #ifndef THREAD_ATOMIC_BIT_SET | |
45 | # define THREAD_ATOMIC_BIT_SET(descr, member, bit) \ | |
46 | atomic_bit_set (&(descr)->member, bit) | |
47 | #endif | |
48 | ||
49 | ||
2c0b891a UD |
50 | /* Adaptive mutex definitions. */ |
51 | #ifndef MAX_ADAPTIVE_COUNT | |
52 | # define MAX_ADAPTIVE_COUNT 100 | |
53 | #endif | |
54 | ||
55 | ||
1bcfb5a5 | 56 | /* Magic cookie representing robust mutex with dead owner. */ |
683040c3 | 57 | #define PTHREAD_MUTEX_INCONSISTENT INT_MAX |
1bcfb5a5 UD |
58 | /* Magic cookie representing not recoverable robust mutex. */ |
59 | #define PTHREAD_MUTEX_NOTRECOVERABLE (INT_MAX - 1) | |
60 | ||
61 | ||
62 | /* Internal mutex type value. */ | |
63 | enum | |
64 | { | |
df47504c | 65 | PTHREAD_MUTEX_KIND_MASK_NP = 3, |
b023e4ca AK |
66 | |
67 | PTHREAD_MUTEX_ELISION_NP = 256, | |
68 | PTHREAD_MUTEX_NO_ELISION_NP = 512, | |
69 | ||
0f6699ea UD |
70 | PTHREAD_MUTEX_ROBUST_NORMAL_NP = 16, |
71 | PTHREAD_MUTEX_ROBUST_RECURSIVE_NP | |
72 | = PTHREAD_MUTEX_ROBUST_NORMAL_NP | PTHREAD_MUTEX_RECURSIVE_NP, | |
73 | PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP | |
74 | = PTHREAD_MUTEX_ROBUST_NORMAL_NP | PTHREAD_MUTEX_ERRORCHECK_NP, | |
75 | PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP | |
76 | = PTHREAD_MUTEX_ROBUST_NORMAL_NP | PTHREAD_MUTEX_ADAPTIVE_NP, | |
df47504c UD |
77 | PTHREAD_MUTEX_PRIO_INHERIT_NP = 32, |
78 | PTHREAD_MUTEX_PI_NORMAL_NP | |
79 | = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_NORMAL, | |
80 | PTHREAD_MUTEX_PI_RECURSIVE_NP | |
81 | = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_RECURSIVE_NP, | |
82 | PTHREAD_MUTEX_PI_ERRORCHECK_NP | |
83 | = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ERRORCHECK_NP, | |
84 | PTHREAD_MUTEX_PI_ADAPTIVE_NP | |
85 | = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ADAPTIVE_NP, | |
86 | PTHREAD_MUTEX_PI_ROBUST_NORMAL_NP | |
87 | = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_NORMAL_NP, | |
88 | PTHREAD_MUTEX_PI_ROBUST_RECURSIVE_NP | |
89 | = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_RECURSIVE_NP, | |
90 | PTHREAD_MUTEX_PI_ROBUST_ERRORCHECK_NP | |
91 | = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP, | |
92 | PTHREAD_MUTEX_PI_ROBUST_ADAPTIVE_NP | |
93 | = PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP, | |
f17efcb4 UD |
94 | PTHREAD_MUTEX_PRIO_PROTECT_NP = 64, |
95 | PTHREAD_MUTEX_PP_NORMAL_NP | |
96 | = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_NORMAL, | |
97 | PTHREAD_MUTEX_PP_RECURSIVE_NP | |
98 | = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_RECURSIVE_NP, | |
99 | PTHREAD_MUTEX_PP_ERRORCHECK_NP | |
100 | = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_ERRORCHECK_NP, | |
101 | PTHREAD_MUTEX_PP_ADAPTIVE_NP | |
b023e4ca AK |
102 | = PTHREAD_MUTEX_PRIO_PROTECT_NP | PTHREAD_MUTEX_ADAPTIVE_NP, |
103 | PTHREAD_MUTEX_ELISION_FLAGS_NP | |
104 | = PTHREAD_MUTEX_ELISION_NP | PTHREAD_MUTEX_NO_ELISION_NP, | |
105 | ||
106 | PTHREAD_MUTEX_TIMED_ELISION_NP = | |
107 | PTHREAD_MUTEX_TIMED_NP | PTHREAD_MUTEX_ELISION_NP, | |
108 | PTHREAD_MUTEX_TIMED_NO_ELISION_NP = | |
109 | PTHREAD_MUTEX_TIMED_NP | PTHREAD_MUTEX_NO_ELISION_NP, | |
1bcfb5a5 | 110 | }; |
5bd8a249 | 111 | #define PTHREAD_MUTEX_PSHARED_BIT 128 |
f17efcb4 | 112 | |
ae1ad3ae | 113 | #define PTHREAD_MUTEX_TYPE(m) \ |
5bd8a249 | 114 | ((m)->__data.__kind & 127) |
e8c659d7 AK |
115 | /* Don't include NO_ELISION, as that type is always the same |
116 | as the underlying lock type. */ | |
b023e4ca | 117 | #define PTHREAD_MUTEX_TYPE_ELISION(m) \ |
e8c659d7 | 118 | ((m)->__data.__kind & (127|PTHREAD_MUTEX_ELISION_NP)) |
5bd8a249 UD |
119 | |
120 | #if LLL_PRIVATE == 0 && LLL_SHARED == 128 | |
121 | # define PTHREAD_MUTEX_PSHARED(m) \ | |
122 | ((m)->__data.__kind & 128) | |
123 | #else | |
124 | # define PTHREAD_MUTEX_PSHARED(m) \ | |
125 | (((m)->__data.__kind & 128) ? LLL_SHARED : LLL_PRIVATE) | |
126 | #endif | |
127 | ||
128 | /* The kernel when waking robust mutexes on exit never uses | |
129 | FUTEX_PRIVATE_FLAG FUTEX_WAKE. */ | |
130 | #define PTHREAD_ROBUST_MUTEX_PSHARED(m) LLL_SHARED | |
ae1ad3ae | 131 | |
f17efcb4 UD |
132 | /* Ceiling in __data.__lock. __data.__lock is signed, so don't |
133 | use the MSB bit in there, but in the mask also include that bit, | |
134 | so that the compiler can optimize & PTHREAD_MUTEX_PRIO_CEILING_MASK | |
135 | masking if the value is then shifted down by | |
136 | PTHREAD_MUTEX_PRIO_CEILING_SHIFT. */ | |
137 | #define PTHREAD_MUTEX_PRIO_CEILING_SHIFT 19 | |
138 | #define PTHREAD_MUTEX_PRIO_CEILING_MASK 0xfff80000 | |
1bcfb5a5 UD |
139 | |
140 | ||
141 | /* Flags in mutex attr. */ | |
a5f2bd86 RM |
142 | #define PTHREAD_MUTEXATTR_PROTOCOL_SHIFT 28 |
143 | #define PTHREAD_MUTEXATTR_PROTOCOL_MASK 0x30000000 | |
f17efcb4 UD |
144 | #define PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT 12 |
145 | #define PTHREAD_MUTEXATTR_PRIO_CEILING_MASK 0x00fff000 | |
a5f2bd86 RM |
146 | #define PTHREAD_MUTEXATTR_FLAG_ROBUST 0x40000000 |
147 | #define PTHREAD_MUTEXATTR_FLAG_PSHARED 0x80000000 | |
1bcfb5a5 | 148 | #define PTHREAD_MUTEXATTR_FLAG_BITS \ |
a5f2bd86 RM |
149 | (PTHREAD_MUTEXATTR_FLAG_ROBUST | PTHREAD_MUTEXATTR_FLAG_PSHARED \ |
150 | | PTHREAD_MUTEXATTR_PROTOCOL_MASK | PTHREAD_MUTEXATTR_PRIO_CEILING_MASK) | |
1bcfb5a5 UD |
151 | |
152 | ||
cc25c8b4 TR |
153 | /* For the following, see pthread_rwlock_common.c. */ |
154 | #define PTHREAD_RWLOCK_WRPHASE 1 | |
155 | #define PTHREAD_RWLOCK_WRLOCKED 2 | |
156 | #define PTHREAD_RWLOCK_RWAITING 4 | |
157 | #define PTHREAD_RWLOCK_READER_SHIFT 3 | |
158 | #define PTHREAD_RWLOCK_READER_OVERFLOW ((unsigned int) 1 \ | |
159 | << (sizeof (unsigned int) * 8 - 1)) | |
160 | #define PTHREAD_RWLOCK_WRHANDOVER ((unsigned int) 1 \ | |
161 | << (sizeof (unsigned int) * 8 - 1)) | |
162 | #define PTHREAD_RWLOCK_FUTEX_USED 2 | |
546346b6 UD |
163 | |
164 | ||
683040c3 UD |
165 | /* Bits used in robust mutex implementation. */ |
166 | #define FUTEX_WAITERS 0x80000000 | |
167 | #define FUTEX_OWNER_DIED 0x40000000 | |
2035d91c | 168 | #define FUTEX_TID_MASK 0x3fffffff |
683040c3 UD |
169 | |
170 | ||
63668b70 TR |
171 | /* pthread_once definitions. See __pthread_once for how these are used. */ |
172 | #define __PTHREAD_ONCE_INPROGRESS 1 | |
173 | #define __PTHREAD_ONCE_DONE 2 | |
174 | #define __PTHREAD_ONCE_FORK_GEN_INCR 4 | |
175 | ||
176 | ||
ed19993b TR |
177 | /* Condition variable definitions. See __pthread_cond_wait_common. |
178 | Need to be defined here so there is one place from which | |
179 | nptl_lock_constants can grab them. */ | |
180 | #define __PTHREAD_COND_CLOCK_MONOTONIC_MASK 2 | |
181 | #define __PTHREAD_COND_SHARED_MASK 1 | |
182 | ||
183 | ||
76a50749 UD |
184 | /* Internal variables. */ |
185 | ||
186 | ||
e903a713 SP |
187 | /* Default pthread attributes. */ |
188 | extern struct pthread_attr __default_pthread_attr attribute_hidden; | |
61dd6208 | 189 | extern int __default_pthread_attr_lock attribute_hidden; |
76a50749 UD |
190 | |
191 | /* Size and alignment of static TLS block. */ | |
192 | extern size_t __static_tls_size attribute_hidden; | |
bc6389ad | 193 | extern size_t __static_tls_align_m1 attribute_hidden; |
76a50749 | 194 | |
2c0b891a UD |
195 | /* Flag whether the machine is SMP or not. */ |
196 | extern int __is_smp attribute_hidden; | |
197 | ||
76a50749 | 198 | /* Thread descriptor handling. */ |
fa9a4ff0 RM |
199 | extern list_t __stack_user; |
200 | hidden_proto (__stack_user) | |
76a50749 UD |
201 | |
202 | /* Attribute handling. */ | |
203 | extern struct pthread_attr *__attr_list attribute_hidden; | |
e51deae7 | 204 | extern int __attr_list_lock attribute_hidden; |
76a50749 | 205 | |
76a50749 UD |
206 | /* Concurrency handling. */ |
207 | extern int __concurrency_level attribute_hidden; | |
208 | ||
209 | /* Thread-local data key handling. */ | |
fa9a4ff0 RM |
210 | extern struct pthread_key_struct __pthread_keys[PTHREAD_KEYS_MAX]; |
211 | hidden_proto (__pthread_keys) | |
76a50749 | 212 | |
47202270 UD |
213 | /* Number of threads running. */ |
214 | extern unsigned int __nptl_nthreads attribute_hidden; | |
215 | ||
0f6699ea UD |
216 | #ifndef __ASSUME_SET_ROBUST_LIST |
217 | /* Negative if we do not have the system call and we can use it. */ | |
218 | extern int __set_robust_list_avail attribute_hidden; | |
219 | #endif | |
220 | ||
f17efcb4 UD |
221 | /* Thread Priority Protection. */ |
222 | extern int __sched_fifo_min_prio attribute_hidden; | |
223 | extern int __sched_fifo_max_prio attribute_hidden; | |
224 | extern void __init_sched_fifo_prio (void) attribute_hidden; | |
225 | extern int __pthread_tpp_change_priority (int prev_prio, int new_prio) | |
226 | attribute_hidden; | |
227 | extern int __pthread_current_priority (void) attribute_hidden; | |
228 | ||
76a50749 UD |
229 | /* The library can run in debugging mode where it performs a lot more |
230 | tests. */ | |
231 | extern int __pthread_debug attribute_hidden; | |
729924a0 UD |
232 | /** For now disable debugging support. */ |
233 | #if 0 | |
234 | # define DEBUGGING_P __builtin_expect (__pthread_debug, 0) | |
8c2e9a29 UD |
235 | # define INVALID_TD_P(pd) (DEBUGGING_P && __find_in_stack_list (pd) == NULL) |
236 | # define INVALID_NOT_TERMINATED_TD_P(pd) INVALID_TD_P (pd) | |
729924a0 UD |
237 | #else |
238 | # define DEBUGGING_P 0 | |
8c2e9a29 UD |
239 | /* Simplified test. This will not catch all invalid descriptors but |
240 | is better than nothing. And if the test triggers the thread | |
241 | descriptor is guaranteed to be invalid. */ | |
242 | # define INVALID_TD_P(pd) __builtin_expect ((pd)->tid <= 0, 0) | |
243 | # define INVALID_NOT_TERMINATED_TD_P(pd) __builtin_expect ((pd)->tid < 0, 0) | |
729924a0 | 244 | #endif |
76a50749 UD |
245 | |
246 | ||
247 | /* Cancellation test. */ | |
248 | #define CANCELLATION_P(self) \ | |
249 | do { \ | |
250 | int cancelhandling = THREAD_GETMEM (self, cancelhandling); \ | |
251 | if (CANCEL_ENABLED_AND_CANCELED (cancelhandling)) \ | |
252 | { \ | |
253 | THREAD_SETMEM (self, result, PTHREAD_CANCELED); \ | |
9ae0909b | 254 | __do_cancel (); \ |
76a50749 UD |
255 | } \ |
256 | } while (0) | |
257 | ||
6efd4814 UD |
258 | |
259 | extern void __pthread_unwind (__pthread_unwind_buf_t *__buf) | |
260 | __cleanup_fct_attribute __attribute ((__noreturn__)) | |
ce9f10f7 | 261 | #if !defined SHARED && !IS_IN (libpthread) |
6efd4814 UD |
262 | weak_function |
263 | #endif | |
264 | ; | |
da0c02ee UD |
265 | extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf) |
266 | __cleanup_fct_attribute __attribute ((__noreturn__)) | |
267 | #ifndef SHARED | |
268 | weak_function | |
269 | #endif | |
270 | ; | |
271 | extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf) | |
272 | __cleanup_fct_attribute; | |
273 | extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf) | |
274 | __cleanup_fct_attribute; | |
ce9f10f7 | 275 | #if IS_IN (libpthread) |
56421b23 | 276 | hidden_proto (__pthread_unwind) |
da0c02ee UD |
277 | hidden_proto (__pthread_unwind_next) |
278 | hidden_proto (__pthread_register_cancel) | |
279 | hidden_proto (__pthread_unregister_cancel) | |
9d79e037 UD |
280 | # ifdef SHARED |
281 | extern void attribute_hidden pthread_cancel_init (void); | |
cca50323 | 282 | extern void __unwind_freeres (void); |
9d79e037 | 283 | # endif |
56421b23 UD |
284 | #endif |
285 | ||
6efd4814 UD |
286 | |
287 | /* Called when a thread reacts on a cancellation request. */ | |
288 | static inline void | |
dd9423a6 | 289 | __attribute ((noreturn, always_inline)) |
6efd4814 UD |
290 | __do_cancel (void) |
291 | { | |
292 | struct pthread *self = THREAD_SELF; | |
293 | ||
294 | /* Make sure we get no more cancellations. */ | |
295 | THREAD_ATOMIC_BIT_SET (self, cancelhandling, EXITING_BIT); | |
296 | ||
297 | __pthread_unwind ((__pthread_unwind_buf_t *) | |
298 | THREAD_GETMEM (self, cleanup_jmp_buf)); | |
299 | } | |
300 | ||
301 | ||
76a50749 | 302 | /* Set cancellation mode to asynchronous. */ |
bdb04f92 UD |
303 | #define CANCEL_ASYNC() \ |
304 | __pthread_enable_asynccancel () | |
76a50749 UD |
305 | /* Reset to previous cancellation mode. */ |
306 | #define CANCEL_RESET(oldtype) \ | |
bdb04f92 | 307 | __pthread_disable_asynccancel (oldtype) |
76a50749 | 308 | |
4f41c682 | 309 | #if IS_IN (libc) |
9ae0909b | 310 | /* Same as CANCEL_ASYNC, but for use in libc.so. */ |
9634cf9d | 311 | # define LIBC_CANCEL_ASYNC() \ |
9ae0909b UD |
312 | __libc_enable_asynccancel () |
313 | /* Same as CANCEL_RESET, but for use in libc.so. */ | |
9634cf9d | 314 | # define LIBC_CANCEL_RESET(oldtype) \ |
9ae0909b | 315 | __libc_disable_asynccancel (oldtype) |
52f3d213 UD |
316 | # define LIBC_CANCEL_HANDLED() \ |
317 | __asm (".globl " __SYMBOL_PREFIX "__libc_enable_asynccancel"); \ | |
318 | __asm (".globl " __SYMBOL_PREFIX "__libc_disable_asynccancel") | |
ce9f10f7 | 319 | #elif IS_IN (libpthread) |
9634cf9d UD |
320 | # define LIBC_CANCEL_ASYNC() CANCEL_ASYNC () |
321 | # define LIBC_CANCEL_RESET(val) CANCEL_RESET (val) | |
52f3d213 UD |
322 | # define LIBC_CANCEL_HANDLED() \ |
323 | __asm (".globl " __SYMBOL_PREFIX "__pthread_enable_asynccancel"); \ | |
324 | __asm (".globl " __SYMBOL_PREFIX "__pthread_disable_asynccancel") | |
016afc75 | 325 | #elif IS_IN (librt) |
1fde494e UD |
326 | # define LIBC_CANCEL_ASYNC() \ |
327 | __librt_enable_asynccancel () | |
328 | # define LIBC_CANCEL_RESET(val) \ | |
329 | __librt_disable_asynccancel (val) | |
330 | # define LIBC_CANCEL_HANDLED() \ | |
331 | __asm (".globl " __SYMBOL_PREFIX "__librt_enable_asynccancel"); \ | |
332 | __asm (".globl " __SYMBOL_PREFIX "__librt_disable_asynccancel") | |
9634cf9d UD |
333 | #else |
334 | # define LIBC_CANCEL_ASYNC() 0 /* Just a dummy value. */ | |
335 | # define LIBC_CANCEL_RESET(val) ((void)(val)) /* Nothing, but evaluate it. */ | |
52f3d213 | 336 | # define LIBC_CANCEL_HANDLED() /* Nothing. */ |
9634cf9d | 337 | #endif |
9ae0909b | 338 | |
2edb61e3 | 339 | |
76a50749 UD |
340 | /* Internal prototypes. */ |
341 | ||
342 | /* Thread list handling. */ | |
343 | extern struct pthread *__find_in_stack_list (struct pthread *pd) | |
90491dc4 | 344 | attribute_hidden internal_function; |
76a50749 UD |
345 | |
346 | /* Deallocate a thread's stack after optionally making sure the thread | |
347 | descriptor is still valid. */ | |
90491dc4 | 348 | extern void __free_tcb (struct pthread *pd) attribute_hidden internal_function; |
76a50749 UD |
349 | |
350 | /* Free allocated stack. */ | |
90491dc4 UD |
351 | extern void __deallocate_stack (struct pthread *pd) |
352 | attribute_hidden internal_function; | |
76a50749 UD |
353 | |
354 | /* Mark all the stacks except for the current one as available. This | |
355 | function also re-initializes the lock for the stack cache. */ | |
356 | extern void __reclaim_stacks (void) attribute_hidden; | |
357 | ||
54ee14b3 | 358 | /* Make all threads's stacks executable. */ |
d1fc817e UD |
359 | extern int __make_stacks_executable (void **stack_endp) |
360 | internal_function attribute_hidden; | |
54ee14b3 | 361 | |
76a50749 UD |
362 | /* longjmp handling. */ |
363 | extern void __pthread_cleanup_upto (__jmp_buf target, char *targetframe); | |
ce9f10f7 | 364 | #if IS_IN (libpthread) |
334fcf2a UD |
365 | hidden_proto (__pthread_cleanup_upto) |
366 | #endif | |
76a50749 UD |
367 | |
368 | ||
369 | /* Functions with versioned interfaces. */ | |
370 | extern int __pthread_create_2_1 (pthread_t *newthread, | |
371 | const pthread_attr_t *attr, | |
372 | void *(*start_routine) (void *), void *arg); | |
373 | extern int __pthread_create_2_0 (pthread_t *newthread, | |
374 | const pthread_attr_t *attr, | |
375 | void *(*start_routine) (void *), void *arg); | |
376 | extern int __pthread_attr_init_2_1 (pthread_attr_t *attr); | |
377 | extern int __pthread_attr_init_2_0 (pthread_attr_t *attr); | |
378 | ||
379 | ||
380 | /* Event handlers for libthread_db interface. */ | |
fa9a4ff0 RM |
381 | extern void __nptl_create_event (void); |
382 | extern void __nptl_death_event (void); | |
383 | hidden_proto (__nptl_create_event) | |
384 | hidden_proto (__nptl_death_event) | |
76a50749 | 385 | |
8454830b | 386 | /* Register the generation counter in the libpthread with the libc. */ |
5a03acfe | 387 | #ifdef TLS_MULTIPLE_THREADS_IN_TCB |
8454830b UD |
388 | extern void __libc_pthread_init (unsigned long int *ptr, |
389 | void (*reclaim) (void), | |
5a03acfe UD |
390 | const struct pthread_functions *functions) |
391 | internal_function; | |
392 | #else | |
393 | extern int *__libc_pthread_init (unsigned long int *ptr, | |
394 | void (*reclaim) (void), | |
395 | const struct pthread_functions *functions) | |
396 | internal_function; | |
397 | ||
439bf404 SP |
398 | /* Variable set to a nonzero value either if more than one thread runs or ran, |
399 | or if a single-threaded process is trying to cancel itself. See | |
400 | nptl/descr.h for more context on the single-threaded process case. */ | |
5a03acfe UD |
401 | extern int __pthread_multiple_threads attribute_hidden; |
402 | /* Pointer to the corresponding variable in libc. */ | |
403 | extern int *__libc_multiple_threads_ptr attribute_hidden; | |
404 | #endif | |
8454830b | 405 | |
4165d44d | 406 | /* Find a thread given its TID. */ |
b639d0c9 UD |
407 | extern struct pthread *__find_thread_by_id (pid_t tid) attribute_hidden |
408 | #ifdef SHARED | |
409 | ; | |
410 | #else | |
411 | weak_function; | |
412 | #define __find_thread_by_id(tid) \ | |
413 | (__find_thread_by_id ? (__find_thread_by_id) (tid) : (struct pthread *) NULL) | |
414 | #endif | |
4165d44d | 415 | |
adc12574 UD |
416 | extern void __pthread_init_static_tls (struct link_map *) attribute_hidden; |
417 | ||
2c1094bd | 418 | extern size_t __pthread_get_minstack (const pthread_attr_t *attr); |
76a50749 UD |
419 | |
420 | /* Namespace save aliases. */ | |
8454830b UD |
421 | extern int __pthread_getschedparam (pthread_t thread_id, int *policy, |
422 | struct sched_param *param); | |
423 | extern int __pthread_setschedparam (pthread_t thread_id, int policy, | |
424 | const struct sched_param *param); | |
425 | extern int __pthread_setcancelstate (int state, int *oldstate); | |
76a50749 | 426 | extern int __pthread_mutex_init (pthread_mutex_t *__mutex, |
a784e502 | 427 | const pthread_mutexattr_t *__mutexattr); |
76a50749 UD |
428 | extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex); |
429 | extern int __pthread_mutex_trylock (pthread_mutex_t *_mutex); | |
430 | extern int __pthread_mutex_lock (pthread_mutex_t *__mutex); | |
fa872e1b AZ |
431 | extern int __pthread_mutex_timedlock (pthread_mutex_t *__mutex, |
432 | const struct timespec *__abstime); | |
69431c9a | 433 | extern int __pthread_mutex_cond_lock (pthread_mutex_t *__mutex) |
67b78ef9 | 434 | attribute_hidden internal_function; |
b0948ffd UD |
435 | extern void __pthread_mutex_cond_lock_adjust (pthread_mutex_t *__mutex) |
436 | attribute_hidden internal_function; | |
76a50749 | 437 | extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex); |
b758b9cb | 438 | extern int __pthread_mutex_unlock_usercnt (pthread_mutex_t *__mutex, |
8f31c0ef | 439 | int __decr) |
3a4f2043 | 440 | attribute_hidden internal_function; |
76a50749 UD |
441 | extern int __pthread_mutexattr_init (pthread_mutexattr_t *attr); |
442 | extern int __pthread_mutexattr_destroy (pthread_mutexattr_t *attr); | |
443 | extern int __pthread_mutexattr_settype (pthread_mutexattr_t *attr, int kind); | |
8454830b UD |
444 | extern int __pthread_attr_destroy (pthread_attr_t *attr); |
445 | extern int __pthread_attr_getdetachstate (const pthread_attr_t *attr, | |
446 | int *detachstate); | |
447 | extern int __pthread_attr_setdetachstate (pthread_attr_t *attr, | |
448 | int detachstate); | |
449 | extern int __pthread_attr_getinheritsched (const pthread_attr_t *attr, | |
450 | int *inherit); | |
451 | extern int __pthread_attr_setinheritsched (pthread_attr_t *attr, int inherit); | |
452 | extern int __pthread_attr_getschedparam (const pthread_attr_t *attr, | |
453 | struct sched_param *param); | |
454 | extern int __pthread_attr_setschedparam (pthread_attr_t *attr, | |
455 | const struct sched_param *param); | |
456 | extern int __pthread_attr_getschedpolicy (const pthread_attr_t *attr, | |
457 | int *policy); | |
458 | extern int __pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy); | |
459 | extern int __pthread_attr_getscope (const pthread_attr_t *attr, int *scope); | |
460 | extern int __pthread_attr_setscope (pthread_attr_t *attr, int scope); | |
a784e502 | 461 | extern int __pthread_attr_getstackaddr (const pthread_attr_t *__restrict |
76a50749 UD |
462 | __attr, void **__restrict __stackaddr); |
463 | extern int __pthread_attr_setstackaddr (pthread_attr_t *__attr, | |
464 | void *__stackaddr); | |
a784e502 | 465 | extern int __pthread_attr_getstacksize (const pthread_attr_t *__restrict |
76a50749 UD |
466 | __attr, |
467 | size_t *__restrict __stacksize); | |
468 | extern int __pthread_attr_setstacksize (pthread_attr_t *__attr, | |
469 | size_t __stacksize); | |
a784e502 | 470 | extern int __pthread_attr_getstack (const pthread_attr_t *__restrict __attr, |
76a50749 UD |
471 | void **__restrict __stackaddr, |
472 | size_t *__restrict __stacksize); | |
473 | extern int __pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr, | |
474 | size_t __stacksize); | |
475 | extern int __pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock, | |
a784e502 | 476 | const pthread_rwlockattr_t *__restrict |
76a50749 UD |
477 | __attr); |
478 | extern int __pthread_rwlock_destroy (pthread_rwlock_t *__rwlock); | |
479 | extern int __pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock); | |
480 | extern int __pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock); | |
481 | extern int __pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock); | |
482 | extern int __pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock); | |
483 | extern int __pthread_rwlock_unlock (pthread_rwlock_t *__rwlock); | |
8454830b UD |
484 | extern int __pthread_cond_broadcast (pthread_cond_t *cond); |
485 | extern int __pthread_cond_destroy (pthread_cond_t *cond); | |
486 | extern int __pthread_cond_init (pthread_cond_t *cond, | |
487 | const pthread_condattr_t *cond_attr); | |
488 | extern int __pthread_cond_signal (pthread_cond_t *cond); | |
489 | extern int __pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex); | |
b5facfda UD |
490 | extern int __pthread_cond_timedwait (pthread_cond_t *cond, |
491 | pthread_mutex_t *mutex, | |
492 | const struct timespec *abstime); | |
8454830b UD |
493 | extern int __pthread_condattr_destroy (pthread_condattr_t *attr); |
494 | extern int __pthread_condattr_init (pthread_condattr_t *attr); | |
76a50749 | 495 | extern int __pthread_key_create (pthread_key_t *key, void (*destr) (void *)); |
fa872e1b | 496 | extern int __pthread_key_delete (pthread_key_t key); |
76a50749 UD |
497 | extern void *__pthread_getspecific (pthread_key_t key); |
498 | extern int __pthread_setspecific (pthread_key_t key, const void *value); | |
499 | extern int __pthread_once (pthread_once_t *once_control, | |
500 | void (*init_routine) (void)); | |
501 | extern int __pthread_atfork (void (*prepare) (void), void (*parent) (void), | |
502 | void (*child) (void)); | |
8454830b UD |
503 | extern pthread_t __pthread_self (void); |
504 | extern int __pthread_equal (pthread_t thread1, pthread_t thread2); | |
fa872e1b AZ |
505 | extern int __pthread_detach (pthread_t th); |
506 | extern int __pthread_cancel (pthread_t th); | |
09efc3ba | 507 | extern int __pthread_kill (pthread_t threadid, int signo); |
356fa562 | 508 | extern void __pthread_exit (void *value) __attribute__ ((__noreturn__)); |
fa872e1b | 509 | extern int __pthread_join (pthread_t threadid, void **thread_return); |
09efc3ba | 510 | extern int __pthread_setcanceltype (int type, int *oldtype); |
bdb04f92 | 511 | extern int __pthread_enable_asynccancel (void) attribute_hidden; |
9ae0909b UD |
512 | extern void __pthread_disable_asynccancel (int oldtype) |
513 | internal_function attribute_hidden; | |
47677f2e | 514 | extern void __pthread_testcancel (void); |
9ae0909b | 515 | |
ce9f10f7 | 516 | #if IS_IN (libpthread) |
4d17e683 AS |
517 | hidden_proto (__pthread_mutex_init) |
518 | hidden_proto (__pthread_mutex_destroy) | |
519 | hidden_proto (__pthread_mutex_lock) | |
fa872e1b | 520 | hidden_proto (__pthread_mutex_trylock) |
4d17e683 AS |
521 | hidden_proto (__pthread_mutex_unlock) |
522 | hidden_proto (__pthread_rwlock_rdlock) | |
523 | hidden_proto (__pthread_rwlock_wrlock) | |
524 | hidden_proto (__pthread_rwlock_unlock) | |
525 | hidden_proto (__pthread_key_create) | |
526 | hidden_proto (__pthread_getspecific) | |
527 | hidden_proto (__pthread_setspecific) | |
528 | hidden_proto (__pthread_once) | |
e5d19c08 | 529 | hidden_proto (__pthread_setcancelstate) |
47677f2e | 530 | hidden_proto (__pthread_testcancel) |
fa872e1b AZ |
531 | hidden_proto (__pthread_mutexattr_init) |
532 | hidden_proto (__pthread_mutexattr_settype) | |
4d17e683 AS |
533 | #endif |
534 | ||
997256dd UD |
535 | extern int __pthread_cond_broadcast_2_0 (pthread_cond_2_0_t *cond); |
536 | extern int __pthread_cond_destroy_2_0 (pthread_cond_2_0_t *cond); | |
537 | extern int __pthread_cond_init_2_0 (pthread_cond_2_0_t *cond, | |
05df18c3 | 538 | const pthread_condattr_t *cond_attr); |
997256dd UD |
539 | extern int __pthread_cond_signal_2_0 (pthread_cond_2_0_t *cond); |
540 | extern int __pthread_cond_timedwait_2_0 (pthread_cond_2_0_t *cond, | |
05df18c3 UD |
541 | pthread_mutex_t *mutex, |
542 | const struct timespec *abstime); | |
997256dd | 543 | extern int __pthread_cond_wait_2_0 (pthread_cond_2_0_t *cond, |
05df18c3 UD |
544 | pthread_mutex_t *mutex); |
545 | ||
439ff07b UD |
546 | extern int __pthread_getaffinity_np (pthread_t th, size_t cpusetsize, |
547 | cpu_set_t *cpuset); | |
73e9ae88 | 548 | |
9ae0909b UD |
549 | /* The two functions are in libc.so and not exported. */ |
550 | extern int __libc_enable_asynccancel (void) attribute_hidden; | |
551 | extern void __libc_disable_asynccancel (int oldtype) | |
552 | internal_function attribute_hidden; | |
09efc3ba | 553 | |
1fde494e UD |
554 | |
555 | /* The two functions are in librt.so and not exported. */ | |
556 | extern int __librt_enable_asynccancel (void) attribute_hidden; | |
557 | extern void __librt_disable_asynccancel (int oldtype) | |
558 | internal_function attribute_hidden; | |
559 | ||
ce9f10f7 | 560 | #if IS_IN (libpthread) |
09efc3ba | 561 | /* Special versions which use non-exported functions. */ |
73e9ae88 UD |
562 | extern void __pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer, |
563 | void (*routine) (void *), void *arg) | |
09efc3ba | 564 | attribute_hidden; |
09efc3ba | 565 | |
203c1a89 MS |
566 | /* Replace cleanup macros defined in <pthread.h> with internal |
567 | versions that don't depend on unwind info and better support | |
568 | cancellation. */ | |
569 | # undef pthread_cleanup_push | |
570 | # define pthread_cleanup_push(routine,arg) \ | |
571 | { struct _pthread_cleanup_buffer _buffer; \ | |
572 | __pthread_cleanup_push (&_buffer, (routine), (arg)); | |
573 | ||
73e9ae88 UD |
574 | extern void __pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer, |
575 | int execute) attribute_hidden; | |
203c1a89 MS |
576 | # undef pthread_cleanup_pop |
577 | # define pthread_cleanup_pop(execute) \ | |
578 | __pthread_cleanup_pop (&_buffer, (execute)); } | |
1e506629 | 579 | #endif |
76a50749 | 580 | |
73e9ae88 UD |
581 | extern void __pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer, |
582 | void (*routine) (void *), void *arg); | |
583 | extern void __pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer, | |
584 | int execute); | |
585 | ||
6efd4814 UD |
586 | /* Old cleanup interfaces, still used in libc.so. */ |
587 | extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer, | |
6f8326ca | 588 | void (*routine) (void *), void *arg); |
6efd4814 | 589 | extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer, |
6f8326ca | 590 | int execute); |
6efd4814 | 591 | extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer, |
6f8326ca | 592 | void (*routine) (void *), void *arg); |
6efd4814 | 593 | extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer, |
6f8326ca | 594 | int execute); |
6efd4814 | 595 | |
3fa21fd8 UD |
596 | extern void __nptl_deallocate_tsd (void) attribute_hidden; |
597 | ||
771eb141 FW |
598 | extern void __nptl_setxid_error (struct xid_command *cmdp, int error) |
599 | attribute_hidden; | |
ccd8de9a | 600 | extern int __nptl_setxid (struct xid_command *cmdp) attribute_hidden; |
6f8326ca UD |
601 | #ifndef SHARED |
602 | extern void __nptl_set_robust (struct pthread *self); | |
603 | #endif | |
2edb61e3 | 604 | |
cca50323 | 605 | extern void __free_stacks (size_t limit) attribute_hidden; |
ba408f84 | 606 | |
df94b641 UD |
607 | extern void __wait_lookup_done (void) attribute_hidden; |
608 | ||
b639d0c9 UD |
609 | #ifdef SHARED |
610 | # define PTHREAD_STATIC_FN_REQUIRE(name) | |
611 | #else | |
612 | # define PTHREAD_STATIC_FN_REQUIRE(name) __asm (".globl " #name); | |
613 | #endif | |
614 | ||
da1304bc SP |
615 | /* Returns 0 if POL is a valid scheduling policy. */ |
616 | static inline int | |
617 | check_sched_policy_attr (int pol) | |
618 | { | |
619 | if (pol == SCHED_OTHER || pol == SCHED_FIFO || pol == SCHED_RR) | |
620 | return 0; | |
621 | ||
622 | return EINVAL; | |
623 | } | |
624 | ||
625 | /* Returns 0 if PR is within the accepted range of priority values for | |
626 | the scheduling policy POL or EINVAL otherwise. */ | |
627 | static inline int | |
628 | check_sched_priority_attr (int pr, int pol) | |
629 | { | |
630 | int min = __sched_get_priority_min (pol); | |
631 | int max = __sched_get_priority_max (pol); | |
632 | ||
633 | if (min >= 0 && max >= 0 && pr >= min && pr <= max) | |
634 | return 0; | |
635 | ||
636 | return EINVAL; | |
637 | } | |
638 | ||
639 | /* Returns 0 if ST is a valid stack size for a thread stack and EINVAL | |
640 | otherwise. */ | |
641 | static inline int | |
642 | check_stacksize_attr (size_t st) | |
643 | { | |
644 | if (st >= PTHREAD_STACK_MIN) | |
645 | return 0; | |
646 | ||
647 | return EINVAL; | |
648 | } | |
649 | ||
76a50749 | 650 | #endif /* pthreadP.h */ |