10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51885Sraf * Common Development and Distribution License (the "License"). 61885Sraf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211016Sraf 220Sstevel@tonic-gate /* 23*13093SRoger.Faulkner@Oracle.COM * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _THR_UBERDATA_H 270Sstevel@tonic-gate #define _THR_UBERDATA_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <stdlib.h> 300Sstevel@tonic-gate #include <unistd.h> 310Sstevel@tonic-gate #include <sys/types.h> 320Sstevel@tonic-gate #include <fcntl.h> 330Sstevel@tonic-gate #include <string.h> 340Sstevel@tonic-gate #include <signal.h> 350Sstevel@tonic-gate #include <ucontext.h> 360Sstevel@tonic-gate #include <thread.h> 370Sstevel@tonic-gate #include <pthread.h> 386812Sraf #include <atomic.h> 390Sstevel@tonic-gate #include <link.h> 400Sstevel@tonic-gate #include <sys/resource.h> 410Sstevel@tonic-gate #include <sys/lwp.h> 420Sstevel@tonic-gate #include <errno.h> 430Sstevel@tonic-gate #include <sys/asm_linkage.h> 440Sstevel@tonic-gate #include <sys/regset.h> 450Sstevel@tonic-gate #include <sys/fcntl.h> 460Sstevel@tonic-gate #include <sys/mman.h> 470Sstevel@tonic-gate #include <synch.h> 480Sstevel@tonic-gate #include <door.h> 490Sstevel@tonic-gate #include <limits.h> 500Sstevel@tonic-gate #include <sys/synch32.h> 510Sstevel@tonic-gate #include <schedctl.h> 520Sstevel@tonic-gate #include <sys/priocntl.h> 530Sstevel@tonic-gate #include <thread_db.h> 542248Sraf #include <setjmp.h> 550Sstevel@tonic-gate #include "libc_int.h" 560Sstevel@tonic-gate #include "tdb_agent.h" 572248Sraf #include "thr_debug.h" 581885Sraf 590Sstevel@tonic-gate /* 600Sstevel@tonic-gate * This is an implementation-specific include file for threading support. 610Sstevel@tonic-gate * It is not to be seen by the clients of the library. 620Sstevel@tonic-gate * 630Sstevel@tonic-gate * This file also describes uberdata in libc. 640Sstevel@tonic-gate * 650Sstevel@tonic-gate * The term "uberdata" refers to data that is unique and visible across 660Sstevel@tonic-gate * all link maps. The name is meant to imply that such data is truly 670Sstevel@tonic-gate * global, not just locally global to a particular link map. 680Sstevel@tonic-gate * 690Sstevel@tonic-gate * See the Linker and Libraries Guide for a full description of alternate 700Sstevel@tonic-gate * link maps and how they are set up and used. 710Sstevel@tonic-gate * 720Sstevel@tonic-gate * Alternate link maps implement multiple global namespaces within a single 730Sstevel@tonic-gate * process. There may be multiple instances of identical dynamic libraries 740Sstevel@tonic-gate * loaded in a process's address space at the same time, each on a different 750Sstevel@tonic-gate * link map (as determined by the dynamic linker), each with its own set of 760Sstevel@tonic-gate * global variables. Which particular instance of a global variable is seen 770Sstevel@tonic-gate * by a thread running in the process is determined by the link map on which 780Sstevel@tonic-gate * the thread happens to be executing at the time. 790Sstevel@tonic-gate * 800Sstevel@tonic-gate * However, there are aspects of a process that are unique across all 810Sstevel@tonic-gate * link maps, in particular the structures used to implement threads 820Sstevel@tonic-gate * of control (in Sparc terminology, there is only one %g7 regardless 830Sstevel@tonic-gate * of the link map on which the thread is executing). 840Sstevel@tonic-gate * 850Sstevel@tonic-gate * All uberdata is referenced from a base pointer in the thread's ulwp_t 860Sstevel@tonic-gate * structure (which is also uberdata). All allocations and deallocations 870Sstevel@tonic-gate * of uberdata are made via the uberdata-aware lmalloc() and lfree() 880Sstevel@tonic-gate * interfaces (malloc() and free() are simply locally-global). 890Sstevel@tonic-gate */ 900Sstevel@tonic-gate 910Sstevel@tonic-gate /* 920Sstevel@tonic-gate * Special libc-private access to errno. 930Sstevel@tonic-gate * We do this so that references to errno do not invoke the dynamic linker. 940Sstevel@tonic-gate */ 950Sstevel@tonic-gate #undef errno 960Sstevel@tonic-gate #define errno (*curthread->ul_errnop) 970Sstevel@tonic-gate 980Sstevel@tonic-gate /* 990Sstevel@tonic-gate * See <sys/synch32.h> for the reasons for these values 1000Sstevel@tonic-gate * and why they are different for sparc and intel. 1010Sstevel@tonic-gate */ 1020Sstevel@tonic-gate #if defined(__sparc) 1036057Sraf 1040Sstevel@tonic-gate /* lock.lock64.pad[x] 4 5 6 7 */ 1050Sstevel@tonic-gate #define LOCKMASK 0xff000000 1060Sstevel@tonic-gate #define WAITERMASK 0x000000ff 1075629Sraf #define SPINNERMASK 0x00ff0000 1085629Sraf #define SPINNERSHIFT 16 1090Sstevel@tonic-gate #define WAITER 0x00000001 1100Sstevel@tonic-gate #define LOCKSET 0xff 1110Sstevel@tonic-gate #define LOCKCLEAR 0 1126057Sraf 1136057Sraf #define PIDSHIFT 32 1146057Sraf #define LOCKMASK64 0xffffffffff000000ULL 1156057Sraf #define LOCKBYTE64 0x00000000ff000000ULL 1166057Sraf #define WAITERMASK64 0x00000000000000ffULL 1176057Sraf #define SPINNERMASK64 0x0000000000ff0000ULL 1186057Sraf 1191016Sraf #elif defined(__x86) 1206057Sraf 1210Sstevel@tonic-gate /* lock.lock64.pad[x] 7 6 5 4 */ 1220Sstevel@tonic-gate #define LOCKMASK 0xff000000 1230Sstevel@tonic-gate #define WAITERMASK 0x00ff0000 1245629Sraf #define SPINNERMASK 0x0000ff00 1255629Sraf #define SPINNERSHIFT 8 1260Sstevel@tonic-gate #define WAITER 0x00010000 1270Sstevel@tonic-gate #define LOCKSET 0x01 1280Sstevel@tonic-gate #define LOCKCLEAR 0 1296057Sraf 1306057Sraf #define PIDSHIFT 0 1316057Sraf #define LOCKMASK64 0xff000000ffffffffULL 1326057Sraf #define LOCKBYTE64 0x0100000000000000ULL 1336057Sraf #define WAITERMASK64 0x00ff000000000000ULL 1346057Sraf #define SPINNERMASK64 0x0000ff0000000000ULL 1356057Sraf 1360Sstevel@tonic-gate #else 1371016Sraf #error "neither __sparc nor __x86 is defined" 1380Sstevel@tonic-gate #endif 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate /* 1410Sstevel@tonic-gate * Fetch the owner of a USYNC_THREAD mutex. 1420Sstevel@tonic-gate * Don't use this with process-shared mutexes; 1430Sstevel@tonic-gate * the owing thread may be in a different process. 1440Sstevel@tonic-gate */ 1450Sstevel@tonic-gate #define MUTEX_OWNER(mp) ((ulwp_t *)(uintptr_t)(mp)->mutex_owner) 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate /* 1484574Sraf * Test if a thread owns a process-private (USYNC_THREAD) mutex. 1494574Sraf * This is inappropriate for a process-shared (USYNC_PROCESS) mutex. 1500Sstevel@tonic-gate * The 'mp' argument must not have side-effects since it is evaluated twice. 1510Sstevel@tonic-gate */ 1520Sstevel@tonic-gate #define MUTEX_OWNED(mp, thrp) \ 1530Sstevel@tonic-gate ((mp)->mutex_lockw != 0 && MUTEX_OWNER(mp) == thrp) 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate /* 1570Sstevel@tonic-gate * uberflags.uf_tdb_register_sync is an interface with libc_db to enable the 1580Sstevel@tonic-gate * collection of lock statistics by a debugger or other collecting tool. 1590Sstevel@tonic-gate * 1600Sstevel@tonic-gate * uberflags.uf_thread_error_detection is set by an environment variable: 1610Sstevel@tonic-gate * _THREAD_ERROR_DETECTION 1620Sstevel@tonic-gate * 0 == no detection of locking primitive errors. 1630Sstevel@tonic-gate * 1 == detect errors and issue a warning message. 1640Sstevel@tonic-gate * 2 == detect errors, issue a warning message, and dump core. 1650Sstevel@tonic-gate * 1660Sstevel@tonic-gate * We bundle these together in uberflags.uf_trs_ted to make a test of either 1670Sstevel@tonic-gate * being non-zero a single memory reference (for speed of mutex_lock(), etc). 1680Sstevel@tonic-gate * 1690Sstevel@tonic-gate * uberflags.uf_mt is set non-zero when the first thread (in addition 1700Sstevel@tonic-gate * to the main thread) is created. 1710Sstevel@tonic-gate * 1720Sstevel@tonic-gate * We bundle all these flags together in uberflags.uf_all to make a test 1730Sstevel@tonic-gate * of any being non-zero a single memory reference (again, for speed). 1740Sstevel@tonic-gate */ 1750Sstevel@tonic-gate typedef union { 1760Sstevel@tonic-gate int uf_all; /* combined all flags */ 1770Sstevel@tonic-gate struct { 1780Sstevel@tonic-gate short h_pad; 1790Sstevel@tonic-gate short h_trs_ted; /* combined reg sync & error detect */ 1800Sstevel@tonic-gate } uf_h; 1810Sstevel@tonic-gate struct { 1820Sstevel@tonic-gate char x_mt; 1830Sstevel@tonic-gate char x_pad; 1840Sstevel@tonic-gate char x_tdb_register_sync; 1850Sstevel@tonic-gate char x_thread_error_detection; 1860Sstevel@tonic-gate } uf_x; 1870Sstevel@tonic-gate } uberflags_t; 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate #define uf_mt uf_x.x_mt 1900Sstevel@tonic-gate #define uf_tdb_register_sync uf_x.x_tdb_register_sync 1910Sstevel@tonic-gate #define uf_thread_error_detection uf_x.x_thread_error_detection 1920Sstevel@tonic-gate #define uf_trs_ted uf_h.h_trs_ted /* both of the above */ 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate /* 1950Sstevel@tonic-gate * NOTE WELL: 1960Sstevel@tonic-gate * To enable further optimization, the "ul_schedctl_called" member 1970Sstevel@tonic-gate * of the ulwp_t structure (below) serves double-duty: 1980Sstevel@tonic-gate * 1. If NULL, it means that the thread must call __schedctl() 1990Sstevel@tonic-gate * to set up its schedctl mappings before acquiring a mutex. 2000Sstevel@tonic-gate * This is required by the implementation of adaptive mutex locking. 2010Sstevel@tonic-gate * 2. If non-NULL, it points to uberdata.uberflags, so that tests of 2020Sstevel@tonic-gate * uberflags can be made without additional memory references. 2030Sstevel@tonic-gate * This allows the common case of _mutex_lock() and _mutex_unlock() for 2040Sstevel@tonic-gate * USYNC_THREAD mutexes with no error detection and no lock statistics 2050Sstevel@tonic-gate * to be optimized for speed. 2060Sstevel@tonic-gate */ 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate /* double the default stack size for 64-bit processes */ 2090Sstevel@tonic-gate #ifdef _LP64 2100Sstevel@tonic-gate #define MINSTACK (8 * 1024) 2110Sstevel@tonic-gate #define DEFAULTSTACK (2 * 1024 * 1024) 2120Sstevel@tonic-gate #else 2130Sstevel@tonic-gate #define MINSTACK (4 * 1024) 2140Sstevel@tonic-gate #define DEFAULTSTACK (1024 * 1024) 2150Sstevel@tonic-gate #endif 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate #define MUTEX_TRY 0 2180Sstevel@tonic-gate #define MUTEX_LOCK 1 2196247Sraf #define MUTEX_NOCEIL 0x40 2200Sstevel@tonic-gate 2211016Sraf #if defined(__x86) 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate typedef struct { /* structure returned by fnstenv */ 2240Sstevel@tonic-gate int fctrl; /* control word */ 2250Sstevel@tonic-gate int fstat; /* status word (flags, etc) */ 2260Sstevel@tonic-gate int ftag; /* tag of which regs busy */ 2270Sstevel@tonic-gate int misc[4]; /* other stuff, 28 bytes total */ 2280Sstevel@tonic-gate } fpuenv_t; 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate #ifdef _SYSCALL32 2310Sstevel@tonic-gate typedef fpuenv_t fpuenv32_t; 2320Sstevel@tonic-gate #endif /* _SYSCALL32 */ 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate #elif defined(__sparc) 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate typedef struct { /* fp state structure */ 2370Sstevel@tonic-gate greg_t fsr; 2380Sstevel@tonic-gate greg_t fpu_en; 2390Sstevel@tonic-gate } fpuenv_t; 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate #ifdef _SYSCALL32 2420Sstevel@tonic-gate typedef struct { 2430Sstevel@tonic-gate greg32_t fsr; 2440Sstevel@tonic-gate greg32_t fpu_en; 2450Sstevel@tonic-gate } fpuenv32_t; 2460Sstevel@tonic-gate #endif /* _SYSCALL32 */ 2470Sstevel@tonic-gate 2481016Sraf #endif /* __x86 */ 2490Sstevel@tonic-gate 2501016Sraf #if defined(__x86) 2510Sstevel@tonic-gate extern void ht_pause(void); /* "pause" instruction */ 2520Sstevel@tonic-gate #define SMT_PAUSE() ht_pause() 2539202SJason.Beloro@Sun.COM #elif defined(SMT_PAUSE_FUNCTION) 2549202SJason.Beloro@Sun.COM extern void SMT_PAUSE_FUNCTION(void); 2559202SJason.Beloro@Sun.COM #define SMT_PAUSE() SMT_PAUSE_FUNCTION() 2560Sstevel@tonic-gate #else 25713081SChris.Kiick@Sun.COM #define SMT_PAUSE() smt_pause() 2581016Sraf #endif /* __x86 */ 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate /* 2610Sstevel@tonic-gate * Cleanup handler related data. 2620Sstevel@tonic-gate * This structure is exported as _cleanup_t in pthread.h. 2630Sstevel@tonic-gate * pthread.h exports only the size of this structure, so check 2640Sstevel@tonic-gate * _cleanup_t in pthread.h before making any change here. 2650Sstevel@tonic-gate */ 2660Sstevel@tonic-gate typedef struct __cleanup { 2670Sstevel@tonic-gate struct __cleanup *next; /* pointer to next handler */ 2680Sstevel@tonic-gate caddr_t fp; /* current frame pointer */ 2690Sstevel@tonic-gate void (*func)(void *); /* cleanup handler address */ 2700Sstevel@tonic-gate void *arg; /* handler's argument */ 2710Sstevel@tonic-gate } __cleanup_t; 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate /* 2740Sstevel@tonic-gate * Thread-Specific Data (TSD) 2750Sstevel@tonic-gate * TSD_NFAST includes the invalid key zero, so there 2760Sstevel@tonic-gate * are really only (TSD_NFAST - 1) fast key slots. 2770Sstevel@tonic-gate */ 2780Sstevel@tonic-gate typedef void (*PFrV)(void *); 2790Sstevel@tonic-gate #define TSD_UNALLOCATED ((PFrV)1) 2800Sstevel@tonic-gate #define TSD_NFAST 9 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate /* 2830Sstevel@tonic-gate * The tsd union is designed to burn a little memory (9 words) to make 2840Sstevel@tonic-gate * lookups blindingly fast. Note that tsd_nalloc could be placed at the 2850Sstevel@tonic-gate * end of the pad region to increase the likelihood that it falls on the 2860Sstevel@tonic-gate * same cache line as the data. 2870Sstevel@tonic-gate */ 2880Sstevel@tonic-gate typedef union tsd { 2890Sstevel@tonic-gate uint_t tsd_nalloc; /* Amount of allocated storage */ 2900Sstevel@tonic-gate void *tsd_pad[TSD_NFAST]; 2910Sstevel@tonic-gate void *tsd_data[1]; 2920Sstevel@tonic-gate } tsd_t; 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate typedef struct { 2950Sstevel@tonic-gate mutex_t tsdm_lock; /* Lock protecting the data */ 2960Sstevel@tonic-gate uint_t tsdm_nkeys; /* Number of allocated keys */ 2970Sstevel@tonic-gate uint_t tsdm_nused; /* Number of used keys */ 2980Sstevel@tonic-gate PFrV *tsdm_destro; /* Per-key destructors */ 2990Sstevel@tonic-gate char tsdm_pad[64 - /* pad to 64 bytes */ 3000Sstevel@tonic-gate (sizeof (mutex_t) + 2 * sizeof (uint_t) + sizeof (PFrV *))]; 3010Sstevel@tonic-gate } tsd_metadata_t; 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate #ifdef _SYSCALL32 3040Sstevel@tonic-gate typedef union tsd32 { 3050Sstevel@tonic-gate uint_t tsd_nalloc; /* Amount of allocated storage */ 3060Sstevel@tonic-gate caddr32_t tsd_pad[TSD_NFAST]; 3070Sstevel@tonic-gate caddr32_t tsd_data[1]; 3080Sstevel@tonic-gate } tsd32_t; 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate typedef struct { 3110Sstevel@tonic-gate mutex_t tsdm_lock; /* Lock protecting the data */ 3120Sstevel@tonic-gate uint_t tsdm_nkeys; /* Number of allocated keys */ 3130Sstevel@tonic-gate uint_t tsdm_nused; /* Number of used keys */ 3140Sstevel@tonic-gate caddr32_t tsdm_destro; /* Per-key destructors */ 3150Sstevel@tonic-gate char tsdm_pad[64 - /* pad to 64 bytes */ 3160Sstevel@tonic-gate (sizeof (mutex_t) + 2 * sizeof (uint_t) + sizeof (caddr32_t))]; 3170Sstevel@tonic-gate } tsd_metadata32_t; 3180Sstevel@tonic-gate #endif /* _SYSCALL32 */ 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate /* 3220Sstevel@tonic-gate * Thread-Local Storage (TLS) 3230Sstevel@tonic-gate */ 3240Sstevel@tonic-gate typedef struct { 3250Sstevel@tonic-gate void *tls_data; 3260Sstevel@tonic-gate size_t tls_size; 3270Sstevel@tonic-gate } tls_t; 3280Sstevel@tonic-gate 3290Sstevel@tonic-gate typedef struct { 3300Sstevel@tonic-gate mutex_t tls_lock; /* Lock protecting the data */ 3310Sstevel@tonic-gate tls_t tls_modinfo; /* Root of all TLS_modinfo data */ 3320Sstevel@tonic-gate tls_t static_tls; /* Template for static TLS */ 3330Sstevel@tonic-gate char tls_pad[64 - /* pad to 64 bytes */ 3340Sstevel@tonic-gate (sizeof (mutex_t) + 2 * sizeof (tls_t))]; 3350Sstevel@tonic-gate } tls_metadata_t; 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate #ifdef _SYSCALL32 3380Sstevel@tonic-gate typedef struct { 3390Sstevel@tonic-gate caddr32_t tls_data; 3400Sstevel@tonic-gate size32_t tls_size; 3410Sstevel@tonic-gate } tls32_t; 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate typedef struct { 3440Sstevel@tonic-gate mutex_t tls_lock; /* Lock protecting the data */ 3450Sstevel@tonic-gate tls32_t tls_modinfo; /* Root of all TLS_modinfo data */ 3460Sstevel@tonic-gate tls32_t static_tls; /* Template for static TLS */ 3470Sstevel@tonic-gate char tls_pad[64 - /* pad to 64 bytes */ 3480Sstevel@tonic-gate (sizeof (mutex_t) + 2 * sizeof (tls32_t))]; 3490Sstevel@tonic-gate } tls_metadata32_t; 3500Sstevel@tonic-gate #endif /* _SYSCALL32 */ 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate 3530Sstevel@tonic-gate /* 3546247Sraf * Sleep queue root for USYNC_THREAD condvars and mutexes. 3556247Sraf * There is a default queue root for each queue head (see below). 3566247Sraf * Also, each ulwp_t contains a queue root that can be used 3576247Sraf * when the thread is enqueued on the queue, if necessary 3586247Sraf * (when more than one wchan hashes to the same queue head). 3596247Sraf */ 3606247Sraf typedef struct queue_root { 3616247Sraf struct queue_root *qr_next; 3626247Sraf struct queue_root *qr_prev; 3636247Sraf struct ulwp *qr_head; 3646247Sraf struct ulwp *qr_tail; 3656247Sraf void *qr_wchan; 3666247Sraf uint32_t qr_rtcount; 3676247Sraf uint32_t qr_qlen; 3686247Sraf uint32_t qr_qmax; 3696247Sraf } queue_root_t; 3706247Sraf 3716247Sraf #ifdef _SYSCALL32 3726247Sraf typedef struct queue_root32 { 3736247Sraf caddr32_t qr_next; 3746247Sraf caddr32_t qr_prev; 3756247Sraf caddr32_t qr_head; 3766247Sraf caddr32_t qr_tail; 3776247Sraf caddr32_t qr_wchan; 3786247Sraf uint32_t qr_rtcount; 3796247Sraf uint32_t qr_qlen; 3806247Sraf uint32_t qr_qmax; 3816247Sraf } queue_root32_t; 3826247Sraf #endif 3836247Sraf 3846247Sraf /* 3856247Sraf * Sleep queue heads for USYNC_THREAD condvars and mutexes. 3866247Sraf * The size and alignment is 128 bytes to reduce cache conflicts. 3876247Sraf * Each queue head points to a list of queue roots, defined above. 3886247Sraf * Each queue head contains a default queue root for use when only one 3896247Sraf * is needed. It is always at the tail of the queue root hash chain. 3900Sstevel@tonic-gate */ 3910Sstevel@tonic-gate typedef union { 3926247Sraf uint64_t qh_64[16]; 3930Sstevel@tonic-gate struct { 3940Sstevel@tonic-gate mutex_t q_lock; 3950Sstevel@tonic-gate uint8_t q_qcnt; 3966247Sraf uint8_t q_type; /* MX or CV */ 3976247Sraf uint8_t q_pad1[2]; 3986247Sraf uint32_t q_lockcount; 3990Sstevel@tonic-gate uint32_t q_qlen; 4000Sstevel@tonic-gate uint32_t q_qmax; 4016247Sraf void *q_wchan; /* valid only while locked */ 4026247Sraf struct queue_root *q_root; /* valid only while locked */ 4036247Sraf struct queue_root *q_hlist; 4046247Sraf #if !defined(_LP64) 4056247Sraf caddr_t q_pad2[3]; 4066247Sraf #endif 4076247Sraf queue_root_t q_def_root; 4086247Sraf uint32_t q_hlen; 4096247Sraf uint32_t q_hmax; 4100Sstevel@tonic-gate } qh_qh; 4110Sstevel@tonic-gate } queue_head_t; 4120Sstevel@tonic-gate 4130Sstevel@tonic-gate #define qh_lock qh_qh.q_lock 4140Sstevel@tonic-gate #define qh_qcnt qh_qh.q_qcnt 4156247Sraf #define qh_type qh_qh.q_type 4166247Sraf #if defined(THREAD_DEBUG) 4170Sstevel@tonic-gate #define qh_lockcount qh_qh.q_lockcount 4180Sstevel@tonic-gate #define qh_qlen qh_qh.q_qlen 4190Sstevel@tonic-gate #define qh_qmax qh_qh.q_qmax 4206247Sraf #endif 4216247Sraf #define qh_wchan qh_qh.q_wchan 4226247Sraf #define qh_root qh_qh.q_root 4236247Sraf #define qh_hlist qh_qh.q_hlist 4246247Sraf #define qh_def_root qh_qh.q_def_root 4256247Sraf #define qh_hlen qh_qh.q_hlen 4266247Sraf #define qh_hmax qh_qh.q_hmax 4270Sstevel@tonic-gate 4286247Sraf /* queue types passed to queue_lock() */ 4290Sstevel@tonic-gate #define MX 0 4300Sstevel@tonic-gate #define CV 1 4314574Sraf #define QHASHSHIFT 9 /* number of hashing bits */ 4324574Sraf #define QHASHSIZE (1 << QHASHSHIFT) /* power of 2 (1<<9 == 512) */ 4334574Sraf #define QUEUE_HASH(wchan, type) ((uint_t) \ 4344574Sraf ((((uintptr_t)(wchan) >> 3) \ 4354574Sraf ^ ((uintptr_t)(wchan) >> (QHASHSHIFT + 3))) \ 4360Sstevel@tonic-gate & (QHASHSIZE - 1)) + (((type) == MX)? 0 : QHASHSIZE)) 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate extern queue_head_t *queue_lock(void *, int); 4390Sstevel@tonic-gate extern void queue_unlock(queue_head_t *); 4406247Sraf extern void enqueue(queue_head_t *, struct ulwp *, int); 4416247Sraf extern struct ulwp *dequeue(queue_head_t *, int *); 4426247Sraf extern struct ulwp **queue_slot(queue_head_t *, struct ulwp **, int *); 4436247Sraf extern struct ulwp *queue_waiter(queue_head_t *); 4446247Sraf extern int dequeue_self(queue_head_t *); 4456247Sraf extern void queue_unlink(queue_head_t *, 4464570Sraf struct ulwp **, struct ulwp *); 4470Sstevel@tonic-gate extern void unsleep_self(void); 4480Sstevel@tonic-gate extern void spin_lock_set(mutex_t *); 4490Sstevel@tonic-gate extern void spin_lock_clear(mutex_t *); 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate /* 4526247Sraf * Scheduling class information structure. 4536247Sraf */ 4546247Sraf typedef struct { 4556247Sraf short pcc_state; 4566247Sraf short pcc_policy; 4576247Sraf pri_t pcc_primin; 4586247Sraf pri_t pcc_primax; 4596247Sraf pcinfo_t pcc_info; 4606247Sraf } pcclass_t; 4616247Sraf 4626247Sraf /* 4630Sstevel@tonic-gate * Memory block for chain of owned ceiling mutexes. 4640Sstevel@tonic-gate */ 4650Sstevel@tonic-gate typedef struct mxchain { 4660Sstevel@tonic-gate struct mxchain *mxchain_next; 4670Sstevel@tonic-gate mutex_t *mxchain_mx; 4680Sstevel@tonic-gate } mxchain_t; 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate /* 4710Sstevel@tonic-gate * Pointer to an rwlock that is held for reading. 4720Sstevel@tonic-gate * Used in rw_rdlock() to allow a thread that already holds a read 4730Sstevel@tonic-gate * lock to acquire another read lock on the same rwlock even if 4740Sstevel@tonic-gate * there are writers waiting. This to avoid deadlock when acquiring 4750Sstevel@tonic-gate * a read lock more than once in the presence of pending writers. 4760Sstevel@tonic-gate * POSIX mandates this behavior. 4770Sstevel@tonic-gate */ 4780Sstevel@tonic-gate typedef struct { 4790Sstevel@tonic-gate void *rd_rwlock; /* the rwlock held for reading */ 4800Sstevel@tonic-gate size_t rd_count; /* count of read locks applied */ 4810Sstevel@tonic-gate } readlock_t; 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate #ifdef _SYSCALL32 4840Sstevel@tonic-gate typedef struct { 4850Sstevel@tonic-gate caddr32_t rd_rwlock; 4860Sstevel@tonic-gate size32_t rd_count; 4870Sstevel@tonic-gate } readlock32_t; 4880Sstevel@tonic-gate #endif /* _SYSCALL32 */ 4890Sstevel@tonic-gate 4900Sstevel@tonic-gate /* 4910Sstevel@tonic-gate * Maximum number of read locks allowed for one thread on one rwlock. 4920Sstevel@tonic-gate * This could be as large as INT_MAX, but the SUSV3 test suite would 4930Sstevel@tonic-gate * take an inordinately long time to complete. This is big enough. 4940Sstevel@tonic-gate */ 4950Sstevel@tonic-gate #define READ_LOCK_MAX 100000 4960Sstevel@tonic-gate 4970Sstevel@tonic-gate #define ul_tlsent ul_tls.tls_data /* array of pointers to dynamic TLS */ 4980Sstevel@tonic-gate #define ul_ntlsent ul_tls.tls_size /* number of entries in ul_tlsent */ 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate /* 5010Sstevel@tonic-gate * Round up an integral value to a multiple of 64 5020Sstevel@tonic-gate */ 5030Sstevel@tonic-gate #define roundup64(x) (-(-(x) & -64)) 5040Sstevel@tonic-gate 5050Sstevel@tonic-gate /* 5060Sstevel@tonic-gate * NOTE: Whatever changes are made to ulwp_t must be 5070Sstevel@tonic-gate * reflected in $SRC/cmd/mdb/common/modules/libc/libc.c 5080Sstevel@tonic-gate * 5090Sstevel@tonic-gate * NOTE: ul_self *must* be the first member of ulwp_t on x86 5100Sstevel@tonic-gate * Low-level x86 code relies on this. 5110Sstevel@tonic-gate */ 5120Sstevel@tonic-gate typedef struct ulwp { 5130Sstevel@tonic-gate /* 5140Sstevel@tonic-gate * These members always need to come first on sparc. 5150Sstevel@tonic-gate * For dtrace, a ulwp_t must be aligned on a 64-byte boundary. 5160Sstevel@tonic-gate */ 5170Sstevel@tonic-gate #if defined(__sparc) 5180Sstevel@tonic-gate uint32_t ul_dinstr; /* scratch space for dtrace */ 5190Sstevel@tonic-gate uint32_t ul_padsparc0[15]; 5200Sstevel@tonic-gate uint32_t ul_dsave; /* dtrace: save %g1, %g0, %sp */ 5210Sstevel@tonic-gate uint32_t ul_drestore; /* dtrace: restore %g0, %g0, %g0 */ 5220Sstevel@tonic-gate uint32_t ul_dftret; /* dtrace: return probe fasttrap */ 5230Sstevel@tonic-gate uint32_t ul_dreturn; /* dtrace: return %o0 */ 5240Sstevel@tonic-gate #endif 5250Sstevel@tonic-gate struct ulwp *ul_self; /* pointer to self */ 5260Sstevel@tonic-gate #if defined(__i386) 5270Sstevel@tonic-gate uint8_t ul_dinstr[40]; /* scratch space for dtrace */ 5280Sstevel@tonic-gate #elif defined(__amd64) 5290Sstevel@tonic-gate uint8_t ul_dinstr[56]; /* scratch space for dtrace */ 5300Sstevel@tonic-gate #endif 5310Sstevel@tonic-gate struct uberdata *ul_uberdata; /* uber (super-global) data */ 5320Sstevel@tonic-gate tls_t ul_tls; /* dynamic thread-local storage base */ 5330Sstevel@tonic-gate struct ulwp *ul_forw; /* forw, back all_lwps list, */ 5340Sstevel@tonic-gate struct ulwp *ul_back; /* protected by link_lock */ 5350Sstevel@tonic-gate struct ulwp *ul_next; /* list to keep track of stacks */ 5360Sstevel@tonic-gate struct ulwp *ul_hash; /* hash chain linked list */ 5370Sstevel@tonic-gate void *ul_rval; /* return value from thr_exit() */ 5380Sstevel@tonic-gate caddr_t ul_stk; /* mapping base of the stack */ 5390Sstevel@tonic-gate size_t ul_mapsiz; /* mapping size of the stack */ 5400Sstevel@tonic-gate size_t ul_guardsize; /* normally _lpagesize */ 5410Sstevel@tonic-gate uintptr_t ul_stktop; /* broken thr_stksegment() interface */ 5420Sstevel@tonic-gate size_t ul_stksiz; /* broken thr_stksegment() interface */ 5430Sstevel@tonic-gate stack_t ul_ustack; /* current stack boundaries */ 5440Sstevel@tonic-gate int ul_ix; /* hash index */ 5450Sstevel@tonic-gate lwpid_t ul_lwpid; /* thread id, aka the lwp id */ 5466247Sraf pri_t ul_pri; /* scheduling priority */ 5476247Sraf pri_t ul_epri; /* real-time ceiling priority */ 5480Sstevel@tonic-gate char ul_policy; /* scheduling policy */ 5496247Sraf char ul_cid; /* scheduling class id */ 5500Sstevel@tonic-gate union { 5510Sstevel@tonic-gate struct { 5520Sstevel@tonic-gate char cursig; /* deferred signal number */ 5530Sstevel@tonic-gate char pleasestop; /* lwp requested to stop itself */ 5540Sstevel@tonic-gate } s; 5550Sstevel@tonic-gate short curplease; /* for testing both at once */ 5560Sstevel@tonic-gate } ul_cp; 5570Sstevel@tonic-gate char ul_stop; /* reason for stopping */ 5580Sstevel@tonic-gate char ul_signalled; /* this lwp was cond_signal()d */ 5590Sstevel@tonic-gate char ul_dead; /* this lwp has called thr_exit */ 5600Sstevel@tonic-gate char ul_unwind; /* posix: unwind C++ stack */ 5610Sstevel@tonic-gate char ul_detached; /* THR_DETACHED at thread_create() */ 5620Sstevel@tonic-gate /* or pthread_detach() was called */ 5630Sstevel@tonic-gate char ul_writer; /* sleeping in rw_wrlock() */ 5640Sstevel@tonic-gate char ul_stopping; /* set by curthread: stopping self */ 5651885Sraf char ul_cancel_prologue; /* for _cancel_prologue() */ 5660Sstevel@tonic-gate short ul_preempt; /* no_preempt()/preempt() */ 5670Sstevel@tonic-gate short ul_savpreempt; /* pre-existing preempt value */ 5680Sstevel@tonic-gate char ul_sigsuspend; /* thread is in sigsuspend/pollsys */ 5690Sstevel@tonic-gate char ul_main; /* thread is the main thread */ 5700Sstevel@tonic-gate char ul_fork; /* thread is performing a fork */ 5710Sstevel@tonic-gate char ul_primarymap; /* primary link-map is initialized */ 5720Sstevel@tonic-gate /* per-thread copies of the corresponding global variables */ 5735629Sraf uint8_t ul_max_spinners; /* thread_max_spinners */ 5740Sstevel@tonic-gate char ul_door_noreserve; /* thread_door_noreserve */ 5750Sstevel@tonic-gate char ul_queue_fifo; /* thread_queue_fifo */ 5760Sstevel@tonic-gate char ul_cond_wait_defer; /* thread_cond_wait_defer */ 5770Sstevel@tonic-gate char ul_error_detection; /* thread_error_detection */ 5780Sstevel@tonic-gate char ul_async_safe; /* thread_async_safe */ 5796247Sraf char ul_rt; /* found on an RT queue */ 5806247Sraf char ul_rtqueued; /* was RT when queued */ 5817255Sraf char ul_misaligned; /* thread_locks_misaligned */ 5827255Sraf char ul_pad[3]; 5830Sstevel@tonic-gate int ul_adaptive_spin; /* thread_adaptive_spin */ 5840Sstevel@tonic-gate int ul_queue_spin; /* thread_queue_spin */ 5850Sstevel@tonic-gate volatile int ul_critical; /* non-zero == in a critical region */ 5860Sstevel@tonic-gate int ul_sigdefer; /* non-zero == defer signals */ 5870Sstevel@tonic-gate int ul_vfork; /* thread is the child of vfork() */ 5880Sstevel@tonic-gate int ul_cancelable; /* _cancelon()/_canceloff() */ 5890Sstevel@tonic-gate char ul_cancel_pending; /* pthread_cancel() was called */ 5900Sstevel@tonic-gate char ul_cancel_disabled; /* PTHREAD_CANCEL_DISABLE */ 5910Sstevel@tonic-gate char ul_cancel_async; /* PTHREAD_CANCEL_ASYNCHRONOUS */ 5920Sstevel@tonic-gate char ul_save_async; /* saved copy of ul_cancel_async */ 5930Sstevel@tonic-gate char ul_mutator; /* lwp is a mutator (java interface) */ 5940Sstevel@tonic-gate char ul_created; /* created suspended */ 5950Sstevel@tonic-gate char ul_replace; /* replacement; must be free()d */ 5960Sstevel@tonic-gate uchar_t ul_nocancel; /* cancellation can't happen */ 5970Sstevel@tonic-gate int ul_errno; /* per-thread errno */ 5980Sstevel@tonic-gate int *ul_errnop; /* pointer to errno or self->ul_errno */ 5990Sstevel@tonic-gate __cleanup_t *ul_clnup_hdr; /* head of cleanup handlers list */ 6006247Sraf uberflags_t *ul_schedctl_called; /* ul_schedctl is set up */ 6016247Sraf volatile sc_shared_t *ul_schedctl; /* schedctl data */ 6020Sstevel@tonic-gate int ul_bindflags; /* bind_guard() interface to ld.so.1 */ 6035891Sraf uint_t ul_libc_locks; /* count of cancel_safe_mutex_lock()s */ 6040Sstevel@tonic-gate tsd_t *ul_stsd; /* slow TLS for keys >= TSD_NFAST */ 6050Sstevel@tonic-gate void *ul_ftsd[TSD_NFAST]; /* fast TLS for keys < TSD_NFAST */ 6060Sstevel@tonic-gate td_evbuf_t ul_td_evbuf; /* event buffer */ 6070Sstevel@tonic-gate char ul_td_events_enable; /* event mechanism enabled */ 6080Sstevel@tonic-gate char ul_sync_obj_reg; /* tdb_sync_obj_register() */ 6090Sstevel@tonic-gate char ul_qtype; /* MX or CV */ 6100Sstevel@tonic-gate char ul_cv_wake; /* != 0: just wake up, don't requeue */ 61110637SRoger.Faulkner@Sun.COM int ul_rtld; /* thread is running inside ld.so.1 */ 6120Sstevel@tonic-gate int ul_usropts; /* flags given to thr_create() */ 6130Sstevel@tonic-gate void *(*ul_startpc)(void *); /* start func (thr_create()) */ 6140Sstevel@tonic-gate void *ul_startarg; /* argument for start function */ 6150Sstevel@tonic-gate void *ul_wchan; /* synch object when sleeping */ 6160Sstevel@tonic-gate struct ulwp *ul_link; /* sleep queue link */ 6170Sstevel@tonic-gate queue_head_t *ul_sleepq; /* sleep queue thread is waiting on */ 6180Sstevel@tonic-gate mutex_t *ul_cvmutex; /* mutex dropped when waiting on a cv */ 6190Sstevel@tonic-gate mxchain_t *ul_mxchain; /* chain of owned ceiling mutexes */ 6206247Sraf int ul_save_state; /* bind_guard() interface to ld.so.1 */ 6214574Sraf uint_t ul_rdlockcnt; /* # entries in ul_readlock array */ 6224574Sraf /* 0 means there is but a single entry */ 6234574Sraf union { /* single entry or pointer to array */ 6240Sstevel@tonic-gate readlock_t single; 6250Sstevel@tonic-gate readlock_t *array; 6260Sstevel@tonic-gate } ul_readlock; 6274574Sraf uint_t ul_heldlockcnt; /* # entries in ul_heldlocks array */ 6284574Sraf /* 0 means there is but a single entry */ 6294574Sraf union { /* single entry or pointer to array */ 6304574Sraf mutex_t *single; 6314574Sraf mutex_t **array; 6324574Sraf } ul_heldlocks; 6330Sstevel@tonic-gate /* PROBE_SUPPORT begin */ 6340Sstevel@tonic-gate void *ul_tpdp; 6350Sstevel@tonic-gate /* PROBE_SUPPORT end */ 6360Sstevel@tonic-gate ucontext_t *ul_siglink; /* pointer to previous context */ 6370Sstevel@tonic-gate uint_t ul_spin_lock_spin; /* spin lock statistics */ 6380Sstevel@tonic-gate uint_t ul_spin_lock_spin2; 6390Sstevel@tonic-gate uint_t ul_spin_lock_sleep; 6400Sstevel@tonic-gate uint_t ul_spin_lock_wakeup; 6416247Sraf queue_root_t ul_queue_root; /* root of a sleep queue */ 6426247Sraf id_t ul_rtclassid; /* real-time class id */ 6436247Sraf uint_t ul_pilocks; /* count of PI locks held */ 6440Sstevel@tonic-gate /* the following members *must* be last in the structure */ 6450Sstevel@tonic-gate /* they are discarded when ulwp is replaced on thr_exit() */ 6460Sstevel@tonic-gate sigset_t ul_sigmask; /* thread's current signal mask */ 6470Sstevel@tonic-gate sigset_t ul_tmpmask; /* signal mask for sigsuspend/pollsys */ 6480Sstevel@tonic-gate siginfo_t ul_siginfo; /* deferred siginfo */ 6490Sstevel@tonic-gate mutex_t ul_spinlock; /* used when suspending/continuing */ 6500Sstevel@tonic-gate fpuenv_t ul_fpuenv; /* floating point state */ 6510Sstevel@tonic-gate uintptr_t ul_sp; /* stack pointer when blocked */ 6520Sstevel@tonic-gate void *ul_ex_unwind; /* address of _ex_unwind() or -1 */ 6530Sstevel@tonic-gate #if defined(sparc) 6540Sstevel@tonic-gate void *ul_unwind_ret; /* used only by _ex_clnup_handler() */ 6550Sstevel@tonic-gate #endif 6560Sstevel@tonic-gate } ulwp_t; 6570Sstevel@tonic-gate 6580Sstevel@tonic-gate #define ul_cursig ul_cp.s.cursig /* deferred signal number */ 6590Sstevel@tonic-gate #define ul_pleasestop ul_cp.s.pleasestop /* lwp requested to stop */ 6600Sstevel@tonic-gate #define ul_curplease ul_cp.curplease /* for testing both at once */ 6610Sstevel@tonic-gate 6620Sstevel@tonic-gate /* 6630Sstevel@tonic-gate * This is the size of a replacement ulwp, retained only for the benefit 6640Sstevel@tonic-gate * of thr_join(). The trailing members are unneeded for this purpose. 6650Sstevel@tonic-gate */ 6660Sstevel@tonic-gate #define REPLACEMENT_SIZE ((size_t)&((ulwp_t *)NULL)->ul_sigmask) 6670Sstevel@tonic-gate 6680Sstevel@tonic-gate /* 6690Sstevel@tonic-gate * Definitions for static initialization of signal sets, 6700Sstevel@tonic-gate * plus some sneaky optimizations in various places. 6710Sstevel@tonic-gate */ 6720Sstevel@tonic-gate 6730Sstevel@tonic-gate #define SIGMASK(sig) ((uint32_t)1 << (((sig) - 1) & (32 - 1))) 6740Sstevel@tonic-gate 67511913SRoger.Faulkner@Sun.COM #if (MAXSIG > (2 * 32) && MAXSIG <= (3 * 32)) 6760Sstevel@tonic-gate #define FILLSET0 0xffffffffu 67711913SRoger.Faulkner@Sun.COM #define FILLSET1 0xffffffffu 67811913SRoger.Faulkner@Sun.COM #define FILLSET2 ((1u << (MAXSIG - 64)) - 1) 67911913SRoger.Faulkner@Sun.COM #define FILLSET3 0 6800Sstevel@tonic-gate #else 6810Sstevel@tonic-gate #error "fix me: MAXSIG out of bounds" 6820Sstevel@tonic-gate #endif 6830Sstevel@tonic-gate 6840Sstevel@tonic-gate #define CANTMASK0 (SIGMASK(SIGKILL) | SIGMASK(SIGSTOP)) 6850Sstevel@tonic-gate #define CANTMASK1 0 68611913SRoger.Faulkner@Sun.COM #define CANTMASK2 0 68711913SRoger.Faulkner@Sun.COM #define CANTMASK3 0 6880Sstevel@tonic-gate 6890Sstevel@tonic-gate #define MASKSET0 (FILLSET0 & ~CANTMASK0) 6900Sstevel@tonic-gate #define MASKSET1 (FILLSET1 & ~CANTMASK1) 69111913SRoger.Faulkner@Sun.COM #define MASKSET2 (FILLSET2 & ~CANTMASK2) 69211913SRoger.Faulkner@Sun.COM #define MASKSET3 (FILLSET3 & ~CANTMASK3) 6930Sstevel@tonic-gate 6942248Sraf extern const sigset_t maskset; /* set of all maskable signals */ 6950Sstevel@tonic-gate 6960Sstevel@tonic-gate extern int thread_adaptive_spin; 6970Sstevel@tonic-gate extern uint_t thread_max_spinners; 6980Sstevel@tonic-gate extern int thread_queue_spin; 6990Sstevel@tonic-gate extern int thread_queue_fifo; 7000Sstevel@tonic-gate extern int thread_queue_dump; 7010Sstevel@tonic-gate extern int thread_cond_wait_defer; 7020Sstevel@tonic-gate extern int thread_async_safe; 7030Sstevel@tonic-gate extern int thread_queue_verify; 7040Sstevel@tonic-gate 7050Sstevel@tonic-gate /* 7060Sstevel@tonic-gate * pthread_atfork() related data, used to store atfork handlers. 7070Sstevel@tonic-gate */ 7080Sstevel@tonic-gate typedef struct atfork { 7090Sstevel@tonic-gate struct atfork *forw; /* forward pointer */ 7100Sstevel@tonic-gate struct atfork *back; /* backward pointer */ 7110Sstevel@tonic-gate void (*prepare)(void); /* pre-fork handler */ 7120Sstevel@tonic-gate void (*parent)(void); /* post-fork parent handler */ 7130Sstevel@tonic-gate void (*child)(void); /* post-fork child handler */ 7140Sstevel@tonic-gate } atfork_t; 7150Sstevel@tonic-gate 7160Sstevel@tonic-gate /* 7179170SRoger.Faulkner@Sun.COM * Element in the table and in the list of registered process 7189170SRoger.Faulkner@Sun.COM * robust locks. We keep track of these to make sure that we 7199170SRoger.Faulkner@Sun.COM * only call ___lwp_mutex_register() once for each such lock 7209170SRoger.Faulkner@Sun.COM * after it is first mapped in (or newly mapped in). 7214574Sraf */ 7224574Sraf typedef struct robust { 7239170SRoger.Faulkner@Sun.COM struct robust *robust_next; /* hash table list */ 7249170SRoger.Faulkner@Sun.COM struct robust *robust_list; /* global list */ 7254574Sraf mutex_t *robust_lock; 7264574Sraf } robust_t; 7274574Sraf 7284574Sraf /* 7299170SRoger.Faulkner@Sun.COM * Invalid address, used to mark an unused element in the hash table. 7309170SRoger.Faulkner@Sun.COM */ 7319170SRoger.Faulkner@Sun.COM #define INVALID_ADDR ((void *)(uintptr_t)(-1L)) 7329170SRoger.Faulkner@Sun.COM 7339170SRoger.Faulkner@Sun.COM /* 7344574Sraf * Parameters of the lock registration hash table. 7354574Sraf */ 7367063Sraf #define LOCKSHIFT 15 /* number of hashing bits */ 7377063Sraf #define LOCKHASHSZ (1 << LOCKSHIFT) /* power of 2 (1<<15 == 32K) */ 7384574Sraf #define LOCK_HASH(addr) (uint_t) \ 7394574Sraf ((((uintptr_t)(addr) >> 3) \ 7404574Sraf ^ ((uintptr_t)(addr) >> (LOCKSHIFT + 3))) \ 7414574Sraf & (LOCKHASHSZ - 1)) 7424574Sraf 7434574Sraf /* 7440Sstevel@tonic-gate * Make our hot locks reside on private cache lines (64 bytes). 7450Sstevel@tonic-gate */ 7460Sstevel@tonic-gate typedef struct { 7470Sstevel@tonic-gate mutex_t pad_lock; 7484843Sraf char pad_pad[64 - sizeof (mutex_t)]; 7490Sstevel@tonic-gate } pad_lock_t; 7500Sstevel@tonic-gate 7510Sstevel@tonic-gate /* 7524843Sraf * Make our semi-hot locks reside on semi-private cache lines (32 bytes). 7534843Sraf */ 7544843Sraf typedef struct { 7554843Sraf mutex_t pad_lock; 7564843Sraf char pad_pad[32 - sizeof (mutex_t)]; 7574843Sraf } pad32_lock_t; 7584843Sraf 7594843Sraf /* 7600Sstevel@tonic-gate * The threads hash table is used for fast lookup and locking of an active 7610Sstevel@tonic-gate * thread structure (ulwp_t) given a thread-id. It is an N-element array of 7620Sstevel@tonic-gate * thr_hash_table_t structures, where N == 1 before the main thread creates 7630Sstevel@tonic-gate * the first additional thread and N == 1024 afterwards. Each element of the 7640Sstevel@tonic-gate * table is 64 bytes in size and alignment to reduce cache conflicts. 7650Sstevel@tonic-gate */ 7660Sstevel@tonic-gate typedef struct { 7670Sstevel@tonic-gate mutex_t hash_lock; /* lock per bucket */ 7680Sstevel@tonic-gate cond_t hash_cond; /* convar per bucket */ 7690Sstevel@tonic-gate ulwp_t *hash_bucket; /* hash bucket points to the list of ulwps */ 7700Sstevel@tonic-gate char hash_pad[64 - /* pad out to 64 bytes */ 7710Sstevel@tonic-gate (sizeof (mutex_t) + sizeof (cond_t) + sizeof (ulwp_t *))]; 7720Sstevel@tonic-gate } thr_hash_table_t; 7730Sstevel@tonic-gate 7740Sstevel@tonic-gate #ifdef _SYSCALL32 7750Sstevel@tonic-gate typedef struct { 7760Sstevel@tonic-gate mutex_t hash_lock; 7770Sstevel@tonic-gate cond_t hash_cond; 7780Sstevel@tonic-gate caddr32_t hash_bucket; 7790Sstevel@tonic-gate char hash_pad[64 - 7800Sstevel@tonic-gate (sizeof (mutex_t) + sizeof (cond_t) + sizeof (caddr32_t))]; 7810Sstevel@tonic-gate } thr_hash_table32_t; 7820Sstevel@tonic-gate #endif /* _SYSCALL32 */ 7830Sstevel@tonic-gate 7840Sstevel@tonic-gate 7850Sstevel@tonic-gate /* 7864570Sraf * siguaction members have 128-byte size and 64-byte alignment. 7874570Sraf * We know that sizeof (struct sigaction) is 32 bytes for both 7884570Sraf * _ILP32 and _LP64 and that sizeof (rwlock_t) is 64 bytes. 7890Sstevel@tonic-gate */ 7900Sstevel@tonic-gate typedef struct { 7914570Sraf rwlock_t sig_lock; 7920Sstevel@tonic-gate struct sigaction sig_uaction; 7934570Sraf char sig_pad[128 - sizeof (rwlock_t) - sizeof (struct sigaction)]; 7940Sstevel@tonic-gate } siguaction_t; 7950Sstevel@tonic-gate 7960Sstevel@tonic-gate #ifdef _SYSCALL32 7970Sstevel@tonic-gate typedef struct { 7984570Sraf rwlock_t sig_lock; 7990Sstevel@tonic-gate struct sigaction32 sig_uaction; 8004570Sraf char sig_pad[128 - sizeof (rwlock_t) - sizeof (struct sigaction32)]; 8010Sstevel@tonic-gate } siguaction32_t; 8020Sstevel@tonic-gate #endif /* _SYSCALL32 */ 8030Sstevel@tonic-gate 8040Sstevel@tonic-gate 8050Sstevel@tonic-gate /* 8060Sstevel@tonic-gate * Bucket structures, used by lmalloc()/lfree(). 8070Sstevel@tonic-gate * See port/threads/alloc.c for details. 8080Sstevel@tonic-gate * A bucket's size and alignment is 64 bytes. 8090Sstevel@tonic-gate */ 8100Sstevel@tonic-gate typedef struct { 8110Sstevel@tonic-gate mutex_t bucket_lock; /* protects the free list allocations */ 8120Sstevel@tonic-gate void *free_list; /* LIFO list of blocks to allocate/free */ 8130Sstevel@tonic-gate size_t chunks; /* number of 64K blocks mmap()ed last time */ 8140Sstevel@tonic-gate char pad64[64 - /* pad out to 64 bytes */ 8150Sstevel@tonic-gate (sizeof (mutex_t) + sizeof (void *) + sizeof (size_t))]; 8160Sstevel@tonic-gate } bucket_t; 8170Sstevel@tonic-gate 8180Sstevel@tonic-gate #ifdef _SYSCALL32 8190Sstevel@tonic-gate typedef struct { 8200Sstevel@tonic-gate mutex_t bucket_lock; 8210Sstevel@tonic-gate caddr32_t free_list; 8220Sstevel@tonic-gate size32_t chunks; 8230Sstevel@tonic-gate char pad64[64 - /* pad out to 64 bytes */ 8240Sstevel@tonic-gate (sizeof (mutex_t) + sizeof (caddr32_t) + sizeof (size32_t))]; 8250Sstevel@tonic-gate } bucket32_t; 8260Sstevel@tonic-gate #endif /* _SYSCALL32 */ 8270Sstevel@tonic-gate 8280Sstevel@tonic-gate #define NBUCKETS 10 /* sizes ranging from 64 to 32768 */ 8290Sstevel@tonic-gate 8300Sstevel@tonic-gate 8310Sstevel@tonic-gate /* 8320Sstevel@tonic-gate * atexit() data structures. 8330Sstevel@tonic-gate * See port/gen/atexit.c for details. 8340Sstevel@tonic-gate */ 8350Sstevel@tonic-gate typedef void (*_exithdlr_func_t) (void); 8360Sstevel@tonic-gate 8370Sstevel@tonic-gate typedef struct _exthdlr { 8380Sstevel@tonic-gate struct _exthdlr *next; /* next in handler list */ 8390Sstevel@tonic-gate _exithdlr_func_t hdlr; /* handler itself */ 8400Sstevel@tonic-gate } _exthdlr_t; 8410Sstevel@tonic-gate 8420Sstevel@tonic-gate typedef struct { 8430Sstevel@tonic-gate mutex_t exitfns_lock; 8440Sstevel@tonic-gate _exthdlr_t *head; 8450Sstevel@tonic-gate void *exit_frame_monitor; 8460Sstevel@tonic-gate char exit_pad[64 - /* pad out to 64 bytes */ 8470Sstevel@tonic-gate (sizeof (mutex_t) + sizeof (_exthdlr_t *) + sizeof (void *))]; 8480Sstevel@tonic-gate } atexit_root_t; 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate #ifdef _SYSCALL32 8510Sstevel@tonic-gate typedef struct { 8520Sstevel@tonic-gate mutex_t exitfns_lock; 8530Sstevel@tonic-gate caddr32_t head; 8540Sstevel@tonic-gate caddr32_t exit_frame_monitor; 8550Sstevel@tonic-gate char exit_pad[64 - /* pad out to 64 bytes */ 8560Sstevel@tonic-gate (sizeof (mutex_t) + sizeof (caddr32_t) + sizeof (caddr32_t))]; 8570Sstevel@tonic-gate } atexit_root32_t; 8580Sstevel@tonic-gate #endif /* _SYSCALL32 */ 8590Sstevel@tonic-gate 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate /* 8620Sstevel@tonic-gate * This is data that is global to all link maps (uberdata, aka super-global). 8630Sstevel@tonic-gate */ 8640Sstevel@tonic-gate typedef struct uberdata { 8650Sstevel@tonic-gate pad_lock_t _link_lock; 8666515Sraf pad_lock_t _ld_lock; 8676515Sraf pad_lock_t _fork_lock; 8686515Sraf pad_lock_t _atfork_lock; 8695002Sraf pad32_lock_t _callout_lock; 8705002Sraf pad32_lock_t _tdb_hash_lock; 8710Sstevel@tonic-gate tdb_sync_stats_t tdb_hash_lock_stats; 8720Sstevel@tonic-gate siguaction_t siguaction[NSIG]; 8730Sstevel@tonic-gate bucket_t bucket[NBUCKETS]; 8740Sstevel@tonic-gate atexit_root_t atexit_root; 8750Sstevel@tonic-gate tsd_metadata_t tsd_metadata; 8760Sstevel@tonic-gate tls_metadata_t tls_metadata; 8770Sstevel@tonic-gate /* 8780Sstevel@tonic-gate * Every object before this point has size and alignment of 64 bytes. 8790Sstevel@tonic-gate * Don't add any other type of data before this point. 8800Sstevel@tonic-gate */ 8810Sstevel@tonic-gate char primary_map; /* set when primary link map is initialized */ 8820Sstevel@tonic-gate char bucket_init; /* set when bucket[NBUCKETS] is initialized */ 8830Sstevel@tonic-gate char pad[2]; 8840Sstevel@tonic-gate uberflags_t uberflags; 8850Sstevel@tonic-gate queue_head_t *queue_head; 8860Sstevel@tonic-gate thr_hash_table_t *thr_hash_table; 8870Sstevel@tonic-gate uint_t hash_size; /* # of entries in thr_hash_table[] */ 8880Sstevel@tonic-gate uint_t hash_mask; /* hash_size - 1 */ 8890Sstevel@tonic-gate ulwp_t *ulwp_one; /* main thread */ 8900Sstevel@tonic-gate ulwp_t *all_lwps; /* circular ul_forw/ul_back list of live lwps */ 8910Sstevel@tonic-gate ulwp_t *all_zombies; /* circular ul_forw/ul_back list of zombies */ 8920Sstevel@tonic-gate int nthreads; /* total number of live threads/lwps */ 8930Sstevel@tonic-gate int nzombies; /* total number of zombie threads */ 8940Sstevel@tonic-gate int ndaemons; /* total number of THR_DAEMON threads/lwps */ 8950Sstevel@tonic-gate pid_t pid; /* the current process's pid */ 8960Sstevel@tonic-gate void (*sigacthandler)(int, siginfo_t *, void *); 8970Sstevel@tonic-gate ulwp_t *lwp_stacks; 8980Sstevel@tonic-gate ulwp_t *lwp_laststack; 8990Sstevel@tonic-gate int nfreestack; 9000Sstevel@tonic-gate int thread_stack_cache; 9010Sstevel@tonic-gate ulwp_t *ulwp_freelist; 9020Sstevel@tonic-gate ulwp_t *ulwp_lastfree; 9030Sstevel@tonic-gate ulwp_t *ulwp_replace_free; 9040Sstevel@tonic-gate ulwp_t *ulwp_replace_last; 9050Sstevel@tonic-gate atfork_t *atforklist; /* circular Q for fork handlers */ 9064574Sraf robust_t **robustlocks; /* table of registered robust locks */ 9079170SRoger.Faulkner@Sun.COM robust_t *robustlist; /* list of registered robust locks */ 908*13093SRoger.Faulkner@Oracle.COM char *progname; /* the basename of the program, from argv[0] */ 9090Sstevel@tonic-gate struct uberdata **tdb_bootstrap; 9100Sstevel@tonic-gate tdb_t tdb; /* thread debug interfaces (for libc_db) */ 9110Sstevel@tonic-gate } uberdata_t; 9120Sstevel@tonic-gate 9130Sstevel@tonic-gate #define link_lock _link_lock.pad_lock 9146515Sraf #define ld_lock _ld_lock.pad_lock 9150Sstevel@tonic-gate #define fork_lock _fork_lock.pad_lock 9164843Sraf #define atfork_lock _atfork_lock.pad_lock 9175002Sraf #define callout_lock _callout_lock.pad_lock 9180Sstevel@tonic-gate #define tdb_hash_lock _tdb_hash_lock.pad_lock 9190Sstevel@tonic-gate 9200Sstevel@tonic-gate #pragma align 64(__uberdata) 9210Sstevel@tonic-gate extern uberdata_t __uberdata; 9220Sstevel@tonic-gate extern uberdata_t **__tdb_bootstrap; /* known to libc_db and mdb */ 9230Sstevel@tonic-gate extern int primary_link_map; 9240Sstevel@tonic-gate 9250Sstevel@tonic-gate #define ulwp_mutex(ulwp, udp) \ 9260Sstevel@tonic-gate (&(udp)->thr_hash_table[(ulwp)->ul_ix].hash_lock) 9270Sstevel@tonic-gate #define ulwp_condvar(ulwp, udp) \ 9280Sstevel@tonic-gate (&(udp)->thr_hash_table[(ulwp)->ul_ix].hash_cond) 9290Sstevel@tonic-gate 9300Sstevel@tonic-gate /* 9310Sstevel@tonic-gate * Grab and release the hash table lock for the specified lwp. 9320Sstevel@tonic-gate */ 9330Sstevel@tonic-gate #define ulwp_lock(ulwp, udp) lmutex_lock(ulwp_mutex(ulwp, udp)) 9340Sstevel@tonic-gate #define ulwp_unlock(ulwp, udp) lmutex_unlock(ulwp_mutex(ulwp, udp)) 9350Sstevel@tonic-gate 9360Sstevel@tonic-gate #ifdef _SYSCALL32 /* needed by libc_db */ 9370Sstevel@tonic-gate 9380Sstevel@tonic-gate typedef struct ulwp32 { 9390Sstevel@tonic-gate #if defined(__sparc) 9400Sstevel@tonic-gate uint32_t ul_dinstr; /* scratch space for dtrace */ 9410Sstevel@tonic-gate uint32_t ul_padsparc0[15]; 9420Sstevel@tonic-gate uint32_t ul_dsave; /* dtrace: save %g1, %g0, %sp */ 9430Sstevel@tonic-gate uint32_t ul_drestore; /* dtrace: restore %g0, %g0, %g0 */ 9440Sstevel@tonic-gate uint32_t ul_dftret; /* dtrace: return probe fasttrap */ 9450Sstevel@tonic-gate uint32_t ul_dreturn; /* dtrace: return %o0 */ 9460Sstevel@tonic-gate #endif 9470Sstevel@tonic-gate caddr32_t ul_self; /* pointer to self */ 9481016Sraf #if defined(__x86) 9490Sstevel@tonic-gate uint8_t ul_dinstr[40]; /* scratch space for dtrace */ 9500Sstevel@tonic-gate #endif 9510Sstevel@tonic-gate caddr32_t ul_uberdata; /* uber (super-global) data */ 9520Sstevel@tonic-gate tls32_t ul_tls; /* dynamic thread-local storage base */ 9530Sstevel@tonic-gate caddr32_t ul_forw; /* forw, back all_lwps list, */ 9540Sstevel@tonic-gate caddr32_t ul_back; /* protected by link_lock */ 9550Sstevel@tonic-gate caddr32_t ul_next; /* list to keep track of stacks */ 9560Sstevel@tonic-gate caddr32_t ul_hash; /* hash chain linked list */ 9570Sstevel@tonic-gate caddr32_t ul_rval; /* return value from thr_exit() */ 9580Sstevel@tonic-gate caddr32_t ul_stk; /* mapping base of the stack */ 9590Sstevel@tonic-gate size32_t ul_mapsiz; /* mapping size of the stack */ 9600Sstevel@tonic-gate size32_t ul_guardsize; /* normally _lpagesize */ 9610Sstevel@tonic-gate caddr32_t ul_stktop; /* broken thr_stksegment() interface */ 9620Sstevel@tonic-gate size32_t ul_stksiz; /* broken thr_stksegment() interface */ 9630Sstevel@tonic-gate stack32_t ul_ustack; /* current stack boundaries */ 9640Sstevel@tonic-gate int ul_ix; /* hash index */ 9650Sstevel@tonic-gate lwpid_t ul_lwpid; /* thread id, aka the lwp id */ 9666247Sraf pri_t ul_pri; /* scheduling priority */ 9676247Sraf pri_t ul_epri; /* real-time ceiling priority */ 9680Sstevel@tonic-gate char ul_policy; /* scheduling policy */ 9696247Sraf char ul_cid; /* scheduling class id */ 9700Sstevel@tonic-gate union { 9710Sstevel@tonic-gate struct { 9720Sstevel@tonic-gate char cursig; /* deferred signal number */ 9730Sstevel@tonic-gate char pleasestop; /* lwp requested to stop itself */ 9740Sstevel@tonic-gate } s; 9750Sstevel@tonic-gate short curplease; /* for testing both at once */ 9760Sstevel@tonic-gate } ul_cp; 9770Sstevel@tonic-gate char ul_stop; /* reason for stopping */ 9780Sstevel@tonic-gate char ul_signalled; /* this lwp was cond_signal()d */ 9790Sstevel@tonic-gate char ul_dead; /* this lwp has called thr_exit */ 9800Sstevel@tonic-gate char ul_unwind; /* posix: unwind C++ stack */ 9810Sstevel@tonic-gate char ul_detached; /* THR_DETACHED at thread_create() */ 9820Sstevel@tonic-gate /* or pthread_detach() was called */ 9830Sstevel@tonic-gate char ul_writer; /* sleeping in rw_wrlock() */ 9840Sstevel@tonic-gate char ul_stopping; /* set by curthread: stopping self */ 9851885Sraf char ul_cancel_prologue; /* for _cancel_prologue() */ 9860Sstevel@tonic-gate short ul_preempt; /* no_preempt()/preempt() */ 9870Sstevel@tonic-gate short ul_savpreempt; /* pre-existing preempt value */ 9880Sstevel@tonic-gate char ul_sigsuspend; /* thread is in sigsuspend/pollsys */ 9890Sstevel@tonic-gate char ul_main; /* thread is the main thread */ 9900Sstevel@tonic-gate char ul_fork; /* thread is performing a fork */ 9910Sstevel@tonic-gate char ul_primarymap; /* primary link-map is initialized */ 9920Sstevel@tonic-gate /* per-thread copies of the corresponding global variables */ 9935629Sraf uint8_t ul_max_spinners; /* thread_max_spinners */ 9940Sstevel@tonic-gate char ul_door_noreserve; /* thread_door_noreserve */ 9950Sstevel@tonic-gate char ul_queue_fifo; /* thread_queue_fifo */ 9960Sstevel@tonic-gate char ul_cond_wait_defer; /* thread_cond_wait_defer */ 9970Sstevel@tonic-gate char ul_error_detection; /* thread_error_detection */ 9980Sstevel@tonic-gate char ul_async_safe; /* thread_async_safe */ 9996247Sraf char ul_rt; /* found on an RT queue */ 10006247Sraf char ul_rtqueued; /* was RT when queued */ 10017255Sraf char ul_misaligned; /* thread_locks_misaligned */ 10027255Sraf char ul_pad[3]; 10030Sstevel@tonic-gate int ul_adaptive_spin; /* thread_adaptive_spin */ 10040Sstevel@tonic-gate int ul_queue_spin; /* thread_queue_spin */ 10050Sstevel@tonic-gate int ul_critical; /* non-zero == in a critical region */ 10060Sstevel@tonic-gate int ul_sigdefer; /* non-zero == defer signals */ 10070Sstevel@tonic-gate int ul_vfork; /* thread is the child of vfork() */ 10080Sstevel@tonic-gate int ul_cancelable; /* _cancelon()/_canceloff() */ 10090Sstevel@tonic-gate char ul_cancel_pending; /* pthread_cancel() was called */ 10100Sstevel@tonic-gate char ul_cancel_disabled; /* PTHREAD_CANCEL_DISABLE */ 10110Sstevel@tonic-gate char ul_cancel_async; /* PTHREAD_CANCEL_ASYNCHRONOUS */ 10120Sstevel@tonic-gate char ul_save_async; /* saved copy of ul_cancel_async */ 10130Sstevel@tonic-gate char ul_mutator; /* lwp is a mutator (java interface) */ 10140Sstevel@tonic-gate char ul_created; /* created suspended */ 10150Sstevel@tonic-gate char ul_replace; /* replacement; must be free()d */ 10160Sstevel@tonic-gate uchar_t ul_nocancel; /* cancellation can't happen */ 10170Sstevel@tonic-gate int ul_errno; /* per-thread errno */ 10180Sstevel@tonic-gate caddr32_t ul_errnop; /* pointer to errno or self->ul_errno */ 10190Sstevel@tonic-gate caddr32_t ul_clnup_hdr; /* head of cleanup handlers list */ 10200Sstevel@tonic-gate caddr32_t ul_schedctl_called; /* ul_schedctl is set up */ 10210Sstevel@tonic-gate caddr32_t ul_schedctl; /* schedctl data */ 10220Sstevel@tonic-gate int ul_bindflags; /* bind_guard() interface to ld.so.1 */ 10235891Sraf uint_t ul_libc_locks; /* count of cancel_safe_mutex_lock()s */ 10240Sstevel@tonic-gate caddr32_t ul_stsd; /* slow TLS for keys >= TSD_NFAST */ 10250Sstevel@tonic-gate caddr32_t ul_ftsd[TSD_NFAST]; /* fast TLS for keys < TSD_NFAST */ 10260Sstevel@tonic-gate td_evbuf32_t ul_td_evbuf; /* event buffer */ 10270Sstevel@tonic-gate char ul_td_events_enable; /* event mechanism enabled */ 10280Sstevel@tonic-gate char ul_sync_obj_reg; /* tdb_sync_obj_register() */ 10290Sstevel@tonic-gate char ul_qtype; /* MX or CV */ 10300Sstevel@tonic-gate char ul_cv_wake; /* != 0: just wake up, don't requeue */ 103110637SRoger.Faulkner@Sun.COM int ul_rtld; /* thread is running inside ld.so.1 */ 10320Sstevel@tonic-gate int ul_usropts; /* flags given to thr_create() */ 10330Sstevel@tonic-gate caddr32_t ul_startpc; /* start func (thr_create()) */ 10340Sstevel@tonic-gate caddr32_t ul_startarg; /* argument for start function */ 10350Sstevel@tonic-gate caddr32_t ul_wchan; /* synch object when sleeping */ 10360Sstevel@tonic-gate caddr32_t ul_link; /* sleep queue link */ 10370Sstevel@tonic-gate caddr32_t ul_sleepq; /* sleep queue thread is waiting on */ 10380Sstevel@tonic-gate caddr32_t ul_cvmutex; /* mutex dropped when waiting on a cv */ 10390Sstevel@tonic-gate caddr32_t ul_mxchain; /* chain of owned ceiling mutexes */ 10406247Sraf int ul_save_state; /* bind_guard() interface to ld.so.1 */ 10414574Sraf uint_t ul_rdlockcnt; /* # entries in ul_readlock array */ 10424574Sraf /* 0 means there is but a single entry */ 10434574Sraf union { /* single entry or pointer to array */ 10440Sstevel@tonic-gate readlock32_t single; 10450Sstevel@tonic-gate caddr32_t array; 10460Sstevel@tonic-gate } ul_readlock; 10474574Sraf uint_t ul_heldlockcnt; /* # entries in ul_heldlocks array */ 10484574Sraf /* 0 means there is but a single entry */ 10494574Sraf union { /* single entry or pointer to array */ 10504574Sraf caddr32_t single; 10514574Sraf caddr32_t array; 10524574Sraf } ul_heldlocks; 10530Sstevel@tonic-gate /* PROBE_SUPPORT begin */ 10540Sstevel@tonic-gate caddr32_t ul_tpdp; 10550Sstevel@tonic-gate /* PROBE_SUPPORT end */ 10560Sstevel@tonic-gate caddr32_t ul_siglink; /* pointer to previous context */ 10570Sstevel@tonic-gate uint_t ul_spin_lock_spin; /* spin lock statistics */ 10580Sstevel@tonic-gate uint_t ul_spin_lock_spin2; 10590Sstevel@tonic-gate uint_t ul_spin_lock_sleep; 10600Sstevel@tonic-gate uint_t ul_spin_lock_wakeup; 10616247Sraf queue_root32_t ul_queue_root; /* root of a sleep queue */ 10626247Sraf id_t ul_rtclassid; /* real-time class id */ 10636247Sraf uint_t ul_pilocks; /* count of PI locks held */ 10640Sstevel@tonic-gate /* the following members *must* be last in the structure */ 10650Sstevel@tonic-gate /* they are discarded when ulwp is replaced on thr_exit() */ 106611913SRoger.Faulkner@Sun.COM sigset_t ul_sigmask; /* thread's current signal mask */ 106711913SRoger.Faulkner@Sun.COM sigset_t ul_tmpmask; /* signal mask for sigsuspend/pollsys */ 10680Sstevel@tonic-gate siginfo32_t ul_siginfo; /* deferred siginfo */ 10690Sstevel@tonic-gate mutex_t ul_spinlock; /* used when suspending/continuing */ 10700Sstevel@tonic-gate fpuenv32_t ul_fpuenv; /* floating point state */ 10710Sstevel@tonic-gate caddr32_t ul_sp; /* stack pointer when blocked */ 10720Sstevel@tonic-gate #if defined(sparc) 10730Sstevel@tonic-gate caddr32_t ul_unwind_ret; /* used only by _ex_clnup_handler() */ 10740Sstevel@tonic-gate #endif 10750Sstevel@tonic-gate } ulwp32_t; 10760Sstevel@tonic-gate 10770Sstevel@tonic-gate #define REPLACEMENT_SIZE32 ((size_t)&((ulwp32_t *)NULL)->ul_sigmask) 10780Sstevel@tonic-gate 10790Sstevel@tonic-gate typedef struct uberdata32 { 10800Sstevel@tonic-gate pad_lock_t _link_lock; 10816515Sraf pad_lock_t _ld_lock; 10826515Sraf pad_lock_t _fork_lock; 10836515Sraf pad_lock_t _atfork_lock; 10845002Sraf pad32_lock_t _callout_lock; 10855002Sraf pad32_lock_t _tdb_hash_lock; 10860Sstevel@tonic-gate tdb_sync_stats_t tdb_hash_lock_stats; 10870Sstevel@tonic-gate siguaction32_t siguaction[NSIG]; 10880Sstevel@tonic-gate bucket32_t bucket[NBUCKETS]; 10890Sstevel@tonic-gate atexit_root32_t atexit_root; 10900Sstevel@tonic-gate tsd_metadata32_t tsd_metadata; 10910Sstevel@tonic-gate tls_metadata32_t tls_metadata; 10920Sstevel@tonic-gate char primary_map; 10930Sstevel@tonic-gate char bucket_init; 10940Sstevel@tonic-gate char pad[2]; 10950Sstevel@tonic-gate uberflags_t uberflags; 10960Sstevel@tonic-gate caddr32_t queue_head; 10970Sstevel@tonic-gate caddr32_t thr_hash_table; 10980Sstevel@tonic-gate uint_t hash_size; 10990Sstevel@tonic-gate uint_t hash_mask; 11000Sstevel@tonic-gate caddr32_t ulwp_one; 11010Sstevel@tonic-gate caddr32_t all_lwps; 11020Sstevel@tonic-gate caddr32_t all_zombies; 11030Sstevel@tonic-gate int nthreads; 11040Sstevel@tonic-gate int nzombies; 11050Sstevel@tonic-gate int ndaemons; 11060Sstevel@tonic-gate int pid; 11070Sstevel@tonic-gate caddr32_t sigacthandler; 11080Sstevel@tonic-gate caddr32_t lwp_stacks; 11090Sstevel@tonic-gate caddr32_t lwp_laststack; 11100Sstevel@tonic-gate int nfreestack; 11110Sstevel@tonic-gate int thread_stack_cache; 11120Sstevel@tonic-gate caddr32_t ulwp_freelist; 11130Sstevel@tonic-gate caddr32_t ulwp_lastfree; 11140Sstevel@tonic-gate caddr32_t ulwp_replace_free; 11150Sstevel@tonic-gate caddr32_t ulwp_replace_last; 11160Sstevel@tonic-gate caddr32_t atforklist; 11174574Sraf caddr32_t robustlocks; 11189170SRoger.Faulkner@Sun.COM caddr32_t robustlist; 11190Sstevel@tonic-gate caddr32_t tdb_bootstrap; 11200Sstevel@tonic-gate tdb32_t tdb; 11210Sstevel@tonic-gate } uberdata32_t; 11220Sstevel@tonic-gate 11230Sstevel@tonic-gate #endif /* _SYSCALL32 */ 11240Sstevel@tonic-gate 11250Sstevel@tonic-gate /* ul_stop values */ 11260Sstevel@tonic-gate #define TSTP_REGULAR 0x01 /* Stopped by thr_suspend() */ 11270Sstevel@tonic-gate #define TSTP_MUTATOR 0x08 /* stopped by thr_suspend_*mutator*() */ 11280Sstevel@tonic-gate #define TSTP_FORK 0x20 /* stopped by suspend_fork() */ 11290Sstevel@tonic-gate 11300Sstevel@tonic-gate /* 11310Sstevel@tonic-gate * Implementation-specific attribute types for pthread_mutexattr_init() etc. 11320Sstevel@tonic-gate */ 11330Sstevel@tonic-gate 11340Sstevel@tonic-gate typedef struct _cvattr { 11350Sstevel@tonic-gate int pshared; 11360Sstevel@tonic-gate clockid_t clockid; 11370Sstevel@tonic-gate } cvattr_t; 11380Sstevel@tonic-gate 11390Sstevel@tonic-gate typedef struct _mattr { 11400Sstevel@tonic-gate int pshared; 11410Sstevel@tonic-gate int protocol; 11420Sstevel@tonic-gate int prioceiling; 11430Sstevel@tonic-gate int type; 11440Sstevel@tonic-gate int robustness; 11450Sstevel@tonic-gate } mattr_t; 11460Sstevel@tonic-gate 11470Sstevel@tonic-gate typedef struct _thrattr { 11480Sstevel@tonic-gate size_t stksize; 11490Sstevel@tonic-gate void *stkaddr; 11500Sstevel@tonic-gate int detachstate; 11511885Sraf int daemonstate; 11520Sstevel@tonic-gate int scope; 11530Sstevel@tonic-gate int prio; 11540Sstevel@tonic-gate int policy; 11550Sstevel@tonic-gate int inherit; 11560Sstevel@tonic-gate size_t guardsize; 11570Sstevel@tonic-gate } thrattr_t; 11580Sstevel@tonic-gate 11590Sstevel@tonic-gate typedef struct _rwlattr { 11600Sstevel@tonic-gate int pshared; 11610Sstevel@tonic-gate } rwlattr_t; 11620Sstevel@tonic-gate 11630Sstevel@tonic-gate /* _curthread() is inline for speed */ 11640Sstevel@tonic-gate extern ulwp_t *_curthread(void); 11650Sstevel@tonic-gate #define curthread (_curthread()) 11660Sstevel@tonic-gate 11670Sstevel@tonic-gate /* this version (also inline) can be tested for NULL */ 11680Sstevel@tonic-gate extern ulwp_t *__curthread(void); 11690Sstevel@tonic-gate 11700Sstevel@tonic-gate /* get the current stack pointer (also inline) */ 11710Sstevel@tonic-gate extern greg_t stkptr(void); 11720Sstevel@tonic-gate 11730Sstevel@tonic-gate /* 11740Sstevel@tonic-gate * Suppress __attribute__((...)) if we are not compiling with gcc 11750Sstevel@tonic-gate */ 11760Sstevel@tonic-gate #if !defined(__GNUC__) 11770Sstevel@tonic-gate #define __attribute__(string) 11780Sstevel@tonic-gate #endif 11790Sstevel@tonic-gate 11806247Sraf /* Fetch the dispatch (kernel) priority of a thread */ 11816247Sraf #define real_priority(ulwp) \ 11826247Sraf ((ulwp)->ul_schedctl? (ulwp)->ul_schedctl->sc_priority : 0) 11836247Sraf 11840Sstevel@tonic-gate /* 11850Sstevel@tonic-gate * Implementation functions. Not visible outside of the library itself. 11860Sstevel@tonic-gate */ 11872248Sraf extern int __nanosleep(const timespec_t *, timespec_t *); 11880Sstevel@tonic-gate extern void getgregs(ulwp_t *, gregset_t); 11890Sstevel@tonic-gate extern void setgregs(ulwp_t *, gregset_t); 11900Sstevel@tonic-gate extern void thr_panic(const char *); 11910Sstevel@tonic-gate #pragma rarely_called(thr_panic) 11920Sstevel@tonic-gate extern ulwp_t *find_lwp(thread_t); 11930Sstevel@tonic-gate extern void finish_init(void); 11946247Sraf extern void update_sched(ulwp_t *); 11950Sstevel@tonic-gate extern void queue_alloc(void); 11960Sstevel@tonic-gate extern void tsd_exit(void); 11970Sstevel@tonic-gate extern void tsd_free(ulwp_t *); 11980Sstevel@tonic-gate extern void tls_setup(void); 11990Sstevel@tonic-gate extern void tls_exit(void); 12000Sstevel@tonic-gate extern void tls_free(ulwp_t *); 12010Sstevel@tonic-gate extern void rwl_free(ulwp_t *); 12024574Sraf extern void heldlock_exit(void); 12034574Sraf extern void heldlock_free(ulwp_t *); 12040Sstevel@tonic-gate extern void sigacthandler(int, siginfo_t *, void *); 12050Sstevel@tonic-gate extern void signal_init(void); 12060Sstevel@tonic-gate extern int sigequalset(const sigset_t *, const sigset_t *); 12070Sstevel@tonic-gate extern void mutex_setup(void); 12080Sstevel@tonic-gate extern void take_deferred_signal(int); 12097657SRoger.Faulkner@Sun.COM extern void *setup_top_frame(void *, size_t, ulwp_t *); 12100Sstevel@tonic-gate extern int setup_context(ucontext_t *, void *(*func)(ulwp_t *), 12110Sstevel@tonic-gate ulwp_t *ulwp, caddr_t stk, size_t stksize); 12120Sstevel@tonic-gate extern volatile sc_shared_t *setup_schedctl(void); 12130Sstevel@tonic-gate extern void *lmalloc(size_t); 12140Sstevel@tonic-gate extern void lfree(void *, size_t); 12150Sstevel@tonic-gate extern void *libc_malloc(size_t); 12160Sstevel@tonic-gate extern void *libc_realloc(void *, size_t); 12170Sstevel@tonic-gate extern void libc_free(void *); 12180Sstevel@tonic-gate extern char *libc_strdup(const char *); 12190Sstevel@tonic-gate extern void ultos(uint64_t, int, char *); 12200Sstevel@tonic-gate extern void lock_error(const mutex_t *, const char *, void *, const char *); 12210Sstevel@tonic-gate extern void rwlock_error(const rwlock_t *, const char *, const char *); 12220Sstevel@tonic-gate extern void thread_error(const char *); 12230Sstevel@tonic-gate extern void grab_assert_lock(void); 12240Sstevel@tonic-gate extern void dump_queue_statistics(void); 12250Sstevel@tonic-gate extern void collect_queue_statistics(void); 12260Sstevel@tonic-gate extern void record_spin_locks(ulwp_t *); 12274574Sraf extern void remember_lock(mutex_t *); 12284574Sraf extern void forget_lock(mutex_t *); 12294574Sraf extern void register_lock(mutex_t *); 12309264SRoger.Faulkner@Sun.COM extern void unregister_locks(void); 12310Sstevel@tonic-gate #if defined(__sparc) 12320Sstevel@tonic-gate extern void _flush_windows(void); 12330Sstevel@tonic-gate #else 12340Sstevel@tonic-gate #define _flush_windows() 12350Sstevel@tonic-gate #endif 12360Sstevel@tonic-gate extern void set_curthread(void *); 12370Sstevel@tonic-gate 12384570Sraf /* 12394574Sraf * Utility function used when waking up many threads (more than MAXLWPS) 12404574Sraf * all at once. See mutex_wakeup_all(), cond_broadcast(), and rw_unlock(). 12414570Sraf */ 12424570Sraf #define MAXLWPS 128 /* max remembered lwpids before overflow */ 12434570Sraf #define NEWLWPS 2048 /* max remembered lwpids at first overflow */ 12444570Sraf extern lwpid_t *alloc_lwpids(lwpid_t *, int *, int *); 12454570Sraf 12460Sstevel@tonic-gate /* enter a critical section */ 12470Sstevel@tonic-gate #define enter_critical(self) (self->ul_critical++) 12480Sstevel@tonic-gate 12490Sstevel@tonic-gate /* exit a critical section, take deferred actions if necessary */ 12500Sstevel@tonic-gate extern void do_exit_critical(void); 12510Sstevel@tonic-gate #define exit_critical(self) \ 12520Sstevel@tonic-gate (void) (self->ul_critical--, \ 12530Sstevel@tonic-gate ((self->ul_curplease && self->ul_critical == 0)? \ 12540Sstevel@tonic-gate (do_exit_critical(), 0) : 0)) 12550Sstevel@tonic-gate 12560Sstevel@tonic-gate /* 12570Sstevel@tonic-gate * Like enter_critical()/exit_critical() but just for deferring signals. 12580Sstevel@tonic-gate * Unlike enter_critical()/exit_critical(), ul_sigdefer may be set while 12590Sstevel@tonic-gate * calling application functions like constructors and destructors. 12600Sstevel@tonic-gate * Care must be taken if the application function attempts to set 12610Sstevel@tonic-gate * the signal mask while a deferred signal is present; the setting 12620Sstevel@tonic-gate * of the signal mask must also be deferred. 12630Sstevel@tonic-gate */ 12640Sstevel@tonic-gate #define sigoff(self) (self->ul_sigdefer++) 126510637SRoger.Faulkner@Sun.COM #define sigon(self) \ 126610637SRoger.Faulkner@Sun.COM (void) ((--self->ul_sigdefer == 0 && \ 126710637SRoger.Faulkner@Sun.COM self->ul_curplease && self->ul_critical == 0)? \ 126810637SRoger.Faulkner@Sun.COM (do_exit_critical(), 0) : 0) 12690Sstevel@tonic-gate 12700Sstevel@tonic-gate /* these are exported functions */ 12710Sstevel@tonic-gate extern void _sigoff(void); 12720Sstevel@tonic-gate extern void _sigon(void); 12730Sstevel@tonic-gate 12740Sstevel@tonic-gate #define sigorset(s1, s2) \ 12750Sstevel@tonic-gate (((s1)->__sigbits[0] |= (s2)->__sigbits[0]), \ 12760Sstevel@tonic-gate ((s1)->__sigbits[1] |= (s2)->__sigbits[1]), \ 12770Sstevel@tonic-gate ((s1)->__sigbits[2] |= (s2)->__sigbits[2]), \ 12780Sstevel@tonic-gate ((s1)->__sigbits[3] |= (s2)->__sigbits[3])) 12790Sstevel@tonic-gate 12800Sstevel@tonic-gate #define sigandset(s1, s2) \ 12810Sstevel@tonic-gate (((s1)->__sigbits[0] &= (s2)->__sigbits[0]), \ 12820Sstevel@tonic-gate ((s1)->__sigbits[1] &= (s2)->__sigbits[1]), \ 12830Sstevel@tonic-gate ((s1)->__sigbits[2] &= (s2)->__sigbits[2]), \ 12840Sstevel@tonic-gate ((s1)->__sigbits[3] &= (s2)->__sigbits[3])) 12850Sstevel@tonic-gate 12860Sstevel@tonic-gate #define sigdiffset(s1, s2) \ 12870Sstevel@tonic-gate (((s1)->__sigbits[0] &= ~(s2)->__sigbits[0]), \ 12880Sstevel@tonic-gate ((s1)->__sigbits[1] &= ~(s2)->__sigbits[1]), \ 12890Sstevel@tonic-gate ((s1)->__sigbits[2] &= ~(s2)->__sigbits[2]), \ 12900Sstevel@tonic-gate ((s1)->__sigbits[3] &= ~(s2)->__sigbits[3])) 12910Sstevel@tonic-gate 12920Sstevel@tonic-gate #define delete_reserved_signals(s) \ 12930Sstevel@tonic-gate (((s)->__sigbits[0] &= MASKSET0), \ 12940Sstevel@tonic-gate ((s)->__sigbits[1] &= (MASKSET1 & ~SIGMASK(SIGCANCEL))),\ 129511913SRoger.Faulkner@Sun.COM ((s)->__sigbits[2] &= MASKSET2), \ 129611913SRoger.Faulkner@Sun.COM ((s)->__sigbits[3] &= MASKSET3)) 12970Sstevel@tonic-gate 12980Sstevel@tonic-gate extern void block_all_signals(ulwp_t *self); 12990Sstevel@tonic-gate 13000Sstevel@tonic-gate /* 13010Sstevel@tonic-gate * When restoring the signal mask after having previously called 13020Sstevel@tonic-gate * block_all_signals(), if we have a deferred signal present then 13030Sstevel@tonic-gate * do nothing other than ASSERT() that we are in a critical region. 13040Sstevel@tonic-gate * The signal mask will be set when we emerge from the critical region 13050Sstevel@tonic-gate * and call take_deferred_signal(). There is no race condition here 13060Sstevel@tonic-gate * because the kernel currently has all signals blocked for this thread. 13070Sstevel@tonic-gate */ 13080Sstevel@tonic-gate #define restore_signals(self) \ 13090Sstevel@tonic-gate ((void) ((self)->ul_cursig? \ 13100Sstevel@tonic-gate (ASSERT((self)->ul_critical + (self)->ul_sigdefer != 0), 0) : \ 131111913SRoger.Faulkner@Sun.COM __lwp_sigmask(SIG_SETMASK, &(self)->ul_sigmask))) 13120Sstevel@tonic-gate 13135891Sraf extern void set_cancel_pending_flag(ulwp_t *, int); 13145891Sraf extern void set_cancel_eintr_flag(ulwp_t *); 13150Sstevel@tonic-gate extern void set_parking_flag(ulwp_t *, int); 13165891Sraf extern int cancel_active(void); 13170Sstevel@tonic-gate 13186812Sraf extern void *_thrp_setup(ulwp_t *); 13190Sstevel@tonic-gate extern void _fpinherit(ulwp_t *); 13200Sstevel@tonic-gate extern void _lwp_start(void); 13210Sstevel@tonic-gate extern void _lwp_terminate(void); 13222248Sraf extern void lmutex_lock(mutex_t *); 13230Sstevel@tonic-gate extern void lmutex_unlock(mutex_t *); 13244570Sraf extern void lrw_rdlock(rwlock_t *); 13254570Sraf extern void lrw_wrlock(rwlock_t *); 13264570Sraf extern void lrw_unlock(rwlock_t *); 13272248Sraf extern void sig_mutex_lock(mutex_t *); 13282248Sraf extern void sig_mutex_unlock(mutex_t *); 13292248Sraf extern int sig_mutex_trylock(mutex_t *); 13302248Sraf extern int sig_cond_wait(cond_t *, mutex_t *); 13312248Sraf extern int sig_cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *); 13325891Sraf extern void cancel_safe_mutex_lock(mutex_t *); 13335891Sraf extern void cancel_safe_mutex_unlock(mutex_t *); 13345891Sraf extern int cancel_safe_mutex_trylock(mutex_t *); 13350Sstevel@tonic-gate extern void _prefork_handler(void); 13360Sstevel@tonic-gate extern void _postfork_parent_handler(void); 13370Sstevel@tonic-gate extern void _postfork_child_handler(void); 13382248Sraf extern void postfork1_child(void); 13392248Sraf extern void postfork1_child_aio(void); 13402248Sraf extern void postfork1_child_sigev_aio(void); 13412248Sraf extern void postfork1_child_sigev_mq(void); 13422248Sraf extern void postfork1_child_sigev_timer(void); 13432248Sraf extern void postfork1_child_tpool(void); 13444843Sraf extern void fork_lock_enter(void); 13450Sstevel@tonic-gate extern void fork_lock_exit(void); 13460Sstevel@tonic-gate extern void suspend_fork(void); 13470Sstevel@tonic-gate extern void continue_fork(int); 13480Sstevel@tonic-gate extern void do_sigcancel(void); 13492248Sraf extern void setup_cancelsig(int); 13502248Sraf extern void init_sigev_thread(void); 13512248Sraf extern void init_aio(void); 1352*13093SRoger.Faulkner@Oracle.COM extern void init_progname(void); 13530Sstevel@tonic-gate extern void _cancelon(void); 13540Sstevel@tonic-gate extern void _canceloff(void); 13550Sstevel@tonic-gate extern void _canceloff_nocancel(void); 13562248Sraf extern void _cancel_prologue(void); 13572248Sraf extern void _cancel_epilogue(void); 13580Sstevel@tonic-gate extern void no_preempt(ulwp_t *); 13590Sstevel@tonic-gate extern void preempt(ulwp_t *); 13600Sstevel@tonic-gate extern void _thrp_unwind(void *); 13610Sstevel@tonic-gate 13623235Sraf extern pid_t __forkx(int); 13633235Sraf extern pid_t __forkallx(int); 136411798SRoger.Faulkner@Sun.COM extern int __open(const char *, int, mode_t); 136511798SRoger.Faulkner@Sun.COM extern int __open64(const char *, int, mode_t); 136611798SRoger.Faulkner@Sun.COM extern int __openat(int, const char *, int, mode_t); 136711798SRoger.Faulkner@Sun.COM extern int __openat64(int, const char *, int, mode_t); 13686515Sraf extern int __close(int); 13695891Sraf extern ssize_t __read(int, void *, size_t); 13705891Sraf extern ssize_t __write(int, const void *, size_t); 13716515Sraf extern int __fcntl(int, int, ...); 13720Sstevel@tonic-gate extern int __lwp_continue(lwpid_t); 13730Sstevel@tonic-gate extern int __lwp_create(ucontext_t *, uint_t, lwpid_t *); 13740Sstevel@tonic-gate extern int ___lwp_suspend(lwpid_t); 13750Sstevel@tonic-gate extern int lwp_wait(lwpid_t, lwpid_t *); 13760Sstevel@tonic-gate extern int __lwp_wait(lwpid_t, lwpid_t *); 13770Sstevel@tonic-gate extern int __lwp_detach(lwpid_t); 13780Sstevel@tonic-gate extern sc_shared_t *__schedctl(void); 13790Sstevel@tonic-gate 13800Sstevel@tonic-gate /* actual system call traps */ 13816515Sraf extern int __setcontext(const ucontext_t *); 13826515Sraf extern int __getcontext(ucontext_t *); 13830Sstevel@tonic-gate extern int __clock_gettime(clockid_t, timespec_t *); 13840Sstevel@tonic-gate extern void abstime_to_reltime(clockid_t, const timespec_t *, timespec_t *); 13850Sstevel@tonic-gate extern void hrt2ts(hrtime_t, timespec_t *); 13860Sstevel@tonic-gate 13870Sstevel@tonic-gate extern int __sigaction(int, const struct sigaction *, struct sigaction *); 138811913SRoger.Faulkner@Sun.COM extern int __sigprocmask(int, const sigset_t *, sigset_t *); 138911913SRoger.Faulkner@Sun.COM extern int __lwp_sigmask(int, const sigset_t *); 13900Sstevel@tonic-gate extern void __sighndlr(int, siginfo_t *, ucontext_t *, void (*)()); 13910Sstevel@tonic-gate extern caddr_t __sighndlrend; 13920Sstevel@tonic-gate #pragma unknown_control_flow(__sighndlr) 13932248Sraf 13942248Sraf /* belongs in <pthread.h> */ 13952248Sraf #define PTHREAD_CREATE_DAEMON_NP 0x100 /* = THR_DAEMON */ 13962248Sraf #define PTHREAD_CREATE_NONDAEMON_NP 0 13976812Sraf extern int pthread_attr_setdaemonstate_np(pthread_attr_t *, int); 13986812Sraf extern int pthread_attr_getdaemonstate_np(const pthread_attr_t *, int *); 13990Sstevel@tonic-gate 14006812Sraf extern int mutex_held(mutex_t *); 14016247Sraf extern int mutex_lock_internal(mutex_t *, timespec_t *, int); 14026247Sraf extern int mutex_unlock_internal(mutex_t *, int); 14030Sstevel@tonic-gate 14045891Sraf /* not cancellation points: */ 14055891Sraf extern int __cond_wait(cond_t *, mutex_t *); 14065891Sraf extern int __cond_timedwait(cond_t *, mutex_t *, const timespec_t *); 14075891Sraf extern int __cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *); 14080Sstevel@tonic-gate 14096812Sraf extern int rw_read_held(rwlock_t *); 14106812Sraf extern int rw_write_held(rwlock_t *); 14110Sstevel@tonic-gate 14122248Sraf extern int _thrp_create(void *, size_t, void *(*)(void *), void *, long, 14136247Sraf thread_t *, size_t); 14140Sstevel@tonic-gate extern int _thrp_suspend(thread_t, uchar_t); 14150Sstevel@tonic-gate extern int _thrp_continue(thread_t, uchar_t); 14160Sstevel@tonic-gate 14176812Sraf extern void _thrp_terminate(void *); 14180Sstevel@tonic-gate extern void _thrp_exit(void); 14190Sstevel@tonic-gate 14206247Sraf extern const pcclass_t *get_info_by_class(id_t); 14216247Sraf extern const pcclass_t *get_info_by_policy(int); 14221885Sraf extern const thrattr_t *def_thrattr(void); 14236247Sraf extern id_t setparam(idtype_t, id_t, int, int); 14246247Sraf extern id_t setprio(idtype_t, id_t, int, int *); 14256247Sraf extern id_t getparam(idtype_t, id_t, int *, struct sched_param *); 14260Sstevel@tonic-gate 14270Sstevel@tonic-gate /* 14280Sstevel@tonic-gate * System call wrappers (direct interfaces to the kernel) 14290Sstevel@tonic-gate */ 14309264SRoger.Faulkner@Sun.COM extern int ___lwp_mutex_register(mutex_t *, mutex_t **); 143110887SRoger.Faulkner@Sun.COM extern int ___lwp_mutex_trylock(mutex_t *, ulwp_t *); 143210887SRoger.Faulkner@Sun.COM extern int ___lwp_mutex_timedlock(mutex_t *, timespec_t *, ulwp_t *); 14330Sstevel@tonic-gate extern int ___lwp_mutex_unlock(mutex_t *); 14344574Sraf extern int ___lwp_mutex_wakeup(mutex_t *, int); 14350Sstevel@tonic-gate extern int ___lwp_cond_wait(cond_t *, mutex_t *, timespec_t *, int); 14360Sstevel@tonic-gate extern int ___lwp_sema_timedwait(lwp_sema_t *, timespec_t *, int); 14370Sstevel@tonic-gate extern int __lwp_rwlock_rdlock(rwlock_t *, timespec_t *); 14380Sstevel@tonic-gate extern int __lwp_rwlock_wrlock(rwlock_t *, timespec_t *); 14390Sstevel@tonic-gate extern int __lwp_rwlock_tryrdlock(rwlock_t *); 14400Sstevel@tonic-gate extern int __lwp_rwlock_trywrlock(rwlock_t *); 14410Sstevel@tonic-gate extern int __lwp_rwlock_unlock(rwlock_t *); 14420Sstevel@tonic-gate extern int __lwp_park(timespec_t *, lwpid_t); 14430Sstevel@tonic-gate extern int __lwp_unpark(lwpid_t); 14440Sstevel@tonic-gate extern int __lwp_unpark_all(lwpid_t *, int); 14451016Sraf #if defined(__x86) 14460Sstevel@tonic-gate extern int ___lwp_private(int, int, void *); 14471016Sraf #endif /* __x86 */ 14480Sstevel@tonic-gate 14490Sstevel@tonic-gate /* 14500Sstevel@tonic-gate * inlines 14510Sstevel@tonic-gate */ 14520Sstevel@tonic-gate extern int set_lock_byte(volatile uint8_t *); 14534570Sraf extern uint32_t atomic_swap_32(volatile uint32_t *, uint32_t); 14544570Sraf extern uint32_t atomic_cas_32(volatile uint32_t *, uint32_t, uint32_t); 14554570Sraf extern void atomic_inc_32(volatile uint32_t *); 14564570Sraf extern void atomic_dec_32(volatile uint32_t *); 14574570Sraf extern void atomic_and_32(volatile uint32_t *, uint32_t); 14584570Sraf extern void atomic_or_32(volatile uint32_t *, uint32_t); 14591016Sraf #if defined(__sparc) 14601016Sraf extern ulong_t caller(void); 14611016Sraf extern ulong_t getfp(void); 14621016Sraf #endif /* __sparc */ 14631016Sraf 14641016Sraf #include "thr_inlines.h" 14650Sstevel@tonic-gate 14660Sstevel@tonic-gate #endif /* _THR_UBERDATA_H */ 1467