2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (C) 2005 Daniel M. Eischen <deischen@freebsd.org>
5 * Copyright (c) 2005 David Xu <davidxu@freebsd.org>
6 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice unmodified, this list of conditions, and the following
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef _THR_PRIVATE_H
35 #define _THR_PRIVATE_H
40 #include <sys/types.h>
42 #include <sys/cdefs.h>
43 #include <sys/queue.h>
44 #include <sys/param.h>
45 #include <sys/cpuset.h>
46 #include <machine/atomic.h>
58 __NULLABILITY_PRAGMA_PUSH
60 #define SYM_FB10(sym) __CONCAT(sym, _fb10)
61 #define SYM_FBP10(sym) __CONCAT(sym, _fbp10)
62 #define WEAK_REF(sym, alias) __weak_reference(sym, alias)
63 #define SYM_COMPAT(sym, impl, ver) __sym_compat(sym, impl, ver)
64 #define SYM_DEFAULT(sym, impl, ver) __sym_default(sym, impl, ver)
66 #define FB10_COMPAT(func, sym) \
67 WEAK_REF(func, SYM_FB10(sym)); \
68 SYM_COMPAT(sym, SYM_FB10(sym), FBSD_1.0)
70 #define FB10_COMPAT_PRIVATE(func, sym) \
71 WEAK_REF(func, SYM_FBP10(sym)); \
72 SYM_DEFAULT(sym, SYM_FBP10(sym), FBSDprivate_1.0)
75 extern struct pthread *_thr_initial __hidden;
77 #include "pthread_md.h"
79 #include "thread_db.h"
81 #ifdef _PTHREAD_FORCED_UNWIND
86 typedef TAILQ_HEAD(pthreadlist, pthread) pthreadlist;
87 typedef TAILQ_HEAD(atfork_head, pthread_atfork) atfork_head;
88 TAILQ_HEAD(mutex_queue, pthread_mutex);
90 /* Signal to do cancellation */
91 #define SIGCANCEL SIGTHR
94 * Kernel fatal error handler macro.
96 #define PANIC(args...) _thread_exitf(__FILE__, __LINE__, ##args)
98 /* Output debug messages like this: */
99 #define stdout_debug(args...) _thread_printf(STDOUT_FILENO, ##args)
100 #define stderr_debug(args...) _thread_printf(STDERR_FILENO, ##args)
102 #ifdef _PTHREADS_INVARIANTS
103 #define THR_ASSERT(cond, msg) do { \
104 if (__predict_false(!(cond))) \
108 #define THR_ASSERT(cond, msg)
112 # define STATIC_LIB_REQUIRE(name)
114 # define STATIC_LIB_REQUIRE(name) __asm (".globl " #name)
117 #define TIMESPEC_ADD(dst, src, val) \
119 (dst)->tv_sec = (src)->tv_sec + (val)->tv_sec; \
120 (dst)->tv_nsec = (src)->tv_nsec + (val)->tv_nsec; \
121 if ((dst)->tv_nsec >= 1000000000) { \
123 (dst)->tv_nsec -= 1000000000; \
127 #define TIMESPEC_SUB(dst, src, val) \
129 (dst)->tv_sec = (src)->tv_sec - (val)->tv_sec; \
130 (dst)->tv_nsec = (src)->tv_nsec - (val)->tv_nsec; \
131 if ((dst)->tv_nsec < 0) { \
133 (dst)->tv_nsec += 1000000000; \
137 /* Magic cookie set for shared pthread locks and cv's pointers */
138 #define THR_PSHARED_PTR \
139 ((void *)(uintptr_t)((1ULL << (NBBY * sizeof(long) - 1)) | 1))
141 /* XXX These values should be same as those defined in pthread.h */
142 #define THR_MUTEX_INITIALIZER ((struct pthread_mutex *)NULL)
143 #define THR_ADAPTIVE_MUTEX_INITIALIZER ((struct pthread_mutex *)1)
144 #define THR_MUTEX_DESTROYED ((struct pthread_mutex *)2)
145 #define THR_COND_INITIALIZER ((struct pthread_cond *)NULL)
146 #define THR_COND_DESTROYED ((struct pthread_cond *)1)
147 #define THR_RWLOCK_INITIALIZER ((struct pthread_rwlock *)NULL)
148 #define THR_RWLOCK_DESTROYED ((struct pthread_rwlock *)1)
150 #define PMUTEX_FLAG_TYPE_MASK 0x0ff
151 #define PMUTEX_FLAG_PRIVATE 0x100
152 #define PMUTEX_FLAG_DEFERRED 0x200
153 #define PMUTEX_TYPE(mtxflags) ((mtxflags) & PMUTEX_FLAG_TYPE_MASK)
155 #define PMUTEX_OWNER_ID(m) ((m)->m_lock.m_owner & ~UMUTEX_CONTESTED)
157 #define MAX_DEFER_WAITERS 50
160 * Values for pthread_mutex m_ps indicator.
162 #define PMUTEX_INITSTAGE_ALLOC 0
163 #define PMUTEX_INITSTAGE_BUSY 1
164 #define PMUTEX_INITSTAGE_DONE 2
166 struct pthread_mutex {
168 * Lock for accesses to this structure.
170 struct umutex m_lock;
175 int m_ps; /* pshared init stage */
177 * Link for all mutexes a thread currently owns, of the same
180 TAILQ_ENTRY(pthread_mutex) m_qe;
181 /* Link for all private mutexes a thread currently owns. */
182 TAILQ_ENTRY(pthread_mutex) m_pqe;
183 struct pthread_mutex *m_rb_prev;
186 struct pthread_mutex_attr {
187 enum pthread_mutextype m_type;
194 #define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \
195 { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE, \
196 PTHREAD_MUTEX_STALLED }
198 struct pthread_cond {
199 __uint32_t __has_user_waiters;
203 struct pthread_cond_attr {
208 struct pthread_barrier {
209 struct umutex b_lock;
218 struct pthread_barrierattr {
222 struct pthread_spinlock {
223 struct umutex s_lock;
227 * Flags for condition variables.
229 #define COND_FLAGS_PRIVATE 0x01
230 #define COND_FLAGS_INITED 0x02
231 #define COND_FLAGS_BUSY 0x04
234 * Cleanup definitions.
236 struct pthread_cleanup {
237 struct pthread_cleanup *prev;
238 void (*routine)(void *);
243 #define THR_CLEANUP_PUSH(td, func, arg) { \
244 struct pthread_cleanup __cup; \
246 __cup.routine = func; \
247 __cup.routine_arg = arg; \
249 __cup.prev = (td)->cleanup; \
250 (td)->cleanup = &__cup;
252 #define THR_CLEANUP_POP(td, exec) \
253 (td)->cleanup = __cup.prev; \
255 __cup.routine(__cup.routine_arg); \
258 struct pthread_atfork {
259 TAILQ_ENTRY(pthread_atfork) qe;
260 void (*prepare)(void);
261 void (*parent)(void);
265 struct pthread_attr {
266 #define pthread_attr_start_copy sched_policy
271 #define THR_STACK_USER 0x100 /* 0xFF reserved for <pthread.h> */
273 void *stackaddr_attr;
274 size_t stacksize_attr;
275 size_t guardsize_attr;
276 #define pthread_attr_end_copy cpuset
282 struct wake_addr *link;
288 TAILQ_HEAD(, pthread) sq_blocked;
289 SLIST_HEAD(, sleepqueue) sq_freeq;
290 LIST_ENTRY(sleepqueue) sq_hash;
291 SLIST_ENTRY(sleepqueue) sq_flink;
297 * Thread creation state attributes.
299 #define THR_CREATE_RUNNING 0
300 #define THR_CREATE_SUSPENDED 1
303 * Miscellaneous definitions.
305 #define THR_STACK_DEFAULT (sizeof(void *) / 4 * 1024 * 1024)
308 * Maximum size of initial thread's stack. This perhaps deserves to be larger
309 * than the stacks of other threads, since many applications are likely to run
310 * almost entirely on this stack.
312 #define THR_STACK_INITIAL (THR_STACK_DEFAULT * 2)
315 * Define priorities returned by kernel.
317 #define THR_MIN_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_min)
318 #define THR_MAX_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_max)
319 #define THR_DEF_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_default)
321 #define THR_MIN_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_min)
322 #define THR_MAX_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_max)
323 #define THR_DEF_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_default)
325 /* XXX The SCHED_FIFO should have same priority range as SCHED_RR */
326 #define THR_MIN_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO_1].pri_min)
327 #define THR_MAX_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_max)
328 #define THR_DEF_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_default)
330 struct pthread_prio {
336 struct pthread_rwlockattr {
340 struct pthread_rwlock {
353 struct pthread_specific_elem {
359 volatile int allocated;
361 void (*destructor)(void *);
365 * lwpid_t is 32bit but kernel thr API exports tid as long type
366 * to preserve the ABI for M:N model in very early date (r131431).
368 #define TID(thread) ((uint32_t) ((thread)->tid))
374 #define _pthread_startzero tid
375 /* Kernel thread id. */
377 #define TID_TERMINATED 1
380 * Lock for accesses to this thread structure.
384 /* Internal condition variable cycle number. */
387 /* How many low level locks the thread held. */
391 * Set to non-zero when this thread has entered a critical
392 * region. We allow for recursive entries into critical regions.
396 /* Signal blocked counter. */
399 /* Fast sigblock var. */
402 /* Queue entry for list of all threads. */
403 TAILQ_ENTRY(pthread) tle; /* link for all threads in process */
405 /* Queue entry for GC lists. */
406 TAILQ_ENTRY(pthread) gcle;
408 /* Hash queue entry. */
409 LIST_ENTRY(pthread) hle;
411 /* Sleep queue entry */
412 TAILQ_ENTRY(pthread) wle;
414 /* Threads reference count. */
418 * Thread start routine, argument, stack pointer and thread
421 void *(*start_routine)(void *);
423 struct pthread_attr attr;
425 #define SHOULD_CANCEL(thr) \
426 ((thr)->cancel_pending && (thr)->cancel_enable && \
427 (thr)->no_cancel == 0)
429 /* Cancellation is enabled */
432 /* Cancellation request is pending */
435 /* Thread is at cancellation point */
438 /* Cancellation is temporarily disabled */
441 /* Asynchronouse cancellation is enabled */
444 /* Cancellation is in progress */
447 /* Thread temporary signal mask. */
450 /* Thread should unblock SIGCANCEL. */
451 int unblock_sigcancel;
453 /* In sigsuspend state */
456 /* deferred signal info */
457 siginfo_t deferred_siginfo;
459 /* signal mask to restore. */
460 sigset_t deferred_sigmask;
462 /* the sigaction should be used for deferred signal. */
463 struct sigaction deferred_sigact;
465 /* deferred signal delivery is performed, do not reenter. */
468 /* Force new thread to exit. */
472 enum pthread_state state;
475 * Error variable used instead of errno. The function __error()
476 * returns a pointer to this.
481 * The joiner is the thread that is joining to this thread. The
482 * join status keeps track of a join operation to another thread.
484 struct pthread *joiner;
486 /* Miscellaneous flags; only set with scheduling lock held. */
488 #define THR_FLAGS_PRIVATE 0x0001
489 #define THR_FLAGS_NEED_SUSPEND 0x0002 /* thread should be suspended */
490 #define THR_FLAGS_SUSPENDED 0x0004 /* thread is suspended */
491 #define THR_FLAGS_DETACHED 0x0008 /* thread is detached */
493 /* Thread list flags; only set with thread list lock held. */
495 #define TLFLAGS_GC_SAFE 0x0001 /* thread safe for cleaning */
496 #define TLFLAGS_IN_TDLIST 0x0002 /* thread in all thread list */
497 #define TLFLAGS_IN_GCLIST 0x0004 /* thread in gc list */
500 * Queues of the owned mutexes. Private queue must have index
501 * + 1 of the corresponding full queue.
503 #define TMQ_NORM 0 /* NORMAL or PRIO_INHERIT normal */
504 #define TMQ_NORM_PRIV 1 /* NORMAL or PRIO_INHERIT normal priv */
505 #define TMQ_NORM_PP 2 /* PRIO_PROTECT normal mutexes */
506 #define TMQ_NORM_PP_PRIV 3 /* PRIO_PROTECT normal priv */
507 #define TMQ_ROBUST_PP 4 /* PRIO_PROTECT robust mutexes */
508 #define TMQ_ROBUST_PP_PRIV 5 /* PRIO_PROTECT robust priv */
510 struct mutex_queue mq[TMQ_NITEMS];
513 struct pthread_specific_elem *specific;
514 int specific_data_count;
516 /* Number rwlocks rdlocks held. */
520 * Current locks bitmap for rtld. */
523 /* Thread control block */
526 /* Cleanup handlers Link List */
527 struct pthread_cleanup *cleanup;
529 #ifdef _PTHREAD_FORCED_UNWIND
530 struct _Unwind_Exception ex;
531 void *unwind_stackend;
536 * Magic value to help recognize a valid thread structure
537 * from an invalid one:
539 #define THR_MAGIC ((u_int32_t) 0xd09ba115)
542 /* Enable event reporting */
549 td_event_msg_t event_buf;
554 /* Referenced mutex. */
555 struct pthread_mutex *mutex_obj;
557 /* Thread will sleep. */
560 /* Number of threads deferred. */
564 uintptr_t robust_list;
565 uintptr_t priv_robust_list;
568 /* Deferred threads from pthread_cond_signal. */
569 unsigned int *defer_waiters[MAX_DEFER_WAITERS];
570 #define _pthread_endzero wake_addr
572 struct wake_addr *wake_addr;
573 #define WAKE_ADDR(td) ((td)->wake_addr)
576 struct sleepqueue *sleepqueue;
578 /* pthread_set/get_name_np */
582 #define THR_SHOULD_GC(thrd) \
583 ((thrd)->refcount == 0 && (thrd)->state == PS_DEAD && \
584 ((thrd)->flags & THR_FLAGS_DETACHED) != 0)
586 #define THR_IN_CRITICAL(thrd) \
587 (((thrd)->locklevel > 0) || \
588 ((thrd)->critical_count > 0))
590 #define THR_CRITICAL_ENTER(thrd) \
591 (thrd)->critical_count++
593 #define THR_CRITICAL_LEAVE(thrd) \
595 (thrd)->critical_count--; \
599 #define THR_UMUTEX_TRYLOCK(thrd, lck) \
600 _thr_umutex_trylock((lck), TID(thrd))
602 #define THR_UMUTEX_LOCK(thrd, lck) \
603 _thr_umutex_lock((lck), TID(thrd))
605 #define THR_UMUTEX_TIMEDLOCK(thrd, lck, timo) \
606 _thr_umutex_timedlock((lck), TID(thrd), (timo))
608 #define THR_UMUTEX_UNLOCK(thrd, lck) \
609 _thr_umutex_unlock((lck), TID(thrd))
611 #define THR_LOCK_ACQUIRE(thrd, lck) \
613 (thrd)->locklevel++; \
614 _thr_umutex_lock(lck, TID(thrd)); \
617 #define THR_LOCK_ACQUIRE_SPIN(thrd, lck) \
619 (thrd)->locklevel++; \
620 _thr_umutex_lock_spin(lck, TID(thrd)); \
623 #ifdef _PTHREADS_INVARIANTS
624 #define THR_ASSERT_LOCKLEVEL(thrd) \
626 if (__predict_false((thrd)->locklevel <= 0)) \
627 _thr_assert_lock_level(); \
630 #define THR_ASSERT_LOCKLEVEL(thrd)
633 #define THR_LOCK_RELEASE(thrd, lck) \
635 THR_ASSERT_LOCKLEVEL(thrd); \
636 _thr_umutex_unlock((lck), TID(thrd)); \
637 (thrd)->locklevel--; \
641 #define THR_LOCK(curthrd) THR_LOCK_ACQUIRE(curthrd, &(curthrd)->lock)
642 #define THR_UNLOCK(curthrd) THR_LOCK_RELEASE(curthrd, &(curthrd)->lock)
643 #define THR_THREAD_LOCK(curthrd, thr) THR_LOCK_ACQUIRE(curthrd, &(thr)->lock)
644 #define THR_THREAD_UNLOCK(curthrd, thr) THR_LOCK_RELEASE(curthrd, &(thr)->lock)
646 #define THREAD_LIST_RDLOCK(curthrd) \
648 (curthrd)->locklevel++; \
649 _thr_rwl_rdlock(&_thr_list_lock); \
652 #define THREAD_LIST_WRLOCK(curthrd) \
654 (curthrd)->locklevel++; \
655 _thr_rwl_wrlock(&_thr_list_lock); \
658 #define THREAD_LIST_UNLOCK(curthrd) \
660 _thr_rwl_unlock(&_thr_list_lock); \
661 (curthrd)->locklevel--; \
666 * Macros to insert/remove threads to the all thread list and
669 #define THR_LIST_ADD(thrd) do { \
670 if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) == 0) { \
671 TAILQ_INSERT_HEAD(&_thread_list, thrd, tle); \
672 _thr_hash_add(thrd); \
673 (thrd)->tlflags |= TLFLAGS_IN_TDLIST; \
676 #define THR_LIST_REMOVE(thrd) do { \
677 if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) != 0) { \
678 TAILQ_REMOVE(&_thread_list, thrd, tle); \
679 _thr_hash_remove(thrd); \
680 (thrd)->tlflags &= ~TLFLAGS_IN_TDLIST; \
683 #define THR_GCLIST_ADD(thrd) do { \
684 if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) == 0) { \
685 TAILQ_INSERT_HEAD(&_thread_gc_list, thrd, gcle);\
686 (thrd)->tlflags |= TLFLAGS_IN_GCLIST; \
690 #define THR_GCLIST_REMOVE(thrd) do { \
691 if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) != 0) { \
692 TAILQ_REMOVE(&_thread_gc_list, thrd, gcle); \
693 (thrd)->tlflags &= ~TLFLAGS_IN_GCLIST; \
698 #define THR_REF_ADD(curthread, pthread) { \
699 THR_CRITICAL_ENTER(curthread); \
700 pthread->refcount++; \
703 #define THR_REF_DEL(curthread, pthread) { \
704 pthread->refcount--; \
705 THR_CRITICAL_LEAVE(curthread); \
708 #define GC_NEEDED() (_gc_count >= 5)
710 #define SHOULD_REPORT_EVENT(curthr, e) \
711 (curthr->report_events && \
712 (((curthr)->event_mask | _thread_event_mask ) & e) != 0)
714 #ifndef __LIBC_ISTHREADED_DECLARED
715 #define __LIBC_ISTHREADED_DECLARED
716 extern int __isthreaded;
720 * Global variables for the pthread kernel.
723 extern char *_usrstack __hidden;
726 extern int _libthr_debug;
727 extern int _thread_event_mask;
728 extern struct pthread *_thread_last_event;
729 /* Used in symbol lookup of libthread_db */
730 extern struct pthread_key _thread_keytable[];
732 /* List of all threads: */
733 extern pthreadlist _thread_list;
735 /* List of threads needing GC: */
736 extern pthreadlist _thread_gc_list __hidden;
738 extern int _thread_active_threads;
739 extern atfork_head _thr_atfork_list __hidden;
740 extern struct urwlock _thr_atfork_lock __hidden;
742 /* Default thread attributes: */
743 extern struct pthread_attr _pthread_attr_default __hidden;
745 /* Default mutex attributes: */
746 extern struct pthread_mutex_attr _pthread_mutexattr_default __hidden;
747 extern struct pthread_mutex_attr _pthread_mutexattr_adaptive_default __hidden;
749 /* Default condition variable attributes: */
750 extern struct pthread_cond_attr _pthread_condattr_default __hidden;
752 extern struct pthread_prio _thr_priorities[] __hidden;
754 extern int _thr_is_smp __hidden;
756 extern size_t _thr_guard_default __hidden;
757 extern size_t _thr_stack_default __hidden;
758 extern size_t _thr_stack_initial __hidden;
759 extern int _thr_page_size __hidden;
760 extern int _thr_spinloops __hidden;
761 extern int _thr_yieldloops __hidden;
762 extern int _thr_queuefifo __hidden;
764 /* Garbage thread count. */
765 extern int _gc_count __hidden;
767 extern struct umutex _mutex_static_lock __hidden;
768 extern struct umutex _cond_static_lock __hidden;
769 extern struct umutex _rwlock_static_lock __hidden;
770 extern struct umutex _keytable_lock __hidden;
771 extern struct urwlock _thr_list_lock __hidden;
772 extern struct umutex _thr_event_lock __hidden;
773 extern struct umutex _suspend_all_lock __hidden;
774 extern int _suspend_all_waiters __hidden;
775 extern int _suspend_all_cycle __hidden;
776 extern struct pthread *_single_thread __hidden;
779 * Function prototype definitions.
782 void _thr_setthreaded(int) __hidden;
783 int _mutex_cv_lock(struct pthread_mutex *, int, bool) __hidden;
784 int _mutex_cv_unlock(struct pthread_mutex *, int *, int *) __hidden;
785 int _mutex_cv_attach(struct pthread_mutex *, int) __hidden;
786 int _mutex_cv_detach(struct pthread_mutex *, int *) __hidden;
787 int _mutex_owned(struct pthread *, const struct pthread_mutex *) __hidden;
788 int _mutex_reinit(pthread_mutex_t *) __hidden;
789 void _mutex_fork(struct pthread *curthread) __hidden;
790 int _mutex_enter_robust(struct pthread *curthread, struct pthread_mutex *m)
792 void _mutex_leave_robust(struct pthread *curthread, struct pthread_mutex *m)
794 void _libpthread_init(struct pthread *) __hidden;
795 struct pthread *_thr_alloc(struct pthread *) __hidden;
796 void _thread_exit(const char *, int, const char *) __hidden __dead2;
797 void _thread_exitf(const char *, int, const char *, ...) __hidden __dead2
799 int _thr_ref_add(struct pthread *, struct pthread *, int) __hidden;
800 void _thr_ref_delete(struct pthread *, struct pthread *) __hidden;
801 void _thr_ref_delete_unlocked(struct pthread *, struct pthread *) __hidden;
802 int _thr_find_thread(struct pthread *, struct pthread *, int) __hidden;
803 void _thr_rtld_init(void) __hidden;
804 void _thr_rtld_postfork_child(void) __hidden;
805 int _thr_stack_alloc(struct pthread_attr *) __hidden;
806 void _thr_stack_free(struct pthread_attr *) __hidden;
807 void _thr_free(struct pthread *, struct pthread *) __hidden;
808 void _thr_gc(struct pthread *) __hidden;
809 void _thread_cleanupspecific(void) __hidden;
810 void _thread_printf(int, const char *, ...) __hidden __printflike(2, 3);
811 void _thread_vprintf(int, const char *, va_list) __hidden;
812 void _thr_spinlock_init(void) __hidden;
813 void _thr_cancel_enter(struct pthread *) __hidden;
814 void _thr_cancel_enter2(struct pthread *, int) __hidden;
815 void _thr_cancel_leave(struct pthread *, int) __hidden;
816 void _thr_testcancel(struct pthread *) __hidden;
817 void _thr_signal_block(struct pthread *) __hidden;
818 void _thr_signal_unblock(struct pthread *) __hidden;
819 void _thr_signal_block_check_fast(void) __hidden;
820 void _thr_signal_block_setup(struct pthread *) __hidden;
821 void _thr_signal_init(int) __hidden;
822 void _thr_signal_deinit(void) __hidden;
823 int _thr_send_sig(struct pthread *, int sig) __hidden;
824 void _thr_list_init(void) __hidden;
825 void _thr_hash_add(struct pthread *) __hidden;
826 void _thr_hash_remove(struct pthread *) __hidden;
827 struct pthread *_thr_hash_find(struct pthread *) __hidden;
828 void _thr_link(struct pthread *, struct pthread *) __hidden;
829 void _thr_unlink(struct pthread *, struct pthread *) __hidden;
830 void _thr_assert_lock_level(void) __hidden __dead2;
831 void _thr_ast(struct pthread *) __hidden;
832 void _thr_report_creation(struct pthread *curthread,
833 struct pthread *newthread) __hidden;
834 void _thr_report_death(struct pthread *curthread) __hidden;
835 int _thr_getscheduler(lwpid_t, int *, struct sched_param *) __hidden;
836 int _thr_setscheduler(lwpid_t, int, const struct sched_param *) __hidden;
837 void _thr_signal_prefork(void) __hidden;
838 void _thr_signal_postfork(void) __hidden;
839 void _thr_signal_postfork_child(void) __hidden;
840 void _thr_suspend_all_lock(struct pthread *) __hidden;
841 void _thr_suspend_all_unlock(struct pthread *) __hidden;
842 void _thr_try_gc(struct pthread *, struct pthread *) __hidden;
843 int _rtp_to_schedparam(const struct rtprio *rtp, int *policy,
844 struct sched_param *param) __hidden;
845 int _schedparam_to_rtp(int policy, const struct sched_param *param,
846 struct rtprio *rtp) __hidden;
847 void _thread_bp_create(void);
848 void _thread_bp_death(void);
849 int _sched_yield(void);
851 void _pthread_cleanup_push(void (*)(void *), void *);
852 void _pthread_cleanup_pop(int);
853 void _pthread_exit_mask(void *status, sigset_t *mask) __dead2 __hidden;
854 #ifndef _LIBC_PRIVATE_H_
855 void _pthread_cancel_enter(int maycancel);
856 void _pthread_cancel_leave(int maycancel);
858 int _pthread_mutex_consistent(pthread_mutex_t * _Nonnull);
859 int _pthread_mutexattr_getrobust(pthread_mutexattr_t * _Nonnull __restrict,
860 int * _Nonnull __restrict);
861 int _pthread_mutexattr_setrobust(pthread_mutexattr_t * _Nonnull, int);
863 /* #include <fcntl.h> */
865 #ifndef _LIBC_PRIVATE_H_
866 int __sys_fcntl(int, int, ...);
867 int __sys_openat(int, const char *, int, ...);
868 #endif /* _LIBC_PRIVATE_H_ */
869 #endif /* _SYS_FCNTL_H_ */
871 /* #include <signal.h> */
873 #ifndef _LIBC_PRIVATE_H_
874 int __sys_sigaction(int, const struct sigaction *, struct sigaction *);
875 int __sys_sigprocmask(int, const sigset_t *, sigset_t *);
876 int __sys_sigsuspend(const sigset_t *);
877 int __sys_sigtimedwait(const sigset_t *, siginfo_t *,
878 const struct timespec *);
879 int __sys_sigwait(const sigset_t *, int *);
880 int __sys_sigwaitinfo(const sigset_t *set, siginfo_t *info);
881 #endif /* _LIBC_PRIVATE_H_ */
882 #endif /* _SYS_FCNTL_H_ */
884 /* #include <time.h> */
886 #ifndef _LIBC_PRIVATE_H_
887 int __sys_clock_nanosleep(clockid_t, int, const struct timespec *,
889 int __sys_nanosleep(const struct timespec *, struct timespec *);
890 #endif /* _LIBC_PRIVATE_H_ */
891 #endif /* _SYS_FCNTL_H_ */
893 /* #include <sys/ucontext.h> */
894 #ifdef _SYS_UCONTEXT_H_
895 #ifndef _LIBC_PRIVATE_H_
896 int __sys_setcontext(const ucontext_t *ucp);
897 int __sys_swapcontext(ucontext_t *oucp, const ucontext_t *ucp);
898 #endif /* _LIBC_PRIVATE_H_ */
899 #endif /* _SYS_FCNTL_H_ */
901 /* #include <unistd.h> */
903 #ifndef _LIBC_PRIVATE_H_
904 int __sys_close(int);
905 int __sys_fork(void);
906 ssize_t __sys_read(int, void *, size_t);
907 #endif /* _LIBC_PRIVATE_H_ */
908 #endif /* _SYS_FCNTL_H_ */
911 _thr_isthreaded(void)
913 return (__isthreaded != 0);
919 return (_thr_initial != NULL);
923 _thr_check_init(void)
925 if (_thr_initial == NULL)
926 _libpthread_init(NULL);
929 struct wake_addr *_thr_alloc_wake_addr(void);
930 void _thr_release_wake_addr(struct wake_addr *);
931 int _thr_sleep(struct pthread *, int, const struct timespec *);
933 void _thr_wake_addr_init(void) __hidden;
936 _thr_clear_wake(struct pthread *td)
938 td->wake_addr->value = 0;
942 _thr_is_woken(struct pthread *td)
944 return td->wake_addr->value != 0;
948 _thr_set_wake(unsigned int *waddr)
951 _thr_umtx_wake(waddr, INT_MAX, 0);
954 void _thr_wake_all(unsigned int *waddrs[], int) __hidden;
956 static inline struct pthread *
957 _sleepq_first(struct sleepqueue *sq)
959 return TAILQ_FIRST(&sq->sq_blocked);
962 void _sleepq_init(void) __hidden;
963 struct sleepqueue *_sleepq_alloc(void) __hidden;
964 void _sleepq_free(struct sleepqueue *) __hidden;
965 void _sleepq_lock(void *) __hidden;
966 void _sleepq_unlock(void *) __hidden;
967 struct sleepqueue *_sleepq_lookup(void *) __hidden;
968 void _sleepq_add(void *, struct pthread *) __hidden;
969 int _sleepq_remove(struct sleepqueue *, struct pthread *) __hidden;
970 void _sleepq_drop(struct sleepqueue *,
971 void (*cb)(struct pthread *, void *arg), void *) __hidden;
973 int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
974 void *(calloc_cb)(size_t, size_t));
977 void __pthread_cxa_finalize(struct dl_phdr_info *phdr_info);
978 void _thr_tsd_unload(struct dl_phdr_info *phdr_info) __hidden;
979 void _thr_sigact_unload(struct dl_phdr_info *phdr_info) __hidden;
980 void _thr_stack_fix_protection(struct pthread *thrd);
981 void __pthread_distribute_static_tls(size_t offset, void *src, size_t len,
984 int *__error_threaded(void) __hidden;
985 void __thr_interpose_libc(void) __hidden;
986 pid_t __thr_fork(void);
987 int __thr_setcontext(const ucontext_t *ucp);
988 int __thr_sigaction(int sig, const struct sigaction *act,
989 struct sigaction *oact) __hidden;
990 int __thr_sigprocmask(int how, const sigset_t *set, sigset_t *oset);
991 int __thr_sigsuspend(const sigset_t * set);
992 int __thr_sigtimedwait(const sigset_t *set, siginfo_t *info,
993 const struct timespec * timeout);
994 int __thr_sigwait(const sigset_t *set, int *sig);
995 int __thr_sigwaitinfo(const sigset_t *set, siginfo_t *info);
996 int __thr_swapcontext(ucontext_t *oucp, const ucontext_t *ucp);
998 void __thr_map_stacks_exec(void);
1001 void __thr_spinunlock(struct _spinlock *lck);
1002 void __thr_spinlock(struct _spinlock *lck);
1004 struct tcb *_tcb_ctor(struct pthread *, int);
1005 void _tcb_dtor(struct tcb *);
1007 void __thr_pshared_init(void) __hidden;
1008 void *__thr_pshared_offpage(void *key, int doalloc) __hidden;
1009 void __thr_pshared_destroy(void *key) __hidden;
1010 void __thr_pshared_atfork_pre(void) __hidden;
1011 void __thr_pshared_atfork_post(void) __hidden;
1013 void *__thr_calloc(size_t num, size_t size);
1014 void __thr_free(void *cp);
1015 void *__thr_malloc(size_t nbytes);
1016 void *__thr_realloc(void *cp, size_t nbytes);
1017 void __thr_malloc_init(void);
1018 void __thr_malloc_prefork(struct pthread *curthread);
1019 void __thr_malloc_postfork(struct pthread *curthread);
1021 int _thr_join(pthread_t, void **);
1022 int _Tthr_kill(pthread_t, int);
1023 int _thr_getthreadid_np(void);
1024 void __thr_cleanup_push_imp(void (*)(void *), void *,
1025 struct _pthread_cleanup_info *);
1026 void __thr_cleanup_pop_imp(int);
1027 void _thr_cleanup_push(void (*)(void *), void *);
1028 void _thr_cleanup_pop(int);
1029 void _Tthr_testcancel(void);
1030 void _Tthr_cancel_enter(int);
1031 void _Tthr_cancel_leave(int);
1032 int _thr_cancel(pthread_t);
1033 int _thr_atfork(void (*)(void), void (*)(void), void (*)(void));
1034 int _thr_attr_destroy(pthread_attr_t *);
1035 int _thr_attr_get_np(pthread_t, pthread_attr_t *);
1036 int _thr_attr_getdetachstate(const pthread_attr_t *, int *);
1037 int _thr_attr_getguardsize(const pthread_attr_t * __restrict,
1038 size_t * __restrict);
1039 int _thr_attr_getinheritsched(const pthread_attr_t * __restrict,
1041 int _thr_attr_getschedparam(const pthread_attr_t * __restrict,
1042 struct sched_param * __restrict);
1043 int _thr_attr_getschedpolicy(const pthread_attr_t * __restrict,
1045 int _thr_attr_getscope(const pthread_attr_t * __restrict, int * __restrict);
1046 int _thr_attr_getstackaddr(const pthread_attr_t *, void **);
1047 int _thr_attr_getstacksize(const pthread_attr_t * __restrict,
1048 size_t * __restrict);
1049 int _thr_attr_init(pthread_attr_t *);
1050 int _thr_attr_setdetachstate(pthread_attr_t *, int);
1051 int _thr_attr_setguardsize(pthread_attr_t *, size_t);
1052 int _thr_attr_setinheritsched(pthread_attr_t *, int);
1053 int _thr_attr_setschedparam(pthread_attr_t * __restrict,
1054 const struct sched_param * __restrict);
1055 int _thr_attr_setschedpolicy(pthread_attr_t *, int);
1056 int _thr_attr_setscope(pthread_attr_t *, int);
1057 int _thr_attr_setstackaddr(pthread_attr_t *, void *);
1058 int _thr_attr_setstacksize(pthread_attr_t *, size_t);
1059 int _thr_cond_init(pthread_cond_t * __restrict,
1060 const pthread_condattr_t * __restrict);
1061 int _thr_cond_destroy(pthread_cond_t *);
1062 int _thr_cond_timedwait(pthread_cond_t * __restrict,
1063 pthread_mutex_t * __restrict, const struct timespec * __restrict);
1064 int _thr_cond_signal(pthread_cond_t * cond);
1065 int _thr_cond_broadcast(pthread_cond_t * cond);
1066 int __thr_cond_wait(pthread_cond_t *, pthread_mutex_t *);
1067 int _thr_cond_wait(pthread_cond_t *, pthread_mutex_t *);
1068 int _thr_detach(pthread_t);
1069 int _thr_equal(pthread_t, pthread_t);
1070 void _Tthr_exit(void *);
1071 int _thr_key_create(pthread_key_t *, void (*)(void *));
1072 int _thr_key_delete(pthread_key_t);
1073 int _thr_setspecific(pthread_key_t, const void *);
1074 void *_thr_getspecific(pthread_key_t);
1075 int _thr_setcancelstate(int, int *);
1076 int _thr_setcanceltype(int, int *);
1077 pthread_t _Tthr_self(void);
1078 int _thr_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *);
1079 int _thr_rwlock_destroy(pthread_rwlock_t *);
1080 int _Tthr_rwlock_rdlock(pthread_rwlock_t *);
1081 int _Tthr_rwlock_tryrdlock(pthread_rwlock_t *);
1082 int _Tthr_rwlock_trywrlock(pthread_rwlock_t *);
1083 int _Tthr_rwlock_wrlock(pthread_rwlock_t *);
1084 int _Tthr_rwlock_unlock(pthread_rwlock_t *);
1085 int _thr_once(pthread_once_t *, void (*)(void));
1086 int _thr_sigmask(int, const sigset_t *, sigset_t *);
1087 int _thr_main_np(void);
1088 int _thr_mutexattr_init(pthread_mutexattr_t *);
1089 int _thr_mutexattr_destroy(pthread_mutexattr_t *);
1090 int _thr_mutexattr_settype(pthread_mutexattr_t *, int);
1091 int _thr_mutexattr_getrobust(pthread_mutexattr_t *, int *);
1092 int _thr_mutexattr_setrobust(pthread_mutexattr_t *, int);
1093 int __Tthr_mutex_init(pthread_mutex_t * __restrict,
1094 const pthread_mutexattr_t * __restrict);
1095 int _Tthr_mutex_consistent(pthread_mutex_t *);
1096 int _thr_mutex_destroy(pthread_mutex_t *);
1097 int _thr_mutex_unlock(pthread_mutex_t *);
1098 int __Tthr_mutex_lock(pthread_mutex_t *);
1099 int __Tthr_mutex_trylock(pthread_mutex_t *);
1102 __NULLABILITY_PRAGMA_POP
1104 #endif /* !_THR_PRIVATE_H */