xref: /illumos-gate/usr/src/lib/libc/inc/thr_uberdata.h (revision 6a817834)
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  */
227c478bd9Sstevel@tonic-gate /*
2323a1cceaSRoger A. Faulkner  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
258a7aa2a5SYuri Pankov 
264f364e7cSRobert Mustacchi /*
27fc2512cfSRobert Mustacchi  * Copyright 2016 Joyent, Inc.
288a7aa2a5SYuri Pankov  * Copyright 2018 Nexenta Systems, Inc.
294f364e7cSRobert Mustacchi  */
317c478bd9Sstevel@tonic-gate #ifndef _THR_UBERDATA_H
327c478bd9Sstevel@tonic-gate #define	_THR_UBERDATA_H
347c478bd9Sstevel@tonic-gate #include <stdlib.h>
357c478bd9Sstevel@tonic-gate #include <unistd.h>
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include <fcntl.h>
387c478bd9Sstevel@tonic-gate #include <string.h>
397c478bd9Sstevel@tonic-gate #include <signal.h>
407c478bd9Sstevel@tonic-gate #include <ucontext.h>
417c478bd9Sstevel@tonic-gate #include <thread.h>
427c478bd9Sstevel@tonic-gate #include <pthread.h>
437257d1b4Sraf #include <atomic.h>
447c478bd9Sstevel@tonic-gate #include <link.h>
457c478bd9Sstevel@tonic-gate #include <sys/resource.h>
467c478bd9Sstevel@tonic-gate #include <sys/lwp.h>
477c478bd9Sstevel@tonic-gate #include <errno.h>
487c478bd9Sstevel@tonic-gate #include <sys/asm_linkage.h>
497c478bd9Sstevel@tonic-gate #include <sys/regset.h>
507c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
517c478bd9Sstevel@tonic-gate #include <sys/mman.h>
527c478bd9Sstevel@tonic-gate #include <synch.h>
537c478bd9Sstevel@tonic-gate #include <door.h>
547c478bd9Sstevel@tonic-gate #include <limits.h>
557c478bd9Sstevel@tonic-gate #include <sys/synch32.h>
567c478bd9Sstevel@tonic-gate #include <schedctl.h>
577c478bd9Sstevel@tonic-gate #include <sys/priocntl.h>
587c478bd9Sstevel@tonic-gate #include <thread_db.h>
59f841f6adSraf #include <setjmp.h>
60ab618543SJohn Levon #include <sys/thread.h>
617c478bd9Sstevel@tonic-gate #include "libc_int.h"
627c478bd9Sstevel@tonic-gate #include "tdb_agent.h"
63f841f6adSraf #include "thr_debug.h"
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate  * This is an implementation-specific include file for threading support.
677c478bd9Sstevel@tonic-gate  * It is not to be seen by the clients of the library.
687c478bd9Sstevel@tonic-gate  *
697c478bd9Sstevel@tonic-gate  * This file also describes uberdata in libc.
707c478bd9Sstevel@tonic-gate  *
717c478bd9Sstevel@tonic-gate  * The term "uberdata" refers to data that is unique and visible across
727c478bd9Sstevel@tonic-gate  * all link maps.  The name is meant to imply that such data is truly
737c478bd9Sstevel@tonic-gate  * global, not just locally global to a particular link map.
747c478bd9Sstevel@tonic-gate  *
757c478bd9Sstevel@tonic-gate  * See the Linker and Libraries Guide for a full description of alternate
767c478bd9Sstevel@tonic-gate  * link maps and how they are set up and used.
777c478bd9Sstevel@tonic-gate  *
787c478bd9Sstevel@tonic-gate  * Alternate link maps implement multiple global namespaces within a single
797c478bd9Sstevel@tonic-gate  * process.  There may be multiple instances of identical dynamic libraries
807c478bd9Sstevel@tonic-gate  * loaded in a process's address space at the same time, each on a different
817c478bd9Sstevel@tonic-gate  * link map (as determined by the dynamic linker), each with its own set of
827c478bd9Sstevel@tonic-gate  * global variables.  Which particular instance of a global variable is seen
837c478bd9Sstevel@tonic-gate  * by a thread running in the process is determined by the link map on which
847c478bd9Sstevel@tonic-gate  * the thread happens to be executing at the time.
857c478bd9Sstevel@tonic-gate  *
867c478bd9Sstevel@tonic-gate  * However, there are aspects of a process that are unique across all
877c478bd9Sstevel@tonic-gate  * link maps, in particular the structures used to implement threads
887c478bd9Sstevel@tonic-gate  * of control (in Sparc terminology, there is only one %g7 regardless
897c478bd9Sstevel@tonic-gate  * of the link map on which the thread is executing).
907c478bd9Sstevel@tonic-gate  *
917c478bd9Sstevel@tonic-gate  * All uberdata is referenced from a base pointer in the thread's ulwp_t
927c478bd9Sstevel@tonic-gate  * structure (which is also uberdata).  All allocations and deallocations
937c478bd9Sstevel@tonic-gate  * of uberdata are made via the uberdata-aware lmalloc() and lfree()
947c478bd9Sstevel@tonic-gate  * interfaces (malloc() and free() are simply locally-global).
957c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate  * Special libc-private access to errno.
997c478bd9Sstevel@tonic-gate  * We do this so that references to errno do not invoke the dynamic linker.
1007c478bd9Sstevel@tonic-gate  */
1017c478bd9Sstevel@tonic-gate #undef errno
1027c478bd9Sstevel@tonic-gate #define	errno (*curthread->ul_errnop)
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate  * See <sys/synch32.h> for the reasons for these values
1067c478bd9Sstevel@tonic-gate  * and why they are different for sparc and intel.
1077c478bd9Sstevel@tonic-gate  */
1087c478bd9Sstevel@tonic-gate #if defined(__sparc)
1107c478bd9Sstevel@tonic-gate /* lock.lock64.pad[x]	   4 5 6 7 */
1117c478bd9Sstevel@tonic-gate #define	LOCKMASK	0xff000000
1127c478bd9Sstevel@tonic-gate #define	WAITERMASK	0x000000ff
1135d1dd9a9Sraf #define	SPINNERMASK	0x00ff0000
1145d1dd9a9Sraf #define	SPINNERSHIFT	16
1157c478bd9Sstevel@tonic-gate #define	WAITER		0x00000001
1167c478bd9Sstevel@tonic-gate #define	LOCKSET		0xff
1177c478bd9Sstevel@tonic-gate #define	LOCKCLEAR	0
11931db3c26Sraf #define	PIDSHIFT	32
12031db3c26Sraf #define	LOCKMASK64	0xffffffffff000000ULL
12131db3c26Sraf #define	LOCKBYTE64	0x00000000ff000000ULL
12231db3c26Sraf #define	WAITERMASK64	0x00000000000000ffULL
12331db3c26Sraf #define	SPINNERMASK64	0x0000000000ff0000ULL
1250ec57554Sraf #elif defined(__x86)
1277c478bd9Sstevel@tonic-gate /* lock.lock64.pad[x]	   7 6 5 4 */
1287c478bd9Sstevel@tonic-gate #define	LOCKMASK	0xff000000
1297c478bd9Sstevel@tonic-gate #define	WAITERMASK	0x00ff0000
1305d1dd9a9Sraf #define	SPINNERMASK	0x0000ff00
1315d1dd9a9Sraf #define	SPINNERSHIFT	8
1327c478bd9Sstevel@tonic-gate #define	WAITER		0x00010000
1337c478bd9Sstevel@tonic-gate #define	LOCKSET		0x01
1347c478bd9Sstevel@tonic-gate #define	LOCKCLEAR	0
13631db3c26Sraf #define	PIDSHIFT	0
13731db3c26Sraf #define	LOCKMASK64	0xff000000ffffffffULL
13831db3c26Sraf #define	LOCKBYTE64	0x0100000000000000ULL
13931db3c26Sraf #define	WAITERMASK64	0x00ff000000000000ULL
14031db3c26Sraf #define	SPINNERMASK64	0x0000ff0000000000ULL
1427c478bd9Sstevel@tonic-gate #else
1430ec57554Sraf #error "neither __sparc nor __x86 is defined"
1447c478bd9Sstevel@tonic-gate #endif
1467c478bd9Sstevel@tonic-gate /*
1477c478bd9Sstevel@tonic-gate  * Fetch the owner of a USYNC_THREAD mutex.
1487c478bd9Sstevel@tonic-gate  * Don't use this with process-shared mutexes;
1497c478bd9Sstevel@tonic-gate  * the owing thread may be in a different process.
1507c478bd9Sstevel@tonic-gate  */
1517c478bd9Sstevel@tonic-gate #define	MUTEX_OWNER(mp)	((ulwp_t *)(uintptr_t)(mp)->mutex_owner)
1537c478bd9Sstevel@tonic-gate /*
154883492d5Sraf  * Test if a thread owns a process-private (USYNC_THREAD) mutex.
155883492d5Sraf  * This is inappropriate for a process-shared (USYNC_PROCESS) mutex.
1567c478bd9Sstevel@tonic-gate  * The 'mp' argument must not have side-effects since it is evaluated twice.
1577c478bd9Sstevel@tonic-gate  */
1587c478bd9Sstevel@tonic-gate #define	MUTEX_OWNED(mp, thrp)	\
1597c478bd9Sstevel@tonic-gate 	((mp)->mutex_lockw != 0 && MUTEX_OWNER(mp) == thrp)
1627c478bd9Sstevel@tonic-gate /*
1637c478bd9Sstevel@tonic-gate  * uberflags.uf_tdb_register_sync is an interface with libc_db to enable the
1647c478bd9Sstevel@tonic-gate  * collection of lock statistics by a debugger or other collecting tool.
1657c478bd9Sstevel@tonic-gate  *
1667c478bd9Sstevel@tonic-gate  * uberflags.uf_thread_error_detection is set by an environment variable:
1677c478bd9Sstevel@tonic-gate  *	_THREAD_ERROR_DETECTION
1687c478bd9Sstevel@tonic-gate  *		0 == no detection of locking primitive errors.
1697c478bd9Sstevel@tonic-gate  *		1 == detect errors and issue a warning message.
1707c478bd9Sstevel@tonic-gate  *		2 == detect errors, issue a warning message, and dump core.
1717c478bd9Sstevel@tonic-gate  *
1727c478bd9Sstevel@tonic-gate  * We bundle these together in uberflags.uf_trs_ted to make a test of either
1737c478bd9Sstevel@tonic-gate  * being non-zero a single memory reference (for speed of mutex_lock(), etc).
1747c478bd9Sstevel@tonic-gate  *
1757c478bd9Sstevel@tonic-gate  * uberflags.uf_mt is set non-zero when the first thread (in addition
1767c478bd9Sstevel@tonic-gate  * to the main thread) is created.
1777c478bd9Sstevel@tonic-gate  *
1787c478bd9Sstevel@tonic-gate  * We bundle all these flags together in uberflags.uf_all to make a test
1797c478bd9Sstevel@tonic-gate  * of any being non-zero a single memory reference (again, for speed).
1807c478bd9Sstevel@tonic-gate  */
1817c478bd9Sstevel@tonic-gate typedef union {
1827c478bd9Sstevel@tonic-gate 	int	uf_all;			/* combined all flags */
1837c478bd9Sstevel@tonic-gate 	struct {
1847c478bd9Sstevel@tonic-gate 		short	h_pad;
1857c478bd9Sstevel@tonic-gate 		short	h_trs_ted;	/* combined reg sync & error detect */
1867c478bd9Sstevel@tonic-gate 	} uf_h;
1877c478bd9Sstevel@tonic-gate 	struct {
1887c478bd9Sstevel@tonic-gate 		char	x_mt;
1897c478bd9Sstevel@tonic-gate 		char	x_pad;
1907c478bd9Sstevel@tonic-gate 		char	x_tdb_register_sync;
1917c478bd9Sstevel@tonic-gate 		char	x_thread_error_detection;
1927c478bd9Sstevel@tonic-gate 	} uf_x;
1937c478bd9Sstevel@tonic-gate } uberflags_t;
1957c478bd9Sstevel@tonic-gate #define	uf_mt				uf_x.x_mt
1967c478bd9Sstevel@tonic-gate #define	uf_tdb_register_sync		uf_x.x_tdb_register_sync
1977c478bd9Sstevel@tonic-gate #define	uf_thread_error_detection	uf_x.x_thread_error_detection
1987c478bd9Sstevel@tonic-gate #define	uf_trs_ted			uf_h.h_trs_ted	/* both of the above */
2007c478bd9Sstevel@tonic-gate /*
2017c478bd9Sstevel@tonic-gate  * NOTE WELL:
2027c478bd9Sstevel@tonic-gate  * To enable further optimization, the "ul_schedctl_called" member
2037c478bd9Sstevel@tonic-gate  * of the ulwp_t structure (below) serves double-duty:
2047c478bd9Sstevel@tonic-gate  *	1. If NULL, it means that the thread must call __schedctl()
2057c478bd9Sstevel@tonic-gate  *	   to set up its schedctl mappings before acquiring a mutex.
2067c478bd9Sstevel@tonic-gate  *	   This is required by the implementation of adaptive mutex locking.
2077c478bd9Sstevel@tonic-gate  *	2. If non-NULL, it points to uberdata.uberflags, so that tests of
2087c478bd9Sstevel@tonic-gate  *	   uberflags can be made without additional memory references.
2097c478bd9Sstevel@tonic-gate  * This allows the common case of _mutex_lock() and _mutex_unlock() for
2107c478bd9Sstevel@tonic-gate  * USYNC_THREAD mutexes with no error detection and no lock statistics
2117c478bd9Sstevel@tonic-gate  * to be optimized for speed.
2127c478bd9Sstevel@tonic-gate  */
2147c478bd9Sstevel@tonic-gate /* double the default stack size for 64-bit processes */
2157c478bd9Sstevel@tonic-gate #ifdef _LP64
2167c478bd9Sstevel@tonic-gate #define	MINSTACK	(8 * 1024)
2177c478bd9Sstevel@tonic-gate #define	DEFAULTSTACK	(2 * 1024 * 1024)
2187c478bd9Sstevel@tonic-gate #else
2197c478bd9Sstevel@tonic-gate #define	MINSTACK	(4 * 1024)
2207c478bd9Sstevel@tonic-gate #define	DEFAULTSTACK	(1024 * 1024)
2217c478bd9Sstevel@tonic-gate #endif
2237c478bd9Sstevel@tonic-gate #define	MUTEX_TRY	0
2247c478bd9Sstevel@tonic-gate #define	MUTEX_LOCK	1
225d4204c85Sraf #define	MUTEX_NOCEIL	0x40
2270ec57554Sraf #if defined(__x86)
2297c478bd9Sstevel@tonic-gate typedef struct {	/* structure returned by fnstenv */
2307c478bd9Sstevel@tonic-gate 	int	fctrl;		/* control word */
2317c478bd9Sstevel@tonic-gate 	int	fstat;		/* status word (flags, etc) */
2327c478bd9Sstevel@tonic-gate 	int	ftag;		/* tag of which regs busy */
2337c478bd9Sstevel@tonic-gate 	int	misc[4];	/* other stuff, 28 bytes total */
2347c478bd9Sstevel@tonic-gate } fpuenv_t;
2367c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
2377c478bd9Sstevel@tonic-gate typedef fpuenv_t fpuenv32_t;
2387c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
2407c478bd9Sstevel@tonic-gate #elif defined(__sparc)
2427c478bd9Sstevel@tonic-gate typedef struct {	/* fp state structure */
2437c478bd9Sstevel@tonic-gate 	greg_t	fsr;
2447c478bd9Sstevel@tonic-gate 	greg_t	fpu_en;
2457c478bd9Sstevel@tonic-gate } fpuenv_t;
2477c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
2487c478bd9Sstevel@tonic-gate typedef struct {
2497c478bd9Sstevel@tonic-gate 	greg32_t	fsr;
2507c478bd9Sstevel@tonic-gate 	greg32_t	fpu_en;
2517c478bd9Sstevel@tonic-gate } fpuenv32_t;
2527c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
2540ec57554Sraf #endif	/* __x86 */
2560ec57554Sraf #if defined(__x86)
2577c478bd9Sstevel@tonic-gate extern	void	ht_pause(void);		/* "pause" instruction */
2587c478bd9Sstevel@tonic-gate #define	SMT_PAUSE()	ht_pause()
259b1593d50SJason Beloro #elif defined(SMT_PAUSE_FUNCTION)
260b1593d50SJason Beloro extern	void	SMT_PAUSE_FUNCTION(void);
261b1593d50SJason Beloro #define	SMT_PAUSE()	SMT_PAUSE_FUNCTION()
2627c478bd9Sstevel@tonic-gate #else
263e2c5185aSChristopher Kiick #define	SMT_PAUSE()	smt_pause()
2640ec57554Sraf #endif	/* __x86 */
2667c478bd9Sstevel@tonic-gate /*
2677c478bd9Sstevel@tonic-gate  * Cleanup handler related data.
2687c478bd9Sstevel@tonic-gate  * This structure is exported as _cleanup_t in pthread.h.
2697c478bd9Sstevel@tonic-gate  * pthread.h exports only the size of this structure, so check
2707c478bd9Sstevel@tonic-gate  * _cleanup_t in pthread.h before making any change here.
2717c478bd9Sstevel@tonic-gate  */
2727c478bd9Sstevel@tonic-gate typedef struct __cleanup {
2737c478bd9Sstevel@tonic-gate 	struct __cleanup *next;		/* pointer to next handler */
2747c478bd9Sstevel@tonic-gate 	caddr_t	fp;			/* current frame pointer */
2757c478bd9Sstevel@tonic-gate 	void	(*func)(void *);	/* cleanup handler address */
2767c478bd9Sstevel@tonic-gate 	void	*arg;			/* handler's argument */
2777c478bd9Sstevel@tonic-gate } __cleanup_t;
2797c478bd9Sstevel@tonic-gate /*
2807c478bd9Sstevel@tonic-gate  * Thread-Specific Data (TSD)
2817c478bd9Sstevel@tonic-gate  * TSD_NFAST includes the invalid key zero, so there
2827c478bd9Sstevel@tonic-gate  * are really only (TSD_NFAST - 1) fast key slots.
2837c478bd9Sstevel@tonic-gate  */
2847c478bd9Sstevel@tonic-gate typedef	void (*PFrV)(void *);
2857c478bd9Sstevel@tonic-gate #define	TSD_UNALLOCATED	((PFrV)1)
2867c478bd9Sstevel@tonic-gate #define	TSD_NFAST	9
2887c478bd9Sstevel@tonic-gate /*
2897c478bd9Sstevel@tonic-gate  * The tsd union is designed to burn a little memory (9 words) to make
2907c478bd9Sstevel@tonic-gate  * lookups blindingly fast.  Note that tsd_nalloc could be placed at the
2917c478bd9Sstevel@tonic-gate  * end of the pad region to increase the likelihood that it falls on the
2927c478bd9Sstevel@tonic-gate  * same cache line as the data.
2937c478bd9Sstevel@tonic-gate  */
2947c478bd9Sstevel@tonic-gate typedef union tsd {
2957c478bd9Sstevel@tonic-gate 	uint_t tsd_nalloc;		/* Amount of allocated storage */
2967c478bd9Sstevel@tonic-gate 	void *tsd_pad[TSD_NFAST];
2977c478bd9Sstevel@tonic-gate 	void *tsd_data[1];
2987c478bd9Sstevel@tonic-gate } tsd_t;
3007c478bd9Sstevel@tonic-gate typedef struct {
3017c478bd9Sstevel@tonic-gate 	mutex_t tsdm_lock;		/* Lock protecting the data */
3027c478bd9Sstevel@tonic-gate 	uint_t tsdm_nkeys;		/* Number of allocated keys */
3037c478bd9Sstevel@tonic-gate 	uint_t tsdm_nused;		/* Number of used keys */
3047c478bd9Sstevel@tonic-gate 	PFrV *tsdm_destro;		/* Per-key destructors */
3057c478bd9Sstevel@tonic-gate 	char tsdm_pad[64 -		/* pad to 64 bytes */
3067c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + 2 * sizeof (uint_t) + sizeof (PFrV *))];
3077c478bd9Sstevel@tonic-gate } tsd_metadata_t;
3097c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
3107c478bd9Sstevel@tonic-gate typedef union tsd32 {
3117c478bd9Sstevel@tonic-gate 	uint_t tsd_nalloc;		/* Amount of allocated storage */
3127c478bd9Sstevel@tonic-gate 	caddr32_t tsd_pad[TSD_NFAST];
3137c478bd9Sstevel@tonic-gate 	caddr32_t tsd_data[1];
3147c478bd9Sstevel@tonic-gate } tsd32_t;
3167c478bd9Sstevel@tonic-gate typedef struct {
3177c478bd9Sstevel@tonic-gate 	mutex_t tsdm_lock;		/* Lock protecting the data */
3187c478bd9Sstevel@tonic-gate 	uint_t tsdm_nkeys;		/* Number of allocated keys */
3197c478bd9Sstevel@tonic-gate 	uint_t tsdm_nused;		/* Number of used keys */
3207c478bd9Sstevel@tonic-gate 	caddr32_t tsdm_destro;		/* Per-key destructors */
3217c478bd9Sstevel@tonic-gate 	char tsdm_pad[64 -		/* pad to 64 bytes */
3227c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + 2 * sizeof (uint_t) + sizeof (caddr32_t))];
3237c478bd9Sstevel@tonic-gate } tsd_metadata32_t;
3247c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
3277c478bd9Sstevel@tonic-gate /*
3287c478bd9Sstevel@tonic-gate  * Thread-Local Storage (TLS)
3297c478bd9Sstevel@tonic-gate  */
3307c478bd9Sstevel@tonic-gate typedef struct {
3317c478bd9Sstevel@tonic-gate 	void		*tls_data;
3327c478bd9Sstevel@tonic-gate 	size_t		tls_size;
3337c478bd9Sstevel@tonic-gate } tls_t;
3357c478bd9Sstevel@tonic-gate typedef struct {
3367c478bd9Sstevel@tonic-gate 	mutex_t	tls_lock;		/* Lock protecting the data */
3377c478bd9Sstevel@tonic-gate 	tls_t	tls_modinfo;		/* Root of all TLS_modinfo data */
3387c478bd9Sstevel@tonic-gate 	tls_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 (tls_t))];
3417c478bd9Sstevel@tonic-gate } tls_metadata_t;
3437c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
3447c478bd9Sstevel@tonic-gate typedef struct {
3457c478bd9Sstevel@tonic-gate 	caddr32_t	tls_data;
3467c478bd9Sstevel@tonic-gate 	size32_t	tls_size;
3477c478bd9Sstevel@tonic-gate } tls32_t;
3497c478bd9Sstevel@tonic-gate typedef struct {
3507c478bd9Sstevel@tonic-gate 	mutex_t	tls_lock;		/* Lock protecting the data */
3517c478bd9Sstevel@tonic-gate 	tls32_t	tls_modinfo;		/* Root of all TLS_modinfo data */
3527c478bd9Sstevel@tonic-gate 	tls32_t	static_tls;		/* Template for static TLS */
3537c478bd9Sstevel@tonic-gate 	char	tls_pad[64 -		/* pad to 64 bytes */
3547c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + 2 * sizeof (tls32_t))];
3557c478bd9Sstevel@tonic-gate } tls_metadata32_t;
3567c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
3597c478bd9Sstevel@tonic-gate /*
360d4204c85Sraf  * Sleep queue root for USYNC_THREAD condvars and mutexes.
361d4204c85Sraf  * There is a default queue root for each queue head (see below).
362d4204c85Sraf  * Also, each ulwp_t contains a queue root that can be used
363d4204c85Sraf  * when the thread is enqueued on the queue, if necessary
364d4204c85Sraf  * (when more than one wchan hashes to the same queue head).
365d4204c85Sraf  */
366d4204c85Sraf typedef struct queue_root {
367d4204c85Sraf 	struct queue_root	*qr_next;
368d4204c85Sraf 	struct queue_root	*qr_prev;
369d4204c85Sraf 	struct ulwp		*qr_head;
370d4204c85Sraf 	struct ulwp		*qr_tail;
371d4204c85Sraf 	void			*qr_wchan;
372d4204c85Sraf 	uint32_t		qr_rtcount;
373d4204c85Sraf 	uint32_t		qr_qlen;
374d4204c85Sraf 	uint32_t		qr_qmax;
375d4204c85Sraf } queue_root_t;
377d4204c85Sraf #ifdef _SYSCALL32
378d4204c85Sraf typedef struct queue_root32 {
379d4204c85Sraf 	caddr32_t		qr_next;
380d4204c85Sraf 	caddr32_t		qr_prev;
381d4204c85Sraf 	caddr32_t		qr_head;
382d4204c85Sraf 	caddr32_t		qr_tail;
383d4204c85Sraf 	caddr32_t		qr_wchan;
384d4204c85Sraf 	uint32_t		qr_rtcount;
385d4204c85Sraf 	uint32_t		qr_qlen;
386d4204c85Sraf 	uint32_t		qr_qmax;
387d4204c85Sraf } queue_root32_t;
388d4204c85Sraf #endif
390d4204c85Sraf /*
391d4204c85Sraf  * Sleep queue heads for USYNC_THREAD condvars and mutexes.
392d4204c85Sraf  * The size and alignment is 128 bytes to reduce cache conflicts.
393d4204c85Sraf  * Each queue head points to a list of queue roots, defined above.
394d4204c85Sraf  * Each queue head contains a default queue root for use when only one
395d4204c85Sraf  * is needed.  It is always at the tail of the queue root hash chain.
3967c478bd9Sstevel@tonic-gate  */
3977c478bd9Sstevel@tonic-gate typedef union {
398d4204c85Sraf 	uint64_t		qh_64[16];
3997c478bd9Sstevel@tonic-gate 	struct {
4007c478bd9Sstevel@tonic-gate 		mutex_t		q_lock;
4017c478bd9Sstevel@tonic-gate 		uint8_t		q_qcnt;
402d4204c85Sraf 		uint8_t		q_type;		/* MX or CV */
403d4204c85Sraf 		uint8_t		q_pad1[2];
404d4204c85Sraf 		uint32_t	q_lockcount;
4057c478bd9Sstevel@tonic-gate 		uint32_t	q_qlen;
4067c478bd9Sstevel@tonic-gate 		uint32_t	q_qmax;
407d4204c85Sraf 		void		*q_wchan;	/* valid only while locked */
408d4204c85Sraf 		struct queue_root *q_root;	/* valid only while locked */
409d4204c85Sraf 		struct queue_root *q_hlist;
410d4204c85Sraf #if !defined(_LP64)
411d4204c85Sraf 		caddr_t		q_pad2[3];
412d4204c85Sraf #endif
413d4204c85Sraf 		queue_root_t	q_def_root;
414d4204c85Sraf 		uint32_t	q_hlen;
415d4204c85Sraf 		uint32_t	q_hmax;
4167c478bd9Sstevel@tonic-gate 	} qh_qh;
4177c478bd9Sstevel@tonic-gate } queue_head_t;
4197c478bd9Sstevel@tonic-gate #define	qh_lock		qh_qh.q_lock
4207c478bd9Sstevel@tonic-gate #define	qh_qcnt		qh_qh.q_qcnt
421d4204c85Sraf #define	qh_type		qh_qh.q_type
422d4204c85Sraf #if defined(THREAD_DEBUG)
4237c478bd9Sstevel@tonic-gate #define	qh_lockcount	qh_qh.q_lockcount
4247c478bd9Sstevel@tonic-gate #define	qh_qlen		qh_qh.q_qlen
4257c478bd9Sstevel@tonic-gate #define	qh_qmax		qh_qh.q_qmax
426d4204c85Sraf #endif
427d4204c85Sraf #define	qh_wchan	qh_qh.q_wchan
428d4204c85Sraf #define	qh_root		qh_qh.q_root
429d4204c85Sraf #define	qh_hlist	qh_qh.q_hlist
430d4204c85Sraf #define	qh_def_root	qh_qh.q_def_root
431d4204c85Sraf #define	qh_hlen		qh_qh.q_hlen
432d4204c85Sraf #define	qh_hmax		qh_qh.q_hmax
434d4204c85Sraf /* queue types passed to queue_lock() */
4357c478bd9Sstevel@tonic-gate #define	MX	0
4367c478bd9Sstevel@tonic-gate #define	CV	1
437883492d5Sraf #define	QHASHSHIFT	9			/* number of hashing bits */
438883492d5Sraf #define	QHASHSIZE	(1 << QHASHSHIFT)	/* power of 2 (1<<9 == 512) */
439883492d5Sraf #define	QUEUE_HASH(wchan, type)	((uint_t)			\
440883492d5Sraf 	((((uintptr_t)(wchan) >> 3)				\
441883492d5Sraf 	^ ((uintptr_t)(wchan) >> (QHASHSHIFT + 3)))		\
4427c478bd9Sstevel@tonic-gate 	& (QHASHSIZE - 1)) + (((type) == MX)? 0 : QHASHSIZE))
4447c478bd9Sstevel@tonic-gate extern	queue_head_t	*queue_lock(void *, int);
4457c478bd9Sstevel@tonic-gate extern	void		queue_unlock(queue_head_t *);
446d4204c85Sraf extern	void		enqueue(queue_head_t *, struct ulwp *, int);
447d4204c85Sraf extern	struct ulwp	*dequeue(queue_head_t *, int *);
448d4204c85Sraf extern	struct ulwp	**queue_slot(queue_head_t *, struct ulwp **, int *);
449d4204c85Sraf extern	struct ulwp	*queue_waiter(queue_head_t *);
450d4204c85Sraf extern	int		dequeue_self(queue_head_t *);
451d4204c85Sraf extern	void		queue_unlink(queue_head_t *,
45241efec22Sraf 				struct ulwp **, struct ulwp *);
4537c478bd9Sstevel@tonic-gate extern	void		unsleep_self(void);
4547c478bd9Sstevel@tonic-gate extern	void		spin_lock_set(mutex_t *);
4557c478bd9Sstevel@tonic-gate extern	void		spin_lock_clear(mutex_t *);
457d4204c85Sraf /*
458d4204c85Sraf  * Scheduling class information structure.
459d4204c85Sraf  */
460d4204c85Sraf typedef struct {
461d4204c85Sraf 	short		pcc_state;
462d4204c85Sraf 	short		pcc_policy;
463d4204c85Sraf 	pri_t		pcc_primin;
464d4204c85Sraf 	pri_t		pcc_primax;
465d4204c85Sraf 	pcinfo_t	pcc_info;
466d4204c85Sraf } pcclass_t;
4687c478bd9Sstevel@tonic-gate /*
4697c478bd9Sstevel@tonic-gate  * Memory block for chain of owned ceiling mutexes.
4707c478bd9Sstevel@tonic-gate  */
4717c478bd9Sstevel@tonic-gate typedef struct mxchain {
4727c478bd9Sstevel@tonic-gate 	struct mxchain	*mxchain_next;
4737c478bd9Sstevel@tonic-gate 	mutex_t		*mxchain_mx;
4747c478bd9Sstevel@tonic-gate } mxchain_t;
4767c478bd9Sstevel@tonic-gate /*
4777c478bd9Sstevel@tonic-gate  * Pointer to an rwlock that is held for reading.
4787c478bd9Sstevel@tonic-gate  * Used in rw_rdlock() to allow a thread that already holds a read
4797c478bd9Sstevel@tonic-gate  * lock to acquire another read lock on the same rwlock even if
4807c478bd9Sstevel@tonic-gate  * there are writers waiting.  This to avoid deadlock when acquiring
4817c478bd9Sstevel@tonic-gate  * a read lock more than once in the presence of pending writers.
4827c478bd9Sstevel@tonic-gate  * POSIX mandates this behavior.
4837c478bd9Sstevel@tonic-gate  */
4847c478bd9Sstevel@tonic-gate typedef struct {
4857c478bd9Sstevel@tonic-gate 	void	*rd_rwlock;	/* the rwlock held for reading */
4867c478bd9Sstevel@tonic-gate 	size_t	rd_count;	/* count of read locks applied */
4877c478bd9Sstevel@tonic-gate } readlock_t;
4897c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
4907c478bd9Sstevel@tonic-gate typedef struct {
4917c478bd9Sstevel@tonic-gate 	caddr32_t	rd_rwlock;
4927c478bd9Sstevel@tonic-gate 	size32_t	rd_count;
4937c478bd9Sstevel@tonic-gate } readlock32_t;
4947c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
4964f364e7cSRobert Mustacchi /*
4974f364e7cSRobert Mustacchi  * As part of per-thread caching libumem (ptcumem), we add a small amount to the
4984f364e7cSRobert Mustacchi  * thread's uberdata to facilitate it. The tm_roots are the roots of linked
4994f364e7cSRobert Mustacchi  * lists which is used by libumem to chain together allocations. tm_size is used
5004f364e7cSRobert Mustacchi  * to track the total amount of data stored across those linked lists. For more
5014f364e7cSRobert Mustacchi  * information, see libumem's big theory statement.
5024f364e7cSRobert Mustacchi  */
5034f364e7cSRobert Mustacchi #define	NTMEMBASE	16
5044f364e7cSRobert Mustacchi 
5054f364e7cSRobert Mustacchi typedef struct {
5064f364e7cSRobert Mustacchi 	size_t		tm_size;
5074f364e7cSRobert Mustacchi 	void		*tm_roots[NTMEMBASE];
5084f364e7cSRobert Mustacchi } tumem_t;
5094f364e7cSRobert Mustacchi 
5104f364e7cSRobert Mustacchi #ifdef _SYSCALL32
5114f364e7cSRobert Mustacchi typedef struct {
5124f364e7cSRobert Mustacchi 	uint32_t	tm_size;
5134f364e7cSRobert Mustacchi 	caddr32_t	tm_roots[NTMEMBASE];
5144f364e7cSRobert Mustacchi } tumem32_t;
5154f364e7cSRobert Mustacchi #endif
5164f364e7cSRobert Mustacchi 
5174f364e7cSRobert Mustacchi typedef void (*tmem_func_t)(void *, int);
5184f364e7cSRobert Mustacchi 
5197c478bd9Sstevel@tonic-gate /*
5207c478bd9Sstevel@tonic-gate  * Maximum number of read locks allowed for one thread on one rwlock.
5217c478bd9Sstevel@tonic-gate  * This could be as large as INT_MAX, but the SUSV3 test suite would
5227c478bd9Sstevel@tonic-gate  * take an inordinately long time to complete.  This is big enough.
5237c478bd9Sstevel@tonic-gate  */
5247c478bd9Sstevel@tonic-gate #define	READ_LOCK_MAX	100000
5267c478bd9Sstevel@tonic-gate #define	ul_tlsent	ul_tls.tls_data	/* array of pointers to dynamic TLS */
5277c478bd9Sstevel@tonic-gate #define	ul_ntlsent	ul_tls.tls_size	/* number of entries in ul_tlsent */
5297c478bd9Sstevel@tonic-gate /*
5307c478bd9Sstevel@tonic-gate  * Round up an integral value to a multiple of 64
5317c478bd9Sstevel@tonic-gate  */
5327c478bd9Sstevel@tonic-gate #define	roundup64(x)	(-(-(x) & -64))
5347c478bd9Sstevel@tonic-gate /*
5357c478bd9Sstevel@tonic-gate  * NOTE:  Whatever changes are made to ulwp_t must be
5367c478bd9Sstevel@tonic-gate  * reflected in $SRC/cmd/mdb/common/modules/libc/libc.c
5377c478bd9Sstevel@tonic-gate  *
5387c478bd9Sstevel@tonic-gate  * NOTE: ul_self *must* be the first member of ulwp_t on x86
5397c478bd9Sstevel@tonic-gate  * Low-level x86 code relies on this.
5407c478bd9Sstevel@tonic-gate  */
5417c478bd9Sstevel@tonic-gate typedef struct ulwp {
5427c478bd9Sstevel@tonic-gate 	/*
5437c478bd9Sstevel@tonic-gate 	 * These members always need to come first on sparc.
5447c478bd9Sstevel@tonic-gate 	 * For dtrace, a ulwp_t must be aligned on a 64-byte boundary.
5457c478bd9Sstevel@tonic-gate 	 */
5467c478bd9Sstevel@tonic-gate #if defined(__sparc)
5477c478bd9Sstevel@tonic-gate 	uint32_t	ul_dinstr;	/* scratch space for dtrace */
5487c478bd9Sstevel@tonic-gate 	uint32_t	ul_padsparc0[15];
5497c478bd9Sstevel@tonic-gate 	uint32_t	ul_dsave;	/* dtrace: save %g1, %g0, %sp */
5507c478bd9Sstevel@tonic-gate 	uint32_t	ul_drestore;	/* dtrace: restore %g0, %g0, %g0 */
5517c478bd9Sstevel@tonic-gate 	uint32_t	ul_dftret;	/* dtrace: return probe fasttrap */
5527c478bd9Sstevel@tonic-gate 	uint32_t	ul_dreturn;	/* dtrace: return %o0 */
5537c478bd9Sstevel@tonic-gate #endif
5547c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_self;	/* pointer to self */
5557c478bd9Sstevel@tonic-gate #if defined(__i386)
5567c478bd9Sstevel@tonic-gate 	uint8_t		ul_dinstr[40];	/* scratch space for dtrace */
5577c478bd9Sstevel@tonic-gate #elif defined(__amd64)
5587c478bd9Sstevel@tonic-gate 	uint8_t		ul_dinstr[56];	/* scratch space for dtrace */
5597c478bd9Sstevel@tonic-gate #endif
5607c478bd9Sstevel@tonic-gate 	struct uberdata *ul_uberdata;	/* uber (super-global) data */
5617c478bd9Sstevel@tonic-gate 	tls_t		ul_tls;		/* dynamic thread-local storage base */
5627c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_forw;	/* forw, back all_lwps list, */
5637c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_back;	/* protected by link_lock */
5647c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_next;	/* list to keep track of stacks */
5657c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_hash;	/* hash chain linked list */
5667c478bd9Sstevel@tonic-gate 	void		*ul_rval;	/* return value from thr_exit() */
5677c478bd9Sstevel@tonic-gate 	caddr_t		ul_stk;		/* mapping base of the stack */
5687c478bd9Sstevel@tonic-gate 	size_t		ul_mapsiz;	/* mapping size of the stack */
5697c478bd9Sstevel@tonic-gate 	size_t		ul_guardsize;	/* normally _lpagesize */
5707c478bd9Sstevel@tonic-gate 	uintptr_t	ul_stktop;	/* broken thr_stksegment() interface */
5717c478bd9Sstevel@tonic-gate 	size_t		ul_stksiz;	/* broken thr_stksegment() interface */
5727c478bd9Sstevel@tonic-gate 	stack_t		ul_ustack;	/* current stack boundaries */
5737c478bd9Sstevel@tonic-gate 	int		ul_ix;		/* hash index */
5747c478bd9Sstevel@tonic-gate 	lwpid_t		ul_lwpid;	/* thread id, aka the lwp id */
575d4204c85Sraf 	pri_t		ul_pri;		/* scheduling priority */
576d4204c85Sraf 	pri_t		ul_epri;	/* real-time ceiling priority */
5777c478bd9Sstevel@tonic-gate 	char		ul_policy;	/* scheduling policy */
578d4204c85Sraf 	char		ul_cid;		/* scheduling class id */
5797c478bd9Sstevel@tonic-gate 	union {
5807c478bd9Sstevel@tonic-gate 		struct {
5817c478bd9Sstevel@tonic-gate 			char	cursig;	/* deferred signal number */
5827c478bd9Sstevel@tonic-gate 			char	pleasestop; /* lwp requested to stop itself */
5837c478bd9Sstevel@tonic-gate 		} s;
5847c478bd9Sstevel@tonic-gate 		short	curplease;	/* for testing both at once */
5857c478bd9Sstevel@tonic-gate 	} ul_cp;
5867c478bd9Sstevel@tonic-gate 	char		ul_stop;	/* reason for stopping */
5877c478bd9Sstevel@tonic-gate 	char		ul_signalled;	/* this lwp was cond_signal()d */
5887c478bd9Sstevel@tonic-gate 	char		ul_dead;	/* this lwp has called thr_exit */
5897c478bd9Sstevel@tonic-gate 	char		ul_unwind;	/* posix: unwind C++ stack */
5907c478bd9Sstevel@tonic-gate 	char		ul_detached;	/* THR_DETACHED at thread_create() */
5917c478bd9Sstevel@tonic-gate 					/* or pthread_detach() was called */
5927c478bd9Sstevel@tonic-gate 	char		ul_writer;	/* sleeping in rw_wrlock() */
5937c478bd9Sstevel@tonic-gate 	char		ul_stopping;	/* set by curthread: stopping self */
59434709573Sraf 	char		ul_cancel_prologue;	/* for _cancel_prologue() */
5957c478bd9Sstevel@tonic-gate 	short		ul_preempt;	/* no_preempt()/preempt() */
5967c478bd9Sstevel@tonic-gate 	short		ul_savpreempt;	/* pre-existing preempt value */
5977c478bd9Sstevel@tonic-gate 	char		ul_sigsuspend;	/* thread is in sigsuspend/pollsys */
5987c478bd9Sstevel@tonic-gate 	char		ul_main;	/* thread is the main thread */
5997c478bd9Sstevel@tonic-gate 	char		ul_fork;	/* thread is performing a fork */
6007c478bd9Sstevel@tonic-gate 	char		ul_primarymap;	/* primary link-map is initialized */
6017c478bd9Sstevel@tonic-gate 	/* per-thread copies of the corresponding global variables */
6025d1dd9a9Sraf 	uint8_t		ul_max_spinners;	/* thread_max_spinners */
6037c478bd9Sstevel@tonic-gate 	char		ul_door_noreserve;	/* thread_door_noreserve */
6047c478bd9Sstevel@tonic-gate 	char		ul_queue_fifo;		/* thread_queue_fifo */
6057c478bd9Sstevel@tonic-gate 	char		ul_cond_wait_defer;	/* thread_cond_wait_defer */
6067c478bd9Sstevel@tonic-gate 	char		ul_error_detection;	/* thread_error_detection */
6077c478bd9Sstevel@tonic-gate 	char		ul_async_safe;		/* thread_async_safe */
608d4204c85Sraf 	char		ul_rt;			/* found on an RT queue */
609d4204c85Sraf 	char		ul_rtqueued;		/* was RT when queued */
6107c5714f6Sraf 	char		ul_misaligned;		/* thread_locks_misaligned */
6117c5714f6Sraf 	char		ul_pad[3];
6127c478bd9Sstevel@tonic-gate 	int		ul_adaptive_spin;	/* thread_adaptive_spin */
6137c478bd9Sstevel@tonic-gate 	int		ul_queue_spin;		/* thread_queue_spin */
6147c478bd9Sstevel@tonic-gate 	volatile int	ul_critical;	/* non-zero == in a critical region */
6157c478bd9Sstevel@tonic-gate 	int		ul_sigdefer;	/* non-zero == defer signals */
6167c478bd9Sstevel@tonic-gate 	int		ul_vfork;	/* thread is the child of vfork() */
6177c478bd9Sstevel@tonic-gate 	int		ul_cancelable;	/* _cancelon()/_canceloff() */
6187c478bd9Sstevel@tonic-gate 	char		ul_cancel_pending;  /* pthread_cancel() was called */
6197c478bd9Sstevel@tonic-gate 	char		ul_cancel_disabled; /* PTHREAD_CANCEL_DISABLE */
6207c478bd9Sstevel@tonic-gate 	char		ul_cancel_async;    /* PTHREAD_CANCEL_ASYNCHRONOUS */
6217c478bd9Sstevel@tonic-gate 	char		ul_save_async;	/* saved copy of ul_cancel_async */
6227c478bd9Sstevel@tonic-gate 	char		ul_mutator;	/* lwp is a mutator (java interface) */
6237c478bd9Sstevel@tonic-gate 	char		ul_created;	/* created suspended */
6247c478bd9Sstevel@tonic-gate 	char		ul_replace;	/* replacement; must be free()d */
6257c478bd9Sstevel@tonic-gate 	uchar_t		ul_nocancel;	/* cancellation can't happen */
6267c478bd9Sstevel@tonic-gate 	int		ul_errno;	/* per-thread errno */
6277c478bd9Sstevel@tonic-gate 	int		*ul_errnop;	/* pointer to errno or self->ul_errno */
6287c478bd9Sstevel@tonic-gate 	__cleanup_t	*ul_clnup_hdr;	/* head of cleanup handlers list */
629d4204c85Sraf 	uberflags_t	*ul_schedctl_called;	/* ul_schedctl is set up */
630d4204c85Sraf 	volatile sc_shared_t *ul_schedctl;	/* schedctl data */
6317c478bd9Sstevel@tonic-gate 	int		ul_bindflags;	/* bind_guard() interface to ld.so.1 */
632a574db85Sraf 	uint_t		ul_libc_locks;	/* count of cancel_safe_mutex_lock()s */
6337c478bd9Sstevel@tonic-gate 	tsd_t		*ul_stsd;	/* slow TLS for keys >= TSD_NFAST */
6347c478bd9Sstevel@tonic-gate 	void		*ul_ftsd[TSD_NFAST]; /* fast TLS for keys < TSD_NFAST */
6357c478bd9Sstevel@tonic-gate 	td_evbuf_t	ul_td_evbuf;	/* event buffer */
6367c478bd9Sstevel@tonic-gate 	char		ul_td_events_enable;	/* event mechanism enabled */
6377c478bd9Sstevel@tonic-gate 	char		ul_sync_obj_reg;	/* tdb_sync_obj_register() */
6387c478bd9Sstevel@tonic-gate 	char		ul_qtype;	/* MX or CV */
6397c478bd9Sstevel@tonic-gate 	char		ul_cv_wake;	/* != 0: just wake up, don't requeue */
640e54ab87fSRoger A. Faulkner 	int		ul_rtld;	/* thread is running inside ld.so.1 */
6417c478bd9Sstevel@tonic-gate 	int		ul_usropts;	/* flags given to thr_create() */
6427c478bd9Sstevel@tonic-gate 	void		*(*ul_startpc)(void *); /* start func (thr_create()) */
6437c478bd9Sstevel@tonic-gate 	void		*ul_startarg;	/* argument for start function */
6447c478bd9Sstevel@tonic-gate 	void		*ul_wchan;	/* synch object when sleeping */
6457c478bd9Sstevel@tonic-gate 	struct ulwp	*ul_link;	/* sleep queue link */
6467c478bd9Sstevel@tonic-gate 	queue_head_t	*ul_sleepq;	/* sleep queue thread is waiting on */
6477c478bd9Sstevel@tonic-gate 	mutex_t		*ul_cvmutex;	/* mutex dropped when waiting on a cv */
6487c478bd9Sstevel@tonic-gate 	mxchain_t	*ul_mxchain;	/* chain of owned ceiling mutexes */
649d4204c85Sraf 	int		ul_save_state;	/* bind_guard() interface to ld.so.1 */
650883492d5Sraf 	uint_t		ul_rdlockcnt;	/* # entries in ul_readlock array */
651883492d5Sraf 				/* 0 means there is but a single entry */
652883492d5Sraf 	union {				/* single entry or pointer to array */
6537c478bd9Sstevel@tonic-gate 		readlock_t	single;
6547c478bd9Sstevel@tonic-gate 		readlock_t	*array;
6557c478bd9Sstevel@tonic-gate 	} ul_readlock;
656883492d5Sraf 	uint_t		ul_heldlockcnt;	/* # entries in ul_heldlocks array */
657883492d5Sraf 				/* 0 means there is but a single entry */
658883492d5Sraf 	union {				/* single entry or pointer to array */
659883492d5Sraf 		mutex_t		*single;
660883492d5Sraf 		mutex_t		**array;
661883492d5Sraf 	} ul_heldlocks;
6627c478bd9Sstevel@tonic-gate 	/* PROBE_SUPPORT begin */
6637c478bd9Sstevel@tonic-gate 	void		*ul_tpdp;
6647c478bd9Sstevel@tonic-gate 	/* PROBE_SUPPORT end */
6657c478bd9Sstevel@tonic-gate 	ucontext_t	*ul_siglink;	/* pointer to previous context */
6667c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_spin;	/* spin lock statistics */
6677c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_spin2;
6687c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_sleep;
6697c478bd9Sstevel@tonic-gate 	uint_t		ul_spin_lock_wakeup;
670d4204c85Sraf 	queue_root_t	ul_queue_root;	/* root of a sleep queue */
671d4204c85Sraf 	id_t		ul_rtclassid;	/* real-time class id */
672d4204c85Sraf 	uint_t		ul_pilocks;	/* count of PI locks held */
6737c478bd9Sstevel@tonic-gate 		/* the following members *must* be last in the structure */
6747c478bd9Sstevel@tonic-gate 		/* they are discarded when ulwp is replaced on thr_exit() */
6757c478bd9Sstevel@tonic-gate 	sigset_t	ul_sigmask;	/* thread's current signal mask */
6767c478bd9Sstevel@tonic-gate 	sigset_t	ul_tmpmask;	/* signal mask for sigsuspend/pollsys */
6777c478bd9Sstevel@tonic-gate 	siginfo_t	ul_siginfo;	/* deferred siginfo */
6787c478bd9Sstevel@tonic-gate 	mutex_t		ul_spinlock;	/* used when suspending/continuing */
6797c478bd9Sstevel@tonic-gate 	fpuenv_t	ul_fpuenv;	/* floating point state */
6807c478bd9Sstevel@tonic-gate 	uintptr_t	ul_sp;		/* stack pointer when blocked */
6817c478bd9Sstevel@tonic-gate 	void		*ul_ex_unwind;	/* address of _ex_unwind() or -1 */
6827c478bd9Sstevel@tonic-gate #if defined(sparc)
6837c478bd9Sstevel@tonic-gate 	void		*ul_unwind_ret;	/* used only by _ex_clnup_handler() */
6847c478bd9Sstevel@tonic-gate #endif
6854f364e7cSRobert Mustacchi 	tumem_t		ul_tmem;	/* used only by umem */
686e56998eeSRobert Mustacchi 	uint_t		ul_ptinherit;	/* pthreads sched inherit value */
6878a7aa2a5SYuri Pankov 	char		ul_ntoabuf[18];	/* thread-specific inet_ntoa buffer */
6887c478bd9Sstevel@tonic-gate } ulwp_t;
6907c478bd9Sstevel@tonic-gate #define	ul_cursig	ul_cp.s.cursig		/* deferred signal number */
6917c478bd9Sstevel@tonic-gate #define	ul_pleasestop	ul_cp.s.pleasestop	/* lwp requested to stop */
6927c478bd9Sstevel@tonic-gate #define	ul_curplease	ul_cp.curplease		/* for testing both at once */
6947c478bd9Sstevel@tonic-gate /*
6957c478bd9Sstevel@tonic-gate  * This is the size of a replacement ulwp, retained only for the benefit
6967c478bd9Sstevel@tonic-gate  * of thr_join().  The trailing members are unneeded for this purpose.
6977c478bd9Sstevel@tonic-gate  */
6987c478bd9Sstevel@tonic-gate #define	REPLACEMENT_SIZE	((size_t)&((ulwp_t *)NULL)->ul_sigmask)
7007c478bd9Sstevel@tonic-gate /*
7017c478bd9Sstevel@tonic-gate  * Definitions for static initialization of signal sets,
7027c478bd9Sstevel@tonic-gate  * plus some sneaky optimizations in various places.
7037c478bd9Sstevel@tonic-gate  */
7057c478bd9Sstevel@tonic-gate #define	SIGMASK(sig)	((uint32_t)1 << (((sig) - 1) & (32 - 1)))
707bdf0047cSRoger A. Faulkner #if (MAXSIG > (2 * 32) && MAXSIG <= (3 * 32))
7087c478bd9Sstevel@tonic-gate #define	FILLSET0	0xffffffffu
709bdf0047cSRoger A. Faulkner #define	FILLSET1	0xffffffffu
710bdf0047cSRoger A. Faulkner #define	FILLSET2	((1u << (MAXSIG - 64)) - 1)
711bdf0047cSRoger A. Faulkner #define	FILLSET3	0
7127c478bd9Sstevel@tonic-gate #else
7137c478bd9Sstevel@tonic-gate #error "fix me: MAXSIG out of bounds"
7147c478bd9Sstevel@tonic-gate #endif
7167c478bd9Sstevel@tonic-gate #define	CANTMASK0	(SIGMASK(SIGKILL) | SIGMASK(SIGSTOP))
7177c478bd9Sstevel@tonic-gate #define	CANTMASK1	0
718bdf0047cSRoger A. Faulkner #define	CANTMASK2	0
719bdf0047cSRoger A. Faulkner #define	CANTMASK3	0
7217c478bd9Sstevel@tonic-gate #define	MASKSET0	(FILLSET0 & ~CANTMASK0)
7227c478bd9Sstevel@tonic-gate #define	MASKSET1	(FILLSET1 & ~CANTMASK1)
723bdf0047cSRoger A. Faulkner #define	MASKSET2	(FILLSET2 & ~CANTMASK2)
724bdf0047cSRoger A. Faulkner #define	MASKSET3	(FILLSET3 & ~CANTMASK3)
726f841f6adSraf extern	const sigset_t maskset;		/* set of all maskable signals */
7287c478bd9Sstevel@tonic-gate extern	int	thread_adaptive_spin;
7297c478bd9Sstevel@tonic-gate extern	uint_t	thread_max_spinners;
7307c478bd9Sstevel@tonic-gate extern	int	thread_queue_spin;
7317c478bd9Sstevel@tonic-gate extern	int	thread_queue_fifo;
7327c478bd9Sstevel@tonic-gate extern	int	thread_queue_dump;
7337c478bd9Sstevel@tonic-gate extern	int	thread_cond_wait_defer;
7347c478bd9Sstevel@tonic-gate extern	int	thread_async_safe;
7357c478bd9Sstevel@tonic-gate extern	int	thread_queue_verify;
7377c478bd9Sstevel@tonic-gate /*
7387c478bd9Sstevel@tonic-gate  * pthread_atfork() related data, used to store atfork handlers.
7397c478bd9Sstevel@tonic-gate  */
7407c478bd9Sstevel@tonic-gate typedef struct atfork {
7417c478bd9Sstevel@tonic-gate 	struct atfork *forw;		/* forward pointer */
7427c478bd9Sstevel@tonic-gate 	struct atfork *back;		/* backward pointer */
7437c478bd9Sstevel@tonic-gate 	void (*prepare)(void);		/* pre-fork handler */
7447c478bd9Sstevel@tonic-gate 	void (*parent)(void);		/* post-fork parent handler */
7457c478bd9Sstevel@tonic-gate 	void (*child)(void);		/* post-fork child handler */
7467c478bd9Sstevel@tonic-gate } atfork_t;
748883492d5Sraf /*
74909ce0d4aSRoger A. Faulkner  * Element in the table and in the list of registered process
75009ce0d4aSRoger A. Faulkner  * robust locks.  We keep track of these to make sure that we
75109ce0d4aSRoger A. Faulkner  * only call ___lwp_mutex_register() once for each such lock
75209ce0d4aSRoger A. Faulkner  * after it is first mapped in (or newly mapped in).
753883492d5Sraf  */
754883492d5Sraf typedef struct robust {
75509ce0d4aSRoger A. Faulkner 	struct robust	*robust_next;	/* hash table list */
75609ce0d4aSRoger A. Faulkner 	struct robust	*robust_list;	/* global list */
757883492d5Sraf 	mutex_t		*robust_lock;
758883492d5Sraf } robust_t;
76009ce0d4aSRoger A. Faulkner /*
76109ce0d4aSRoger A. Faulkner  * Invalid address, used to mark an unused element in the hash table.
76209ce0d4aSRoger A. Faulkner  */
76309ce0d4aSRoger A. Faulkner #define	INVALID_ADDR	((void *)(uintptr_t)(-1L))
76409ce0d4aSRoger A. Faulkner 
765883492d5Sraf /*
766883492d5Sraf  * Parameters of the lock registration hash table.
767883492d5Sraf  */
768daa03c95Sraf #define	LOCKSHIFT	15			/* number of hashing bits */
769daa03c95Sraf #define	LOCKHASHSZ	(1 << LOCKSHIFT)	/* power of 2 (1<<15 == 32K) */
770883492d5Sraf #define	LOCK_HASH(addr)	(uint_t)			\
771883492d5Sraf 	((((uintptr_t)(addr) >> 3)			\
772883492d5Sraf 	^ ((uintptr_t)(addr) >> (LOCKSHIFT + 3)))	\
773883492d5Sraf 	& (LOCKHASHSZ - 1))
7757c478bd9Sstevel@tonic-gate /*
7767c478bd9Sstevel@tonic-gate  * Make our hot locks reside on private cache lines (64 bytes).
7777c478bd9Sstevel@tonic-gate  */
7787c478bd9Sstevel@tonic-gate typedef struct {
7797c478bd9Sstevel@tonic-gate 	mutex_t	pad_lock;
7802e145884Sraf 	char	pad_pad[64 - sizeof (mutex_t)];
7817c478bd9Sstevel@tonic-gate } pad_lock_t;
7832e145884Sraf /*
7842e145884Sraf  * Make our semi-hot locks reside on semi-private cache lines (32 bytes).
7852e145884Sraf  */
7862e145884Sraf typedef struct {
7872e145884Sraf 	mutex_t	pad_lock;
7882e145884Sraf 	char	pad_pad[32 - sizeof (mutex_t)];
7892e145884Sraf } pad32_lock_t;
7917c478bd9Sstevel@tonic-gate /*
7927c478bd9Sstevel@tonic-gate  * The threads hash table is used for fast lookup and locking of an active
7937c478bd9Sstevel@tonic-gate  * thread structure (ulwp_t) given a thread-id.  It is an N-element array of
7947c478bd9Sstevel@tonic-gate  * thr_hash_table_t structures, where N == 1 before the main thread creates
7957c478bd9Sstevel@tonic-gate  * the first additional thread and N == 1024 afterwards.  Each element of the
7967c478bd9Sstevel@tonic-gate  * table is 64 bytes in size and alignment to reduce cache conflicts.
7977c478bd9Sstevel@tonic-gate  */
7987c478bd9Sstevel@tonic-gate typedef struct {
7997c478bd9Sstevel@tonic-gate 	mutex_t	hash_lock;	/* lock per bucket */
8007c478bd9Sstevel@tonic-gate 	cond_t	hash_cond;	/* convar per bucket */
8017c478bd9Sstevel@tonic-gate 	ulwp_t	*hash_bucket;	/* hash bucket points to the list of ulwps */
8027c478bd9Sstevel@tonic-gate 	char	hash_pad[64 -	/* pad out to 64 bytes */
8037c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (cond_t) + sizeof (ulwp_t *))];
8047c478bd9Sstevel@tonic-gate } thr_hash_table_t;
8067c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
8077c478bd9Sstevel@tonic-gate typedef struct {
8087c478bd9Sstevel@tonic-gate 	mutex_t	hash_lock;
8097c478bd9Sstevel@tonic-gate 	cond_t	hash_cond;
8107c478bd9Sstevel@tonic-gate 	caddr32_t hash_bucket;
8117c478bd9Sstevel@tonic-gate 	char	hash_pad[64 -
8127c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (cond_t) + sizeof (caddr32_t))];
8137c478bd9Sstevel@tonic-gate } thr_hash_table32_t;
8147c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
8177c478bd9Sstevel@tonic-gate /*
81841efec22Sraf  * siguaction members have 128-byte size and 64-byte alignment.
81941efec22Sraf  * We know that sizeof (struct sigaction) is 32 bytes for both
82041efec22Sraf  * _ILP32 and _LP64 and that sizeof (rwlock_t) is 64 bytes.
8217c478bd9Sstevel@tonic-gate  */
8227c478bd9Sstevel@tonic-gate typedef struct {
82341efec22Sraf 	rwlock_t	sig_lock;
8247c478bd9Sstevel@tonic-gate 	struct sigaction sig_uaction;
82541efec22Sraf 	char	sig_pad[128 - sizeof (rwlock_t) - sizeof (struct sigaction)];
8267c478bd9Sstevel@tonic-gate } siguaction_t;
8287c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
8297c478bd9Sstevel@tonic-gate typedef struct {
83041efec22Sraf 	rwlock_t	sig_lock;
8317c478bd9Sstevel@tonic-gate 	struct sigaction32 sig_uaction;
83241efec22Sraf 	char	sig_pad[128 - sizeof (rwlock_t) - sizeof (struct sigaction32)];
8337c478bd9Sstevel@tonic-gate } siguaction32_t;
8347c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
8377c478bd9Sstevel@tonic-gate /*
8387c478bd9Sstevel@tonic-gate  * Bucket structures, used by lmalloc()/lfree().
8397c478bd9Sstevel@tonic-gate  * See port/threads/alloc.c for details.
8407c478bd9Sstevel@tonic-gate  * A bucket's size and alignment is 64 bytes.
8417c478bd9Sstevel@tonic-gate  */
8427c478bd9Sstevel@tonic-gate typedef struct {
8437c478bd9Sstevel@tonic-gate 	mutex_t	bucket_lock;	/* protects the free list allocations */
8447c478bd9Sstevel@tonic-gate 	void	*free_list;	/* LIFO list of blocks to allocate/free */
8457c478bd9Sstevel@tonic-gate 	size_t	chunks;		/* number of 64K blocks mmap()ed last time */
8467c478bd9Sstevel@tonic-gate 	char	pad64[64 -	/* pad out to 64 bytes */
8477c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (void *) + sizeof (size_t))];
8487c478bd9Sstevel@tonic-gate } bucket_t;
8507c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
8517c478bd9Sstevel@tonic-gate typedef struct {
8527c478bd9Sstevel@tonic-gate 	mutex_t		bucket_lock;
8537c478bd9Sstevel@tonic-gate 	caddr32_t	free_list;
8547c478bd9Sstevel@tonic-gate 	size32_t	chunks;
8557c478bd9Sstevel@tonic-gate 	char	pad64[64 -	/* pad out to 64 bytes */
8567c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (caddr32_t) + sizeof (size32_t))];
8577c478bd9Sstevel@tonic-gate } bucket32_t;
8587c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
8607c478bd9Sstevel@tonic-gate #define	NBUCKETS	10	/* sizes ranging from 64 to 32768 */
8637c478bd9Sstevel@tonic-gate /*
8647c478bd9Sstevel@tonic-gate  * atexit() data structures.
8657c478bd9Sstevel@tonic-gate  * See port/gen/atexit.c for details.
8667c478bd9Sstevel@tonic-gate  */
8675c069a6cSRichard Lowe typedef void (*_exithdlr_func_t) (void*);
8697c478bd9Sstevel@tonic-gate typedef struct _exthdlr {
8708a7aa2a5SYuri Pankov 	struct _exthdlr		*next;	/* next in handler list */
8717c478bd9Sstevel@tonic-gate 	_exithdlr_func_t	hdlr;	/* handler itself */
8725c069a6cSRichard Lowe 	void			*arg;	/* argument to handler */
8735c069a6cSRichard Lowe 	void			*dso;	/* DSO associated with handler */
8747c478bd9Sstevel@tonic-gate } _exthdlr_t;
8767c478bd9Sstevel@tonic-gate typedef struct {
8777c478bd9Sstevel@tonic-gate 	mutex_t		exitfns_lock;
8787c478bd9Sstevel@tonic-gate 	_exthdlr_t	*head;
8795c069a6cSRichard Lowe 	/*
8805c069a6cSRichard Lowe 	 * exit_frame_monitor is part of a private contract between libc and
8815c069a6cSRichard Lowe 	 * the Sun C++ runtime.
8825c069a6cSRichard Lowe 	 *
8835c069a6cSRichard Lowe 	 * It should be NULL until exit() is called, and thereafter hold the
8845c069a6cSRichard Lowe 	 * frame pointer of the function implementing our exit processing.
8855c069a6cSRichard Lowe 	 */
8867c478bd9Sstevel@tonic-gate 	void		*exit_frame_monitor;
8877c478bd9Sstevel@tonic-gate 	char		exit_pad[64 -	/* pad out to 64 bytes */
8887c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (_exthdlr_t *) + sizeof (void *))];
8897c478bd9Sstevel@tonic-gate } atexit_root_t;
8917c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
8927c478bd9Sstevel@tonic-gate typedef struct {
8937c478bd9Sstevel@tonic-gate 	mutex_t		exitfns_lock;
8947c478bd9Sstevel@tonic-gate 	caddr32_t	head;
8957c478bd9Sstevel@tonic-gate 	caddr32_t	exit_frame_monitor;
8967c478bd9Sstevel@tonic-gate 	char		exit_pad[64 -	/* pad out to 64 bytes */
8977c478bd9Sstevel@tonic-gate 		(sizeof (mutex_t) + sizeof (caddr32_t) + sizeof (caddr32_t))];
8987c478bd9Sstevel@tonic-gate } atexit_root32_t;
8997c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
901fc2512cfSRobert Mustacchi /*
902fc2512cfSRobert Mustacchi  * at_quick_exit() and quick_exit() data structures. The ISO/IEC C11 odd
903fc2512cfSRobert Mustacchi  * siblings of atexit()
904fc2512cfSRobert Mustacchi  */
905fc2512cfSRobert Mustacchi typedef void (*_quick_exithdlr_func_t)(void);
906fc2512cfSRobert Mustacchi 
907fc2512cfSRobert Mustacchi typedef struct _qexthdlr {
9088a7aa2a5SYuri Pankov 	struct _qexthdlr	*next;	/* next in handler list */
909fc2512cfSRobert Mustacchi 	_quick_exithdlr_func_t	hdlr;	/* handler itself */
910fc2512cfSRobert Mustacchi } _qexthdlr_t;
911fc2512cfSRobert Mustacchi 
912ff892b7cSRobert Mustacchi /*
913ff892b7cSRobert Mustacchi  * We add a pad on 32-bit systems to allow us to always have the structure size
914ff892b7cSRobert Mustacchi  * be 32-bytes which helps us deal with the compiler's alignment when building
915ff892b7cSRobert Mustacchi  * in ILP32 / LP64 systems.
916ff892b7cSRobert Mustacchi  */
917fc2512cfSRobert Mustacchi typedef struct {
918fc2512cfSRobert Mustacchi 	mutex_t		exitfns_lock;
919fc2512cfSRobert Mustacchi 	_qexthdlr_t	*head;
920ff892b7cSRobert Mustacchi #if !defined(_LP64)
921ff892b7cSRobert Mustacchi 	uint32_t	pad;
922ff892b7cSRobert Mustacchi #endif
923fc2512cfSRobert Mustacchi } quickexit_root_t;
924fc2512cfSRobert Mustacchi 
925fc2512cfSRobert Mustacchi #ifdef _SYSCALL32
926fc2512cfSRobert Mustacchi typedef struct {
927fc2512cfSRobert Mustacchi 	mutex_t		exitfns_lock;
928fc2512cfSRobert Mustacchi 	caddr32_t	head;
929ff892b7cSRobert Mustacchi 	uint32_t	pad;
930fc2512cfSRobert Mustacchi } quickexit_root32_t;
931fc2512cfSRobert Mustacchi #endif /* _SYSCALL32 */
9337c478bd9Sstevel@tonic-gate /*
9347c478bd9Sstevel@tonic-gate  * This is data that is global to all link maps (uberdata, aka super-global).
935fe4be5acSGordon Ross  * Note: When changing this, please be sure to keep the 32-bit variant of
936fe4be5acSGordon Ross  * this in sync.  (see uberdata32_t below)
9377c478bd9Sstevel@tonic-gate  */
9387c478bd9Sstevel@tonic-gate typedef struct uberdata {
9397c478bd9Sstevel@tonic-gate 	pad_lock_t	_link_lock;
9408cd45542Sraf 	pad_lock_t	_ld_lock;
9418cd45542Sraf 	pad_lock_t	_fork_lock;
9428cd45542Sraf 	pad_lock_t	_atfork_lock;
94398c1a6b4Sraf 	pad32_lock_t	_callout_lock;
94498c1a6b4Sraf 	pad32_lock_t	_tdb_hash_lock;
9457c478bd9Sstevel@tonic-gate 	tdb_sync_stats_t tdb_hash_lock_stats;
9467c478bd9Sstevel@tonic-gate 	siguaction_t	siguaction[NSIG];
9477c478bd9Sstevel@tonic-gate 	bucket_t	bucket[NBUCKETS];
9487c478bd9Sstevel@tonic-gate 	atexit_root_t	atexit_root;
949fc2512cfSRobert Mustacchi 	quickexit_root_t quickexit_root;
9507c478bd9Sstevel@tonic-gate 	tsd_metadata_t	tsd_metadata;
9517c478bd9Sstevel@tonic-gate 	tls_metadata_t	tls_metadata;
9527c478bd9Sstevel@tonic-gate 	/*
9537c478bd9Sstevel@tonic-gate 	 * Every object before this point has size and alignment of 64 bytes.
9547c478bd9Sstevel@tonic-gate 	 * Don't add any other type of data before this point.
9557c478bd9Sstevel@tonic-gate 	 */
9567c478bd9Sstevel@tonic-gate 	char	primary_map;	/* set when primary link map is initialized */
9577c478bd9Sstevel@tonic-gate 	char	bucket_init;	/* set when bucket[NBUCKETS] is initialized */
9587c478bd9Sstevel@tonic-gate 	char	pad[2];
9597c478bd9Sstevel@tonic-gate 	uberflags_t	uberflags;
9607c478bd9Sstevel@tonic-gate 	queue_head_t	*queue_head;
9617c478bd9Sstevel@tonic-gate 	thr_hash_table_t *thr_hash_table;
9627c478bd9Sstevel@tonic-gate 	uint_t		hash_size;	/* # of entries in thr_hash_table[] */
9637c478bd9Sstevel@tonic-gate 	uint_t		hash_mask;	/* hash_size - 1 */
9647c478bd9Sstevel@tonic-gate 	ulwp_t	*ulwp_one;	/* main thread */
9657c478bd9Sstevel@tonic-gate 	ulwp_t	*all_lwps;	/* circular ul_forw/ul_back list of live lwps */
9667c478bd9Sstevel@tonic-gate 	ulwp_t	*all_zombies;	/* circular ul_forw/ul_back list of zombies */
9677c478bd9Sstevel@tonic-gate 	int	nthreads;	/* total number of live threads/lwps */
9687c478bd9Sstevel@tonic-gate 	int	nzombies;	/* total number of zombie threads */
9697c478bd9Sstevel@tonic-gate 	int	ndaemons;	/* total number of THR_DAEMON threads/lwps */
9707c478bd9Sstevel@tonic-gate 	pid_t	pid;		/* the current process's pid */
9717c478bd9Sstevel@tonic-gate 	void	(*sigacthandler)(int, siginfo_t *, void *);
9727c478bd9Sstevel@tonic-gate 	ulwp_t	*lwp_stacks;
9737c478bd9Sstevel@tonic-gate 	ulwp_t	*lwp_laststack;
9747c478bd9Sstevel@tonic-gate 	int	nfreestack;
9757c478bd9Sstevel@tonic-gate 	int	thread_stack_cache;
9767c478bd9Sstevel@tonic-gate 	ulwp_t	*ulwp_freelist;
9777c478bd9Sstevel@tonic-gate 	ulwp_t	*ulwp_lastfree;
9787c478bd9Sstevel@tonic-gate 	ulwp_t	*ulwp_replace_free;
9797c478bd9Sstevel@tonic-gate 	ulwp_t	*ulwp_replace_last;
9807c478bd9Sstevel@tonic-gate 	atfork_t	*atforklist;	/* circular Q for fork handlers */
981883492d5Sraf 	robust_t	**robustlocks;	/* table of registered robust locks */
98209ce0d4aSRoger A. Faulkner 	robust_t	*robustlist;	/* list of registered robust locks */
98323a1cceaSRoger A. Faulkner 	char	*progname;	/* the basename of the program, from argv[0] */
9842428aad8SPatrick Mooney 	void	*ub_comm_page;	/* arch-specific comm page of kernel data */
9857c478bd9Sstevel@tonic-gate 	struct uberdata **tdb_bootstrap;
9867c478bd9Sstevel@tonic-gate 	tdb_t	tdb;		/* thread debug interfaces (for libc_db) */
9877c478bd9Sstevel@tonic-gate } uberdata_t;
9897c478bd9Sstevel@tonic-gate #define	link_lock	_link_lock.pad_lock
9908cd45542Sraf #define	ld_lock		_ld_lock.pad_lock
9917c478bd9Sstevel@tonic-gate #define	fork_lock	_fork_lock.pad_lock
9922e145884Sraf #define	atfork_lock	_atfork_lock.pad_lock
99398c1a6b4Sraf #define	callout_lock	_callout_lock.pad_lock
9947c478bd9Sstevel@tonic-gate #define	tdb_hash_lock	_tdb_hash_lock.pad_lock
9967c478bd9Sstevel@tonic-gate #pragma align 64(__uberdata)
9977c478bd9Sstevel@tonic-gate extern	uberdata_t	__uberdata;
9987c478bd9Sstevel@tonic-gate extern	uberdata_t	**__tdb_bootstrap;	/* known to libc_db and mdb */
9997c478bd9Sstevel@tonic-gate extern	int		primary_link_map;
10017c478bd9Sstevel@tonic-gate #define	ulwp_mutex(ulwp, udp)	\
10027c478bd9Sstevel@tonic-gate 	(&(udp)->thr_hash_table[(ulwp)->ul_ix].hash_lock)
10037c478bd9Sstevel@tonic-gate #define	ulwp_condvar(ulwp, udp)	\
10047c478bd9Sstevel@tonic-gate 	(&(udp)->thr_hash_table[(ulwp)->ul_ix].hash_cond)
10067c478bd9Sstevel@tonic-gate /*
10077c478bd9Sstevel@tonic-gate  * Grab and release the hash table lock for the specified lwp.
10087c478bd9Sstevel@tonic-gate  */
10097c478bd9Sstevel@tonic-gate #define	ulwp_lock(ulwp, udp)	lmutex_lock(ulwp_mutex(ulwp, udp))
10107c478bd9Sstevel@tonic-gate #define	ulwp_unlock(ulwp, udp)	lmutex_unlock(ulwp_mutex(ulwp, udp))
10127c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32	/* needed by libc_db */
10147c478bd9Sstevel@tonic-gate typedef struct ulwp32 {
10157c478bd9Sstevel@tonic-gate #if defined(__sparc)
10167c478bd9Sstevel@tonic-gate 	uint32_t	ul_dinstr;	/* scratch space for dtrace */
10177c478bd9Sstevel@tonic-gate 	uint32_t	ul_padsparc0[15];
10187c478bd9Sstevel@tonic-gate 	uint32_t	ul_dsave;	/* dtrace: save %g1, %g0, %sp */
10197c478bd9Sstevel@tonic-gate 	uint32_t	ul_drestore;	/* dtrace: restore %g0, %g0, %g0 */
10207c478bd9Sstevel@tonic-gate 	uint32_t	ul_dftret;	/* dtrace: return probe fasttrap */
10217c478bd9Sstevel@tonic-gate 	uint32_t	ul_dreturn;	/* dtrace: return %o0 */
10227c478bd9Sstevel@tonic-gate #endif
10237c478bd9Sstevel@tonic-gate 	caddr32_t	ul_self;	/* pointer to self */
10240ec57554Sraf #if defined(__x86)