1 /* Copyright (C) 2002-2014 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, see
17 <http://www.gnu.org/licenses/>. */
25 #include <sys/syscall.h>
28 #include <lowlevellock.h>
29 #include <stackinfo.h>
30 #include <internaltypes.h>
31 #include <pthread-functions.h>
33 #include <kernel-features.h>
36 /* Atomic operations on TLS memory. */
37 #ifndef THREAD_ATOMIC_CMPXCHG_VAL
38 # define THREAD_ATOMIC_CMPXCHG_VAL(descr, member, new, old) \
39 atomic_compare_and_exchange_val_acq (&(descr)->member, new, old)
42 #ifndef THREAD_ATOMIC_BIT_SET
43 # define THREAD_ATOMIC_BIT_SET(descr, member, bit) \
44 atomic_bit_set (&(descr)->member, bit)
48 /* Adaptive mutex definitions. */
49 #ifndef MAX_ADAPTIVE_COUNT
50 # define MAX_ADAPTIVE_COUNT 100
54 /* Magic cookie representing robust mutex with dead owner. */
55 #define PTHREAD_MUTEX_INCONSISTENT INT_MAX
56 /* Magic cookie representing not recoverable robust mutex. */
57 #define PTHREAD_MUTEX_NOTRECOVERABLE (INT_MAX - 1)
60 /* Internal mutex type value. */
63 PTHREAD_MUTEX_KIND_MASK_NP
= 3,
65 PTHREAD_MUTEX_ELISION_NP
= 256,
66 PTHREAD_MUTEX_NO_ELISION_NP
= 512,
68 PTHREAD_MUTEX_ROBUST_NORMAL_NP
= 16,
69 PTHREAD_MUTEX_ROBUST_RECURSIVE_NP
70 = PTHREAD_MUTEX_ROBUST_NORMAL_NP
| PTHREAD_MUTEX_RECURSIVE_NP
,
71 PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP
72 = PTHREAD_MUTEX_ROBUST_NORMAL_NP
| PTHREAD_MUTEX_ERRORCHECK_NP
,
73 PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP
74 = PTHREAD_MUTEX_ROBUST_NORMAL_NP
| PTHREAD_MUTEX_ADAPTIVE_NP
,
75 PTHREAD_MUTEX_PRIO_INHERIT_NP
= 32,
76 PTHREAD_MUTEX_PI_NORMAL_NP
77 = PTHREAD_MUTEX_PRIO_INHERIT_NP
| PTHREAD_MUTEX_NORMAL
,
78 PTHREAD_MUTEX_PI_RECURSIVE_NP
79 = PTHREAD_MUTEX_PRIO_INHERIT_NP
| PTHREAD_MUTEX_RECURSIVE_NP
,
80 PTHREAD_MUTEX_PI_ERRORCHECK_NP
81 = PTHREAD_MUTEX_PRIO_INHERIT_NP
| PTHREAD_MUTEX_ERRORCHECK_NP
,
82 PTHREAD_MUTEX_PI_ADAPTIVE_NP
83 = PTHREAD_MUTEX_PRIO_INHERIT_NP
| PTHREAD_MUTEX_ADAPTIVE_NP
,
84 PTHREAD_MUTEX_PI_ROBUST_NORMAL_NP
85 = PTHREAD_MUTEX_PRIO_INHERIT_NP
| PTHREAD_MUTEX_ROBUST_NORMAL_NP
,
86 PTHREAD_MUTEX_PI_ROBUST_RECURSIVE_NP
87 = PTHREAD_MUTEX_PRIO_INHERIT_NP
| PTHREAD_MUTEX_ROBUST_RECURSIVE_NP
,
88 PTHREAD_MUTEX_PI_ROBUST_ERRORCHECK_NP
89 = PTHREAD_MUTEX_PRIO_INHERIT_NP
| PTHREAD_MUTEX_ROBUST_ERRORCHECK_NP
,
90 PTHREAD_MUTEX_PI_ROBUST_ADAPTIVE_NP
91 = PTHREAD_MUTEX_PRIO_INHERIT_NP
| PTHREAD_MUTEX_ROBUST_ADAPTIVE_NP
,
92 PTHREAD_MUTEX_PRIO_PROTECT_NP
= 64,
93 PTHREAD_MUTEX_PP_NORMAL_NP
94 = PTHREAD_MUTEX_PRIO_PROTECT_NP
| PTHREAD_MUTEX_NORMAL
,
95 PTHREAD_MUTEX_PP_RECURSIVE_NP
96 = PTHREAD_MUTEX_PRIO_PROTECT_NP
| PTHREAD_MUTEX_RECURSIVE_NP
,
97 PTHREAD_MUTEX_PP_ERRORCHECK_NP
98 = PTHREAD_MUTEX_PRIO_PROTECT_NP
| PTHREAD_MUTEX_ERRORCHECK_NP
,
99 PTHREAD_MUTEX_PP_ADAPTIVE_NP
100 = PTHREAD_MUTEX_PRIO_PROTECT_NP
| PTHREAD_MUTEX_ADAPTIVE_NP
,
101 PTHREAD_MUTEX_ELISION_FLAGS_NP
102 = PTHREAD_MUTEX_ELISION_NP
| PTHREAD_MUTEX_NO_ELISION_NP
,
104 PTHREAD_MUTEX_TIMED_ELISION_NP
=
105 PTHREAD_MUTEX_TIMED_NP
| PTHREAD_MUTEX_ELISION_NP
,
106 PTHREAD_MUTEX_TIMED_NO_ELISION_NP
=
107 PTHREAD_MUTEX_TIMED_NP
| PTHREAD_MUTEX_NO_ELISION_NP
,
109 #define PTHREAD_MUTEX_PSHARED_BIT 128
111 #define PTHREAD_MUTEX_TYPE(m) \
112 ((m)->__data.__kind & 127)
113 /* Don't include NO_ELISION, as that type is always the same
114 as the underlying lock type. */
115 #define PTHREAD_MUTEX_TYPE_ELISION(m) \
116 ((m)->__data.__kind & (127|PTHREAD_MUTEX_ELISION_NP))
118 #if LLL_PRIVATE == 0 && LLL_SHARED == 128
119 # define PTHREAD_MUTEX_PSHARED(m) \
120 ((m)->__data.__kind & 128)
122 # define PTHREAD_MUTEX_PSHARED(m) \
123 (((m)->__data.__kind & 128) ? LLL_SHARED : LLL_PRIVATE)
126 /* The kernel when waking robust mutexes on exit never uses
127 FUTEX_PRIVATE_FLAG FUTEX_WAKE. */
128 #define PTHREAD_ROBUST_MUTEX_PSHARED(m) LLL_SHARED
130 /* Ceiling in __data.__lock. __data.__lock is signed, so don't
131 use the MSB bit in there, but in the mask also include that bit,
132 so that the compiler can optimize & PTHREAD_MUTEX_PRIO_CEILING_MASK
133 masking if the value is then shifted down by
134 PTHREAD_MUTEX_PRIO_CEILING_SHIFT. */
135 #define PTHREAD_MUTEX_PRIO_CEILING_SHIFT 19
136 #define PTHREAD_MUTEX_PRIO_CEILING_MASK 0xfff80000
139 /* Flags in mutex attr. */
140 #define PTHREAD_MUTEXATTR_PROTOCOL_SHIFT 28
141 #define PTHREAD_MUTEXATTR_PROTOCOL_MASK 0x30000000
142 #define PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT 12
143 #define PTHREAD_MUTEXATTR_PRIO_CEILING_MASK 0x00fff000
144 #define PTHREAD_MUTEXATTR_FLAG_ROBUST 0x40000000
145 #define PTHREAD_MUTEXATTR_FLAG_PSHARED 0x80000000
146 #define PTHREAD_MUTEXATTR_FLAG_BITS \
147 (PTHREAD_MUTEXATTR_FLAG_ROBUST | PTHREAD_MUTEXATTR_FLAG_PSHARED \
148 | PTHREAD_MUTEXATTR_PROTOCOL_MASK | PTHREAD_MUTEXATTR_PRIO_CEILING_MASK)
151 /* Check whether rwlock prefers readers. */
152 #define PTHREAD_RWLOCK_PREFER_READER_P(rwlock) \
153 ((rwlock)->__data.__flags == 0)
156 /* Bits used in robust mutex implementation. */
157 #define FUTEX_WAITERS 0x80000000
158 #define FUTEX_OWNER_DIED 0x40000000
159 #define FUTEX_TID_MASK 0x3fffffff
162 /* Internal variables. */
165 /* Default pthread attributes. */
166 extern struct pthread_attr __default_pthread_attr attribute_hidden
;
167 extern int __default_pthread_attr_lock attribute_hidden
;
169 /* Size and alignment of static TLS block. */
170 extern size_t __static_tls_size attribute_hidden
;
171 extern size_t __static_tls_align_m1 attribute_hidden
;
173 /* Flag whether the machine is SMP or not. */
174 extern int __is_smp attribute_hidden
;
176 /* Thread descriptor handling. */
177 extern list_t __stack_user
;
178 hidden_proto (__stack_user
)
180 /* Attribute handling. */
181 extern struct pthread_attr
*__attr_list attribute_hidden
;
182 extern int __attr_list_lock attribute_hidden
;
184 /* First available RT signal. */
185 extern int __current_sigrtmin attribute_hidden
;
186 /* Last available RT signal. */
187 extern int __current_sigrtmax attribute_hidden
;
189 /* Concurrency handling. */
190 extern int __concurrency_level attribute_hidden
;
192 /* Thread-local data key handling. */
193 extern struct pthread_key_struct __pthread_keys
[PTHREAD_KEYS_MAX
];
194 hidden_proto (__pthread_keys
)
196 /* Number of threads running. */
197 extern unsigned int __nptl_nthreads attribute_hidden
;
199 #ifndef __ASSUME_SET_ROBUST_LIST
200 /* Negative if we do not have the system call and we can use it. */
201 extern int __set_robust_list_avail attribute_hidden
;
204 /* Thread Priority Protection. */
205 extern int __sched_fifo_min_prio attribute_hidden
;
206 extern int __sched_fifo_max_prio attribute_hidden
;
207 extern void __init_sched_fifo_prio (void) attribute_hidden
;
208 extern int __pthread_tpp_change_priority (int prev_prio
, int new_prio
)
210 extern int __pthread_current_priority (void) attribute_hidden
;
212 /* The library can run in debugging mode where it performs a lot more
214 extern int __pthread_debug attribute_hidden
;
215 /** For now disable debugging support. */
217 # define DEBUGGING_P __builtin_expect (__pthread_debug, 0)
218 # define INVALID_TD_P(pd) (DEBUGGING_P && __find_in_stack_list (pd) == NULL)
219 # define INVALID_NOT_TERMINATED_TD_P(pd) INVALID_TD_P (pd)
221 # define DEBUGGING_P 0
222 /* Simplified test. This will not catch all invalid descriptors but
223 is better than nothing. And if the test triggers the thread
224 descriptor is guaranteed to be invalid. */
225 # define INVALID_TD_P(pd) __builtin_expect ((pd)->tid <= 0, 0)
226 # define INVALID_NOT_TERMINATED_TD_P(pd) __builtin_expect ((pd)->tid < 0, 0)
230 /* Cancellation test. */
231 #define CANCELLATION_P(self) \
233 int cancelhandling = THREAD_GETMEM (self, cancelhandling); \
234 if (CANCEL_ENABLED_AND_CANCELED (cancelhandling)) \
236 THREAD_SETMEM (self, result, PTHREAD_CANCELED); \
242 extern void __pthread_unwind (__pthread_unwind_buf_t
*__buf
)
243 __cleanup_fct_attribute
__attribute ((__noreturn__
))
244 #if !defined SHARED && !defined IS_IN_libpthread
248 extern void __pthread_unwind_next (__pthread_unwind_buf_t
*__buf
)
249 __cleanup_fct_attribute
__attribute ((__noreturn__
))
254 extern void __pthread_register_cancel (__pthread_unwind_buf_t
*__buf
)
255 __cleanup_fct_attribute
;
256 extern void __pthread_unregister_cancel (__pthread_unwind_buf_t
*__buf
)
257 __cleanup_fct_attribute
;
258 #if defined NOT_IN_libc && defined IS_IN_libpthread
259 hidden_proto (__pthread_unwind
)
260 hidden_proto (__pthread_unwind_next
)
261 hidden_proto (__pthread_register_cancel
)
262 hidden_proto (__pthread_unregister_cancel
)
264 extern void attribute_hidden
pthread_cancel_init (void);
265 extern void __unwind_freeres (void);
270 /* Called when a thread reacts on a cancellation request. */
272 __attribute ((noreturn
, always_inline
))
275 struct pthread
*self
= THREAD_SELF
;
277 /* Make sure we get no more cancellations. */
278 THREAD_ATOMIC_BIT_SET (self
, cancelhandling
, EXITING_BIT
);
280 __pthread_unwind ((__pthread_unwind_buf_t
*)
281 THREAD_GETMEM (self
, cleanup_jmp_buf
));
285 /* Set cancellation mode to asynchronous. */
286 #define CANCEL_ASYNC() \
287 __pthread_enable_asynccancel ()
288 /* Reset to previous cancellation mode. */
289 #define CANCEL_RESET(oldtype) \
290 __pthread_disable_asynccancel (oldtype)
292 #if !defined NOT_IN_libc
293 /* Same as CANCEL_ASYNC, but for use in libc.so. */
294 # define LIBC_CANCEL_ASYNC() \
295 __libc_enable_asynccancel ()
296 /* Same as CANCEL_RESET, but for use in libc.so. */
297 # define LIBC_CANCEL_RESET(oldtype) \
298 __libc_disable_asynccancel (oldtype)
299 # define LIBC_CANCEL_HANDLED() \
300 __asm (".globl " __SYMBOL_PREFIX "__libc_enable_asynccancel"); \
301 __asm (".globl " __SYMBOL_PREFIX "__libc_disable_asynccancel")
302 #elif defined NOT_IN_libc && defined IS_IN_libpthread
303 # define LIBC_CANCEL_ASYNC() CANCEL_ASYNC ()
304 # define LIBC_CANCEL_RESET(val) CANCEL_RESET (val)
305 # define LIBC_CANCEL_HANDLED() \
306 __asm (".globl " __SYMBOL_PREFIX "__pthread_enable_asynccancel"); \
307 __asm (".globl " __SYMBOL_PREFIX "__pthread_disable_asynccancel")
308 #elif defined NOT_IN_libc && defined IS_IN_librt
309 # define LIBC_CANCEL_ASYNC() \
310 __librt_enable_asynccancel ()
311 # define LIBC_CANCEL_RESET(val) \
312 __librt_disable_asynccancel (val)
313 # define LIBC_CANCEL_HANDLED() \
314 __asm (".globl " __SYMBOL_PREFIX "__librt_enable_asynccancel"); \
315 __asm (".globl " __SYMBOL_PREFIX "__librt_disable_asynccancel")
317 # define LIBC_CANCEL_ASYNC() 0 /* Just a dummy value. */
318 # define LIBC_CANCEL_RESET(val) ((void)(val)) /* Nothing, but evaluate it. */
319 # define LIBC_CANCEL_HANDLED() /* Nothing. */
322 /* The signal used for asynchronous cancelation. */
323 #define SIGCANCEL __SIGRTMIN
326 /* Signal needed for the kernel-supported POSIX timer implementation.
327 We can reuse the cancellation signal since we can distinguish
328 cancellation from timer expirations. */
329 #define SIGTIMER SIGCANCEL
332 /* Signal used to implement the setuid et.al. functions. */
333 #define SIGSETXID (__SIGRTMIN + 1)
335 /* Used to communicate with signal handler. */
336 extern struct xid_command
*__xidcmd attribute_hidden
;
339 /* Internal prototypes. */
341 /* Thread list handling. */
342 extern struct pthread
*__find_in_stack_list (struct pthread
*pd
)
343 attribute_hidden internal_function
;
345 /* Deallocate a thread's stack after optionally making sure the thread
346 descriptor is still valid. */
347 extern void __free_tcb (struct pthread
*pd
) attribute_hidden internal_function
;
349 /* Free allocated stack. */
350 extern void __deallocate_stack (struct pthread
*pd
)
351 attribute_hidden internal_function
;
353 /* Mark all the stacks except for the current one as available. This
354 function also re-initializes the lock for the stack cache. */
355 extern void __reclaim_stacks (void) attribute_hidden
;
357 /* Make all threads's stacks executable. */
358 extern int __make_stacks_executable (void **stack_endp
)
359 internal_function attribute_hidden
;
361 /* longjmp handling. */
362 extern void __pthread_cleanup_upto (__jmp_buf target
, char *targetframe
);
363 #if defined NOT_IN_libc && defined IS_IN_libpthread
364 hidden_proto (__pthread_cleanup_upto
)
368 /* Functions with versioned interfaces. */
369 extern int __pthread_create_2_1 (pthread_t
*newthread
,
370 const pthread_attr_t
*attr
,
371 void *(*start_routine
) (void *), void *arg
);
372 extern int __pthread_create_2_0 (pthread_t
*newthread
,
373 const pthread_attr_t
*attr
,
374 void *(*start_routine
) (void *), void *arg
);
375 extern int __pthread_attr_init_2_1 (pthread_attr_t
*attr
);
376 extern int __pthread_attr_init_2_0 (pthread_attr_t
*attr
);
379 /* Event handlers for libthread_db interface. */
380 extern void __nptl_create_event (void);
381 extern void __nptl_death_event (void);
382 hidden_proto (__nptl_create_event
)
383 hidden_proto (__nptl_death_event
)
385 /* Register the generation counter in the libpthread with the libc. */
386 #ifdef TLS_MULTIPLE_THREADS_IN_TCB
387 extern void __libc_pthread_init (unsigned long int *ptr
,
388 void (*reclaim
) (void),
389 const struct pthread_functions
*functions
)
392 extern int *__libc_pthread_init (unsigned long int *ptr
,
393 void (*reclaim
) (void),
394 const struct pthread_functions
*functions
)
397 /* Variable set to a nonzero value either if more than one thread runs or ran,
398 or if a single-threaded process is trying to cancel itself. See
399 nptl/descr.h for more context on the single-threaded process case. */
400 extern int __pthread_multiple_threads attribute_hidden
;
401 /* Pointer to the corresponding variable in libc. */
402 extern int *__libc_multiple_threads_ptr attribute_hidden
;
405 /* Find a thread given its TID. */
406 extern struct pthread
*__find_thread_by_id (pid_t tid
) attribute_hidden
411 #define __find_thread_by_id(tid) \
412 (__find_thread_by_id ? (__find_thread_by_id) (tid) : (struct pthread *) NULL)
415 extern void __pthread_init_static_tls (struct link_map
*) attribute_hidden
;
417 extern size_t __pthread_get_minstack (const pthread_attr_t
*attr
);
419 /* Namespace save aliases. */
420 extern int __pthread_getschedparam (pthread_t thread_id
, int *policy
,
421 struct sched_param
*param
);
422 extern int __pthread_setschedparam (pthread_t thread_id
, int policy
,
423 const struct sched_param
*param
);
424 extern int __pthread_setcancelstate (int state
, int *oldstate
);
425 extern int __pthread_mutex_init (pthread_mutex_t
*__mutex
,
426 const pthread_mutexattr_t
*__mutexattr
);
427 extern int __pthread_mutex_destroy (pthread_mutex_t
*__mutex
);
428 extern int __pthread_mutex_trylock (pthread_mutex_t
*_mutex
);
429 extern int __pthread_mutex_lock (pthread_mutex_t
*__mutex
);
430 extern int __pthread_mutex_cond_lock (pthread_mutex_t
*__mutex
)
431 attribute_hidden internal_function
;
432 extern void __pthread_mutex_cond_lock_adjust (pthread_mutex_t
*__mutex
)
433 attribute_hidden internal_function
;
434 extern int __pthread_mutex_unlock (pthread_mutex_t
*__mutex
);
435 extern int __pthread_mutex_unlock_usercnt (pthread_mutex_t
*__mutex
,
437 attribute_hidden internal_function
;
438 extern int __pthread_mutexattr_init (pthread_mutexattr_t
*attr
);
439 extern int __pthread_mutexattr_destroy (pthread_mutexattr_t
*attr
);
440 extern int __pthread_mutexattr_settype (pthread_mutexattr_t
*attr
, int kind
);
441 extern int __pthread_attr_destroy (pthread_attr_t
*attr
);
442 extern int __pthread_attr_getdetachstate (const pthread_attr_t
*attr
,
444 extern int __pthread_attr_setdetachstate (pthread_attr_t
*attr
,
446 extern int __pthread_attr_getinheritsched (const pthread_attr_t
*attr
,
448 extern int __pthread_attr_setinheritsched (pthread_attr_t
*attr
, int inherit
);
449 extern int __pthread_attr_getschedparam (const pthread_attr_t
*attr
,
450 struct sched_param
*param
);
451 extern int __pthread_attr_setschedparam (pthread_attr_t
*attr
,
452 const struct sched_param
*param
);
453 extern int __pthread_attr_getschedpolicy (const pthread_attr_t
*attr
,
455 extern int __pthread_attr_setschedpolicy (pthread_attr_t
*attr
, int policy
);
456 extern int __pthread_attr_getscope (const pthread_attr_t
*attr
, int *scope
);
457 extern int __pthread_attr_setscope (pthread_attr_t
*attr
, int scope
);
458 extern int __pthread_attr_getstackaddr (const pthread_attr_t
*__restrict
459 __attr
, void **__restrict __stackaddr
);
460 extern int __pthread_attr_setstackaddr (pthread_attr_t
*__attr
,
462 extern int __pthread_attr_getstacksize (const pthread_attr_t
*__restrict
464 size_t *__restrict __stacksize
);
465 extern int __pthread_attr_setstacksize (pthread_attr_t
*__attr
,
467 extern int __pthread_attr_getstack (const pthread_attr_t
*__restrict __attr
,
468 void **__restrict __stackaddr
,
469 size_t *__restrict __stacksize
);
470 extern int __pthread_attr_setstack (pthread_attr_t
*__attr
, void *__stackaddr
,
472 extern int __pthread_rwlock_init (pthread_rwlock_t
*__restrict __rwlock
,
473 const pthread_rwlockattr_t
*__restrict
475 extern int __pthread_rwlock_destroy (pthread_rwlock_t
*__rwlock
);
476 extern int __pthread_rwlock_rdlock (pthread_rwlock_t
*__rwlock
);
477 extern int __pthread_rwlock_tryrdlock (pthread_rwlock_t
*__rwlock
);
478 extern int __pthread_rwlock_wrlock (pthread_rwlock_t
*__rwlock
);
479 extern int __pthread_rwlock_trywrlock (pthread_rwlock_t
*__rwlock
);
480 extern int __pthread_rwlock_unlock (pthread_rwlock_t
*__rwlock
);
481 extern int __pthread_cond_broadcast (pthread_cond_t
*cond
);
482 extern int __pthread_cond_destroy (pthread_cond_t
*cond
);
483 extern int __pthread_cond_init (pthread_cond_t
*cond
,
484 const pthread_condattr_t
*cond_attr
);
485 extern int __pthread_cond_signal (pthread_cond_t
*cond
);
486 extern int __pthread_cond_wait (pthread_cond_t
*cond
, pthread_mutex_t
*mutex
);
487 extern int __pthread_cond_timedwait (pthread_cond_t
*cond
,
488 pthread_mutex_t
*mutex
,
489 const struct timespec
*abstime
);
490 extern int __pthread_condattr_destroy (pthread_condattr_t
*attr
);
491 extern int __pthread_condattr_init (pthread_condattr_t
*attr
);
492 extern int __pthread_key_create (pthread_key_t
*key
, void (*destr
) (void *));
493 extern void *__pthread_getspecific (pthread_key_t key
);
494 extern int __pthread_setspecific (pthread_key_t key
, const void *value
);
495 extern int __pthread_once (pthread_once_t
*once_control
,
496 void (*init_routine
) (void));
497 extern int __pthread_atfork (void (*prepare
) (void), void (*parent
) (void),
498 void (*child
) (void));
499 extern pthread_t
__pthread_self (void);
500 extern int __pthread_equal (pthread_t thread1
, pthread_t thread2
);
501 extern int __pthread_kill (pthread_t threadid
, int signo
);
502 extern void __pthread_exit (void *value
) __attribute__ ((__noreturn__
));
503 extern int __pthread_setcanceltype (int type
, int *oldtype
);
504 extern int __pthread_enable_asynccancel (void) attribute_hidden
;
505 extern void __pthread_disable_asynccancel (int oldtype
)
506 internal_function attribute_hidden
;
508 #if defined NOT_IN_libc && defined IS_IN_libpthread
509 hidden_proto (__pthread_mutex_init
)
510 hidden_proto (__pthread_mutex_destroy
)
511 hidden_proto (__pthread_mutex_lock
)
512 hidden_proto (__pthread_mutex_unlock
)
513 hidden_proto (__pthread_rwlock_rdlock
)
514 hidden_proto (__pthread_rwlock_wrlock
)
515 hidden_proto (__pthread_rwlock_unlock
)
516 hidden_proto (__pthread_key_create
)
517 hidden_proto (__pthread_getspecific
)
518 hidden_proto (__pthread_setspecific
)
519 hidden_proto (__pthread_once
)
522 extern int __pthread_cond_broadcast_2_0 (pthread_cond_2_0_t
*cond
);
523 extern int __pthread_cond_destroy_2_0 (pthread_cond_2_0_t
*cond
);
524 extern int __pthread_cond_init_2_0 (pthread_cond_2_0_t
*cond
,
525 const pthread_condattr_t
*cond_attr
);
526 extern int __pthread_cond_signal_2_0 (pthread_cond_2_0_t
*cond
);
527 extern int __pthread_cond_timedwait_2_0 (pthread_cond_2_0_t
*cond
,
528 pthread_mutex_t
*mutex
,
529 const struct timespec
*abstime
);
530 extern int __pthread_cond_wait_2_0 (pthread_cond_2_0_t
*cond
,
531 pthread_mutex_t
*mutex
);
533 extern int __pthread_getaffinity_np (pthread_t th
, size_t cpusetsize
,
536 /* The two functions are in libc.so and not exported. */
537 extern int __libc_enable_asynccancel (void) attribute_hidden
;
538 extern void __libc_disable_asynccancel (int oldtype
)
539 internal_function attribute_hidden
;
542 /* The two functions are in librt.so and not exported. */
543 extern int __librt_enable_asynccancel (void) attribute_hidden
;
544 extern void __librt_disable_asynccancel (int oldtype
)
545 internal_function attribute_hidden
;
547 #ifdef IS_IN_libpthread
548 /* Special versions which use non-exported functions. */
549 extern void __pthread_cleanup_push (struct _pthread_cleanup_buffer
*buffer
,
550 void (*routine
) (void *), void *arg
)
552 # undef pthread_cleanup_push
553 # define pthread_cleanup_push(routine,arg) \
554 { struct _pthread_cleanup_buffer _buffer; \
555 __pthread_cleanup_push (&_buffer, (routine), (arg));
557 extern void __pthread_cleanup_pop (struct _pthread_cleanup_buffer
*buffer
,
558 int execute
) attribute_hidden
;
559 # undef pthread_cleanup_pop
560 # define pthread_cleanup_pop(execute) \
561 __pthread_cleanup_pop (&_buffer, (execute)); }
564 extern void __pthread_cleanup_push_defer (struct _pthread_cleanup_buffer
*buffer
,
565 void (*routine
) (void *), void *arg
);
566 extern void __pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer
*buffer
,
569 /* Old cleanup interfaces, still used in libc.so. */
570 extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer
*buffer
,
571 void (*routine
) (void *), void *arg
);
572 extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer
*buffer
,
574 extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer
*buffer
,
575 void (*routine
) (void *), void *arg
);
576 extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer
*buffer
,
579 extern void __nptl_deallocate_tsd (void) attribute_hidden
;
581 extern int __nptl_setxid (struct xid_command
*cmdp
) attribute_hidden
;
583 extern void __nptl_set_robust (struct pthread
*self
);
586 extern void __free_stacks (size_t limit
) attribute_hidden
;
588 extern void __wait_lookup_done (void) attribute_hidden
;
591 # define PTHREAD_STATIC_FN_REQUIRE(name)
593 # define PTHREAD_STATIC_FN_REQUIRE(name) __asm (".globl " #name);
596 /* Test if the mutex is suitable for the FUTEX_WAIT_REQUEUE_PI operation. */
597 #if (defined lll_futex_wait_requeue_pi \
598 && defined __ASSUME_REQUEUE_PI)
599 # define USE_REQUEUE_PI(mut) \
600 ((mut) && (mut) != (void *) ~0l \
601 && (((mut)->__data.__kind \
602 & (PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_NORMAL_NP)) \
603 == PTHREAD_MUTEX_PRIO_INHERIT_NP))
605 # define USE_REQUEUE_PI(mut) 0
608 /* Returns 0 if POL is a valid scheduling policy. */
610 check_sched_policy_attr (int pol
)
612 if (pol
== SCHED_OTHER
|| pol
== SCHED_FIFO
|| pol
== SCHED_RR
)
618 /* Returns 0 if PR is within the accepted range of priority values for
619 the scheduling policy POL or EINVAL otherwise. */
621 check_sched_priority_attr (int pr
, int pol
)
623 int min
= __sched_get_priority_min (pol
);
624 int max
= __sched_get_priority_max (pol
);
626 if (min
>= 0 && max
>= 0 && pr
>= min
&& pr
<= max
)
632 /* Returns 0 if ST is a valid stack size for a thread stack and EINVAL
635 check_stacksize_attr (size_t st
)
637 if (st
>= PTHREAD_STACK_MIN
)
643 /* Defined in pthread_setaffinity.c. */
644 extern size_t __kernel_cpumask_size attribute_hidden
;
645 extern int __determine_cpumask_size (pid_t tid
);
647 /* Returns 0 if CS and SZ are valid values for the cpuset and cpuset size
648 respectively. Otherwise it returns an error number. */
650 check_cpuset_attr (const cpu_set_t
*cs
, const size_t sz
)
652 if (__kernel_cpumask_size
== 0)
654 int res
= __determine_cpumask_size (THREAD_SELF
->tid
);
659 /* Check whether the new bitmask has any bit set beyond the
660 last one the kernel accepts. */
661 for (size_t cnt
= __kernel_cpumask_size
; cnt
< sz
; ++cnt
)
662 if (((char *) cs
)[cnt
] != '\0')
663 /* Found a nonzero byte. This means the user request cannot be
670 #endif /* pthreadP.h */