xref: /illumos-gate/usr/src/lib/libc/inc/thr_uberdata.h (revision a574db851cdc636fc3939b68e80d79fe7fbd57f2)
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 /*
23*a574db85Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _THR_UBERDATA_H
287c478bd9Sstevel@tonic-gate #define	_THR_UBERDATA_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
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>
417c478bd9Sstevel@tonic-gate #include <link.h>
427c478bd9Sstevel@tonic-gate #include <sys/resource.h>
437c478bd9Sstevel@tonic-gate #include <sys/lwp.h>
447c478bd9Sstevel@tonic-gate #include <errno.h>
457c478bd9Sstevel@tonic-gate #include <sys/asm_linkage.h>
467c478bd9Sstevel@tonic-gate #include <sys/regset.h>
477c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
487c478bd9Sstevel@tonic-gate #include <sys/mman.h>
497c478bd9Sstevel@tonic-gate #include <synch.h>
507c478bd9Sstevel@tonic-gate #include <door.h>
517c478bd9Sstevel@tonic-gate #include <limits.h>
527c478bd9Sstevel@tonic-gate #include <sys/synch32.h>
537c478bd9Sstevel@tonic-gate #include <schedctl.h>
547c478bd9Sstevel@tonic-gate #include <sys/priocntl.h>
557c478bd9Sstevel@tonic-gate #include <thread_db.h>
56f841f6adSraf #include <setjmp.h>
577c478bd9Sstevel@tonic-gate #include "libc_int.h"
587c478bd9Sstevel@tonic-gate #include "tdb_agent.h"
59f841f6adSraf #include "thr_debug.h"
6034709573Sraf 
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate  * This is an implementation-specific include file for threading support.
637c478bd9Sstevel@tonic-gate  * It is not to be seen by the clients of the library.
647c478bd9Sstevel@tonic-gate  *
657c478bd9Sstevel@tonic-gate  * This file also describes uberdata in libc.
667c478bd9Sstevel@tonic-gate  *
677c478bd9Sstevel@tonic-gate  * The term "uberdata" refers to data that is unique and visible across
687c478bd9Sstevel@tonic-gate  * all link maps.  The name is meant to imply that such data is truly
697c478bd9Sstevel@tonic-gate  * global, not just locally global to a particular link map.
707c478bd9Sstevel@tonic-gate  *
717c478bd9Sstevel@tonic-gate  * See the Linker and Libraries Guide for a full description of alternate
727c478bd9Sstevel@tonic-gate  * link maps and how they are set up and used.
737c478bd9Sstevel@tonic-gate  *
747c478bd9Sstevel@tonic-gate  * Alternate link maps implement multiple global namespaces within a single
757c478bd9Sstevel@tonic-gate  * process.  There may be multiple instances of identical dynamic libraries
767c478bd9Sstevel@tonic-gate  * loaded in a process's address space at the same time, each on a different
777c478bd9Sstevel@tonic-gate  * link map (as determined by the dynamic linker), each with its own set of
787c478bd9Sstevel@tonic-gate  * global variables.  Which particular instance of a global variable is seen
797c478bd9Sstevel@tonic-gate  * by a thread running in the process is determined by the link map on which
807c478bd9Sstevel@tonic-gate  * the thread happens to be executing at the time.
817c478bd9Sstevel@tonic-gate  *
827c478bd9Sstevel@tonic-gate  * However, there are aspects of a process that are unique across all
837c478bd9Sstevel@tonic-gate  * link maps, in particular the structures used to implement threads
847c478bd9Sstevel@tonic-gate  * of control (in Sparc terminology, there is only one %g7 regardless
857c478bd9Sstevel@tonic-gate  * of the link map on which the thread is executing).
867c478bd9Sstevel@tonic-gate  *
877c478bd9Sstevel@tonic-gate  * All uberdata is referenced from a base pointer in the thread's ulwp_t
887c478bd9Sstevel@tonic-gate  * structure (which is also uberdata).  All allocations and deallocations
897c478bd9Sstevel@tonic-gate  * of uberdata are made via the uberdata-aware lmalloc() and lfree()
907c478bd9Sstevel@tonic-gate  * interfaces (malloc() and free() are simply locally-global).
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * Special libc-private access to errno.
957c478bd9Sstevel@tonic-gate  * We do this so that references to errno do not invoke the dynamic linker.
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate #undef errno
987c478bd9Sstevel@tonic-gate #define	errno (*curthread->ul_errnop)
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate  * See <sys/synch32.h> for the reasons for these values
1027c478bd9Sstevel@tonic-gate  * and why they are different for sparc and intel.
1037c478bd9Sstevel@tonic-gate  */
1047c478bd9Sstevel@tonic-gate #if defined(__sparc)
1057c478bd9Sstevel@tonic-gate /* lock.lock64.pad[x]	   4 5 6 7 */
1067c478bd9Sstevel@tonic-gate #define	LOCKMASK	0xff000000
1077c478bd9Sstevel@tonic-gate #define	WAITERMASK	0x000000ff
1085d1dd9a9Sraf #define	SPINNERMASK	0x00ff0000
1095d1dd9a9Sraf #define	SPINNERSHIFT	16
1107c478bd9Sstevel@tonic-gate #define	WAITER		0x00000001
1117c478bd9Sstevel@tonic-gate #define	LOCKSET		0xff
1127c478bd9Sstevel@tonic-gate #define	LOCKCLEAR	0
1130ec57554Sraf #elif defined(__x86)
1147c478bd9Sstevel@tonic-gate /* lock.lock64.pad[x]	   7 6 5 4 */
1157c478bd9Sstevel@tonic-gate #define	LOCKMASK	0xff000000
1167c478bd9Sstevel@tonic-gate #define	WAITERMASK	0x00ff0000
1175d1dd9a9Sraf #define	SPINNERMASK	0x0000ff00
1185d1dd9a9Sraf #define	SPINNERSHIFT	8
1197c478bd9Sstevel@tonic-gate #define	WAITER		0x00010000
1207c478bd9Sstevel@tonic-gate #define	LOCKSET		0x01
1217c478bd9Sstevel@tonic-gate #define	LOCKCLEAR	0
1227c478bd9Sstevel@tonic-gate #else
1230ec57554Sraf #error "neither __sparc nor __x86 is defined"
1247c478bd9Sstevel@tonic-gate #endif
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate /*
1277c478bd9Sstevel@tonic-gate  * Fetch the owner of a USYNC_THREAD mutex.
1287c478bd9Sstevel@tonic-gate  * Don't use this with process-shared mutexes;
1297c478bd9Sstevel@tonic-gate  * the owing thread may be in a different process.
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate #define	MUTEX_OWNER(mp)	((ulwp_t *)(uintptr_t)(mp)->mutex_owner)
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /*
134883492d5Sraf  * Test if a thread owns a process-private (USYNC_THREAD) mutex.
135883492d5Sraf  * This is inappropriate for a process-shared (USYNC_PROCESS) mutex.
1367c478bd9Sstevel@tonic-gate  * The 'mp' argument must not have side-effects since it is evaluated twice.
1377c478bd9Sstevel@tonic-gate  */
1387c478bd9Sstevel@tonic-gate #define	MUTEX_OWNED(mp, thrp)	\
1397c478bd9Sstevel@tonic-gate 	((mp)->mutex_lockw != 0 && MUTEX_OWNER(mp) == thrp)
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate  * uberflags.uf_tdb_register_sync is an interface with libc_db to enable the
1447c478bd9Sstevel@tonic-gate  * collection of lock statistics by a debugger or other collecting tool.
1457c478bd9Sstevel@tonic-gate  *
1467c478bd9Sstevel@tonic-gate  * uberflags.uf_thread_error_detection is set by an environment variable:
1477c478bd9Sstevel@tonic-gate  *	_THREAD_ERROR_DETECTION
1487c478bd9Sstevel@tonic-gate  *		0 == no detection of locking primitive errors.
1497c478bd9Sstevel@tonic-gate  *		1 == detect errors and issue a warning message.
1507c478bd9Sstevel@tonic-gate  *		2 == detect errors, issue a warning message, and dump core.
1517c478bd9Sstevel@tonic-gate  *
1527c478bd9Sstevel@tonic-gate  * We bundle these together in uberflags.uf_trs_ted to make a test of either
1537c478bd9Sstevel@tonic-gate  * being non-zero a single memory reference (for speed of mutex_lock(), etc).
1547c478bd9Sstevel@tonic-gate  *
1557c478bd9Sstevel@tonic-gate  * uberflags.uf_mt is set non-zero when the first thread (in addition
1567c478bd9Sstevel@tonic-gate  * to the main thread) is created.
1577c478bd9Sstevel@tonic-gate  *
1587c478bd9Sstevel@tonic-gate  * We bundle all these flags together in uberflags.uf_all to make a test
1597c478bd9Sstevel@tonic-gate  * of any being non-zero a single memory reference (again, for speed).
1607c478bd9Sstevel@tonic-gate  */
1617c478bd9Sstevel@tonic-gate typedef union {
1627c478bd9Sstevel@tonic-gate 	int	uf_all;			/* combined all flags */
1637c478bd9Sstevel@tonic-gate 	struct {
1647c478bd9Sstevel@tonic-gate 		short	h_pad;
1657c478bd9Sstevel@tonic-gate 		short	h_trs_ted;	/* combined reg sync & error detect */
1667c478bd9Sstevel@tonic-gate 	} uf_h;
1677c478bd9Sstevel@tonic-gate 	struct {
1687c478bd9Sstevel@tonic-gate 		char	x_mt;
1697c478bd9Sstevel@tonic-gate 		char	x_pad;
1707c478bd9Sstevel@tonic-gate 		char	x_tdb_register_sync;
1717c478bd9Sstevel@tonic-gate 		char	x_thread_error_detection;
1727c478bd9Sstevel@tonic-gate 	} uf_x;
1737c478bd9Sstevel@tonic-gate } uberflags_t;
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate #define	uf_mt				uf_x.x_mt
1767c478bd9Sstevel@tonic-gate #define	uf_tdb_register_sync		uf_x.x_tdb_register_sync
1777c478bd9Sstevel@tonic-gate #define	uf_thread_error_detection	uf_x.x_thread_error_detection
1787c478bd9Sstevel@tonic-gate #define	uf_trs_ted			uf_h.h_trs_ted	/* both of the above */
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate /*
1817c478bd9Sstevel@tonic-gate  * NOTE WELL:
1827c478bd9Sstevel@tonic-gate  * To enable further optimization, the "ul_schedctl_called" member
1837c478bd9Sstevel@tonic-gate  * of the ulwp_t structure (below) serves double-duty:
1847c478bd9Sstevel@tonic-gate  *	1. If NULL, it means that the thread must call __schedctl()
1857c478bd9Sstevel@tonic-gate  *	   to set up its schedctl mappings before acquiring a mutex.
1867c478bd9Sstevel@tonic-gate  *	   This is required by the implementation of adaptive mutex locking.
1877c478bd9Sstevel@tonic-gate  *	2. If non-NULL, it points to uberdata.uberflags, so that tests of
1887c478bd9Sstevel@tonic-gate  *	   uberflags can be made without additional memory references.
1897c478bd9Sstevel@tonic-gate  * This allows the common case of _mutex_lock() and _mutex_unlock() for
1907c478bd9Sstevel@tonic-gate  * USYNC_THREAD mutexes with no error detection and no lock statistics
1917c478bd9Sstevel@tonic-gate  * to be optimized for speed.
1927c478bd9Sstevel@tonic-gate  */
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate /* double the default stack size for 64-bit processes */
1967c478bd9Sstevel@tonic-gate #ifdef _LP64
1977c478bd9Sstevel@tonic-gate #define	MINSTACK	(8 * 1024)
1987c478bd9Sstevel@tonic-gate #define	DEFAULTSTACK	(2 * 1024 * 1024)
1997c478bd9Sstevel@tonic-gate #else
2007c478bd9Sstevel@tonic-gate #define	MINSTACK	(4 * 1024)
2017c478bd9Sstevel@tonic-gate #define	DEFAULTSTACK	(1024 * 1024)
2027c478bd9Sstevel@tonic-gate #endif
2037c478bd9Sstevel@tonic-gate #define	TSD_NKEYS	_POSIX_THREAD_KEYS_MAX
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate #define	THREAD_MIN_PRIORITY	0
2067c478bd9Sstevel@tonic-gate #define	THREAD_MAX_PRIORITY	127
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate #define	PRIO_SET	0	/* set priority and policy */
2097c478bd9Sstevel@tonic-gate #define	PRIO_SET_PRIO	1	/* set priority only */
2107c478bd9Sstevel@tonic-gate #define	PRIO_INHERIT	2
2117c478bd9Sstevel@tonic-gate #define	PRIO_DISINHERIT	3
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate #define	MUTEX_TRY	0
2147c478bd9Sstevel@tonic-gate #define	MUTEX_LOCK	1
2157c478bd9Sstevel@tonic-gate 
2160ec57554Sraf #if defined(__x86)
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate typedef struct {	/* structure returned by fnstenv */
2197c478bd9Sstevel@tonic-gate 	int	fctrl;		/* control word */
2207c478bd9Sstevel@tonic-gate 	int	fstat;		/* status word (flags, etc) */
2217c478bd9Sstevel@tonic-gate 	int	ftag;		/* tag of which regs busy */
2227c478bd9Sstevel@tonic-gate 	int	misc[4];	/* other stuff, 28 bytes total */
2237c478bd9Sstevel@tonic-gate } fpuenv_t;
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
2267c478bd9Sstevel@tonic-gate typedef fpuenv_t fpuenv32_t;
2277c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate #elif defined(__sparc)
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate typedef struct {	/* fp state structure */
2327c478bd9Sstevel@tonic-gate 	greg_t	fsr;
2337c478bd9Sstevel@tonic-gate 	greg_t	fpu_en;
2347c478bd9Sstevel@tonic-gate } fpuenv_t;
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
2377c478bd9Sstevel@tonic-gate typedef struct {
2387c478bd9Sstevel@tonic-gate 	greg32_t	fsr;
2397c478bd9Sstevel@tonic-gate 	greg32_t	fpu_en;
2407c478bd9Sstevel@tonic-gate } fpuenv32_t;
2417c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
2427c478bd9Sstevel@tonic-gate 
2430ec57554Sraf #endif	/* __x86 */
2447c478bd9Sstevel@tonic-gate 
2450ec57554Sraf #if defined(__x86)
2467c478bd9Sstevel@tonic-gate extern	void	ht_pause(void);		/* "pause" instruction */
2477c478bd9Sstevel@tonic-gate #define	SMT_PAUSE()	ht_pause()
2487c478bd9Sstevel@tonic-gate #else
2497c478bd9Sstevel@tonic-gate #define	SMT_PAUSE()
2500ec57554Sraf #endif	/* __x86 */
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate /*
2537c478bd9Sstevel@tonic-gate  * Cleanup handler related data.
2547c478bd9Sstevel@tonic-gate  * This structure is exported as _cleanup_t in pthread.h.
2557c478bd9Sstevel@tonic-gate  * pthread.h exports only the size of this structure, so check
2567c478bd9Sstevel@tonic-gate  * _cleanup_t in pthread.h before making any change here.
2577c478bd9Sstevel@tonic-gate  */
2587c478bd9Sstevel@tonic-gate typedef struct __cleanup {
2597c478bd9Sstevel@tonic-gate 	struct __cleanup *next;		/* pointer to next handler */
2607c478bd9Sstevel@tonic-gate 	caddr_t	fp;			/* current frame pointer */
2617c478bd9Sstevel@tonic-gate 	void	(*func)(void *);	/* cleanup handler address */
2627c478bd9Sstevel@tonic-gate 	void	*arg;			/* handler's argument */
2637c478bd9Sstevel@tonic-gate } __cleanup_t;
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate /*
2667c478bd9Sstevel@tonic-gate  * Thread-Specific Data (TSD)
2677c478bd9Sstevel@tonic-gate  * TSD_NFAST includes the invalid key zero, so there
2687c478bd9Sstevel@tonic-gate  * are really only (TSD_NFAST - 1) fast key slots.
2697c478bd9Sstevel@tonic-gate  */
2707c478bd9Sstevel@tonic-gate typedef	void (*PFrV)(void *);
2717c478bd9Sstevel@tonic-gate #define	TSD_UNALLOCATED	((PFrV)1)
2727c478bd9Sstevel@tonic-gate #define	TSD_NFAST	9
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate /*
2757c478bd9Sstevel@tonic-gate  * The tsd union is designed to burn a little memory (9 words) to make
2767c478bd9Sstevel@tonic-gate  * lookups blindingly fast.  Note that tsd_nalloc could be placed at the
2777c478bd9Sstevel@tonic-gate  * end of the pad region to increase the likelihood that it falls on the
2787c478bd9Sstevel@tonic-gate  * same cache line as the data.
2797c478bd9Sstevel@tonic-gate  */
2807c478bd9Sstevel@tonic-gate typedef union tsd {
2817c478bd9Sstevel@tonic-gate 	uint_t tsd_nalloc;		/* Amount of allocated storage */
2827c478bd9Sstevel@tonic-gate 	void *tsd_pad[TSD_NFAST];
2837c478bd9Sstevel@tonic-gate 	void *tsd_data[1];
2847c478bd9Sstevel@tonic-gate } tsd_t;
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate typedef struct {
2877c478bd9Sstevel@tonic-gate 	mutex_t tsdm_lock;		/* Lock protecting the data */
2887c478bd9Sstevel@tonic-gate 	uint_t tsdm_nkeys;		/* Number of allocated keys */
2897c478bd9Sstevel@tonic-gate 	uint_t tsdm_nused;		/* Number of used keys */
2907c478bd9Sstevel@tonic-gate 	PFrV *tsdm_destro;		/* Per-key destructors */
2917c478bd9Sstevel@tonic-gate 	char tsdm_pad[64 -		/* pad to 64 bytes */
2927c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + 2 * sizeof (uint_t) + sizeof (PFrV *))];
2937c478bd9Sstevel@tonic-gate } tsd_metadata_t;
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
2967c478bd9Sstevel@tonic-gate typedef union tsd32 {
2977c478bd9Sstevel@tonic-gate 	uint_t tsd_nalloc;		/* Amount of allocated storage */
2987c478bd9Sstevel@tonic-gate 	caddr32_t tsd_pad[TSD_NFAST];
2997c478bd9Sstevel@tonic-gate 	caddr32_t tsd_data[1];
3007c478bd9Sstevel@tonic-gate } tsd32_t;
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate typedef struct {
3037c478bd9Sstevel@tonic-gate 	mutex_t tsdm_lock;		/* Lock protecting the data */
3047c478bd9Sstevel@tonic-gate 	uint_t tsdm_nkeys;		/* Number of allocated keys */
3057c478bd9Sstevel@tonic-gate 	uint_t tsdm_nused;		/* Number of used keys */
3067c478bd9Sstevel@tonic-gate 	caddr32_t tsdm_destro;		/* Per-key destructors */
3077c478bd9Sstevel@tonic-gate 	char tsdm_pad[64 -		/* pad to 64 bytes */
3087c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + 2 * sizeof (uint_t) + sizeof (caddr32_t))];
3097c478bd9Sstevel@tonic-gate } tsd_metadata32_t;
3107c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate /*
3147c478bd9Sstevel@tonic-gate  * Thread-Local Storage (TLS)
3157c478bd9Sstevel@tonic-gate  */
3167c478bd9Sstevel@tonic-gate typedef struct {
3177c478bd9Sstevel@tonic-gate 	void		*tls_data;
3187c478bd9Sstevel@tonic-gate 	size_t		tls_size;
3197c478bd9Sstevel@tonic-gate } tls_t;
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate typedef struct {
3227c478bd9Sstevel@tonic-gate 	mutex_t	tls_lock;		/* Lock protecting the data */
3237c478bd9Sstevel@tonic-gate 	tls_t	tls_modinfo;		/* Root of all TLS_modinfo data */
3247c478bd9Sstevel@tonic-gate 	tls_t	static_tls;		/* Template for static TLS */
3257c478bd9Sstevel@tonic-gate 	char	tls_pad[64 -		/* pad to 64 bytes */
3267c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + 2 * sizeof (tls_t))];
3277c478bd9Sstevel@tonic-gate } tls_metadata_t;
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
3307c478bd9Sstevel@tonic-gate typedef struct {
3317c478bd9Sstevel@tonic-gate 	caddr32_t	tls_data;
3327c478bd9Sstevel@tonic-gate 	size32_t	tls_size;
3337c478bd9Sstevel@tonic-gate } tls32_t;
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate typedef struct {
3367c478bd9Sstevel@tonic-gate 	mutex_t	tls_lock;		/* Lock protecting the data */
3377c478bd9Sstevel@tonic-gate 	tls32_t	tls_modinfo;		/* Root of all TLS_modinfo data */
3387c478bd9Sstevel@tonic-gate 	tls32_t	static_tls;		/* Template for static TLS */
3397c478bd9Sstevel@tonic-gate 	char	tls_pad[64 -		/* pad to 64 bytes */
3407c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + 2 * sizeof (tls32_t))];
3417c478bd9Sstevel@tonic-gate } tls_metadata32_t;
3427c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate /*
3467c478bd9Sstevel@tonic-gate  * Sleep queues for USYNC_THREAD condvars and mutexes.
3477c478bd9Sstevel@tonic-gate  * The size and alignment is 64 bytes to reduce cache conflicts.
3487c478bd9Sstevel@tonic-gate  */
3497c478bd9Sstevel@tonic-gate typedef union {
3507c478bd9Sstevel@tonic-gate 	uint64_t	qh_64[8];
3517c478bd9Sstevel@tonic-gate 	struct {
3527c478bd9Sstevel@tonic-gate 		mutex_t		q_lock;
3537c478bd9Sstevel@tonic-gate 		uint8_t		q_qcnt;
3547c478bd9Sstevel@tonic-gate 		uint8_t		q_pad[7];
3557c478bd9Sstevel@tonic-gate 		uint64_t	q_lockcount;
3567c478bd9Sstevel@tonic-gate 		uint32_t	q_qlen;
3577c478bd9Sstevel@tonic-gate 		uint32_t	q_qmax;
3587c478bd9Sstevel@tonic-gate 		struct ulwp	*q_head;
3597c478bd9Sstevel@tonic-gate 		struct ulwp	*q_tail;
3607c478bd9Sstevel@tonic-gate 	} qh_qh;
3617c478bd9Sstevel@tonic-gate } queue_head_t;
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate #define	qh_lock		qh_qh.q_lock
3647c478bd9Sstevel@tonic-gate #define	qh_qcnt		qh_qh.q_qcnt
3657c478bd9Sstevel@tonic-gate #define	qh_lockcount	qh_qh.q_lockcount
3667c478bd9Sstevel@tonic-gate #define	qh_qlen		qh_qh.q_qlen
3677c478bd9Sstevel@tonic-gate #define	qh_qmax		qh_qh.q_qmax
3687c478bd9Sstevel@tonic-gate #define	qh_head		qh_qh.q_head
3697c478bd9Sstevel@tonic-gate #define	qh_tail		qh_qh.q_tail
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate /* queue types passed to queue_lock() and enqueue() */
3727c478bd9Sstevel@tonic-gate #define	MX	0
3737c478bd9Sstevel@tonic-gate #define	CV	1
3747c478bd9Sstevel@tonic-gate #define	FIFOQ	0x10	/* or'ing with FIFOQ asks for FIFO queueing */
375883492d5Sraf #define	QHASHSHIFT	9			/* number of hashing bits */
376883492d5Sraf #define	QHASHSIZE	(1 << QHASHSHIFT)	/* power of 2 (1<<9 == 512) */
377883492d5Sraf #define	QUEUE_HASH(wchan, type)	((uint_t)			\
378883492d5Sraf 	((((uintptr_t)(wchan) >> 3)				\
379883492d5Sraf 	^ ((uintptr_t)(wchan) >> (QHASHSHIFT + 3)))		\
3807c478bd9Sstevel@tonic-gate 	& (QHASHSIZE - 1)) + (((type) == MX)? 0 : QHASHSIZE))
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate extern	queue_head_t	*queue_lock(void *, int);
3837c478bd9Sstevel@tonic-gate extern	void		queue_unlock(queue_head_t *);
3847c478bd9Sstevel@tonic-gate extern	void		enqueue(queue_head_t *, struct ulwp *, void *, int);
3857c478bd9Sstevel@tonic-gate extern	struct ulwp	*dequeue(queue_head_t *, void *, int *);
3867c478bd9Sstevel@tonic-gate extern	struct ulwp	*queue_waiter(queue_head_t *, void *);
38741efec22Sraf extern	struct ulwp	*queue_unlink(queue_head_t *,
38841efec22Sraf 				struct ulwp **, struct ulwp *);
3897c478bd9Sstevel@tonic-gate extern	uint8_t		dequeue_self(queue_head_t *, void *);
3907c478bd9Sstevel@tonic-gate extern	void		unsleep_self(void);
3917c478bd9Sstevel@tonic-gate extern	void		spin_lock_set(mutex_t *);
3927c478bd9Sstevel@tonic-gate extern	void		spin_lock_clear(mutex_t *);
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate /*
3957c478bd9Sstevel@tonic-gate  * Memory block for chain of owned ceiling mutexes.
3967c478bd9Sstevel@tonic-gate  */
3977c478bd9Sstevel@tonic-gate typedef struct mxchain {
3987c478bd9Sstevel@tonic-gate 	struct mxchain	*mxchain_next;
3997c478bd9Sstevel@tonic-gate 	mutex_t		*mxchain_mx;
4007c478bd9Sstevel@tonic-gate } mxchain_t;
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate /*
4037c478bd9Sstevel@tonic-gate  * Pointer to an rwlock that is held for reading.
4047c478bd9Sstevel@tonic-gate  * Used in rw_rdlock() to allow a thread that already holds a read
4057c478bd9Sstevel@tonic-gate  * lock to acquire another read lock on the same rwlock even if
4067c478bd9Sstevel@tonic-gate  * there are writers waiting.  This to avoid deadlock when acquiring
4077c478bd9Sstevel@tonic-gate  * a read lock more than once in the presence of pending writers.
4087c478bd9Sstevel@tonic-gate  * POSIX mandates this behavior.
4097c478bd9Sstevel@tonic-gate  */
4107c478bd9Sstevel@tonic-gate typedef struct {
4117c478bd9Sstevel@tonic-gate 	void	*rd_rwlock;	/* the rwlock held for reading */
4127c478bd9Sstevel@tonic-gate 	size_t	rd_count;	/* count of read locks applied */
4137c478bd9Sstevel@tonic-gate } readlock_t;
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
4167c478bd9Sstevel@tonic-gate typedef struct {
4177c478bd9Sstevel@tonic-gate 	caddr32_t	rd_rwlock;
4187c478bd9Sstevel@tonic-gate 	size32_t	rd_count;
4197c478bd9Sstevel@tonic-gate } readlock32_t;
4207c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate /*
4237c478bd9Sstevel@tonic-gate  * Maximum number of read locks allowed for one thread on one rwlock.
4247c478bd9Sstevel@tonic-gate  * This could be as large as INT_MAX, but the SUSV3 test suite would
4257c478bd9Sstevel@tonic-gate  * take an inordinately long time to complete.  This is big enough.
4267c478bd9Sstevel@tonic-gate  */
4277c478bd9Sstevel@tonic-gate #define	READ_LOCK_MAX	100000
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate #define	ul_tlsent	ul_tls.tls_data	/* array of pointers to dynamic TLS */
4307c478bd9Sstevel@tonic-gate #define	ul_ntlsent	ul_tls.tls_size	/* number of entries in ul_tlsent */
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate /*
4337c478bd9Sstevel@tonic-gate  * Round up an integral value to a multiple of 64
4347c478bd9Sstevel@tonic-gate  */
4357c478bd9Sstevel@tonic-gate #define	roundup64(x)	(-(-(x) & -64))
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate /*
4387c478bd9Sstevel@tonic-gate  * NOTE:  Whatever changes are made to ulwp_t must be
4397c478bd9Sstevel@tonic-gate  * reflected in $SRC/cmd/mdb/common/modules/libc/libc.c
4407c478bd9Sstevel@tonic-gate  *
4417c478bd9Sstevel@tonic-gate  * NOTE: ul_self *must* be the first member of ulwp_t on x86
4427c478bd9Sstevel@tonic-gate  * Low-level x86 code relies on this.
4437c478bd9Sstevel@tonic-gate  */
4447c478bd9Sstevel@tonic-gate typedef struct ulwp {
4457c478bd9Sstevel@tonic-gate 	/*
4467c478bd9Sstevel@tonic-gate 	 * These members always need to come first on sparc.
4477c478bd9Sstevel@tonic-gate 	 * For dtrace, a ulwp_t must be aligned on a 64-byte boundary.
4487c478bd9Sstevel@tonic-gate 	 */
4497c478bd9Sstevel@tonic-gate #if defined(__sparc)
4507c478bd9Sstevel@tonic-gate 	uint32_t	ul_dinstr;	/* scratch space for dtrace */
4517c478bd9Sstevel@tonic-gate 	uint32_t	ul_padsparc0[15];
4527c478bd9Sstevel@tonic-gate 	uint32_t	ul_dsave;	/* dtrace: save %g1, %g0, %sp */
4537c478bd9Sstevel@tonic-gate 	uint32_t	ul_drestore;	/* dtrace: restore %g0, %g0, %g0 */
4547c478bd9Sstevel@tonic-gate 	uint32_t	ul_dftret;	/* dtrace: return probe fasttrap */
4557c478bd9Sstevel@tonic-gate 	uint32_t	ul_dreturn;	/* dtrace: return %o0 */
4567c478bd9Sstevel@tonic-gate #endif
4577c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_self;	/* pointer to self */
4587c478bd9Sstevel@tonic-gate #if defined(__i386)
4597c478bd9Sstevel@tonic-gate 	uint8_t		ul_dinstr[40];	/* scratch space for dtrace */
4607c478bd9Sstevel@tonic-gate #elif defined(__amd64)
4617c478bd9Sstevel@tonic-gate 	uint8_t		ul_dinstr[56];	/* scratch space for dtrace */
4627c478bd9Sstevel@tonic-gate #endif
4637c478bd9Sstevel@tonic-gate 	struct uberdata *ul_uberdata;	/* uber (super-global) data */
4647c478bd9Sstevel@tonic-gate 	tls_t		ul_tls;		/* dynamic thread-local storage base */
4657c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_forw;	/* forw, back all_lwps list, */
4667c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_back;	/* protected by link_lock */
4677c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_next;	/* list to keep track of stacks */
4687c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_hash;	/* hash chain linked list */
4697c478bd9Sstevel@tonic-gate 	void		*ul_rval;	/* return value from thr_exit() */
4707c478bd9Sstevel@tonic-gate 	caddr_t		ul_stk;		/* mapping base of the stack */
4717c478bd9Sstevel@tonic-gate 	size_t		ul_mapsiz;	/* mapping size of the stack */
4727c478bd9Sstevel@tonic-gate 	size_t		ul_guardsize;	/* normally _lpagesize */
4737c478bd9Sstevel@tonic-gate 	uintptr_t	ul_stktop;	/* broken thr_stksegment() interface */
4747c478bd9Sstevel@tonic-gate 	size_t		ul_stksiz;	/* broken thr_stksegment() interface */
4757c478bd9Sstevel@tonic-gate 	stack_t		ul_ustack;	/* current stack boundaries */
4767c478bd9Sstevel@tonic-gate 	int		ul_ix;		/* hash index */
4777c478bd9Sstevel@tonic-gate 	lwpid_t		ul_lwpid;	/* thread id, aka the lwp id */
4787c478bd9Sstevel@tonic-gate 	pri_t		ul_pri;		/* priority known to the library */
4797c478bd9Sstevel@tonic-gate 	pri_t		ul_mappedpri;	/* priority known to the application */
4807c478bd9Sstevel@tonic-gate 	char		ul_policy;	/* scheduling policy */
4817c478bd9Sstevel@tonic-gate 	char		ul_pri_mapped;	/* != 0 means ul_mappedpri is valid */
4827c478bd9Sstevel@tonic-gate 	union {
4837c478bd9Sstevel@tonic-gate 		struct {
4847c478bd9Sstevel@tonic-gate 			char	cursig;	/* deferred signal number */
4857c478bd9Sstevel@tonic-gate 			char	pleasestop; /* lwp requested to stop itself */
4867c478bd9Sstevel@tonic-gate 		} s;
4877c478bd9Sstevel@tonic-gate 		short	curplease;	/* for testing both at once */
4887c478bd9Sstevel@tonic-gate 	} ul_cp;
4897c478bd9Sstevel@tonic-gate 	char		ul_stop;	/* reason for stopping */
4907c478bd9Sstevel@tonic-gate 	char		ul_signalled;	/* this lwp was cond_signal()d */
4917c478bd9Sstevel@tonic-gate 	char		ul_dead;	/* this lwp has called thr_exit */
4927c478bd9Sstevel@tonic-gate 	char		ul_unwind;	/* posix: unwind C++ stack */
4937c478bd9Sstevel@tonic-gate 	char		ul_detached;	/* THR_DETACHED at thread_create() */
4947c478bd9Sstevel@tonic-gate 					/* or pthread_detach() was called */
4957c478bd9Sstevel@tonic-gate 	char		ul_writer;	/* sleeping in rw_wrlock() */
4967c478bd9Sstevel@tonic-gate 	char		ul_stopping;	/* set by curthread: stopping self */
49734709573Sraf 	char		ul_cancel_prologue;	/* for _cancel_prologue() */
4987c478bd9Sstevel@tonic-gate 	short		ul_preempt;	/* no_preempt()/preempt() */
4997c478bd9Sstevel@tonic-gate 	short		ul_savpreempt;	/* pre-existing preempt value */
5007c478bd9Sstevel@tonic-gate 	char		ul_sigsuspend;	/* thread is in sigsuspend/pollsys */
5017c478bd9Sstevel@tonic-gate 	char		ul_main;	/* thread is the main thread */
5027c478bd9Sstevel@tonic-gate 	char		ul_fork;	/* thread is performing a fork */
5037c478bd9Sstevel@tonic-gate 	char		ul_primarymap;	/* primary link-map is initialized */
5047c478bd9Sstevel@tonic-gate 	/* per-thread copies of the corresponding global variables */
5055d1dd9a9Sraf 	uint8_t		ul_max_spinners;	/* thread_max_spinners */
5067c478bd9Sstevel@tonic-gate 	char		ul_door_noreserve;	/* thread_door_noreserve */
5077c478bd9Sstevel@tonic-gate 	char		ul_queue_fifo;		/* thread_queue_fifo */
5087c478bd9Sstevel@tonic-gate 	char		ul_cond_wait_defer;	/* thread_cond_wait_defer */
5097c478bd9Sstevel@tonic-gate 	char		ul_error_detection;	/* thread_error_detection */
5107c478bd9Sstevel@tonic-gate 	char		ul_async_safe;		/* thread_async_safe */
511*a574db85Sraf 	char		ul_pad1;
512*a574db85Sraf 	char		ul_save_state;	/* bind_guard() interface to ld.so.1 */
5137c478bd9Sstevel@tonic-gate 	int		ul_adaptive_spin;	/* thread_adaptive_spin */
5147c478bd9Sstevel@tonic-gate 	int		ul_queue_spin;		/* thread_queue_spin */
5157c478bd9Sstevel@tonic-gate 	volatile int	ul_critical;	/* non-zero == in a critical region */
5167c478bd9Sstevel@tonic-gate 	int		ul_sigdefer;	/* non-zero == defer signals */
5177c478bd9Sstevel@tonic-gate 	int		ul_vfork;	/* thread is the child of vfork() */
5187c478bd9Sstevel@tonic-gate 	int		ul_cancelable;	/* _cancelon()/_canceloff() */
5197c478bd9Sstevel@tonic-gate 	char		ul_cancel_pending;  /* pthread_cancel() was called */
5207c478bd9Sstevel@tonic-gate 	char		ul_cancel_disabled; /* PTHREAD_CANCEL_DISABLE */
5217c478bd9Sstevel@tonic-gate 	char		ul_cancel_async;    /* PTHREAD_CANCEL_ASYNCHRONOUS */
5227c478bd9Sstevel@tonic-gate 	char		ul_save_async;	/* saved copy of ul_cancel_async */
5237c478bd9Sstevel@tonic-gate 	char		ul_mutator;	/* lwp is a mutator (java interface) */
5247c478bd9Sstevel@tonic-gate 	char		ul_created;	/* created suspended */
5257c478bd9Sstevel@tonic-gate 	char		ul_replace;	/* replacement; must be free()d */
5267c478bd9Sstevel@tonic-gate 	uchar_t		ul_nocancel;	/* cancellation can't happen */
5277c478bd9Sstevel@tonic-gate 	int		ul_errno;	/* per-thread errno */
5287c478bd9Sstevel@tonic-gate 	int		*ul_errnop;	/* pointer to errno or self->ul_errno */
5297c478bd9Sstevel@tonic-gate 	__cleanup_t	*ul_clnup_hdr;	/* head of cleanup handlers list */
5307c478bd9Sstevel@tonic-gate 	uberflags_t *volatile ul_schedctl_called; /* ul_schedctl is set up */
5317c478bd9Sstevel@tonic-gate 	volatile sc_shared_t *volatile ul_schedctl;	/* schedctl data */
5327c478bd9Sstevel@tonic-gate 	int		ul_bindflags;	/* bind_guard() interface to ld.so.1 */
533*a574db85Sraf 	uint_t		ul_libc_locks;	/* count of cancel_safe_mutex_lock()s */
5347c478bd9Sstevel@tonic-gate 	tsd_t		*ul_stsd;	/* slow TLS for keys >= TSD_NFAST */
5357c478bd9Sstevel@tonic-gate 	void		*ul_ftsd[TSD_NFAST]; /* fast TLS for keys < TSD_NFAST */
5367c478bd9Sstevel@tonic-gate 	td_evbuf_t	ul_td_evbuf;	/* event buffer */
5377c478bd9Sstevel@tonic-gate 	char		ul_td_events_enable;	/* event mechanism enabled */
5387c478bd9Sstevel@tonic-gate 	char		ul_sync_obj_reg;	/* tdb_sync_obj_register() */
5397c478bd9Sstevel@tonic-gate 	char		ul_qtype;	/* MX or CV */
5407c478bd9Sstevel@tonic-gate 	char		ul_cv_wake;	/* != 0: just wake up, don't requeue */
5417c478bd9Sstevel@tonic-gate 	int		ul_usropts;	/* flags given to thr_create() */
5427c478bd9Sstevel@tonic-gate 	void		*(*ul_startpc)(void *); /* start func (thr_create()) */
5437c478bd9Sstevel@tonic-gate 	void		*ul_startarg;	/* argument for start function */
5447c478bd9Sstevel@tonic-gate 	void		*ul_wchan;	/* synch object when sleeping */
5457c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_link;	/* sleep queue link */
5467c478bd9Sstevel@tonic-gate 	queue_head_t	*ul_sleepq;	/* sleep queue thread is waiting on */
5477c478bd9Sstevel@tonic-gate 	mutex_t		*ul_cvmutex;	/* mutex dropped when waiting on a cv */
5487c478bd9Sstevel@tonic-gate 	mxchain_t	*ul_mxchain;	/* chain of owned ceiling mutexes */
5497c478bd9Sstevel@tonic-gate 	pri_t		ul_epri;	/* effective scheduling priority */
5507c478bd9Sstevel@tonic-gate 	pri_t		ul_emappedpri;	/* effective mapped priority */
551883492d5Sraf 	uint_t		ul_rdlockcnt;	/* # entries in ul_readlock array */
552883492d5Sraf 				/* 0 means there is but a single entry */
553883492d5Sraf 	union {				/* single entry or pointer to array */
5547c478bd9Sstevel@tonic-gate 		readlock_t	single;
5557c478bd9Sstevel@tonic-gate 		readlock_t	*array;
5567c478bd9Sstevel@tonic-gate 	} ul_readlock;
557883492d5Sraf 	uint_t		ul_heldlockcnt;	/* # entries in ul_heldlocks array */
558883492d5Sraf 				/* 0 means there is but a single entry */
559883492d5Sraf 	union {				/* single entry or pointer to array */
560883492d5Sraf 		mutex_t		*single;
561883492d5Sraf 		mutex_t		**array;
562883492d5Sraf 	} ul_heldlocks;
5637c478bd9Sstevel@tonic-gate 	/* PROBE_SUPPORT begin */
5647c478bd9Sstevel@tonic-gate 	void		*ul_tpdp;
5657c478bd9Sstevel@tonic-gate 	/* PROBE_SUPPORT end */
5667c478bd9Sstevel@tonic-gate 	ucontext_t	*ul_siglink;	/* pointer to previous context */
5677c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_spin;	/* spin lock statistics */
5687c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_spin2;
5697c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_sleep;
5707c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_wakeup;
5717c478bd9Sstevel@tonic-gate 		/* the following members *must* be last in the structure */
5727c478bd9Sstevel@tonic-gate 		/* they are discarded when ulwp is replaced on thr_exit() */
5737c478bd9Sstevel@tonic-gate 	sigset_t	ul_sigmask;	/* thread's current signal mask */
5747c478bd9Sstevel@tonic-gate 	sigset_t	ul_tmpmask;	/* signal mask for sigsuspend/pollsys */
5757c478bd9Sstevel@tonic-gate 	siginfo_t	ul_siginfo;	/* deferred siginfo */
5767c478bd9Sstevel@tonic-gate 	mutex_t		ul_spinlock;	/* used when suspending/continuing */
5777c478bd9Sstevel@tonic-gate 	fpuenv_t	ul_fpuenv;	/* floating point state */
5787c478bd9Sstevel@tonic-gate 	uintptr_t	ul_sp;		/* stack pointer when blocked */
5797c478bd9Sstevel@tonic-gate 	void		*ul_ex_unwind;	/* address of _ex_unwind() or -1 */
5807c478bd9Sstevel@tonic-gate #if defined(sparc)
5817c478bd9Sstevel@tonic-gate 	void		*ul_unwind_ret;	/* used only by _ex_clnup_handler() */
5827c478bd9Sstevel@tonic-gate #endif
5837c478bd9Sstevel@tonic-gate } ulwp_t;
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate #define	ul_cursig	ul_cp.s.cursig		/* deferred signal number */
5867c478bd9Sstevel@tonic-gate #define	ul_pleasestop	ul_cp.s.pleasestop	/* lwp requested to stop */
5877c478bd9Sstevel@tonic-gate #define	ul_curplease	ul_cp.curplease		/* for testing both at once */
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate /*
5907c478bd9Sstevel@tonic-gate  * This is the size of a replacement ulwp, retained only for the benefit
5917c478bd9Sstevel@tonic-gate  * of thr_join().  The trailing members are unneeded for this purpose.
5927c478bd9Sstevel@tonic-gate  */
5937c478bd9Sstevel@tonic-gate #define	REPLACEMENT_SIZE	((size_t)&((ulwp_t *)NULL)->ul_sigmask)
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate /*
5967c478bd9Sstevel@tonic-gate  * Definitions for static initialization of signal sets,
5977c478bd9Sstevel@tonic-gate  * plus some sneaky optimizations in various places.
5987c478bd9Sstevel@tonic-gate  */
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate #define	SIGMASK(sig)	((uint32_t)1 << (((sig) - 1) & (32 - 1)))
6017c478bd9Sstevel@tonic-gate 
6027c478bd9Sstevel@tonic-gate #if (MAXSIG > 32 && MAXSIG <= 64)
6037c478bd9Sstevel@tonic-gate #define	FILLSET0	0xffffffffu
6047c478bd9Sstevel@tonic-gate #define	FILLSET1	((1u << (MAXSIG - 32)) - 1)
6057c478bd9Sstevel@tonic-gate #else
6067c478bd9Sstevel@tonic-gate #error "fix me: MAXSIG out of bounds"
6077c478bd9Sstevel@tonic-gate #endif
6087c478bd9Sstevel@tonic-gate 
6097c478bd9Sstevel@tonic-gate #define	CANTMASK0	(SIGMASK(SIGKILL) | SIGMASK(SIGSTOP))
6107c478bd9Sstevel@tonic-gate #define	CANTMASK1	0
6117c478bd9Sstevel@tonic-gate 
6127c478bd9Sstevel@tonic-gate #define	MASKSET0	(FILLSET0 & ~CANTMASK0)
6137c478bd9Sstevel@tonic-gate #define	MASKSET1	(FILLSET1 & ~CANTMASK1)
6147c478bd9Sstevel@tonic-gate 
615f841f6adSraf extern	const sigset_t maskset;		/* set of all maskable signals */
6167c478bd9Sstevel@tonic-gate 
6177c478bd9Sstevel@tonic-gate extern	int	thread_adaptive_spin;
6187c478bd9Sstevel@tonic-gate extern	uint_t	thread_max_spinners;
6197c478bd9Sstevel@tonic-gate extern	int	thread_queue_spin;
6207c478bd9Sstevel@tonic-gate extern	int	thread_queue_fifo;
6217c478bd9Sstevel@tonic-gate extern	int	thread_queue_dump;
6227c478bd9Sstevel@tonic-gate extern	int	thread_cond_wait_defer;
6237c478bd9Sstevel@tonic-gate extern	int	thread_async_safe;
6247c478bd9Sstevel@tonic-gate extern	int	thread_queue_verify;
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate /*
6277c478bd9Sstevel@tonic-gate  * pthread_atfork() related data, used to store atfork handlers.
6287c478bd9Sstevel@tonic-gate  */
6297c478bd9Sstevel@tonic-gate typedef struct atfork {
6307c478bd9Sstevel@tonic-gate 	struct atfork *forw;		/* forward pointer */
6317c478bd9Sstevel@tonic-gate 	struct atfork *back;		/* backward pointer */
6327c478bd9Sstevel@tonic-gate 	void (*prepare)(void);		/* pre-fork handler */
6337c478bd9Sstevel@tonic-gate 	void (*parent)(void);		/* post-fork parent handler */
6347c478bd9Sstevel@tonic-gate 	void (*child)(void);		/* post-fork child handler */
6357c478bd9Sstevel@tonic-gate } atfork_t;
6367c478bd9Sstevel@tonic-gate 
637883492d5Sraf /*
638883492d5Sraf  * Element in the table of registered process robust locks.
639883492d5Sraf  * We keep track of these to make sure that we only call
640883492d5Sraf  * ___lwp_mutex_register() once for each such lock.
641883492d5Sraf  */
642883492d5Sraf typedef struct robust {
643883492d5Sraf 	struct robust	*robust_next;
644883492d5Sraf 	mutex_t		*robust_lock;
645883492d5Sraf } robust_t;
646883492d5Sraf 
647883492d5Sraf /*
648883492d5Sraf  * Parameters of the lock registration hash table.
649883492d5Sraf  */
650883492d5Sraf #define	LOCKSHIFT	9			/* number of hashing bits */
651883492d5Sraf #define	LOCKHASHSZ	(1 << LOCKSHIFT)	/* power of 2 (1<<9 == 512) */
652883492d5Sraf #define	LOCK_HASH(addr)	(uint_t)			\
653883492d5Sraf 	((((uintptr_t)(addr) >> 3)			\
654883492d5Sraf 	^ ((uintptr_t)(addr) >> (LOCKSHIFT + 3)))	\
655883492d5Sraf 	& (LOCKHASHSZ - 1))
656883492d5Sraf 
6577c478bd9Sstevel@tonic-gate /*
6587c478bd9Sstevel@tonic-gate  * Make our hot locks reside on private cache lines (64 bytes).
6597c478bd9Sstevel@tonic-gate  */
6607c478bd9Sstevel@tonic-gate typedef struct {
6617c478bd9Sstevel@tonic-gate 	mutex_t	pad_lock;
6622e145884Sraf 	char	pad_pad[64 - sizeof (mutex_t)];
6637c478bd9Sstevel@tonic-gate } pad_lock_t;
6647c478bd9Sstevel@tonic-gate 
6652e145884Sraf /*
6662e145884Sraf  * Make our semi-hot locks reside on semi-private cache lines (32 bytes).
6672e145884Sraf  */
6682e145884Sraf typedef struct {
6692e145884Sraf 	mutex_t	pad_lock;
6702e145884Sraf 	char	pad_pad[32 - sizeof (mutex_t)];
6712e145884Sraf } pad32_lock_t;
6722e145884Sraf 
6737c478bd9Sstevel@tonic-gate /*
6747c478bd9Sstevel@tonic-gate  * The threads hash table is used for fast lookup and locking of an active
6757c478bd9Sstevel@tonic-gate  * thread structure (ulwp_t) given a thread-id.  It is an N-element array of
6767c478bd9Sstevel@tonic-gate  * thr_hash_table_t structures, where N == 1 before the main thread creates
6777c478bd9Sstevel@tonic-gate  * the first additional thread and N == 1024 afterwards.  Each element of the
6787c478bd9Sstevel@tonic-gate  * table is 64 bytes in size and alignment to reduce cache conflicts.
6797c478bd9Sstevel@tonic-gate  */
6807c478bd9Sstevel@tonic-gate typedef struct {
6817c478bd9Sstevel@tonic-gate 	mutex_t	hash_lock;	/* lock per bucket */
6827c478bd9Sstevel@tonic-gate 	cond_t	hash_cond;	/* convar per bucket */
6837c478bd9Sstevel@tonic-gate 	ulwp_t	*hash_bucket;	/* hash bucket points to the list of ulwps */
6847c478bd9Sstevel@tonic-gate 	char	hash_pad[64 -	/* pad out to 64 bytes */
6857c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (cond_t) + sizeof (ulwp_t *))];
6867c478bd9Sstevel@tonic-gate } thr_hash_table_t;
6877c478bd9Sstevel@tonic-gate 
6887c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
6897c478bd9Sstevel@tonic-gate typedef struct {
6907c478bd9Sstevel@tonic-gate 	mutex_t	hash_lock;
6917c478bd9Sstevel@tonic-gate 	cond_t	hash_cond;
6927c478bd9Sstevel@tonic-gate 	caddr32_t hash_bucket;
6937c478bd9Sstevel@tonic-gate 	char	hash_pad[64 -
6947c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (cond_t) + sizeof (caddr32_t))];
6957c478bd9Sstevel@tonic-gate } thr_hash_table32_t;
6967c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
6977c478bd9Sstevel@tonic-gate 
6987c478bd9Sstevel@tonic-gate 
6997c478bd9Sstevel@tonic-gate /*
70041efec22Sraf  * siguaction members have 128-byte size and 64-byte alignment.
70141efec22Sraf  * We know that sizeof (struct sigaction) is 32 bytes for both
70241efec22Sraf  * _ILP32 and _LP64 and that sizeof (rwlock_t) is 64 bytes.
7037c478bd9Sstevel@tonic-gate  */
7047c478bd9Sstevel@tonic-gate typedef struct {
70541efec22Sraf 	rwlock_t	sig_lock;
7067c478bd9Sstevel@tonic-gate 	struct sigaction sig_uaction;
70741efec22Sraf 	char	sig_pad[128 - sizeof (rwlock_t) - sizeof (struct sigaction)];
7087c478bd9Sstevel@tonic-gate } siguaction_t;
7097c478bd9Sstevel@tonic-gate 
7107c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
7117c478bd9Sstevel@tonic-gate typedef struct {
71241efec22Sraf 	rwlock_t	sig_lock;
7137c478bd9Sstevel@tonic-gate 	struct sigaction32 sig_uaction;
71441efec22Sraf 	char	sig_pad[128 - sizeof (rwlock_t) - sizeof (struct sigaction32)];
7157c478bd9Sstevel@tonic-gate } siguaction32_t;
7167c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
7177c478bd9Sstevel@tonic-gate 
7187c478bd9Sstevel@tonic-gate 
7197c478bd9Sstevel@tonic-gate /*
7207c478bd9Sstevel@tonic-gate  * Bucket structures, used by lmalloc()/lfree().
7217c478bd9Sstevel@tonic-gate  * See port/threads/alloc.c for details.
7227c478bd9Sstevel@tonic-gate  * A bucket's size and alignment is 64 bytes.
7237c478bd9Sstevel@tonic-gate  */
7247c478bd9Sstevel@tonic-gate typedef struct {
7257c478bd9Sstevel@tonic-gate 	mutex_t	bucket_lock;	/* protects the free list allocations */
7267c478bd9Sstevel@tonic-gate 	void	*free_list;	/* LIFO list of blocks to allocate/free */
7277c478bd9Sstevel@tonic-gate 	size_t	chunks;		/* number of 64K blocks mmap()ed last time */
7287c478bd9Sstevel@tonic-gate 	char	pad64[64 -	/* pad out to 64 bytes */
7297c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (void *) + sizeof (size_t))];
7307c478bd9Sstevel@tonic-gate } bucket_t;
7317c478bd9Sstevel@tonic-gate 
7327c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
7337c478bd9Sstevel@tonic-gate typedef struct {
7347c478bd9Sstevel@tonic-gate 	mutex_t		bucket_lock;
7357c478bd9Sstevel@tonic-gate 	caddr32_t	free_list;
7367c478bd9Sstevel@tonic-gate 	size32_t	chunks;
7377c478bd9Sstevel@tonic-gate 	char	pad64[64 -	/* pad out to 64 bytes */
7387c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (caddr32_t) + sizeof (size32_t))];
7397c478bd9Sstevel@tonic-gate } bucket32_t;
7407c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
7417c478bd9Sstevel@tonic-gate 
7427c478bd9Sstevel@tonic-gate #define	NBUCKETS	10	/* sizes ranging from 64 to 32768 */
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate 
7457c478bd9Sstevel@tonic-gate /*
7467c478bd9Sstevel@tonic-gate  * atexit() data structures.
7477c478bd9Sstevel@tonic-gate  * See port/gen/atexit.c for details.
7487c478bd9Sstevel@tonic-gate  */
7497c478bd9Sstevel@tonic-gate typedef void (*_exithdlr_func_t) (void);
7507c478bd9Sstevel@tonic-gate 
7517c478bd9Sstevel@tonic-gate typedef struct _exthdlr {
7527c478bd9Sstevel@tonic-gate 	struct _exthdlr 	*next;	/* next in handler list */
7537c478bd9Sstevel@tonic-gate 	_exithdlr_func_t	hdlr;	/* handler itself */
7547c478bd9Sstevel@tonic-gate } _exthdlr_t;
7557c478bd9Sstevel@tonic-gate 
7567c478bd9Sstevel@tonic-gate typedef struct {
7577c478bd9Sstevel@tonic-gate 	mutex_t		exitfns_lock;
7587c478bd9Sstevel@tonic-gate 	_exthdlr_t	*head;
7597c478bd9Sstevel@tonic-gate 	void		*exit_frame_monitor;
7607c478bd9Sstevel@tonic-gate 	char		exit_pad[64 -	/* pad out to 64 bytes */
7617c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (_exthdlr_t *) + sizeof (void *))];
7627c478bd9Sstevel@tonic-gate } atexit_root_t;
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
7657c478bd9Sstevel@tonic-gate typedef struct {
7667c478bd9Sstevel@tonic-gate 	mutex_t		exitfns_lock;
7677c478bd9Sstevel@tonic-gate 	caddr32_t	head;
7687c478bd9Sstevel@tonic-gate 	caddr32_t	exit_frame_monitor;
7697c478bd9Sstevel@tonic-gate 	char		exit_pad[64 -	/* pad out to 64 bytes */
7707c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (caddr32_t) + sizeof (caddr32_t))];
7717c478bd9Sstevel@tonic-gate } atexit_root32_t;
7727c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
7737c478bd9Sstevel@tonic-gate 
7747c478bd9Sstevel@tonic-gate 
7757c478bd9Sstevel@tonic-gate /*
7767c478bd9Sstevel@tonic-gate  * This is data that is global to all link maps (uberdata, aka super-global).
7777c478bd9Sstevel@tonic-gate  */
7787c478bd9Sstevel@tonic-gate typedef struct uberdata {
7797c478bd9Sstevel@tonic-gate 	pad_lock_t	_link_lock;
7802e145884Sraf 	pad32_lock_t	_fork_lock;
7812e145884Sraf 	pad32_lock_t	_atfork_lock;
78298c1a6b4Sraf 	pad32_lock_t	_callout_lock;
78398c1a6b4Sraf 	pad32_lock_t	_tdb_hash_lock;
7847c478bd9Sstevel@tonic-gate 	tdb_sync_stats_t tdb_hash_lock_stats;
7857c478bd9Sstevel@tonic-gate 	siguaction_t	siguaction[NSIG];
7867c478bd9Sstevel@tonic-gate 	bucket_t	bucket[NBUCKETS];
7877c478bd9Sstevel@tonic-gate 	atexit_root_t	atexit_root;
7887c478bd9Sstevel@tonic-gate 	tsd_metadata_t	tsd_metadata;
7897c478bd9Sstevel@tonic-gate 	tls_metadata_t	tls_metadata;
7907c478bd9Sstevel@tonic-gate 	/*
7917c478bd9Sstevel@tonic-gate 	 * Every object before this point has size and alignment of 64 bytes.
7927c478bd9Sstevel@tonic-gate 	 * Don't add any other type of data before this point.
7937c478bd9Sstevel@tonic-gate 	 */
7947c478bd9Sstevel@tonic-gate 	char	primary_map;	/* set when primary link map is initialized */
7957c478bd9Sstevel@tonic-gate 	char	bucket_init;	/* set when bucket[NBUCKETS] is initialized */
7967c478bd9Sstevel@tonic-gate 	char	pad[2];
7977c478bd9Sstevel@tonic-gate 	uberflags_t	uberflags;
7987c478bd9Sstevel@tonic-gate 	queue_head_t	*queue_head;
7997c478bd9Sstevel@tonic-gate 	thr_hash_table_t *thr_hash_table;
8007c478bd9Sstevel@tonic-gate 	uint_t		hash_size;	/* # of entries in thr_hash_table[] */
8017c478bd9Sstevel@tonic-gate 	uint_t		hash_mask;	/* hash_size - 1 */
8027c478bd9Sstevel@tonic-gate 	ulwp_t	*ulwp_one;	/* main thread */
8037c478bd9Sstevel@tonic-gate 	ulwp_t	*all_lwps;	/* circular ul_forw/ul_back list of live lwps */
8047c478bd9Sstevel@tonic-gate 	ulwp_t	*all_zombies;	/* circular ul_forw/ul_back list of zombies */
8057c478bd9Sstevel@tonic-gate 	int	nthreads;	/* total number of live threads/lwps */
8067c478bd9Sstevel@tonic-gate 	int	nzombies;	/* total number of zombie threads */
8077c478bd9Sstevel@tonic-gate 	int	ndaemons;	/* total number of THR_DAEMON threads/lwps */
8087c478bd9Sstevel@tonic-gate 	pid_t	pid;		/* the current process's pid */
8097c478bd9Sstevel@tonic-gate 	void	(*sigacthandler)(int, siginfo_t *, void *);
8107c478bd9Sstevel@tonic-gate 	ulwp_t	*lwp_stacks;
8117c478bd9Sstevel@tonic-gate 	ulwp_t	*lwp_laststack;
8127c478bd9Sstevel@tonic-gate 	int	nfreestack;
8137c478bd9Sstevel@tonic-gate 	int	thread_stack_cache;
8147c478bd9Sstevel@tonic-gate 	ulwp_t	*ulwp_freelist;
8157c478bd9Sstevel@tonic-gate 	ulwp_t	*ulwp_lastfree;
8167c478bd9Sstevel@tonic-gate 	ulwp_t	*ulwp_replace_free;
8177c478bd9Sstevel@tonic-gate 	ulwp_t	*ulwp_replace_last;
8187c478bd9Sstevel@tonic-gate 	atfork_t	*atforklist;	/* circular Q for fork handlers */
819883492d5Sraf 	robust_t	**robustlocks;	/* table of registered robust locks */
8207c478bd9Sstevel@tonic-gate 	struct uberdata **tdb_bootstrap;
8217c478bd9Sstevel@tonic-gate 	tdb_t	tdb;		/* thread debug interfaces (for libc_db) */
8227c478bd9Sstevel@tonic-gate } uberdata_t;
8237c478bd9Sstevel@tonic-gate 
8247c478bd9Sstevel@tonic-gate #define	link_lock	_link_lock.pad_lock
8257c478bd9Sstevel@tonic-gate #define	fork_lock	_fork_lock.pad_lock
8262e145884Sraf #define	atfork_lock	_atfork_lock.pad_lock
82798c1a6b4Sraf #define	callout_lock	_callout_lock.pad_lock
8287c478bd9Sstevel@tonic-gate #define	tdb_hash_lock	_tdb_hash_lock.pad_lock
8297c478bd9Sstevel@tonic-gate 
8307c478bd9Sstevel@tonic-gate #pragma align 64(__uberdata)
8317c478bd9Sstevel@tonic-gate extern	uberdata_t	__uberdata;
8327c478bd9Sstevel@tonic-gate extern	uberdata_t	**__tdb_bootstrap;	/* known to libc_db and mdb */
8337c478bd9Sstevel@tonic-gate extern	int		primary_link_map;
8347c478bd9Sstevel@tonic-gate 
8357c478bd9Sstevel@tonic-gate #define	ulwp_mutex(ulwp, udp)	\
8367c478bd9Sstevel@tonic-gate 	(&(udp)->thr_hash_table[(ulwp)->ul_ix].hash_lock)
8377c478bd9Sstevel@tonic-gate #define	ulwp_condvar(ulwp, udp)	\
8387c478bd9Sstevel@tonic-gate 	(&(udp)->thr_hash_table[(ulwp)->ul_ix].hash_cond)
8397c478bd9Sstevel@tonic-gate 
8407c478bd9Sstevel@tonic-gate /*
8417c478bd9Sstevel@tonic-gate  * Grab and release the hash table lock for the specified lwp.
8427c478bd9Sstevel@tonic-gate  */
8437c478bd9Sstevel@tonic-gate #define	ulwp_lock(ulwp, udp)	lmutex_lock(ulwp_mutex(ulwp, udp))
8447c478bd9Sstevel@tonic-gate #define	ulwp_unlock(ulwp, udp)	lmutex_unlock(ulwp_mutex(ulwp, udp))
8457c478bd9Sstevel@tonic-gate 
8467c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32	/* needed by libc_db */
8477c478bd9Sstevel@tonic-gate 
8487c478bd9Sstevel@tonic-gate typedef struct ulwp32 {
8497c478bd9Sstevel@tonic-gate #if defined(__sparc)
8507c478bd9Sstevel@tonic-gate 	uint32_t	ul_dinstr;	/* scratch space for dtrace */
8517c478bd9Sstevel@tonic-gate 	uint32_t	ul_padsparc0[15];
8527c478bd9Sstevel@tonic-gate 	uint32_t	ul_dsave;	/* dtrace: save %g1, %g0, %sp */
8537c478bd9Sstevel@tonic-gate 	uint32_t	ul_drestore;	/* dtrace: restore %g0, %g0, %g0 */
8547c478bd9Sstevel@tonic-gate 	uint32_t	ul_dftret;	/* dtrace: return probe fasttrap */
8557c478bd9Sstevel@tonic-gate 	uint32_t	ul_dreturn;	/* dtrace: return %o0 */
8567c478bd9Sstevel@tonic-gate #endif
8577c478bd9Sstevel@tonic-gate 	caddr32_t	ul_self;	/* pointer to self */
8580ec57554Sraf #if defined(__x86)
8597c478bd9Sstevel@tonic-gate 	uint8_t		ul_dinstr[40];	/* scratch space for dtrace */
8607c478bd9Sstevel@tonic-gate #endif
8617c478bd9Sstevel@tonic-gate 	caddr32_t	ul_uberdata;	/* uber (super-global) data */
8627c478bd9Sstevel@tonic-gate 	tls32_t		ul_tls;		/* dynamic thread-local storage base */
8637c478bd9Sstevel@tonic-gate 	caddr32_t	ul_forw;	/* forw, back all_lwps list, */
8647c478bd9Sstevel@tonic-gate 	caddr32_t	ul_back;	/* protected by link_lock */
8657c478bd9Sstevel@tonic-gate 	caddr32_t	ul_next;	/* list to keep track of stacks */
8667c478bd9Sstevel@tonic-gate 	caddr32_t	ul_hash;	/* hash chain linked list */
8677c478bd9Sstevel@tonic-gate 	caddr32_t	ul_rval;	/* return value from thr_exit() */
8687c478bd9Sstevel@tonic-gate 	caddr32_t	ul_stk;		/* mapping base of the stack */
8697c478bd9Sstevel@tonic-gate 	size32_t	ul_mapsiz;	/* mapping size of the stack */
8707c478bd9Sstevel@tonic-gate 	size32_t	ul_guardsize;	/* normally _lpagesize */
8717c478bd9Sstevel@tonic-gate 	caddr32_t	ul_stktop;	/* broken thr_stksegment() interface */
8727c478bd9Sstevel@tonic-gate 	size32_t	ul_stksiz;	/* broken thr_stksegment() interface */
8737c478bd9Sstevel@tonic-gate 	stack32_t	ul_ustack;	/* current stack boundaries */
8747c478bd9Sstevel@tonic-gate 	int		ul_ix;		/* hash index */
8757c478bd9Sstevel@tonic-gate 	lwpid_t		ul_lwpid;	/* thread id, aka the lwp id */
8767c478bd9Sstevel@tonic-gate 	pri_t		ul_pri;		/* priority known to the library */
8777c478bd9Sstevel@tonic-gate 	pri_t		ul_mappedpri;	/* priority known to the application */
8787c478bd9Sstevel@tonic-gate 	char		ul_policy;	/* scheduling policy */
8797c478bd9Sstevel@tonic-gate 	char		ul_pri_mapped;	/* != 0 means ul_mappedpri is valid */
8807c478bd9Sstevel@tonic-gate 	union {
8817c478bd9Sstevel@tonic-gate 		struct {
8827c478bd9Sstevel@tonic-gate 			char	cursig;	/* deferred signal number */
8837c478bd9Sstevel@tonic-gate 			char	pleasestop; /* lwp requested to stop itself */
8847c478bd9Sstevel@tonic-gate 		} s;
8857c478bd9Sstevel@tonic-gate 		short	curplease;	/* for testing both at once */
8867c478bd9Sstevel@tonic-gate 	} ul_cp;
8877c478bd9Sstevel@tonic-gate 	char		ul_stop;	/* reason for stopping */
8887c478bd9Sstevel@tonic-gate 	char		ul_signalled;	/* this lwp was cond_signal()d */
8897c478bd9Sstevel@tonic-gate 	char		ul_dead;	/* this lwp has called thr_exit */
8907c478bd9Sstevel@tonic-gate 	char		ul_unwind;	/* posix: unwind C++ stack */
8917c478bd9Sstevel@tonic-gate 	char		ul_detached;	/* THR_DETACHED at thread_create() */
8927c478bd9Sstevel@tonic-gate 					/* or pthread_detach() was called */
8937c478bd9Sstevel@tonic-gate 	char		ul_writer;	/* sleeping in rw_wrlock() */
8947c478bd9Sstevel@tonic-gate 	char		ul_stopping;	/* set by curthread: stopping self */
89534709573Sraf 	char		ul_cancel_prologue;	/* for _cancel_prologue() */
8967c478bd9Sstevel@tonic-gate 	short		ul_preempt;	/* no_preempt()/preempt() */
8977c478bd9Sstevel@tonic-gate 	short		ul_savpreempt;	/* pre-existing preempt value */
8987c478bd9Sstevel@tonic-gate 	char		ul_sigsuspend;	/* thread is in sigsuspend/pollsys */
8997c478bd9Sstevel@tonic-gate 	char		ul_main;	/* thread is the main thread */
9007c478bd9Sstevel@tonic-gate 	char		ul_fork;	/* thread is performing a fork */
9017c478bd9Sstevel@tonic-gate 	char		ul_primarymap;	/* primary link-map is initialized */
9027c478bd9Sstevel@tonic-gate 	/* per-thread copies of the corresponding global variables */
9035d1dd9a9Sraf 	uint8_t		ul_max_spinners;	/* thread_max_spinners */
9047c478bd9Sstevel@tonic-gate 	char		ul_door_noreserve;	/* thread_door_noreserve */
9057c478bd9Sstevel@tonic-gate 	char		ul_queue_fifo;		/* thread_queue_fifo */
9067c478bd9Sstevel@tonic-gate 	char		ul_cond_wait_defer;	/* thread_cond_wait_defer */
9077c478bd9Sstevel@tonic-gate 	char		ul_error_detection;	/* thread_error_detection */
9087c478bd9Sstevel@tonic-gate 	char		ul_async_safe;		/* thread_async_safe */
909*a574db85Sraf 	char		ul_pad1;
910*a574db85Sraf 	char		ul_save_state;	/* bind_guard() interface to ld.so.1 */
9117c478bd9Sstevel@tonic-gate 	int		ul_adaptive_spin;	/* thread_adaptive_spin */
9127c478bd9Sstevel@tonic-gate 	int		ul_queue_spin;		/* thread_queue_spin */
9137c478bd9Sstevel@tonic-gate 	int		ul_critical;	/* non-zero == in a critical region */
9147c478bd9Sstevel@tonic-gate 	int		ul_sigdefer;	/* non-zero == defer signals */
9157c478bd9Sstevel@tonic-gate 	int		ul_vfork;	/* thread is the child of vfork() */
9167c478bd9Sstevel@tonic-gate 	int		ul_cancelable;	/* _cancelon()/_canceloff() */
9177c478bd9Sstevel@tonic-gate 	char		ul_cancel_pending;  /* pthread_cancel() was called */
9187c478bd9Sstevel@tonic-gate 	char		ul_cancel_disabled; /* PTHREAD_CANCEL_DISABLE */
9197c478bd9Sstevel@tonic-gate 	char		ul_cancel_async;    /* PTHREAD_CANCEL_ASYNCHRONOUS */
9207c478bd9Sstevel@tonic-gate 	char		ul_save_async;	/* saved copy of ul_cancel_async */
9217c478bd9Sstevel@tonic-gate 	char		ul_mutator;	/* lwp is a mutator (java interface) */
9227c478bd9Sstevel@tonic-gate 	char		ul_created;	/* created suspended */
9237c478bd9Sstevel@tonic-gate 	char		ul_replace;	/* replacement; must be free()d */
9247c478bd9Sstevel@tonic-gate 	uchar_t		ul_nocancel;	/* cancellation can't happen */
9257c478bd9Sstevel@tonic-gate 	int		ul_errno;	/* per-thread errno */
9267c478bd9Sstevel@tonic-gate 	caddr32_t	ul_errnop;	/* pointer to errno or self->ul_errno */
9277c478bd9Sstevel@tonic-gate 	caddr32_t	ul_clnup_hdr;	/* head of cleanup handlers list */
9287c478bd9Sstevel@tonic-gate 	caddr32_t	ul_schedctl_called; /* ul_schedctl is set up */
9297c478bd9Sstevel@tonic-gate 	caddr32_t	ul_schedctl;	/* schedctl data */
9307c478bd9Sstevel@tonic-gate 	int		ul_bindflags;	/* bind_guard() interface to ld.so.1 */
931*a574db85Sraf 	uint_t		ul_libc_locks;	/* count of cancel_safe_mutex_lock()s */
9327c478bd9Sstevel@tonic-gate 	caddr32_t	ul_stsd;	/* slow TLS for keys >= TSD_NFAST */
9337c478bd9Sstevel@tonic-gate 	caddr32_t	ul_ftsd[TSD_NFAST]; /* fast TLS for keys < TSD_NFAST */
9347c478bd9Sstevel@tonic-gate 	td_evbuf32_t	ul_td_evbuf;	/* event buffer */
9357c478bd9Sstevel@tonic-gate 	char		ul_td_events_enable;	/* event mechanism enabled */
9367c478bd9Sstevel@tonic-gate 	char		ul_sync_obj_reg;	/* tdb_sync_obj_register() */
9377c478bd9Sstevel@tonic-gate 	char		ul_qtype;	/* MX or CV */
9387c478bd9Sstevel@tonic-gate 	char		ul_cv_wake;	/* != 0: just wake up, don't requeue */
9397c478bd9Sstevel@tonic-gate 	int		ul_usropts;	/* flags given to thr_create() */
9407c478bd9Sstevel@tonic-gate 	caddr32_t	ul_startpc;	/* start func (thr_create()) */
9417c478bd9Sstevel@tonic-gate 	caddr32_t	ul_startarg;	/* argument for start function */
9427c478bd9Sstevel@tonic-gate 	caddr32_t	ul_wchan;	/* synch object when sleeping */
9437c478bd9Sstevel@tonic-gate 	caddr32_t	ul_link;	/* sleep queue link */
9447c478bd9Sstevel@tonic-gate 	caddr32_t	ul_sleepq;	/* sleep queue thread is waiting on */
9457c478bd9Sstevel@tonic-gate 	caddr32_t	ul_cvmutex;	/* mutex dropped when waiting on a cv */
9467c478bd9Sstevel@tonic-gate 	caddr32_t	ul_mxchain;	/* chain of owned ceiling mutexes */
9477c478bd9Sstevel@tonic-gate 	pri_t		ul_epri;	/* effective scheduling priority */
9487c478bd9Sstevel@tonic-gate 	pri_t		ul_emappedpri;	/* effective mapped priority */
949883492d5Sraf 	uint_t		ul_rdlockcnt;	/* # entries in ul_readlock array */
950883492d5Sraf 				/* 0 means there is but a single entry */
951883492d5Sraf 	union {				/* single entry or pointer to array */
9527c478bd9Sstevel@tonic-gate 		readlock32_t	single;
9537c478bd9Sstevel@tonic-gate 		caddr32_t	array;
9547c478bd9Sstevel@tonic-gate 	} ul_readlock;
955883492d5Sraf 	uint_t		ul_heldlockcnt;	/* # entries in ul_heldlocks array */
956883492d5Sraf 				/* 0 means there is but a single entry */
957883492d5Sraf 	union {				/* single entry or pointer to array */
958883492d5Sraf 		caddr32_t	single;
959883492d5Sraf 		caddr32_t	array;
960883492d5Sraf 	} ul_heldlocks;
9617c478bd9Sstevel@tonic-gate 	/* PROBE_SUPPORT begin */
9627c478bd9Sstevel@tonic-gate 	caddr32_t	ul_tpdp;
9637c478bd9Sstevel@tonic-gate 	/* PROBE_SUPPORT end */
9647c478bd9Sstevel@tonic-gate 	caddr32_t	ul_siglink;	/* pointer to previous context */
9657c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_spin;	/* spin lock statistics */
9667c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_spin2;
9677c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_sleep;
9687c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_wakeup;
9697c478bd9Sstevel@tonic-gate 		/* the following members *must* be last in the structure */
9707c478bd9Sstevel@tonic-gate 		/* they are discarded when ulwp is replaced on thr_exit() */
9717c478bd9Sstevel@tonic-gate 	sigset32_t	ul_sigmask;	/* thread's current signal mask */
9727c478bd9Sstevel@tonic-gate 	sigset32_t	ul_tmpmask;	/* signal mask for sigsuspend/pollsys */
9737c478bd9Sstevel@tonic-gate 	siginfo32_t	ul_siginfo;	/* deferred siginfo */
9747c478bd9Sstevel@tonic-gate 	mutex_t		ul_spinlock;	/* used when suspending/continuing */
9757c478bd9Sstevel@tonic-gate 	fpuenv32_t	ul_fpuenv;	/* floating point state */
9767c478bd9Sstevel@tonic-gate 	caddr32_t	ul_sp;		/* stack pointer when blocked */
9777c478bd9Sstevel@tonic-gate #if defined(sparc)
9787c478bd9Sstevel@tonic-gate 	caddr32_t	ul_unwind_ret;	/* used only by _ex_clnup_handler() */
9797c478bd9Sstevel@tonic-gate #endif
9807c478bd9Sstevel@tonic-gate } ulwp32_t;
9817c478bd9Sstevel@tonic-gate 
9827c478bd9Sstevel@tonic-gate #define	REPLACEMENT_SIZE32	((size_t)&((ulwp32_t *)NULL)->ul_sigmask)
9837c478bd9Sstevel@tonic-gate 
9847c478bd9Sstevel@tonic-gate typedef struct uberdata32 {
9857c478bd9Sstevel@tonic-gate 	pad_lock_t	_link_lock;
9862e145884Sraf 	pad32_lock_t	_fork_lock;
9872e145884Sraf 	pad32_lock_t	_atfork_lock;
98898c1a6b4Sraf 	pad32_lock_t	_callout_lock;
98998c1a6b4Sraf 	pad32_lock_t	_tdb_hash_lock;
9907c478bd9Sstevel@tonic-gate 	tdb_sync_stats_t tdb_hash_lock_stats;
9917c478bd9Sstevel@tonic-gate 	siguaction32_t	siguaction[NSIG];
9927c478bd9Sstevel@tonic-gate 	bucket32_t	bucket[NBUCKETS];
9937c478bd9Sstevel@tonic-gate 	atexit_root32_t	atexit_root;
9947c478bd9Sstevel@tonic-gate 	tsd_metadata32_t tsd_metadata;
9957c478bd9Sstevel@tonic-gate 	tls_metadata32_t tls_metadata;
9967c478bd9Sstevel@tonic-gate 	char		primary_map;
9977c478bd9Sstevel@tonic-gate 	char		bucket_init;
9987c478bd9Sstevel@tonic-gate 	char		pad[2];
9997c478bd9Sstevel@tonic-gate 	uberflags_t	uberflags;
10007c478bd9Sstevel@tonic-gate 	caddr32_t	queue_head;
10017c478bd9Sstevel@tonic-gate 	caddr32_t	thr_hash_table;
10027c478bd9Sstevel@tonic-gate 	uint_t		hash_size;
10037c478bd9Sstevel@tonic-gate 	uint_t		hash_mask;
10047c478bd9Sstevel@tonic-gate 	caddr32_t	ulwp_one;
10057c478bd9Sstevel@tonic-gate 	caddr32_t	all_lwps;
10067c478bd9Sstevel@tonic-gate 	caddr32_t	all_zombies;
10077c478bd9Sstevel@tonic-gate 	int		nthreads;
10087c478bd9Sstevel@tonic-gate 	int		nzombies;
10097c478bd9Sstevel@tonic-gate 	int		ndaemons;
10107c478bd9Sstevel@tonic-gate 	int		pid;
10117c478bd9Sstevel@tonic-gate 	caddr32_t	sigacthandler;
10127c478bd9Sstevel@tonic-gate 	caddr32_t	lwp_stacks;
10137c478bd9Sstevel@tonic-gate 	caddr32_t	lwp_laststack;
10147c478bd9Sstevel@tonic-gate 	int		nfreestack;
10157c478bd9Sstevel@tonic-gate 	int		thread_stack_cache;
10167c478bd9Sstevel@tonic-gate 	caddr32_t	ulwp_freelist;
10177c478bd9Sstevel@tonic-gate 	caddr32_t	ulwp_lastfree;
10187c478bd9Sstevel@tonic-gate 	caddr32_t	ulwp_replace_free;
10197c478bd9Sstevel@tonic-gate 	caddr32_t	ulwp_replace_last;
10207c478bd9Sstevel@tonic-gate 	caddr32_t	atforklist;
1021883492d5Sraf 	caddr32_t	robustlocks;
10227c478bd9Sstevel@tonic-gate 	caddr32_t	tdb_bootstrap;
10237c478bd9Sstevel@tonic-gate 	tdb32_t		tdb;
10247c478bd9Sstevel@tonic-gate } uberdata32_t;
10257c478bd9Sstevel@tonic-gate 
10267c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate /* ul_stop values */
10297c478bd9Sstevel@tonic-gate #define	TSTP_REGULAR	0x01	/* Stopped by thr_suspend() */
10307c478bd9Sstevel@tonic-gate #define	TSTP_MUTATOR	0x08	/* stopped by thr_suspend_*mutator*() */
10317c478bd9Sstevel@tonic-gate #define	TSTP_FORK	0x20	/* stopped by suspend_fork() */
10327c478bd9Sstevel@tonic-gate 
10337c478bd9Sstevel@tonic-gate /*
10347c478bd9Sstevel@tonic-gate  * Implementation-specific attribute types for pthread_mutexattr_init() etc.
10357c478bd9Sstevel@tonic-gate  */
10367c478bd9Sstevel@tonic-gate 
10377c478bd9Sstevel@tonic-gate typedef	struct	_cvattr {
10387c478bd9Sstevel@tonic-gate 	int	pshared;
10397c478bd9Sstevel@tonic-gate 	clockid_t clockid;
10407c478bd9Sstevel@tonic-gate } cvattr_t;
10417c478bd9Sstevel@tonic-gate 
10427c478bd9Sstevel@tonic-gate typedef	struct	_mattr {
10437c478bd9Sstevel@tonic-gate 	int	pshared;
10447c478bd9Sstevel@tonic-gate 	int	protocol;
10457c478bd9Sstevel@tonic-gate 	int	prioceiling;
10467c478bd9Sstevel@tonic-gate 	int	type;
10477c478bd9Sstevel@tonic-gate 	int	robustness;
10487c478bd9Sstevel@tonic-gate } mattr_t;
10497c478bd9Sstevel@tonic-gate 
10507c478bd9Sstevel@tonic-gate typedef	struct	_thrattr {
10517c478bd9Sstevel@tonic-gate 	size_t	stksize;
10527c478bd9Sstevel@tonic-gate 	void	*stkaddr;
10537c478bd9Sstevel@tonic-gate 	int	detachstate;
105434709573Sraf 	int	daemonstate;
10557c478bd9Sstevel@tonic-gate 	int	scope;
10567c478bd9Sstevel@tonic-gate 	int	prio;
10577c478bd9Sstevel@tonic-gate 	int	policy;
10587c478bd9Sstevel@tonic-gate 	int	inherit;
10597c478bd9Sstevel@tonic-gate 	size_t	guardsize;
10607c478bd9Sstevel@tonic-gate } thrattr_t;
10617c478bd9Sstevel@tonic-gate 
10627c478bd9Sstevel@tonic-gate typedef	struct	_rwlattr {
10637c478bd9Sstevel@tonic-gate 	int	pshared;
10647c478bd9Sstevel@tonic-gate } rwlattr_t;
10657c478bd9Sstevel@tonic-gate 
10667c478bd9Sstevel@tonic-gate /* _curthread() is inline for speed */
10677c478bd9Sstevel@tonic-gate extern	ulwp_t		*_curthread(void);
10687c478bd9Sstevel@tonic-gate #define	curthread	(_curthread())
10697c478bd9Sstevel@tonic-gate 
10707c478bd9Sstevel@tonic-gate /* this version (also inline) can be tested for NULL */
10717c478bd9Sstevel@tonic-gate extern	ulwp_t		*__curthread(void);
10727c478bd9Sstevel@tonic-gate 
10737c478bd9Sstevel@tonic-gate /* get the current stack pointer (also inline) */
10747c478bd9Sstevel@tonic-gate extern	greg_t		stkptr(void);
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate /*
10777c478bd9Sstevel@tonic-gate  * Suppress __attribute__((...)) if we are not compiling with gcc
10787c478bd9Sstevel@tonic-gate  */
10797c478bd9Sstevel@tonic-gate #if !defined(__GNUC__)
10807c478bd9Sstevel@tonic-gate #define	__attribute__(string)
10817c478bd9Sstevel@tonic-gate #endif
10827c478bd9Sstevel@tonic-gate 
10837c478bd9Sstevel@tonic-gate /*
10847c478bd9Sstevel@tonic-gate  * Implementation functions.  Not visible outside of the library itself.
10857c478bd9Sstevel@tonic-gate  */
1086f841f6adSraf extern	int	__nanosleep(const timespec_t *, timespec_t *);
10877c478bd9Sstevel@tonic-gate extern	void	getgregs(ulwp_t *, gregset_t);
10887c478bd9Sstevel@tonic-gate extern	void	setgregs(ulwp_t *, gregset_t);
10897c478bd9Sstevel@tonic-gate extern	void	thr_panic(const char *);
10907c478bd9Sstevel@tonic-gate #pragma rarely_called(thr_panic)
10917c478bd9Sstevel@tonic-gate extern	ulwp_t	*find_lwp(thread_t);
10927c478bd9Sstevel@tonic-gate extern	int	real_priority(ulwp_t *);
10937c478bd9Sstevel@tonic-gate extern	void	finish_init(void);
10947c478bd9Sstevel@tonic-gate extern	void	queue_alloc(void);
10957c478bd9Sstevel@tonic-gate extern	void	tsd_exit(void);
10967c478bd9Sstevel@tonic-gate extern	void	tsd_free(ulwp_t *);
10977c478bd9Sstevel@tonic-gate extern	void	tls_setup(void);
10987c478bd9Sstevel@tonic-gate extern	void	tls_exit(void);
10997c478bd9Sstevel@tonic-gate extern	void	tls_free(ulwp_t *);
11007c478bd9Sstevel@tonic-gate extern	void	rwl_free(ulwp_t *);
1101883492d5Sraf extern	void	heldlock_exit(void);
1102883492d5Sraf extern	void	heldlock_free(ulwp_t *);
11037c478bd9Sstevel@tonic-gate extern	void	sigacthandler(int, siginfo_t *, void *);
11047c478bd9Sstevel@tonic-gate extern	void	signal_init(void);
11057c478bd9Sstevel@tonic-gate extern	int	sigequalset(const sigset_t *, const sigset_t *);
11067c478bd9Sstevel@tonic-gate extern	void	mutex_setup(void);
11077c478bd9Sstevel@tonic-gate extern	void	take_deferred_signal(int);
11087c478bd9Sstevel@tonic-gate extern	int	setup_context(ucontext_t *, void *(*func)(ulwp_t *),
11097c478bd9Sstevel@tonic-gate 			ulwp_t *ulwp, caddr_t stk, size_t stksize);
11107c478bd9Sstevel@tonic-gate extern	volatile sc_shared_t *setup_schedctl(void);
11117c478bd9Sstevel@tonic-gate extern	void	*lmalloc(size_t);
11127c478bd9Sstevel@tonic-gate extern	void	lfree(void *, size_t);
11137c478bd9Sstevel@tonic-gate extern	void	*libc_malloc(size_t);
11147c478bd9Sstevel@tonic-gate extern	void	*libc_realloc(void *, size_t);
11157c478bd9Sstevel@tonic-gate extern	void	libc_free(void *);
11167c478bd9Sstevel@tonic-gate extern	char	*libc_strdup(const char *);
11177c478bd9Sstevel@tonic-gate extern	void	ultos(uint64_t, int, char *);
11187c478bd9Sstevel@tonic-gate extern	void	lock_error(const mutex_t *, const char *, void *, const char *);
11197c478bd9Sstevel@tonic-gate extern	void	rwlock_error(const rwlock_t *, const char *, const char *);
11207c478bd9Sstevel@tonic-gate extern	void	thread_error(const char *);
11217c478bd9Sstevel@tonic-gate extern	void	grab_assert_lock(void);
11227c478bd9Sstevel@tonic-gate extern	void	dump_queue_statistics(void);
11237c478bd9Sstevel@tonic-gate extern	void	collect_queue_statistics(void);
11247c478bd9Sstevel@tonic-gate extern	void	record_spin_locks(ulwp_t *);
1125883492d5Sraf extern	void	remember_lock(mutex_t *);
1126883492d5Sraf extern	void	forget_lock(mutex_t *);
1127883492d5Sraf extern	void	register_lock(mutex_t *);
1128883492d5Sraf extern	void	unregister_locks(void);
11297c478bd9Sstevel@tonic-gate #if defined(__sparc)
11307c478bd9Sstevel@tonic-gate extern	void	_flush_windows(void);
11317c478bd9Sstevel@tonic-gate #else
11327c478bd9Sstevel@tonic-gate #define	_flush_windows()
11337c478bd9Sstevel@tonic-gate #endif
11347c478bd9Sstevel@tonic-gate extern	void	set_curthread(void *);
11357c478bd9Sstevel@tonic-gate 
113641efec22Sraf /*
1137883492d5Sraf  * Utility function used when waking up many threads (more than MAXLWPS)
1138883492d5Sraf  * all at once.  See mutex_wakeup_all(), cond_broadcast(), and rw_unlock().
113941efec22Sraf  */
114041efec22Sraf #define	MAXLWPS	128	/* max remembered lwpids before overflow */
114141efec22Sraf #define	NEWLWPS	2048	/* max remembered lwpids at first overflow */
114241efec22Sraf extern	lwpid_t	*alloc_lwpids(lwpid_t *, int *, int *);
114341efec22Sraf 
11447c478bd9Sstevel@tonic-gate /* enter a critical section */
11457c478bd9Sstevel@tonic-gate #define	enter_critical(self)	(self->ul_critical++)
11467c478bd9Sstevel@tonic-gate 
11477c478bd9Sstevel@tonic-gate /* exit a critical section, take deferred actions if necessary */
11487c478bd9Sstevel@tonic-gate extern	void	do_exit_critical(void);
11497c478bd9Sstevel@tonic-gate #define	exit_critical(self)					\
11507c478bd9Sstevel@tonic-gate 	(void) (self->ul_critical--,				\
11517c478bd9Sstevel@tonic-gate 	    ((self->ul_curplease && self->ul_critical == 0)?	\
11527c478bd9Sstevel@tonic-gate 	    (do_exit_critical(), 0) : 0))
11537c478bd9Sstevel@tonic-gate 
11547c478bd9Sstevel@tonic-gate /*
11557c478bd9Sstevel@tonic-gate  * Like enter_critical()/exit_critical() but just for deferring signals.
11567c478bd9Sstevel@tonic-gate  * Unlike enter_critical()/exit_critical(), ul_sigdefer may be set while
11577c478bd9Sstevel@tonic-gate  * calling application functions like constructors and destructors.
11587c478bd9Sstevel@tonic-gate  * Care must be taken if the application function attempts to set
11597c478bd9Sstevel@tonic-gate  * the signal mask while a deferred signal is present; the setting
11607c478bd9Sstevel@tonic-gate  * of the signal mask must also be deferred.
11617c478bd9Sstevel@tonic-gate  */
11627c478bd9Sstevel@tonic-gate #define	sigoff(self)	(self->ul_sigdefer++)
11637c478bd9Sstevel@tonic-gate extern	void	sigon(ulwp_t *);
11647c478bd9Sstevel@tonic-gate 
11657c478bd9Sstevel@tonic-gate /* these are exported functions */
11667c478bd9Sstevel@tonic-gate extern	void	_sigoff(void);
11677c478bd9Sstevel@tonic-gate extern	void	_sigon(void);
11687c478bd9Sstevel@tonic-gate 
11697c478bd9Sstevel@tonic-gate #define	sigorset(s1, s2)				\
11707c478bd9Sstevel@tonic-gate 	(((s1)->__sigbits[0] |= (s2)->__sigbits[0]),	\
11717c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[1] |= (s2)->__sigbits[1]),	\
11727c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[2] |= (s2)->__sigbits[2]),	\
11737c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[3] |= (s2)->__sigbits[3]))
11747c478bd9Sstevel@tonic-gate 
11757c478bd9Sstevel@tonic-gate #define	sigandset(s1, s2)				\
11767c478bd9Sstevel@tonic-gate 	(((s1)->__sigbits[0] &= (s2)->__sigbits[0]),	\
11777c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[1] &= (s2)->__sigbits[1]),	\
11787c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[2] &= (s2)->__sigbits[2]),	\
11797c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[3] &= (s2)->__sigbits[3]))
11807c478bd9Sstevel@tonic-gate 
11817c478bd9Sstevel@tonic-gate #define	sigdiffset(s1, s2)				\
11827c478bd9Sstevel@tonic-gate 	(((s1)->__sigbits[0] &= ~(s2)->__sigbits[0]),	\
11837c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[1] &= ~(s2)->__sigbits[1]),	\
11847c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[2] &= ~(s2)->__sigbits[2]),	\
11857c478bd9Sstevel@tonic-gate 	((s1)->__sigbits[3] &= ~(s2)->__sigbits[3]))
11867c478bd9Sstevel@tonic-gate 
11877c478bd9Sstevel@tonic-gate #define	delete_reserved_signals(s)			\
11887c478bd9Sstevel@tonic-gate 	(((s)->__sigbits[0] &= MASKSET0),		\
11897c478bd9Sstevel@tonic-gate 	((s)->__sigbits[1] &= (MASKSET1 & ~SIGMASK(SIGCANCEL))),\
11907c478bd9Sstevel@tonic-gate 	((s)->__sigbits[2] = 0),			\
11917c478bd9Sstevel@tonic-gate 	((s)->__sigbits[3] = 0))
11927c478bd9Sstevel@tonic-gate 
11937c478bd9Sstevel@tonic-gate extern	void	block_all_signals(ulwp_t *self);
11947c478bd9Sstevel@tonic-gate 
11957c478bd9Sstevel@tonic-gate /*
11967c478bd9Sstevel@tonic-gate  * When restoring the signal mask after having previously called
11977c478bd9Sstevel@tonic-gate  * block_all_signals(), if we have a deferred signal present then
11987c478bd9Sstevel@tonic-gate  * do nothing other than ASSERT() that we are in a critical region.
11997c478bd9Sstevel@tonic-gate  * The signal mask will be set when we emerge from the critical region
12007c478bd9Sstevel@tonic-gate  * and call take_deferred_signal().  There is no race condition here
12017c478bd9Sstevel@tonic-gate  * because the kernel currently has all signals blocked for this thread.
12027c478bd9Sstevel@tonic-gate  */
12037c478bd9Sstevel@tonic-gate #define	restore_signals(self)						\
12047c478bd9Sstevel@tonic-gate 	((void) ((self)->ul_cursig?					\
12057c478bd9Sstevel@tonic-gate 	(ASSERT((self)->ul_critical + (self)->ul_sigdefer != 0), 0) :	\
12067c478bd9Sstevel@tonic-gate 	__lwp_sigmask(SIG_SETMASK, &(self)->ul_sigmask, NULL)))
12077c478bd9Sstevel@tonic-gate 
1208*a574db85Sraf extern	void	set_cancel_pending_flag(ulwp_t *, int);
1209*a574db85Sraf extern	void	set_cancel_eintr_flag(ulwp_t *);
12107c478bd9Sstevel@tonic-gate extern	void	set_parking_flag(ulwp_t *, int);
1211*a574db85Sraf extern	int	cancel_active(void);
12127c478bd9Sstevel@tonic-gate 
12137c478bd9Sstevel@tonic-gate extern	void	*_thr_setup(ulwp_t *);
12147c478bd9Sstevel@tonic-gate extern	void	_fpinherit(ulwp_t *);
12157c478bd9Sstevel@tonic-gate extern	void	_lwp_start(void);
12167c478bd9Sstevel@tonic-gate extern	void	_lwp_terminate(void);
12177c478bd9Sstevel@tonic-gate extern	void	lmutex_lock(mutex_t *);
1218f841f6adSraf extern	void	lmutex_unlock(mutex_t *);
121941efec22Sraf extern	void	lrw_rdlock(rwlock_t *);
122041efec22Sraf extern	void	lrw_wrlock(rwlock_t *);
122141efec22Sraf extern	void	lrw_unlock(rwlock_t *);
1222f841f6adSraf extern	void	sig_mutex_lock(mutex_t *);
1223f841f6adSraf extern	void	sig_mutex_unlock(mutex_t *);
1224f841f6adSraf extern	int	sig_mutex_trylock(mutex_t *);
1225f841f6adSraf extern	int	sig_cond_wait(cond_t *, mutex_t *);
1226f841f6adSraf extern	int	sig_cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *);
1227*a574db85Sraf extern	void	cancel_safe_mutex_lock(mutex_t *);
1228*a574db85Sraf extern	void	cancel_safe_mutex_unlock(mutex_t *);
1229*a574db85Sraf extern	int	cancel_safe_mutex_trylock(mutex_t *);
12307c478bd9Sstevel@tonic-gate extern	void	_prefork_handler(void);
12317c478bd9Sstevel@tonic-gate extern	void	_postfork_parent_handler(void);
12327c478bd9Sstevel@tonic-gate extern	void	_postfork_child_handler(void);
1233f841f6adSraf extern	void	postfork1_child(void);
1234f841f6adSraf extern	void	postfork1_child_aio(void);
1235f841f6adSraf extern	void	postfork1_child_sigev_aio(void);
1236f841f6adSraf extern	void	postfork1_child_sigev_mq(void);
1237f841f6adSraf extern	void	postfork1_child_sigev_timer(void);
1238f841f6adSraf extern	void	postfork1_child_tpool(void);
12392e145884Sraf extern	void	fork_lock_enter(void);
12407c478bd9Sstevel@tonic-gate extern	void	fork_lock_exit(void);
12417c478bd9Sstevel@tonic-gate extern	void	suspend_fork(void);
12427c478bd9Sstevel@tonic-gate extern	void	continue_fork(int);
12437c478bd9Sstevel@tonic-gate extern	void	do_sigcancel(void);
1244f841f6adSraf extern	void	setup_cancelsig(int);
1245f841f6adSraf extern	void	init_sigev_thread(void);
1246f841f6adSraf extern	void	init_aio(void);
12477c478bd9Sstevel@tonic-gate extern	void	_cancelon(void);
12487c478bd9Sstevel@tonic-gate extern	void	_canceloff(void);
12497c478bd9Sstevel@tonic-gate extern	void	_canceloff_nocancel(void);
1250f841f6adSraf extern	void	_cancel_prologue(void);
1251f841f6adSraf extern	void	_cancel_epilogue(void);
12527c478bd9Sstevel@tonic-gate extern	void	no_preempt(ulwp_t *);
12537c478bd9Sstevel@tonic-gate extern	void	preempt(ulwp_t *);
12547c478bd9Sstevel@tonic-gate extern	void	_thrp_unwind(void *);
12557c478bd9Sstevel@tonic-gate 
12567c478bd9Sstevel@tonic-gate /*
12577c478bd9Sstevel@tonic-gate  * Prototypes for the strong versions of the interface functions
12587c478bd9Sstevel@tonic-gate  */
1259657b1f3dSraf extern	pid_t	__forkx(int);
1260657b1f3dSraf extern	pid_t	__forkallx(int);
12617c478bd9Sstevel@tonic-gate extern	pid_t	_private_getpid(void);
12627c478bd9Sstevel@tonic-gate extern	uid_t	_private_geteuid(void);
12637c478bd9Sstevel@tonic-gate extern	int	_kill(pid_t, int);
1264*a574db85Sraf extern	int	_private_open(const char *, int, ...);
1265*a574db85Sraf extern	int	_private_close(int);
1266*a574db85Sraf extern	ssize_t	__read(int, void *, size_t);
1267*a574db85Sraf extern	ssize_t	__write(int, const void *, size_t);
12687c478bd9Sstevel@tonic-gate extern	void	*_memcpy(void *, const void *, size_t);
12697c478bd9Sstevel@tonic-gate extern	void	*_memset(void *, int, size_t);
127034709573Sraf extern	int	_memcmp(const void *, const void *, size_t);
12717c478bd9Sstevel@tonic-gate extern	void	*_private_memcpy(void *, const void *, size_t);
12727c478bd9Sstevel@tonic-gate extern	void	*_private_memset(void *, int, size_t);
12737c478bd9Sstevel@tonic-gate extern	int	_private_sigfillset(sigset_t *);
12747c478bd9Sstevel@tonic-gate extern	int	_private_sigemptyset(sigset_t *);
12757c478bd9Sstevel@tonic-gate extern	int	_private_sigaddset(sigset_t *, int);
12767c478bd9Sstevel@tonic-gate extern	int	_private_sigdelset(sigset_t *, int);
12777c478bd9Sstevel@tonic-gate extern	int	_private_sigismember(sigset_t *, int);
12787c478bd9Sstevel@tonic-gate extern	void	*_private_mmap(void *, size_t, int, int, int, off_t);
12797c478bd9Sstevel@tonic-gate extern	int	_private_mprotect(void *, size_t, int);
12807c478bd9Sstevel@tonic-gate extern	int	_private_munmap(void *, size_t);
12817c478bd9Sstevel@tonic-gate extern	int	_private_getrlimit(int, struct rlimit *);
12827c478bd9Sstevel@tonic-gate extern	int	__lwp_continue(lwpid_t);
12837c478bd9Sstevel@tonic-gate extern	int	__lwp_create(ucontext_t *, uint_t, lwpid_t *);
12847c478bd9Sstevel@tonic-gate extern	int	__lwp_kill(lwpid_t, int);
12857c478bd9Sstevel@tonic-gate extern	lwpid_t	__lwp_self(void);
12867c478bd9Sstevel@tonic-gate extern	int	___lwp_suspend(lwpid_t);
12877c478bd9Sstevel@tonic-gate extern	void	lwp_yield(void);
12887c478bd9Sstevel@tonic-gate extern	int	lwp_wait(lwpid_t, lwpid_t *);
12897c478bd9Sstevel@tonic-gate extern	int	__lwp_wait(lwpid_t, lwpid_t *);
12907c478bd9Sstevel@tonic-gate extern	int	__lwp_detach(lwpid_t);
12917c478bd9Sstevel@tonic-gate extern	sc_shared_t *__schedctl(void);
12927c478bd9Sstevel@tonic-gate 
12937c478bd9Sstevel@tonic-gate extern	int	_private_setcontext(const ucontext_t *);
12947c478bd9Sstevel@tonic-gate extern	int	_private_getcontext(ucontext_t *);
12957c478bd9Sstevel@tonic-gate #pragma unknown_control_flow(_private_getcontext)
12967c478bd9Sstevel@tonic-gate /* actual system call traps */
12977c478bd9Sstevel@tonic-gate extern	int	__setcontext_syscall(const ucontext_t *);
12987c478bd9Sstevel@tonic-gate extern	int	__getcontext_syscall(ucontext_t *);
12997c478bd9Sstevel@tonic-gate extern	int	_private_setustack(stack_t *);
13007c478bd9Sstevel@tonic-gate extern	int	__clock_gettime(clockid_t, timespec_t *);
13017c478bd9Sstevel@tonic-gate extern	void	abstime_to_reltime(clockid_t, const timespec_t *, timespec_t *);
13027c478bd9Sstevel@tonic-gate extern	void	hrt2ts(hrtime_t, timespec_t *);
13037c478bd9Sstevel@tonic-gate 
13047c478bd9Sstevel@tonic-gate extern	int	__sigaction(int, const struct sigaction *, struct sigaction *);
13057c478bd9Sstevel@tonic-gate extern	int	__lwp_sigmask(int, const sigset_t *, sigset_t *);
13067c478bd9Sstevel@tonic-gate extern	void	__sighndlr(int, siginfo_t *, ucontext_t *, void (*)());
13077c478bd9Sstevel@tonic-gate extern	caddr_t	__sighndlrend;
13087c478bd9Sstevel@tonic-gate #pragma unknown_control_flow(__sighndlr)
1309f841f6adSraf extern	void	_siglongjmp(sigjmp_buf, int);
13107c478bd9Sstevel@tonic-gate 
1311f841f6adSraf extern	int	_pthread_setspecific(pthread_key_t, const void *);
1312f841f6adSraf extern	void	*_pthread_getspecific(pthread_key_t);
13137c478bd9Sstevel@tonic-gate extern	void	_pthread_exit(void *);
1314*a574db85Sraf extern	int	_pthread_setcancelstate(int, int *);
1315f841f6adSraf extern	void	_private_testcancel(void);
1316f841f6adSraf 
1317f841f6adSraf /* belongs in <pthread.h> */
1318f841f6adSraf #define	PTHREAD_CREATE_DAEMON_NP	0x100	/* = THR_DAEMON */
1319f841f6adSraf #define	PTHREAD_CREATE_NONDAEMON_NP	0
1320f841f6adSraf extern	int	_pthread_attr_setdaemonstate_np(pthread_attr_t *, int);
1321f841f6adSraf extern	int	_pthread_attr_getdaemonstate_np(const pthread_attr_t *, int *);
13227c478bd9Sstevel@tonic-gate 
13237c478bd9Sstevel@tonic-gate /* these are private to the library */
13247c478bd9Sstevel@tonic-gate extern	int	_private_mutex_init(mutex_t *, int, void *);
13257c478bd9Sstevel@tonic-gate extern	int	_private_mutex_destroy(mutex_t *);
13267c478bd9Sstevel@tonic-gate extern	int	_private_mutex_lock(mutex_t *);
13277c478bd9Sstevel@tonic-gate extern	int	_private_mutex_trylock(mutex_t *);
13287c478bd9Sstevel@tonic-gate extern	int	_private_mutex_unlock(mutex_t *);
13297c478bd9Sstevel@tonic-gate 
13307c478bd9Sstevel@tonic-gate extern	int	_mutex_init(mutex_t *, int, void *);
13317c478bd9Sstevel@tonic-gate extern	int	_mutex_destroy(mutex_t *);
1332883492d5Sraf extern	int	_mutex_consistent(mutex_t *);
13337c478bd9Sstevel@tonic-gate extern	int	_mutex_lock(mutex_t *);
13347c478bd9Sstevel@tonic-gate extern	int	_mutex_trylock(mutex_t *);
13357c478bd9Sstevel@tonic-gate extern	int	_mutex_unlock(mutex_t *);
13367c478bd9Sstevel@tonic-gate extern	int	__mutex_init(mutex_t *, int, void *);
13377c478bd9Sstevel@tonic-gate extern	int	__mutex_destroy(mutex_t *);
1338883492d5Sraf extern	int	__mutex_consistent(mutex_t *);
13397c478bd9Sstevel@tonic-gate extern	int	__mutex_lock(mutex_t *);
13407c478bd9Sstevel@tonic-gate extern	int	__mutex_trylock(mutex_t *);
13417c478bd9Sstevel@tonic-gate extern	int	__mutex_unlock(mutex_t *);
13427c478bd9Sstevel@tonic-gate extern	int	mutex_is_held(mutex_t *);
13437c478bd9Sstevel@tonic-gate 
13447c478bd9Sstevel@tonic-gate extern	int	_cond_init(cond_t *, int, void *);
13457c478bd9Sstevel@tonic-gate extern	int	_cond_signal(cond_t *);
13467c478bd9Sstevel@tonic-gate extern	int	_cond_broadcast(cond_t *);
13477c478bd9Sstevel@tonic-gate extern	int	_cond_destroy(cond_t *);
13487c478bd9Sstevel@tonic-gate extern	int	cond_signal_internal(cond_t *);
13497c478bd9Sstevel@tonic-gate extern	int	cond_broadcast_internal(cond_t *);
1350*a574db85Sraf /* cancellation points: */
1351*a574db85Sraf extern	int	_cond_wait(cond_t *, mutex_t *);
1352*a574db85Sraf extern	int	_cond_timedwait(cond_t *, mutex_t *, const timespec_t *);
1353*a574db85Sraf extern	int	_cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *);
1354*a574db85Sraf /* not cancellation points: */
1355*a574db85Sraf extern	int	__cond_wait(cond_t *, mutex_t *);
1356*a574db85Sraf extern	int	__cond_timedwait(cond_t *, mutex_t *, const timespec_t *);
1357*a574db85Sraf extern	int	__cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *);
13587c478bd9Sstevel@tonic-gate 
13597c478bd9Sstevel@tonic-gate extern	int	__rwlock_init(rwlock_t *, int, void *);
13607c478bd9Sstevel@tonic-gate extern	int	rw_read_is_held(rwlock_t *);
13617c478bd9Sstevel@tonic-gate extern	int	rw_write_is_held(rwlock_t *);
13627c478bd9Sstevel@tonic-gate 
1363cb620785Sraf extern	void	_membar_enter(void);
1364cb620785Sraf extern	void	_membar_exit(void);
1365cb620785Sraf extern	void	_membar_producer(void);
1366cb620785Sraf extern	void	_membar_consumer(void);
1367cb620785Sraf 
13687c478bd9Sstevel@tonic-gate extern	int	_thr_continue(thread_t);
1369f841f6adSraf extern	int	_thr_create(void *, size_t, void *(*)(void *), void *, long,
1370f841f6adSraf 			thread_t *);
1371f841f6adSraf extern	int	_thrp_create(void *, size_t, void *(*)(void *), void *, long,
1372f841f6adSraf 			thread_t *, pri_t, int, size_t);
13737c478bd9Sstevel@tonic-gate extern	int	_thr_getprio(thread_t, int *);
13747c478bd9Sstevel@tonic-gate extern	int	_thr_getspecific(thread_key_t, void **);
13757c478bd9Sstevel@tonic-gate extern	int	_thr_join(thread_t, thread_t *, void **);
13767c478bd9Sstevel@tonic-gate extern	int	_thr_keycreate(thread_key_t *, PFrV);
1377cb620785Sraf extern	int	_thr_keycreate_once(thread_key_t *, PFrV);
13787c478bd9Sstevel@tonic-gate extern	int	_thr_key_delete(thread_key_t);
13797c478bd9Sstevel@tonic-gate extern	int	_thr_main(void);
13807c478bd9Sstevel@tonic-gate extern	thread_t _thr_self(void);
13817c478bd9Sstevel@tonic-gate extern	int	_thr_getconcurrency(void);
13827c478bd9Sstevel@tonic-gate extern	int	_thr_setconcurrency(int);
13837c478bd9Sstevel@tonic-gate extern	int	_thr_setprio(thread_t, int);
13847c478bd9Sstevel@tonic-gate extern	int	_thr_setspecific(thread_key_t, void *);
13857c478bd9Sstevel@tonic-gate extern	int	_thr_stksegment(stack_t *);
13867c478bd9Sstevel@tonic-gate extern	int	_thrp_suspend(thread_t, uchar_t);
13877c478bd9Sstevel@tonic-gate extern	int	_thrp_continue(thread_t, uchar_t);
13887c478bd9Sstevel@tonic-gate extern	int	_thr_sigsetmask(int, const sigset_t *, sigset_t *);
13897c478bd9Sstevel@tonic-gate 
13907c478bd9Sstevel@tonic-gate extern	void	_thr_terminate(void *);
13917c478bd9Sstevel@tonic-gate extern	void	_thr_exit(void *);
13927c478bd9Sstevel@tonic-gate extern	void	_thrp_exit(void);
13937c478bd9Sstevel@tonic-gate 
139434709573Sraf extern	const thrattr_t *def_thrattr(void);
13957c478bd9Sstevel@tonic-gate extern	int	_thread_setschedparam_main(pthread_t, int,
13967c478bd9Sstevel@tonic-gate 			const struct sched_param *, int);
13977c478bd9Sstevel@tonic-gate extern	int	_validate_rt_prio(int, int);
13987c478bd9Sstevel@tonic-gate extern	int	_thrp_setlwpprio(lwpid_t, int, int);
1399f841f6adSraf extern	pri_t	map_rtpri_to_gp(pri_t);
1400f841f6adSraf extern	int	get_info_by_policy(int);
14017c478bd9Sstevel@tonic-gate 
14027c478bd9Sstevel@tonic-gate /*
14037c478bd9Sstevel@tonic-gate  * System call wrappers (direct interfaces to the kernel)
14047c478bd9Sstevel@tonic-gate  */
1405883492d5Sraf extern	int	___lwp_mutex_register(mutex_t *);
14067c478bd9Sstevel@tonic-gate extern	int	___lwp_mutex_trylock(mutex_t *);
14077c478bd9Sstevel@tonic-gate extern	int	___lwp_mutex_timedlock(mutex_t *, timespec_t *);
14087c478bd9Sstevel@tonic-gate extern	int	___lwp_mutex_unlock(mutex_t *);
1409883492d5Sraf extern	int	___lwp_mutex_wakeup(mutex_t *, int);
14107c478bd9Sstevel@tonic-gate extern	int	___lwp_cond_wait(cond_t *, mutex_t *, timespec_t *, int);
14117c478bd9Sstevel@tonic-gate extern	int	__lwp_cond_signal(lwp_cond_t *);
14127c478bd9Sstevel@tonic-gate extern	int	__lwp_cond_broadcast(lwp_cond_t *);
14137c478bd9Sstevel@tonic-gate extern	int	___lwp_sema_timedwait(lwp_sema_t *, timespec_t *, int);
14147c478bd9Sstevel@tonic-gate extern	int	__lwp_sema_trywait(lwp_sema_t *);
14157c478bd9Sstevel@tonic-gate extern	int	__lwp_sema_post(lwp_sema_t *);
14167c478bd9Sstevel@tonic-gate extern	int	__lwp_rwlock_rdlock(rwlock_t *, timespec_t *);
14177c478bd9Sstevel@tonic-gate extern	int	__lwp_rwlock_wrlock(rwlock_t *, timespec_t *);
14187c478bd9Sstevel@tonic-gate extern	int	__lwp_rwlock_tryrdlock(rwlock_t *);
14197c478bd9Sstevel@tonic-gate extern	int	__lwp_rwlock_trywrlock(rwlock_t *);
14207c478bd9Sstevel@tonic-gate extern	int	__lwp_rwlock_unlock(rwlock_t *);
14217c478bd9Sstevel@tonic-gate extern	int	__lwp_park(timespec_t *, lwpid_t);
14227c478bd9Sstevel@tonic-gate extern	int	__lwp_unpark(lwpid_t);
14237c478bd9Sstevel@tonic-gate extern	int	__lwp_unpark_all(lwpid_t *, int);
14240ec57554Sraf #if defined(__x86)
14257c478bd9Sstevel@tonic-gate extern	int	___lwp_private(int, int, void *);
14260ec57554Sraf #endif	/* __x86 */
14277c478bd9Sstevel@tonic-gate 
14287c478bd9Sstevel@tonic-gate extern	int	_private_lwp_mutex_lock(mutex_t *);
14297c478bd9Sstevel@tonic-gate extern	int	_private_lwp_mutex_unlock(mutex_t *);
14307c478bd9Sstevel@tonic-gate 
14317c478bd9Sstevel@tonic-gate /*
14327c478bd9Sstevel@tonic-gate  * inlines
14337c478bd9Sstevel@tonic-gate  */
14347c478bd9Sstevel@tonic-gate extern	int		set_lock_byte(volatile uint8_t *);
143541efec22Sraf extern	uint32_t	atomic_swap_32(volatile uint32_t *, uint32_t);
143641efec22Sraf extern	uint32_t	atomic_cas_32(volatile uint32_t *, uint32_t, uint32_t);
143741efec22Sraf extern	void		atomic_inc_32(volatile uint32_t *);
143841efec22Sraf extern	void		atomic_dec_32(volatile uint32_t *);
143941efec22Sraf extern	void		atomic_and_32(volatile uint32_t *, uint32_t);
144041efec22Sraf extern	void		atomic_or_32(volatile uint32_t *, uint32_t);
14410ec57554Sraf #if defined(__sparc)
14420ec57554Sraf extern	ulong_t		caller(void);
14430ec57554Sraf extern	ulong_t		getfp(void);
14440ec57554Sraf #endif	/* __sparc */
14450ec57554Sraf 
14460ec57554Sraf #include "thr_inlines.h"
14477c478bd9Sstevel@tonic-gate 
14487c478bd9Sstevel@tonic-gate #endif	/* _THR_UBERDATA_H */
1449