thr_uberdata.h revision 0d045c0d0cb001d79480ee33be28514e847f8612
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* Copyright (c) 2015, Joyent, Inc.
*/
#ifndef _THR_UBERDATA_H
#define _THR_UBERDATA_H
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <signal.h>
#include <ucontext.h>
#include <thread.h>
#include <pthread.h>
#include <atomic.h>
#include <link.h>
#include <sys/resource.h>
#include <errno.h>
#include <sys/asm_linkage.h>
#include <synch.h>
#include <door.h>
#include <limits.h>
#include <schedctl.h>
#include <sys/priocntl.h>
#include <thread_db.h>
#include <setjmp.h>
#include "libc_int.h"
#include "tdb_agent.h"
#include "thr_debug.h"
/*
* This is an implementation-specific include file for threading support.
* It is not to be seen by the clients of the library.
*
* This file also describes uberdata in libc.
*
* The term "uberdata" refers to data that is unique and visible across
* all link maps. The name is meant to imply that such data is truly
* global, not just locally global to a particular link map.
*
* See the Linker and Libraries Guide for a full description of alternate
* link maps and how they are set up and used.
*
* Alternate link maps implement multiple global namespaces within a single
* process. There may be multiple instances of identical dynamic libraries
* loaded in a process's address space at the same time, each on a different
* link map (as determined by the dynamic linker), each with its own set of
* global variables. Which particular instance of a global variable is seen
* by a thread running in the process is determined by the link map on which
* the thread happens to be executing at the time.
*
* However, there are aspects of a process that are unique across all
* link maps, in particular the structures used to implement threads
* of control (in Sparc terminology, there is only one %g7 regardless
* of the link map on which the thread is executing).
*
* All uberdata is referenced from a base pointer in the thread's ulwp_t
* structure (which is also uberdata). All allocations and deallocations
* of uberdata are made via the uberdata-aware lmalloc() and lfree()
* interfaces (malloc() and free() are simply locally-global).
*/
/*
* Special libc-private access to errno.
* We do this so that references to errno do not invoke the dynamic linker.
*/
/*
* and why they are different for sparc and intel.
*/
#if defined(__sparc)
/* lock.lock64.pad[x] 4 5 6 7 */
#define LOCKMASK 0xff000000
#define WAITERMASK 0x000000ff
#define SPINNERMASK 0x00ff0000
#define SPINNERSHIFT 16
#define WAITER 0x00000001
#define LOCKSET 0xff
#define LOCKCLEAR 0
#define PIDSHIFT 32
#define LOCKMASK64 0xffffffffff000000ULL
#define LOCKBYTE64 0x00000000ff000000ULL
#define WAITERMASK64 0x00000000000000ffULL
#define SPINNERMASK64 0x0000000000ff0000ULL
/* lock.lock64.pad[x] 7 6 5 4 */
#define LOCKMASK 0xff000000
#define WAITERMASK 0x00ff0000
#define SPINNERMASK 0x0000ff00
#define SPINNERSHIFT 8
#define WAITER 0x00010000
#define LOCKSET 0x01
#define LOCKCLEAR 0
#define PIDSHIFT 0
#define LOCKMASK64 0xff000000ffffffffULL
#define LOCKBYTE64 0x0100000000000000ULL
#define WAITERMASK64 0x00ff000000000000ULL
#define SPINNERMASK64 0x0000ff0000000000ULL
#else
#error "neither __sparc nor __x86 is defined"
#endif
/*
* Fetch the owner of a USYNC_THREAD mutex.
* Don't use this with process-shared mutexes;
* the owing thread may be in a different process.
*/
/*
* Test if a thread owns a process-private (USYNC_THREAD) mutex.
* This is inappropriate for a process-shared (USYNC_PROCESS) mutex.
* The 'mp' argument must not have side-effects since it is evaluated twice.
*/
/*
* uberflags.uf_tdb_register_sync is an interface with libc_db to enable the
* collection of lock statistics by a debugger or other collecting tool.
*
* uberflags.uf_thread_error_detection is set by an environment variable:
* _THREAD_ERROR_DETECTION
* 0 == no detection of locking primitive errors.
* 1 == detect errors and issue a warning message.
* 2 == detect errors, issue a warning message, and dump core.
*
* We bundle these together in uberflags.uf_trs_ted to make a test of either
* being non-zero a single memory reference (for speed of mutex_lock(), etc).
*
* uberflags.uf_mt is set non-zero when the first thread (in addition
* to the main thread) is created.
*
* We bundle all these flags together in uberflags.uf_all to make a test
* of any being non-zero a single memory reference (again, for speed).
*/
typedef union {
int uf_all; /* combined all flags */
struct {
short h_pad;
short h_trs_ted; /* combined reg sync & error detect */
} uf_h;
struct {
char x_mt;
char x_pad;
char x_tdb_register_sync;
char x_thread_error_detection;
} uf_x;
} uberflags_t;
/*
* NOTE WELL:
* To enable further optimization, the "ul_schedctl_called" member
* of the ulwp_t structure (below) serves double-duty:
* 1. If NULL, it means that the thread must call __schedctl()
* to set up its schedctl mappings before acquiring a mutex.
* This is required by the implementation of adaptive mutex locking.
* 2. If non-NULL, it points to uberdata.uberflags, so that tests of
* uberflags can be made without additional memory references.
* This allows the common case of _mutex_lock() and _mutex_unlock() for
* USYNC_THREAD mutexes with no error detection and no lock statistics
* to be optimized for speed.
*/
/* double the default stack size for 64-bit processes */
#ifdef _LP64
#else
#endif
#define MUTEX_TRY 0
#define MUTEX_LOCK 1
#define MUTEX_NOCEIL 0x40
#if defined(__x86)
typedef struct { /* structure returned by fnstenv */
int fctrl; /* control word */
int fstat; /* status word (flags, etc) */
int ftag; /* tag of which regs busy */
} fpuenv_t;
#ifdef _SYSCALL32
typedef fpuenv_t fpuenv32_t;
#endif /* _SYSCALL32 */
typedef struct { /* fp state structure */
} fpuenv_t;
#ifdef _SYSCALL32
typedef struct {
} fpuenv32_t;
#endif /* _SYSCALL32 */
#endif /* __x86 */
#if defined(__x86)
extern void ht_pause(void); /* "pause" instruction */
#elif defined(SMT_PAUSE_FUNCTION)
extern void SMT_PAUSE_FUNCTION(void);
#define SMT_PAUSE() SMT_PAUSE_FUNCTION()
#else
#endif /* __x86 */
/*
* Cleanup handler related data.
* This structure is exported as _cleanup_t in pthread.h.
* pthread.h exports only the size of this structure, so check
* _cleanup_t in pthread.h before making any change here.
*/
typedef struct __cleanup {
void (*func)(void *); /* cleanup handler address */
void *arg; /* handler's argument */
} __cleanup_t;
/*
* Thread-Specific Data (TSD)
* TSD_NFAST includes the invalid key zero, so there
* are really only (TSD_NFAST - 1) fast key slots.
*/
typedef void (*PFrV)(void *);
#define TSD_NFAST 9
/*
* The tsd union is designed to burn a little memory (9 words) to make
* lookups blindingly fast. Note that tsd_nalloc could be placed at the
* end of the pad region to increase the likelihood that it falls on the
* same cache line as the data.
*/
typedef union tsd {
void *tsd_data[1];
} tsd_t;
typedef struct {
#ifdef _SYSCALL32
typedef union tsd32 {
} tsd32_t;
typedef struct {
#endif /* _SYSCALL32 */
/*
* Thread-Local Storage (TLS)
*/
typedef struct {
void *tls_data;
} tls_t;
typedef struct {
#ifdef _SYSCALL32
typedef struct {
} tls32_t;
typedef struct {
#endif /* _SYSCALL32 */
/*
* Sleep queue root for USYNC_THREAD condvars and mutexes.
* There is a default queue root for each queue head (see below).
* Also, each ulwp_t contains a queue root that can be used
* when the thread is enqueued on the queue, if necessary
* (when more than one wchan hashes to the same queue head).
*/
typedef struct queue_root {
struct queue_root *qr_next;
struct queue_root *qr_prev;
void *qr_wchan;
} queue_root_t;
#ifdef _SYSCALL32
typedef struct queue_root32 {
#endif
/*
* Sleep queue heads for USYNC_THREAD condvars and mutexes.
* The size and alignment is 128 bytes to reduce cache conflicts.
* Each queue head points to a list of queue roots, defined above.
* Each queue head contains a default queue root for use when only one
* is needed. It is always at the tail of the queue root hash chain.
*/
typedef union {
struct {
void *q_wchan; /* valid only while locked */
struct queue_root *q_hlist;
#if !defined(_LP64)
#endif
} qh_qh;
} queue_head_t;
#if defined(THREAD_DEBUG)
#endif
/* queue types passed to queue_lock() */
#define MX 0
#define CV 1
extern queue_head_t *queue_lock(void *, int);
extern void queue_unlock(queue_head_t *);
extern int dequeue_self(queue_head_t *);
extern void queue_unlink(queue_head_t *,
extern void unsleep_self(void);
extern void spin_lock_set(mutex_t *);
extern void spin_lock_clear(mutex_t *);
/*
* Scheduling class information structure.
*/
typedef struct {
short pcc_state;
short pcc_policy;
} pcclass_t;
/*
* Memory block for chain of owned ceiling mutexes.
*/
typedef struct mxchain {
struct mxchain *mxchain_next;
} mxchain_t;
/*
* Pointer to an rwlock that is held for reading.
* Used in rw_rdlock() to allow a thread that already holds a read
* lock to acquire another read lock on the same rwlock even if
* there are writers waiting. This to avoid deadlock when acquiring
* a read lock more than once in the presence of pending writers.
* POSIX mandates this behavior.
*/
typedef struct {
void *rd_rwlock; /* the rwlock held for reading */
} readlock_t;
#ifdef _SYSCALL32
typedef struct {
} readlock32_t;
#endif /* _SYSCALL32 */
/*
* As part of per-thread caching libumem (ptcumem), we add a small amount to the
* thread's uberdata to facilitate it. The tm_roots are the roots of linked
* lists which is used by libumem to chain together allocations. tm_size is used
* to track the total amount of data stored across those linked lists. For more
* information, see libumem's big theory statement.
*/
#define NTMEMBASE 16
typedef struct {
} tumem_t;
#ifdef _SYSCALL32
typedef struct {
} tumem32_t;
#endif
typedef void (*tmem_func_t)(void *, int);
/*
* Maximum number of read locks allowed for one thread on one rwlock.
* This could be as large as INT_MAX, but the SUSV3 test suite would
* take an inordinately long time to complete. This is big enough.
*/
#define READ_LOCK_MAX 100000
/*
* Round up an integral value to a multiple of 64
*/
#define roundup64(x) (-(-(x) & -64))
/*
* NOTE: Whatever changes are made to ulwp_t must be
*
* NOTE: ul_self *must* be the first member of ulwp_t on x86
* Low-level x86 code relies on this.
*/
typedef struct ulwp {
/*
* These members always need to come first on sparc.
* For dtrace, a ulwp_t must be aligned on a 64-byte boundary.
*/
#if defined(__sparc)
#endif
#if defined(__i386)
#endif
void *ul_rval; /* return value from thr_exit() */
int ul_ix; /* hash index */
char ul_policy; /* scheduling policy */
char ul_cid; /* scheduling class id */
union {
struct {
char cursig; /* deferred signal number */
char pleasestop; /* lwp requested to stop itself */
} s;
short curplease; /* for testing both at once */
} ul_cp;
char ul_stop; /* reason for stopping */
char ul_signalled; /* this lwp was cond_signal()d */
char ul_dead; /* this lwp has called thr_exit */
char ul_unwind; /* posix: unwind C++ stack */
char ul_detached; /* THR_DETACHED at thread_create() */
/* or pthread_detach() was called */
char ul_writer; /* sleeping in rw_wrlock() */
char ul_stopping; /* set by curthread: stopping self */
char ul_cancel_prologue; /* for _cancel_prologue() */
short ul_preempt; /* no_preempt()/preempt() */
short ul_savpreempt; /* pre-existing preempt value */
char ul_sigsuspend; /* thread is in sigsuspend/pollsys */
char ul_main; /* thread is the main thread */
char ul_fork; /* thread is performing a fork */
char ul_primarymap; /* primary link-map is initialized */
/* per-thread copies of the corresponding global variables */
char ul_door_noreserve; /* thread_door_noreserve */
char ul_queue_fifo; /* thread_queue_fifo */
char ul_cond_wait_defer; /* thread_cond_wait_defer */
char ul_error_detection; /* thread_error_detection */
char ul_async_safe; /* thread_async_safe */
char ul_rt; /* found on an RT queue */
char ul_rtqueued; /* was RT when queued */
char ul_misaligned; /* thread_locks_misaligned */
char ul_pad[3];
int ul_adaptive_spin; /* thread_adaptive_spin */
int ul_queue_spin; /* thread_queue_spin */
volatile int ul_critical; /* non-zero == in a critical region */
int ul_sigdefer; /* non-zero == defer signals */
int ul_vfork; /* thread is the child of vfork() */
int ul_cancelable; /* _cancelon()/_canceloff() */
char ul_cancel_pending; /* pthread_cancel() was called */
char ul_cancel_disabled; /* PTHREAD_CANCEL_DISABLE */
char ul_cancel_async; /* PTHREAD_CANCEL_ASYNCHRONOUS */
char ul_save_async; /* saved copy of ul_cancel_async */
char ul_mutator; /* lwp is a mutator (java interface) */
char ul_created; /* created suspended */
char ul_replace; /* replacement; must be free()d */
int ul_errno; /* per-thread errno */
int *ul_errnop; /* pointer to errno or self->ul_errno */
int ul_bindflags; /* bind_guard() interface to ld.so.1 */
char ul_td_events_enable; /* event mechanism enabled */
char ul_sync_obj_reg; /* tdb_sync_obj_register() */
char ul_qtype; /* MX or CV */
char ul_cv_wake; /* != 0: just wake up, don't requeue */
int ul_usropts; /* flags given to thr_create() */
void *(*ul_startpc)(void *); /* start func (thr_create()) */
void *ul_startarg; /* argument for start function */
void *ul_wchan; /* synch object when sleeping */
int ul_save_state; /* bind_guard() interface to ld.so.1 */
/* 0 means there is but a single entry */
union { /* single entry or pointer to array */
} ul_readlock;
/* 0 means there is but a single entry */
union { /* single entry or pointer to array */
} ul_heldlocks;
/* PROBE_SUPPORT begin */
void *ul_tpdp;
/* PROBE_SUPPORT end */
/* the following members *must* be last in the structure */
/* they are discarded when ulwp is replaced on thr_exit() */
void *ul_ex_unwind; /* address of _ex_unwind() or -1 */
#if defined(sparc)
void *ul_unwind_ret; /* used only by _ex_clnup_handler() */
#endif
} ulwp_t;
/*
* This is the size of a replacement ulwp, retained only for the benefit
* of thr_join(). The trailing members are unneeded for this purpose.
*/
/*
* Definitions for static initialization of signal sets,
* plus some sneaky optimizations in various places.
*/
#define FILLSET0 0xffffffffu
#define FILLSET1 0xffffffffu
#define FILLSET3 0
#else
#error "fix me: MAXSIG out of bounds"
#endif
#define CANTMASK1 0
#define CANTMASK2 0
#define CANTMASK3 0
extern int thread_adaptive_spin;
extern uint_t thread_max_spinners;
extern int thread_queue_spin;
extern int thread_queue_fifo;
extern int thread_queue_dump;
extern int thread_cond_wait_defer;
extern int thread_async_safe;
extern int thread_queue_verify;
/*
* pthread_atfork() related data, used to store atfork handlers.
*/
typedef struct atfork {
void (*prepare)(void); /* pre-fork handler */
void (*parent)(void); /* post-fork parent handler */
void (*child)(void); /* post-fork child handler */
} atfork_t;
/*
* Element in the table and in the list of registered process
* robust locks. We keep track of these to make sure that we
* only call ___lwp_mutex_register() once for each such lock
* after it is first mapped in (or newly mapped in).
*/
typedef struct robust {
} robust_t;
/*
* Invalid address, used to mark an unused element in the hash table.
*/
/*
* Parameters of the lock registration hash table.
*/
& (LOCKHASHSZ - 1))
/*
* Make our hot locks reside on private cache lines (64 bytes).
*/
typedef struct {
} pad_lock_t;
/*
* Make our semi-hot locks reside on semi-private cache lines (32 bytes).
*/
typedef struct {
} pad32_lock_t;
/*
* The threads hash table is used for fast lookup and locking of an active
* thread structure (ulwp_t) given a thread-id. It is an N-element array of
* thr_hash_table_t structures, where N == 1 before the main thread creates
* the first additional thread and N == 1024 afterwards. Each element of the
* table is 64 bytes in size and alignment to reduce cache conflicts.
*/
typedef struct {
#ifdef _SYSCALL32
typedef struct {
char hash_pad[64 -
#endif /* _SYSCALL32 */
/*
* siguaction members have 128-byte size and 64-byte alignment.
* We know that sizeof (struct sigaction) is 32 bytes for both
* _ILP32 and _LP64 and that sizeof (rwlock_t) is 64 bytes.
*/
typedef struct {
struct sigaction sig_uaction;
} siguaction_t;
#ifdef _SYSCALL32
typedef struct {
struct sigaction32 sig_uaction;
#endif /* _SYSCALL32 */
/*
* Bucket structures, used by lmalloc()/lfree().
* A bucket's size and alignment is 64 bytes.
*/
typedef struct {
} bucket_t;
#ifdef _SYSCALL32
typedef struct {
} bucket32_t;
#endif /* _SYSCALL32 */
/*
* atexit() data structures.
*/
typedef void (*_exithdlr_func_t) (void*);
typedef struct _exthdlr {
void *arg; /* argument to handler */
void *dso; /* DSO associated with handler */
} _exthdlr_t;
typedef struct {
/*
* exit_frame_monitor is part of a private contract between libc and
* the Sun C++ runtime.
*
* It should be NULL until exit() is called, and thereafter hold the
* frame pointer of the function implementing our exit processing.
*/
void *exit_frame_monitor;
(sizeof (mutex_t) + sizeof (_exthdlr_t *) + sizeof (void *))];
#ifdef _SYSCALL32
typedef struct {
#endif /* _SYSCALL32 */
/*
* This is data that is global to all link maps (uberdata, aka super-global).
* Note: When changing this, please be sure to keep the 32-bit variant of
* this in sync. (see uberdata32_t below)
*/
typedef struct uberdata {
/*
* Every object before this point has size and alignment of 64 bytes.
* Don't add any other type of data before this point.
*/
char primary_map; /* set when primary link map is initialized */
char bucket_init; /* set when bucket[NBUCKETS] is initialized */
char pad[2];
int nzombies; /* total number of zombie threads */
void (*sigacthandler)(int, siginfo_t *, void *);
int nfreestack;
int thread_stack_cache;
char *progname; /* the basename of the program, from argv[0] */
struct uberdata **tdb_bootstrap;
} uberdata_t;
extern uberdata_t __uberdata;
extern int primary_link_map;
/*
* Grab and release the hash table lock for the specified lwp.
*/
#ifdef _SYSCALL32 /* needed by libc_db */
typedef struct ulwp32 {
#if defined(__sparc)
#endif
#if defined(__x86)
#endif
int ul_ix; /* hash index */
char ul_policy; /* scheduling policy */
char ul_cid; /* scheduling class id */
union {
struct {
char cursig; /* deferred signal number */
char pleasestop; /* lwp requested to stop itself */
} s;
short curplease; /* for testing both at once */
} ul_cp;
char ul_stop; /* reason for stopping */
char ul_signalled; /* this lwp was cond_signal()d */
char ul_dead; /* this lwp has called thr_exit */
char ul_unwind; /* posix: unwind C++ stack */
char ul_detached; /* THR_DETACHED at thread_create() */
/* or pthread_detach() was called */
char ul_writer; /* sleeping in rw_wrlock() */
char ul_stopping; /* set by curthread: stopping self */
char ul_cancel_prologue; /* for _cancel_prologue() */
short ul_preempt; /* no_preempt()/preempt() */
short ul_savpreempt; /* pre-existing preempt value */
char ul_sigsuspend; /* thread is in sigsuspend/pollsys */
char ul_main; /* thread is the main thread */
char ul_fork; /* thread is performing a fork */
char ul_primarymap; /* primary link-map is initialized */
/* per-thread copies of the corresponding global variables */
char ul_door_noreserve; /* thread_door_noreserve */
char ul_queue_fifo; /* thread_queue_fifo */
char ul_cond_wait_defer; /* thread_cond_wait_defer */
char ul_error_detection; /* thread_error_detection */
char ul_async_safe; /* thread_async_safe */
char ul_rt; /* found on an RT queue */
char ul_rtqueued; /* was RT when queued */
char ul_misaligned; /* thread_locks_misaligned */
char ul_pad[3];
int ul_adaptive_spin; /* thread_adaptive_spin */
int ul_queue_spin; /* thread_queue_spin */
int ul_critical; /* non-zero == in a critical region */
int ul_sigdefer; /* non-zero == defer signals */
int ul_vfork; /* thread is the child of vfork() */
int ul_cancelable; /* _cancelon()/_canceloff() */
char ul_cancel_pending; /* pthread_cancel() was called */
char ul_cancel_disabled; /* PTHREAD_CANCEL_DISABLE */
char ul_cancel_async; /* PTHREAD_CANCEL_ASYNCHRONOUS */
char ul_save_async; /* saved copy of ul_cancel_async */
char ul_mutator; /* lwp is a mutator (java interface) */
char ul_created; /* created suspended */
char ul_replace; /* replacement; must be free()d */
int ul_errno; /* per-thread errno */
int ul_bindflags; /* bind_guard() interface to ld.so.1 */
char ul_td_events_enable; /* event mechanism enabled */
char ul_sync_obj_reg; /* tdb_sync_obj_register() */
char ul_qtype; /* MX or CV */
char ul_cv_wake; /* != 0: just wake up, don't requeue */
int ul_usropts; /* flags given to thr_create() */
int ul_save_state; /* bind_guard() interface to ld.so.1 */
/* 0 means there is but a single entry */
union { /* single entry or pointer to array */
} ul_readlock;
/* 0 means there is but a single entry */
union { /* single entry or pointer to array */
} ul_heldlocks;
/* PROBE_SUPPORT begin */
/* PROBE_SUPPORT end */
/* the following members *must* be last in the structure */
/* they are discarded when ulwp is replaced on thr_exit() */
#if defined(sparc)
#endif
} ulwp32_t;
typedef struct uberdata32 {
char primary_map;
char bucket_init;
char pad[2];
int nthreads;
int nzombies;
int ndaemons;
int pid;
int nfreestack;
int thread_stack_cache;
} uberdata32_t;
#endif /* _SYSCALL32 */
/* ul_stop values */
/*
* Implementation-specific attribute types for pthread_mutexattr_init() etc.
*/
typedef struct _cvattr {
int pshared;
} cvattr_t;
typedef struct _mattr {
int pshared;
int protocol;
int prioceiling;
int type;
int robustness;
} mattr_t;
typedef struct _thrattr {
void *stkaddr;
int detachstate;
int daemonstate;
int scope;
int prio;
int policy;
int inherit;
} thrattr_t;
typedef struct _rwlattr {
int pshared;
} rwlattr_t;
/* _curthread() is inline for speed */
extern ulwp_t *_curthread(void);
#define curthread (_curthread())
/* this version (also inline) can be tested for NULL */
extern ulwp_t *__curthread(void);
/* get the current stack pointer (also inline) */
/*
* Suppress __attribute__((...)) if we are not compiling with gcc
*/
#if !defined(__GNUC__)
#define __attribute__(string)
#endif
/* Fetch the dispatch (kernel) priority of a thread */
#define real_priority(ulwp) \
/*
* Implementation functions. Not visible outside of the library itself.
*/
extern void thr_panic(const char *);
#pragma rarely_called(thr_panic)
extern void mutex_panic(mutex_t *, const char *);
#pragma rarely_called(mutex_panic)
extern void finish_init(void);
extern void update_sched(ulwp_t *);
extern void queue_alloc(void);
extern void tmem_exit(void);
extern void tsd_exit(void);
extern void tls_setup(void);
extern void tls_exit(void);
extern void heldlock_exit(void);
extern void heldlock_free(ulwp_t *);
extern void sigacthandler(int, siginfo_t *, void *);
extern void signal_init(void);
extern void mutex_setup(void);
extern void take_deferred_signal(int);
extern volatile sc_shared_t *setup_schedctl(void);
extern void *libc_malloc(size_t);
extern void *libc_realloc(void *, size_t);
extern void libc_free(void *);
extern char *libc_strdup(const char *);
extern void lock_error(const mutex_t *, const char *, void *, const char *);
extern void rwlock_error(const rwlock_t *, const char *, const char *);
extern void thread_error(const char *);
extern void grab_assert_lock(void);
extern void dump_queue_statistics(void);
extern void collect_queue_statistics(void);
extern void record_spin_locks(ulwp_t *);
extern void remember_lock(mutex_t *);
extern void forget_lock(mutex_t *);
extern void register_lock(mutex_t *);
extern void unregister_locks(void);
#if defined(__sparc)
extern void _flush_windows(void);
#else
#define _flush_windows()
#endif
extern void set_curthread(void *);
/*
* Utility function used when waking up many threads (more than MAXLWPS)
* all at once. See mutex_wakeup_all(), cond_broadcast(), and rw_unlock().
*/
/* enter a critical section */
/* exit a critical section, take deferred actions if necessary */
extern void do_exit_critical(void);
#define exit_critical(self) \
(void) (self->ul_critical--, \
(do_exit_critical(), 0) : 0))
/*
* Like enter_critical()/exit_critical() but just for deferring signals.
* Unlike enter_critical()/exit_critical(), ul_sigdefer may be set while
* calling application functions like constructors and destructors.
* Care must be taken if the application function attempts to set
* the signal mask while a deferred signal is present; the setting
* of the signal mask must also be deferred.
*/
(void) ((--self->ul_sigdefer == 0 && \
(do_exit_critical(), 0) : 0)
/* these are exported functions */
extern void _sigoff(void);
extern void _sigon(void);
#define delete_reserved_signals(s) \
/*
* When restoring the signal mask after having previously called
* block_all_signals(), if we have a deferred signal present then
* do nothing other than ASSERT() that we are in a critical region.
* The signal mask will be set when we emerge from the critical region
* and call take_deferred_signal(). There is no race condition here
* because the kernel currently has all signals blocked for this thread.
*/
#define restore_signals(self) \
extern void set_cancel_pending_flag(ulwp_t *, int);
extern void set_cancel_eintr_flag(ulwp_t *);
extern void set_parking_flag(ulwp_t *, int);
extern int cancel_active(void);
extern void *_thrp_setup(ulwp_t *);
extern void _fpinherit(ulwp_t *);
extern void _lwp_start(void);
extern void _lwp_terminate(void);
extern void lmutex_lock(mutex_t *);
extern void lmutex_unlock(mutex_t *);
extern void lrw_rdlock(rwlock_t *);
extern void lrw_wrlock(rwlock_t *);
extern void lrw_unlock(rwlock_t *);
extern void sig_mutex_lock(mutex_t *);
extern void sig_mutex_unlock(mutex_t *);
extern int sig_mutex_trylock(mutex_t *);
extern void cancel_safe_mutex_lock(mutex_t *);
extern void cancel_safe_mutex_unlock(mutex_t *);
extern int cancel_safe_mutex_trylock(mutex_t *);
extern void _prefork_handler(void);
extern void _postfork_parent_handler(void);
extern void _postfork_child_handler(void);
extern void postfork1_child(void);
extern void postfork1_child_aio(void);
extern void postfork1_child_sigev_aio(void);
extern void postfork1_child_sigev_mq(void);
extern void postfork1_child_sigev_timer(void);
extern void postfork1_child_tpool(void);
extern void fork_lock_enter(void);
extern void fork_lock_exit(void);
extern void suspend_fork(void);
extern void continue_fork(int);
extern void do_sigcancel(void);
extern void setup_cancelsig(int);
extern void init_sigev_thread(void);
extern void init_aio(void);
extern void init_progname(void);
extern void _cancelon(void);
extern void _canceloff(void);
extern void _canceloff_nocancel(void);
extern void _cancel_prologue(void);
extern void _cancel_epilogue(void);
extern void no_preempt(ulwp_t *);
extern void _thrp_unwind(void *);
extern pid_t __forkallx(int);
extern int __openat64(int, const char *, int, mode_t);
extern int __close(int);
extern int __fcntl(int, int, ...);
extern int __lwp_continue(lwpid_t);
extern int ___lwp_suspend(lwpid_t);
extern int __lwp_detach(lwpid_t);
extern sc_shared_t *__schedctl(void);
/* actual system call traps */
extern int __setcontext(const ucontext_t *);
extern int __getcontext(ucontext_t *);
extern int __lwp_sigmask(int, const sigset_t *);
extern caddr_t __sighndlrend;
#pragma unknown_control_flow(__sighndlr)
/* belongs in <pthread.h> */
#define PTHREAD_CREATE_NONDAEMON_NP 0
extern int pthread_attr_setdaemonstate_np(pthread_attr_t *, int);
extern int pthread_attr_getdaemonstate_np(const pthread_attr_t *, int *);
extern int mutex_held(mutex_t *);
extern int mutex_unlock_internal(mutex_t *, int);
/* not cancellation points: */
extern int rw_read_held(rwlock_t *);
extern int rw_write_held(rwlock_t *);
extern int _thrp_create(void *, size_t, void *(*)(void *), void *, long,
extern void _thrp_terminate(void *);
extern void _thrp_exit(void);
extern const pcclass_t *get_info_by_policy(int);
extern const thrattr_t *def_thrattr(void);
/*
* System call wrappers (direct interfaces to the kernel)
*/
extern int ___lwp_mutex_unlock(mutex_t *);
extern int ___lwp_mutex_wakeup(mutex_t *, int);
extern int __lwp_rwlock_tryrdlock(rwlock_t *);
extern int __lwp_rwlock_trywrlock(rwlock_t *);
extern int __lwp_rwlock_unlock(rwlock_t *);
extern int __lwp_unpark(lwpid_t);
extern int __lwp_unpark_all(lwpid_t *, int);
#if defined(__x86)
extern int ___lwp_private(int, int, void *);
#endif /* __x86 */
/*
* inlines
*/
extern int set_lock_byte(volatile uint8_t *);
extern void atomic_inc_32(volatile uint32_t *);
extern void atomic_dec_32(volatile uint32_t *);
#if defined(__sparc)
#endif /* __sparc */
#include "thr_inlines.h"
#endif /* _THR_UBERDATA_H */