xref: /illumos-gate/usr/src/lib/libc/inc/thr_uberdata.h (revision fc2512cf)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
534709573Sraf  * Common Development and Distribution License (the "License").
634709573Sraf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
210ec57554Sraf 
227c478bd9Sstevel@tonic-gate /*
2323a1cceaSRoger A. Faulkner  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
254f364e7cSRobert Mustacchi /*
26*fc2512cfSRobert Mustacchi  * Copyright 2016 Joyent, Inc.
274f364e7cSRobert Mustacchi  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef _THR_UBERDATA_H
307c478bd9Sstevel@tonic-gate #define	_THR_UBERDATA_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <stdlib.h>
337c478bd9Sstevel@tonic-gate #include <unistd.h>
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <fcntl.h>
367c478bd9Sstevel@tonic-gate #include <string.h>
377c478bd9Sstevel@tonic-gate #include <signal.h>
387c478bd9Sstevel@tonic-gate #include <ucontext.h>
397c478bd9Sstevel@tonic-gate #include <thread.h>
407c478bd9Sstevel@tonic-gate #include <pthread.h>
417257d1b4Sraf #include <atomic.h>
427c478bd9Sstevel@tonic-gate #include <link.h>
437c478bd9Sstevel@tonic-gate #include <sys/resource.h>
447c478bd9Sstevel@tonic-gate #include <sys/lwp.h>
457c478bd9Sstevel@tonic-gate #include <errno.h>
467c478bd9Sstevel@tonic-gate #include <sys/asm_linkage.h>
477c478bd9Sstevel@tonic-gate #include <sys/regset.h>
487c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
497c478bd9Sstevel@tonic-gate #include <sys/mman.h>
507c478bd9Sstevel@tonic-gate #include <synch.h>
517c478bd9Sstevel@tonic-gate #include <door.h>
527c478bd9Sstevel@tonic-gate #include <limits.h>
537c478bd9Sstevel@tonic-gate #include <sys/synch32.h>
547c478bd9Sstevel@tonic-gate #include <schedctl.h>
557c478bd9Sstevel@tonic-gate #include <sys/priocntl.h>
567c478bd9Sstevel@tonic-gate #include <thread_db.h>
57f841f6adSraf #include <setjmp.h>
587c478bd9Sstevel@tonic-gate #include "libc_int.h"
597c478bd9Sstevel@tonic-gate #include "tdb_agent.h"
60f841f6adSraf #include "thr_debug.h"
6134709573Sraf 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * This is an implementation-specific include file for threading support.
647c478bd9Sstevel@tonic-gate  * It is not to be seen by the clients of the library.
657c478bd9Sstevel@tonic-gate  *
667c478bd9Sstevel@tonic-gate  * This file also describes uberdata in libc.
677c478bd9Sstevel@tonic-gate  *
687c478bd9Sstevel@tonic-gate  * The term "uberdata" refers to data that is unique and visible across
697c478bd9Sstevel@tonic-gate  * all link maps.  The name is meant to imply that such data is truly
707c478bd9Sstevel@tonic-gate  * global, not just locally global to a particular link map.
717c478bd9Sstevel@tonic-gate  *
727c478bd9Sstevel@tonic-gate  * See the Linker and Libraries Guide for a full description of alternate
737c478bd9Sstevel@tonic-gate  * link maps and how they are set up and used.
747c478bd9Sstevel@tonic-gate  *
757c478bd9Sstevel@tonic-gate  * Alternate link maps implement multiple global namespaces within a single
767c478bd9Sstevel@tonic-gate  * process.  There may be multiple instances of identical dynamic libraries
777c478bd9Sstevel@tonic-gate  * loaded in a process's address space at the same time, each on a different
787c478bd9Sstevel@tonic-gate  * link map (as determined by the dynamic linker), each with its own set of
797c478bd9Sstevel@tonic-gate  * global variables.  Which particular instance of a global variable is seen
807c478bd9Sstevel@tonic-gate  * by a thread running in the process is determined by the link map on which
817c478bd9Sstevel@tonic-gate  * the thread happens to be executing at the time.
827c478bd9Sstevel@tonic-gate  *
837c478bd9Sstevel@tonic-gate  * However, there are aspects of a process that are unique across all
847c478bd9Sstevel@tonic-gate  * link maps, in particular the structures used to implement threads
857c478bd9Sstevel@tonic-gate  * of control (in Sparc terminology, there is only one %g7 regardless
867c478bd9Sstevel@tonic-gate  * of the link map on which the thread is executing).
877c478bd9Sstevel@tonic-gate  *
887c478bd9Sstevel@tonic-gate  * All uberdata is referenced from a base pointer in the thread's ulwp_t
897c478bd9Sstevel@tonic-gate  * structure (which is also uberdata).  All allocations and deallocations
907c478bd9Sstevel@tonic-gate  * of uberdata are made via the uberdata-aware lmalloc() and lfree()
917c478bd9Sstevel@tonic-gate  * interfaces (malloc() and free() are simply locally-global).
927c478bd9Sstevel@tonic-gate  */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate  * Special libc-private access to errno.
967c478bd9Sstevel@tonic-gate  * We do this so that references to errno do not invoke the dynamic linker.
977c478bd9Sstevel@tonic-gate  */
987c478bd9Sstevel@tonic-gate #undef errno
997c478bd9Sstevel@tonic-gate #define	errno (*curthread->ul_errnop)
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  * See <sys/synch32.h> for the reasons for these values
1037c478bd9Sstevel@tonic-gate  * and why they are different for sparc and intel.
1047c478bd9Sstevel@tonic-gate  */
1057c478bd9Sstevel@tonic-gate #if defined(__sparc)
10631db3c26Sraf 
1077c478bd9Sstevel@tonic-gate /* lock.lock64.pad[x]	   4 5 6 7 */
1087c478bd9Sstevel@tonic-gate #define	LOCKMASK	0xff000000
1097c478bd9Sstevel@tonic-gate #define	WAITERMASK	0x000000ff
1105d1dd9a9Sraf #define	SPINNERMASK	0x00ff0000
1115d1dd9a9Sraf #define	SPINNERSHIFT	16
1127c478bd9Sstevel@tonic-gate #define	WAITER		0x00000001
1137c478bd9Sstevel@tonic-gate #define	LOCKSET		0xff
1147c478bd9Sstevel@tonic-gate #define	LOCKCLEAR	0
11531db3c26Sraf 
11631db3c26Sraf #define	PIDSHIFT	32
11731db3c26Sraf #define	LOCKMASK64	0xffffffffff000000ULL
11831db3c26Sraf #define	LOCKBYTE64	0x00000000ff000000ULL
11931db3c26Sraf #define	WAITERMASK64	0x00000000000000ffULL
12031db3c26Sraf #define	SPINNERMASK64	0x0000000000ff0000ULL
12131db3c26Sraf 
1220ec57554Sraf #elif defined(__x86)
12331db3c26Sraf 
1247c478bd9Sstevel@tonic-gate /* lock.lock64.pad[x]	   7 6 5 4 */
1257c478bd9Sstevel@tonic-gate #define	LOCKMASK	0xff000000
1267c478bd9Sstevel@tonic-gate #define	WAITERMASK	0x00ff0000
1275d1dd9a9Sraf #define	SPINNERMASK	0x0000ff00
1285d1dd9a9Sraf #define	SPINNERSHIFT	8
1297c478bd9Sstevel@tonic-gate #define	WAITER		0x00010000
1307c478bd9Sstevel@tonic-gate #define	LOCKSET		0x01
1317c478bd9Sstevel@tonic-gate #define	LOCKCLEAR	0
13231db3c26Sraf 
13331db3c26Sraf #define	PIDSHIFT	0
13431db3c26Sraf #define	LOCKMASK64	0xff000000ffffffffULL
13531db3c26Sraf #define	LOCKBYTE64	0x0100000000000000ULL
13631db3c26Sraf #define	WAITERMASK64	0x00ff000000000000ULL
13731db3c26Sraf #define	SPINNERMASK64	0x0000ff0000000000ULL
13831db3c26Sraf 
1397c478bd9Sstevel@tonic-gate #else
1400ec57554Sraf #error "neither __sparc nor __x86 is defined"
1417c478bd9Sstevel@tonic-gate #endif
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate /*
1447c478bd9Sstevel@tonic-gate  * Fetch the owner of a USYNC_THREAD mutex.
1457c478bd9Sstevel@tonic-gate  * Don't use this with process-shared mutexes;
1467c478bd9Sstevel@tonic-gate  * the owing thread may be in a different process.
1477c478bd9Sstevel@tonic-gate  */
1487c478bd9Sstevel@tonic-gate #define	MUTEX_OWNER(mp)	((ulwp_t *)(uintptr_t)(mp)->mutex_owner)
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
151883492d5Sraf  * Test if a thread owns a process-private (USYNC_THREAD) mutex.
152883492d5Sraf  * This is inappropriate for a process-shared (USYNC_PROCESS) mutex.
1537c478bd9Sstevel@tonic-gate  * The 'mp' argument must not have side-effects since it is evaluated twice.
1547c478bd9Sstevel@tonic-gate  */
1557c478bd9Sstevel@tonic-gate #define	MUTEX_OWNED(mp, thrp)	\
1567c478bd9Sstevel@tonic-gate 	((mp)->mutex_lockw != 0 && MUTEX_OWNER(mp) == thrp)
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate /*
1607c478bd9Sstevel@tonic-gate  * uberflags.uf_tdb_register_sync is an interface with libc_db to enable the
1617c478bd9Sstevel@tonic-gate  * collection of lock statistics by a debugger or other collecting tool.
1627c478bd9Sstevel@tonic-gate  *
1637c478bd9Sstevel@tonic-gate  * uberflags.uf_thread_error_detection is set by an environment variable:
1647c478bd9Sstevel@tonic-gate  *	_THREAD_ERROR_DETECTION
1657c478bd9Sstevel@tonic-gate  *		0 == no detection of locking primitive errors.
1667c478bd9Sstevel@tonic-gate  *		1 == detect errors and issue a warning message.
1677c478bd9Sstevel@tonic-gate  *		2 == detect errors, issue a warning message, and dump core.
1687c478bd9Sstevel@tonic-gate  *
1697c478bd9Sstevel@tonic-gate  * We bundle these together in uberflags.uf_trs_ted to make a test of either
1707c478bd9Sstevel@tonic-gate  * being non-zero a single memory reference (for speed of mutex_lock(), etc).
1717c478bd9Sstevel@tonic-gate  *
1727c478bd9Sstevel@tonic-gate  * uberflags.uf_mt is set non-zero when the first thread (in addition
1737c478bd9Sstevel@tonic-gate  * to the main thread) is created.
1747c478bd9Sstevel@tonic-gate  *
1757c478bd9Sstevel@tonic-gate  * We bundle all these flags together in uberflags.uf_all to make a test
1767c478bd9Sstevel@tonic-gate  * of any being non-zero a single memory reference (again, for speed).
1777c478bd9Sstevel@tonic-gate  */
1787c478bd9Sstevel@tonic-gate typedef union {
1797c478bd9Sstevel@tonic-gate 	int	uf_all;			/* combined all flags */
1807c478bd9Sstevel@tonic-gate 	struct {
1817c478bd9Sstevel@tonic-gate 		short	h_pad;
1827c478bd9Sstevel@tonic-gate 		short	h_trs_ted;	/* combined reg sync & error detect */
1837c478bd9Sstevel@tonic-gate 	} uf_h;
1847c478bd9Sstevel@tonic-gate 	struct {
1857c478bd9Sstevel@tonic-gate 		char	x_mt;
1867c478bd9Sstevel@tonic-gate 		char	x_pad;
1877c478bd9Sstevel@tonic-gate 		char	x_tdb_register_sync;
1887c478bd9Sstevel@tonic-gate 		char	x_thread_error_detection;
1897c478bd9Sstevel@tonic-gate 	} uf_x;
1907c478bd9Sstevel@tonic-gate } uberflags_t;
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate #define	uf_mt				uf_x.x_mt
1937c478bd9Sstevel@tonic-gate #define	uf_tdb_register_sync		uf_x.x_tdb_register_sync
1947c478bd9Sstevel@tonic-gate #define	uf_thread_error_detection	uf_x.x_thread_error_detection
1957c478bd9Sstevel@tonic-gate #define	uf_trs_ted			uf_h.h_trs_ted	/* both of the above */
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate  * NOTE WELL:
1997c478bd9Sstevel@tonic-gate  * To enable further optimization, the "ul_schedctl_called" member
2007c478bd9Sstevel@tonic-gate  * of the ulwp_t structure (below) serves double-duty:
2017c478bd9Sstevel@tonic-gate  *	1. If NULL, it means that the thread must call __schedctl()
2027c478bd9Sstevel@tonic-gate  *	   to set up its schedctl mappings before acquiring a mutex.
2037c478bd9Sstevel@tonic-gate  *	   This is required by the implementation of adaptive mutex locking.
2047c478bd9Sstevel@tonic-gate  *	2. If non-NULL, it points to uberdata.uberflags, so that tests of
2057c478bd9Sstevel@tonic-gate  *	   uberflags can be made without additional memory references.
2067c478bd9Sstevel@tonic-gate  * This allows the common case of _mutex_lock() and _mutex_unlock() for
2077c478bd9Sstevel@tonic-gate  * USYNC_THREAD mutexes with no error detection and no lock statistics
2087c478bd9Sstevel@tonic-gate  * to be optimized for speed.
2097c478bd9Sstevel@tonic-gate  */
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate /* double the default stack size for 64-bit processes */
2127c478bd9Sstevel@tonic-gate #ifdef _LP64
2137c478bd9Sstevel@tonic-gate #define	MINSTACK	(8 * 1024)
2147c478bd9Sstevel@tonic-gate #define	DEFAULTSTACK	(2 * 1024 * 1024)
2157c478bd9Sstevel@tonic-gate #else
2167c478bd9Sstevel@tonic-gate #define	MINSTACK	(4 * 1024)
2177c478bd9Sstevel@tonic-gate #define	DEFAULTSTACK	(1024 * 1024)
2187c478bd9Sstevel@tonic-gate #endif
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate #define	MUTEX_TRY	0
2217c478bd9Sstevel@tonic-gate #define	MUTEX_LOCK	1
222d4204c85Sraf #define	MUTEX_NOCEIL	0x40
2237c478bd9Sstevel@tonic-gate 
2240ec57554Sraf #if defined(__x86)
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate typedef struct {	/* structure returned by fnstenv */
2277c478bd9Sstevel@tonic-gate 	int	fctrl;		/* control word */
2287c478bd9Sstevel@tonic-gate 	int	fstat;		/* status word (flags, etc) */
2297c478bd9Sstevel@tonic-gate 	int	ftag;		/* tag of which regs busy */
2307c478bd9Sstevel@tonic-gate 	int	misc[4];	/* other stuff, 28 bytes total */
2317c478bd9Sstevel@tonic-gate } fpuenv_t;
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
2347c478bd9Sstevel@tonic-gate typedef fpuenv_t fpuenv32_t;
2357c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate #elif defined(__sparc)
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate typedef struct {	/* fp state structure */
2407c478bd9Sstevel@tonic-gate 	greg_t	fsr;
2417c478bd9Sstevel@tonic-gate 	greg_t	fpu_en;
2427c478bd9Sstevel@tonic-gate } fpuenv_t;
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
2457c478bd9Sstevel@tonic-gate typedef struct {
2467c478bd9Sstevel@tonic-gate 	greg32_t	fsr;
2477c478bd9Sstevel@tonic-gate 	greg32_t	fpu_en;
2487c478bd9Sstevel@tonic-gate } fpuenv32_t;
2497c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
2507c478bd9Sstevel@tonic-gate 
2510ec57554Sraf #endif	/* __x86 */
2527c478bd9Sstevel@tonic-gate 
2530ec57554Sraf #if defined(__x86)
2547c478bd9Sstevel@tonic-gate extern	void	ht_pause(void);		/* "pause" instruction */
2557c478bd9Sstevel@tonic-gate #define	SMT_PAUSE()	ht_pause()
256b1593d50SJason Beloro #elif defined(SMT_PAUSE_FUNCTION)
257b1593d50SJason Beloro extern	void	SMT_PAUSE_FUNCTION(void);
258b1593d50SJason Beloro #define	SMT_PAUSE()	SMT_PAUSE_FUNCTION()
2597c478bd9Sstevel@tonic-gate #else
260e2c5185aSChristopher Kiick #define	SMT_PAUSE()	smt_pause()
2610ec57554Sraf #endif	/* __x86 */
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate /*
2647c478bd9Sstevel@tonic-gate  * Cleanup handler related data.
2657c478bd9Sstevel@tonic-gate  * This structure is exported as _cleanup_t in pthread.h.
2667c478bd9Sstevel@tonic-gate  * pthread.h exports only the size of this structure, so check
2677c478bd9Sstevel@tonic-gate  * _cleanup_t in pthread.h before making any change here.
2687c478bd9Sstevel@tonic-gate  */
2697c478bd9Sstevel@tonic-gate typedef struct __cleanup {
2707c478bd9Sstevel@tonic-gate 	struct __cleanup *next;		/* pointer to next handler */
2717c478bd9Sstevel@tonic-gate 	caddr_t	fp;			/* current frame pointer */
2727c478bd9Sstevel@tonic-gate 	void	(*func)(void *);	/* cleanup handler address */
2737c478bd9Sstevel@tonic-gate 	void	*arg;			/* handler's argument */
2747c478bd9Sstevel@tonic-gate } __cleanup_t;
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate /*
2777c478bd9Sstevel@tonic-gate  * Thread-Specific Data (TSD)
2787c478bd9Sstevel@tonic-gate  * TSD_NFAST includes the invalid key zero, so there
2797c478bd9Sstevel@tonic-gate  * are really only (TSD_NFAST - 1) fast key slots.
2807c478bd9Sstevel@tonic-gate  */
2817c478bd9Sstevel@tonic-gate typedef	void (*PFrV)(void *);
2827c478bd9Sstevel@tonic-gate #define	TSD_UNALLOCATED	((PFrV)1)
2837c478bd9Sstevel@tonic-gate #define	TSD_NFAST	9
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate /*
2867c478bd9Sstevel@tonic-gate  * The tsd union is designed to burn a little memory (9 words) to make
2877c478bd9Sstevel@tonic-gate  * lookups blindingly fast.  Note that tsd_nalloc could be placed at the
2887c478bd9Sstevel@tonic-gate  * end of the pad region to increase the likelihood that it falls on the
2897c478bd9Sstevel@tonic-gate  * same cache line as the data.
2907c478bd9Sstevel@tonic-gate  */
2917c478bd9Sstevel@tonic-gate typedef union tsd {
2927c478bd9Sstevel@tonic-gate 	uint_t tsd_nalloc;		/* Amount of allocated storage */
2937c478bd9Sstevel@tonic-gate 	void *tsd_pad[TSD_NFAST];
2947c478bd9Sstevel@tonic-gate 	void *tsd_data[1];
2957c478bd9Sstevel@tonic-gate } tsd_t;
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate typedef struct {
2987c478bd9Sstevel@tonic-gate 	mutex_t tsdm_lock;		/* Lock protecting the data */
2997c478bd9Sstevel@tonic-gate 	uint_t tsdm_nkeys;		/* Number of allocated keys */
3007c478bd9Sstevel@tonic-gate 	uint_t tsdm_nused;		/* Number of used keys */
3017c478bd9Sstevel@tonic-gate 	PFrV *tsdm_destro;		/* Per-key destructors */
3027c478bd9Sstevel@tonic-gate 	char tsdm_pad[64 -		/* pad to 64 bytes */
3037c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + 2 * sizeof (uint_t) + sizeof (PFrV *))];
3047c478bd9Sstevel@tonic-gate } tsd_metadata_t;
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
3077c478bd9Sstevel@tonic-gate typedef union tsd32 {
3087c478bd9Sstevel@tonic-gate 	uint_t tsd_nalloc;		/* Amount of allocated storage */
3097c478bd9Sstevel@tonic-gate 	caddr32_t tsd_pad[TSD_NFAST];
3107c478bd9Sstevel@tonic-gate 	caddr32_t tsd_data[1];
3117c478bd9Sstevel@tonic-gate } tsd32_t;
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate typedef struct {
3147c478bd9Sstevel@tonic-gate 	mutex_t tsdm_lock;		/* Lock protecting the data */
3157c478bd9Sstevel@tonic-gate 	uint_t tsdm_nkeys;		/* Number of allocated keys */
3167c478bd9Sstevel@tonic-gate 	uint_t tsdm_nused;		/* Number of used keys */
3177c478bd9Sstevel@tonic-gate 	caddr32_t tsdm_destro;		/* Per-key destructors */
3187c478bd9Sstevel@tonic-gate 	char tsdm_pad[64 -		/* pad to 64 bytes */
3197c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + 2 * sizeof (uint_t) + sizeof (caddr32_t))];
3207c478bd9Sstevel@tonic-gate } tsd_metadata32_t;
3217c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate /*
3257c478bd9Sstevel@tonic-gate  * Thread-Local Storage (TLS)
3267c478bd9Sstevel@tonic-gate  */
3277c478bd9Sstevel@tonic-gate typedef struct {
3287c478bd9Sstevel@tonic-gate 	void		*tls_data;
3297c478bd9Sstevel@tonic-gate 	size_t		tls_size;
3307c478bd9Sstevel@tonic-gate } tls_t;
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate typedef struct {
3337c478bd9Sstevel@tonic-gate 	mutex_t	tls_lock;		/* Lock protecting the data */
3347c478bd9Sstevel@tonic-gate 	tls_t	tls_modinfo;		/* Root of all TLS_modinfo data */
3357c478bd9Sstevel@tonic-gate 	tls_t	static_tls;		/* Template for static TLS */
3367c478bd9Sstevel@tonic-gate 	char	tls_pad[64 -		/* pad to 64 bytes */
3377c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + 2 * sizeof (tls_t))];
3387c478bd9Sstevel@tonic-gate } tls_metadata_t;
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
3417c478bd9Sstevel@tonic-gate typedef struct {
3427c478bd9Sstevel@tonic-gate 	caddr32_t	tls_data;
3437c478bd9Sstevel@tonic-gate 	size32_t	tls_size;
3447c478bd9Sstevel@tonic-gate } tls32_t;
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate typedef struct {
3477c478bd9Sstevel@tonic-gate 	mutex_t	tls_lock;		/* Lock protecting the data */
3487c478bd9Sstevel@tonic-gate 	tls32_t	tls_modinfo;		/* Root of all TLS_modinfo data */
3497c478bd9Sstevel@tonic-gate 	tls32_t	static_tls;		/* Template for static TLS */
3507c478bd9Sstevel@tonic-gate 	char	tls_pad[64 -		/* pad to 64 bytes */
3517c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + 2 * sizeof (tls32_t))];
3527c478bd9Sstevel@tonic-gate } tls_metadata32_t;
3537c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate /*
357d4204c85Sraf  * Sleep queue root for USYNC_THREAD condvars and mutexes.
358d4204c85Sraf  * There is a default queue root for each queue head (see below).
359d4204c85Sraf  * Also, each ulwp_t contains a queue root that can be used
360d4204c85Sraf  * when the thread is enqueued on the queue, if necessary
361d4204c85Sraf  * (when more than one wchan hashes to the same queue head).
362d4204c85Sraf  */
363d4204c85Sraf typedef struct queue_root {
364d4204c85Sraf 	struct queue_root	*qr_next;
365d4204c85Sraf 	struct queue_root	*qr_prev;
366d4204c85Sraf 	struct ulwp		*qr_head;
367d4204c85Sraf 	struct ulwp		*qr_tail;
368d4204c85Sraf 	void			*qr_wchan;
369d4204c85Sraf 	uint32_t		qr_rtcount;
370d4204c85Sraf 	uint32_t		qr_qlen;
371d4204c85Sraf 	uint32_t		qr_qmax;
372d4204c85Sraf } queue_root_t;
373d4204c85Sraf 
374d4204c85Sraf #ifdef _SYSCALL32
375d4204c85Sraf typedef struct queue_root32 {
376d4204c85Sraf 	caddr32_t		qr_next;
377d4204c85Sraf 	caddr32_t		qr_prev;
378d4204c85Sraf 	caddr32_t		qr_head;
379d4204c85Sraf 	caddr32_t		qr_tail;
380d4204c85Sraf 	caddr32_t		qr_wchan;
381d4204c85Sraf 	uint32_t		qr_rtcount;
382d4204c85Sraf 	uint32_t		qr_qlen;
383d4204c85Sraf 	uint32_t		qr_qmax;
384d4204c85Sraf } queue_root32_t;
385d4204c85Sraf #endif
386d4204c85Sraf 
387d4204c85Sraf /*
388d4204c85Sraf  * Sleep queue heads for USYNC_THREAD condvars and mutexes.
389d4204c85Sraf  * The size and alignment is 128 bytes to reduce cache conflicts.
390d4204c85Sraf  * Each queue head points to a list of queue roots, defined above.
391d4204c85Sraf  * Each queue head contains a default queue root for use when only one
392d4204c85Sraf  * is needed.  It is always at the tail of the queue root hash chain.
3937c478bd9Sstevel@tonic-gate  */
3947c478bd9Sstevel@tonic-gate typedef union {
395d4204c85Sraf 	uint64_t		qh_64[16];
3967c478bd9Sstevel@tonic-gate 	struct {
3977c478bd9Sstevel@tonic-gate 		mutex_t		q_lock;
3987c478bd9Sstevel@tonic-gate 		uint8_t		q_qcnt;
399d4204c85Sraf 		uint8_t		q_type;		/* MX or CV */
400d4204c85Sraf 		uint8_t		q_pad1[2];
401d4204c85Sraf 		uint32_t	q_lockcount;
4027c478bd9Sstevel@tonic-gate 		uint32_t	q_qlen;
4037c478bd9Sstevel@tonic-gate 		uint32_t	q_qmax;
404d4204c85Sraf 		void		*q_wchan;	/* valid only while locked */
405d4204c85Sraf 		struct queue_root *q_root;	/* valid only while locked */
406d4204c85Sraf 		struct queue_root *q_hlist;
407d4204c85Sraf #if !defined(_LP64)
408d4204c85Sraf 		caddr_t		q_pad2[3];
409d4204c85Sraf #endif
410d4204c85Sraf 		queue_root_t	q_def_root;
411d4204c85Sraf 		uint32_t	q_hlen;
412d4204c85Sraf 		uint32_t	q_hmax;
4137c478bd9Sstevel@tonic-gate 	} qh_qh;
4147c478bd9Sstevel@tonic-gate } queue_head_t;
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate #define	qh_lock		qh_qh.q_lock
4177c478bd9Sstevel@tonic-gate #define	qh_qcnt		qh_qh.q_qcnt
418d4204c85Sraf #define	qh_type		qh_qh.q_type
419d4204c85Sraf #if defined(THREAD_DEBUG)
4207c478bd9Sstevel@tonic-gate #define	qh_lockcount	qh_qh.q_lockcount
4217c478bd9Sstevel@tonic-gate #define	qh_qlen		qh_qh.q_qlen
4227c478bd9Sstevel@tonic-gate #define	qh_qmax		qh_qh.q_qmax
423d4204c85Sraf #endif
424d4204c85Sraf #define	qh_wchan	qh_qh.q_wchan
425d4204c85Sraf #define	qh_root		qh_qh.q_root
426d4204c85Sraf #define	qh_hlist	qh_qh.q_hlist
427d4204c85Sraf #define	qh_def_root	qh_qh.q_def_root
428d4204c85Sraf #define	qh_hlen		qh_qh.q_hlen
429d4204c85Sraf #define	qh_hmax		qh_qh.q_hmax
430d4204c85Sraf 
431d4204c85Sraf /* queue types passed to queue_lock() */
4327c478bd9Sstevel@tonic-gate #define	MX	0
4337c478bd9Sstevel@tonic-gate #define	CV	1
434883492d5Sraf #define	QHASHSHIFT	9			/* number of hashing bits */
435883492d5Sraf #define	QHASHSIZE	(1 << QHASHSHIFT)	/* power of 2 (1<<9 == 512) */
436883492d5Sraf #define	QUEUE_HASH(wchan, type)	((uint_t)			\
437883492d5Sraf 	((((uintptr_t)(wchan) >> 3)				\
438883492d5Sraf 	^ ((uintptr_t)(wchan) >> (QHASHSHIFT + 3)))		\
4397c478bd9Sstevel@tonic-gate 	& (QHASHSIZE - 1)) + (((type) == MX)? 0 : QHASHSIZE))
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate extern	queue_head_t	*queue_lock(void *, int);
4427c478bd9Sstevel@tonic-gate extern	void		queue_unlock(queue_head_t *);
443d4204c85Sraf extern	void		enqueue(queue_head_t *, struct ulwp *, int);
444d4204c85Sraf extern	struct ulwp	*dequeue(queue_head_t *, int *);
445d4204c85Sraf extern	struct ulwp	**queue_slot(queue_head_t *, struct ulwp **, int *);
446d4204c85Sraf extern	struct ulwp	*queue_waiter(queue_head_t *);
447d4204c85Sraf extern	int		dequeue_self(queue_head_t *);
448d4204c85Sraf extern	void		queue_unlink(queue_head_t *,
44941efec22Sraf 				struct ulwp **, struct ulwp *);
4507c478bd9Sstevel@tonic-gate extern	void		unsleep_self(void);
4517c478bd9Sstevel@tonic-gate extern	void		spin_lock_set(mutex_t *);
4527c478bd9Sstevel@tonic-gate extern	void		spin_lock_clear(mutex_t *);
4537c478bd9Sstevel@tonic-gate 
454d4204c85Sraf /*
455d4204c85Sraf  * Scheduling class information structure.
456d4204c85Sraf  */
457d4204c85Sraf typedef struct {
458d4204c85Sraf 	short		pcc_state;
459d4204c85Sraf 	short		pcc_policy;
460d4204c85Sraf 	pri_t		pcc_primin;
461d4204c85Sraf 	pri_t		pcc_primax;
462d4204c85Sraf 	pcinfo_t	pcc_info;
463d4204c85Sraf } pcclass_t;
464d4204c85Sraf 
4657c478bd9Sstevel@tonic-gate /*
4667c478bd9Sstevel@tonic-gate  * Memory block for chain of owned ceiling mutexes.
4677c478bd9Sstevel@tonic-gate  */
4687c478bd9Sstevel@tonic-gate typedef struct mxchain {
4697c478bd9Sstevel@tonic-gate 	struct mxchain	*mxchain_next;
4707c478bd9Sstevel@tonic-gate 	mutex_t		*mxchain_mx;
4717c478bd9Sstevel@tonic-gate } mxchain_t;
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate /*
4747c478bd9Sstevel@tonic-gate  * Pointer to an rwlock that is held for reading.
4757c478bd9Sstevel@tonic-gate  * Used in rw_rdlock() to allow a thread that already holds a read
4767c478bd9Sstevel@tonic-gate  * lock to acquire another read lock on the same rwlock even if
4777c478bd9Sstevel@tonic-gate  * there are writers waiting.  This to avoid deadlock when acquiring
4787c478bd9Sstevel@tonic-gate  * a read lock more than once in the presence of pending writers.
4797c478bd9Sstevel@tonic-gate  * POSIX mandates this behavior.
4807c478bd9Sstevel@tonic-gate  */
4817c478bd9Sstevel@tonic-gate typedef struct {
4827c478bd9Sstevel@tonic-gate 	void	*rd_rwlock;	/* the rwlock held for reading */
4837c478bd9Sstevel@tonic-gate 	size_t	rd_count;	/* count of read locks applied */
4847c478bd9Sstevel@tonic-gate } readlock_t;
4857c478bd9Sstevel@tonic-gate 
4867c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
4877c478bd9Sstevel@tonic-gate typedef struct {
4887c478bd9Sstevel@tonic-gate 	caddr32_t	rd_rwlock;
4897c478bd9Sstevel@tonic-gate 	size32_t	rd_count;
4907c478bd9Sstevel@tonic-gate } readlock32_t;
4917c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
4927c478bd9Sstevel@tonic-gate 
4934f364e7cSRobert Mustacchi /*
4944f364e7cSRobert Mustacchi  * As part of per-thread caching libumem (ptcumem), we add a small amount to the
4954f364e7cSRobert Mustacchi  * thread's uberdata to facilitate it. The tm_roots are the roots of linked
4964f364e7cSRobert Mustacchi  * lists which is used by libumem to chain together allocations. tm_size is used
4974f364e7cSRobert Mustacchi  * to track the total amount of data stored across those linked lists. For more
4984f364e7cSRobert Mustacchi  * information, see libumem's big theory statement.
4994f364e7cSRobert Mustacchi  */
5004f364e7cSRobert Mustacchi #define	NTMEMBASE	16
5014f364e7cSRobert Mustacchi 
5024f364e7cSRobert Mustacchi typedef struct {
5034f364e7cSRobert Mustacchi 	size_t		tm_size;
5044f364e7cSRobert Mustacchi 	void		*tm_roots[NTMEMBASE];
5054f364e7cSRobert Mustacchi } tumem_t;
5064f364e7cSRobert Mustacchi 
5074f364e7cSRobert Mustacchi #ifdef _SYSCALL32
5084f364e7cSRobert Mustacchi typedef struct {
5094f364e7cSRobert Mustacchi 	uint32_t	tm_size;
5104f364e7cSRobert Mustacchi 	caddr32_t	tm_roots[NTMEMBASE];
5114f364e7cSRobert Mustacchi } tumem32_t;
5124f364e7cSRobert Mustacchi #endif
5134f364e7cSRobert Mustacchi 
5144f364e7cSRobert Mustacchi typedef void (*tmem_func_t)(void *, int);
5154f364e7cSRobert Mustacchi 
5167c478bd9Sstevel@tonic-gate /*
5177c478bd9Sstevel@tonic-gate  * Maximum number of read locks allowed for one thread on one rwlock.
5187c478bd9Sstevel@tonic-gate  * This could be as large as INT_MAX, but the SUSV3 test suite would
5197c478bd9Sstevel@tonic-gate  * take an inordinately long time to complete.  This is big enough.
5207c478bd9Sstevel@tonic-gate  */
5217c478bd9Sstevel@tonic-gate #define	READ_LOCK_MAX	100000
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate #define	ul_tlsent	ul_tls.tls_data	/* array of pointers to dynamic TLS */
5247c478bd9Sstevel@tonic-gate #define	ul_ntlsent	ul_tls.tls_size	/* number of entries in ul_tlsent */
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate /*
5277c478bd9Sstevel@tonic-gate  * Round up an integral value to a multiple of 64
5287c478bd9Sstevel@tonic-gate  */
5297c478bd9Sstevel@tonic-gate #define	roundup64(x)	(-(-(x) & -64))
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate /*
5327c478bd9Sstevel@tonic-gate  * NOTE:  Whatever changes are made to ulwp_t must be
5337c478bd9Sstevel@tonic-gate  * reflected in $SRC/cmd/mdb/common/modules/libc/libc.c
5347c478bd9Sstevel@tonic-gate  *
5357c478bd9Sstevel@tonic-gate  * NOTE: ul_self *must* be the first member of ulwp_t on x86
5367c478bd9Sstevel@tonic-gate  * Low-level x86 code relies on this.
5377c478bd9Sstevel@tonic-gate  */
5387c478bd9Sstevel@tonic-gate typedef struct ulwp {
5397c478bd9Sstevel@tonic-gate 	/*
5407c478bd9Sstevel@tonic-gate 	 * These members always need to come first on sparc.
5417c478bd9Sstevel@tonic-gate 	 * For dtrace, a ulwp_t must be aligned on a 64-byte boundary.
5427c478bd9Sstevel@tonic-gate 	 */
5437c478bd9Sstevel@tonic-gate #if defined(__sparc)
5447c478bd9Sstevel@tonic-gate 	uint32_t	ul_dinstr;	/* scratch space for dtrace */
5457c478bd9Sstevel@tonic-gate 	uint32_t	ul_padsparc0[15];
5467c478bd9Sstevel@tonic-gate 	uint32_t	ul_dsave;	/* dtrace: save %g1, %g0, %sp */
5477c478bd9Sstevel@tonic-gate 	uint32_t	ul_drestore;	/* dtrace: restore %g0, %g0, %g0 */
5487c478bd9Sstevel@tonic-gate 	uint32_t	ul_dftret;	/* dtrace: return probe fasttrap */
5497c478bd9Sstevel@tonic-gate 	uint32_t	ul_dreturn;	/* dtrace: return %o0 */
5507c478bd9Sstevel@tonic-gate #endif
5517c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_self;	/* pointer to self */
5527c478bd9Sstevel@tonic-gate #if defined(__i386)
5537c478bd9Sstevel@tonic-gate 	uint8_t		ul_dinstr[40];	/* scratch space for dtrace */
5547c478bd9Sstevel@tonic-gate #elif defined(__amd64)
5557c478bd9Sstevel@tonic-gate 	uint8_t		ul_dinstr[56];	/* scratch space for dtrace */
5567c478bd9Sstevel@tonic-gate #endif
5577c478bd9Sstevel@tonic-gate 	struct uberdata *ul_uberdata;	/* uber (super-global) data */
5587c478bd9Sstevel@tonic-gate 	tls_t		ul_tls;		/* dynamic thread-local storage base */
5597c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_forw;	/* forw, back all_lwps list, */
5607c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_back;	/* protected by link_lock */
5617c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_next;	/* list to keep track of stacks */
5627c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_hash;	/* hash chain linked list */
5637c478bd9Sstevel@tonic-gate 	void		*ul_rval;	/* return value from thr_exit() */
5647c478bd9Sstevel@tonic-gate 	caddr_t		ul_stk;		/* mapping base of the stack */
5657c478bd9Sstevel@tonic-gate 	size_t		ul_mapsiz;	/* mapping size of the stack */
5667c478bd9Sstevel@tonic-gate 	size_t		ul_guardsize;	/* normally _lpagesize */
5677c478bd9Sstevel@tonic-gate 	uintptr_t	ul_stktop;	/* broken thr_stksegment() interface */
5687c478bd9Sstevel@tonic-gate 	size_t		ul_stksiz;	/* broken thr_stksegment() interface */
5697c478bd9Sstevel@tonic-gate 	stack_t		ul_ustack;	/* current stack boundaries */
5707c478bd9Sstevel@tonic-gate 	int		ul_ix;		/* hash index */
5717c478bd9Sstevel@tonic-gate 	lwpid_t		ul_lwpid;	/* thread id, aka the lwp id */
572d4204c85Sraf 	pri_t		ul_pri;		/* scheduling priority */
573d4204c85Sraf 	pri_t		ul_epri;	/* real-time ceiling priority */
5747c478bd9Sstevel@tonic-gate 	char		ul_policy;	/* scheduling policy */
575d4204c85Sraf 	char		ul_cid;		/* scheduling class id */
5767c478bd9Sstevel@tonic-gate 	union {
5777c478bd9Sstevel@tonic-gate 		struct {
5787c478bd9Sstevel@tonic-gate 			char	cursig;	/* deferred signal number */
5797c478bd9Sstevel@tonic-gate 			char	pleasestop; /* lwp requested to stop itself */
5807c478bd9Sstevel@tonic-gate 		} s;
5817c478bd9Sstevel@tonic-gate 		short	curplease;	/* for testing both at once */
5827c478bd9Sstevel@tonic-gate 	} ul_cp;
5837c478bd9Sstevel@tonic-gate 	char		ul_stop;	/* reason for stopping */
5847c478bd9Sstevel@tonic-gate 	char		ul_signalled;	/* this lwp was cond_signal()d */
5857c478bd9Sstevel@tonic-gate 	char		ul_dead;	/* this lwp has called thr_exit */
5867c478bd9Sstevel@tonic-gate 	char		ul_unwind;	/* posix: unwind C++ stack */
5877c478bd9Sstevel@tonic-gate 	char		ul_detached;	/* THR_DETACHED at thread_create() */
5887c478bd9Sstevel@tonic-gate 					/* or pthread_detach() was called */
5897c478bd9Sstevel@tonic-gate 	char		ul_writer;	/* sleeping in rw_wrlock() */
5907c478bd9Sstevel@tonic-gate 	char		ul_stopping;	/* set by curthread: stopping self */
59134709573Sraf 	char		ul_cancel_prologue;	/* for _cancel_prologue() */
5927c478bd9Sstevel@tonic-gate 	short		ul_preempt;	/* no_preempt()/preempt() */
5937c478bd9Sstevel@tonic-gate 	short		ul_savpreempt;	/* pre-existing preempt value */
5947c478bd9Sstevel@tonic-gate 	char		ul_sigsuspend;	/* thread is in sigsuspend/pollsys */
5957c478bd9Sstevel@tonic-gate 	char		ul_main;	/* thread is the main thread */
5967c478bd9Sstevel@tonic-gate 	char		ul_fork;	/* thread is performing a fork */
5977c478bd9Sstevel@tonic-gate 	char		ul_primarymap;	/* primary link-map is initialized */
5987c478bd9Sstevel@tonic-gate 	/* per-thread copies of the corresponding global variables */
5995d1dd9a9Sraf 	uint8_t		ul_max_spinners;	/* thread_max_spinners */
6007c478bd9Sstevel@tonic-gate 	char		ul_door_noreserve;	/* thread_door_noreserve */
6017c478bd9Sstevel@tonic-gate 	char		ul_queue_fifo;		/* thread_queue_fifo */
6027c478bd9Sstevel@tonic-gate 	char		ul_cond_wait_defer;	/* thread_cond_wait_defer */
6037c478bd9Sstevel@tonic-gate 	char		ul_error_detection;	/* thread_error_detection */
6047c478bd9Sstevel@tonic-gate 	char		ul_async_safe;		/* thread_async_safe */
605d4204c85Sraf 	char		ul_rt;			/* found on an RT queue */
606d4204c85Sraf 	char		ul_rtqueued;		/* was RT when queued */
6077c5714f6Sraf 	char		ul_misaligned;		/* thread_locks_misaligned */
6087c5714f6Sraf 	char		ul_pad[3];
6097c478bd9Sstevel@tonic-gate 	int		ul_adaptive_spin;	/* thread_adaptive_spin */
6107c478bd9Sstevel@tonic-gate 	int		ul_queue_spin;		/* thread_queue_spin */
6117c478bd9Sstevel@tonic-gate 	volatile int	ul_critical;	/* non-zero == in a critical region */
6127c478bd9Sstevel@tonic-gate 	int		ul_sigdefer;	/* non-zero == defer signals */
6137c478bd9Sstevel@tonic-gate 	int		ul_vfork;	/* thread is the child of vfork() */
6147c478bd9Sstevel@tonic-gate 	int		ul_cancelable;	/* _cancelon()/_canceloff() */
6157c478bd9Sstevel@tonic-gate 	char		ul_cancel_pending;  /* pthread_cancel() was called */
6167c478bd9Sstevel@tonic-gate 	char		ul_cancel_disabled; /* PTHREAD_CANCEL_DISABLE */
6177c478bd9Sstevel@tonic-gate 	char		ul_cancel_async;    /* PTHREAD_CANCEL_ASYNCHRONOUS */
6187c478bd9Sstevel@tonic-gate 	char		ul_save_async;	/* saved copy of ul_cancel_async */
6197c478bd9Sstevel@tonic-gate 	char		ul_mutator;	/* lwp is a mutator (java interface) */
6207c478bd9Sstevel@tonic-gate 	char		ul_created;	/* created suspended */
6217c478bd9Sstevel@tonic-gate 	char		ul_replace;	/* replacement; must be free()d */
6227c478bd9Sstevel@tonic-gate 	uchar_t		ul_nocancel;	/* cancellation can't happen */
6237c478bd9Sstevel@tonic-gate 	int		ul_errno;	/* per-thread errno */
6247c478bd9Sstevel@tonic-gate 	int		*ul_errnop;	/* pointer to errno or self->ul_errno */
6257c478bd9Sstevel@tonic-gate 	__cleanup_t	*ul_clnup_hdr;	/* head of cleanup handlers list */
626d4204c85Sraf 	uberflags_t	*ul_schedctl_called;	/* ul_schedctl is set up */
627d4204c85Sraf 	volatile sc_shared_t *ul_schedctl;	/* schedctl data */
6287c478bd9Sstevel@tonic-gate 	int		ul_bindflags;	/* bind_guard() interface to ld.so.1 */
629a574db85Sraf 	uint_t		ul_libc_locks;	/* count of cancel_safe_mutex_lock()s */
6307c478bd9Sstevel@tonic-gate 	tsd_t		*ul_stsd;	/* slow TLS for keys >= TSD_NFAST */
6317c478bd9Sstevel@tonic-gate 	void		*ul_ftsd[TSD_NFAST]; /* fast TLS for keys < TSD_NFAST */
6327c478bd9Sstevel@tonic-gate 	td_evbuf_t	ul_td_evbuf;	/* event buffer */
6337c478bd9Sstevel@tonic-gate 	char		ul_td_events_enable;	/* event mechanism enabled */
6347c478bd9Sstevel@tonic-gate 	char		ul_sync_obj_reg;	/* tdb_sync_obj_register() */
6357c478bd9Sstevel@tonic-gate 	char		ul_qtype;	/* MX or CV */
6367c478bd9Sstevel@tonic-gate 	char		ul_cv_wake;	/* != 0: just wake up, don't requeue */
637e54ab87fSRoger A. Faulkner 	int		ul_rtld;	/* thread is running inside ld.so.1 */
6387c478bd9Sstevel@tonic-gate 	int		ul_usropts;	/* flags given to thr_create() */
6397c478bd9Sstevel@tonic-gate 	void		*(*ul_startpc)(void *); /* start func (thr_create()) */
6407c478bd9Sstevel@tonic-gate 	void		*ul_startarg;	/* argument for start function */
6417c478bd9Sstevel@tonic-gate 	void		*ul_wchan;	/* synch object when sleeping */
6427c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_link;	/* sleep queue link */
6437c478bd9Sstevel@tonic-gate 	queue_head_t	*ul_sleepq;	/* sleep queue thread is waiting on */
6447c478bd9Sstevel@tonic-gate 	mutex_t		*ul_cvmutex;	/* mutex dropped when waiting on a cv */
6457c478bd9Sstevel@tonic-gate 	mxchain_t	*ul_mxchain;	/* chain of owned ceiling mutexes */
646d4204c85Sraf 	int		ul_save_state;	/* bind_guard() interface to ld.so.1 */
647883492d5Sraf 	uint_t		ul_rdlockcnt;	/* # entries in ul_readlock array */
648883492d5Sraf 				/* 0 means there is but a single entry */
649883492d5Sraf 	union {				/* single entry or pointer to array */
6507c478bd9Sstevel@tonic-gate 		readlock_t	single;
6517c478bd9Sstevel@tonic-gate 		readlock_t	*array;
6527c478bd9Sstevel@tonic-gate 	} ul_readlock;
653883492d5Sraf 	uint_t		ul_heldlockcnt;	/* # entries in ul_heldlocks array */
654883492d5Sraf 				/* 0 means there is but a single entry */
655883492d5Sraf 	union {				/* single entry or pointer to array */
656883492d5Sraf 		mutex_t		*single;
657883492d5Sraf 		mutex_t		**array;
658883492d5Sraf 	} ul_heldlocks;
6597c478bd9Sstevel@tonic-gate 	/* PROBE_SUPPORT begin */
6607c478bd9Sstevel@tonic-gate 	void		*ul_tpdp;
6617c478bd9Sstevel@tonic-gate 	/* PROBE_SUPPORT end */
6627c478bd9Sstevel@tonic-gate 	ucontext_t	*ul_siglink;	/* pointer to previous context */
6637c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_spin;	/* spin lock statistics */
6647c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_spin2;
6657c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_sleep;
6667c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_wakeup;
667d4204c85Sraf 	queue_root_t	ul_queue_root;	/* root of a sleep queue */
668d4204c85Sraf 	id_t		ul_rtclassid;	/* real-time class id */
669d4204c85Sraf 	uint_t		ul_pilocks;	/* count of PI locks held */
6707c478bd9Sstevel@tonic-gate 		/* the following members *must* be last in the structure */
6717c478bd9Sstevel@tonic-gate 		/* they are discarded when ulwp is replaced on thr_exit() */
6727c478bd9Sstevel@tonic-gate 	sigset_t	ul_sigmask;	/* thread's current signal mask */
6737c478bd9Sstevel@tonic-gate 	sigset_t	ul_tmpmask;	/* signal mask for sigsuspend/pollsys */
6747c478bd9Sstevel@tonic-gate 	siginfo_t	ul_siginfo;	/* deferred siginfo */
6757c478bd9Sstevel@tonic-gate 	mutex_t		ul_spinlock;	/* used when suspending/continuing */
6767c478bd9Sstevel@tonic-gate 	fpuenv_t	ul_fpuenv;	/* floating point state */
6777c478bd9Sstevel@tonic-gate 	uintptr_t	ul_sp;		/* stack pointer when blocked */
6787c478bd9Sstevel@tonic-gate 	void		*ul_ex_unwind;	/* address of _ex_unwind() or -1 */
6797c478bd9Sstevel@tonic-gate #if defined(sparc)
6807c478bd9Sstevel@tonic-gate 	void		*ul_unwind_ret;	/* used only by _ex_clnup_handler() */
6817c478bd9Sstevel@tonic-gate #endif
6824f364e7cSRobert Mustacchi 	tumem_t		ul_tmem;	/* used only by umem */
6837c478bd9Sstevel@tonic-gate } ulwp_t;
6847c478bd9Sstevel@tonic-gate 
6857c478bd9Sstevel@tonic-gate #define	ul_cursig	ul_cp.s.cursig		/* deferred signal number */
6867c478bd9Sstevel@tonic-gate #define	ul_pleasestop	ul_cp.s.pleasestop	/* lwp requested to stop */
6877c478bd9Sstevel@tonic-gate #define	ul_curplease	ul_cp.curplease		/* for testing both at once */
6887c478bd9Sstevel@tonic-gate 
6897c478bd9Sstevel@tonic-gate /*
6907c478bd9Sstevel@tonic-gate  * This is the size of a replacement ulwp, retained only for the benefit
6917c478bd9Sstevel@tonic-gate  * of thr_join().  The trailing members are unneeded for this purpose.
6927c478bd9Sstevel@tonic-gate  */
6937c478bd9Sstevel@tonic-gate #define	REPLACEMENT_SIZE	((size_t)&((ulwp_t *)NULL)->ul_sigmask)
6947c478bd9Sstevel@tonic-gate 
6957c478bd9Sstevel@tonic-gate /*
6967c478bd9Sstevel@tonic-gate  * Definitions for static initialization of signal sets,
6977c478bd9Sstevel@tonic-gate  * plus some sneaky optimizations in various places.
6987c478bd9Sstevel@tonic-gate  */
6997c478bd9Sstevel@tonic-gate 
7007c478bd9Sstevel@tonic-gate #define	SIGMASK(sig)	((uint32_t)1 << (((sig) - 1) & (32 - 1)))
7017c478bd9Sstevel@tonic-gate 
702bdf0047cSRoger A. Faulkner #if (MAXSIG > (2 * 32) && MAXSIG <= (3 * 32))
7037c478bd9Sstevel@tonic-gate #define	FILLSET0	0xffffffffu
704bdf0047cSRoger A. Faulkner #define	FILLSET1	0xffffffffu
705bdf0047cSRoger A. Faulkner #define	FILLSET2	((1u << (MAXSIG - 64)) - 1)
706bdf0047cSRoger A. Faulkner #define	FILLSET3	0
7077c478bd9Sstevel@tonic-gate #else
7087c478bd9Sstevel@tonic-gate #error "fix me: MAXSIG out of bounds"
7097c478bd9Sstevel@tonic-gate #endif
7107c478bd9Sstevel@tonic-gate 
7117c478bd9Sstevel@tonic-gate #define	CANTMASK0	(SIGMASK(SIGKILL) | SIGMASK(SIGSTOP))
7127c478bd9Sstevel@tonic-gate #define	CANTMASK1	0
713bdf0047cSRoger A. Faulkner #define	CANTMASK2	0
714bdf0047cSRoger A. Faulkner #define	CANTMASK3	0
7157c478bd9Sstevel@tonic-gate 
7167c478bd9Sstevel@tonic-gate #define	MASKSET0	(FILLSET0 & ~CANTMASK0)
7177c478bd9Sstevel@tonic-gate #define	MASKSET1	(FILLSET1 & ~CANTMASK1)
718bdf0047cSRoger A. Faulkner #define	MASKSET2	(FILLSET2 & ~CANTMASK2)
719bdf0047cSRoger A. Faulkner #define	MASKSET3	(FILLSET3 & ~CANTMASK3)
7207c478bd9Sstevel@tonic-gate 
721f841f6adSraf extern	const sigset_t maskset;		/* set of all maskable signals */
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate extern	int	thread_adaptive_spin;
7247c478bd9Sstevel@tonic-gate extern	uint_t	thread_max_spinners;
7257c478bd9Sstevel@tonic-gate extern	int	thread_queue_spin;
7267c478bd9Sstevel@tonic-gate extern	int	thread_queue_fifo;
7277c478bd9Sstevel@tonic-gate extern	int	thread_queue_dump;
7287c478bd9Sstevel@tonic-gate extern	int	thread_cond_wait_defer;
7297c478bd9Sstevel@tonic-gate extern	int	thread_async_safe;
7307c478bd9Sstevel@tonic-gate extern	int	thread_queue_verify;
7317c478bd9Sstevel@tonic-gate 
7327c478bd9Sstevel@tonic-gate /*
7337c478bd9Sstevel@tonic-gate  * pthread_atfork() related data, used to store atfork handlers.
7347c478bd9Sstevel@tonic-gate  */
7357c478bd9Sstevel@tonic-gate typedef struct atfork {
7367c478bd9Sstevel@tonic-gate 	struct atfork *forw;		/* forward pointer */
7377c478bd9Sstevel@tonic-gate 	struct atfork *back;		/* backward pointer */
7387c478bd9Sstevel@tonic-gate 	void (*prepare)(void);		/* pre-fork handler */
7397c478bd9Sstevel@tonic-gate 	void (*parent)(void);		/* post-fork parent handler */
7407c478bd9Sstevel@tonic-gate 	void (*child)(void);		/* post-fork child handler */
7417c478bd9Sstevel@tonic-gate } atfork_t;
7427c478bd9Sstevel@tonic-gate 
743883492d5Sraf /*
74409ce0d4aSRoger A. Faulkner  * Element in the table and in the list of registered process
74509ce0d4aSRoger A. Faulkner  * robust locks.  We keep track of these to make sure that we
74609ce0d4aSRoger A. Faulkner  * only call ___lwp_mutex_register() once for each such lock
74709ce0d4aSRoger A. Faulkner  * after it is first mapped in (or newly mapped in).
748883492d5Sraf  */
749883492d5Sraf typedef struct robust {
75009ce0d4aSRoger A. Faulkner 	struct robust	*robust_next;	/* hash table list */
75109ce0d4aSRoger A. Faulkner 	struct robust	*robust_list;	/* global list */
752883492d5Sraf 	mutex_t		*robust_lock;
753883492d5Sraf } robust_t;
754883492d5Sraf 
75509ce0d4aSRoger A. Faulkner /*
75609ce0d4aSRoger A. Faulkner  * Invalid address, used to mark an unused element in the hash table.
75709ce0d4aSRoger A. Faulkner  */
75809ce0d4aSRoger A. Faulkner #define	INVALID_ADDR	((void *)(uintptr_t)(-1L))
75909ce0d4aSRoger A. Faulkner 
760883492d5Sraf /*
761883492d5Sraf  * Parameters of the lock registration hash table.
762883492d5Sraf  */
763daa03c95Sraf #define	LOCKSHIFT	15			/* number of hashing bits */
764daa03c95Sraf #define	LOCKHASHSZ	(1 << LOCKSHIFT)	/* power of 2 (1<<15 == 32K) */
765883492d5Sraf #define	LOCK_HASH(addr)	(uint_t)			\
766883492d5Sraf 	((((uintptr_t)(addr) >> 3)			\
767883492d5Sraf 	^ ((uintptr_t)(addr) >> (LOCKSHIFT + 3)))	\
768883492d5Sraf 	& (LOCKHASHSZ - 1))
769883492d5Sraf 
7707c478bd9Sstevel@tonic-gate /*
7717c478bd9Sstevel@tonic-gate  * Make our hot locks reside on private cache lines (64 bytes).
7727c478bd9Sstevel@tonic-gate  */
7737c478bd9Sstevel@tonic-gate typedef struct {
7747c478bd9Sstevel@tonic-gate 	mutex_t	pad_lock;
7752e145884Sraf 	char	pad_pad[64 - sizeof (mutex_t)];
7767c478bd9Sstevel@tonic-gate } pad_lock_t;
7777c478bd9Sstevel@tonic-gate 
7782e145884Sraf /*
7792e145884Sraf  * Make our semi-hot locks reside on semi-private cache lines (32 bytes).
7802e145884Sraf  */
7812e145884Sraf typedef struct {
7822e145884Sraf 	mutex_t	pad_lock;
7832e145884Sraf 	char	pad_pad[32 - sizeof (mutex_t)];
7842e145884Sraf } pad32_lock_t;
7852e145884Sraf 
7867c478bd9Sstevel@tonic-gate /*
7877c478bd9Sstevel@tonic-gate  * The threads hash table is used for fast lookup and locking of an active
7887c478bd9Sstevel@tonic-gate  * thread structure (ulwp_t) given a thread-id.  It is an N-element array of
7897c478bd9Sstevel@tonic-gate  * thr_hash_table_t structures, where N == 1 before the main thread creates
7907c478bd9Sstevel@tonic-gate  * the first additional thread and N == 1024 afterwards.  Each element of the
7917c478bd9Sstevel@tonic-gate  * table is 64 bytes in size and alignment to reduce cache conflicts.
7927c478bd9Sstevel@tonic-gate  */
7937c478bd9Sstevel@tonic-gate typedef struct {
7947c478bd9Sstevel@tonic-gate 	mutex_t	hash_lock;	/* lock per bucket */
7957c478bd9Sstevel@tonic-gate 	cond_t	hash_cond;	/* convar per bucket */
7967c478bd9Sstevel@tonic-gate 	ulwp_t	*hash_bucket;	/* hash bucket points to the list of ulwps */
7977c478bd9Sstevel@tonic-gate 	char	hash_pad[64 -	/* pad out to 64 bytes */
7987c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (cond_t) + sizeof (ulwp_t *))];
7997c478bd9Sstevel@tonic-gate } thr_hash_table_t;
8007c478bd9Sstevel@tonic-gate 
8017c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
8027c478bd9Sstevel@tonic-gate typedef struct {
8037c478bd9Sstevel@tonic-gate 	mutex_t	hash_lock;
8047c478bd9Sstevel@tonic-gate 	cond_t	hash_cond;
8057c478bd9Sstevel@tonic-gate 	caddr32_t hash_bucket;
8067c478bd9Sstevel@tonic-gate 	char	hash_pad[64 -
8077c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (cond_t) + sizeof (caddr32_t))];
8087c478bd9Sstevel@tonic-gate } thr_hash_table32_t;
8097c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate 
8127c478bd9Sstevel@tonic-gate /*
81341efec22Sraf  * siguaction members have 128-byte size and 64-byte alignment.
81441efec22Sraf  * We know that sizeof (struct sigaction) is 32 bytes for both
81541efec22Sraf  * _ILP32 and _LP64 and that sizeof (rwlock_t) is 64 bytes.
8167c478bd9Sstevel@tonic-gate  */
8177c478bd9Sstevel@tonic-gate typedef struct {
81841efec22Sraf 	rwlock_t	sig_lock;
8197c478bd9Sstevel@tonic-gate 	struct sigaction sig_uaction;
82041efec22Sraf 	char	sig_pad[128 - sizeof (rwlock_t) - sizeof (struct sigaction)];
8217c478bd9Sstevel@tonic-gate } siguaction_t;
8227c478bd9Sstevel@tonic-gate 
8237c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
8247c478bd9Sstevel@tonic-gate typedef struct {
82541efec22Sraf 	rwlock_t	sig_lock;
8267c478bd9Sstevel@tonic-gate 	struct sigaction32 sig_uaction;
82741efec22Sraf 	char	sig_pad[128 - sizeof (rwlock_t) - sizeof (struct sigaction32)];
8287c478bd9Sstevel@tonic-gate } siguaction32_t;
8297c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
8307c478bd9Sstevel@tonic-gate 
8317c478bd9Sstevel@tonic-gate 
8327c478bd9Sstevel@tonic-gate /*
8337c478bd9Sstevel@tonic-gate  * Bucket structures, used by lmalloc()/lfree().
8347c478bd9Sstevel@tonic-gate  * See port/threads/alloc.c for details.
8357c478bd9Sstevel@tonic-gate  * A bucket's size and alignment is 64 bytes.
8367c478bd9Sstevel@tonic-gate  */
8377c478bd9Sstevel@tonic-gate typedef struct {
8387c478bd9Sstevel@tonic-gate 	mutex_t	bucket_lock;	/* protects the free list allocations */
8397c478bd9Sstevel@tonic-gate 	void	*free_list;	/* LIFO list of blocks to allocate/free */
8407c478bd9Sstevel@tonic-gate 	size_t	chunks;		/* number of 64K blocks mmap()ed last time */
8417c478bd9Sstevel@tonic-gate 	char	pad64[64 -	/* pad out to 64 bytes */
8427c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (void *) + sizeof (size_t))];
8437c478bd9Sstevel@tonic-gate } bucket_t;
8447c478bd9Sstevel@tonic-gate 
8457c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
8467c478bd9Sstevel@tonic-gate typedef struct {
8477c478bd9Sstevel@tonic-gate 	mutex_t		bucket_lock;
8487c478bd9Sstevel@tonic-gate 	caddr32_t	free_list;
8497c478bd9Sstevel@tonic-gate 	size32_t	chunks;
8507c478bd9Sstevel@tonic-gate 	char	pad64[64 -	/* pad out to 64 bytes */
8517c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (caddr32_t) + sizeof (size32_t))];
8527c478bd9Sstevel@tonic-gate } bucket32_t;
8537c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
8547c478bd9Sstevel@tonic-gate 
8557c478bd9Sstevel@tonic-gate #define	NBUCKETS	10	/* sizes ranging from 64 to 32768 */
8567c478bd9Sstevel@tonic-gate 
8577c478bd9Sstevel@tonic-gate 
8587c478bd9Sstevel@tonic-gate /*
8597c478bd9Sstevel@tonic-gate  * atexit() data structures.
8607c478bd9Sstevel@tonic-gate  * See port/gen/atexit.c for details.
8617c478bd9Sstevel@tonic-gate  */
8625c069a6cSRichard Lowe typedef void (*_exithdlr_func_t) (void*);
8637c478bd9Sstevel@tonic-gate 
8647c478bd9Sstevel@tonic-gate typedef struct _exthdlr {
8657c478bd9Sstevel@tonic-gate 	struct _exthdlr 	*next;	/* next in handler list */
8667c478bd9Sstevel@tonic-gate 	_exithdlr_func_t	hdlr;	/* handler itself */
8675c069a6cSRichard Lowe 	void			*arg;	/* argument to handler */
8685c069a6cSRichard Lowe 	void			*dso;	/* DSO associated with handler */
8697c478bd9Sstevel@tonic-gate } _exthdlr_t;
8707c478bd9Sstevel@tonic-gate 
8717c478bd9Sstevel@tonic-gate typedef struct {
8727c478bd9Sstevel@tonic-gate 	mutex_t		exitfns_lock;
8737c478bd9Sstevel@tonic-gate 	_exthdlr_t	*head;
8745c069a6cSRichard Lowe 	/*
8755c069a6cSRichard Lowe 	 * exit_frame_monitor is part of a private contract between libc and
8765c069a6cSRichard Lowe 	 * the Sun C++ runtime.
8775c069a6cSRichard Lowe 	 *
8785c069a6cSRichard Lowe 	 * It should be NULL until exit() is called, and thereafter hold the
8795c069a6cSRichard Lowe 	 * frame pointer of the function implementing our exit processing.
8805c069a6cSRichard Lowe 	 */
8817c478bd9Sstevel@tonic-gate 	void		*exit_frame_monitor;
8827c478bd9Sstevel@tonic-gate 	char		exit_pad[64 -	/* pad out to 64 bytes */
8837c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (_exthdlr_t *) + sizeof (void *))];
8847c478bd9Sstevel@tonic-gate } atexit_root_t;
8857c478bd9Sstevel@tonic-gate 
8867c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
8877c478bd9Sstevel@tonic-gate typedef struct {
8887c478bd9Sstevel@tonic-gate 	mutex_t		exitfns_lock;
8897c478bd9Sstevel@tonic-gate 	caddr32_t	head;
8907c478bd9Sstevel@tonic-gate 	caddr32_t	exit_frame_monitor;
8917c478bd9Sstevel@tonic-gate 	char		exit_pad[64 -	/* pad out to 64 bytes */
8927c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (caddr32_t) + sizeof (caddr32_t))];
8937c478bd9Sstevel@tonic-gate } atexit_root32_t;
8947c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
8957c478bd9Sstevel@tonic-gate 
896*fc2512cfSRobert Mustacchi /*
897*fc2512cfSRobert Mustacchi  * at_quick_exit() and quick_exit() data structures. The ISO/IEC C11 odd
898*fc2512cfSRobert Mustacchi  * siblings of atexit()
899*fc2512cfSRobert Mustacchi  */
900*fc2512cfSRobert Mustacchi typedef void (*_quick_exithdlr_func_t)(void);
901*fc2512cfSRobert Mustacchi 
902*fc2512cfSRobert Mustacchi typedef struct _qexthdlr {
903*fc2512cfSRobert Mustacchi 	struct _qexthdlr 	*next;	/* next in handler list */
904*fc2512cfSRobert Mustacchi 	_quick_exithdlr_func_t	hdlr;	/* handler itself */
905*fc2512cfSRobert Mustacchi } _qexthdlr_t;
906*fc2512cfSRobert Mustacchi 
907*fc2512cfSRobert Mustacchi typedef struct {
908*fc2512cfSRobert Mustacchi 	mutex_t		exitfns_lock;
909*fc2512cfSRobert Mustacchi 	_qexthdlr_t	*head;
910*fc2512cfSRobert Mustacchi } quickexit_root_t;
911*fc2512cfSRobert Mustacchi 
912*fc2512cfSRobert Mustacchi #ifdef _SYSCALL32
913*fc2512cfSRobert Mustacchi typedef struct {
914*fc2512cfSRobert Mustacchi 	mutex_t		exitfns_lock;
915*fc2512cfSRobert Mustacchi 	caddr32_t	head;
916*fc2512cfSRobert Mustacchi } quickexit_root32_t;
917*fc2512cfSRobert Mustacchi #endif /* _SYSCALL32 */
9187c478bd9Sstevel@tonic-gate 
9197c478bd9Sstevel@tonic-gate /*
9207c478bd9Sstevel@tonic-gate  * This is data that is global to all link maps (uberdata, aka super-global).
921fe4be5acSGordon Ross  * Note: When changing this, please be sure to keep the 32-bit variant of
922fe4be5acSGordon Ross  * this in sync.  (see uberdata32_t below)
9237c478bd9Sstevel@tonic-gate  */
9247c478bd9Sstevel@tonic-gate typedef struct uberdata {
9257c478bd9Sstevel@tonic-gate 	pad_lock_t	_link_lock;
9268cd45542Sraf 	pad_lock_t	_ld_lock;
9278cd45542Sraf 	pad_lock_t	_fork_lock;
9288cd45542Sraf 	pad_lock_t	_atfork_lock;
92998c1a6b4Sraf 	pad32_lock_t	_callout_lock;
93098c1a6b4Sraf 	pad32_lock_t	_tdb_hash_lock;
9317c478bd9Sstevel@tonic-gate 	tdb_sync_stats_t tdb_hash_lock_stats;
9327c478bd9Sstevel@tonic-gate 	siguaction_t	siguaction[NSIG];
9337c478bd9Sstevel@tonic-gate 	bucket_t	bucket[NBUCKETS];
9347c478bd9Sstevel@tonic-gate 	atexit_root_t	atexit_root;
935*fc2512cfSRobert Mustacchi 	quickexit_root_t quickexit_root;
9367c478bd9Sstevel@tonic-gate 	tsd_metadata_t	tsd_metadata;
9377c478bd9Sstevel@tonic-gate 	tls_metadata_t	tls_metadata;
9387c478bd9Sstevel@tonic-gate 	/*
9397c478bd9Sstevel@tonic-gate 	 * Every object before this point has size and alignment of 64 bytes.
9407c478bd9Sstevel@tonic-gate 	 * Don't add any other type of data before this point.
9417c478bd9Sstevel@tonic-gate 	 */
9427c478bd9Sstevel@tonic-gate 	char	primary_map;	/* set when primary link map is initialized */
9437c478bd9Sstevel@tonic-gate 	char	bucket_init;	/* set when bucket[NBUCKETS] is initialized */
9447c478bd9Sstevel@tonic-gate 	char	pad[2];
9457c478bd9Sstevel@tonic-gate 	uberflags_t	uberflags;
9467c478bd9Sstevel@tonic-gate 	queue_head_t	*queue_head;
9477c478bd9Sstevel@tonic-gate 	thr_hash_table_t *thr_hash_table;
9487c478bd9Sstevel@tonic-gate 	uint_t		hash_size;	/* # of entries in thr_hash_table[] */
9497c478bd9Sstevel@tonic-gate 	uint_t		hash_mask;	/* hash_size - 1 */
9507c478bd9Sstevel@tonic-gate 	ulwp_t	*ulwp_one;	/* main thread */
9517c478bd9Sstevel@tonic-gate 	ulwp_t	*all_lwps;	/* circular ul_forw/ul_back list of live lwps */
9527c478bd9Sstevel@tonic-gate 	ulwp_t	*all_zombies;	/* circular ul_forw/ul_back list of zombies */
9537c478bd9Sstevel@tonic-gate 	int	nthreads;	/* total number of live threads/lwps */
9547c478bd9Sstevel@tonic-gate 	int	nzombies;	/* total number of zombie threads */
9557c478bd9Sstevel@tonic-gate 	int	ndaemons;	/* total number of THR_DAEMON threads/lwps */
9567c478bd9Sstevel@tonic-gate 	pid_t	pid;		/* the current process's pid */
9577c478bd9Sstevel@tonic-gate 	void	(*sigacthandler)(int, siginfo_t *, void *);
9587c478bd9Sstevel@tonic-gate 	ulwp_t	*lwp_stacks;
9597c478bd9Sstevel@tonic-gate 	ulwp_t	*lwp_laststack;
9607c478bd9Sstevel@tonic-gate 	int	nfreestack;
9617c478bd9Sstevel@tonic-gate 	int	thread_stack_cache;
9627c478bd9Sstevel@tonic-gate 	ulwp_t	*ulwp_freelist;
9637c478bd9Sstevel@tonic-gate 	ulwp_t	*ulwp_lastfree;
9647c478bd9Sstevel@tonic-gate 	ulwp_t	*ulwp_replace_free;
9657c478bd9Sstevel@tonic-gate 	ulwp_t	*ulwp_replace_last;
9667c478bd9Sstevel@tonic-gate 	atfork_t	*atforklist;	/* circular Q for fork handlers */
967883492d5Sraf 	robust_t	**robustlocks;	/* table of registered robust locks */
96809ce0d4aSRoger A. Faulkner 	robust_t	*robustlist;	/* list of registered robust locks */
96923a1cceaSRoger A. Faulkner 	char	*progname;	/* the basename of the program, from argv[0] */
9707c478bd9Sstevel@tonic-gate 	struct uberdata **tdb_bootstrap;
9717c478bd9Sstevel@tonic-gate 	tdb_t	tdb;		/* thread debug interfaces (for libc_db) */
9727c478bd9Sstevel@tonic-gate } uberdata_t;
9737c478bd9Sstevel@tonic-gate 
9747c478bd9Sstevel@tonic-gate #define	link_lock	_link_lock.pad_lock
9758cd45542Sraf #define	ld_lock		_ld_lock.pad_lock
9767c478bd9Sstevel@tonic-gate #define	fork_lock	_fork_lock.pad_lock
9772e145884Sraf #define	atfork_lock	_atfork_lock.pad_lock
97898c1a6b4Sraf #define	callout_lock	_callout_lock.pad_lock
9797c478bd9Sstevel@tonic-gate #define	tdb_hash_lock	_tdb_hash_lock.pad_lock
9807c478bd9Sstevel@tonic-gate 
9817c478bd9Sstevel@tonic-gate #pragma align 64(__uberdata)
9827c478bd9Sstevel@tonic-gate extern	uberdata_t	__uberdata;
9837c478bd9Sstevel@tonic-gate extern	uberdata_t	**__tdb_bootstrap;	/* known to libc_db and mdb */
9847c478bd9Sstevel@tonic-gate extern	int		primary_link_map;
9857c478bd9Sstevel@tonic-gate 
9867c478bd9Sstevel@tonic-gate #define	ulwp_mutex(ulwp, udp)	\
9877c478bd9Sstevel@tonic-gate 	(&(udp)->thr_hash_table[(ulwp)->ul_ix].hash_lock)
9887c478bd9Sstevel@tonic-gate #define	ulwp_condvar(ulwp, udp)	\
9897c478bd9Sstevel@tonic-gate 	(&(udp)->thr_hash_table[(ulwp)->ul_ix].hash_cond)
9907c478bd9Sstevel@tonic-gate 
9917c478bd9Sstevel@tonic-gate /*
9927c478bd9Sstevel@tonic-gate  * Grab and release the hash table lock for the specified lwp.
9937c478bd9Sstevel@tonic-gate  */
9947c478bd9Sstevel@tonic-gate #define	ulwp_lock(ulwp, udp)	lmutex_lock(ulwp_mutex(ulwp, udp))
9957c478bd9Sstevel@tonic-gate #define	ulwp_unlock(ulwp, udp)	lmutex_unlock(ulwp_mutex(ulwp, udp))
9967c478bd9Sstevel@tonic-gate 
9977c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32	/* needed by libc_db */
9987c478bd9Sstevel@tonic-gate 
9997c478bd9Sstevel@tonic-gate typedef struct ulwp32 {
10007c478bd9Sstevel@tonic-gate #if defined(__sparc)
10017c478bd9Sstevel@tonic-gate 	uint32_t	ul_dinstr;	/* scratch space for dtrace */
10027c478bd9Sstevel@tonic-gate 	uint32_t	ul_padsparc0[15];
10037c478bd9Sstevel@tonic-gate 	uint32_t	ul_dsave;	/* dtrace: save %g1, %g0, %sp */
10047c478bd9Sstevel@tonic-gate 	uint32_t	ul_drestore;	/* dtrace: restore %g0, %g0, %g0 */
10057c478bd9Sstevel@tonic-gate 	uint32_t	ul_dftret;	/* dtrace: return probe fasttrap */
10067c478bd9Sstevel@tonic-gate 	uint32_t	ul_dreturn;	/* dtrace: return %o0 */
10077c478bd9Sstevel@tonic-gate #endif
10087c478bd9Sstevel@tonic-gate 	caddr32_t	ul_self;	/* pointer to self */
10090ec57554Sraf #if defined(__x86)
10107c478bd9Sstevel@tonic-gate 	uint8_t		ul_dinstr[40];	/* scratch space for dtrace */
10117c478bd9Sstevel@tonic-gate #endif
10127c478bd9Sstevel@tonic-gate 	caddr32_t	ul_uberdata;	/* uber (super-global) data */
10137c478bd9Sstevel@tonic-gate 	tls32_t		ul_tls;		/* dynamic thread-local storage base */
10147c478bd9Sstevel@tonic-gate 	caddr32_t	ul_forw;	/* forw, back all_lwps list, */
10157c478bd9Sstevel@tonic-gate 	caddr32_t	ul_back;	/* protected by link_lock */
10167c478bd9Sstevel@tonic-gate 	caddr32_t	ul_next;	/* list to keep track of stacks */
10177c478bd9Sstevel@tonic-gate 	caddr32_t	ul_hash;	/* hash chain linked list */
10187c478bd9Sstevel@tonic-gate 	caddr32_t	ul_rval;	/* return value from thr_exit() */
10197c478bd9Sstevel@tonic-gate 	caddr32_t	ul_stk;		/* mapping base of the stack */
10207c478bd9Sstevel@tonic-gate 	size32_t	ul_mapsiz;	/* mapping size of the stack */
10217c478bd9Sstevel@tonic-gate 	size32_t	ul_guardsize;	/* normally _lpagesize */
10227c478bd9Sstevel@tonic-gate 	caddr32_t	ul_stktop;	/* broken thr_stksegment() interface */
10237c478bd9Sstevel@tonic-gate 	size32_t	ul_stksiz;	/* broken thr_stksegment() interface */
10247c478bd9Sstevel@tonic-gate 	stack32_t	ul_ustack;	/* current stack boundaries */
10257c478bd9Sstevel@tonic-gate 	int		ul_ix;		/* hash index */
10267c478bd9Sstevel@tonic-gate 	lwpid_t		ul_lwpid;	/* thread id, aka the lwp id */
1027d4204c85Sraf 	pri_t		ul_pri;		/* scheduling priority */
1028d4204c85Sraf 	pri_t		ul_epri;	/* real-time ceiling priority */
10297c478bd9Sstevel@tonic-gate 	char		ul_policy;	/* scheduling policy */
1030d4204c85Sraf 	char		ul_cid;		/* scheduling class id */
10317c478bd9Sstevel@tonic-gate 	union {
10327c478bd9Sstevel@tonic-gate 		struct {
10337c478bd9Sstevel@tonic-gate 			char	cursig;	/* deferred signal number */
10347c478bd9Sstevel@tonic-gate 			char	pleasestop; /* lwp requested to stop itself */
10357c478bd9Sstevel@tonic-gate 		} s;
10367c478bd9Sstevel@tonic-gate 		short	curplease;	/* for testing both at once */
10377c478bd9Sstevel@tonic-gate 	} ul_cp;
10387c478bd9Sstevel@tonic-gate 	char		ul_stop;	/* reason for stopping */
10397c478bd9Sstevel@tonic-gate 	char		ul_signalled;	/* this lwp was cond_signal()d */
10407c478bd9Sstevel@tonic-gate 	char		ul_dead;	/* this lwp has called thr_exit */
10417c478bd9Sstevel@tonic-gate 	char		ul_unwind;	/* posix: unwind C++ stack */
10427c478bd9Sstevel@tonic-gate 	char		ul_detached;	/* THR_DETACHED at thread_create() */
10437c478bd9Sstevel@tonic-gate 					/* or pthread_detach() was called */
10447c478bd9Sstevel@tonic-gate 	char		ul_writer;	/* sleeping in rw_wrlock() */
10457c478bd9Sstevel@tonic-gate 	char		ul_stopping;	/* set by curthread: stopping self */
104634709573Sraf 	char		ul_cancel_prologue;	/* for _cancel_prologue() */
10477c478bd9Sstevel@tonic-gate 	short		ul_preempt;	/* no_preempt()/preempt() */
10487c478bd9Sstevel@tonic-gate 	short		ul_savpreempt;	/* pre-existing preempt value */
10497c478bd9Sstevel@tonic-gate 	char		ul_sigsuspend;	/* thread is in sigsuspend/pollsys */
10507c478bd9Sstevel@tonic-gate 	char		ul_main;	/* thread is the main thread */
10517c478bd9Sstevel@tonic-gate 	char		ul_fork;	/* thread is performing a fork */
10527c478bd9Sstevel@tonic-gate 	char		ul_primarymap;	/* primary link-map is initialized */
10537c478bd9Sstevel@tonic-gate 	/* per-thread copies of the corresponding global variables */
10545d1dd9a9Sraf 	uint8_t		ul_max_spinners;	/* thread_max_spinners */
10557c478bd9Sstevel@tonic-gate 	char		ul_door_noreserve;	/* thread_door_noreserve */
10567c478bd9Sstevel@tonic-gate 	char		ul_queue_fifo;		/* thread_queue_fifo */
10577c478bd9Sstevel@tonic-gate 	char		ul_cond_wait_defer;	/* thread_cond_wait_defer */
10587c478bd9Sstevel@tonic-gate 	char		ul_error_detection;	/* thread_error_detection */
10597c478bd9Sstevel@tonic-gate 	char		ul_async_safe;		/* thread_async_safe */
1060d4204c85Sraf 	char		ul_rt;			/* found on an RT queue */
1061d4204c85Sraf 	char		ul_rtqueued;		/* was RT when queued */
10627c5714f6Sraf 	char		ul_misaligned;		/* thread_locks_misaligned */
10637c5714f6Sraf 	char		ul_pad[3];
10647c478bd9Sstevel@tonic-gate 	int		ul_adaptive_spin;	/* thread_adaptive_spin */
10657c478bd9Sstevel@tonic-gate 	int		ul_queue_spin;		/* thread_queue_spin */
10667c478bd9Sstevel@tonic-gate 	int		ul_critical;	/* non-zero == in a critical region */
10677c478bd9Sstevel@tonic-gate 	int		ul_sigdefer;	/* non-zero == defer signals */
10687c478bd9Sstevel@tonic-gate 	int		ul_vfork;	/* thread is the child of vfork() */
10697c478bd9Sstevel@tonic-gate 	int		ul_cancelable;	/* _cancelon()/_canceloff() */
10707c478bd9Sstevel@tonic-gate 	char		ul_cancel_pending;  /* pthread_cancel() was called */
10717c478bd9Sstevel@tonic-gate 	char		ul_cancel_disabled; /* PTHREAD_CANCEL_DISABLE */
10727c478bd9Sstevel@tonic-gate 	char		ul_cancel_async;    /* PTHREAD_CANCEL_ASYNCHRONOUS */
10737c478bd9Sstevel@tonic-gate 	char		ul_save_async;	/* saved copy of ul_cancel_async */
10747c478bd9Sstevel@tonic-gate 	char		ul_mutator;	/* lwp is a mutator (java interface) */
10757c478bd9Sstevel@tonic-gate 	char		ul_created;	/* created suspended */
10767c478bd9Sstevel@tonic-gate 	char		ul_replace;	/* replacement; must be free()d */
10777c478bd9Sstevel@tonic-gate 	uchar_t		ul_nocancel;	/* cancellation can't happen */
10787c478bd9Sstevel@tonic-gate 	int		ul_errno;	/* per-thread errno */
10797c478bd9Sstevel@tonic-gate 	caddr32_t	ul_errnop;	/* pointer to errno or self->ul_errno */
10807c478bd9Sstevel@tonic-gate 	caddr32_t	ul_clnup_hdr;	/* head of cleanup handlers list */
10817c478bd9Sstevel@tonic-gate 	caddr32_t	ul_schedctl_called; /* ul_schedctl is set up */
10827c478bd9Sstevel@tonic-gate 	caddr32_t	ul_schedctl;	/* schedctl data */
10837c478bd9Sstevel@tonic-gate 	int		ul_bindflags;	/* bind_guard() interface to ld.so.1 */
1084a574db85Sraf 	uint_t		ul_libc_locks;	/* count of cancel_safe_mutex_lock()s */
10857c478bd9Sstevel@tonic-gate 	caddr32_t	ul_stsd;	/* slow TLS for keys >= TSD_NFAST */
10867c478bd9Sstevel@tonic-gate 	caddr32_t	ul_ftsd[TSD_NFAST]; /* fast TLS for keys < TSD_NFAST */
10877c478bd9Sstevel@tonic-gate 	td_evbuf32_t	ul_td_evbuf;	/* event buffer */
10887c478bd9Sstevel@tonic-gate 	char		ul_td_events_enable;	/* event mechanism enabled */
10897c478bd9Sstevel@tonic-gate 	char		ul_sync_obj_reg;	/* tdb_sync_obj_register() */
10907c478bd9Sstevel@tonic-gate 	char		ul_qtype;	/* MX or CV */
10917c478bd9Sstevel@tonic-gate 	char		ul_cv_wake;	/* != 0: just wake up, don't requeue */
1092e54ab87fSRoger A. Faulkner 	int		ul_rtld;	/* thread is running inside ld.so.1 */
10937c478bd9Sstevel@tonic-gate 	int		ul_usropts;	/* flags given to thr_create() */
10947c478bd9Sstevel@tonic-gate 	caddr32_t	ul_startpc;	/* start func (thr_create()) */
10957c478bd9Sstevel@tonic-gate 	caddr32_t	ul_startarg;	/* argument for start function */
10967c478bd9Sstevel@tonic-gate 	caddr32_t	ul_wchan;	/* synch object when sleeping */
10977c478bd9Sstevel@tonic-gate 	caddr32_t	ul_link;	/* sleep queue link */
10987c478bd9Sstevel@tonic-gate 	caddr32_t	ul_sleepq;	/* sleep queue thread is waiting on */
10997c478bd9Sstevel@tonic-gate 	caddr32_t	ul_cvmutex;	/* mutex dropped when waiting on a cv */
11007c478bd9Sstevel@tonic-gate 	caddr32_t	ul_mxchain;	/* chain of owned ceiling mutexes */
1101d4204c85Sraf 	int		ul_save_state;	/* bind_guard() interface to ld.so.1 */
1102883492d5Sraf 	uint_t		ul_rdlockcnt;	/* # entries in ul_readlock array */
1103883492d5Sraf 				/* 0 means there is but a single entry */
1104883492d5Sraf 	union {				/* single entry or pointer to array */
11057c478bd9Sstevel@tonic-gate 		readlock32_t	single;
11067c478bd9Sstevel@tonic-gate 		caddr32_t	array;
11077c478bd9Sstevel@tonic-gate 	} ul_readlock;
1108883492d5Sraf 	uint_t		ul_heldlockcnt;	/* # entries in ul_heldlocks array */
1109883492d5Sraf 				/* 0 means there is but a single entry */
1110883492d5Sraf 	union {				/* single entry or pointer to array */
1111883492d5Sraf 		caddr32_t	single;
1112883492d5Sraf 		caddr32_t	array;
1113883492d5Sraf 	} ul_heldlocks;
11147c478bd9Sstevel@tonic-gate 	/* PROBE_SUPPORT begin */
11157c478bd9Sstevel@tonic-gate 	caddr32_t	ul_tpdp;
11167c478bd9Sstevel@tonic-gate 	/* PROBE_SUPPORT end */
11177c478bd9Sstevel@tonic-gate 	caddr32_t	ul_siglink;	/* pointer to previous context */
11187c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_spin;	/* spin lock statistics */
11197c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_spin2;
11207c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_sleep;
11217c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_wakeup;
1122d4204c85Sraf 	queue_root32_t	ul_queue_root;	/* root of a sleep queue */
1123d4204c85Sraf 	id_t		ul_rtclassid;	/* real-time class id */
1124d4204c85Sraf 	uint_t		ul_pilocks;	/* count of PI locks held */
11257c478bd9Sstevel@tonic-gate 		/* the following members *must* be last in the structure */
11267c478bd9Sstevel@tonic-gate 		/* they are discarded when ulwp is replaced on thr_exit() */
1127bdf0047cSRoger A. Faulkner 	sigset_t	ul_sigmask;	/* thread's current signal mask */
1128bdf0047cSRoger A. Faulkner 	sigset_t	ul_tmpmask;	/* signal mask for sigsuspend/pollsys */
11297c478bd9Sstevel@tonic-gate 	siginfo32_t	ul_siginfo;	/* deferred siginfo */
11307c478bd9Sstevel@tonic-gate 	mutex_t		ul_spinlock;	/* used when suspending/continuing */
11317c478bd9Sstevel@tonic-gate 	fpuenv32_t	ul_fpuenv;	/* floating point state */
11327c478bd9Sstevel@tonic-gate 	caddr32_t	ul_sp;		/* stack pointer when blocked */
11337c478bd9Sstevel@tonic-gate #if defined(sparc)
11347c478bd9Sstevel@tonic-gate 	caddr32_t	ul_unwind_ret;	/* used only by _ex_clnup_handler() */
11357c478bd9Sstevel@tonic-gate #endif
11364f364e7cSRobert Mustacchi 	tumem32_t	ul_tmem;	/* used only by umem */
11377c478bd9Sstevel@tonic-gate } ulwp32_t;
11387c478bd9Sstevel@tonic-gate 
11397c478bd9Sstevel@tonic-gate #define	REPLACEMENT_SIZE32	((size_t)&((ulwp32_t *)NULL)->ul_sigmask)
11407c478bd9Sstevel@tonic-gate 
11417c478bd9Sstevel@tonic-gate typedef struct uberdata32 {
11427c478bd9Sstevel@tonic-gate 	pad_lock_t	_link_lock;
11438cd45542Sraf 	pad_lock_t	_ld_lock;
11448cd45542Sraf 	pad_lock_t	_fork_lock;
11458cd45542Sraf 	pad_lock_t	_atfork_lock;
114698c1a6b4Sraf 	pad32_lock_t	_callout_lock;
114798c1a6b4Sraf 	pad32_lock_t	_tdb_hash_lock;
11487c478bd9Sstevel@tonic-gate 	tdb_sync_stats_t tdb_hash_lock_stats;
11497c478bd9Sstevel@tonic-gate 	siguaction32_t	siguaction[NSIG];
11507c478bd9Sstevel@tonic-gate 	bucket32_t	bucket[NBUCKETS];
11517c478bd9Sstevel@tonic-gate 	atexit_root32_t	atexit_root;
1152*fc2512cfSRobert Mustacchi 	quickexit_root32_t quickexit_root;
11537c478bd9Sstevel@tonic-gate 	tsd_metadata32_t tsd_metadata;
11547c478bd9Sstevel@tonic-gate 	tls_metadata32_t tls_metadata;
11557c478bd9Sstevel@tonic-gate 	char		primary_map;
11567c478bd9Sstevel@tonic-gate 	char		bucket_init;
11577c478bd9Sstevel@tonic-gate 	char		pad[2];
11587c478bd9Sstevel@tonic-gate 	uberflags_t	uberflags;
11597c478bd9Sstevel@tonic-gate 	caddr32_t	queue_head;
11607c478bd9Sstevel@tonic-gate 	caddr32_t	thr_hash_table;
11617c478bd9Sstevel@tonic-gate 	uint_t		hash_size;
11627c478bd9Sstevel@tonic-gate 	uint_t		hash_mask;
11637c478bd9Sstevel@tonic-gate 	caddr32_t	ulwp_one;
11647c478bd9Sstevel@tonic-gate 	caddr32_t	all_lwps;
11657c478bd9Sstevel@tonic-gate 	caddr32_t	all_zombies;
11667c478bd9Sstevel@tonic-gate 	int		nthreads;
11677c478bd9Sstevel@tonic-gate 	int		nzombies;
11687c478bd9Sstevel@tonic-gate 	int		ndaemons;
11697c478bd9Sstevel@tonic-gate 	int		pid;
11707c478bd9Sstevel@tonic-gate 	caddr32_t	sigacthandler;
11717c478bd9Sstevel@tonic-gate 	caddr32_t	lwp_stacks;
11727c478bd9Sstevel@tonic-gate 	caddr32_t	lwp_laststack;
11737c478bd9Sstevel@tonic-gate 	int		nfreestack;
11747c478bd9Sstevel@tonic-gate 	int		thread_stack_cache;
11757c478bd9Sstevel@tonic-gate 	caddr32_t	ulwp_freelist;
11767c478bd9Sstevel@tonic-gate 	caddr32_t	ulwp_lastfree;
11777c478bd9Sstevel@tonic-gate 	caddr32_t	ulwp_replace_free;
11787c478bd9Sstevel@tonic-gate 	caddr32_t	ulwp_replace_last;
11797c478bd9Sstevel@tonic-gate 	caddr32_t	atforklist;
1180883492d5Sraf 	caddr32_t	robustlocks;
118109ce0d4aSRoger A. Faulkner 	caddr32_t	robustlist;
1182fe4be5acSGordon Ross 	caddr32_t	progname;
11837c478bd9Sstevel@tonic-gate 	caddr32_t	tdb_bootstrap;
11847c478bd9Sstevel@tonic-gate 	tdb32_t		tdb;
11857c478bd9Sstevel@tonic-gate } uberdata32_t;
11867c478bd9Sstevel@tonic-gate 
11877c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
11887c478bd9Sstevel@tonic-gate 
11897c478bd9Sstevel@tonic-gate /* ul_stop values */
11907c478bd9Sstevel@tonic-gate #define	TSTP_REGULAR	0x01	/* Stopped by thr_suspend() */
11917c478bd9Sstevel@tonic-gate #define	TSTP_MUTATOR	0x08	/* stopped by thr_suspend_*mutator*() */
11927c478bd9Sstevel@tonic-gate #define	TSTP_FORK	0x20	/* stopped by suspend_fork() */
11937c478bd9Sstevel@tonic-gate 
11947c478bd9Sstevel@tonic-gate /*
11957c478bd9Sstevel@tonic-gate  * Implementation-specific attribute types for pthread_mutexattr_init() etc.
11967c478bd9Sstevel@tonic-gate  */
11977c478bd9Sstevel@tonic-gate 
11987c478bd9Sstevel@tonic-gate typedef	struct	_cvattr {
11997c478bd9Sstevel@tonic-gate 	int	pshared;
12007c478bd9Sstevel@tonic-gate 	clockid_t clockid;
12017c478bd9Sstevel@tonic-gate } cvattr_t;
12027c478bd9Sstevel@tonic-gate 
12037c478bd9Sstevel@tonic-gate typedef	struct	_mattr {
12047c478bd9Sstevel@tonic-gate 	int	pshared;
12057c478bd9Sstevel@tonic-gate 	int	protocol;
12067c478bd9Sstevel@tonic-gate 	int	prioceiling;
12077c478bd9Sstevel@tonic-gate 	int	type;
12087c478bd9Sstevel@tonic-gate 	int	robustness;
12097c478bd9Sstevel@tonic-gate } mattr_t;
12107c478bd9Sstevel@tonic-gate 
12117c478bd9Sstevel@tonic-gate typedef	struct	_thrattr {
12127c478bd9Sstevel@tonic-gate 	size_t	stksize;
12137c478bd9Sstevel@tonic-gate 	void	*stkaddr;
12147c478bd9Sstevel@tonic-gate 	int	detachstate;
121534709573Sraf 	int	daemonstate;
12167c478bd9Sstevel@tonic-gate 	int	scope;
12177c478bd9Sstevel@tonic-gate 	int	prio;
12187c478bd9Sstevel@tonic-gate 	int	policy;
12197c478bd9Sstevel@tonic-gate 	int	inherit;
12207c478bd9Sstevel@tonic-gate 	size_t	guardsize;
12217c478bd9Sstevel@tonic-gate } thrattr_t;
12227c478bd9Sstevel@tonic-gate 
12237c478bd9Sstevel@tonic-gate typedef	struct	_rwlattr {
12247c478bd9Sstevel@tonic-gate 	int	pshared;
12257c478bd9Sstevel@tonic-gate } rwlattr_t;
12267c478bd9Sstevel@tonic-gate 
12277c478bd9Sstevel@tonic-gate /* _curthread() is inline for speed */
12287c478bd9Sstevel@tonic-gate extern	ulwp_t		*_curthread(void);
12297c478bd9Sstevel@tonic-gate #define	curthread	(_curthread())
12307c478bd9Sstevel@tonic-gate 
12317c478bd9Sstevel@tonic-gate /* this version (also inline) can be tested for NULL */
12327c478bd9Sstevel@tonic-gate extern	ulwp_t		*__curthread(void);
12337c478bd9Sstevel@tonic-gate 
12347c478bd9Sstevel@tonic-gate /* get the current stack pointer (also inline) */
12357c478bd9Sstevel@tonic-gate extern	greg_t		stkptr(void);
12367c478bd9Sstevel@tonic-gate 
12377c478bd9Sstevel@tonic-gate /*
12387c478bd9Sstevel@tonic-gate  * Suppress __attribute__((...)) if we are not compiling with gcc
12397c478bd9Sstevel@tonic-gate  */
12407c478bd9Sstevel@tonic-gate #if !defined(__GNUC__)
12417c478bd9Sstevel@tonic-gate #define	__attribute__(string)
12427c478bd9Sstevel@tonic-gate #endif
12437c478bd9Sstevel@tonic-gate 
1244d4204c85Sraf /* Fetch the dispatch (kernel) priority of a thread */
1245d4204c85Sraf #define	real_priority(ulwp)	\
1246d4204c85Sraf 	((ulwp)->ul_schedctl? (ulwp)->ul_schedctl->sc_priority : 0)
1247d4204c85Sraf 
12487c478bd9Sstevel@tonic-gate /*
12497c478bd9Sstevel@tonic-gate  * Implementation functions.  Not visible outside of the library itself.
12507c478bd9Sstevel@tonic-gate  */
1251f841f6adSraf extern	int	__nanosleep(const timespec_t *, timespec_t *);
12527c478bd9Sstevel@tonic-gate extern	void	getgregs(ulwp_t *, gregset_t);
12537c478bd9Sstevel@tonic-gate extern	void	setgregs(ulwp_t *, gregset_t);
12547c478bd9Sstevel@tonic-gate extern	void	thr_panic(const char *);
12557c478bd9Sstevel@tonic-gate #pragma rarely_called(thr_panic)
12560d045c0dSRobert Mustacchi extern	void	mutex_panic(mutex_t *, const char *);
12570d045c0dSRobert Mustacchi #pragma rarely_called(mutex_panic)
12587c478bd9Sstevel@tonic-gate extern	ulwp_t	*find_lwp(thread_t);
12597c478bd9Sstevel@tonic-gate extern	void	finish_init(void);
1260d4204c85Sraf extern	void	update_sched(ulwp_t *);
12617c478bd9Sstevel@tonic-gate extern	void	queue_alloc(void);
12624f364e7cSRobert Mustacchi extern	void	tmem_exit(void);
12637c478bd9Sstevel@tonic-gate extern	void	tsd_exit(void);
12647c478bd9Sstevel@tonic-gate extern	void	tsd_free(ulwp_t *);
12657c478bd9Sstevel@tonic-gate extern	void	tls_setup(void);
12667c478bd9Sstevel@tonic-gate extern	void	tls_exit(void);
12677c478bd9Sstevel@tonic-gate extern	void	tls_free(ulwp_t *);
12687c478bd9Sstevel@tonic-gate extern	void	rwl_free(ulwp_t *);
1269883492d5Sraf extern	void	heldlock_exit(void);
1270883492d5Sraf extern	void	heldlock_free(ulwp_t *);
12717c478bd9Sstevel@tonic-gate extern	void	sigacthandler(int, siginfo_t *, void *);
12727c478bd9Sstevel@tonic-gate extern	void	signal_init(void);
12737c478bd9Sstevel@tonic-gate extern	int	sigequalset(const sigset_t *, const sigset_t *);
12747c478bd9Sstevel@tonic-gate extern	void	mutex_setup(void);
12757c478bd9Sstevel@tonic-gate extern	void	take_deferred_signal(int);
1276373d25a2SRoger A. Faulkner extern	void	*setup_top_frame(void *, size_t, ulwp_t *);
12777c478bd9Sstevel@tonic-gate extern	int	setup_context(ucontext_t *, void *(*func)(ulwp_t *),
12787c478bd9Sstevel@tonic-gate 			ulwp_t *ulwp, caddr_t stk, size_t stksize);
12797c478bd9Sstevel@tonic-gate extern	volatile sc_shared_t *setup_schedctl(void);
12807c478bd9Sstevel@tonic-gate extern	void	*lmalloc(size_t);
12817c478bd9Sstevel@tonic-gate extern	void	lfree(void *, size_t);
12827c478bd9Sstevel@tonic-gate extern	void	*libc_malloc(size_t);
12837c478bd9Sstevel@tonic-gate extern	void	*libc_realloc(void *, size_t);
12847c478bd9Sstevel@tonic-gate extern	void	libc_free(void *);
12857c478bd9Sstevel@tonic-gate extern	char	*libc_strdup(const char *);
12867c478bd9Sstevel@tonic-gate extern	void	ultos(uint64_t, int, char *);
12877c478bd9Sstevel@tonic-gate extern	void	lock_error(const mutex_t *, const char *, void *, const char *);
12887c478bd9Sstevel@tonic-gate extern	void	rwlock_error(const rwlock_t *, const char *, const char *);
12897c478bd9Sstevel@tonic-gate extern	void	thread_error(const char *);
12907c478bd9Sstevel@tonic-gate extern	void	grab_assert_lock(void);
12917c478bd9Sstevel@tonic-gate extern	void	dump_queue_statistics(void);
12927c478bd9Sstevel@tonic-gate extern	void	collect_queue_statistics(void);
12937c478bd9Sstevel@tonic-gate extern	void	record_spin_locks(ulwp_t *);
1294883492d5Sraf extern	void	remember_lock(mutex_t *);
1295883492d5Sraf extern	void	forget_lock(mutex_t *);
1296883492d5Sraf extern	void	register_lock(mutex_t *);
1297c242ec1bSRoger A. Faulkner extern	void	unregister_locks(void);
12987c478bd9Sstevel@tonic-gate #if defined(__sparc)
12997c478bd9Sstevel@tonic-gate extern	void	_flush_windows(void);
13007c478bd9Sstevel@tonic-gate #else
13017c478bd9Sstevel@tonic-gate #define	_flush_windows()
13027c478bd9Sstevel@tonic-gate #endif
13037c478bd9Sstevel@tonic-gate extern	void	set_curthread(void *);
13047c478bd9Sstevel@tonic-gate 
130541efec22Sraf /*
1306883492d5Sraf  * Utility function used when waking up many threads (more than MAXLWPS)
1307883492d5Sraf  * all at once.  See mutex_wakeup_all(), cond_broadcast(), and rw_unlock().
130841efec22Sraf  */
130941efec22Sraf #define	MAXLWPS	128	/* max remembered lwpids before overflow */
131041efec22Sraf #define	NEWLWPS	2048	/* max remembered lwpids at first overflow */
131141efec22Sraf extern	lwpid_t	*alloc_lwpids(lwpid_t *, int *, int *);
131241efec22Sraf 
13137c478bd9Sstevel@tonic-gate /* enter a critical section */
13147c478bd9Sstevel@tonic-gate #define	enter_critical(self)	(self->ul_critical++)
13157c478bd9Sstevel@tonic-gate 
13167c478bd9Sstevel@tonic-gate /* exit a critical section, take deferred actions if necessary */
13177c478bd9Sstevel@tonic-gate extern	void	do_exit_critical(void);
13187c478bd9Sstevel@tonic-gate #define	exit_critical(self)					\
13197c478bd9Sstevel@tonic-gate 	(void) (self->ul_critical--,				\
13207c478bd9Sstevel@tonic-gate 	    ((self->ul_curplease && self->ul_critical == 0)?	\
13217c478bd9Sstevel@tonic-gate 	    (do_exit_critical(), 0) : 0))
13227c478bd9Sstevel@tonic-gate 
13237c478bd9Sstevel@tonic-gate /*
13247c478bd9Sstevel@tonic-gate  * Like enter_critical()/exit_critical() but just for deferring signals.
13257c478bd9Sstevel@tonic-gate  * Unlike enter_critical()/exit_critical(), ul_sigdefer may be set while
13267c478bd9Sstevel@tonic-gate  * calling application functions like constructors and destructors.
13277c478bd9Sstevel@tonic-gate  * Care must be taken if the application function attempts to set
13287c478bd9Sstevel@tonic-gate  * the signal mask while a deferred signal is present; the setting
13297c478bd9Sstevel@tonic-gate  * of the signal mask must also be deferred.
13307c478bd9Sstevel@tonic-gate  */
13317c478bd9Sstevel@tonic-gate #define	sigoff(self)	(self->ul_sigdefer++)
1332e54ab87fSRoger A. Faulkner #define	sigon(self)						\
1333e54ab87fSRoger A. Faulkner 	(void) ((--self->ul_sigdefer == 0 &&			\
1334e54ab87fSRoger A. Faulkner 	    self->ul_curplease && self->ul_critical == 0)?	\
1335e54ab87fSRoger A. Faulkner 	    (do_exit_critical(), 0) : 0)
13367c478bd9Sstevel@tonic-gate 
13377c478bd9Sstevel@tonic-gate /* these are exported functions */
13387c478bd9Sstevel@tonic-gate extern	void	_sigoff(void);
13397c478bd9Sstevel@tonic-gate extern	void	_sigon(void);
13407c478bd9Sstevel@tonic-gate 
13417c478bd9Sstevel@tonic-gate #define	sigorset(s1, s2)				\
13427c478bd9Sstevel@tonic-gate 	(((s1)->__sigbits[0] |= (s2)->__sigbits[0]),	\
13437c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[1] |= (s2)->__sigbits[1]),	\
13447c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[2] |= (s2)->__sigbits[2]),	\
13457c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[3] |= (s2)->__sigbits[3]))
13467c478bd9Sstevel@tonic-gate 
13477c478bd9Sstevel@tonic-gate #define	sigandset(s1, s2)				\
13487c478bd9Sstevel@tonic-gate 	(((s1)->__sigbits[0] &= (s2)->__sigbits[0]),	\
13497c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[1] &= (s2)->__sigbits[1]),	\
13507c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[2] &= (s2)->__sigbits[2]),	\
13517c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[3] &= (s2)->__sigbits[3]))
13527c478bd9Sstevel@tonic-gate 
13537c478bd9Sstevel@tonic-gate #define	sigdiffset(s1, s2)				\
13547c478bd9Sstevel@tonic-gate 	(((s1)->__sigbits[0] &= ~(s2)->__sigbits[0]),	\
13557c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[1] &= ~(s2)->__sigbits[1]),	\
13567c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[2] &= ~(s2)->__sigbits[2]),	\
13577c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[3] &= ~(s2)->__sigbits[3]))
13587c478bd9Sstevel@tonic-gate 
13597c478bd9Sstevel@tonic-gate #define	delete_reserved_signals(s)			\
13607c478bd9Sstevel@tonic-gate 	(((s)->__sigbits[0] &= MASKSET0),		\
13617c478bd9Sstevel@tonic-gate 	((s)->__sigbits[1] &= (MASKSET1 & ~SIGMASK(SIGCANCEL))),\
1362bdf0047cSRoger A. Faulkner 	((s)->__sigbits[2] &= MASKSET2),		\
1363bdf0047cSRoger A. Faulkner 	((s)->__sigbits[3] &= MASKSET3))
13647c478bd9Sstevel@tonic-gate 
13657c478bd9Sstevel@tonic-gate extern	void	block_all_signals(ulwp_t *self);
13667c478bd9Sstevel@tonic-gate 
13677c478bd9Sstevel@tonic-gate /*
13687c478bd9Sstevel@tonic-gate  * When restoring the signal mask after having previously called
13697c478bd9Sstevel@tonic-gate  * block_all_signals(), if we have a deferred signal present then
13707c478bd9Sstevel@tonic-gate  * do nothing other than ASSERT() that we are in a critical region.
13717c478bd9Sstevel@tonic-gate  * The signal mask will be set when we emerge from the critical region
13727c478bd9Sstevel@tonic-gate  * and call take_deferred_signal().  There is no race condition here
13737c478bd9Sstevel@tonic-gate  * because the kernel currently has all signals blocked for this thread.
13747c478bd9Sstevel@tonic-gate  */
13757c478bd9Sstevel@tonic-gate #define	restore_signals(self)						\
13767c478bd9Sstevel@tonic-gate 	((void) ((self)->ul_cursig?					\
13777c478bd9Sstevel@tonic-gate 	(ASSERT((self)->ul_critical + (self)->ul_sigdefer != 0), 0) :	\
1378bdf0047cSRoger A. Faulkner 	__lwp_sigmask(SIG_SETMASK, &(self)->ul_sigmask)))
13797c478bd9Sstevel@tonic-gate 
1380a574db85Sraf extern	void	set_cancel_pending_flag(ulwp_t *, int);
1381a574db85Sraf extern	void	set_cancel_eintr_flag(ulwp_t *);
13827c478bd9Sstevel@tonic-gate extern	void	set_parking_flag(ulwp_t *, int);
1383a574db85Sraf extern	int	cancel_active(void);
13847c478bd9Sstevel@tonic-gate 
13857257d1b4Sraf extern	void	*_thrp_setup(ulwp_t *);
13867c478bd9Sstevel@tonic-gate extern	void	_fpinherit(ulwp_t *);
13877c478bd9Sstevel@tonic-gate extern	void	_lwp_start(void);
13887c478bd9Sstevel@tonic-gate extern	void	_lwp_terminate(void);
13897c478bd9Sstevel@tonic-gate extern	void	lmutex_lock(mutex_t *);
1390f841f6adSraf extern	void	lmutex_unlock(mutex_t *);
139141efec22Sraf extern	void	lrw_rdlock(rwlock_t *);
139241efec22Sraf extern	void	lrw_wrlock(rwlock_t *);
139341efec22Sraf extern	void	lrw_unlock(rwlock_t *);
1394f841f6adSraf extern	void	sig_mutex_lock(mutex_t *);
1395f841f6adSraf extern	void	sig_mutex_unlock(mutex_t *);
1396f841f6adSraf extern	int	sig_mutex_trylock(mutex_t *);
1397f841f6adSraf extern	int	sig_cond_wait(cond_t *, mutex_t *);
1398f841f6adSraf extern	int	sig_cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *);
1399a574db85Sraf extern	void	cancel_safe_mutex_lock(mutex_t *);
1400a574db85Sraf extern	void	cancel_safe_mutex_unlock(mutex_t *);
1401a574db85Sraf extern	int	cancel_safe_mutex_trylock(mutex_t *);
14027c478bd9Sstevel@tonic-gate extern	void	_prefork_handler(void);
14037c478bd9Sstevel@tonic-gate extern	void	_postfork_parent_handler(void);
14047c478bd9Sstevel@tonic-gate extern	void	_postfork_child_handler(void);
1405f841f6adSraf extern	void	postfork1_child(void);
1406f841f6adSraf extern	void	postfork1_child_aio(void);
1407f841f6adSraf extern	void	postfork1_child_sigev_aio(void);
1408f841f6adSraf extern	void	postfork1_child_sigev_mq(void);
1409f841f6adSraf extern	void	postfork1_child_sigev_timer(void);
1410f841f6adSraf extern	void	postfork1_child_tpool(void);
14112e145884Sraf extern	void	fork_lock_enter(void);
14127c478bd9Sstevel@tonic-gate extern	void	fork_lock_exit(void);
14137c478bd9Sstevel@tonic-gate extern	void	suspend_fork(void);
14147c478bd9Sstevel@tonic-gate extern	void	continue_fork(int);
14157c478bd9Sstevel@tonic-gate extern	void	do_sigcancel(void);
1416f841f6adSraf extern	void	setup_cancelsig(int);
1417f841f6adSraf extern	void	init_sigev_thread(void);
1418f841f6adSraf extern	void	init_aio(void);
141923a1cceaSRoger A. Faulkner extern	void	init_progname(void);
14207c478bd9Sstevel@tonic-gate extern	void	_cancelon(void);
14217c478bd9Sstevel@tonic-gate extern	void	_canceloff(void);
14227c478bd9Sstevel@tonic-gate extern	void	_canceloff_nocancel(void);
1423f841f6adSraf extern	void	_cancel_prologue(void);
1424f841f6adSraf extern	void	_cancel_epilogue(void);
14257c478bd9Sstevel@tonic-gate extern	void	no_preempt(ulwp_t *);
14267c478bd9Sstevel@tonic-gate extern	void	preempt(ulwp_t *);
14277c478bd9Sstevel@tonic-gate extern	void	_thrp_unwind(void *);
14287c478bd9Sstevel@tonic-gate 
1429657b1f3dSraf extern	pid_t	__forkx(int);
1430657b1f3dSraf extern	pid_t	__forkallx(int);
14318fd04b83SRoger A. Faulkner extern	int	__open(const char *, int, mode_t);
14328fd04b83SRoger A. Faulkner extern	int	__open64(const char *, int, mode_t);
14338fd04b83SRoger A. Faulkner extern	int	__openat(int, const char *, int, mode_t);
14348fd04b83SRoger A. Faulkner extern	int	__openat64(int, const char *, int, mode_t);
14358cd45542Sraf extern	int	__close(int);
1436a574db85Sraf extern	ssize_t	__read(int, void *, size_t);
1437a574db85Sraf extern	ssize_t	__write(int, const void *, size_t);
14388cd45542Sraf extern	int	__fcntl(int, int, ...);
14397c478bd9Sstevel@tonic-gate extern	int	__lwp_continue(lwpid_t);
14407c478bd9Sstevel@tonic-gate extern	int	__lwp_create(ucontext_t *, uint_t, lwpid_t *);
14417c478bd9Sstevel@tonic-gate extern	int	___lwp_suspend(lwpid_t);
14427c478bd9Sstevel@tonic-gate extern	int	lwp_wait(lwpid_t, lwpid_t *);
14437c478bd9Sstevel@tonic-gate extern	int	__lwp_wait(lwpid_t, lwpid_t *);
14447c478bd9Sstevel@tonic-gate extern	int	__lwp_detach(lwpid_t);
14457c478bd9Sstevel@tonic-gate extern	sc_shared_t *__schedctl(void);
14467c478bd9Sstevel@tonic-gate 
14477c478bd9Sstevel@tonic-gate /* actual system call traps */
14488cd45542Sraf extern	int	__setcontext(const ucontext_t *);
14498cd45542Sraf extern	int	__getcontext(ucontext_t *);
14507c478bd9Sstevel@tonic-gate extern	int	__clock_gettime(clockid_t, timespec_t *);
14517c478bd9Sstevel@tonic-gate extern	void	abstime_to_reltime(clockid_t, const timespec_t *, timespec_t *);
14527c478bd9Sstevel@tonic-gate extern	void	hrt2ts(hrtime_t, timespec_t *);
14537c478bd9Sstevel@tonic-gate 
14547c478bd9Sstevel@tonic-gate extern	int	__sigaction(int, const struct sigaction *, struct sigaction *);
1455bdf0047cSRoger A. Faulkner extern	int	__sigprocmask(int, const sigset_t *, sigset_t *);
1456bdf0047cSRoger A. Faulkner extern	int	__lwp_sigmask(int, const sigset_t *);
14577c478bd9Sstevel@tonic-gate extern	void	__sighndlr(int, siginfo_t *, ucontext_t *, void (*)());
14587c478bd9Sstevel@tonic-gate extern	caddr_t	__sighndlrend;
14597c478bd9Sstevel@tonic-gate #pragma unknown_control_flow(__sighndlr)
1460f841f6adSraf 
1461f841f6adSraf /* belongs in <pthread.h> */
1462f841f6adSraf #define	PTHREAD_CREATE_DAEMON_NP	0x100	/* = THR_DAEMON */
1463f841f6adSraf #define	PTHREAD_CREATE_NONDAEMON_NP	0
14647257d1b4Sraf extern	int	pthread_attr_setdaemonstate_np(pthread_attr_t *, int);
14657257d1b4Sraf extern	int	pthread_attr_getdaemonstate_np(const pthread_attr_t *, int *);
14667257d1b4Sraf 
14677257d1b4Sraf extern	int	mutex_held(mutex_t *);
1468d4204c85Sraf extern	int	mutex_lock_internal(mutex_t *, timespec_t *, int);
1469d4204c85Sraf extern	int	mutex_unlock_internal(mutex_t *, int);
14707c478bd9Sstevel@tonic-gate 
1471a574db85Sraf /* not cancellation points: */
1472a574db85Sraf extern	int	__cond_wait(cond_t *, mutex_t *);
1473a574db85Sraf extern	int	__cond_timedwait(cond_t *, mutex_t *, const timespec_t *);
1474a574db85Sraf extern	int	__cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *);
14757c478bd9Sstevel@tonic-gate 
14767257d1b4Sraf extern	int	rw_read_held(rwlock_t *);
14777257d1b4Sraf extern	int	rw_write_held(rwlock_t *);
1478cb620785Sraf 
1479f841f6adSraf extern	int	_thrp_create(void *, size_t, void *(*)(void *), void *, long,
1480d4204c85Sraf 			thread_t *, size_t);
14817c478bd9Sstevel@tonic-gate extern	int	_thrp_suspend(thread_t, uchar_t);
14827c478bd9Sstevel@tonic-gate extern	int	_thrp_continue(thread_t, uchar_t);
14837c478bd9Sstevel@tonic-gate 
14847257d1b4Sraf extern	void	_thrp_terminate(void *);
14857c478bd9Sstevel@tonic-gate extern	void	_thrp_exit(void);
14867c478bd9Sstevel@tonic-gate 
1487d4204c85Sraf extern	const pcclass_t *get_info_by_class(id_t);
1488d4204c85Sraf extern	const pcclass_t *get_info_by_policy(int);
148934709573Sraf extern	const thrattr_t *def_thrattr(void);
1490d4204c85Sraf extern	id_t	setparam(idtype_t, id_t, int, int);
1491d4204c85Sraf extern	id_t	setprio(idtype_t, id_t, int, int *);
1492d4204c85Sraf extern	id_t	getparam(idtype_t, id_t, int *, struct sched_param *);
14937c478bd9Sstevel@tonic-gate 
14947c478bd9Sstevel@tonic-gate /*
14957c478bd9Sstevel@tonic-gate  * System call wrappers (direct interfaces to the kernel)
14967c478bd9Sstevel@tonic-gate  */
1497c242ec1bSRoger A. Faulkner extern	int	___lwp_mutex_register(mutex_t *, mutex_t **);
1498db94676fSRoger A. Faulkner extern	int	___lwp_mutex_trylock(mutex_t *, ulwp_t *);
1499db94676fSRoger A. Faulkner extern	int	___lwp_mutex_timedlock(mutex_t *, timespec_t *, ulwp_t *);
15007c478bd9Sstevel@tonic-gate extern	int	___lwp_mutex_unlock(mutex_t *);
1501883492d5Sraf extern	int	___lwp_mutex_wakeup(mutex_t *, int);
15027c478bd9Sstevel@tonic-gate extern	int	___lwp_cond_wait(cond_t *, mutex_t *, timespec_t *, int);
15037c478bd9Sstevel@tonic-gate extern	int	___lwp_sema_timedwait(lwp_sema_t *, timespec_t *, int);
15047c478bd9Sstevel@tonic-gate extern	int	__lwp_rwlock_rdlock(rwlock_t *, timespec_t *);
15057c478bd9Sstevel@tonic-gate extern	int	__lwp_rwlock_wrlock(rwlock_t *, timespec_t *);
15067c478bd9Sstevel@tonic-gate extern	int	__lwp_rwlock_tryrdlock(rwlock_t *);
15077c478bd9Sstevel@tonic-gate extern	int	__lwp_rwlock_trywrlock(rwlock_t *);
15087c478bd9Sstevel@tonic-gate extern	int	__lwp_rwlock_unlock(rwlock_t *);
15097c478bd9Sstevel@tonic-gate extern	int	__lwp_park(timespec_t *, lwpid_t);
15107c478bd9Sstevel@tonic-gate extern	int	__lwp_unpark(lwpid_t);
15117c478bd9Sstevel@tonic-gate extern	int	__lwp_unpark_all(lwpid_t *, int);
15120ec57554Sraf #if defined(__x86)
15137c478bd9Sstevel@tonic-gate extern	int	___lwp_private(int, int, void *);
15140ec57554Sraf #endif	/* __x86 */
15157c478bd9Sstevel@tonic-gate 
15167c478bd9Sstevel@tonic-gate /*
15177c478bd9Sstevel@tonic-gate  * inlines
15187c478bd9Sstevel@tonic-gate  */
15197c478bd9Sstevel@tonic-gate extern	int		set_lock_byte(volatile uint8_t *);
152041efec22Sraf extern	uint32_t	atomic_swap_32(volatile uint32_t *, uint32_t);
152141efec22Sraf extern	uint32_t	atomic_cas_32(volatile uint32_t *, uint32_t, uint32_t);
152241efec22Sraf extern	void		atomic_inc_32(volatile uint32_t *);
152341efec22Sraf extern	void		atomic_dec_32(volatile uint32_t *);
152441efec22Sraf extern	void		atomic_and_32(volatile uint32_t *, uint32_t);
152541efec22Sraf extern	void		atomic_or_32(volatile uint32_t *, uint32_t);
15260ec57554Sraf #if defined(__sparc)
15270ec57554Sraf extern	ulong_t		caller(void);
15280ec57554Sraf extern	ulong_t		getfp(void);
15290ec57554Sraf #endif	/* __sparc */
15300ec57554Sraf 
15310ec57554Sraf #include "thr_inlines.h"
15327c478bd9Sstevel@tonic-gate 
15337c478bd9Sstevel@tonic-gate #endif	/* _THR_UBERDATA_H */
1534