1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _THR_UBERDATA_H 28*7c478bd9Sstevel@tonic-gate #define _THR_UBERDATA_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 33*7c478bd9Sstevel@tonic-gate #include <unistd.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 35*7c478bd9Sstevel@tonic-gate #include <fcntl.h> 36*7c478bd9Sstevel@tonic-gate #include <string.h> 37*7c478bd9Sstevel@tonic-gate #include <signal.h> 38*7c478bd9Sstevel@tonic-gate #include <ucontext.h> 39*7c478bd9Sstevel@tonic-gate #include <thread.h> 40*7c478bd9Sstevel@tonic-gate #include <pthread.h> 41*7c478bd9Sstevel@tonic-gate #include <link.h> 42*7c478bd9Sstevel@tonic-gate #include <sys/resource.h> 43*7c478bd9Sstevel@tonic-gate #include <sys/lwp.h> 44*7c478bd9Sstevel@tonic-gate #include <errno.h> 45*7c478bd9Sstevel@tonic-gate #include <sys/asm_linkage.h> 46*7c478bd9Sstevel@tonic-gate #include <sys/regset.h> 47*7c478bd9Sstevel@tonic-gate #include <sys/fcntl.h> 48*7c478bd9Sstevel@tonic-gate #include <sys/mman.h> 49*7c478bd9Sstevel@tonic-gate #include <synch.h> 50*7c478bd9Sstevel@tonic-gate #include <door.h> 51*7c478bd9Sstevel@tonic-gate #include <limits.h> 52*7c478bd9Sstevel@tonic-gate #include <sys/synch32.h> 53*7c478bd9Sstevel@tonic-gate #include <schedctl.h> 54*7c478bd9Sstevel@tonic-gate #include <sys/priocntl.h> 55*7c478bd9Sstevel@tonic-gate #include <thread_db.h> 56*7c478bd9Sstevel@tonic-gate #include "libc_int.h" 57*7c478bd9Sstevel@tonic-gate #include "tdb_agent.h" 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate /* 60*7c478bd9Sstevel@tonic-gate * This is an implementation-specific include file for threading support. 61*7c478bd9Sstevel@tonic-gate * It is not to be seen by the clients of the library. 62*7c478bd9Sstevel@tonic-gate * 63*7c478bd9Sstevel@tonic-gate * This file also describes uberdata in libc. 64*7c478bd9Sstevel@tonic-gate * 65*7c478bd9Sstevel@tonic-gate * The term "uberdata" refers to data that is unique and visible across 66*7c478bd9Sstevel@tonic-gate * all link maps. The name is meant to imply that such data is truly 67*7c478bd9Sstevel@tonic-gate * global, not just locally global to a particular link map. 68*7c478bd9Sstevel@tonic-gate * 69*7c478bd9Sstevel@tonic-gate * See the Linker and Libraries Guide for a full description of alternate 70*7c478bd9Sstevel@tonic-gate * link maps and how they are set up and used. 71*7c478bd9Sstevel@tonic-gate * 72*7c478bd9Sstevel@tonic-gate * Alternate link maps implement multiple global namespaces within a single 73*7c478bd9Sstevel@tonic-gate * process. There may be multiple instances of identical dynamic libraries 74*7c478bd9Sstevel@tonic-gate * loaded in a process's address space at the same time, each on a different 75*7c478bd9Sstevel@tonic-gate * link map (as determined by the dynamic linker), each with its own set of 76*7c478bd9Sstevel@tonic-gate * global variables. Which particular instance of a global variable is seen 77*7c478bd9Sstevel@tonic-gate * by a thread running in the process is determined by the link map on which 78*7c478bd9Sstevel@tonic-gate * the thread happens to be executing at the time. 79*7c478bd9Sstevel@tonic-gate * 80*7c478bd9Sstevel@tonic-gate * However, there are aspects of a process that are unique across all 81*7c478bd9Sstevel@tonic-gate * link maps, in particular the structures used to implement threads 82*7c478bd9Sstevel@tonic-gate * of control (in Sparc terminology, there is only one %g7 regardless 83*7c478bd9Sstevel@tonic-gate * of the link map on which the thread is executing). 84*7c478bd9Sstevel@tonic-gate * 85*7c478bd9Sstevel@tonic-gate * All uberdata is referenced from a base pointer in the thread's ulwp_t 86*7c478bd9Sstevel@tonic-gate * structure (which is also uberdata). All allocations and deallocations 87*7c478bd9Sstevel@tonic-gate * of uberdata are made via the uberdata-aware lmalloc() and lfree() 88*7c478bd9Sstevel@tonic-gate * interfaces (malloc() and free() are simply locally-global). 89*7c478bd9Sstevel@tonic-gate */ 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate /* 92*7c478bd9Sstevel@tonic-gate * Special libc-private access to errno. 93*7c478bd9Sstevel@tonic-gate * We do this so that references to errno do not invoke the dynamic linker. 94*7c478bd9Sstevel@tonic-gate */ 95*7c478bd9Sstevel@tonic-gate #undef errno 96*7c478bd9Sstevel@tonic-gate #define errno (*curthread->ul_errnop) 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate /* 99*7c478bd9Sstevel@tonic-gate * See <sys/synch32.h> for the reasons for these values 100*7c478bd9Sstevel@tonic-gate * and why they are different for sparc and intel. 101*7c478bd9Sstevel@tonic-gate */ 102*7c478bd9Sstevel@tonic-gate #if defined(__sparc) 103*7c478bd9Sstevel@tonic-gate /* lock.lock64.pad[x] 4 5 6 7 */ 104*7c478bd9Sstevel@tonic-gate #define LOCKMASK 0xff000000 105*7c478bd9Sstevel@tonic-gate #define WAITERMASK 0x000000ff 106*7c478bd9Sstevel@tonic-gate #define WAITER 0x00000001 107*7c478bd9Sstevel@tonic-gate #define LOCKSET 0xff 108*7c478bd9Sstevel@tonic-gate #define LOCKCLEAR 0 109*7c478bd9Sstevel@tonic-gate #elif defined(__i386) || defined(__amd64) 110*7c478bd9Sstevel@tonic-gate /* lock.lock64.pad[x] 7 6 5 4 */ 111*7c478bd9Sstevel@tonic-gate #define LOCKMASK 0xff000000 112*7c478bd9Sstevel@tonic-gate #define WAITERMASK 0x00ff0000 113*7c478bd9Sstevel@tonic-gate #define WAITER 0x00010000 114*7c478bd9Sstevel@tonic-gate #define LOCKSET 0x01 115*7c478bd9Sstevel@tonic-gate #define LOCKCLEAR 0 116*7c478bd9Sstevel@tonic-gate #else 117*7c478bd9Sstevel@tonic-gate #error "none of __sparc __i386 __amd64 is defined" 118*7c478bd9Sstevel@tonic-gate #endif 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate /* 121*7c478bd9Sstevel@tonic-gate * Fetch the owner of a USYNC_THREAD mutex. 122*7c478bd9Sstevel@tonic-gate * Don't use this with process-shared mutexes; 123*7c478bd9Sstevel@tonic-gate * the owing thread may be in a different process. 124*7c478bd9Sstevel@tonic-gate */ 125*7c478bd9Sstevel@tonic-gate #define MUTEX_OWNER(mp) ((ulwp_t *)(uintptr_t)(mp)->mutex_owner) 126*7c478bd9Sstevel@tonic-gate 127*7c478bd9Sstevel@tonic-gate /* 128*7c478bd9Sstevel@tonic-gate * Test if a thread owns a USYNC_THREAD mutex. This is inappropriate 129*7c478bd9Sstevel@tonic-gate * for a process-shared (USYNC_PROCESS | USYNC_PROCESS_ROBUST) mutex. 130*7c478bd9Sstevel@tonic-gate * The 'mp' argument must not have side-effects since it is evaluated twice. 131*7c478bd9Sstevel@tonic-gate */ 132*7c478bd9Sstevel@tonic-gate #define MUTEX_OWNED(mp, thrp) \ 133*7c478bd9Sstevel@tonic-gate ((mp)->mutex_lockw != 0 && MUTEX_OWNER(mp) == thrp) 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate /* 137*7c478bd9Sstevel@tonic-gate * uberflags.uf_tdb_register_sync is an interface with libc_db to enable the 138*7c478bd9Sstevel@tonic-gate * collection of lock statistics by a debugger or other collecting tool. 139*7c478bd9Sstevel@tonic-gate * 140*7c478bd9Sstevel@tonic-gate * uberflags.uf_thread_error_detection is set by an environment variable: 141*7c478bd9Sstevel@tonic-gate * _THREAD_ERROR_DETECTION 142*7c478bd9Sstevel@tonic-gate * 0 == no detection of locking primitive errors. 143*7c478bd9Sstevel@tonic-gate * 1 == detect errors and issue a warning message. 144*7c478bd9Sstevel@tonic-gate * 2 == detect errors, issue a warning message, and dump core. 145*7c478bd9Sstevel@tonic-gate * 146*7c478bd9Sstevel@tonic-gate * We bundle these together in uberflags.uf_trs_ted to make a test of either 147*7c478bd9Sstevel@tonic-gate * being non-zero a single memory reference (for speed of mutex_lock(), etc). 148*7c478bd9Sstevel@tonic-gate * 149*7c478bd9Sstevel@tonic-gate * uberflags.uf_mt is set non-zero when the first thread (in addition 150*7c478bd9Sstevel@tonic-gate * to the main thread) is created. 151*7c478bd9Sstevel@tonic-gate * 152*7c478bd9Sstevel@tonic-gate * We bundle all these flags together in uberflags.uf_all to make a test 153*7c478bd9Sstevel@tonic-gate * of any being non-zero a single memory reference (again, for speed). 154*7c478bd9Sstevel@tonic-gate */ 155*7c478bd9Sstevel@tonic-gate typedef union { 156*7c478bd9Sstevel@tonic-gate int uf_all; /* combined all flags */ 157*7c478bd9Sstevel@tonic-gate struct { 158*7c478bd9Sstevel@tonic-gate short h_pad; 159*7c478bd9Sstevel@tonic-gate short h_trs_ted; /* combined reg sync & error detect */ 160*7c478bd9Sstevel@tonic-gate } uf_h; 161*7c478bd9Sstevel@tonic-gate struct { 162*7c478bd9Sstevel@tonic-gate char x_mt; 163*7c478bd9Sstevel@tonic-gate char x_pad; 164*7c478bd9Sstevel@tonic-gate char x_tdb_register_sync; 165*7c478bd9Sstevel@tonic-gate char x_thread_error_detection; 166*7c478bd9Sstevel@tonic-gate } uf_x; 167*7c478bd9Sstevel@tonic-gate } uberflags_t; 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate #define uf_mt uf_x.x_mt 170*7c478bd9Sstevel@tonic-gate #define uf_tdb_register_sync uf_x.x_tdb_register_sync 171*7c478bd9Sstevel@tonic-gate #define uf_thread_error_detection uf_x.x_thread_error_detection 172*7c478bd9Sstevel@tonic-gate #define uf_trs_ted uf_h.h_trs_ted /* both of the above */ 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate /* 175*7c478bd9Sstevel@tonic-gate * NOTE WELL: 176*7c478bd9Sstevel@tonic-gate * To enable further optimization, the "ul_schedctl_called" member 177*7c478bd9Sstevel@tonic-gate * of the ulwp_t structure (below) serves double-duty: 178*7c478bd9Sstevel@tonic-gate * 1. If NULL, it means that the thread must call __schedctl() 179*7c478bd9Sstevel@tonic-gate * to set up its schedctl mappings before acquiring a mutex. 180*7c478bd9Sstevel@tonic-gate * This is required by the implementation of adaptive mutex locking. 181*7c478bd9Sstevel@tonic-gate * 2. If non-NULL, it points to uberdata.uberflags, so that tests of 182*7c478bd9Sstevel@tonic-gate * uberflags can be made without additional memory references. 183*7c478bd9Sstevel@tonic-gate * This allows the common case of _mutex_lock() and _mutex_unlock() for 184*7c478bd9Sstevel@tonic-gate * USYNC_THREAD mutexes with no error detection and no lock statistics 185*7c478bd9Sstevel@tonic-gate * to be optimized for speed. 186*7c478bd9Sstevel@tonic-gate */ 187*7c478bd9Sstevel@tonic-gate 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate /* double the default stack size for 64-bit processes */ 190*7c478bd9Sstevel@tonic-gate #ifdef _LP64 191*7c478bd9Sstevel@tonic-gate #define MINSTACK (8 * 1024) 192*7c478bd9Sstevel@tonic-gate #define DEFAULTSTACK (2 * 1024 * 1024) 193*7c478bd9Sstevel@tonic-gate #else 194*7c478bd9Sstevel@tonic-gate #define MINSTACK (4 * 1024) 195*7c478bd9Sstevel@tonic-gate #define DEFAULTSTACK (1024 * 1024) 196*7c478bd9Sstevel@tonic-gate #endif 197*7c478bd9Sstevel@tonic-gate #define TSD_NKEYS _POSIX_THREAD_KEYS_MAX 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate #define THREAD_MIN_PRIORITY 0 200*7c478bd9Sstevel@tonic-gate #define THREAD_MAX_PRIORITY 127 201*7c478bd9Sstevel@tonic-gate 202*7c478bd9Sstevel@tonic-gate #define PRIO_SET 0 /* set priority and policy */ 203*7c478bd9Sstevel@tonic-gate #define PRIO_SET_PRIO 1 /* set priority only */ 204*7c478bd9Sstevel@tonic-gate #define PRIO_INHERIT 2 205*7c478bd9Sstevel@tonic-gate #define PRIO_DISINHERIT 3 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate struct pcclass { 208*7c478bd9Sstevel@tonic-gate short pcc_state; 209*7c478bd9Sstevel@tonic-gate pri_t pcc_primin; 210*7c478bd9Sstevel@tonic-gate pri_t pcc_primax; 211*7c478bd9Sstevel@tonic-gate pcinfo_t pcc_info; 212*7c478bd9Sstevel@tonic-gate }; 213*7c478bd9Sstevel@tonic-gate extern struct pcclass ts_class, rt_class; 214*7c478bd9Sstevel@tonic-gate 215*7c478bd9Sstevel@tonic-gate #define MUTEX_TRY 0 216*7c478bd9Sstevel@tonic-gate #define MUTEX_LOCK 1 217*7c478bd9Sstevel@tonic-gate 218*7c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64) 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate typedef struct { /* structure returned by fnstenv */ 221*7c478bd9Sstevel@tonic-gate int fctrl; /* control word */ 222*7c478bd9Sstevel@tonic-gate int fstat; /* status word (flags, etc) */ 223*7c478bd9Sstevel@tonic-gate int ftag; /* tag of which regs busy */ 224*7c478bd9Sstevel@tonic-gate int misc[4]; /* other stuff, 28 bytes total */ 225*7c478bd9Sstevel@tonic-gate } fpuenv_t; 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32 228*7c478bd9Sstevel@tonic-gate typedef fpuenv_t fpuenv32_t; 229*7c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 230*7c478bd9Sstevel@tonic-gate 231*7c478bd9Sstevel@tonic-gate #elif defined(__sparc) 232*7c478bd9Sstevel@tonic-gate 233*7c478bd9Sstevel@tonic-gate typedef struct { /* fp state structure */ 234*7c478bd9Sstevel@tonic-gate greg_t fsr; 235*7c478bd9Sstevel@tonic-gate greg_t fpu_en; 236*7c478bd9Sstevel@tonic-gate } fpuenv_t; 237*7c478bd9Sstevel@tonic-gate 238*7c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32 239*7c478bd9Sstevel@tonic-gate typedef struct { 240*7c478bd9Sstevel@tonic-gate greg32_t fsr; 241*7c478bd9Sstevel@tonic-gate greg32_t fpu_en; 242*7c478bd9Sstevel@tonic-gate } fpuenv32_t; 243*7c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 244*7c478bd9Sstevel@tonic-gate 245*7c478bd9Sstevel@tonic-gate #endif /* __i386 || __amd64 */ 246*7c478bd9Sstevel@tonic-gate 247*7c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64) 248*7c478bd9Sstevel@tonic-gate extern void ht_pause(void); /* "pause" instruction */ 249*7c478bd9Sstevel@tonic-gate #define SMT_PAUSE() ht_pause() 250*7c478bd9Sstevel@tonic-gate #else 251*7c478bd9Sstevel@tonic-gate #define SMT_PAUSE() 252*7c478bd9Sstevel@tonic-gate #endif /* __i386 || __amd64 */ 253*7c478bd9Sstevel@tonic-gate 254*7c478bd9Sstevel@tonic-gate /* 255*7c478bd9Sstevel@tonic-gate * Cleanup handler related data. 256*7c478bd9Sstevel@tonic-gate * This structure is exported as _cleanup_t in pthread.h. 257*7c478bd9Sstevel@tonic-gate * pthread.h exports only the size of this structure, so check 258*7c478bd9Sstevel@tonic-gate * _cleanup_t in pthread.h before making any change here. 259*7c478bd9Sstevel@tonic-gate */ 260*7c478bd9Sstevel@tonic-gate typedef struct __cleanup { 261*7c478bd9Sstevel@tonic-gate struct __cleanup *next; /* pointer to next handler */ 262*7c478bd9Sstevel@tonic-gate caddr_t fp; /* current frame pointer */ 263*7c478bd9Sstevel@tonic-gate void (*func)(void *); /* cleanup handler address */ 264*7c478bd9Sstevel@tonic-gate void *arg; /* handler's argument */ 265*7c478bd9Sstevel@tonic-gate } __cleanup_t; 266*7c478bd9Sstevel@tonic-gate 267*7c478bd9Sstevel@tonic-gate /* 268*7c478bd9Sstevel@tonic-gate * Thread-Specific Data (TSD) 269*7c478bd9Sstevel@tonic-gate * TSD_NFAST includes the invalid key zero, so there 270*7c478bd9Sstevel@tonic-gate * are really only (TSD_NFAST - 1) fast key slots. 271*7c478bd9Sstevel@tonic-gate */ 272*7c478bd9Sstevel@tonic-gate typedef void (*PFrV)(void *); 273*7c478bd9Sstevel@tonic-gate #define TSD_UNALLOCATED ((PFrV)1) 274*7c478bd9Sstevel@tonic-gate #define TSD_NFAST 9 275*7c478bd9Sstevel@tonic-gate 276*7c478bd9Sstevel@tonic-gate /* 277*7c478bd9Sstevel@tonic-gate * The tsd union is designed to burn a little memory (9 words) to make 278*7c478bd9Sstevel@tonic-gate * lookups blindingly fast. Note that tsd_nalloc could be placed at the 279*7c478bd9Sstevel@tonic-gate * end of the pad region to increase the likelihood that it falls on the 280*7c478bd9Sstevel@tonic-gate * same cache line as the data. 281*7c478bd9Sstevel@tonic-gate */ 282*7c478bd9Sstevel@tonic-gate typedef union tsd { 283*7c478bd9Sstevel@tonic-gate uint_t tsd_nalloc; /* Amount of allocated storage */ 284*7c478bd9Sstevel@tonic-gate void *tsd_pad[TSD_NFAST]; 285*7c478bd9Sstevel@tonic-gate void *tsd_data[1]; 286*7c478bd9Sstevel@tonic-gate } tsd_t; 287*7c478bd9Sstevel@tonic-gate 288*7c478bd9Sstevel@tonic-gate typedef struct { 289*7c478bd9Sstevel@tonic-gate mutex_t tsdm_lock; /* Lock protecting the data */ 290*7c478bd9Sstevel@tonic-gate uint_t tsdm_nkeys; /* Number of allocated keys */ 291*7c478bd9Sstevel@tonic-gate uint_t tsdm_nused; /* Number of used keys */ 292*7c478bd9Sstevel@tonic-gate PFrV *tsdm_destro; /* Per-key destructors */ 293*7c478bd9Sstevel@tonic-gate char tsdm_pad[64 - /* pad to 64 bytes */ 294*7c478bd9Sstevel@tonic-gate (sizeof (mutex_t) + 2 * sizeof (uint_t) + sizeof (PFrV *))]; 295*7c478bd9Sstevel@tonic-gate } tsd_metadata_t; 296*7c478bd9Sstevel@tonic-gate 297*7c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32 298*7c478bd9Sstevel@tonic-gate typedef union tsd32 { 299*7c478bd9Sstevel@tonic-gate uint_t tsd_nalloc; /* Amount of allocated storage */ 300*7c478bd9Sstevel@tonic-gate caddr32_t tsd_pad[TSD_NFAST]; 301*7c478bd9Sstevel@tonic-gate caddr32_t tsd_data[1]; 302*7c478bd9Sstevel@tonic-gate } tsd32_t; 303*7c478bd9Sstevel@tonic-gate 304*7c478bd9Sstevel@tonic-gate typedef struct { 305*7c478bd9Sstevel@tonic-gate mutex_t tsdm_lock; /* Lock protecting the data */ 306*7c478bd9Sstevel@tonic-gate uint_t tsdm_nkeys; /* Number of allocated keys */ 307*7c478bd9Sstevel@tonic-gate uint_t tsdm_nused; /* Number of used keys */ 308*7c478bd9Sstevel@tonic-gate caddr32_t tsdm_destro; /* Per-key destructors */ 309*7c478bd9Sstevel@tonic-gate char tsdm_pad[64 - /* pad to 64 bytes */ 310*7c478bd9Sstevel@tonic-gate (sizeof (mutex_t) + 2 * sizeof (uint_t) + sizeof (caddr32_t))]; 311*7c478bd9Sstevel@tonic-gate } tsd_metadata32_t; 312*7c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 313*7c478bd9Sstevel@tonic-gate 314*7c478bd9Sstevel@tonic-gate 315*7c478bd9Sstevel@tonic-gate /* 316*7c478bd9Sstevel@tonic-gate * Thread-Local Storage (TLS) 317*7c478bd9Sstevel@tonic-gate */ 318*7c478bd9Sstevel@tonic-gate typedef struct { 319*7c478bd9Sstevel@tonic-gate void *tls_data; 320*7c478bd9Sstevel@tonic-gate size_t tls_size; 321*7c478bd9Sstevel@tonic-gate } tls_t; 322*7c478bd9Sstevel@tonic-gate 323*7c478bd9Sstevel@tonic-gate typedef struct { 324*7c478bd9Sstevel@tonic-gate mutex_t tls_lock; /* Lock protecting the data */ 325*7c478bd9Sstevel@tonic-gate tls_t tls_modinfo; /* Root of all TLS_modinfo data */ 326*7c478bd9Sstevel@tonic-gate tls_t static_tls; /* Template for static TLS */ 327*7c478bd9Sstevel@tonic-gate char tls_pad[64 - /* pad to 64 bytes */ 328*7c478bd9Sstevel@tonic-gate (sizeof (mutex_t) + 2 * sizeof (tls_t))]; 329*7c478bd9Sstevel@tonic-gate } tls_metadata_t; 330*7c478bd9Sstevel@tonic-gate 331*7c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32 332*7c478bd9Sstevel@tonic-gate typedef struct { 333*7c478bd9Sstevel@tonic-gate caddr32_t tls_data; 334*7c478bd9Sstevel@tonic-gate size32_t tls_size; 335*7c478bd9Sstevel@tonic-gate } tls32_t; 336*7c478bd9Sstevel@tonic-gate 337*7c478bd9Sstevel@tonic-gate typedef struct { 338*7c478bd9Sstevel@tonic-gate mutex_t tls_lock; /* Lock protecting the data */ 339*7c478bd9Sstevel@tonic-gate tls32_t tls_modinfo; /* Root of all TLS_modinfo data */ 340*7c478bd9Sstevel@tonic-gate tls32_t static_tls; /* Template for static TLS */ 341*7c478bd9Sstevel@tonic-gate char tls_pad[64 - /* pad to 64 bytes */ 342*7c478bd9Sstevel@tonic-gate (sizeof (mutex_t) + 2 * sizeof (tls32_t))]; 343*7c478bd9Sstevel@tonic-gate } tls_metadata32_t; 344*7c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 345*7c478bd9Sstevel@tonic-gate 346*7c478bd9Sstevel@tonic-gate 347*7c478bd9Sstevel@tonic-gate /* 348*7c478bd9Sstevel@tonic-gate * Sleep queues for USYNC_THREAD condvars and mutexes. 349*7c478bd9Sstevel@tonic-gate * The size and alignment is 64 bytes to reduce cache conflicts. 350*7c478bd9Sstevel@tonic-gate */ 351*7c478bd9Sstevel@tonic-gate typedef union { 352*7c478bd9Sstevel@tonic-gate uint64_t qh_64[8]; 353*7c478bd9Sstevel@tonic-gate struct { 354*7c478bd9Sstevel@tonic-gate mutex_t q_lock; 355*7c478bd9Sstevel@tonic-gate uint8_t q_qcnt; 356*7c478bd9Sstevel@tonic-gate uint8_t q_pad[7]; 357*7c478bd9Sstevel@tonic-gate uint64_t q_lockcount; 358*7c478bd9Sstevel@tonic-gate uint32_t q_qlen; 359*7c478bd9Sstevel@tonic-gate uint32_t q_qmax; 360*7c478bd9Sstevel@tonic-gate struct ulwp *q_head; 361*7c478bd9Sstevel@tonic-gate struct ulwp *q_tail; 362*7c478bd9Sstevel@tonic-gate } qh_qh; 363*7c478bd9Sstevel@tonic-gate } queue_head_t; 364*7c478bd9Sstevel@tonic-gate 365*7c478bd9Sstevel@tonic-gate #define qh_lock qh_qh.q_lock 366*7c478bd9Sstevel@tonic-gate #define qh_qcnt qh_qh.q_qcnt 367*7c478bd9Sstevel@tonic-gate #define qh_lockcount qh_qh.q_lockcount 368*7c478bd9Sstevel@tonic-gate #define qh_qlen qh_qh.q_qlen 369*7c478bd9Sstevel@tonic-gate #define qh_qmax qh_qh.q_qmax 370*7c478bd9Sstevel@tonic-gate #define qh_head qh_qh.q_head 371*7c478bd9Sstevel@tonic-gate #define qh_tail qh_qh.q_tail 372*7c478bd9Sstevel@tonic-gate 373*7c478bd9Sstevel@tonic-gate /* queue types passed to queue_lock() and enqueue() */ 374*7c478bd9Sstevel@tonic-gate #define MX 0 375*7c478bd9Sstevel@tonic-gate #define CV 1 376*7c478bd9Sstevel@tonic-gate #define FIFOQ 0x10 /* or'ing with FIFOQ asks for FIFO queueing */ 377*7c478bd9Sstevel@tonic-gate #define QHASHSIZE 512 378*7c478bd9Sstevel@tonic-gate #define QUEUE_HASH(wchan, type) \ 379*7c478bd9Sstevel@tonic-gate ((uint_t)((((uintptr_t)(wchan) >> 3) ^ ((uintptr_t)(wchan) >> 12)) \ 380*7c478bd9Sstevel@tonic-gate & (QHASHSIZE - 1)) + (((type) == MX)? 0 : QHASHSIZE)) 381*7c478bd9Sstevel@tonic-gate 382*7c478bd9Sstevel@tonic-gate extern queue_head_t *queue_lock(void *, int); 383*7c478bd9Sstevel@tonic-gate extern void queue_unlock(queue_head_t *); 384*7c478bd9Sstevel@tonic-gate extern void enqueue(queue_head_t *, struct ulwp *, void *, int); 385*7c478bd9Sstevel@tonic-gate extern struct ulwp *dequeue(queue_head_t *, void *, int *); 386*7c478bd9Sstevel@tonic-gate extern struct ulwp *queue_waiter(queue_head_t *, void *); 387*7c478bd9Sstevel@tonic-gate extern uint8_t dequeue_self(queue_head_t *, void *); 388*7c478bd9Sstevel@tonic-gate extern void unsleep_self(void); 389*7c478bd9Sstevel@tonic-gate extern void spin_lock_set(mutex_t *); 390*7c478bd9Sstevel@tonic-gate extern void spin_lock_clear(mutex_t *); 391*7c478bd9Sstevel@tonic-gate 392*7c478bd9Sstevel@tonic-gate /* 393*7c478bd9Sstevel@tonic-gate * Memory block for chain of owned ceiling mutexes. 394*7c478bd9Sstevel@tonic-gate */ 395*7c478bd9Sstevel@tonic-gate typedef struct mxchain { 396*7c478bd9Sstevel@tonic-gate struct mxchain *mxchain_next; 397*7c478bd9Sstevel@tonic-gate mutex_t *mxchain_mx; 398*7c478bd9Sstevel@tonic-gate } mxchain_t; 399*7c478bd9Sstevel@tonic-gate 400*7c478bd9Sstevel@tonic-gate /* 401*7c478bd9Sstevel@tonic-gate * Pointer to an rwlock that is held for reading. 402*7c478bd9Sstevel@tonic-gate * Used in rw_rdlock() to allow a thread that already holds a read 403*7c478bd9Sstevel@tonic-gate * lock to acquire another read lock on the same rwlock even if 404*7c478bd9Sstevel@tonic-gate * there are writers waiting. This to avoid deadlock when acquiring 405*7c478bd9Sstevel@tonic-gate * a read lock more than once in the presence of pending writers. 406*7c478bd9Sstevel@tonic-gate * POSIX mandates this behavior. 407*7c478bd9Sstevel@tonic-gate */ 408*7c478bd9Sstevel@tonic-gate typedef struct { 409*7c478bd9Sstevel@tonic-gate void *rd_rwlock; /* the rwlock held for reading */ 410*7c478bd9Sstevel@tonic-gate size_t rd_count; /* count of read locks applied */ 411*7c478bd9Sstevel@tonic-gate } readlock_t; 412*7c478bd9Sstevel@tonic-gate 413*7c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32 414*7c478bd9Sstevel@tonic-gate typedef struct { 415*7c478bd9Sstevel@tonic-gate caddr32_t rd_rwlock; 416*7c478bd9Sstevel@tonic-gate size32_t rd_count; 417*7c478bd9Sstevel@tonic-gate } readlock32_t; 418*7c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 419*7c478bd9Sstevel@tonic-gate 420*7c478bd9Sstevel@tonic-gate /* 421*7c478bd9Sstevel@tonic-gate * Maximum number of read locks allowed for one thread on one rwlock. 422*7c478bd9Sstevel@tonic-gate * This could be as large as INT_MAX, but the SUSV3 test suite would 423*7c478bd9Sstevel@tonic-gate * take an inordinately long time to complete. This is big enough. 424*7c478bd9Sstevel@tonic-gate */ 425*7c478bd9Sstevel@tonic-gate #define READ_LOCK_MAX 100000 426*7c478bd9Sstevel@tonic-gate 427*7c478bd9Sstevel@tonic-gate #define ul_tlsent ul_tls.tls_data /* array of pointers to dynamic TLS */ 428*7c478bd9Sstevel@tonic-gate #define ul_ntlsent ul_tls.tls_size /* number of entries in ul_tlsent */ 429*7c478bd9Sstevel@tonic-gate 430*7c478bd9Sstevel@tonic-gate /* 431*7c478bd9Sstevel@tonic-gate * Round up an integral value to a multiple of 64 432*7c478bd9Sstevel@tonic-gate */ 433*7c478bd9Sstevel@tonic-gate #define roundup64(x) (-(-(x) & -64)) 434*7c478bd9Sstevel@tonic-gate 435*7c478bd9Sstevel@tonic-gate /* 436*7c478bd9Sstevel@tonic-gate * NOTE: Whatever changes are made to ulwp_t must be 437*7c478bd9Sstevel@tonic-gate * reflected in $SRC/cmd/mdb/common/modules/libc/libc.c 438*7c478bd9Sstevel@tonic-gate * 439*7c478bd9Sstevel@tonic-gate * NOTE: ul_self *must* be the first member of ulwp_t on x86 440*7c478bd9Sstevel@tonic-gate * Low-level x86 code relies on this. 441*7c478bd9Sstevel@tonic-gate */ 442*7c478bd9Sstevel@tonic-gate typedef struct ulwp { 443*7c478bd9Sstevel@tonic-gate /* 444*7c478bd9Sstevel@tonic-gate * These members always need to come first on sparc. 445*7c478bd9Sstevel@tonic-gate * For dtrace, a ulwp_t must be aligned on a 64-byte boundary. 446*7c478bd9Sstevel@tonic-gate */ 447*7c478bd9Sstevel@tonic-gate #if defined(__sparc) 448*7c478bd9Sstevel@tonic-gate uint32_t ul_dinstr; /* scratch space for dtrace */ 449*7c478bd9Sstevel@tonic-gate uint32_t ul_padsparc0[15]; 450*7c478bd9Sstevel@tonic-gate uint32_t ul_dsave; /* dtrace: save %g1, %g0, %sp */ 451*7c478bd9Sstevel@tonic-gate uint32_t ul_drestore; /* dtrace: restore %g0, %g0, %g0 */ 452*7c478bd9Sstevel@tonic-gate uint32_t ul_dftret; /* dtrace: return probe fasttrap */ 453*7c478bd9Sstevel@tonic-gate uint32_t ul_dreturn; /* dtrace: return %o0 */ 454*7c478bd9Sstevel@tonic-gate #endif 455*7c478bd9Sstevel@tonic-gate struct ulwp *ul_self; /* pointer to self */ 456*7c478bd9Sstevel@tonic-gate #if defined(__i386) 457*7c478bd9Sstevel@tonic-gate uint8_t ul_dinstr[40]; /* scratch space for dtrace */ 458*7c478bd9Sstevel@tonic-gate #elif defined(__amd64) 459*7c478bd9Sstevel@tonic-gate uint8_t ul_dinstr[56]; /* scratch space for dtrace */ 460*7c478bd9Sstevel@tonic-gate #endif 461*7c478bd9Sstevel@tonic-gate struct uberdata *ul_uberdata; /* uber (super-global) data */ 462*7c478bd9Sstevel@tonic-gate tls_t ul_tls; /* dynamic thread-local storage base */ 463*7c478bd9Sstevel@tonic-gate struct ulwp *ul_forw; /* forw, back all_lwps list, */ 464*7c478bd9Sstevel@tonic-gate struct ulwp *ul_back; /* protected by link_lock */ 465*7c478bd9Sstevel@tonic-gate struct ulwp *ul_next; /* list to keep track of stacks */ 466*7c478bd9Sstevel@tonic-gate struct ulwp *ul_hash; /* hash chain linked list */ 467*7c478bd9Sstevel@tonic-gate void *ul_rval; /* return value from thr_exit() */ 468*7c478bd9Sstevel@tonic-gate caddr_t ul_stk; /* mapping base of the stack */ 469*7c478bd9Sstevel@tonic-gate size_t ul_mapsiz; /* mapping size of the stack */ 470*7c478bd9Sstevel@tonic-gate size_t ul_guardsize; /* normally _lpagesize */ 471*7c478bd9Sstevel@tonic-gate uintptr_t ul_stktop; /* broken thr_stksegment() interface */ 472*7c478bd9Sstevel@tonic-gate size_t ul_stksiz; /* broken thr_stksegment() interface */ 473*7c478bd9Sstevel@tonic-gate stack_t ul_ustack; /* current stack boundaries */ 474*7c478bd9Sstevel@tonic-gate int ul_ix; /* hash index */ 475*7c478bd9Sstevel@tonic-gate lwpid_t ul_lwpid; /* thread id, aka the lwp id */ 476*7c478bd9Sstevel@tonic-gate pri_t ul_pri; /* priority known to the library */ 477*7c478bd9Sstevel@tonic-gate pri_t ul_mappedpri; /* priority known to the application */ 478*7c478bd9Sstevel@tonic-gate char ul_policy; /* scheduling policy */ 479*7c478bd9Sstevel@tonic-gate char ul_pri_mapped; /* != 0 means ul_mappedpri is valid */ 480*7c478bd9Sstevel@tonic-gate union { 481*7c478bd9Sstevel@tonic-gate struct { 482*7c478bd9Sstevel@tonic-gate char cursig; /* deferred signal number */ 483*7c478bd9Sstevel@tonic-gate char pleasestop; /* lwp requested to stop itself */ 484*7c478bd9Sstevel@tonic-gate } s; 485*7c478bd9Sstevel@tonic-gate short curplease; /* for testing both at once */ 486*7c478bd9Sstevel@tonic-gate } ul_cp; 487*7c478bd9Sstevel@tonic-gate char ul_stop; /* reason for stopping */ 488*7c478bd9Sstevel@tonic-gate char ul_signalled; /* this lwp was cond_signal()d */ 489*7c478bd9Sstevel@tonic-gate char ul_dead; /* this lwp has called thr_exit */ 490*7c478bd9Sstevel@tonic-gate char ul_unwind; /* posix: unwind C++ stack */ 491*7c478bd9Sstevel@tonic-gate char ul_detached; /* THR_DETACHED at thread_create() */ 492*7c478bd9Sstevel@tonic-gate /* or pthread_detach() was called */ 493*7c478bd9Sstevel@tonic-gate char ul_writer; /* sleeping in rw_wrlock() */ 494*7c478bd9Sstevel@tonic-gate char ul_stopping; /* set by curthread: stopping self */ 495*7c478bd9Sstevel@tonic-gate char ul_pad4; 496*7c478bd9Sstevel@tonic-gate short ul_preempt; /* no_preempt()/preempt() */ 497*7c478bd9Sstevel@tonic-gate short ul_savpreempt; /* pre-existing preempt value */ 498*7c478bd9Sstevel@tonic-gate char ul_sigsuspend; /* thread is in sigsuspend/pollsys */ 499*7c478bd9Sstevel@tonic-gate char ul_main; /* thread is the main thread */ 500*7c478bd9Sstevel@tonic-gate char ul_fork; /* thread is performing a fork */ 501*7c478bd9Sstevel@tonic-gate char ul_primarymap; /* primary link-map is initialized */ 502*7c478bd9Sstevel@tonic-gate /* per-thread copies of the corresponding global variables */ 503*7c478bd9Sstevel@tonic-gate uchar_t ul_max_spinners; /* thread_max_spinners */ 504*7c478bd9Sstevel@tonic-gate char ul_door_noreserve; /* thread_door_noreserve */ 505*7c478bd9Sstevel@tonic-gate char ul_queue_fifo; /* thread_queue_fifo */ 506*7c478bd9Sstevel@tonic-gate char ul_cond_wait_defer; /* thread_cond_wait_defer */ 507*7c478bd9Sstevel@tonic-gate char ul_error_detection; /* thread_error_detection */ 508*7c478bd9Sstevel@tonic-gate char ul_async_safe; /* thread_async_safe */ 509*7c478bd9Sstevel@tonic-gate char ul_pad1[2]; 510*7c478bd9Sstevel@tonic-gate int ul_adaptive_spin; /* thread_adaptive_spin */ 511*7c478bd9Sstevel@tonic-gate int ul_release_spin; /* thread_release_spin */ 512*7c478bd9Sstevel@tonic-gate int ul_queue_spin; /* thread_queue_spin */ 513*7c478bd9Sstevel@tonic-gate volatile int ul_critical; /* non-zero == in a critical region */ 514*7c478bd9Sstevel@tonic-gate int ul_sigdefer; /* non-zero == defer signals */ 515*7c478bd9Sstevel@tonic-gate int ul_vfork; /* thread is the child of vfork() */ 516*7c478bd9Sstevel@tonic-gate int ul_cancelable; /* _cancelon()/_canceloff() */ 517*7c478bd9Sstevel@tonic-gate char ul_cancel_pending; /* pthread_cancel() was called */ 518*7c478bd9Sstevel@tonic-gate char ul_cancel_disabled; /* PTHREAD_CANCEL_DISABLE */ 519*7c478bd9Sstevel@tonic-gate char ul_cancel_async; /* PTHREAD_CANCEL_ASYNCHRONOUS */ 520*7c478bd9Sstevel@tonic-gate char ul_save_async; /* saved copy of ul_cancel_async */ 521*7c478bd9Sstevel@tonic-gate char ul_mutator; /* lwp is a mutator (java interface) */ 522*7c478bd9Sstevel@tonic-gate char ul_created; /* created suspended */ 523*7c478bd9Sstevel@tonic-gate char ul_replace; /* replacement; must be free()d */ 524*7c478bd9Sstevel@tonic-gate uchar_t ul_nocancel; /* cancellation can't happen */ 525*7c478bd9Sstevel@tonic-gate int ul_errno; /* per-thread errno */ 526*7c478bd9Sstevel@tonic-gate int *ul_errnop; /* pointer to errno or self->ul_errno */ 527*7c478bd9Sstevel@tonic-gate __cleanup_t *ul_clnup_hdr; /* head of cleanup handlers list */ 528*7c478bd9Sstevel@tonic-gate uberflags_t *volatile ul_schedctl_called; /* ul_schedctl is set up */ 529*7c478bd9Sstevel@tonic-gate volatile sc_shared_t *volatile ul_schedctl; /* schedctl data */ 530*7c478bd9Sstevel@tonic-gate int ul_bindflags; /* bind_guard() interface to ld.so.1 */ 531*7c478bd9Sstevel@tonic-gate int ul_gs; /* x86 only: value of %gs/%fs */ 532*7c478bd9Sstevel@tonic-gate tsd_t *ul_stsd; /* slow TLS for keys >= TSD_NFAST */ 533*7c478bd9Sstevel@tonic-gate void *ul_ftsd[TSD_NFAST]; /* fast TLS for keys < TSD_NFAST */ 534*7c478bd9Sstevel@tonic-gate td_evbuf_t ul_td_evbuf; /* event buffer */ 535*7c478bd9Sstevel@tonic-gate char ul_td_events_enable; /* event mechanism enabled */ 536*7c478bd9Sstevel@tonic-gate char ul_sync_obj_reg; /* tdb_sync_obj_register() */ 537*7c478bd9Sstevel@tonic-gate char ul_qtype; /* MX or CV */ 538*7c478bd9Sstevel@tonic-gate char ul_cv_wake; /* != 0: just wake up, don't requeue */ 539*7c478bd9Sstevel@tonic-gate int ul_usropts; /* flags given to thr_create() */ 540*7c478bd9Sstevel@tonic-gate void *(*ul_startpc)(void *); /* start func (thr_create()) */ 541*7c478bd9Sstevel@tonic-gate void *ul_startarg; /* argument for start function */ 542*7c478bd9Sstevel@tonic-gate void *ul_wchan; /* synch object when sleeping */ 543*7c478bd9Sstevel@tonic-gate struct ulwp *ul_link; /* sleep queue link */ 544*7c478bd9Sstevel@tonic-gate queue_head_t *ul_sleepq; /* sleep queue thread is waiting on */ 545*7c478bd9Sstevel@tonic-gate mutex_t *ul_cvmutex; /* mutex dropped when waiting on a cv */ 546*7c478bd9Sstevel@tonic-gate mxchain_t *ul_mxchain; /* chain of owned ceiling mutexes */ 547*7c478bd9Sstevel@tonic-gate pri_t ul_epri; /* effective scheduling priority */ 548*7c478bd9Sstevel@tonic-gate pri_t ul_emappedpri; /* effective mapped priority */ 549*7c478bd9Sstevel@tonic-gate uint_t ul_rdlocks; /* # of entries in ul_readlock array */ 550*7c478bd9Sstevel@tonic-gate /* 0 means there is but a single lock */ 551*7c478bd9Sstevel@tonic-gate union { /* single rwlock or pointer to array */ 552*7c478bd9Sstevel@tonic-gate readlock_t single; 553*7c478bd9Sstevel@tonic-gate readlock_t *array; 554*7c478bd9Sstevel@tonic-gate } ul_readlock; 555*7c478bd9Sstevel@tonic-gate /* PROBE_SUPPORT begin */ 556*7c478bd9Sstevel@tonic-gate void *ul_tpdp; 557*7c478bd9Sstevel@tonic-gate /* PROBE_SUPPORT end */ 558*7c478bd9Sstevel@tonic-gate ucontext_t *ul_siglink; /* pointer to previous context */ 559*7c478bd9Sstevel@tonic-gate uint_t ul_spin_lock_spin; /* spin lock statistics */ 560*7c478bd9Sstevel@tonic-gate uint_t ul_spin_lock_spin2; 561*7c478bd9Sstevel@tonic-gate uint_t ul_spin_lock_sleep; 562*7c478bd9Sstevel@tonic-gate uint_t ul_spin_lock_wakeup; 563*7c478bd9Sstevel@tonic-gate /* the following members *must* be last in the structure */ 564*7c478bd9Sstevel@tonic-gate /* they are discarded when ulwp is replaced on thr_exit() */ 565*7c478bd9Sstevel@tonic-gate sigset_t ul_sigmask; /* thread's current signal mask */ 566*7c478bd9Sstevel@tonic-gate sigset_t ul_tmpmask; /* signal mask for sigsuspend/pollsys */ 567*7c478bd9Sstevel@tonic-gate siginfo_t ul_siginfo; /* deferred siginfo */ 568*7c478bd9Sstevel@tonic-gate mutex_t ul_spinlock; /* used when suspending/continuing */ 569*7c478bd9Sstevel@tonic-gate fpuenv_t ul_fpuenv; /* floating point state */ 570*7c478bd9Sstevel@tonic-gate uintptr_t ul_sp; /* stack pointer when blocked */ 571*7c478bd9Sstevel@tonic-gate void *ul_ex_unwind; /* address of _ex_unwind() or -1 */ 572*7c478bd9Sstevel@tonic-gate #if defined(sparc) 573*7c478bd9Sstevel@tonic-gate void *ul_unwind_ret; /* used only by _ex_clnup_handler() */ 574*7c478bd9Sstevel@tonic-gate #endif 575*7c478bd9Sstevel@tonic-gate } ulwp_t; 576*7c478bd9Sstevel@tonic-gate 577*7c478bd9Sstevel@tonic-gate #define ul_cursig ul_cp.s.cursig /* deferred signal number */ 578*7c478bd9Sstevel@tonic-gate #define ul_pleasestop ul_cp.s.pleasestop /* lwp requested to stop */ 579*7c478bd9Sstevel@tonic-gate #define ul_curplease ul_cp.curplease /* for testing both at once */ 580*7c478bd9Sstevel@tonic-gate 581*7c478bd9Sstevel@tonic-gate /* 582*7c478bd9Sstevel@tonic-gate * This is the size of a replacement ulwp, retained only for the benefit 583*7c478bd9Sstevel@tonic-gate * of thr_join(). The trailing members are unneeded for this purpose. 584*7c478bd9Sstevel@tonic-gate */ 585*7c478bd9Sstevel@tonic-gate #define REPLACEMENT_SIZE ((size_t)&((ulwp_t *)NULL)->ul_sigmask) 586*7c478bd9Sstevel@tonic-gate 587*7c478bd9Sstevel@tonic-gate extern size_t _lpagesize; 588*7c478bd9Sstevel@tonic-gate 589*7c478bd9Sstevel@tonic-gate /* 590*7c478bd9Sstevel@tonic-gate * Definitions for static initialization of signal sets, 591*7c478bd9Sstevel@tonic-gate * plus some sneaky optimizations in various places. 592*7c478bd9Sstevel@tonic-gate */ 593*7c478bd9Sstevel@tonic-gate 594*7c478bd9Sstevel@tonic-gate #define SIGMASK(sig) ((uint32_t)1 << (((sig) - 1) & (32 - 1))) 595*7c478bd9Sstevel@tonic-gate 596*7c478bd9Sstevel@tonic-gate #if (MAXSIG > 32 && MAXSIG <= 64) 597*7c478bd9Sstevel@tonic-gate #define FILLSET0 0xffffffffu 598*7c478bd9Sstevel@tonic-gate #define FILLSET1 ((1u << (MAXSIG - 32)) - 1) 599*7c478bd9Sstevel@tonic-gate #else 600*7c478bd9Sstevel@tonic-gate #error "fix me: MAXSIG out of bounds" 601*7c478bd9Sstevel@tonic-gate #endif 602*7c478bd9Sstevel@tonic-gate 603*7c478bd9Sstevel@tonic-gate #define CANTMASK0 (SIGMASK(SIGKILL) | SIGMASK(SIGSTOP)) 604*7c478bd9Sstevel@tonic-gate #define CANTMASK1 0 605*7c478bd9Sstevel@tonic-gate 606*7c478bd9Sstevel@tonic-gate #define MASKSET0 (FILLSET0 & ~CANTMASK0) 607*7c478bd9Sstevel@tonic-gate #define MASKSET1 (FILLSET1 & ~CANTMASK1) 608*7c478bd9Sstevel@tonic-gate 609*7c478bd9Sstevel@tonic-gate extern const sigset_t maskset; /* set of all maskable signals */ 610*7c478bd9Sstevel@tonic-gate 611*7c478bd9Sstevel@tonic-gate extern int thread_adaptive_spin; 612*7c478bd9Sstevel@tonic-gate extern uint_t thread_max_spinners; 613*7c478bd9Sstevel@tonic-gate extern int thread_release_spin; 614*7c478bd9Sstevel@tonic-gate extern int thread_queue_spin; 615*7c478bd9Sstevel@tonic-gate extern int thread_queue_fifo; 616*7c478bd9Sstevel@tonic-gate extern int thread_queue_dump; 617*7c478bd9Sstevel@tonic-gate extern int thread_cond_wait_defer; 618*7c478bd9Sstevel@tonic-gate extern int thread_async_safe; 619*7c478bd9Sstevel@tonic-gate extern int thread_queue_verify; 620*7c478bd9Sstevel@tonic-gate 621*7c478bd9Sstevel@tonic-gate /* 622*7c478bd9Sstevel@tonic-gate * pthread_atfork() related data, used to store atfork handlers. 623*7c478bd9Sstevel@tonic-gate */ 624*7c478bd9Sstevel@tonic-gate typedef struct atfork { 625*7c478bd9Sstevel@tonic-gate struct atfork *forw; /* forward pointer */ 626*7c478bd9Sstevel@tonic-gate struct atfork *back; /* backward pointer */ 627*7c478bd9Sstevel@tonic-gate void (*prepare)(void); /* pre-fork handler */ 628*7c478bd9Sstevel@tonic-gate void (*parent)(void); /* post-fork parent handler */ 629*7c478bd9Sstevel@tonic-gate void (*child)(void); /* post-fork child handler */ 630*7c478bd9Sstevel@tonic-gate } atfork_t; 631*7c478bd9Sstevel@tonic-gate 632*7c478bd9Sstevel@tonic-gate /* 633*7c478bd9Sstevel@tonic-gate * Make our hot locks reside on private cache lines (64 bytes). 634*7c478bd9Sstevel@tonic-gate * pad_cond, pad_owner, and pad_count (aka fork_cond, fork_owner, 635*7c478bd9Sstevel@tonic-gate * and fork_count for _fork_lock) are used only in fork_lock_enter() 636*7c478bd9Sstevel@tonic-gate * to implement the special form of mutual exclusion therein. 637*7c478bd9Sstevel@tonic-gate */ 638*7c478bd9Sstevel@tonic-gate typedef struct { 639*7c478bd9Sstevel@tonic-gate mutex_t pad_lock; 640*7c478bd9Sstevel@tonic-gate cond_t pad_cond; 641*7c478bd9Sstevel@tonic-gate ulwp_t *pad_owner; 642*7c478bd9Sstevel@tonic-gate size_t pad_count; 643*7c478bd9Sstevel@tonic-gate char pad_pad[64 - (sizeof (mutex_t) + sizeof (cond_t) + 644*7c478bd9Sstevel@tonic-gate sizeof (ulwp_t *) + sizeof (size_t))]; 645*7c478bd9Sstevel@tonic-gate } pad_lock_t; 646*7c478bd9Sstevel@tonic-gate 647*7c478bd9Sstevel@tonic-gate /* 648*7c478bd9Sstevel@tonic-gate * The threads hash table is used for fast lookup and locking of an active 649*7c478bd9Sstevel@tonic-gate * thread structure (ulwp_t) given a thread-id. It is an N-element array of 650*7c478bd9Sstevel@tonic-gate * thr_hash_table_t structures, where N == 1 before the main thread creates 651*7c478bd9Sstevel@tonic-gate * the first additional thread and N == 1024 afterwards. Each element of the 652*7c478bd9Sstevel@tonic-gate * table is 64 bytes in size and alignment to reduce cache conflicts. 653*7c478bd9Sstevel@tonic-gate */ 654*7c478bd9Sstevel@tonic-gate typedef struct { 655*7c478bd9Sstevel@tonic-gate mutex_t hash_lock; /* lock per bucket */ 656*7c478bd9Sstevel@tonic-gate cond_t hash_cond; /* convar per bucket */ 657*7c478bd9Sstevel@tonic-gate ulwp_t *hash_bucket; /* hash bucket points to the list of ulwps */ 658*7c478bd9Sstevel@tonic-gate char hash_pad[64 - /* pad out to 64 bytes */ 659*7c478bd9Sstevel@tonic-gate (sizeof (mutex_t) + sizeof (cond_t) + sizeof (ulwp_t *))]; 660*7c478bd9Sstevel@tonic-gate } thr_hash_table_t; 661*7c478bd9Sstevel@tonic-gate 662*7c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32 663*7c478bd9Sstevel@tonic-gate typedef struct { 664*7c478bd9Sstevel@tonic-gate mutex_t hash_lock; 665*7c478bd9Sstevel@tonic-gate cond_t hash_cond; 666*7c478bd9Sstevel@tonic-gate caddr32_t hash_bucket; 667*7c478bd9Sstevel@tonic-gate char hash_pad[64 - 668*7c478bd9Sstevel@tonic-gate (sizeof (mutex_t) + sizeof (cond_t) + sizeof (caddr32_t))]; 669*7c478bd9Sstevel@tonic-gate } thr_hash_table32_t; 670*7c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 671*7c478bd9Sstevel@tonic-gate 672*7c478bd9Sstevel@tonic-gate 673*7c478bd9Sstevel@tonic-gate /* 674*7c478bd9Sstevel@tonic-gate * siguaction members have 64-byte size and alignment. 675*7c478bd9Sstevel@tonic-gate * We know that sizeof (struct sigaction) is 32 bytes for 676*7c478bd9Sstevel@tonic-gate * both _ILP32 and _LP64, so we put the padding in the middle. 677*7c478bd9Sstevel@tonic-gate */ 678*7c478bd9Sstevel@tonic-gate typedef struct { 679*7c478bd9Sstevel@tonic-gate mutex_t sig_lock; 680*7c478bd9Sstevel@tonic-gate char sig_pad[64 - (sizeof (mutex_t) + sizeof (struct sigaction))]; 681*7c478bd9Sstevel@tonic-gate struct sigaction sig_uaction; 682*7c478bd9Sstevel@tonic-gate } siguaction_t; 683*7c478bd9Sstevel@tonic-gate 684*7c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32 685*7c478bd9Sstevel@tonic-gate typedef struct { 686*7c478bd9Sstevel@tonic-gate mutex_t sig_lock; 687*7c478bd9Sstevel@tonic-gate char sig_pad[64 - (sizeof (mutex_t) + sizeof (struct sigaction32))]; 688*7c478bd9Sstevel@tonic-gate struct sigaction32 sig_uaction; 689*7c478bd9Sstevel@tonic-gate } siguaction32_t; 690*7c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 691*7c478bd9Sstevel@tonic-gate 692*7c478bd9Sstevel@tonic-gate 693*7c478bd9Sstevel@tonic-gate /* 694*7c478bd9Sstevel@tonic-gate * Bucket structures, used by lmalloc()/lfree(). 695*7c478bd9Sstevel@tonic-gate * See port/threads/alloc.c for details. 696*7c478bd9Sstevel@tonic-gate * A bucket's size and alignment is 64 bytes. 697*7c478bd9Sstevel@tonic-gate */ 698*7c478bd9Sstevel@tonic-gate typedef struct { 699*7c478bd9Sstevel@tonic-gate mutex_t bucket_lock; /* protects the free list allocations */ 700*7c478bd9Sstevel@tonic-gate void *free_list; /* LIFO list of blocks to allocate/free */ 701*7c478bd9Sstevel@tonic-gate size_t chunks; /* number of 64K blocks mmap()ed last time */ 702*7c478bd9Sstevel@tonic-gate char pad64[64 - /* pad out to 64 bytes */ 703*7c478bd9Sstevel@tonic-gate (sizeof (mutex_t) + sizeof (void *) + sizeof (size_t))]; 704*7c478bd9Sstevel@tonic-gate } bucket_t; 705*7c478bd9Sstevel@tonic-gate 706*7c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32 707*7c478bd9Sstevel@tonic-gate typedef struct { 708*7c478bd9Sstevel@tonic-gate mutex_t bucket_lock; 709*7c478bd9Sstevel@tonic-gate caddr32_t free_list; 710*7c478bd9Sstevel@tonic-gate size32_t chunks; 711*7c478bd9Sstevel@tonic-gate char pad64[64 - /* pad out to 64 bytes */ 712*7c478bd9Sstevel@tonic-gate (sizeof (mutex_t) + sizeof (caddr32_t) + sizeof (size32_t))]; 713*7c478bd9Sstevel@tonic-gate } bucket32_t; 714*7c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 715*7c478bd9Sstevel@tonic-gate 716*7c478bd9Sstevel@tonic-gate #define NBUCKETS 10 /* sizes ranging from 64 to 32768 */ 717*7c478bd9Sstevel@tonic-gate 718*7c478bd9Sstevel@tonic-gate 719*7c478bd9Sstevel@tonic-gate /* 720*7c478bd9Sstevel@tonic-gate * atexit() data structures. 721*7c478bd9Sstevel@tonic-gate * See port/gen/atexit.c for details. 722*7c478bd9Sstevel@tonic-gate */ 723*7c478bd9Sstevel@tonic-gate typedef void (*_exithdlr_func_t) (void); 724*7c478bd9Sstevel@tonic-gate 725*7c478bd9Sstevel@tonic-gate typedef struct _exthdlr { 726*7c478bd9Sstevel@tonic-gate struct _exthdlr *next; /* next in handler list */ 727*7c478bd9Sstevel@tonic-gate _exithdlr_func_t hdlr; /* handler itself */ 728*7c478bd9Sstevel@tonic-gate } _exthdlr_t; 729*7c478bd9Sstevel@tonic-gate 730*7c478bd9Sstevel@tonic-gate typedef struct { 731*7c478bd9Sstevel@tonic-gate mutex_t exitfns_lock; 732*7c478bd9Sstevel@tonic-gate _exthdlr_t *head; 733*7c478bd9Sstevel@tonic-gate void *exit_frame_monitor; 734*7c478bd9Sstevel@tonic-gate char exit_pad[64 - /* pad out to 64 bytes */ 735*7c478bd9Sstevel@tonic-gate (sizeof (mutex_t) + sizeof (_exthdlr_t *) + sizeof (void *))]; 736*7c478bd9Sstevel@tonic-gate } atexit_root_t; 737*7c478bd9Sstevel@tonic-gate 738*7c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32 739*7c478bd9Sstevel@tonic-gate typedef struct { 740*7c478bd9Sstevel@tonic-gate mutex_t exitfns_lock; 741*7c478bd9Sstevel@tonic-gate caddr32_t head; 742*7c478bd9Sstevel@tonic-gate caddr32_t exit_frame_monitor; 743*7c478bd9Sstevel@tonic-gate char exit_pad[64 - /* pad out to 64 bytes */ 744*7c478bd9Sstevel@tonic-gate (sizeof (mutex_t) + sizeof (caddr32_t) + sizeof (caddr32_t))]; 745*7c478bd9Sstevel@tonic-gate } atexit_root32_t; 746*7c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 747*7c478bd9Sstevel@tonic-gate 748*7c478bd9Sstevel@tonic-gate 749*7c478bd9Sstevel@tonic-gate /* 750*7c478bd9Sstevel@tonic-gate * This is data that is global to all link maps (uberdata, aka super-global). 751*7c478bd9Sstevel@tonic-gate */ 752*7c478bd9Sstevel@tonic-gate typedef struct uberdata { 753*7c478bd9Sstevel@tonic-gate pad_lock_t _link_lock; 754*7c478bd9Sstevel@tonic-gate pad_lock_t _fork_lock; 755*7c478bd9Sstevel@tonic-gate pad_lock_t _tdb_hash_lock; 756*7c478bd9Sstevel@tonic-gate tdb_sync_stats_t tdb_hash_lock_stats; 757*7c478bd9Sstevel@tonic-gate siguaction_t siguaction[NSIG]; 758*7c478bd9Sstevel@tonic-gate bucket_t bucket[NBUCKETS]; 759*7c478bd9Sstevel@tonic-gate atexit_root_t atexit_root; 760*7c478bd9Sstevel@tonic-gate tsd_metadata_t tsd_metadata; 761*7c478bd9Sstevel@tonic-gate tls_metadata_t tls_metadata; 762*7c478bd9Sstevel@tonic-gate /* 763*7c478bd9Sstevel@tonic-gate * Every object before this point has size and alignment of 64 bytes. 764*7c478bd9Sstevel@tonic-gate * Don't add any other type of data before this point. 765*7c478bd9Sstevel@tonic-gate */ 766*7c478bd9Sstevel@tonic-gate char primary_map; /* set when primary link map is initialized */ 767*7c478bd9Sstevel@tonic-gate char bucket_init; /* set when bucket[NBUCKETS] is initialized */ 768*7c478bd9Sstevel@tonic-gate char pad[2]; 769*7c478bd9Sstevel@tonic-gate uberflags_t uberflags; 770*7c478bd9Sstevel@tonic-gate queue_head_t *queue_head; 771*7c478bd9Sstevel@tonic-gate thr_hash_table_t *thr_hash_table; 772*7c478bd9Sstevel@tonic-gate uint_t hash_size; /* # of entries in thr_hash_table[] */ 773*7c478bd9Sstevel@tonic-gate uint_t hash_mask; /* hash_size - 1 */ 774*7c478bd9Sstevel@tonic-gate ulwp_t *ulwp_one; /* main thread */ 775*7c478bd9Sstevel@tonic-gate ulwp_t *all_lwps; /* circular ul_forw/ul_back list of live lwps */ 776*7c478bd9Sstevel@tonic-gate ulwp_t *all_zombies; /* circular ul_forw/ul_back list of zombies */ 777*7c478bd9Sstevel@tonic-gate int nthreads; /* total number of live threads/lwps */ 778*7c478bd9Sstevel@tonic-gate int nzombies; /* total number of zombie threads */ 779*7c478bd9Sstevel@tonic-gate int ndaemons; /* total number of THR_DAEMON threads/lwps */ 780*7c478bd9Sstevel@tonic-gate pid_t pid; /* the current process's pid */ 781*7c478bd9Sstevel@tonic-gate void (*sigacthandler)(int, siginfo_t *, void *); 782*7c478bd9Sstevel@tonic-gate ulwp_t *lwp_stacks; 783*7c478bd9Sstevel@tonic-gate ulwp_t *lwp_laststack; 784*7c478bd9Sstevel@tonic-gate int nfreestack; 785*7c478bd9Sstevel@tonic-gate int thread_stack_cache; 786*7c478bd9Sstevel@tonic-gate ulwp_t *ulwp_freelist; 787*7c478bd9Sstevel@tonic-gate ulwp_t *ulwp_lastfree; 788*7c478bd9Sstevel@tonic-gate ulwp_t *ulwp_replace_free; 789*7c478bd9Sstevel@tonic-gate ulwp_t *ulwp_replace_last; 790*7c478bd9Sstevel@tonic-gate atfork_t *atforklist; /* circular Q for fork handlers */ 791*7c478bd9Sstevel@tonic-gate struct uberdata **tdb_bootstrap; 792*7c478bd9Sstevel@tonic-gate tdb_t tdb; /* thread debug interfaces (for libc_db) */ 793*7c478bd9Sstevel@tonic-gate } uberdata_t; 794*7c478bd9Sstevel@tonic-gate 795*7c478bd9Sstevel@tonic-gate #define link_lock _link_lock.pad_lock 796*7c478bd9Sstevel@tonic-gate #define fork_lock _fork_lock.pad_lock 797*7c478bd9Sstevel@tonic-gate #define fork_cond _fork_lock.pad_cond 798*7c478bd9Sstevel@tonic-gate #define fork_owner _fork_lock.pad_owner 799*7c478bd9Sstevel@tonic-gate #define fork_count _fork_lock.pad_count 800*7c478bd9Sstevel@tonic-gate #define tdb_hash_lock _tdb_hash_lock.pad_lock 801*7c478bd9Sstevel@tonic-gate 802*7c478bd9Sstevel@tonic-gate #pragma align 64(__uberdata) 803*7c478bd9Sstevel@tonic-gate extern uberdata_t __uberdata; 804*7c478bd9Sstevel@tonic-gate extern uberdata_t **__tdb_bootstrap; /* known to libc_db and mdb */ 805*7c478bd9Sstevel@tonic-gate extern int primary_link_map; 806*7c478bd9Sstevel@tonic-gate 807*7c478bd9Sstevel@tonic-gate #define ulwp_mutex(ulwp, udp) \ 808*7c478bd9Sstevel@tonic-gate (&(udp)->thr_hash_table[(ulwp)->ul_ix].hash_lock) 809*7c478bd9Sstevel@tonic-gate #define ulwp_condvar(ulwp, udp) \ 810*7c478bd9Sstevel@tonic-gate (&(udp)->thr_hash_table[(ulwp)->ul_ix].hash_cond) 811*7c478bd9Sstevel@tonic-gate 812*7c478bd9Sstevel@tonic-gate /* 813*7c478bd9Sstevel@tonic-gate * Grab and release the hash table lock for the specified lwp. 814*7c478bd9Sstevel@tonic-gate */ 815*7c478bd9Sstevel@tonic-gate #define ulwp_lock(ulwp, udp) lmutex_lock(ulwp_mutex(ulwp, udp)) 816*7c478bd9Sstevel@tonic-gate #define ulwp_unlock(ulwp, udp) lmutex_unlock(ulwp_mutex(ulwp, udp)) 817*7c478bd9Sstevel@tonic-gate 818*7c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32 /* needed by libc_db */ 819*7c478bd9Sstevel@tonic-gate 820*7c478bd9Sstevel@tonic-gate typedef struct ulwp32 { 821*7c478bd9Sstevel@tonic-gate #if defined(__sparc) 822*7c478bd9Sstevel@tonic-gate uint32_t ul_dinstr; /* scratch space for dtrace */ 823*7c478bd9Sstevel@tonic-gate uint32_t ul_padsparc0[15]; 824*7c478bd9Sstevel@tonic-gate uint32_t ul_dsave; /* dtrace: save %g1, %g0, %sp */ 825*7c478bd9Sstevel@tonic-gate uint32_t ul_drestore; /* dtrace: restore %g0, %g0, %g0 */ 826*7c478bd9Sstevel@tonic-gate uint32_t ul_dftret; /* dtrace: return probe fasttrap */ 827*7c478bd9Sstevel@tonic-gate uint32_t ul_dreturn; /* dtrace: return %o0 */ 828*7c478bd9Sstevel@tonic-gate #endif 829*7c478bd9Sstevel@tonic-gate caddr32_t ul_self; /* pointer to self */ 830*7c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64) 831*7c478bd9Sstevel@tonic-gate uint8_t ul_dinstr[40]; /* scratch space for dtrace */ 832*7c478bd9Sstevel@tonic-gate #endif 833*7c478bd9Sstevel@tonic-gate caddr32_t ul_uberdata; /* uber (super-global) data */ 834*7c478bd9Sstevel@tonic-gate tls32_t ul_tls; /* dynamic thread-local storage base */ 835*7c478bd9Sstevel@tonic-gate caddr32_t ul_forw; /* forw, back all_lwps list, */ 836*7c478bd9Sstevel@tonic-gate caddr32_t ul_back; /* protected by link_lock */ 837*7c478bd9Sstevel@tonic-gate caddr32_t ul_next; /* list to keep track of stacks */ 838*7c478bd9Sstevel@tonic-gate caddr32_t ul_hash; /* hash chain linked list */ 839*7c478bd9Sstevel@tonic-gate caddr32_t ul_rval; /* return value from thr_exit() */ 840*7c478bd9Sstevel@tonic-gate caddr32_t ul_stk; /* mapping base of the stack */ 841*7c478bd9Sstevel@tonic-gate size32_t ul_mapsiz; /* mapping size of the stack */ 842*7c478bd9Sstevel@tonic-gate size32_t ul_guardsize; /* normally _lpagesize */ 843*7c478bd9Sstevel@tonic-gate caddr32_t ul_stktop; /* broken thr_stksegment() interface */ 844*7c478bd9Sstevel@tonic-gate size32_t ul_stksiz; /* broken thr_stksegment() interface */ 845*7c478bd9Sstevel@tonic-gate stack32_t ul_ustack; /* current stack boundaries */ 846*7c478bd9Sstevel@tonic-gate int ul_ix; /* hash index */ 847*7c478bd9Sstevel@tonic-gate lwpid_t ul_lwpid; /* thread id, aka the lwp id */ 848*7c478bd9Sstevel@tonic-gate pri_t ul_pri; /* priority known to the library */ 849*7c478bd9Sstevel@tonic-gate pri_t ul_mappedpri; /* priority known to the application */ 850*7c478bd9Sstevel@tonic-gate char ul_policy; /* scheduling policy */ 851*7c478bd9Sstevel@tonic-gate char ul_pri_mapped; /* != 0 means ul_mappedpri is valid */ 852*7c478bd9Sstevel@tonic-gate union { 853*7c478bd9Sstevel@tonic-gate struct { 854*7c478bd9Sstevel@tonic-gate char cursig; /* deferred signal number */ 855*7c478bd9Sstevel@tonic-gate char pleasestop; /* lwp requested to stop itself */ 856*7c478bd9Sstevel@tonic-gate } s; 857*7c478bd9Sstevel@tonic-gate short curplease; /* for testing both at once */ 858*7c478bd9Sstevel@tonic-gate } ul_cp; 859*7c478bd9Sstevel@tonic-gate char ul_stop; /* reason for stopping */ 860*7c478bd9Sstevel@tonic-gate char ul_signalled; /* this lwp was cond_signal()d */ 861*7c478bd9Sstevel@tonic-gate char ul_dead; /* this lwp has called thr_exit */ 862*7c478bd9Sstevel@tonic-gate char ul_unwind; /* posix: unwind C++ stack */ 863*7c478bd9Sstevel@tonic-gate char ul_detached; /* THR_DETACHED at thread_create() */ 864*7c478bd9Sstevel@tonic-gate /* or pthread_detach() was called */ 865*7c478bd9Sstevel@tonic-gate char ul_writer; /* sleeping in rw_wrlock() */ 866*7c478bd9Sstevel@tonic-gate char ul_stopping; /* set by curthread: stopping self */ 867*7c478bd9Sstevel@tonic-gate char ul_pad4; 868*7c478bd9Sstevel@tonic-gate short ul_preempt; /* no_preempt()/preempt() */ 869*7c478bd9Sstevel@tonic-gate short ul_savpreempt; /* pre-existing preempt value */ 870*7c478bd9Sstevel@tonic-gate char ul_sigsuspend; /* thread is in sigsuspend/pollsys */ 871*7c478bd9Sstevel@tonic-gate char ul_main; /* thread is the main thread */ 872*7c478bd9Sstevel@tonic-gate char ul_fork; /* thread is performing a fork */ 873*7c478bd9Sstevel@tonic-gate char ul_primarymap; /* primary link-map is initialized */ 874*7c478bd9Sstevel@tonic-gate /* per-thread copies of the corresponding global variables */ 875*7c478bd9Sstevel@tonic-gate uchar_t ul_max_spinners; /* thread_max_spinners */ 876*7c478bd9Sstevel@tonic-gate char ul_door_noreserve; /* thread_door_noreserve */ 877*7c478bd9Sstevel@tonic-gate char ul_queue_fifo; /* thread_queue_fifo */ 878*7c478bd9Sstevel@tonic-gate char ul_cond_wait_defer; /* thread_cond_wait_defer */ 879*7c478bd9Sstevel@tonic-gate char ul_error_detection; /* thread_error_detection */ 880*7c478bd9Sstevel@tonic-gate char ul_async_safe; /* thread_async_safe */ 881*7c478bd9Sstevel@tonic-gate char ul_pad1[2]; 882*7c478bd9Sstevel@tonic-gate int ul_adaptive_spin; /* thread_adaptive_spin */ 883*7c478bd9Sstevel@tonic-gate int ul_release_spin; /* thread_release_spin */ 884*7c478bd9Sstevel@tonic-gate int ul_queue_spin; /* thread_queue_spin */ 885*7c478bd9Sstevel@tonic-gate int ul_critical; /* non-zero == in a critical region */ 886*7c478bd9Sstevel@tonic-gate int ul_sigdefer; /* non-zero == defer signals */ 887*7c478bd9Sstevel@tonic-gate int ul_vfork; /* thread is the child of vfork() */ 888*7c478bd9Sstevel@tonic-gate int ul_cancelable; /* _cancelon()/_canceloff() */ 889*7c478bd9Sstevel@tonic-gate char ul_cancel_pending; /* pthread_cancel() was called */ 890*7c478bd9Sstevel@tonic-gate char ul_cancel_disabled; /* PTHREAD_CANCEL_DISABLE */ 891*7c478bd9Sstevel@tonic-gate char ul_cancel_async; /* PTHREAD_CANCEL_ASYNCHRONOUS */ 892*7c478bd9Sstevel@tonic-gate char ul_save_async; /* saved copy of ul_cancel_async */ 893*7c478bd9Sstevel@tonic-gate char ul_mutator; /* lwp is a mutator (java interface) */ 894*7c478bd9Sstevel@tonic-gate char ul_created; /* created suspended */ 895*7c478bd9Sstevel@tonic-gate char ul_replace; /* replacement; must be free()d */ 896*7c478bd9Sstevel@tonic-gate uchar_t ul_nocancel; /* cancellation can't happen */ 897*7c478bd9Sstevel@tonic-gate int ul_errno; /* per-thread errno */ 898*7c478bd9Sstevel@tonic-gate caddr32_t ul_errnop; /* pointer to errno or self->ul_errno */ 899*7c478bd9Sstevel@tonic-gate caddr32_t ul_clnup_hdr; /* head of cleanup handlers list */ 900*7c478bd9Sstevel@tonic-gate caddr32_t ul_schedctl_called; /* ul_schedctl is set up */ 901*7c478bd9Sstevel@tonic-gate caddr32_t ul_schedctl; /* schedctl data */ 902*7c478bd9Sstevel@tonic-gate int ul_bindflags; /* bind_guard() interface to ld.so.1 */ 903*7c478bd9Sstevel@tonic-gate int ul_gs; /* x86 only: value of %gs/%fs */ 904*7c478bd9Sstevel@tonic-gate caddr32_t ul_stsd; /* slow TLS for keys >= TSD_NFAST */ 905*7c478bd9Sstevel@tonic-gate caddr32_t ul_ftsd[TSD_NFAST]; /* fast TLS for keys < TSD_NFAST */ 906*7c478bd9Sstevel@tonic-gate td_evbuf32_t ul_td_evbuf; /* event buffer */ 907*7c478bd9Sstevel@tonic-gate char ul_td_events_enable; /* event mechanism enabled */ 908*7c478bd9Sstevel@tonic-gate char ul_sync_obj_reg; /* tdb_sync_obj_register() */ 909*7c478bd9Sstevel@tonic-gate char ul_qtype; /* MX or CV */ 910*7c478bd9Sstevel@tonic-gate char ul_cv_wake; /* != 0: just wake up, don't requeue */ 911*7c478bd9Sstevel@tonic-gate int ul_usropts; /* flags given to thr_create() */ 912*7c478bd9Sstevel@tonic-gate caddr32_t ul_startpc; /* start func (thr_create()) */ 913*7c478bd9Sstevel@tonic-gate caddr32_t ul_startarg; /* argument for start function */ 914*7c478bd9Sstevel@tonic-gate caddr32_t ul_wchan; /* synch object when sleeping */ 915*7c478bd9Sstevel@tonic-gate caddr32_t ul_link; /* sleep queue link */ 916*7c478bd9Sstevel@tonic-gate caddr32_t ul_sleepq; /* sleep queue thread is waiting on */ 917*7c478bd9Sstevel@tonic-gate caddr32_t ul_cvmutex; /* mutex dropped when waiting on a cv */ 918*7c478bd9Sstevel@tonic-gate caddr32_t ul_mxchain; /* chain of owned ceiling mutexes */ 919*7c478bd9Sstevel@tonic-gate pri_t ul_epri; /* effective scheduling priority */ 920*7c478bd9Sstevel@tonic-gate pri_t ul_emappedpri; /* effective mapped priority */ 921*7c478bd9Sstevel@tonic-gate uint_t ul_rdlocks; /* # of entries in ul_readlock array */ 922*7c478bd9Sstevel@tonic-gate /* 0 means there is but a single lock */ 923*7c478bd9Sstevel@tonic-gate union { /* single rwlock or pointer to array */ 924*7c478bd9Sstevel@tonic-gate readlock32_t single; 925*7c478bd9Sstevel@tonic-gate caddr32_t array; 926*7c478bd9Sstevel@tonic-gate } ul_readlock; 927*7c478bd9Sstevel@tonic-gate /* PROBE_SUPPORT begin */ 928*7c478bd9Sstevel@tonic-gate caddr32_t ul_tpdp; 929*7c478bd9Sstevel@tonic-gate /* PROBE_SUPPORT end */ 930*7c478bd9Sstevel@tonic-gate caddr32_t ul_siglink; /* pointer to previous context */ 931*7c478bd9Sstevel@tonic-gate uint_t ul_spin_lock_spin; /* spin lock statistics */ 932*7c478bd9Sstevel@tonic-gate uint_t ul_spin_lock_spin2; 933*7c478bd9Sstevel@tonic-gate uint_t ul_spin_lock_sleep; 934*7c478bd9Sstevel@tonic-gate uint_t ul_spin_lock_wakeup; 935*7c478bd9Sstevel@tonic-gate /* the following members *must* be last in the structure */ 936*7c478bd9Sstevel@tonic-gate /* they are discarded when ulwp is replaced on thr_exit() */ 937*7c478bd9Sstevel@tonic-gate sigset32_t ul_sigmask; /* thread's current signal mask */ 938*7c478bd9Sstevel@tonic-gate sigset32_t ul_tmpmask; /* signal mask for sigsuspend/pollsys */ 939*7c478bd9Sstevel@tonic-gate siginfo32_t ul_siginfo; /* deferred siginfo */ 940*7c478bd9Sstevel@tonic-gate mutex_t ul_spinlock; /* used when suspending/continuing */ 941*7c478bd9Sstevel@tonic-gate fpuenv32_t ul_fpuenv; /* floating point state */ 942*7c478bd9Sstevel@tonic-gate caddr32_t ul_sp; /* stack pointer when blocked */ 943*7c478bd9Sstevel@tonic-gate #if defined(sparc) 944*7c478bd9Sstevel@tonic-gate caddr32_t ul_unwind_ret; /* used only by _ex_clnup_handler() */ 945*7c478bd9Sstevel@tonic-gate #endif 946*7c478bd9Sstevel@tonic-gate } ulwp32_t; 947*7c478bd9Sstevel@tonic-gate 948*7c478bd9Sstevel@tonic-gate #define REPLACEMENT_SIZE32 ((size_t)&((ulwp32_t *)NULL)->ul_sigmask) 949*7c478bd9Sstevel@tonic-gate 950*7c478bd9Sstevel@tonic-gate typedef struct uberdata32 { 951*7c478bd9Sstevel@tonic-gate pad_lock_t _link_lock; 952*7c478bd9Sstevel@tonic-gate pad_lock_t _fork_lock; 953*7c478bd9Sstevel@tonic-gate pad_lock_t _tdb_hash_lock; 954*7c478bd9Sstevel@tonic-gate tdb_sync_stats_t tdb_hash_lock_stats; 955*7c478bd9Sstevel@tonic-gate siguaction32_t siguaction[NSIG]; 956*7c478bd9Sstevel@tonic-gate bucket32_t bucket[NBUCKETS]; 957*7c478bd9Sstevel@tonic-gate atexit_root32_t atexit_root; 958*7c478bd9Sstevel@tonic-gate tsd_metadata32_t tsd_metadata; 959*7c478bd9Sstevel@tonic-gate tls_metadata32_t tls_metadata; 960*7c478bd9Sstevel@tonic-gate char primary_map; 961*7c478bd9Sstevel@tonic-gate char bucket_init; 962*7c478bd9Sstevel@tonic-gate char pad[2]; 963*7c478bd9Sstevel@tonic-gate uberflags_t uberflags; 964*7c478bd9Sstevel@tonic-gate caddr32_t queue_head; 965*7c478bd9Sstevel@tonic-gate caddr32_t thr_hash_table; 966*7c478bd9Sstevel@tonic-gate uint_t hash_size; 967*7c478bd9Sstevel@tonic-gate uint_t hash_mask; 968*7c478bd9Sstevel@tonic-gate caddr32_t ulwp_one; 969*7c478bd9Sstevel@tonic-gate caddr32_t all_lwps; 970*7c478bd9Sstevel@tonic-gate caddr32_t all_zombies; 971*7c478bd9Sstevel@tonic-gate int nthreads; 972*7c478bd9Sstevel@tonic-gate int nzombies; 973*7c478bd9Sstevel@tonic-gate int ndaemons; 974*7c478bd9Sstevel@tonic-gate int pid; 975*7c478bd9Sstevel@tonic-gate caddr32_t sigacthandler; 976*7c478bd9Sstevel@tonic-gate caddr32_t lwp_stacks; 977*7c478bd9Sstevel@tonic-gate caddr32_t lwp_laststack; 978*7c478bd9Sstevel@tonic-gate int nfreestack; 979*7c478bd9Sstevel@tonic-gate int thread_stack_cache; 980*7c478bd9Sstevel@tonic-gate caddr32_t ulwp_freelist; 981*7c478bd9Sstevel@tonic-gate caddr32_t ulwp_lastfree; 982*7c478bd9Sstevel@tonic-gate caddr32_t ulwp_replace_free; 983*7c478bd9Sstevel@tonic-gate caddr32_t ulwp_replace_last; 984*7c478bd9Sstevel@tonic-gate caddr32_t atforklist; 985*7c478bd9Sstevel@tonic-gate caddr32_t tdb_bootstrap; 986*7c478bd9Sstevel@tonic-gate tdb32_t tdb; 987*7c478bd9Sstevel@tonic-gate } uberdata32_t; 988*7c478bd9Sstevel@tonic-gate 989*7c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 990*7c478bd9Sstevel@tonic-gate 991*7c478bd9Sstevel@tonic-gate /* ul_stop values */ 992*7c478bd9Sstevel@tonic-gate #define TSTP_REGULAR 0x01 /* Stopped by thr_suspend() */ 993*7c478bd9Sstevel@tonic-gate #define TSTP_MUTATOR 0x08 /* stopped by thr_suspend_*mutator*() */ 994*7c478bd9Sstevel@tonic-gate #define TSTP_FORK 0x20 /* stopped by suspend_fork() */ 995*7c478bd9Sstevel@tonic-gate 996*7c478bd9Sstevel@tonic-gate /* 997*7c478bd9Sstevel@tonic-gate * Implementation-specific attribute types for pthread_mutexattr_init() etc. 998*7c478bd9Sstevel@tonic-gate */ 999*7c478bd9Sstevel@tonic-gate 1000*7c478bd9Sstevel@tonic-gate typedef struct _cvattr { 1001*7c478bd9Sstevel@tonic-gate int pshared; 1002*7c478bd9Sstevel@tonic-gate clockid_t clockid; 1003*7c478bd9Sstevel@tonic-gate } cvattr_t; 1004*7c478bd9Sstevel@tonic-gate 1005*7c478bd9Sstevel@tonic-gate typedef struct _mattr { 1006*7c478bd9Sstevel@tonic-gate int pshared; 1007*7c478bd9Sstevel@tonic-gate int protocol; 1008*7c478bd9Sstevel@tonic-gate int prioceiling; 1009*7c478bd9Sstevel@tonic-gate int type; 1010*7c478bd9Sstevel@tonic-gate int robustness; 1011*7c478bd9Sstevel@tonic-gate } mattr_t; 1012*7c478bd9Sstevel@tonic-gate 1013*7c478bd9Sstevel@tonic-gate typedef struct _thrattr { 1014*7c478bd9Sstevel@tonic-gate size_t stksize; 1015*7c478bd9Sstevel@tonic-gate void *stkaddr; 1016*7c478bd9Sstevel@tonic-gate int detachstate; 1017*7c478bd9Sstevel@tonic-gate int scope; 1018*7c478bd9Sstevel@tonic-gate int prio; 1019*7c478bd9Sstevel@tonic-gate int policy; 1020*7c478bd9Sstevel@tonic-gate int inherit; 1021*7c478bd9Sstevel@tonic-gate size_t guardsize; 1022*7c478bd9Sstevel@tonic-gate } thrattr_t; 1023*7c478bd9Sstevel@tonic-gate 1024*7c478bd9Sstevel@tonic-gate typedef struct _rwlattr { 1025*7c478bd9Sstevel@tonic-gate int pshared; 1026*7c478bd9Sstevel@tonic-gate } rwlattr_t; 1027*7c478bd9Sstevel@tonic-gate 1028*7c478bd9Sstevel@tonic-gate /* _curthread() is inline for speed */ 1029*7c478bd9Sstevel@tonic-gate extern ulwp_t *_curthread(void); 1030*7c478bd9Sstevel@tonic-gate #define curthread (_curthread()) 1031*7c478bd9Sstevel@tonic-gate 1032*7c478bd9Sstevel@tonic-gate /* this version (also inline) can be tested for NULL */ 1033*7c478bd9Sstevel@tonic-gate extern ulwp_t *__curthread(void); 1034*7c478bd9Sstevel@tonic-gate 1035*7c478bd9Sstevel@tonic-gate /* get the current stack pointer (also inline) */ 1036*7c478bd9Sstevel@tonic-gate extern greg_t stkptr(void); 1037*7c478bd9Sstevel@tonic-gate 1038*7c478bd9Sstevel@tonic-gate /* 1039*7c478bd9Sstevel@tonic-gate * Suppress __attribute__((...)) if we are not compiling with gcc 1040*7c478bd9Sstevel@tonic-gate */ 1041*7c478bd9Sstevel@tonic-gate #if !defined(__GNUC__) 1042*7c478bd9Sstevel@tonic-gate #define __attribute__(string) 1043*7c478bd9Sstevel@tonic-gate #endif 1044*7c478bd9Sstevel@tonic-gate 1045*7c478bd9Sstevel@tonic-gate #if !defined(__lint) && defined(__GNUC__) && \ 1046*7c478bd9Sstevel@tonic-gate (defined(__i386) || defined(__amd64)) 1047*7c478bd9Sstevel@tonic-gate 1048*7c478bd9Sstevel@tonic-gate /* inlines for gcc */ 1049*7c478bd9Sstevel@tonic-gate 1050*7c478bd9Sstevel@tonic-gate extern __inline__ ulwp_t *_curthread(void) 1051*7c478bd9Sstevel@tonic-gate { 1052*7c478bd9Sstevel@tonic-gate void *__value; 1053*7c478bd9Sstevel@tonic-gate __asm__ __volatile__( 1054*7c478bd9Sstevel@tonic-gate #if defined(__amd64) 1055*7c478bd9Sstevel@tonic-gate "movq %%fs:0,%0" : "=r" (__value)); 1056*7c478bd9Sstevel@tonic-gate #else /* __i386 */ 1057*7c478bd9Sstevel@tonic-gate "movl %%gs:0,%0" : "=r" (__value)); 1058*7c478bd9Sstevel@tonic-gate #endif 1059*7c478bd9Sstevel@tonic-gate return (__value); 1060*7c478bd9Sstevel@tonic-gate } 1061*7c478bd9Sstevel@tonic-gate 1062*7c478bd9Sstevel@tonic-gate extern __inline__ ulwp_t *__curthread(void) 1063*7c478bd9Sstevel@tonic-gate { 1064*7c478bd9Sstevel@tonic-gate void *__value; 1065*7c478bd9Sstevel@tonic-gate __asm__ __volatile__( 1066*7c478bd9Sstevel@tonic-gate #if defined(__amd64) 1067*7c478bd9Sstevel@tonic-gate "xorq %0,%0;" 1068*7c478bd9Sstevel@tonic-gate "mov %%fs,%0;" 1069*7c478bd9Sstevel@tonic-gate "andq %0,%0;" 1070*7c478bd9Sstevel@tonic-gate "je 1f;" 1071*7c478bd9Sstevel@tonic-gate "movq %%fs:0,%0;" 1072*7c478bd9Sstevel@tonic-gate #else /* __i386 */ 1073*7c478bd9Sstevel@tonic-gate "xorl %0,%0;" 1074*7c478bd9Sstevel@tonic-gate "mov %%gs,%0;" 1075*7c478bd9Sstevel@tonic-gate "andl %0,%0;" 1076*7c478bd9Sstevel@tonic-gate "je 1f;" 1077*7c478bd9Sstevel@tonic-gate "movl %%gs:0,%0;" 1078*7c478bd9Sstevel@tonic-gate #endif 1079*7c478bd9Sstevel@tonic-gate "1:" : "=r" (__value)); 1080*7c478bd9Sstevel@tonic-gate return (__value); 1081*7c478bd9Sstevel@tonic-gate } 1082*7c478bd9Sstevel@tonic-gate 1083*7c478bd9Sstevel@tonic-gate extern __inline__ greg_t stkptr(void) 1084*7c478bd9Sstevel@tonic-gate { 1085*7c478bd9Sstevel@tonic-gate greg_t __value; 1086*7c478bd9Sstevel@tonic-gate __asm__ __volatile__( 1087*7c478bd9Sstevel@tonic-gate #if defined(__amd64) 1088*7c478bd9Sstevel@tonic-gate "movq %%rsp, %0" 1089*7c478bd9Sstevel@tonic-gate #else /* __i386 */ 1090*7c478bd9Sstevel@tonic-gate "movl %%esp, %0" 1091*7c478bd9Sstevel@tonic-gate #endif 1092*7c478bd9Sstevel@tonic-gate : "=r" (__value)); 1093*7c478bd9Sstevel@tonic-gate return (__value); 1094*7c478bd9Sstevel@tonic-gate } 1095*7c478bd9Sstevel@tonic-gate 1096*7c478bd9Sstevel@tonic-gate extern __inline__ hrtime_t gethrtime(void) 1097*7c478bd9Sstevel@tonic-gate { 1098*7c478bd9Sstevel@tonic-gate hrtime_t __value; 1099*7c478bd9Sstevel@tonic-gate #if defined(__amd64) 1100*7c478bd9Sstevel@tonic-gate __asm__ __volatile__( 1101*7c478bd9Sstevel@tonic-gate "movl $3,%%eax;" 1102*7c478bd9Sstevel@tonic-gate "int $0xd2" /* caller-saved registers are trashed */ 1103*7c478bd9Sstevel@tonic-gate : "=a" (__value) 1104*7c478bd9Sstevel@tonic-gate : : "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10", "r11"); 1105*7c478bd9Sstevel@tonic-gate #else /* __i386 */ 1106*7c478bd9Sstevel@tonic-gate __asm__ __volatile__( 1107*7c478bd9Sstevel@tonic-gate "movl $3,%%eax;" 1108*7c478bd9Sstevel@tonic-gate "int $0xd2" 1109*7c478bd9Sstevel@tonic-gate : "=A" (__value) 1110*7c478bd9Sstevel@tonic-gate : : "ecx"); 1111*7c478bd9Sstevel@tonic-gate #endif 1112*7c478bd9Sstevel@tonic-gate return (__value); 1113*7c478bd9Sstevel@tonic-gate } 1114*7c478bd9Sstevel@tonic-gate 1115*7c478bd9Sstevel@tonic-gate extern __inline__ int set_lock_byte(volatile uint8_t *__lockp) 1116*7c478bd9Sstevel@tonic-gate { 1117*7c478bd9Sstevel@tonic-gate int __value; 1118*7c478bd9Sstevel@tonic-gate __asm__ __volatile__( 1119*7c478bd9Sstevel@tonic-gate "movl $1,%0;" 1120*7c478bd9Sstevel@tonic-gate "xchgb %%dl,%1" : "+d" (__value) : "m" (*__lockp)); 1121*7c478bd9Sstevel@tonic-gate return (__value); 1122*7c478bd9Sstevel@tonic-gate } 1123*7c478bd9Sstevel@tonic-gate 1124*7c478bd9Sstevel@tonic-gate extern __inline__ uint32_t 1125*7c478bd9Sstevel@tonic-gate swap32(volatile uint32_t *__memory, uint32_t __value) 1126*7c478bd9Sstevel@tonic-gate { 1127*7c478bd9Sstevel@tonic-gate __asm__ __volatile__( 1128*7c478bd9Sstevel@tonic-gate "xchgl %0,%1" : "+q" (__value) : "m" (*__memory)); 1129*7c478bd9Sstevel@tonic-gate return (__value); 1130*7c478bd9Sstevel@tonic-gate } 1131*7c478bd9Sstevel@tonic-gate 1132*7c478bd9Sstevel@tonic-gate extern __inline__ uint32_t 1133*7c478bd9Sstevel@tonic-gate cas32(volatile uint32_t *__memory, uint32_t __cmp, uint32_t __newvalue) 1134*7c478bd9Sstevel@tonic-gate { 1135*7c478bd9Sstevel@tonic-gate uint32_t __oldvalue; 1136*7c478bd9Sstevel@tonic-gate __asm__ __volatile__( 1137*7c478bd9Sstevel@tonic-gate "lock; cmpxchgl %3, %0" 1138*7c478bd9Sstevel@tonic-gate : "=m" (*__memory), "=a" (__oldvalue) 1139*7c478bd9Sstevel@tonic-gate : "a" (__cmp), "r" (__newvalue)); 1140*7c478bd9Sstevel@tonic-gate return (__oldvalue); 1141*7c478bd9Sstevel@tonic-gate } 1142*7c478bd9Sstevel@tonic-gate 1143*7c478bd9Sstevel@tonic-gate extern __inline__ void incr32(volatile uint32_t *__memory) 1144*7c478bd9Sstevel@tonic-gate { 1145*7c478bd9Sstevel@tonic-gate __asm__ __volatile__( 1146*7c478bd9Sstevel@tonic-gate "lock; incl %0" : "=m" (*__memory) : "m" (*__memory)); 1147*7c478bd9Sstevel@tonic-gate } 1148*7c478bd9Sstevel@tonic-gate 1149*7c478bd9Sstevel@tonic-gate extern __inline__ void decr32(volatile uint32_t *__memory) 1150*7c478bd9Sstevel@tonic-gate { 1151*7c478bd9Sstevel@tonic-gate __asm__ __volatile__( 1152*7c478bd9Sstevel@tonic-gate "lock; decl %0" : "=m" (*__memory) : "m" (*__memory)); 1153*7c478bd9Sstevel@tonic-gate } 1154*7c478bd9Sstevel@tonic-gate 1155*7c478bd9Sstevel@tonic-gate extern __inline__ void ht_pause() 1156*7c478bd9Sstevel@tonic-gate { 1157*7c478bd9Sstevel@tonic-gate __asm__ __volatile__("rep; nop"); 1158*7c478bd9Sstevel@tonic-gate } 1159*7c478bd9Sstevel@tonic-gate 1160*7c478bd9Sstevel@tonic-gate #endif /* !__lint && __GNUC__ && (__i386 || __amd64) */ 1161*7c478bd9Sstevel@tonic-gate 1162*7c478bd9Sstevel@tonic-gate /* 1163*7c478bd9Sstevel@tonic-gate * Implementation functions. Not visible outside of the library itself. 1164*7c478bd9Sstevel@tonic-gate */ 1165*7c478bd9Sstevel@tonic-gate extern int ___nanosleep(const timespec_t *, timespec_t *); 1166*7c478bd9Sstevel@tonic-gate extern void getgregs(ulwp_t *, gregset_t); 1167*7c478bd9Sstevel@tonic-gate extern void setgregs(ulwp_t *, gregset_t); 1168*7c478bd9Sstevel@tonic-gate extern void thr_panic(const char *); 1169*7c478bd9Sstevel@tonic-gate #pragma rarely_called(thr_panic) 1170*7c478bd9Sstevel@tonic-gate extern ulwp_t *find_lwp(thread_t); 1171*7c478bd9Sstevel@tonic-gate extern int real_priority(ulwp_t *); 1172*7c478bd9Sstevel@tonic-gate extern void finish_init(void); 1173*7c478bd9Sstevel@tonic-gate extern void queue_alloc(void); 1174*7c478bd9Sstevel@tonic-gate extern void tsd_exit(void); 1175*7c478bd9Sstevel@tonic-gate extern void tsd_free(ulwp_t *); 1176*7c478bd9Sstevel@tonic-gate extern void tls_setup(void); 1177*7c478bd9Sstevel@tonic-gate extern void tls_exit(void); 1178*7c478bd9Sstevel@tonic-gate extern void tls_free(ulwp_t *); 1179*7c478bd9Sstevel@tonic-gate extern void rwl_free(ulwp_t *); 1180*7c478bd9Sstevel@tonic-gate extern void sigacthandler(int, siginfo_t *, void *); 1181*7c478bd9Sstevel@tonic-gate extern void signal_init(void); 1182*7c478bd9Sstevel@tonic-gate extern int sigequalset(const sigset_t *, const sigset_t *); 1183*7c478bd9Sstevel@tonic-gate extern void mutex_setup(void); 1184*7c478bd9Sstevel@tonic-gate extern void take_deferred_signal(int); 1185*7c478bd9Sstevel@tonic-gate extern int setup_context(ucontext_t *, void *(*func)(ulwp_t *), 1186*7c478bd9Sstevel@tonic-gate ulwp_t *ulwp, caddr_t stk, size_t stksize); 1187*7c478bd9Sstevel@tonic-gate extern volatile sc_shared_t *setup_schedctl(void); 1188*7c478bd9Sstevel@tonic-gate extern void *lmalloc(size_t); 1189*7c478bd9Sstevel@tonic-gate extern void lfree(void *, size_t); 1190*7c478bd9Sstevel@tonic-gate extern void *libc_malloc(size_t); 1191*7c478bd9Sstevel@tonic-gate extern void *libc_realloc(void *, size_t); 1192*7c478bd9Sstevel@tonic-gate extern void libc_free(void *); 1193*7c478bd9Sstevel@tonic-gate extern char *libc_strdup(const char *); 1194*7c478bd9Sstevel@tonic-gate extern void ultos(uint64_t, int, char *); 1195*7c478bd9Sstevel@tonic-gate extern void lock_error(const mutex_t *, const char *, void *, const char *); 1196*7c478bd9Sstevel@tonic-gate extern void rwlock_error(const rwlock_t *, const char *, const char *); 1197*7c478bd9Sstevel@tonic-gate extern void thread_error(const char *); 1198*7c478bd9Sstevel@tonic-gate extern void grab_assert_lock(void); 1199*7c478bd9Sstevel@tonic-gate extern void dump_queue_statistics(void); 1200*7c478bd9Sstevel@tonic-gate extern void collect_queue_statistics(void); 1201*7c478bd9Sstevel@tonic-gate extern void record_spin_locks(ulwp_t *); 1202*7c478bd9Sstevel@tonic-gate #if defined(__sparc) 1203*7c478bd9Sstevel@tonic-gate extern void _flush_windows(void); 1204*7c478bd9Sstevel@tonic-gate #else 1205*7c478bd9Sstevel@tonic-gate #define _flush_windows() 1206*7c478bd9Sstevel@tonic-gate #endif 1207*7c478bd9Sstevel@tonic-gate extern void set_curthread(void *); 1208*7c478bd9Sstevel@tonic-gate 1209*7c478bd9Sstevel@tonic-gate #if defined(THREAD_DEBUG) 1210*7c478bd9Sstevel@tonic-gate 1211*7c478bd9Sstevel@tonic-gate extern void __assfail(const char *, const char *, int); 1212*7c478bd9Sstevel@tonic-gate #pragma rarely_called(__assfail) 1213*7c478bd9Sstevel@tonic-gate #define ASSERT(EX) (void)((EX) || (__assfail(#EX, __FILE__, __LINE__), 0)) 1214*7c478bd9Sstevel@tonic-gate 1215*7c478bd9Sstevel@tonic-gate #else /* THREAD_DEBUG */ 1216*7c478bd9Sstevel@tonic-gate 1217*7c478bd9Sstevel@tonic-gate #define ASSERT(EX) ((void)0) 1218*7c478bd9Sstevel@tonic-gate 1219*7c478bd9Sstevel@tonic-gate #endif /* THREAD_DEBUG */ 1220*7c478bd9Sstevel@tonic-gate 1221*7c478bd9Sstevel@tonic-gate /* enter a critical section */ 1222*7c478bd9Sstevel@tonic-gate #define enter_critical(self) (self->ul_critical++) 1223*7c478bd9Sstevel@tonic-gate 1224*7c478bd9Sstevel@tonic-gate /* exit a critical section, take deferred actions if necessary */ 1225*7c478bd9Sstevel@tonic-gate extern void do_exit_critical(void); 1226*7c478bd9Sstevel@tonic-gate #define exit_critical(self) \ 1227*7c478bd9Sstevel@tonic-gate (void) (self->ul_critical--, \ 1228*7c478bd9Sstevel@tonic-gate ((self->ul_curplease && self->ul_critical == 0)? \ 1229*7c478bd9Sstevel@tonic-gate (do_exit_critical(), 0) : 0)) 1230*7c478bd9Sstevel@tonic-gate 1231*7c478bd9Sstevel@tonic-gate /* 1232*7c478bd9Sstevel@tonic-gate * Like enter_critical()/exit_critical() but just for deferring signals. 1233*7c478bd9Sstevel@tonic-gate * Unlike enter_critical()/exit_critical(), ul_sigdefer may be set while 1234*7c478bd9Sstevel@tonic-gate * calling application functions like constructors and destructors. 1235*7c478bd9Sstevel@tonic-gate * Care must be taken if the application function attempts to set 1236*7c478bd9Sstevel@tonic-gate * the signal mask while a deferred signal is present; the setting 1237*7c478bd9Sstevel@tonic-gate * of the signal mask must also be deferred. 1238*7c478bd9Sstevel@tonic-gate */ 1239*7c478bd9Sstevel@tonic-gate #define sigoff(self) (self->ul_sigdefer++) 1240*7c478bd9Sstevel@tonic-gate extern void sigon(ulwp_t *); 1241*7c478bd9Sstevel@tonic-gate 1242*7c478bd9Sstevel@tonic-gate /* these are exported functions */ 1243*7c478bd9Sstevel@tonic-gate extern void _sigoff(void); 1244*7c478bd9Sstevel@tonic-gate extern void _sigon(void); 1245*7c478bd9Sstevel@tonic-gate 1246*7c478bd9Sstevel@tonic-gate #define sigorset(s1, s2) \ 1247*7c478bd9Sstevel@tonic-gate (((s1)->__sigbits[0] |= (s2)->__sigbits[0]), \ 1248*7c478bd9Sstevel@tonic-gate ((s1)->__sigbits[1] |= (s2)->__sigbits[1]), \ 1249*7c478bd9Sstevel@tonic-gate ((s1)->__sigbits[2] |= (s2)->__sigbits[2]), \ 1250*7c478bd9Sstevel@tonic-gate ((s1)->__sigbits[3] |= (s2)->__sigbits[3])) 1251*7c478bd9Sstevel@tonic-gate 1252*7c478bd9Sstevel@tonic-gate #define sigandset(s1, s2) \ 1253*7c478bd9Sstevel@tonic-gate (((s1)->__sigbits[0] &= (s2)->__sigbits[0]), \ 1254*7c478bd9Sstevel@tonic-gate ((s1)->__sigbits[1] &= (s2)->__sigbits[1]), \ 1255*7c478bd9Sstevel@tonic-gate ((s1)->__sigbits[2] &= (s2)->__sigbits[2]), \ 1256*7c478bd9Sstevel@tonic-gate ((s1)->__sigbits[3] &= (s2)->__sigbits[3])) 1257*7c478bd9Sstevel@tonic-gate 1258*7c478bd9Sstevel@tonic-gate #define sigdiffset(s1, s2) \ 1259*7c478bd9Sstevel@tonic-gate (((s1)->__sigbits[0] &= ~(s2)->__sigbits[0]), \ 1260*7c478bd9Sstevel@tonic-gate ((s1)->__sigbits[1] &= ~(s2)->__sigbits[1]), \ 1261*7c478bd9Sstevel@tonic-gate ((s1)->__sigbits[2] &= ~(s2)->__sigbits[2]), \ 1262*7c478bd9Sstevel@tonic-gate ((s1)->__sigbits[3] &= ~(s2)->__sigbits[3])) 1263*7c478bd9Sstevel@tonic-gate 1264*7c478bd9Sstevel@tonic-gate #define delete_reserved_signals(s) \ 1265*7c478bd9Sstevel@tonic-gate (((s)->__sigbits[0] &= MASKSET0), \ 1266*7c478bd9Sstevel@tonic-gate ((s)->__sigbits[1] &= (MASKSET1 & ~SIGMASK(SIGCANCEL))),\ 1267*7c478bd9Sstevel@tonic-gate ((s)->__sigbits[2] = 0), \ 1268*7c478bd9Sstevel@tonic-gate ((s)->__sigbits[3] = 0)) 1269*7c478bd9Sstevel@tonic-gate 1270*7c478bd9Sstevel@tonic-gate extern void block_all_signals(ulwp_t *self); 1271*7c478bd9Sstevel@tonic-gate 1272*7c478bd9Sstevel@tonic-gate /* 1273*7c478bd9Sstevel@tonic-gate * When restoring the signal mask after having previously called 1274*7c478bd9Sstevel@tonic-gate * block_all_signals(), if we have a deferred signal present then 1275*7c478bd9Sstevel@tonic-gate * do nothing other than ASSERT() that we are in a critical region. 1276*7c478bd9Sstevel@tonic-gate * The signal mask will be set when we emerge from the critical region 1277*7c478bd9Sstevel@tonic-gate * and call take_deferred_signal(). There is no race condition here 1278*7c478bd9Sstevel@tonic-gate * because the kernel currently has all signals blocked for this thread. 1279*7c478bd9Sstevel@tonic-gate */ 1280*7c478bd9Sstevel@tonic-gate #define restore_signals(self) \ 1281*7c478bd9Sstevel@tonic-gate ((void) ((self)->ul_cursig? \ 1282*7c478bd9Sstevel@tonic-gate (ASSERT((self)->ul_critical + (self)->ul_sigdefer != 0), 0) : \ 1283*7c478bd9Sstevel@tonic-gate __lwp_sigmask(SIG_SETMASK, &(self)->ul_sigmask, NULL))) 1284*7c478bd9Sstevel@tonic-gate 1285*7c478bd9Sstevel@tonic-gate extern void set_parking_flag(ulwp_t *, int); 1286*7c478bd9Sstevel@tonic-gate 1287*7c478bd9Sstevel@tonic-gate extern void *_thr_setup(ulwp_t *); 1288*7c478bd9Sstevel@tonic-gate extern void _fpinherit(ulwp_t *); 1289*7c478bd9Sstevel@tonic-gate extern void _lwp_start(void); 1290*7c478bd9Sstevel@tonic-gate extern void _lwp_terminate(void); 1291*7c478bd9Sstevel@tonic-gate extern void lmutex_unlock(mutex_t *); 1292*7c478bd9Sstevel@tonic-gate extern void lmutex_lock(mutex_t *); 1293*7c478bd9Sstevel@tonic-gate extern void _prefork_handler(void); 1294*7c478bd9Sstevel@tonic-gate extern void _postfork_parent_handler(void); 1295*7c478bd9Sstevel@tonic-gate extern void _postfork_child_handler(void); 1296*7c478bd9Sstevel@tonic-gate extern void _postfork1_child(void); 1297*7c478bd9Sstevel@tonic-gate extern int fork_lock_enter(const char *); 1298*7c478bd9Sstevel@tonic-gate extern void fork_lock_exit(void); 1299*7c478bd9Sstevel@tonic-gate extern void suspend_fork(void); 1300*7c478bd9Sstevel@tonic-gate extern void continue_fork(int); 1301*7c478bd9Sstevel@tonic-gate extern void do_sigcancel(void); 1302*7c478bd9Sstevel@tonic-gate extern void init_sigcancel(void); 1303*7c478bd9Sstevel@tonic-gate extern void _cancelon(void); 1304*7c478bd9Sstevel@tonic-gate extern void _canceloff(void); 1305*7c478bd9Sstevel@tonic-gate extern void _canceloff_nocancel(void); 1306*7c478bd9Sstevel@tonic-gate extern void no_preempt(ulwp_t *); 1307*7c478bd9Sstevel@tonic-gate extern void preempt(ulwp_t *); 1308*7c478bd9Sstevel@tonic-gate extern void _thrp_unwind(void *); 1309*7c478bd9Sstevel@tonic-gate 1310*7c478bd9Sstevel@tonic-gate /* 1311*7c478bd9Sstevel@tonic-gate * Prototypes for the strong versions of the interface functions 1312*7c478bd9Sstevel@tonic-gate */ 1313*7c478bd9Sstevel@tonic-gate extern pid_t _fork(void); 1314*7c478bd9Sstevel@tonic-gate extern pid_t _fork1(void); 1315*7c478bd9Sstevel@tonic-gate extern pid_t __fork1(void); 1316*7c478bd9Sstevel@tonic-gate extern pid_t _forkall(void); 1317*7c478bd9Sstevel@tonic-gate extern pid_t __forkall(void); 1318*7c478bd9Sstevel@tonic-gate extern pid_t _private_getpid(void); 1319*7c478bd9Sstevel@tonic-gate extern uid_t _private_geteuid(void); 1320*7c478bd9Sstevel@tonic-gate extern int _kill(pid_t, int); 1321*7c478bd9Sstevel@tonic-gate extern int _open(const char *, int, ...); 1322*7c478bd9Sstevel@tonic-gate extern int _close(int); 1323*7c478bd9Sstevel@tonic-gate extern ssize_t _read(int, void *, size_t); 1324*7c478bd9Sstevel@tonic-gate extern ssize_t _write(int, const void *, size_t); 1325*7c478bd9Sstevel@tonic-gate extern void *_memcpy(void *, const void *, size_t); 1326*7c478bd9Sstevel@tonic-gate extern void *_memset(void *, int, size_t); 1327*7c478bd9Sstevel@tonic-gate extern void *_private_memcpy(void *, const void *, size_t); 1328*7c478bd9Sstevel@tonic-gate extern void *_private_memset(void *, int, size_t); 1329*7c478bd9Sstevel@tonic-gate extern int _private_sigfillset(sigset_t *); 1330*7c478bd9Sstevel@tonic-gate extern int _private_sigemptyset(sigset_t *); 1331*7c478bd9Sstevel@tonic-gate extern int _private_sigaddset(sigset_t *, int); 1332*7c478bd9Sstevel@tonic-gate extern int _private_sigdelset(sigset_t *, int); 1333*7c478bd9Sstevel@tonic-gate extern int _private_sigismember(sigset_t *, int); 1334*7c478bd9Sstevel@tonic-gate extern void *_private_mmap(void *, size_t, int, int, int, off_t); 1335*7c478bd9Sstevel@tonic-gate extern int _private_mprotect(void *, size_t, int); 1336*7c478bd9Sstevel@tonic-gate extern int _private_munmap(void *, size_t); 1337*7c478bd9Sstevel@tonic-gate extern int _private_getrlimit(int, struct rlimit *); 1338*7c478bd9Sstevel@tonic-gate extern int __lwp_continue(lwpid_t); 1339*7c478bd9Sstevel@tonic-gate extern int __lwp_create(ucontext_t *, uint_t, lwpid_t *); 1340*7c478bd9Sstevel@tonic-gate extern int __lwp_kill(lwpid_t, int); 1341*7c478bd9Sstevel@tonic-gate extern lwpid_t __lwp_self(void); 1342*7c478bd9Sstevel@tonic-gate extern int ___lwp_suspend(lwpid_t); 1343*7c478bd9Sstevel@tonic-gate extern void lwp_yield(void); 1344*7c478bd9Sstevel@tonic-gate extern int lwp_wait(lwpid_t, lwpid_t *); 1345*7c478bd9Sstevel@tonic-gate extern int __lwp_wait(lwpid_t, lwpid_t *); 1346*7c478bd9Sstevel@tonic-gate extern int __lwp_detach(lwpid_t); 1347*7c478bd9Sstevel@tonic-gate extern sc_shared_t *__schedctl(void); 1348*7c478bd9Sstevel@tonic-gate 1349*7c478bd9Sstevel@tonic-gate extern int _private_setcontext(const ucontext_t *); 1350*7c478bd9Sstevel@tonic-gate extern int _private_getcontext(ucontext_t *); 1351*7c478bd9Sstevel@tonic-gate #pragma unknown_control_flow(_private_getcontext) 1352*7c478bd9Sstevel@tonic-gate /* actual system call traps */ 1353*7c478bd9Sstevel@tonic-gate extern int __setcontext_syscall(const ucontext_t *); 1354*7c478bd9Sstevel@tonic-gate extern int __getcontext_syscall(ucontext_t *); 1355*7c478bd9Sstevel@tonic-gate extern int _private_setustack(stack_t *); 1356*7c478bd9Sstevel@tonic-gate extern int __clock_gettime(clockid_t, timespec_t *); 1357*7c478bd9Sstevel@tonic-gate extern void abstime_to_reltime(clockid_t, const timespec_t *, timespec_t *); 1358*7c478bd9Sstevel@tonic-gate extern void hrt2ts(hrtime_t, timespec_t *); 1359*7c478bd9Sstevel@tonic-gate 1360*7c478bd9Sstevel@tonic-gate extern int __sigaction(int, const struct sigaction *, struct sigaction *); 1361*7c478bd9Sstevel@tonic-gate extern int __lwp_sigmask(int, const sigset_t *, sigset_t *); 1362*7c478bd9Sstevel@tonic-gate extern void __sighndlr(int, siginfo_t *, ucontext_t *, void (*)()); 1363*7c478bd9Sstevel@tonic-gate extern caddr_t __sighndlrend; 1364*7c478bd9Sstevel@tonic-gate #pragma unknown_control_flow(__sighndlr) 1365*7c478bd9Sstevel@tonic-gate 1366*7c478bd9Sstevel@tonic-gate extern void _pthread_exit(void *); 1367*7c478bd9Sstevel@tonic-gate 1368*7c478bd9Sstevel@tonic-gate /* these are private to the library */ 1369*7c478bd9Sstevel@tonic-gate extern int _private_mutex_init(mutex_t *, int, void *); 1370*7c478bd9Sstevel@tonic-gate extern int _private_mutex_destroy(mutex_t *); 1371*7c478bd9Sstevel@tonic-gate extern int _private_mutex_lock(mutex_t *); 1372*7c478bd9Sstevel@tonic-gate extern int _private_mutex_trylock(mutex_t *); 1373*7c478bd9Sstevel@tonic-gate extern int _private_mutex_unlock(mutex_t *); 1374*7c478bd9Sstevel@tonic-gate 1375*7c478bd9Sstevel@tonic-gate extern int _mutex_init(mutex_t *, int, void *); 1376*7c478bd9Sstevel@tonic-gate extern int _mutex_destroy(mutex_t *); 1377*7c478bd9Sstevel@tonic-gate extern int _mutex_lock(mutex_t *); 1378*7c478bd9Sstevel@tonic-gate extern int _mutex_trylock(mutex_t *); 1379*7c478bd9Sstevel@tonic-gate extern int _mutex_unlock(mutex_t *); 1380*7c478bd9Sstevel@tonic-gate extern void _mutex_set_typeattr(mutex_t *, int); 1381*7c478bd9Sstevel@tonic-gate extern int __mutex_init(mutex_t *, int, void *); 1382*7c478bd9Sstevel@tonic-gate extern int __mutex_destroy(mutex_t *); 1383*7c478bd9Sstevel@tonic-gate extern int __mutex_lock(mutex_t *); 1384*7c478bd9Sstevel@tonic-gate extern int __mutex_trylock(mutex_t *); 1385*7c478bd9Sstevel@tonic-gate extern int __mutex_unlock(mutex_t *); 1386*7c478bd9Sstevel@tonic-gate extern int mutex_is_held(mutex_t *); 1387*7c478bd9Sstevel@tonic-gate extern int mutex_lock_internal(mutex_t *, timespec_t *, int); 1388*7c478bd9Sstevel@tonic-gate extern int mutex_trylock_adaptive(mutex_t *); 1389*7c478bd9Sstevel@tonic-gate extern int mutex_queuelock_adaptive(mutex_t *); 1390*7c478bd9Sstevel@tonic-gate extern int mutex_lock_impl(mutex_t *mp, timespec_t *tsp); 1391*7c478bd9Sstevel@tonic-gate 1392*7c478bd9Sstevel@tonic-gate extern int _cond_init(cond_t *, int, void *); 1393*7c478bd9Sstevel@tonic-gate extern int _cond_wait(cond_t *, mutex_t *); 1394*7c478bd9Sstevel@tonic-gate extern int _cond_timedwait(cond_t *, mutex_t *, const timespec_t *); 1395*7c478bd9Sstevel@tonic-gate extern int _cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *); 1396*7c478bd9Sstevel@tonic-gate extern int _cond_signal(cond_t *); 1397*7c478bd9Sstevel@tonic-gate extern int _cond_broadcast(cond_t *); 1398*7c478bd9Sstevel@tonic-gate extern int _cond_destroy(cond_t *); 1399*7c478bd9Sstevel@tonic-gate extern int cond_sleep_queue(cond_t *, mutex_t *, timespec_t *); 1400*7c478bd9Sstevel@tonic-gate extern int cond_sleep_kernel(cond_t *, mutex_t *, timespec_t *); 1401*7c478bd9Sstevel@tonic-gate extern int cond_signal_internal(cond_t *); 1402*7c478bd9Sstevel@tonic-gate extern int cond_broadcast_internal(cond_t *); 1403*7c478bd9Sstevel@tonic-gate 1404*7c478bd9Sstevel@tonic-gate extern int __rwlock_init(rwlock_t *, int, void *); 1405*7c478bd9Sstevel@tonic-gate extern int rw_read_is_held(rwlock_t *); 1406*7c478bd9Sstevel@tonic-gate extern int rw_write_is_held(rwlock_t *); 1407*7c478bd9Sstevel@tonic-gate 1408*7c478bd9Sstevel@tonic-gate extern int _thr_continue(thread_t); 1409*7c478bd9Sstevel@tonic-gate extern int _thrp_create(void *, size_t, void *(*func)(void *), void *, 1410*7c478bd9Sstevel@tonic-gate long, thread_t *, pri_t, int, size_t); 1411*7c478bd9Sstevel@tonic-gate extern int _thr_getprio(thread_t, int *); 1412*7c478bd9Sstevel@tonic-gate extern int _thr_getspecific(thread_key_t, void **); 1413*7c478bd9Sstevel@tonic-gate extern int _thr_join(thread_t, thread_t *, void **); 1414*7c478bd9Sstevel@tonic-gate extern int _thr_keycreate(thread_key_t *, PFrV); 1415*7c478bd9Sstevel@tonic-gate extern int _thr_key_delete(thread_key_t); 1416*7c478bd9Sstevel@tonic-gate extern int _thr_main(void); 1417*7c478bd9Sstevel@tonic-gate extern thread_t _thr_self(void); 1418*7c478bd9Sstevel@tonic-gate extern int _thr_getconcurrency(void); 1419*7c478bd9Sstevel@tonic-gate extern int _thr_setconcurrency(int); 1420*7c478bd9Sstevel@tonic-gate extern int _thr_setprio(thread_t, int); 1421*7c478bd9Sstevel@tonic-gate extern int _thr_setspecific(thread_key_t, void *); 1422*7c478bd9Sstevel@tonic-gate extern int _thr_stksegment(stack_t *); 1423*7c478bd9Sstevel@tonic-gate extern int _thrp_suspend(thread_t, uchar_t); 1424*7c478bd9Sstevel@tonic-gate extern int _thrp_continue(thread_t, uchar_t); 1425*7c478bd9Sstevel@tonic-gate extern int _thr_sigsetmask(int, const sigset_t *, sigset_t *); 1426*7c478bd9Sstevel@tonic-gate 1427*7c478bd9Sstevel@tonic-gate extern void _thr_terminate(void *); 1428*7c478bd9Sstevel@tonic-gate extern void _thr_exit(void *); 1429*7c478bd9Sstevel@tonic-gate extern void _thrp_exit(void); 1430*7c478bd9Sstevel@tonic-gate 1431*7c478bd9Sstevel@tonic-gate extern int _thread_setschedparam_main(pthread_t, int, 1432*7c478bd9Sstevel@tonic-gate const struct sched_param *, int); 1433*7c478bd9Sstevel@tonic-gate extern int _validate_rt_prio(int, int); 1434*7c478bd9Sstevel@tonic-gate extern int _thrp_setlwpprio(lwpid_t, int, int); 1435*7c478bd9Sstevel@tonic-gate extern pri_t _map_rtpri_to_gp(pri_t); 1436*7c478bd9Sstevel@tonic-gate 1437*7c478bd9Sstevel@tonic-gate /* 1438*7c478bd9Sstevel@tonic-gate * System call wrappers (direct interfaces to the kernel) 1439*7c478bd9Sstevel@tonic-gate */ 1440*7c478bd9Sstevel@tonic-gate extern int ___lwp_mutex_init(mutex_t *, int); 1441*7c478bd9Sstevel@tonic-gate extern int ___lwp_mutex_trylock(mutex_t *); 1442*7c478bd9Sstevel@tonic-gate extern int ___lwp_mutex_timedlock(mutex_t *, timespec_t *); 1443*7c478bd9Sstevel@tonic-gate extern int ___lwp_mutex_unlock(mutex_t *); 1444*7c478bd9Sstevel@tonic-gate extern int ___lwp_mutex_wakeup(mutex_t *); 1445*7c478bd9Sstevel@tonic-gate extern int ___lwp_cond_wait(cond_t *, mutex_t *, timespec_t *, int); 1446*7c478bd9Sstevel@tonic-gate extern int __lwp_cond_signal(lwp_cond_t *); 1447*7c478bd9Sstevel@tonic-gate extern int __lwp_cond_broadcast(lwp_cond_t *); 1448*7c478bd9Sstevel@tonic-gate extern int ___lwp_sema_timedwait(lwp_sema_t *, timespec_t *, int); 1449*7c478bd9Sstevel@tonic-gate extern int __lwp_sema_trywait(lwp_sema_t *); 1450*7c478bd9Sstevel@tonic-gate extern int __lwp_sema_post(lwp_sema_t *); 1451*7c478bd9Sstevel@tonic-gate extern int __lwp_rwlock_rdlock(rwlock_t *, timespec_t *); 1452*7c478bd9Sstevel@tonic-gate extern int __lwp_rwlock_wrlock(rwlock_t *, timespec_t *); 1453*7c478bd9Sstevel@tonic-gate extern int __lwp_rwlock_tryrdlock(rwlock_t *); 1454*7c478bd9Sstevel@tonic-gate extern int __lwp_rwlock_trywrlock(rwlock_t *); 1455*7c478bd9Sstevel@tonic-gate extern int __lwp_rwlock_unlock(rwlock_t *); 1456*7c478bd9Sstevel@tonic-gate extern int __lwp_park(timespec_t *, lwpid_t); 1457*7c478bd9Sstevel@tonic-gate extern int __lwp_unpark(lwpid_t); 1458*7c478bd9Sstevel@tonic-gate extern int __lwp_unpark_all(lwpid_t *, int); 1459*7c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64) 1460*7c478bd9Sstevel@tonic-gate extern int ___lwp_private(int, int, void *); 1461*7c478bd9Sstevel@tonic-gate #endif /* __i386 || __amd64 */ 1462*7c478bd9Sstevel@tonic-gate 1463*7c478bd9Sstevel@tonic-gate extern int _private_lwp_mutex_lock(mutex_t *); 1464*7c478bd9Sstevel@tonic-gate extern int _private_lwp_mutex_unlock(mutex_t *); 1465*7c478bd9Sstevel@tonic-gate 1466*7c478bd9Sstevel@tonic-gate /* 1467*7c478bd9Sstevel@tonic-gate * inlines 1468*7c478bd9Sstevel@tonic-gate */ 1469*7c478bd9Sstevel@tonic-gate extern int set_lock_byte(volatile uint8_t *); 1470*7c478bd9Sstevel@tonic-gate extern uint32_t swap32(volatile uint32_t *, uint32_t); 1471*7c478bd9Sstevel@tonic-gate extern uint32_t cas32(volatile uint32_t *, uint32_t, uint32_t); 1472*7c478bd9Sstevel@tonic-gate extern void incr32(volatile uint32_t *); 1473*7c478bd9Sstevel@tonic-gate extern void decr32(volatile uint32_t *); 1474*7c478bd9Sstevel@tonic-gate 1475*7c478bd9Sstevel@tonic-gate #endif /* _THR_UBERDATA_H */ 1476