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