thr_private.h revision 212630
1/* 2 * Copyright (C) 2005 Daniel M. Eischen <deischen@freebsd.org> 3 * Copyright (c) 2005 David Xu <davidxu@freebsd.org> 4 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>. 5 * 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice unmodified, this list of conditions, and the following 13 * disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 * $FreeBSD: head/lib/libthr/thread/thr_private.h 212630 2010-09-15 02:56:32Z davidxu $ 30 */ 31 32#ifndef _THR_PRIVATE_H 33#define _THR_PRIVATE_H 34 35/* 36 * Include files. 37 */ 38#include <sys/types.h> 39#include <sys/time.h> 40#include <sys/cdefs.h> 41#include <sys/queue.h> 42#include <sys/param.h> 43#include <sys/cpuset.h> 44#include <machine/atomic.h> 45#include <errno.h> 46#include <limits.h> 47#include <signal.h> 48#include <stddef.h> 49#include <stdio.h> 50#include <unistd.h> 51#include <ucontext.h> 52#include <sys/thr.h> 53#include <pthread.h> 54 55#define SYM_FB10(sym) __CONCAT(sym, _fb10) 56#define SYM_FBP10(sym) __CONCAT(sym, _fbp10) 57#define WEAK_REF(sym, alias) __weak_reference(sym, alias) 58#define SYM_COMPAT(sym, impl, ver) __sym_compat(sym, impl, ver) 59#define SYM_DEFAULT(sym, impl, ver) __sym_default(sym, impl, ver) 60 61#define FB10_COMPAT(func, sym) \ 62 WEAK_REF(func, SYM_FB10(sym)); \ 63 SYM_COMPAT(sym, SYM_FB10(sym), FBSD_1.0) 64 65#define FB10_COMPAT_PRIVATE(func, sym) \ 66 WEAK_REF(func, SYM_FBP10(sym)); \ 67 SYM_DEFAULT(sym, SYM_FBP10(sym), FBSDprivate_1.0) 68 69#include "pthread_md.h" 70#include "thr_umtx.h" 71#include "thread_db.h" 72 73#ifdef _PTHREAD_FORCED_UNWIND 74#include <unwind-generic.h> 75#endif 76 77typedef TAILQ_HEAD(pthreadlist, pthread) pthreadlist; 78typedef TAILQ_HEAD(atfork_head, pthread_atfork) atfork_head; 79TAILQ_HEAD(mutex_queue, pthread_mutex); 80 81/* Signal to do cancellation */ 82#define SIGCANCEL 32 83 84/* 85 * Kernel fatal error handler macro. 86 */ 87#define PANIC(string) _thread_exit(__FILE__,__LINE__,string) 88 89/* Output debug messages like this: */ 90#define stdout_debug(args...) _thread_printf(STDOUT_FILENO, ##args) 91#define stderr_debug(args...) _thread_printf(STDERR_FILENO, ##args) 92 93#ifdef _PTHREADS_INVARIANTS 94#define THR_ASSERT(cond, msg) do { \ 95 if (__predict_false(!(cond))) \ 96 PANIC(msg); \ 97} while (0) 98#else 99#define THR_ASSERT(cond, msg) 100#endif 101 102#ifdef PIC 103# define STATIC_LIB_REQUIRE(name) 104#else 105# define STATIC_LIB_REQUIRE(name) __asm (".globl " #name) 106#endif 107 108#define TIMESPEC_ADD(dst, src, val) \ 109 do { \ 110 (dst)->tv_sec = (src)->tv_sec + (val)->tv_sec; \ 111 (dst)->tv_nsec = (src)->tv_nsec + (val)->tv_nsec; \ 112 if ((dst)->tv_nsec >= 1000000000) { \ 113 (dst)->tv_sec++; \ 114 (dst)->tv_nsec -= 1000000000; \ 115 } \ 116 } while (0) 117 118#define TIMESPEC_SUB(dst, src, val) \ 119 do { \ 120 (dst)->tv_sec = (src)->tv_sec - (val)->tv_sec; \ 121 (dst)->tv_nsec = (src)->tv_nsec - (val)->tv_nsec; \ 122 if ((dst)->tv_nsec < 0) { \ 123 (dst)->tv_sec--; \ 124 (dst)->tv_nsec += 1000000000; \ 125 } \ 126 } while (0) 127 128struct pthread_mutex { 129 /* 130 * Lock for accesses to this structure. 131 */ 132 struct umutex m_lock; 133 enum pthread_mutextype m_type; 134 struct pthread *m_owner; 135 int m_count; 136 int m_refcount; 137 int m_spinloops; 138 int m_yieldloops; 139 int m_private; 140 /* 141 * Link for all mutexes a thread currently owns. 142 */ 143 TAILQ_ENTRY(pthread_mutex) m_qe; 144}; 145 146struct pthread_mutex_attr { 147 enum pthread_mutextype m_type; 148 int m_protocol; 149 int m_ceiling; 150}; 151 152#define PTHREAD_MUTEXATTR_STATIC_INITIALIZER \ 153 { PTHREAD_MUTEX_DEFAULT, PTHREAD_PRIO_NONE, 0, MUTEX_FLAGS_PRIVATE } 154 155struct pthread_cond { 156 struct umutex c_lock; 157 struct ucond c_kerncv; 158 int c_pshared; 159 int c_clockid; 160}; 161 162struct pthread_cond_attr { 163 int c_pshared; 164 int c_clockid; 165}; 166 167struct pthread_barrier { 168 struct umutex b_lock; 169 struct ucond b_cv; 170 volatile int64_t b_cycle; 171 volatile int b_count; 172 volatile int b_waiters; 173}; 174 175struct pthread_barrierattr { 176 int pshared; 177}; 178 179struct pthread_spinlock { 180 struct umutex s_lock; 181}; 182 183/* 184 * Flags for condition variables. 185 */ 186#define COND_FLAGS_PRIVATE 0x01 187#define COND_FLAGS_INITED 0x02 188#define COND_FLAGS_BUSY 0x04 189 190/* 191 * Cleanup definitions. 192 */ 193struct pthread_cleanup { 194 struct pthread_cleanup *prev; 195 void (*routine)(void *); 196 void *routine_arg; 197 int onheap; 198}; 199 200#define THR_CLEANUP_PUSH(td, func, arg) { \ 201 struct pthread_cleanup __cup; \ 202 \ 203 __cup.routine = func; \ 204 __cup.routine_arg = arg; \ 205 __cup.onheap = 0; \ 206 __cup.prev = (td)->cleanup; \ 207 (td)->cleanup = &__cup; 208 209#define THR_CLEANUP_POP(td, exec) \ 210 (td)->cleanup = __cup.prev; \ 211 if ((exec) != 0) \ 212 __cup.routine(__cup.routine_arg); \ 213} 214 215struct pthread_atfork { 216 TAILQ_ENTRY(pthread_atfork) qe; 217 void (*prepare)(void); 218 void (*parent)(void); 219 void (*child)(void); 220}; 221 222struct pthread_attr { 223 int sched_policy; 224 int sched_inherit; 225 int prio; 226 int suspend; 227#define THR_STACK_USER 0x100 /* 0xFF reserved for <pthread.h> */ 228 int flags; 229 void *stackaddr_attr; 230 size_t stacksize_attr; 231 size_t guardsize_attr; 232 cpuset_t *cpuset; 233 size_t cpusetsize; 234}; 235 236/* 237 * Thread creation state attributes. 238 */ 239#define THR_CREATE_RUNNING 0 240#define THR_CREATE_SUSPENDED 1 241 242/* 243 * Miscellaneous definitions. 244 */ 245#define THR_STACK_DEFAULT (sizeof(void *) / 4 * 1024 * 1024) 246 247/* 248 * Maximum size of initial thread's stack. This perhaps deserves to be larger 249 * than the stacks of other threads, since many applications are likely to run 250 * almost entirely on this stack. 251 */ 252#define THR_STACK_INITIAL (THR_STACK_DEFAULT * 2) 253 254/* 255 * Define priorities returned by kernel. 256 */ 257#define THR_MIN_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_min) 258#define THR_MAX_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_max) 259#define THR_DEF_PRIORITY (_thr_priorities[SCHED_OTHER-1].pri_default) 260 261#define THR_MIN_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_min) 262#define THR_MAX_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_max) 263#define THR_DEF_RR_PRIORITY (_thr_priorities[SCHED_RR-1].pri_default) 264 265/* XXX The SCHED_FIFO should have same priority range as SCHED_RR */ 266#define THR_MIN_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO_1].pri_min) 267#define THR_MAX_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_max) 268#define THR_DEF_FIFO_PRIORITY (_thr_priorities[SCHED_FIFO-1].pri_default) 269 270struct pthread_prio { 271 int pri_min; 272 int pri_max; 273 int pri_default; 274}; 275 276struct pthread_rwlockattr { 277 int pshared; 278}; 279 280struct pthread_rwlock { 281 struct urwlock lock; 282 struct pthread *owner; 283}; 284 285/* 286 * Thread states. 287 */ 288enum pthread_state { 289 PS_RUNNING, 290 PS_DEAD 291}; 292 293struct pthread_specific_elem { 294 const void *data; 295 int seqno; 296}; 297 298struct pthread_key { 299 volatile int allocated; 300 int seqno; 301 void (*destructor)(void *); 302}; 303 304/* 305 * lwpid_t is 32bit but kernel thr API exports tid as long type 306 * in very earily date. 307 */ 308#define TID(thread) ((uint32_t) ((thread)->tid)) 309 310/* 311 * Thread structure. 312 */ 313struct pthread { 314 /* Kernel thread id. */ 315 long tid; 316#define TID_TERMINATED 1 317 318 /* 319 * Lock for accesses to this thread structure. 320 */ 321 struct umutex lock; 322 323 /* Internal condition variable cycle number. */ 324 uint32_t cycle; 325 326 /* How many low level locks the thread held. */ 327 int locklevel; 328 329 /* 330 * Set to non-zero when this thread has entered a critical 331 * region. We allow for recursive entries into critical regions. 332 */ 333 int critical_count; 334 335 /* Signal blocked counter. */ 336 int sigblock; 337 338 /* Queue entry for list of all threads. */ 339 TAILQ_ENTRY(pthread) tle; /* link for all threads in process */ 340 341 /* Queue entry for GC lists. */ 342 TAILQ_ENTRY(pthread) gcle; 343 344 /* Hash queue entry. */ 345 LIST_ENTRY(pthread) hle; 346 347 /* Threads reference count. */ 348 int refcount; 349 350 /* 351 * Thread start routine, argument, stack pointer and thread 352 * attributes. 353 */ 354 void *(*start_routine)(void *); 355 void *arg; 356 struct pthread_attr attr; 357 358#define SHOULD_CANCEL(thr) \ 359 ((thr)->cancel_pending && \ 360 ((thr)->cancel_point || (thr)->cancel_async) && \ 361 (thr)->cancel_enable && (thr)->cancelling == 0) 362 363 /* Cancellation is enabled */ 364 int cancel_enable; 365 366 /* Cancellation request is pending */ 367 int cancel_pending; 368 369 /* Thread is at cancellation point */ 370 int cancel_point; 371 372 /* Cancellation should be synchoronized */ 373 int cancel_defer; 374 375 /* Asynchronouse cancellation is enabled */ 376 int cancel_async; 377 378 /* Cancellation is in progress */ 379 int cancelling; 380 381 /* Thread temporary signal mask. */ 382 sigset_t sigmask; 383 384 /* Thread should unblock SIGCANCEL. */ 385 int unblock_sigcancel; 386 387 /* In sigsuspend state */ 388 int in_sigsuspend; 389 390 /* deferred signal info */ 391 siginfo_t deferred_siginfo; 392 393 /* signal mask to restore. */ 394 sigset_t deferred_sigmask; 395 396 /* the sigaction should be used for deferred signal. */ 397 struct sigaction deferred_sigact; 398 399 /* Force new thread to exit. */ 400 int force_exit; 401 402 /* Thread state: */ 403 enum pthread_state state; 404 405 /* 406 * Error variable used instead of errno. The function __error() 407 * returns a pointer to this. 408 */ 409 int error; 410 411 /* 412 * The joiner is the thread that is joining to this thread. The 413 * join status keeps track of a join operation to another thread. 414 */ 415 struct pthread *joiner; 416 417 /* Miscellaneous flags; only set with scheduling lock held. */ 418 int flags; 419#define THR_FLAGS_PRIVATE 0x0001 420#define THR_FLAGS_NEED_SUSPEND 0x0002 /* thread should be suspended */ 421#define THR_FLAGS_SUSPENDED 0x0004 /* thread is suspended */ 422#define THR_FLAGS_DETACHED 0x0008 /* thread is detached */ 423 424 /* Thread list flags; only set with thread list lock held. */ 425 int tlflags; 426#define TLFLAGS_GC_SAFE 0x0001 /* thread safe for cleaning */ 427#define TLFLAGS_IN_TDLIST 0x0002 /* thread in all thread list */ 428#define TLFLAGS_IN_GCLIST 0x0004 /* thread in gc list */ 429 430 /* Queue of currently owned NORMAL or PRIO_INHERIT type mutexes. */ 431 struct mutex_queue mutexq; 432 433 /* Queue of all owned PRIO_PROTECT mutexes. */ 434 struct mutex_queue pp_mutexq; 435 436 void *ret; 437 struct pthread_specific_elem *specific; 438 int specific_data_count; 439 440 /* Number rwlocks rdlocks held. */ 441 int rdlock_count; 442 443 /* 444 * Current locks bitmap for rtld. */ 445 int rtld_bits; 446 447 /* Thread control block */ 448 struct tcb *tcb; 449 450 /* Cleanup handlers Link List */ 451 struct pthread_cleanup *cleanup; 452 453#ifdef _PTHREAD_FORCED_UNWIND 454 struct _Unwind_Exception ex; 455 void *unwind_stackend; 456#endif 457 458 /* 459 * Magic value to help recognize a valid thread structure 460 * from an invalid one: 461 */ 462#define THR_MAGIC ((u_int32_t) 0xd09ba115) 463 u_int32_t magic; 464 465 /* Enable event reporting */ 466 int report_events; 467 468 /* Event mask */ 469 int event_mask; 470 471 /* Event */ 472 td_event_msg_t event_buf; 473}; 474 475#define THR_SHOULD_GC(thrd) \ 476 ((thrd)->refcount == 0 && (thrd)->state == PS_DEAD && \ 477 ((thrd)->flags & THR_FLAGS_DETACHED) != 0) 478 479#define THR_IN_CRITICAL(thrd) \ 480 (((thrd)->locklevel > 0) || \ 481 ((thrd)->critical_count > 0)) 482 483#define THR_CRITICAL_ENTER(thrd) \ 484 (thrd)->critical_count++ 485 486#define THR_CRITICAL_LEAVE(thrd) \ 487 do { \ 488 (thrd)->critical_count--; \ 489 _thr_ast(thrd); \ 490 } while (0) 491 492#define THR_UMUTEX_TRYLOCK(thrd, lck) \ 493 _thr_umutex_trylock((lck), TID(thrd)) 494 495#define THR_UMUTEX_LOCK(thrd, lck) \ 496 _thr_umutex_lock((lck), TID(thrd)) 497 498#define THR_UMUTEX_TIMEDLOCK(thrd, lck, timo) \ 499 _thr_umutex_timedlock((lck), TID(thrd), (timo)) 500 501#define THR_UMUTEX_UNLOCK(thrd, lck) \ 502 _thr_umutex_unlock((lck), TID(thrd)) 503 504#define THR_LOCK_ACQUIRE(thrd, lck) \ 505do { \ 506 (thrd)->locklevel++; \ 507 _thr_umutex_lock(lck, TID(thrd)); \ 508} while (0) 509 510#ifdef _PTHREADS_INVARIANTS 511#define THR_ASSERT_LOCKLEVEL(thrd) \ 512do { \ 513 if (__predict_false((thrd)->locklevel <= 0)) \ 514 _thr_assert_lock_level(); \ 515} while (0) 516#else 517#define THR_ASSERT_LOCKLEVEL(thrd) 518#endif 519 520#define THR_LOCK_RELEASE(thrd, lck) \ 521do { \ 522 THR_ASSERT_LOCKLEVEL(thrd); \ 523 _thr_umutex_unlock((lck), TID(thrd)); \ 524 (thrd)->locklevel--; \ 525 _thr_ast(thrd); \ 526} while (0) 527 528#define THR_LOCK(curthrd) THR_LOCK_ACQUIRE(curthrd, &(curthrd)->lock) 529#define THR_UNLOCK(curthrd) THR_LOCK_RELEASE(curthrd, &(curthrd)->lock) 530#define THR_THREAD_LOCK(curthrd, thr) THR_LOCK_ACQUIRE(curthrd, &(thr)->lock) 531#define THR_THREAD_UNLOCK(curthrd, thr) THR_LOCK_RELEASE(curthrd, &(thr)->lock) 532 533#define THREAD_LIST_RDLOCK(curthrd) \ 534do { \ 535 (curthrd)->locklevel++; \ 536 _thr_rwl_rdlock(&_thr_list_lock); \ 537} while (0) 538 539#define THREAD_LIST_WRLOCK(curthrd) \ 540do { \ 541 (curthrd)->locklevel++; \ 542 _thr_rwl_wrlock(&_thr_list_lock); \ 543} while (0) 544 545#define THREAD_LIST_UNLOCK(curthrd) \ 546do { \ 547 _thr_rwl_unlock(&_thr_list_lock); \ 548 (curthrd)->locklevel--; \ 549 _thr_ast(curthrd); \ 550} while (0) 551 552/* 553 * Macros to insert/remove threads to the all thread list and 554 * the gc list. 555 */ 556#define THR_LIST_ADD(thrd) do { \ 557 if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) == 0) { \ 558 TAILQ_INSERT_HEAD(&_thread_list, thrd, tle); \ 559 _thr_hash_add(thrd); \ 560 (thrd)->tlflags |= TLFLAGS_IN_TDLIST; \ 561 } \ 562} while (0) 563#define THR_LIST_REMOVE(thrd) do { \ 564 if (((thrd)->tlflags & TLFLAGS_IN_TDLIST) != 0) { \ 565 TAILQ_REMOVE(&_thread_list, thrd, tle); \ 566 _thr_hash_remove(thrd); \ 567 (thrd)->tlflags &= ~TLFLAGS_IN_TDLIST; \ 568 } \ 569} while (0) 570#define THR_GCLIST_ADD(thrd) do { \ 571 if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) == 0) { \ 572 TAILQ_INSERT_HEAD(&_thread_gc_list, thrd, gcle);\ 573 (thrd)->tlflags |= TLFLAGS_IN_GCLIST; \ 574 _gc_count++; \ 575 } \ 576} while (0) 577#define THR_GCLIST_REMOVE(thrd) do { \ 578 if (((thrd)->tlflags & TLFLAGS_IN_GCLIST) != 0) { \ 579 TAILQ_REMOVE(&_thread_gc_list, thrd, gcle); \ 580 (thrd)->tlflags &= ~TLFLAGS_IN_GCLIST; \ 581 _gc_count--; \ 582 } \ 583} while (0) 584 585#define THR_REF_ADD(curthread, pthread) { \ 586 THR_CRITICAL_ENTER(curthread); \ 587 pthread->refcount++; \ 588} while (0) 589 590#define THR_REF_DEL(curthread, pthread) { \ 591 pthread->refcount--; \ 592 THR_CRITICAL_LEAVE(curthread); \ 593} while (0) 594 595#define GC_NEEDED() (_gc_count >= 5) 596 597#define SHOULD_REPORT_EVENT(curthr, e) \ 598 (curthr->report_events && \ 599 (((curthr)->event_mask | _thread_event_mask ) & e) != 0) 600 601extern int __isthreaded; 602 603/* 604 * Global variables for the pthread kernel. 605 */ 606 607extern char *_usrstack __hidden; 608extern struct pthread *_thr_initial __hidden; 609 610/* For debugger */ 611extern int _libthr_debug; 612extern int _thread_event_mask; 613extern struct pthread *_thread_last_event; 614 615/* List of all threads: */ 616extern pthreadlist _thread_list; 617 618/* List of threads needing GC: */ 619extern pthreadlist _thread_gc_list __hidden; 620 621extern int _thread_active_threads; 622extern atfork_head _thr_atfork_list __hidden; 623extern struct urwlock _thr_atfork_lock __hidden; 624 625/* Default thread attributes: */ 626extern struct pthread_attr _pthread_attr_default __hidden; 627 628/* Default mutex attributes: */ 629extern struct pthread_mutex_attr _pthread_mutexattr_default __hidden; 630 631/* Default condition variable attributes: */ 632extern struct pthread_cond_attr _pthread_condattr_default __hidden; 633 634extern struct pthread_prio _thr_priorities[] __hidden; 635 636extern pid_t _thr_pid __hidden; 637extern int _thr_is_smp __hidden; 638 639extern size_t _thr_guard_default __hidden; 640extern size_t _thr_stack_default __hidden; 641extern size_t _thr_stack_initial __hidden; 642extern int _thr_page_size __hidden; 643extern int _thr_spinloops __hidden; 644extern int _thr_yieldloops __hidden; 645 646/* Garbage thread count. */ 647extern int _gc_count __hidden; 648 649extern struct umutex _mutex_static_lock __hidden; 650extern struct umutex _cond_static_lock __hidden; 651extern struct umutex _rwlock_static_lock __hidden; 652extern struct umutex _keytable_lock __hidden; 653extern struct urwlock _thr_list_lock __hidden; 654extern struct umutex _thr_event_lock __hidden; 655 656/* 657 * Function prototype definitions. 658 */ 659__BEGIN_DECLS 660int _thr_setthreaded(int) __hidden; 661int _mutex_cv_lock(pthread_mutex_t *, int count) __hidden; 662int _mutex_cv_unlock(pthread_mutex_t *, int *count) __hidden; 663int _mutex_reinit(pthread_mutex_t *) __hidden; 664void _mutex_fork(struct pthread *curthread) __hidden; 665void _libpthread_init(struct pthread *) __hidden; 666struct pthread *_thr_alloc(struct pthread *) __hidden; 667void _thread_exit(const char *, int, const char *) __hidden __dead2; 668int _thr_ref_add(struct pthread *, struct pthread *, int) __hidden; 669void _thr_ref_delete(struct pthread *, struct pthread *) __hidden; 670void _thr_ref_delete_unlocked(struct pthread *, struct pthread *) __hidden; 671int _thr_find_thread(struct pthread *, struct pthread *, int) __hidden; 672void _thr_rtld_init(void) __hidden; 673void _thr_rtld_fini(void) __hidden; 674void _thr_rtld_postfork_child(void) __hidden; 675int _thr_stack_alloc(struct pthread_attr *) __hidden; 676void _thr_stack_free(struct pthread_attr *) __hidden; 677void _thr_free(struct pthread *, struct pthread *) __hidden; 678void _thr_gc(struct pthread *) __hidden; 679void _thread_cleanupspecific(void) __hidden; 680void _thread_printf(int, const char *, ...) __hidden; 681void _thr_spinlock_init(void) __hidden; 682void _thr_cancel_enter(struct pthread *) __hidden; 683void _thr_cancel_enter2(struct pthread *, int) __hidden; 684void _thr_cancel_leave(struct pthread *, int) __hidden; 685void _thr_testcancel(struct pthread *) __hidden; 686void _thr_signal_block(struct pthread *) __hidden; 687void _thr_signal_unblock(struct pthread *) __hidden; 688void _thr_signal_init(void) __hidden; 689void _thr_signal_deinit(void) __hidden; 690int _thr_send_sig(struct pthread *, int sig) __hidden; 691void _thr_list_init(void) __hidden; 692void _thr_hash_add(struct pthread *) __hidden; 693void _thr_hash_remove(struct pthread *) __hidden; 694struct pthread *_thr_hash_find(struct pthread *) __hidden; 695void _thr_link(struct pthread *, struct pthread *) __hidden; 696void _thr_unlink(struct pthread *, struct pthread *) __hidden; 697void _thr_assert_lock_level(void) __hidden __dead2; 698void _thr_ast(struct pthread *) __hidden; 699void _thr_once_init(void) __hidden; 700void _thr_report_creation(struct pthread *curthread, 701 struct pthread *newthread) __hidden; 702void _thr_report_death(struct pthread *curthread) __hidden; 703int _thr_getscheduler(lwpid_t, int *, struct sched_param *) __hidden; 704int _thr_setscheduler(lwpid_t, int, const struct sched_param *) __hidden; 705void _thr_signal_prefork(void) __hidden; 706void _thr_signal_postfork(void) __hidden; 707void _thr_signal_postfork_child(void) __hidden; 708void _thr_try_gc(struct pthread *, struct pthread *) __hidden; 709int _rtp_to_schedparam(const struct rtprio *rtp, int *policy, 710 struct sched_param *param) __hidden; 711int _schedparam_to_rtp(int policy, const struct sched_param *param, 712 struct rtprio *rtp) __hidden; 713void _thread_bp_create(void); 714void _thread_bp_death(void); 715int _sched_yield(void); 716 717void _pthread_cleanup_push(void (*)(void *), void *); 718void _pthread_cleanup_pop(int); 719void _pthread_exit_mask(void *status, sigset_t *mask) __dead2 __hidden; 720 721 722/* #include <fcntl.h> */ 723#ifdef _SYS_FCNTL_H_ 724int __sys_fcntl(int, int, ...); 725int __sys_open(const char *, int, ...); 726int __sys_openat(int, const char *, int, ...); 727#endif 728 729/* #include <signal.h> */ 730#ifdef _SIGNAL_H_ 731int __sys_kill(pid_t, int); 732int __sys_sigaction(int, const struct sigaction *, struct sigaction *); 733int __sys_sigpending(sigset_t *); 734int __sys_sigprocmask(int, const sigset_t *, sigset_t *); 735int __sys_sigsuspend(const sigset_t *); 736int __sys_sigreturn(const ucontext_t *); 737int __sys_sigaltstack(const struct sigaltstack *, struct sigaltstack *); 738int __sys_sigwait(const sigset_t *, int *); 739int __sys_sigtimedwait(const sigset_t *, siginfo_t *, 740 const struct timespec *); 741int __sys_sigwaitinfo(const sigset_t *set, siginfo_t *info); 742#endif 743 744/* #include <time.h> */ 745#ifdef _TIME_H_ 746int __sys_nanosleep(const struct timespec *, struct timespec *); 747#endif 748 749/* #include <sys/ucontext.h> */ 750#ifdef _SYS_UCONTEXT_H_ 751int __sys_setcontext(const ucontext_t *ucp); 752int __sys_swapcontext(ucontext_t *oucp, const ucontext_t *ucp); 753#endif 754 755/* #include <unistd.h> */ 756#ifdef _UNISTD_H_ 757int __sys_close(int); 758int __sys_fork(void); 759pid_t __sys_getpid(void); 760ssize_t __sys_read(int, void *, size_t); 761ssize_t __sys_write(int, const void *, size_t); 762void __sys_exit(int); 763#endif 764 765int _umtx_op_err(void *, int op, u_long, void *, void *) __hidden; 766 767static inline int 768_thr_isthreaded(void) 769{ 770 return (__isthreaded != 0); 771} 772 773static inline int 774_thr_is_inited(void) 775{ 776 return (_thr_initial != NULL); 777} 778 779static inline void 780_thr_check_init(void) 781{ 782 if (_thr_initial == NULL) 783 _libpthread_init(NULL); 784} 785 786struct dl_phdr_info; 787void __pthread_cxa_finalize(struct dl_phdr_info *phdr_info); 788void _thr_tsd_unload(struct dl_phdr_info *phdr_info) __hidden; 789void _thr_sigact_unload(struct dl_phdr_info *phdr_info) __hidden; 790 791__END_DECLS 792 793#endif /* !_THR_PRIVATE_H */ 794