2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#ifndef _THR_UBERDATA_H
2N/A#define _THR_UBERDATA_H
2N/A
2N/A#include <stdlib.h>
2N/A#include <unistd.h>
2N/A#include <sys/types.h>
2N/A#include <fcntl.h>
2N/A#include <string.h>
2N/A#include <signal.h>
2N/A#include <ucontext.h>
2N/A#include <thread.h>
2N/A#include <pthread.h>
2N/A#include <atomic.h>
2N/A#include <link.h>
2N/A#include <sys/resource.h>
2N/A#include <sys/lwp.h>
2N/A#include <errno.h>
2N/A#include <sys/asm_linkage.h>
2N/A#include <sys/regset.h>
2N/A#include <sys/fcntl.h>
2N/A#include <sys/mman.h>
2N/A#include <synch.h>
2N/A#include <door.h>
2N/A#include <limits.h>
2N/A#include <sys/synch32.h>
2N/A#include <schedctl.h>
2N/A#include <sys/priocntl.h>
2N/A#include <thread_db.h>
2N/A#include <setjmp.h>
2N/A#include "libc_int.h"
2N/A#include "tdb_agent.h"
2N/A#include "thr_debug.h"
2N/A
2N/A/*
2N/A * This is an implementation-specific include file for threading support.
2N/A * It is not to be seen by the clients of the library.
2N/A *
2N/A * This file also describes uberdata in libc.
2N/A *
2N/A * The term "uberdata" refers to data that is unique and visible across
2N/A * all link maps. The name is meant to imply that such data is truly
2N/A * global, not just locally global to a particular link map.
2N/A *
2N/A * See the Linker and Libraries Guide for a full description of alternate
2N/A * link maps and how they are set up and used.
2N/A *
2N/A * Alternate link maps implement multiple global namespaces within a single
2N/A * process. There may be multiple instances of identical dynamic libraries
2N/A * loaded in a process's address space at the same time, each on a different
2N/A * link map (as determined by the dynamic linker), each with its own set of
2N/A * global variables. Which particular instance of a global variable is seen
2N/A * by a thread running in the process is determined by the link map on which
2N/A * the thread happens to be executing at the time.
2N/A *
2N/A * However, there are aspects of a process that are unique across all
2N/A * link maps, in particular the structures used to implement threads
2N/A * of control (in Sparc terminology, there is only one %g7 regardless
2N/A * of the link map on which the thread is executing).
2N/A *
2N/A * All uberdata is referenced from a base pointer in the thread's ulwp_t
2N/A * structure (which is also uberdata). All allocations and deallocations
2N/A * of uberdata are made via the uberdata-aware lmalloc() and lfree()
2N/A * interfaces (malloc() and free() are simply locally-global).
2N/A */
2N/A
2N/A/*
2N/A * Special libc-private access to errno.
2N/A * We do this so that references to errno do not invoke the dynamic linker.
2N/A */
2N/A#undef errno
2N/A#define errno (*curthread->ul_errnop)
2N/A
2N/A/*
2N/A * See <sys/synch32.h> for the reasons for these values
2N/A * and why they are different for sparc and intel.
2N/A */
2N/A#if defined(__sparc)
2N/A
2N/A/* lock.lock64.pad[x] 4 5 6 7 */
2N/A#define LOCKMASK 0xff000000
2N/A#define WAITERMASK 0x000000ff
2N/A#define SPINNERMASK 0x00ff0000
2N/A#define SPINNERSHIFT 16
2N/A#define WAITER 0x00000001
2N/A#define LOCKSET 0xff
2N/A#define LOCKCLEAR 0
2N/A
2N/A#define PIDSHIFT 32
2N/A#define LOCKMASK64 0xffffffffff000000ULL
2N/A#define LOCKBYTE64 0x00000000ff000000ULL
2N/A#define WAITERMASK64 0x00000000000000ffULL
2N/A#define SPINNERMASK64 0x0000000000ff0000ULL
2N/A
2N/A#elif defined(__x86)
2N/A
2N/A/* lock.lock64.pad[x] 7 6 5 4 */
2N/A#define LOCKMASK 0xff000000
2N/A#define WAITERMASK 0x00ff0000
2N/A#define SPINNERMASK 0x0000ff00
2N/A#define SPINNERSHIFT 8
2N/A#define WAITER 0x00010000
2N/A#define LOCKSET 0x01
2N/A#define LOCKCLEAR 0
2N/A
2N/A#define PIDSHIFT 0
2N/A#define LOCKMASK64 0xff000000ffffffffULL
2N/A#define LOCKBYTE64 0x0100000000000000ULL
2N/A#define WAITERMASK64 0x00ff000000000000ULL
2N/A#define SPINNERMASK64 0x0000ff0000000000ULL
2N/A
2N/A#else
2N/A#error "neither __sparc nor __x86 is defined"
2N/A#endif
2N/A
2N/A/*
2N/A * Fetch the owner of a USYNC_THREAD mutex.
2N/A * Don't use this with process-shared mutexes;
2N/A * the owing thread may be in a different process.
2N/A */
2N/A#define MUTEX_OWNER(mp) ((ulwp_t *)(uintptr_t)(mp)->mutex_owner)
2N/A
2N/A/*
2N/A * Test if a thread owns a process-private (USYNC_THREAD) mutex.
2N/A * This is inappropriate for a process-shared (USYNC_PROCESS) mutex.
2N/A * The 'mp' argument must not have side-effects since it is evaluated twice.
2N/A */
2N/A#define MUTEX_OWNED(mp, thrp) \
2N/A ((mp)->mutex_lockw != 0 && MUTEX_OWNER(mp) == thrp)
2N/A
2N/A
2N/A/*
2N/A * uberflags.uf_tdb_register_sync is an interface with libc_db to enable the
2N/A * collection of lock statistics by a debugger or other collecting tool.
2N/A *
2N/A * uberflags.uf_thread_error_detection is set by an environment variable:
2N/A * _THREAD_ERROR_DETECTION
2N/A * 0 == no detection of locking primitive errors.
2N/A * 1 == detect errors and issue a warning message.
2N/A * 2 == detect errors, issue a warning message, and dump core.
2N/A *
2N/A * We bundle these together in uberflags.uf_trs_ted to make a test of either
2N/A * being non-zero a single memory reference (for speed of mutex_lock(), etc).
2N/A *
2N/A * uberflags.uf_mt is set non-zero when the first thread (in addition
2N/A * to the main thread) is created.
2N/A *
2N/A * We bundle all these flags together in uberflags.uf_all to make a test
2N/A * of any being non-zero a single memory reference (again, for speed).
2N/A */
2N/Atypedef union {
2N/A int uf_all; /* combined all flags */
2N/A struct {
2N/A short h_pad;
2N/A short h_trs_ted; /* combined reg sync & error detect */
2N/A } uf_h;
2N/A struct {
2N/A char x_mt;
2N/A char x_pad;
2N/A char x_tdb_register_sync;
2N/A char x_thread_error_detection;
2N/A } uf_x;
2N/A} uberflags_t;
2N/A
2N/A#define uf_mt uf_x.x_mt
2N/A#define uf_tdb_register_sync uf_x.x_tdb_register_sync
2N/A#define uf_thread_error_detection uf_x.x_thread_error_detection
2N/A#define uf_trs_ted uf_h.h_trs_ted /* both of the above */
2N/A
2N/A/*
2N/A * NOTE WELL:
2N/A * To enable further optimization, the "ul_schedctl_called" member
2N/A * of the ulwp_t structure (below) serves double-duty:
2N/A * 1. If NULL, it means that the thread must call __schedctl()
2N/A * to set up its schedctl mappings before acquiring a mutex.
2N/A * This is required by the implementation of adaptive mutex locking.
2N/A * 2. If non-NULL, it points to uberdata.uberflags, so that tests of
2N/A * uberflags can be made without additional memory references.
2N/A * This allows the common case of _mutex_lock() and _mutex_unlock() for
2N/A * USYNC_THREAD mutexes with no error detection and no lock statistics
2N/A * to be optimized for speed.
2N/A */
2N/A
2N/A/* double the default stack size for 64-bit processes */
2N/A#ifdef _LP64
2N/A#define MINSTACK (8 * 1024)
2N/A#define DEFAULTSTACK (2 * 1024 * 1024)
2N/A#else
2N/A#define MINSTACK (4 * 1024)
2N/A#define DEFAULTSTACK (1024 * 1024)
2N/A#endif
2N/A
2N/A#define MUTEX_TRY 0
2N/A#define MUTEX_LOCK 1
2N/A#define MUTEX_NOCEIL 0x40
2N/A
2N/A#if defined(__x86)
2N/A
2N/Atypedef struct { /* structure returned by fnstenv */
2N/A int fctrl; /* control word */
2N/A int fstat; /* status word (flags, etc) */
2N/A int ftag; /* tag of which regs busy */
2N/A int misc[4]; /* other stuff, 28 bytes total */
2N/A} fpuenv_t;
2N/A
2N/A#ifdef _SYSCALL32
2N/Atypedef fpuenv_t fpuenv32_t;
2N/A#endif /* _SYSCALL32 */
2N/A
2N/A#elif defined(__sparc)
2N/A
2N/Atypedef struct { /* fp state structure */
2N/A greg_t fsr;
2N/A greg_t fpu_en;
2N/A} fpuenv_t;
2N/A
2N/A#ifdef _SYSCALL32
2N/Atypedef struct {
2N/A greg32_t fsr;
2N/A greg32_t fpu_en;
2N/A} fpuenv32_t;
2N/A#endif /* _SYSCALL32 */
2N/A
2N/A#endif /* __x86 */
2N/A
2N/A#if defined(__x86)
2N/Aextern void ht_pause(void); /* "pause" instruction */
2N/A#define SMT_PAUSE() ht_pause()
2N/A#elif defined(SMT_PAUSE_FUNCTION)
2N/Aextern void SMT_PAUSE_FUNCTION(void);
2N/A#define SMT_PAUSE() SMT_PAUSE_FUNCTION()
2N/A#else
2N/A#define SMT_PAUSE() smt_pause()
2N/A#endif /* __x86 */
2N/A
2N/A/*
2N/A * Cleanup handler related data.
2N/A * This structure is exported as _cleanup_t in pthread.h.
2N/A * pthread.h exports only the size of this structure, so check
2N/A * _cleanup_t in pthread.h before making any change here.
2N/A */
2N/Atypedef struct __cleanup {
2N/A struct __cleanup *next; /* pointer to next handler */
2N/A caddr_t fp; /* current frame pointer */
2N/A void (*func)(void *); /* cleanup handler address */
2N/A void *arg; /* handler's argument */
2N/A} __cleanup_t;
2N/A
2N/A/*
2N/A * Thread-Specific Data (TSD)
2N/A * TSD_NFAST includes the invalid key zero, so there
2N/A * are really only (TSD_NFAST - 1) fast key slots.
2N/A */
2N/Atypedef void (*PFrV)(void *);
2N/A#define TSD_UNALLOCATED ((PFrV)1)
2N/A#define TSD_NFAST 9
2N/A
2N/A/*
2N/A * The tsd union is designed to burn a little memory (9 words) to make
2N/A * lookups blindingly fast. Note that tsd_nalloc could be placed at the
2N/A * end of the pad region to increase the likelihood that it falls on the
2N/A * same cache line as the data.
2N/A */
2N/Atypedef union tsd {
2N/A uint_t tsd_nalloc; /* Amount of allocated storage */
2N/A void *tsd_pad[TSD_NFAST];
2N/A void *tsd_data[1];
2N/A} tsd_t;
2N/A
2N/Atypedef struct {
2N/A mutex_t tsdm_lock; /* Lock protecting the data */
2N/A uint_t tsdm_nkeys; /* Number of allocated keys */
2N/A uint_t tsdm_nused; /* Number of used keys */
2N/A PFrV *tsdm_destro; /* Per-key destructors */
2N/A char tsdm_pad[64 - /* pad to 64 bytes */
2N/A (sizeof (mutex_t) + 2 * sizeof (uint_t) + sizeof (PFrV *))];
2N/A} tsd_metadata_t;
2N/A
2N/A#ifdef _SYSCALL32
2N/Atypedef union tsd32 {
2N/A uint_t tsd_nalloc; /* Amount of allocated storage */
2N/A caddr32_t tsd_pad[TSD_NFAST];
2N/A caddr32_t tsd_data[1];
2N/A} tsd32_t;
2N/A
2N/Atypedef struct {
2N/A mutex_t tsdm_lock; /* Lock protecting the data */
2N/A uint_t tsdm_nkeys; /* Number of allocated keys */
2N/A uint_t tsdm_nused; /* Number of used keys */
2N/A caddr32_t tsdm_destro; /* Per-key destructors */
2N/A char tsdm_pad[64 - /* pad to 64 bytes */
2N/A (sizeof (mutex_t) + 2 * sizeof (uint_t) + sizeof (caddr32_t))];
2N/A} tsd_metadata32_t;
2N/A#endif /* _SYSCALL32 */
2N/A
2N/A
2N/A/*
2N/A * Thread-Local Storage (TLS)
2N/A */
2N/Atypedef struct {
2N/A void *tls_data;
2N/A size_t tls_size;
2N/A} tls_t;
2N/A
2N/Atypedef struct {
2N/A mutex_t tls_lock; /* Lock protecting the data */
2N/A tls_t tls_modinfo; /* Root of all TLS_modinfo data */
2N/A tls_t static_tls; /* Template for static TLS */
2N/A char tls_pad[64 - /* pad to 64 bytes */
2N/A (sizeof (mutex_t) + 2 * sizeof (tls_t))];
2N/A} tls_metadata_t;
2N/A
2N/A#ifdef _SYSCALL32
2N/Atypedef struct {
2N/A caddr32_t tls_data;
2N/A size32_t tls_size;
2N/A} tls32_t;
2N/A
2N/Atypedef struct {
2N/A mutex_t tls_lock; /* Lock protecting the data */
2N/A tls32_t tls_modinfo; /* Root of all TLS_modinfo data */
2N/A tls32_t static_tls; /* Template for static TLS */
2N/A char tls_pad[64 - /* pad to 64 bytes */
2N/A (sizeof (mutex_t) + 2 * sizeof (tls32_t))];
2N/A} tls_metadata32_t;
2N/A#endif /* _SYSCALL32 */
2N/A
2N/A
2N/A/*
2N/A * Sleep queue root for USYNC_THREAD condvars and mutexes.
2N/A * There is a default queue root for each queue head (see below).
2N/A * Also, each ulwp_t contains a queue root that can be used
2N/A * when the thread is enqueued on the queue, if necessary
2N/A * (when more than one wchan hashes to the same queue head).
2N/A */
2N/Atypedef struct queue_root {
2N/A struct queue_root *qr_next;
2N/A struct queue_root *qr_prev;
2N/A struct ulwp *qr_head;
2N/A struct ulwp *qr_tail;
2N/A void *qr_wchan;
2N/A uint32_t qr_rtcount;
2N/A uint32_t qr_qlen;
2N/A uint32_t qr_qmax;
2N/A} queue_root_t;
2N/A
2N/A#ifdef _SYSCALL32
2N/Atypedef struct queue_root32 {
2N/A caddr32_t qr_next;
2N/A caddr32_t qr_prev;
2N/A caddr32_t qr_head;
2N/A caddr32_t qr_tail;
2N/A caddr32_t qr_wchan;
2N/A uint32_t qr_rtcount;
2N/A uint32_t qr_qlen;
2N/A uint32_t qr_qmax;
2N/A} queue_root32_t;
2N/A#endif
2N/A
2N/A/*
2N/A * Sleep queue heads for USYNC_THREAD condvars and mutexes.
2N/A * The size and alignment is 128 bytes to reduce cache conflicts.
2N/A * Each queue head points to a list of queue roots, defined above.
2N/A * Each queue head contains a default queue root for use when only one
2N/A * is needed. It is always at the tail of the queue root hash chain.
2N/A */
2N/Atypedef union {
2N/A uint64_t qh_64[16];
2N/A struct {
2N/A mutex_t q_lock;
2N/A uint8_t q_qcnt;
2N/A uint8_t q_type; /* MX or CV */
2N/A uint8_t q_pad1[2];
2N/A uint32_t q_lockcount;
2N/A uint32_t q_qlen;
2N/A uint32_t q_qmax;
2N/A void *q_wchan; /* valid only while locked */
2N/A struct queue_root *q_root; /* valid only while locked */
2N/A struct queue_root *q_hlist;
2N/A#if !defined(_LP64)
2N/A caddr_t q_pad2[3];
2N/A#endif
2N/A queue_root_t q_def_root;
2N/A uint32_t q_hlen;
2N/A uint32_t q_hmax;
2N/A } qh_qh;
2N/A} queue_head_t;
2N/A
2N/A#define qh_lock qh_qh.q_lock
2N/A#define qh_qcnt qh_qh.q_qcnt
2N/A#define qh_type qh_qh.q_type
2N/A#if defined(THREAD_DEBUG)
2N/A#define qh_lockcount qh_qh.q_lockcount
2N/A#define qh_qlen qh_qh.q_qlen
2N/A#define qh_qmax qh_qh.q_qmax
2N/A#endif
2N/A#define qh_wchan qh_qh.q_wchan
2N/A#define qh_root qh_qh.q_root
2N/A#define qh_hlist qh_qh.q_hlist
2N/A#define qh_def_root qh_qh.q_def_root
2N/A#define qh_hlen qh_qh.q_hlen
2N/A#define qh_hmax qh_qh.q_hmax
2N/A
2N/A/* queue types passed to queue_lock() */
2N/A#define MX 0
2N/A#define CV 1
2N/A#define QHASHSHIFT 9 /* number of hashing bits */
2N/A#define QHASHSIZE (1 << QHASHSHIFT) /* power of 2 (1<<9 == 512) */
2N/A#define QUEUE_HASH(wchan, type) ((uint_t) \
2N/A ((((uintptr_t)(wchan) >> 3) \
2N/A ^ ((uintptr_t)(wchan) >> (QHASHSHIFT + 3))) \
2N/A & (QHASHSIZE - 1)) + (((type) == MX)? 0 : QHASHSIZE))
2N/A
2N/Aextern queue_head_t *queue_lock(void *, int);
2N/Aextern void queue_unlock(queue_head_t *);
2N/Aextern void enqueue(queue_head_t *, struct ulwp *, int);
2N/Aextern struct ulwp *dequeue(queue_head_t *, int *);
2N/Aextern struct ulwp **queue_slot(queue_head_t *, struct ulwp **, int *);
2N/Aextern struct ulwp *queue_waiter(queue_head_t *);
2N/Aextern int dequeue_self(queue_head_t *);
2N/Aextern void queue_unlink(queue_head_t *,
2N/A struct ulwp **, struct ulwp *);
2N/Aextern void unsleep_self(void);
2N/Aextern void spin_lock_set(mutex_t *);
2N/Aextern void spin_lock_clear(mutex_t *);
2N/A
2N/A/*
2N/A * Scheduling class information structure.
2N/A */
2N/Atypedef struct {
2N/A short pcc_state;
2N/A short pcc_policy;
2N/A pri_t pcc_primin;
2N/A pri_t pcc_primax;
2N/A pcinfo_t pcc_info;
2N/A} pcclass_t;
2N/A
2N/A/*
2N/A * Memory block for chain of owned ceiling mutexes.
2N/A */
2N/Atypedef struct mxchain {
2N/A struct mxchain *mxchain_next;
2N/A mutex_t *mxchain_mx;
2N/A} mxchain_t;
2N/A
2N/A/*
2N/A * Pointer to an rwlock that is held for reading.
2N/A * Used in rw_rdlock() to allow a thread that already holds a read
2N/A * lock to acquire another read lock on the same rwlock even if
2N/A * there are writers waiting. This to avoid deadlock when acquiring
2N/A * a read lock more than once in the presence of pending writers.
2N/A * POSIX mandates this behavior.
2N/A */
2N/Atypedef struct {
2N/A void *rd_rwlock; /* the rwlock held for reading */
2N/A size_t rd_count; /* count of read locks applied */
2N/A} readlock_t;
2N/A
2N/A#ifdef _SYSCALL32
2N/Atypedef struct {
2N/A caddr32_t rd_rwlock;
2N/A size32_t rd_count;
2N/A} readlock32_t;
2N/A#endif /* _SYSCALL32 */
2N/A
2N/A/*
2N/A * Maximum number of read locks allowed for one thread on one rwlock.
2N/A * This could be as large as INT_MAX, but the SUSV3 test suite would
2N/A * take an inordinately long time to complete. This is big enough.
2N/A */
2N/A#define READ_LOCK_MAX 100000
2N/A
2N/A#define ul_tlsent ul_tls.tls_data /* array of pointers to dynamic TLS */
2N/A#define ul_ntlsent ul_tls.tls_size /* number of entries in ul_tlsent */
2N/A
2N/A/*
2N/A * Round up an integral value to a multiple of 64
2N/A */
2N/A#define roundup64(x) (-(-(x) & -64))
2N/A
2N/A/*
2N/A * NOTE: Whatever changes are made to ulwp_t must be
2N/A * reflected in $SRC/cmd/mdb/common/modules/libc/libc.c
2N/A *
2N/A * NOTE: ul_self *must* be the first member of ulwp_t on x86
2N/A * Low-level x86 code relies on this.
2N/A */
2N/Atypedef struct ulwp {
2N/A /*
2N/A * These members always need to come first on sparc.
2N/A * For dtrace, a ulwp_t must be aligned on a 64-byte boundary.
2N/A */
2N/A#if defined(__sparc)
2N/A uint32_t ul_dinstr; /* scratch space for dtrace */
2N/A uint32_t ul_padsparc0[15];
2N/A uint32_t ul_dsave; /* dtrace: save %g1, %g0, %sp */
2N/A uint32_t ul_drestore; /* dtrace: restore %g0, %g0, %g0 */
2N/A uint32_t ul_dftret; /* dtrace: return probe fasttrap */
2N/A uint32_t ul_dreturn; /* dtrace: return %o0 */
2N/A#endif
2N/A struct ulwp *ul_self; /* pointer to self */
2N/A#if defined(__i386)
2N/A uint8_t ul_dinstr[40]; /* scratch space for dtrace */
2N/A#elif defined(__amd64)
2N/A uint8_t ul_dinstr[56]; /* scratch space for dtrace */
2N/A#endif
2N/A struct uberdata *ul_uberdata; /* uber (super-global) data */
2N/A tls_t ul_tls; /* dynamic thread-local storage base */
2N/A struct ulwp *ul_forw; /* forw, back all_lwps list, */
2N/A struct ulwp *ul_back; /* protected by link_lock */
2N/A struct ulwp *ul_next; /* list to keep track of stacks */
2N/A struct ulwp *ul_hash; /* hash chain linked list */
2N/A void *ul_rval; /* return value from thr_exit() */
2N/A caddr_t ul_stk; /* mapping base of the stack */
2N/A size_t ul_mapsiz; /* mapping size of the stack */
2N/A size_t ul_guardsize; /* normally _lpagesize */
2N/A uintptr_t ul_stktop; /* broken thr_stksegment() interface */
2N/A size_t ul_stksiz; /* broken thr_stksegment() interface */
2N/A stack_t ul_ustack; /* current stack boundaries */
2N/A int ul_ix; /* hash index */
2N/A lwpid_t ul_lwpid; /* thread id, aka the lwp id */
2N/A pri_t ul_pri; /* scheduling priority */
2N/A pri_t ul_epri; /* real-time ceiling priority */
2N/A char ul_policy; /* scheduling policy */
2N/A char ul_cid; /* scheduling class id */
2N/A union {
2N/A struct {
2N/A char cursig; /* deferred signal number */
2N/A char pleasestop; /* lwp requested to stop itself */
2N/A } s;
2N/A short curplease; /* for testing both at once */
2N/A } ul_cp;
2N/A char ul_stop; /* reason for stopping */
2N/A char ul_signalled; /* this lwp was cond_signal()d */
2N/A char ul_dead; /* this lwp has called thr_exit */
2N/A char ul_unwind; /* posix: unwind C++ stack */
2N/A char ul_detached; /* THR_DETACHED at thread_create() */
2N/A /* or pthread_detach() was called */
2N/A char ul_writer; /* sleeping in rw_wrlock() */
2N/A char ul_stopping; /* set by curthread: stopping self */
2N/A char ul_cancel_prologue; /* for _cancel_prologue() */
2N/A short ul_preempt; /* no_preempt()/preempt() */
2N/A short ul_savpreempt; /* pre-existing preempt value */
2N/A char ul_sigsuspend; /* thread is in sigsuspend/pollsys */
2N/A char ul_main; /* thread is the main thread */
2N/A char ul_fork; /* thread is performing a fork */
2N/A char ul_primarymap; /* primary link-map is initialized */
2N/A /* per-thread copies of the corresponding global variables */
2N/A uint8_t ul_max_spinners; /* thread_max_spinners */
2N/A char ul_door_noreserve; /* thread_door_noreserve */
2N/A char ul_queue_fifo; /* thread_queue_fifo */
2N/A char ul_cond_wait_defer; /* thread_cond_wait_defer */
2N/A char ul_error_detection; /* thread_error_detection */
2N/A char ul_async_safe; /* thread_async_safe */
2N/A char ul_rt; /* found on an RT queue */
2N/A char ul_rtqueued; /* was RT when queued */
2N/A char ul_misaligned; /* thread_locks_misaligned */
2N/A char ul_pad[3];
2N/A int ul_adaptive_spin; /* thread_adaptive_spin */
2N/A int ul_queue_spin; /* thread_queue_spin */
2N/A volatile int ul_critical; /* non-zero == in a critical region */
2N/A int ul_sigdefer; /* non-zero == defer signals */
2N/A int ul_vfork; /* thread is the child of vfork() */
2N/A int ul_cancelable; /* _cancelon()/_canceloff() */
2N/A char ul_cancel_pending; /* pthread_cancel() was called */
2N/A char ul_cancel_disabled; /* PTHREAD_CANCEL_DISABLE */
2N/A char ul_cancel_async; /* PTHREAD_CANCEL_ASYNCHRONOUS */
2N/A char ul_save_async; /* saved copy of ul_cancel_async */
2N/A char ul_mutator; /* lwp is a mutator (java interface) */
2N/A char ul_created; /* created suspended */
2N/A char ul_replace; /* replacement; must be free()d */
2N/A uchar_t ul_nocancel; /* cancellation can't happen */
2N/A int ul_errno; /* per-thread errno */
2N/A int *ul_errnop; /* pointer to errno or self->ul_errno */
2N/A __cleanup_t *ul_clnup_hdr; /* head of cleanup handlers list */
2N/A uberflags_t *ul_schedctl_called; /* ul_schedctl is set up */
2N/A volatile sc_shared_t *ul_schedctl; /* schedctl data */
2N/A int ul_bindflags; /* bind_guard() interface to ld.so.1 */
2N/A uint_t ul_libc_locks; /* count of cancel_safe_mutex_lock()s */
2N/A tsd_t *ul_stsd; /* slow TLS for keys >= TSD_NFAST */
2N/A void *ul_ftsd[TSD_NFAST]; /* fast TLS for keys < TSD_NFAST */
2N/A td_evbuf_t ul_td_evbuf; /* event buffer */
2N/A char ul_td_events_enable; /* event mechanism enabled */
2N/A char ul_sync_obj_reg; /* tdb_sync_obj_register() */
2N/A char ul_qtype; /* MX or CV */
2N/A char ul_cv_wake; /* != 0: just wake up, don't requeue */
2N/A int ul_rtld; /* thread is running inside ld.so.1 */
2N/A int ul_usropts; /* flags given to thr_create() */
2N/A void *(*ul_startpc)(void *); /* start func (thr_create()) */
2N/A void *ul_startarg; /* argument for start function */
2N/A void *ul_wchan; /* synch object when sleeping */
2N/A struct ulwp *ul_link; /* sleep queue link */
2N/A queue_head_t *ul_sleepq; /* sleep queue thread is waiting on */
2N/A mutex_t *ul_cvmutex; /* mutex dropped when waiting on a cv */
2N/A mxchain_t *ul_mxchain; /* chain of owned ceiling mutexes */
2N/A int ul_save_state; /* bind_guard() interface to ld.so.1 */
2N/A uint_t ul_rdlockcnt; /* # entries in ul_readlock array */
2N/A /* 0 means there is but a single entry */
2N/A union { /* single entry or pointer to array */
2N/A readlock_t single;
2N/A readlock_t *array;
2N/A } ul_readlock;
2N/A uint_t ul_heldlockcnt; /* # entries in ul_heldlocks array */
2N/A /* 0 means there is but a single entry */
2N/A union { /* single entry or pointer to array */
2N/A mutex_t *single;
2N/A mutex_t **array;
2N/A } ul_heldlocks;
2N/A /* PROBE_SUPPORT begin */
2N/A void *ul_tpdp;
2N/A /* PROBE_SUPPORT end */
2N/A ucontext_t *ul_siglink; /* pointer to previous context */
2N/A uint_t ul_spin_lock_spin; /* spin lock statistics */
2N/A uint_t ul_spin_lock_spin2;
2N/A uint_t ul_spin_lock_sleep;
2N/A uint_t ul_spin_lock_wakeup;
2N/A queue_root_t ul_queue_root; /* root of a sleep queue */
2N/A id_t ul_rtclassid; /* real-time class id */
2N/A uint_t ul_pilocks; /* count of PI locks held */
2N/A /* the following members *must* be last in the structure */
2N/A /* they are discarded when ulwp is replaced on thr_exit() */
2N/A sigset_t ul_sigmask; /* thread's current signal mask */
2N/A sigset_t ul_tmpmask; /* signal mask for sigsuspend/pollsys */
2N/A siginfo_t ul_siginfo; /* deferred siginfo */
2N/A mutex_t ul_spinlock; /* used when suspending/continuing */
2N/A fpuenv_t ul_fpuenv; /* floating point state */
2N/A uintptr_t ul_sp; /* stack pointer when blocked */
2N/A void *ul_ex_unwind; /* address of _ex_unwind() or -1 */
2N/A#if defined(sparc)
2N/A void *ul_unwind_ret; /* used only by _ex_clnup_handler() */
2N/A#endif
2N/A} ulwp_t;
2N/A
2N/A#define ul_cursig ul_cp.s.cursig /* deferred signal number */
2N/A#define ul_pleasestop ul_cp.s.pleasestop /* lwp requested to stop */
2N/A#define ul_curplease ul_cp.curplease /* for testing both at once */
2N/A
2N/A/*
2N/A * This is the size of a replacement ulwp, retained only for the benefit
2N/A * of thr_join(). The trailing members are unneeded for this purpose.
2N/A */
2N/A#define REPLACEMENT_SIZE ((size_t)&((ulwp_t *)NULL)->ul_sigmask)
2N/A
2N/A/*
2N/A * Definitions for static initialization of signal sets,
2N/A * plus some sneaky optimizations in various places.
2N/A */
2N/A
2N/A#define SIGMASK(sig) ((uint32_t)1 << (((sig) - 1) & (32 - 1)))
2N/A
2N/A#if (MAXSIG > (2 * 32) && MAXSIG <= (3 * 32))
2N/A#define FILLSET0 0xffffffffu
2N/A#define FILLSET1 0xffffffffu
2N/A#define FILLSET2 ((1u << (MAXSIG - 64)) - 1)
2N/A#define FILLSET3 0
2N/A#else
2N/A#error "fix me: MAXSIG out of bounds"
2N/A#endif
2N/A
2N/A#define CANTMASK0 (SIGMASK(SIGKILL) | SIGMASK(SIGSTOP))
2N/A#define CANTMASK1 0
2N/A#define CANTMASK2 0
2N/A#define CANTMASK3 0
2N/A
2N/A#define MASKSET0 (FILLSET0 & ~CANTMASK0)
2N/A#define MASKSET1 (FILLSET1 & ~CANTMASK1)
2N/A#define MASKSET2 (FILLSET2 & ~CANTMASK2)
2N/A#define MASKSET3 (FILLSET3 & ~CANTMASK3)
2N/A
2N/Aextern const sigset_t maskset; /* set of all maskable signals */
2N/A
2N/Aextern int thread_adaptive_spin;
2N/Aextern uint_t thread_max_spinners;
2N/Aextern int thread_queue_spin;
2N/Aextern int thread_queue_fifo;
2N/Aextern int thread_queue_dump;
2N/Aextern int thread_cond_wait_defer;
2N/Aextern int thread_async_safe;
2N/Aextern int thread_queue_verify;
2N/A
2N/A/*
2N/A * pthread_atfork() related data, used to store atfork handlers.
2N/A */
2N/Atypedef struct atfork {
2N/A struct atfork *forw; /* forward pointer */
2N/A struct atfork *back; /* backward pointer */
2N/A void (*prepare)(void); /* pre-fork handler */
2N/A void (*parent)(void); /* post-fork parent handler */
2N/A void (*child)(void); /* post-fork child handler */
2N/A} atfork_t;
2N/A
2N/A/*
2N/A * Element in the table and in the list of registered process
2N/A * robust locks. We keep track of these to make sure that we
2N/A * only call ___lwp_mutex_register() once for each such lock
2N/A * after it is first mapped in (or newly mapped in).
2N/A */
2N/Atypedef struct robust {
2N/A struct robust *robust_next; /* hash table list */
2N/A struct robust *robust_list; /* global list */
2N/A mutex_t *robust_lock;
2N/A} robust_t;
2N/A
2N/A/*
2N/A * Invalid address, used to mark an unused element in the hash table.
2N/A */
2N/A#define INVALID_ADDR ((void *)(uintptr_t)(-1L))
2N/A
2N/A/*
2N/A * Parameters of the lock registration hash table.
2N/A */
2N/A#define LOCKSHIFT 15 /* number of hashing bits */
2N/A#define LOCKHASHSZ (1 << LOCKSHIFT) /* power of 2 (1<<15 == 32K) */
2N/A#define LOCK_HASH(addr) (uint_t) \
2N/A ((((uintptr_t)(addr) >> 3) \
2N/A ^ ((uintptr_t)(addr) >> (LOCKSHIFT + 3))) \
2N/A & (LOCKHASHSZ - 1))
2N/A
2N/A/*
2N/A * Make our hot locks reside on private cache lines (64 bytes).
2N/A */
2N/Atypedef struct {
2N/A mutex_t pad_lock;
2N/A char pad_pad[64 - sizeof (mutex_t)];
2N/A} pad_lock_t;
2N/A
2N/A/*
2N/A * Make our semi-hot locks reside on semi-private cache lines (32 bytes).
2N/A */
2N/Atypedef struct {
2N/A mutex_t pad_lock;
2N/A char pad_pad[32 - sizeof (mutex_t)];
2N/A} pad32_lock_t;
2N/A
2N/A/*
2N/A * The threads hash table is used for fast lookup and locking of an active
2N/A * thread structure (ulwp_t) given a thread-id. It is an N-element array of
2N/A * thr_hash_table_t structures, where N == 1 before the main thread creates
2N/A * the first additional thread and N == 1024 afterwards. Each element of the
2N/A * table is 64 bytes in size and alignment to reduce cache conflicts.
2N/A */
2N/Atypedef struct {
2N/A mutex_t hash_lock; /* lock per bucket */
2N/A cond_t hash_cond; /* convar per bucket */
2N/A ulwp_t *hash_bucket; /* hash bucket points to the list of ulwps */
2N/A char hash_pad[64 - /* pad out to 64 bytes */
2N/A (sizeof (mutex_t) + sizeof (cond_t) + sizeof (ulwp_t *))];
2N/A} thr_hash_table_t;
2N/A
2N/A#ifdef _SYSCALL32
2N/Atypedef struct {
2N/A mutex_t hash_lock;
2N/A cond_t hash_cond;
2N/A caddr32_t hash_bucket;
2N/A char hash_pad[64 -
2N/A (sizeof (mutex_t) + sizeof (cond_t) + sizeof (caddr32_t))];
2N/A} thr_hash_table32_t;
2N/A#endif /* _SYSCALL32 */
2N/A
2N/A
2N/A/*
2N/A * siguaction members have 128-byte size and 64-byte alignment.
2N/A * We know that sizeof (struct sigaction) is 32 bytes for both
2N/A * _ILP32 and _LP64 and that sizeof (rwlock_t) is 64 bytes.
2N/A */
2N/Atypedef struct {
2N/A rwlock_t sig_lock;
2N/A struct sigaction sig_uaction;
2N/A char sig_pad[128 - sizeof (rwlock_t) - sizeof (struct sigaction)];
2N/A} siguaction_t;
2N/A
2N/A#ifdef _SYSCALL32
2N/Atypedef struct {
2N/A rwlock_t sig_lock;
2N/A struct sigaction32 sig_uaction;
2N/A char sig_pad[128 - sizeof (rwlock_t) - sizeof (struct sigaction32)];
2N/A} siguaction32_t;
2N/A#endif /* _SYSCALL32 */
2N/A
2N/A
2N/A/*
2N/A * Bucket structures, used by lmalloc()/lfree().
2N/A * See port/threads/alloc.c for details.
2N/A * A bucket's size and alignment is 64 bytes.
2N/A */
2N/Atypedef struct {
2N/A mutex_t bucket_lock; /* protects the free list allocations */
2N/A void *free_list; /* LIFO list of blocks to allocate/free */
2N/A size_t chunks; /* number of 64K blocks mmap()ed last time */
2N/A char pad64[64 - /* pad out to 64 bytes */
2N/A (sizeof (mutex_t) + sizeof (void *) + sizeof (size_t))];
2N/A} bucket_t;
2N/A
2N/A#ifdef _SYSCALL32
2N/Atypedef struct {
2N/A mutex_t bucket_lock;
2N/A caddr32_t free_list;
2N/A size32_t chunks;
2N/A char pad64[64 - /* pad out to 64 bytes */
2N/A (sizeof (mutex_t) + sizeof (caddr32_t) + sizeof (size32_t))];
2N/A} bucket32_t;
2N/A#endif /* _SYSCALL32 */
2N/A
2N/A#define NBUCKETS 10 /* sizes ranging from 64 to 32768 */
2N/A
2N/A
2N/A/*
2N/A * atexit() data structures.
2N/A * See port/gen/atexit.c for details.
2N/A */
2N/Atypedef void (*_exithdlr_func_t) (void);
2N/A
2N/Atypedef struct _exthdlr {
2N/A struct _exthdlr *next; /* next in handler list */
2N/A _exithdlr_func_t hdlr; /* handler itself */
2N/A} _exthdlr_t;
2N/A
2N/Atypedef struct {
2N/A mutex_t exitfns_lock;
2N/A _exthdlr_t *head;
2N/A void *exit_frame_monitor;
2N/A char exit_pad[64 - /* pad out to 64 bytes */
2N/A (sizeof (mutex_t) + sizeof (_exthdlr_t *) + sizeof (void *))];
2N/A} atexit_root_t;
2N/A
2N/A#ifdef _SYSCALL32
2N/Atypedef struct {
2N/A mutex_t exitfns_lock;
2N/A caddr32_t head;
2N/A caddr32_t exit_frame_monitor;
2N/A char exit_pad[64 - /* pad out to 64 bytes */
2N/A (sizeof (mutex_t) + sizeof (caddr32_t) + sizeof (caddr32_t))];
2N/A} atexit_root32_t;
2N/A#endif /* _SYSCALL32 */
2N/A
2N/A
2N/A/*
2N/A * This is data that is global to all link maps (uberdata, aka super-global).
2N/A */
2N/Atypedef struct uberdata {
2N/A pad_lock_t _link_lock;
2N/A pad_lock_t _ld_lock;
2N/A pad_lock_t _fork_lock;
2N/A pad_lock_t _atfork_lock;
2N/A pad32_lock_t _callout_lock;
2N/A pad32_lock_t _tdb_hash_lock;
2N/A tdb_sync_stats_t tdb_hash_lock_stats;
2N/A siguaction_t siguaction[NSIG];
2N/A bucket_t bucket[NBUCKETS];
2N/A atexit_root_t atexit_root;
2N/A tsd_metadata_t tsd_metadata;
2N/A tls_metadata_t tls_metadata;
2N/A /*
2N/A * Every object before this point has size and alignment of 64 bytes.
2N/A * Don't add any other type of data before this point.
2N/A */
2N/A char primary_map; /* set when primary link map is initialized */
2N/A char bucket_init; /* set when bucket[NBUCKETS] is initialized */
2N/A char pad[2];
2N/A uberflags_t uberflags;
2N/A queue_head_t *queue_head;
2N/A thr_hash_table_t *thr_hash_table;
2N/A uint_t hash_size; /* # of entries in thr_hash_table[] */
2N/A uint_t hash_mask; /* hash_size - 1 */
2N/A ulwp_t *ulwp_one; /* main thread */
2N/A ulwp_t *all_lwps; /* circular ul_forw/ul_back list of live lwps */
2N/A ulwp_t *all_zombies; /* circular ul_forw/ul_back list of zombies */
2N/A int nthreads; /* total number of live threads/lwps */
2N/A int nzombies; /* total number of zombie threads */
2N/A int ndaemons; /* total number of THR_DAEMON threads/lwps */
2N/A pid_t pid; /* the current process's pid */
2N/A void (*sigacthandler)(int, siginfo_t *, void *);
2N/A ulwp_t *lwp_stacks;
2N/A ulwp_t *lwp_laststack;
2N/A int nfreestack;
2N/A int thread_stack_cache;
2N/A ulwp_t *ulwp_freelist;
2N/A ulwp_t *ulwp_lastfree;
2N/A ulwp_t *ulwp_replace_free;
2N/A ulwp_t *ulwp_replace_last;
2N/A atfork_t *atforklist; /* circular Q for fork handlers */
2N/A robust_t **robustlocks; /* table of registered robust locks */
2N/A robust_t *robustlist; /* list of registered robust locks */
2N/A char *progname; /* the basename of the program, from argv[0] */
2N/A struct uberdata **tdb_bootstrap;
2N/A tdb_t tdb; /* thread debug interfaces (for libc_db) */
2N/A} uberdata_t;
2N/A
2N/A#define link_lock _link_lock.pad_lock
2N/A#define ld_lock _ld_lock.pad_lock
2N/A#define fork_lock _fork_lock.pad_lock
2N/A#define atfork_lock _atfork_lock.pad_lock
2N/A#define callout_lock _callout_lock.pad_lock
2N/A#define tdb_hash_lock _tdb_hash_lock.pad_lock
2N/A
2N/A#pragma align 64(__uberdata)
2N/Aextern uberdata_t __uberdata;
2N/Aextern uberdata_t **__tdb_bootstrap; /* known to libc_db and mdb */
2N/Aextern int primary_link_map;
2N/A
2N/A#define ulwp_mutex(ulwp, udp) \
2N/A (&(udp)->thr_hash_table[(ulwp)->ul_ix].hash_lock)
2N/A#define ulwp_condvar(ulwp, udp) \
2N/A (&(udp)->thr_hash_table[(ulwp)->ul_ix].hash_cond)
2N/A
2N/A/*
2N/A * Grab and release the hash table lock for the specified lwp.
2N/A */
2N/A#define ulwp_lock(ulwp, udp) lmutex_lock(ulwp_mutex(ulwp, udp))
2N/A#define ulwp_unlock(ulwp, udp) lmutex_unlock(ulwp_mutex(ulwp, udp))
2N/A
2N/A#ifdef _SYSCALL32 /* needed by libc_db */
2N/A
2N/Atypedef struct ulwp32 {
2N/A#if defined(__sparc)
2N/A uint32_t ul_dinstr; /* scratch space for dtrace */
2N/A uint32_t ul_padsparc0[15];
2N/A uint32_t ul_dsave; /* dtrace: save %g1, %g0, %sp */
2N/A uint32_t ul_drestore; /* dtrace: restore %g0, %g0, %g0 */
2N/A uint32_t ul_dftret; /* dtrace: return probe fasttrap */
2N/A uint32_t ul_dreturn; /* dtrace: return %o0 */
2N/A#endif
2N/A caddr32_t ul_self; /* pointer to self */
2N/A#if defined(__x86)
2N/A uint8_t ul_dinstr[40]; /* scratch space for dtrace */
2N/A#endif
2N/A caddr32_t ul_uberdata; /* uber (super-global) data */
2N/A tls32_t ul_tls; /* dynamic thread-local storage base */
2N/A caddr32_t ul_forw; /* forw, back all_lwps list, */
2N/A caddr32_t ul_back; /* protected by link_lock */
2N/A caddr32_t ul_next; /* list to keep track of stacks */
2N/A caddr32_t ul_hash; /* hash chain linked list */
2N/A caddr32_t ul_rval; /* return value from thr_exit() */
2N/A caddr32_t ul_stk; /* mapping base of the stack */
2N/A size32_t ul_mapsiz; /* mapping size of the stack */
2N/A size32_t ul_guardsize; /* normally _lpagesize */
2N/A caddr32_t ul_stktop; /* broken thr_stksegment() interface */
2N/A size32_t ul_stksiz; /* broken thr_stksegment() interface */
2N/A stack32_t ul_ustack; /* current stack boundaries */
2N/A int ul_ix; /* hash index */
2N/A lwpid_t ul_lwpid; /* thread id, aka the lwp id */
2N/A pri_t ul_pri; /* scheduling priority */
2N/A pri_t ul_epri; /* real-time ceiling priority */
2N/A char ul_policy; /* scheduling policy */
2N/A char ul_cid; /* scheduling class id */
2N/A union {
2N/A struct {
2N/A char cursig; /* deferred signal number */
2N/A char pleasestop; /* lwp requested to stop itself */
2N/A } s;
2N/A short curplease; /* for testing both at once */
2N/A } ul_cp;
2N/A char ul_stop; /* reason for stopping */
2N/A char ul_signalled; /* this lwp was cond_signal()d */
2N/A char ul_dead; /* this lwp has called thr_exit */
2N/A char ul_unwind; /* posix: unwind C++ stack */
2N/A char ul_detached; /* THR_DETACHED at thread_create() */
2N/A /* or pthread_detach() was called */
2N/A char ul_writer; /* sleeping in rw_wrlock() */
2N/A char ul_stopping; /* set by curthread: stopping self */
2N/A char ul_cancel_prologue; /* for _cancel_prologue() */
2N/A short ul_preempt; /* no_preempt()/preempt() */
2N/A short ul_savpreempt; /* pre-existing preempt value */
2N/A char ul_sigsuspend; /* thread is in sigsuspend/pollsys */
2N/A char ul_main; /* thread is the main thread */
2N/A char ul_fork; /* thread is performing a fork */
2N/A char ul_primarymap; /* primary link-map is initialized */
2N/A /* per-thread copies of the corresponding global variables */
2N/A uint8_t ul_max_spinners; /* thread_max_spinners */
2N/A char ul_door_noreserve; /* thread_door_noreserve */
2N/A char ul_queue_fifo; /* thread_queue_fifo */
2N/A char ul_cond_wait_defer; /* thread_cond_wait_defer */
2N/A char ul_error_detection; /* thread_error_detection */
2N/A char ul_async_safe; /* thread_async_safe */
2N/A char ul_rt; /* found on an RT queue */
2N/A char ul_rtqueued; /* was RT when queued */
2N/A char ul_misaligned; /* thread_locks_misaligned */
2N/A char ul_pad[3];
2N/A int ul_adaptive_spin; /* thread_adaptive_spin */
2N/A int ul_queue_spin; /* thread_queue_spin */
2N/A int ul_critical; /* non-zero == in a critical region */
2N/A int ul_sigdefer; /* non-zero == defer signals */
2N/A int ul_vfork; /* thread is the child of vfork() */
2N/A int ul_cancelable; /* _cancelon()/_canceloff() */
2N/A char ul_cancel_pending; /* pthread_cancel() was called */
2N/A char ul_cancel_disabled; /* PTHREAD_CANCEL_DISABLE */
2N/A char ul_cancel_async; /* PTHREAD_CANCEL_ASYNCHRONOUS */
2N/A char ul_save_async; /* saved copy of ul_cancel_async */
2N/A char ul_mutator; /* lwp is a mutator (java interface) */
2N/A char ul_created; /* created suspended */
2N/A char ul_replace; /* replacement; must be free()d */
2N/A uchar_t ul_nocancel; /* cancellation can't happen */
2N/A int ul_errno; /* per-thread errno */
2N/A caddr32_t ul_errnop; /* pointer to errno or self->ul_errno */
2N/A caddr32_t ul_clnup_hdr; /* head of cleanup handlers list */
2N/A caddr32_t ul_schedctl_called; /* ul_schedctl is set up */
2N/A caddr32_t ul_schedctl; /* schedctl data */
2N/A int ul_bindflags; /* bind_guard() interface to ld.so.1 */
2N/A uint_t ul_libc_locks; /* count of cancel_safe_mutex_lock()s */
2N/A caddr32_t ul_stsd; /* slow TLS for keys >= TSD_NFAST */
2N/A caddr32_t ul_ftsd[TSD_NFAST]; /* fast TLS for keys < TSD_NFAST */
2N/A td_evbuf32_t ul_td_evbuf; /* event buffer */
2N/A char ul_td_events_enable; /* event mechanism enabled */
2N/A char ul_sync_obj_reg; /* tdb_sync_obj_register() */
2N/A char ul_qtype; /* MX or CV */
2N/A char ul_cv_wake; /* != 0: just wake up, don't requeue */
2N/A int ul_rtld; /* thread is running inside ld.so.1 */
2N/A int ul_usropts; /* flags given to thr_create() */
2N/A caddr32_t ul_startpc; /* start func (thr_create()) */
2N/A caddr32_t ul_startarg; /* argument for start function */
2N/A caddr32_t ul_wchan; /* synch object when sleeping */
2N/A caddr32_t ul_link; /* sleep queue link */
2N/A caddr32_t ul_sleepq; /* sleep queue thread is waiting on */
2N/A caddr32_t ul_cvmutex; /* mutex dropped when waiting on a cv */
2N/A caddr32_t ul_mxchain; /* chain of owned ceiling mutexes */
2N/A int ul_save_state; /* bind_guard() interface to ld.so.1 */
2N/A uint_t ul_rdlockcnt; /* # entries in ul_readlock array */
2N/A /* 0 means there is but a single entry */
2N/A union { /* single entry or pointer to array */
2N/A readlock32_t single;
2N/A caddr32_t array;
2N/A } ul_readlock;
2N/A uint_t ul_heldlockcnt; /* # entries in ul_heldlocks array */
2N/A /* 0 means there is but a single entry */
2N/A union { /* single entry or pointer to array */
2N/A caddr32_t single;
2N/A caddr32_t array;
2N/A } ul_heldlocks;
2N/A /* PROBE_SUPPORT begin */
2N/A caddr32_t ul_tpdp;
2N/A /* PROBE_SUPPORT end */
2N/A caddr32_t ul_siglink; /* pointer to previous context */
2N/A uint_t ul_spin_lock_spin; /* spin lock statistics */
2N/A uint_t ul_spin_lock_spin2;
2N/A uint_t ul_spin_lock_sleep;
2N/A uint_t ul_spin_lock_wakeup;
2N/A queue_root32_t ul_queue_root; /* root of a sleep queue */
2N/A id_t ul_rtclassid; /* real-time class id */
2N/A uint_t ul_pilocks; /* count of PI locks held */
2N/A /* the following members *must* be last in the structure */
2N/A /* they are discarded when ulwp is replaced on thr_exit() */
2N/A sigset_t ul_sigmask; /* thread's current signal mask */
2N/A sigset_t ul_tmpmask; /* signal mask for sigsuspend/pollsys */
2N/A siginfo32_t ul_siginfo; /* deferred siginfo */
2N/A mutex_t ul_spinlock; /* used when suspending/continuing */
2N/A fpuenv32_t ul_fpuenv; /* floating point state */
2N/A caddr32_t ul_sp; /* stack pointer when blocked */
2N/A#if defined(sparc)
2N/A caddr32_t ul_unwind_ret; /* used only by _ex_clnup_handler() */
2N/A#endif
2N/A} ulwp32_t;
2N/A
2N/A#define REPLACEMENT_SIZE32 ((size_t)&((ulwp32_t *)NULL)->ul_sigmask)
2N/A
2N/Atypedef struct uberdata32 {
2N/A pad_lock_t _link_lock;
2N/A pad_lock_t _ld_lock;
2N/A pad_lock_t _fork_lock;
2N/A pad_lock_t _atfork_lock;
2N/A pad32_lock_t _callout_lock;
2N/A pad32_lock_t _tdb_hash_lock;
2N/A tdb_sync_stats_t tdb_hash_lock_stats;
2N/A siguaction32_t siguaction[NSIG];
2N/A bucket32_t bucket[NBUCKETS];
2N/A atexit_root32_t atexit_root;
2N/A tsd_metadata32_t tsd_metadata;
2N/A tls_metadata32_t tls_metadata;
2N/A char primary_map;
2N/A char bucket_init;
2N/A char pad[2];
2N/A uberflags_t uberflags;
2N/A caddr32_t queue_head;
2N/A caddr32_t thr_hash_table;
2N/A uint_t hash_size;
2N/A uint_t hash_mask;
2N/A caddr32_t ulwp_one;
2N/A caddr32_t all_lwps;
2N/A caddr32_t all_zombies;
2N/A int nthreads;
2N/A int nzombies;
2N/A int ndaemons;
2N/A int pid;
2N/A caddr32_t sigacthandler;
2N/A caddr32_t lwp_stacks;
2N/A caddr32_t lwp_laststack;
2N/A int nfreestack;
2N/A int thread_stack_cache;
2N/A caddr32_t ulwp_freelist;
2N/A caddr32_t ulwp_lastfree;
2N/A caddr32_t ulwp_replace_free;
2N/A caddr32_t ulwp_replace_last;
2N/A caddr32_t atforklist;
2N/A caddr32_t robustlocks;
2N/A caddr32_t robustlist;
2N/A caddr32_t progname;
2N/A caddr32_t tdb_bootstrap;
2N/A tdb32_t tdb;
2N/A} uberdata32_t;
2N/A
2N/A#endif /* _SYSCALL32 */
2N/A
2N/A/* ul_stop values */
2N/A#define TSTP_REGULAR 0x01 /* Stopped by thr_suspend() */
2N/A#define TSTP_MUTATOR 0x08 /* stopped by thr_suspend_*mutator*() */
2N/A#define TSTP_FORK 0x20 /* stopped by suspend_fork() */
2N/A
2N/A/*
2N/A * Implementation-specific attribute types for pthread_mutexattr_init() etc.
2N/A */
2N/A
2N/Atypedef struct _cvattr {
2N/A int pshared;
2N/A clockid_t clockid;
2N/A} cvattr_t;
2N/A
2N/Atypedef struct _mattr {
2N/A int pshared;
2N/A int protocol;
2N/A int prioceiling;
2N/A int type;
2N/A int robustness;
2N/A} mattr_t;
2N/A
2N/Atypedef struct _thrattr {
2N/A size_t stksize;
2N/A void *stkaddr;
2N/A int detachstate;
2N/A int daemonstate;
2N/A int scope;
2N/A int prio;
2N/A int policy;
2N/A int inherit;
2N/A size_t guardsize;
2N/A} thrattr_t;
2N/A
2N/Atypedef struct _rwlattr {
2N/A int pshared;
2N/A} rwlattr_t;
2N/A
2N/A/* _curthread() is inline for speed */
2N/Aextern ulwp_t *_curthread(void);
2N/A#define curthread (_curthread())
2N/A
2N/A/* this version (also inline) can be tested for NULL */
2N/Aextern ulwp_t *__curthread(void);
2N/A
2N/A/* get the current stack pointer (also inline) */
2N/Aextern greg_t stkptr(void);
2N/A
2N/A/*
2N/A * Suppress __attribute__((...)) if we are not compiling with gcc
2N/A */
2N/A#if !defined(__GNUC__)
2N/A#define __attribute__(string)
2N/A#endif
2N/A
2N/A/* Fetch the dispatch (kernel) priority of a thread */
2N/A#define real_priority(ulwp) \
2N/A ((ulwp)->ul_schedctl? (ulwp)->ul_schedctl->sc_priority : 0)
2N/A
2N/A/*
2N/A * Implementation functions. Not visible outside of the library itself.
2N/A */
2N/Aextern int __nanosleep(const timespec_t *, timespec_t *);
2N/Aextern void getgregs(ulwp_t *, gregset_t);
2N/Aextern void setgregs(ulwp_t *, gregset_t);
2N/Aextern void thr_panic(const char *);
2N/A#pragma rarely_called(thr_panic)
2N/Aextern ulwp_t *find_lwp(thread_t);
2N/Aextern void finish_init(void);
2N/Aextern void update_sched(ulwp_t *);
2N/Aextern void queue_alloc(void);
2N/Aextern void tsd_exit(void);
2N/Aextern void tsd_free(ulwp_t *);
2N/Aextern void tls_setup(void);
2N/Aextern void tls_exit(void);
2N/Aextern void tls_free(ulwp_t *);
2N/Aextern void rwl_free(ulwp_t *);
2N/Aextern void heldlock_exit(void);
2N/Aextern void heldlock_free(ulwp_t *);
2N/Aextern void sigacthandler(int, siginfo_t *, void *);
2N/Aextern void signal_init(void);
2N/Aextern int sigequalset(const sigset_t *, const sigset_t *);
2N/Aextern void mutex_setup(void);
2N/Aextern void take_deferred_signal(int);
2N/Aextern void *setup_top_frame(void *, size_t, ulwp_t *);
2N/Aextern int setup_context(ucontext_t *, void *(*func)(ulwp_t *),
2N/A ulwp_t *ulwp, caddr_t stk, size_t stksize);
2N/Aextern volatile sc_shared_t *setup_schedctl(void);
2N/Aextern void *lmalloc(size_t);
2N/Aextern void lfree(void *, size_t);
2N/Aextern void *libc_malloc(size_t);
2N/Aextern void *libc_realloc(void *, size_t);
2N/Aextern void libc_free(void *);
2N/Aextern char *libc_strdup(const char *);
2N/Aextern void ultos(uint64_t, int, char *);
2N/Aextern void lock_error(const mutex_t *, const char *, void *, const char *);
2N/Aextern void rwlock_error(const rwlock_t *, const char *, const char *);
2N/Aextern void thread_error(const char *);
2N/Aextern void grab_assert_lock(void);
2N/Aextern void dump_queue_statistics(void);
2N/Aextern void collect_queue_statistics(void);
2N/Aextern void record_spin_locks(ulwp_t *);
2N/Aextern void remember_lock(mutex_t *);
2N/Aextern void forget_lock(mutex_t *);
2N/Aextern void register_lock(mutex_t *);
2N/Aextern void unregister_locks(void);
2N/A#if defined(__sparc)
2N/Aextern void _flush_windows(void);
2N/A#else
2N/A#define _flush_windows()
2N/A#endif
2N/Aextern void set_curthread(void *);
2N/A
2N/A/*
2N/A * Utility function used when waking up many threads (more than MAXLWPS)
2N/A * all at once. See mutex_wakeup_all(), cond_broadcast(), and rw_unlock().
2N/A */
2N/A#define MAXLWPS 128 /* max remembered lwpids before overflow */
2N/A#define NEWLWPS 2048 /* max remembered lwpids at first overflow */
2N/Aextern lwpid_t *alloc_lwpids(lwpid_t *, int *, int *);
2N/A
2N/A/* enter a critical section */
2N/A#define enter_critical(self) (self->ul_critical++)
2N/A
2N/A/* exit a critical section, take deferred actions if necessary */
2N/Aextern void do_exit_critical(void);
2N/A#define exit_critical(self) \
2N/A (void) (self->ul_critical--, \
2N/A ((self->ul_curplease && self->ul_critical == 0)? \
2N/A (do_exit_critical(), 0) : 0))
2N/A
2N/A/*
2N/A * Like enter_critical()/exit_critical() but just for deferring signals.
2N/A * Unlike enter_critical()/exit_critical(), ul_sigdefer may be set while
2N/A * calling application functions like constructors and destructors.
2N/A * Care must be taken if the application function attempts to set
2N/A * the signal mask while a deferred signal is present; the setting
2N/A * of the signal mask must also be deferred.
2N/A */
2N/A#define sigoff(self) (self->ul_sigdefer++)
2N/A#define sigon(self) \
2N/A (void) ((--self->ul_sigdefer == 0 && \
2N/A self->ul_curplease && self->ul_critical == 0)? \
2N/A (do_exit_critical(), 0) : 0)
2N/A
2N/A/* these are exported functions */
2N/Aextern void _sigoff(void);
2N/Aextern void _sigon(void);
2N/A
2N/A#define sigorset(s1, s2) \
2N/A (((s1)->__sigbits[0] |= (s2)->__sigbits[0]), \
2N/A ((s1)->__sigbits[1] |= (s2)->__sigbits[1]), \
2N/A ((s1)->__sigbits[2] |= (s2)->__sigbits[2]), \
2N/A ((s1)->__sigbits[3] |= (s2)->__sigbits[3]))
2N/A
2N/A#define sigandset(s1, s2) \
2N/A (((s1)->__sigbits[0] &= (s2)->__sigbits[0]), \
2N/A ((s1)->__sigbits[1] &= (s2)->__sigbits[1]), \
2N/A ((s1)->__sigbits[2] &= (s2)->__sigbits[2]), \
2N/A ((s1)->__sigbits[3] &= (s2)->__sigbits[3]))
2N/A
2N/A#define sigdiffset(s1, s2) \
2N/A (((s1)->__sigbits[0] &= ~(s2)->__sigbits[0]), \
2N/A ((s1)->__sigbits[1] &= ~(s2)->__sigbits[1]), \
2N/A ((s1)->__sigbits[2] &= ~(s2)->__sigbits[2]), \
2N/A ((s1)->__sigbits[3] &= ~(s2)->__sigbits[3]))
2N/A
2N/A#define delete_reserved_signals(s) \
2N/A (((s)->__sigbits[0] &= MASKSET0), \
2N/A ((s)->__sigbits[1] &= (MASKSET1 & ~SIGMASK(SIGCANCEL))),\
2N/A ((s)->__sigbits[2] &= MASKSET2), \
2N/A ((s)->__sigbits[3] &= MASKSET3))
2N/A
2N/Aextern void block_all_signals(ulwp_t *self);
2N/A
2N/A/*
2N/A * When restoring the signal mask after having previously called
2N/A * block_all_signals(), if we have a deferred signal present then
2N/A * do nothing other than ASSERT() that we are in a critical region.
2N/A * The signal mask will be set when we emerge from the critical region
2N/A * and call take_deferred_signal(). There is no race condition here
2N/A * because the kernel currently has all signals blocked for this thread.
2N/A */
2N/A#define restore_signals(self) \
2N/A ((void) ((self)->ul_cursig? \
2N/A (ASSERT((self)->ul_critical + (self)->ul_sigdefer != 0), 0) : \
2N/A __lwp_sigmask(SIG_SETMASK, &(self)->ul_sigmask)))
2N/A
2N/Aextern void set_cancel_pending_flag(ulwp_t *, int);
2N/Aextern void set_cancel_eintr_flag(ulwp_t *);
2N/Aextern void set_parking_flag(ulwp_t *, int);
2N/Aextern int cancel_active(void);
2N/A
2N/Aextern void *_thrp_setup(ulwp_t *);
2N/Aextern void _fpinherit(ulwp_t *);
2N/Aextern void _lwp_start(void);
2N/Aextern void _lwp_terminate(void);
2N/Aextern void lmutex_lock(mutex_t *);
2N/Aextern void lmutex_unlock(mutex_t *);
2N/Aextern void lrw_rdlock(rwlock_t *);
2N/Aextern void lrw_wrlock(rwlock_t *);
2N/Aextern void lrw_unlock(rwlock_t *);
2N/Aextern void sig_mutex_lock(mutex_t *);
2N/Aextern void sig_mutex_unlock(mutex_t *);
2N/Aextern int sig_mutex_trylock(mutex_t *);
2N/Aextern int sig_cond_wait(cond_t *, mutex_t *);
2N/Aextern int sig_cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *);
2N/Aextern void cancel_safe_mutex_lock(mutex_t *);
2N/Aextern void cancel_safe_mutex_unlock(mutex_t *);
2N/Aextern int cancel_safe_mutex_trylock(mutex_t *);
2N/Aextern void _prefork_handler(void);
2N/Aextern void _postfork_parent_handler(void);
2N/Aextern void _postfork_child_handler(void);
2N/Aextern void postfork1_child(void);
2N/Aextern void postfork1_child_aio(void);
2N/Aextern void postfork1_child_sigev_aio(void);
2N/Aextern void postfork1_child_sigev_mq(void);
2N/Aextern void postfork1_child_sigev_timer(void);
2N/Aextern void postfork1_child_tpool(void);
2N/Aextern void fork_lock_enter(void);
2N/Aextern void fork_lock_exit(void);
2N/Aextern void suspend_fork(void);
2N/Aextern void continue_fork(int);
2N/Aextern void do_sigcancel(void);
2N/Aextern void setup_cancelsig(int);
2N/Aextern void init_sigev_thread(void);
2N/Aextern void init_aio(void);
2N/Aextern void init_progname(void);
2N/Aextern void _cancelon(void);
2N/Aextern void _canceloff(void);
2N/Aextern void _canceloff_nocancel(void);
2N/Aextern void _cancel_prologue(void);
2N/Aextern void _cancel_epilogue(void);
2N/Aextern void no_preempt(ulwp_t *);
2N/Aextern void preempt(ulwp_t *);
2N/Aextern void _thrp_unwind(void *);
2N/A
2N/Aextern pid_t __forkx(int);
2N/Aextern pid_t __forkallx(int);
2N/Aextern int __open(const char *, int, mode_t);
2N/Aextern int __open64(const char *, int, mode_t);
2N/Aextern int __openat(int, const char *, int, mode_t);
2N/Aextern int __openat64(int, const char *, int, mode_t);
2N/Aextern int __close(int);
2N/Aextern ssize_t __read(int, void *, size_t);
2N/Aextern ssize_t __write(int, const void *, size_t);
2N/Aextern int __fcntl(int, int, ...);
2N/Aextern int __lwp_continue(lwpid_t);
2N/Aextern int __lwp_create(ucontext_t *, uint_t, lwpid_t *);
2N/Aextern int ___lwp_suspend(lwpid_t);
2N/Aextern int lwp_wait(lwpid_t, lwpid_t *);
2N/Aextern int __lwp_wait(lwpid_t, lwpid_t *);
2N/Aextern int __lwp_detach(lwpid_t);
2N/Aextern sc_shared_t *__schedctl(void);
2N/A
2N/A/* actual system call traps */
2N/Aextern int __setcontext(const ucontext_t *);
2N/Aextern int __getcontext(ucontext_t *);
2N/Aextern int __clock_gettime(clockid_t, timespec_t *);
2N/Aextern void abstime_to_reltime(clockid_t, const timespec_t *, timespec_t *);
2N/Aextern void hrt2ts(hrtime_t, timespec_t *);
2N/A
2N/Aextern int __sigaction(int, const struct sigaction *, struct sigaction *);
2N/Aextern int __sigprocmask(int, const sigset_t *, sigset_t *);
2N/Aextern int __lwp_sigmask(int, const sigset_t *);
2N/Aextern void __sighndlr(int, siginfo_t *, ucontext_t *, void (*)());
2N/Aextern caddr_t __sighndlrend;
2N/A#pragma unknown_control_flow(__sighndlr)
2N/Aextern int __sigqueue(pid_t, int, /* const union sigval */ void *, int,
2N/A const timespec_t *);
2N/A
2N/A/* belongs in <pthread.h> */
2N/A#define PTHREAD_CREATE_DAEMON_NP 0x100 /* = THR_DAEMON */
2N/A#define PTHREAD_CREATE_NONDAEMON_NP 0
2N/Aextern int pthread_attr_setdaemonstate_np(pthread_attr_t *, int);
2N/Aextern int pthread_attr_getdaemonstate_np(const pthread_attr_t *, int *);
2N/A
2N/Aextern int mutex_held(mutex_t *);
2N/Aextern int mutex_lock_internal(mutex_t *, timespec_t *, int);
2N/Aextern int mutex_unlock_internal(mutex_t *, int);
2N/A
2N/A/* not cancellation points: */
2N/Aextern int __cond_wait(cond_t *, mutex_t *);
2N/Aextern int __cond_timedwait(cond_t *, mutex_t *, const timespec_t *);
2N/Aextern int __cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *);
2N/A
2N/Aextern int rw_read_held(rwlock_t *);
2N/Aextern int rw_write_held(rwlock_t *);
2N/A
2N/Aextern int _thrp_create(void *, size_t, void *(*)(void *), void *, long,
2N/A thread_t *, size_t);
2N/Aextern int _thrp_suspend(thread_t, uchar_t);
2N/Aextern int _thrp_continue(thread_t, uchar_t);
2N/A
2N/Aextern void _thrp_terminate(void *);
2N/Aextern void _thrp_exit(void);
2N/A
2N/Aextern const pcclass_t *get_info_by_class(id_t);
2N/Aextern const pcclass_t *get_info_by_policy(int);
2N/Aextern const thrattr_t *def_thrattr(void);
2N/Aextern id_t setparam(idtype_t, id_t, int, int);
2N/Aextern id_t setprio(idtype_t, id_t, int, int *);
2N/Aextern id_t getparam(idtype_t, id_t, int *, struct sched_param *);
2N/A
2N/A/*
2N/A * System call wrappers (direct interfaces to the kernel)
2N/A */
2N/Aextern int ___lwp_mutex_register(mutex_t *, mutex_t **);
2N/Aextern int ___lwp_mutex_trylock(mutex_t *, ulwp_t *);
2N/Aextern int ___lwp_mutex_timedlock(mutex_t *, timespec_t *, ulwp_t *);
2N/Aextern int ___lwp_mutex_unlock(mutex_t *);
2N/Aextern int ___lwp_mutex_wakeup(mutex_t *, int);
2N/Aextern int ___lwp_cond_wait(cond_t *, mutex_t *, timespec_t *, int);
2N/Aextern int ___lwp_sema_timedwait(lwp_sema_t *, timespec_t *, int);
2N/Aextern int __lwp_rwlock_rdlock(rwlock_t *, timespec_t *);
2N/Aextern int __lwp_rwlock_wrlock(rwlock_t *, timespec_t *);
2N/Aextern int __lwp_rwlock_tryrdlock(rwlock_t *);
2N/Aextern int __lwp_rwlock_trywrlock(rwlock_t *);
2N/Aextern int __lwp_rwlock_unlock(rwlock_t *);
2N/Aextern int __lwp_park(timespec_t *, lwpid_t);
2N/Aextern int __lwp_unpark(lwpid_t);
2N/Aextern int __lwp_unpark_all(lwpid_t *, int);
2N/A#if defined(__x86)
2N/Aextern int ___lwp_private(int, int, void *);
2N/A#endif /* __x86 */
2N/A
2N/A/*
2N/A * inlines
2N/A */
2N/Aextern int set_lock_byte(volatile uint8_t *);
2N/Aextern uint32_t atomic_swap_32(volatile uint32_t *, uint32_t);
2N/Aextern uint32_t atomic_cas_32(volatile uint32_t *, uint32_t, uint32_t);
2N/Aextern void atomic_inc_32(volatile uint32_t *);
2N/Aextern void atomic_dec_32(volatile uint32_t *);
2N/Aextern void atomic_and_32(volatile uint32_t *, uint32_t);
2N/Aextern void atomic_or_32(volatile uint32_t *, uint32_t);
2N/A#if defined(__sparc)
2N/Aextern ulong_t caller(void);
2N/Aextern ulong_t getfp(void);
2N/A#endif /* __sparc */
2N/A#if defined(__x86)
2N/Aextern void libc_fpu_init(void);
2N/A#endif /* __x86 */
2N/A
2N/A#include "thr_inlines.h"
2N/A
2N/A#endif /* _THR_UBERDATA_H */