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