xref: /onnv-gate/usr/src/lib/libc/port/threads/scalls.c (revision 4914:8e96a2e351b2)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51885Sraf  * Common Development and Distribution License (the "License").
61885Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211111Sraf 
220Sstevel@tonic-gate /*
233512Sraf  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include "lint.h"
300Sstevel@tonic-gate #include "thr_uberdata.h"
310Sstevel@tonic-gate #include <stdarg.h>
320Sstevel@tonic-gate #include <poll.h>
330Sstevel@tonic-gate #include <stropts.h>
340Sstevel@tonic-gate #include <dlfcn.h>
350Sstevel@tonic-gate #include <sys/uio.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate /*
38*4914Sraf  * fork_lock does double-duty.  Not only does it (and atfork_lock)
39*4914Sraf  * serialize calls to fork() and forkall(), but it also serializes calls
40*4914Sraf  * to thr_suspend() and thr_continue() (because fork() and forkall() also
41*4914Sraf  * suspend and continue other threads and they want no competition).
42*4914Sraf  *
43*4914Sraf  * atfork_lock also does double-duty.  Not only does it protect the
44*4914Sraf  * pthread_atfork() data structures, but it also serializes I18N calls
45*4914Sraf  * to functions in dlopen()ed L10N objects.  These functions can do
46*4914Sraf  * anything, including call malloc() and free().  Such calls are not
47*4914Sraf  * fork-safe when protected by an ordinary mutex because, with an
48*4914Sraf  * interposed malloc library present, there would be a lock ordering
49*4914Sraf  * violation due to the pthread_atfork() prefork function in the
50*4914Sraf  * interposition library acquiring its malloc lock(s) before the
51*4914Sraf  * ordinary mutex in libc being acquired by libc's prefork functions.
52*4914Sraf  *
53*4914Sraf  * Within libc, calls to malloc() and free() are fork-safe only if the
54*4914Sraf  * calls are made while holding no other libc locks.  This covers almost
55*4914Sraf  * all of libc's malloc() and free() calls.  For those libc code paths,
56*4914Sraf  * such as the above-mentioned I18N calls, that require serialization and
57*4914Sraf  * that may call malloc() or free(), libc uses atfork_lock_enter() to perform
58*4914Sraf  * the serialization.  This works because atfork_lock is acquired by fork()
59*4914Sraf  * before any of the pthread_atfork() prefork functions are called.
600Sstevel@tonic-gate  */
61*4914Sraf 
624843Sraf void
634843Sraf fork_lock_enter(void)
640Sstevel@tonic-gate {
65*4914Sraf 	ASSERT(curthread->ul_critical == 0);
66*4914Sraf 	(void) _private_mutex_lock(&curthread->ul_uberdata->fork_lock);
670Sstevel@tonic-gate }
680Sstevel@tonic-gate 
690Sstevel@tonic-gate void
700Sstevel@tonic-gate fork_lock_exit(void)
710Sstevel@tonic-gate {
72*4914Sraf 	ASSERT(curthread->ul_critical == 0);
73*4914Sraf 	(void) _private_mutex_unlock(&curthread->ul_uberdata->fork_lock);
74*4914Sraf }
750Sstevel@tonic-gate 
76*4914Sraf void
77*4914Sraf atfork_lock_enter(void)
78*4914Sraf {
79*4914Sraf 	ASSERT(curthread->ul_critical == 0);
80*4914Sraf 	(void) _private_mutex_lock(&curthread->ul_uberdata->atfork_lock);
81*4914Sraf }
82*4914Sraf 
83*4914Sraf void
84*4914Sraf atfork_lock_exit(void)
85*4914Sraf {
86*4914Sraf 	ASSERT(curthread->ul_critical == 0);
87*4914Sraf 	(void) _private_mutex_unlock(&curthread->ul_uberdata->atfork_lock);
880Sstevel@tonic-gate }
890Sstevel@tonic-gate 
903235Sraf #pragma weak forkx = _private_forkx
913235Sraf #pragma weak _forkx = _private_forkx
924292Sab196087 pid_t
933235Sraf _private_forkx(int flags)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate 	ulwp_t *self = curthread;
960Sstevel@tonic-gate 	uberdata_t *udp = self->ul_uberdata;
970Sstevel@tonic-gate 	pid_t pid;
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	if (self->ul_vfork) {
1000Sstevel@tonic-gate 		/*
1010Sstevel@tonic-gate 		 * We are a child of vfork(); omit all of the fork
1020Sstevel@tonic-gate 		 * logic and go straight to the system call trap.
1030Sstevel@tonic-gate 		 * A vfork() child of a multithreaded parent
1040Sstevel@tonic-gate 		 * must never call fork().
1050Sstevel@tonic-gate 		 */
1060Sstevel@tonic-gate 		if (udp->uberflags.uf_mt) {
1070Sstevel@tonic-gate 			errno = ENOTSUP;
1080Sstevel@tonic-gate 			return (-1);
1090Sstevel@tonic-gate 		}
1103235Sraf 		pid = __forkx(flags);
1110Sstevel@tonic-gate 		if (pid == 0) {		/* child */
1120Sstevel@tonic-gate 			udp->pid = _private_getpid();
1130Sstevel@tonic-gate 			self->ul_vfork = 0;
1140Sstevel@tonic-gate 		}
1150Sstevel@tonic-gate 		return (pid);
1160Sstevel@tonic-gate 	}
1170Sstevel@tonic-gate 
1184843Sraf 	sigoff(self);
1194843Sraf 	if (self->ul_fork) {
1200Sstevel@tonic-gate 		/*
1210Sstevel@tonic-gate 		 * Cannot call fork() from a fork handler.
1220Sstevel@tonic-gate 		 */
1234843Sraf 		sigon(self);
1244843Sraf 		errno = EDEADLK;
1250Sstevel@tonic-gate 		return (-1);
1260Sstevel@tonic-gate 	}
1270Sstevel@tonic-gate 	self->ul_fork = 1;
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate 	/*
1300Sstevel@tonic-gate 	 * The functions registered by pthread_atfork() are defined by
1310Sstevel@tonic-gate 	 * the application and its libraries and we must not hold any
1324843Sraf 	 * internal lmutex_lock()-acquired locks while invoking them.
1334843Sraf 	 * We hold only udp->atfork_lock to protect the atfork linkages.
1344843Sraf 	 * If one of these pthread_atfork() functions attempts to fork
135*4914Sraf 	 * or to call pthread_atfork(), libc will detect the error and
136*4914Sraf 	 * fail the call with EDEADLK.  Otherwise, the pthread_atfork()
137*4914Sraf 	 * functions are free to do anything they please (except they
138*4914Sraf 	 * will not receive any signals).
1390Sstevel@tonic-gate 	 */
140*4914Sraf 	(void) _private_mutex_lock(&udp->atfork_lock);
1410Sstevel@tonic-gate 	_prefork_handler();
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate 	/*
1444843Sraf 	 * Block every other thread attempting thr_suspend() or thr_continue().
1454843Sraf 	 */
146*4914Sraf 	(void) _private_mutex_lock(&udp->fork_lock);
1474843Sraf 
1484843Sraf 	/*
1490Sstevel@tonic-gate 	 * Block all signals.
1504843Sraf 	 * Just deferring them via sigoff() is not enough.
1510Sstevel@tonic-gate 	 * We have to avoid taking a deferred signal in the child
1523235Sraf 	 * that was actually sent to the parent before __forkx().
1530Sstevel@tonic-gate 	 */
1540Sstevel@tonic-gate 	block_all_signals(self);
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate 	/*
1570Sstevel@tonic-gate 	 * This suspends all threads but this one, leaving them
1580Sstevel@tonic-gate 	 * suspended outside of any critical regions in the library.
159*4914Sraf 	 * Thus, we are assured that no lmutex_lock()-acquired library
160*4914Sraf 	 * locks are held while we invoke fork() from the current thread.
1610Sstevel@tonic-gate 	 */
1620Sstevel@tonic-gate 	suspend_fork();
1630Sstevel@tonic-gate 
1643235Sraf 	pid = __forkx(flags);
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 	if (pid == 0) {		/* child */
1670Sstevel@tonic-gate 		/*
1680Sstevel@tonic-gate 		 * Clear our schedctl pointer.
1690Sstevel@tonic-gate 		 * Discard any deferred signal that was sent to the parent.
1703235Sraf 		 * Because we blocked all signals before __forkx(), a
1710Sstevel@tonic-gate 		 * deferred signal cannot have been taken by the child.
1720Sstevel@tonic-gate 		 */
1730Sstevel@tonic-gate 		self->ul_schedctl_called = NULL;
1740Sstevel@tonic-gate 		self->ul_schedctl = NULL;
1750Sstevel@tonic-gate 		self->ul_cursig = 0;
1760Sstevel@tonic-gate 		self->ul_siginfo.si_signo = 0;
1770Sstevel@tonic-gate 		udp->pid = _private_getpid();
1780Sstevel@tonic-gate 		/* reset the library's data structures to reflect one thread */
1794574Sraf 		unregister_locks();
1802248Sraf 		postfork1_child();
1810Sstevel@tonic-gate 		restore_signals(self);
182*4914Sraf 		(void) _private_mutex_unlock(&udp->fork_lock);
1830Sstevel@tonic-gate 		_postfork_child_handler();
1840Sstevel@tonic-gate 	} else {
1853235Sraf 		/* restart all threads that were suspended for fork() */
1860Sstevel@tonic-gate 		continue_fork(0);
1870Sstevel@tonic-gate 		restore_signals(self);
188*4914Sraf 		(void) _private_mutex_unlock(&udp->fork_lock);
1890Sstevel@tonic-gate 		_postfork_parent_handler();
1900Sstevel@tonic-gate 	}
1910Sstevel@tonic-gate 
1924843Sraf 	(void) _private_mutex_unlock(&udp->atfork_lock);
1930Sstevel@tonic-gate 	self->ul_fork = 0;
1944843Sraf 	sigon(self);
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate 	return (pid);
1970Sstevel@tonic-gate }
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate /*
2003235Sraf  * fork() is fork1() for both Posix threads and Solaris threads.
2013235Sraf  * The forkall() interface exists for applications that require
2023235Sraf  * the semantics of replicating all threads.
2030Sstevel@tonic-gate  */
2043235Sraf #pragma weak fork1 = _fork
2053235Sraf #pragma weak _fork1 = _fork
2063235Sraf #pragma weak fork = _fork
2070Sstevel@tonic-gate pid_t
2083235Sraf _fork(void)
2093235Sraf {
2103235Sraf 	return (_private_forkx(0));
2113235Sraf }
2123235Sraf 
2133235Sraf /*
2143235Sraf  * Much of the logic here is the same as in forkx().
2153235Sraf  * See the comments in forkx(), above.
2163235Sraf  */
2173235Sraf #pragma weak forkallx = _private_forkallx
2183235Sraf #pragma weak _forkallx = _private_forkallx
2194292Sab196087 pid_t
2203235Sraf _private_forkallx(int flags)
2210Sstevel@tonic-gate {
2220Sstevel@tonic-gate 	ulwp_t *self = curthread;
2230Sstevel@tonic-gate 	uberdata_t *udp = self->ul_uberdata;
2240Sstevel@tonic-gate 	pid_t pid;
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate 	if (self->ul_vfork) {
2270Sstevel@tonic-gate 		if (udp->uberflags.uf_mt) {
2280Sstevel@tonic-gate 			errno = ENOTSUP;
2290Sstevel@tonic-gate 			return (-1);
2300Sstevel@tonic-gate 		}
2313235Sraf 		pid = __forkallx(flags);
2320Sstevel@tonic-gate 		if (pid == 0) {		/* child */
2330Sstevel@tonic-gate 			udp->pid = _private_getpid();
2340Sstevel@tonic-gate 			self->ul_vfork = 0;
2350Sstevel@tonic-gate 		}
2360Sstevel@tonic-gate 		return (pid);
2370Sstevel@tonic-gate 	}
2380Sstevel@tonic-gate 
2394843Sraf 	sigoff(self);
2404843Sraf 	if (self->ul_fork) {
2414843Sraf 		sigon(self);
2424843Sraf 		errno = EDEADLK;
2430Sstevel@tonic-gate 		return (-1);
2440Sstevel@tonic-gate 	}
2450Sstevel@tonic-gate 	self->ul_fork = 1;
246*4914Sraf 	(void) _private_mutex_lock(&udp->atfork_lock);
247*4914Sraf 	(void) _private_mutex_lock(&udp->fork_lock);
2480Sstevel@tonic-gate 	block_all_signals(self);
2490Sstevel@tonic-gate 	suspend_fork();
2500Sstevel@tonic-gate 
2513235Sraf 	pid = __forkallx(flags);
2520Sstevel@tonic-gate 
2530Sstevel@tonic-gate 	if (pid == 0) {
2540Sstevel@tonic-gate 		self->ul_schedctl_called = NULL;
2550Sstevel@tonic-gate 		self->ul_schedctl = NULL;
2560Sstevel@tonic-gate 		self->ul_cursig = 0;
2570Sstevel@tonic-gate 		self->ul_siginfo.si_signo = 0;
2580Sstevel@tonic-gate 		udp->pid = _private_getpid();
2594574Sraf 		unregister_locks();
2600Sstevel@tonic-gate 		continue_fork(1);
2610Sstevel@tonic-gate 	} else {
2620Sstevel@tonic-gate 		continue_fork(0);
2630Sstevel@tonic-gate 	}
2640Sstevel@tonic-gate 	restore_signals(self);
265*4914Sraf 	(void) _private_mutex_unlock(&udp->fork_lock);
266*4914Sraf 	(void) _private_mutex_unlock(&udp->atfork_lock);
2670Sstevel@tonic-gate 	self->ul_fork = 0;
2684843Sraf 	sigon(self);
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate 	return (pid);
2710Sstevel@tonic-gate }
2720Sstevel@tonic-gate 
2733235Sraf #pragma weak forkall = _forkall
2743235Sraf pid_t
2753235Sraf _forkall(void)
2763235Sraf {
2773235Sraf 	return (_private_forkallx(0));
2783235Sraf }
2793235Sraf 
2800Sstevel@tonic-gate /*
2810Sstevel@tonic-gate  * Hacks for system calls to provide cancellation
2820Sstevel@tonic-gate  * and improve java garbage collection.
2830Sstevel@tonic-gate  */
2840Sstevel@tonic-gate #define	PROLOGUE							\
2850Sstevel@tonic-gate {									\
2860Sstevel@tonic-gate 	ulwp_t *self = curthread;					\
2870Sstevel@tonic-gate 	int nocancel = (self->ul_vfork | self->ul_nocancel);		\
2880Sstevel@tonic-gate 	if (nocancel == 0) {						\
2890Sstevel@tonic-gate 		self->ul_save_async = self->ul_cancel_async;		\
2900Sstevel@tonic-gate 		if (!self->ul_cancel_disabled) {			\
2910Sstevel@tonic-gate 			self->ul_cancel_async = 1;			\
2920Sstevel@tonic-gate 			if (self->ul_cancel_pending)			\
2930Sstevel@tonic-gate 				_pthread_exit(PTHREAD_CANCELED);	\
2940Sstevel@tonic-gate 		}							\
2950Sstevel@tonic-gate 		self->ul_sp = stkptr();					\
2960Sstevel@tonic-gate 	}
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate #define	EPILOGUE							\
2990Sstevel@tonic-gate 	if (nocancel == 0) {						\
3000Sstevel@tonic-gate 		self->ul_sp = 0;					\
3010Sstevel@tonic-gate 		self->ul_cancel_async = self->ul_save_async;		\
3020Sstevel@tonic-gate 	}								\
3030Sstevel@tonic-gate }
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate /*
3060Sstevel@tonic-gate  * Perform the body of the action required by most of the cancelable
3070Sstevel@tonic-gate  * function calls.  The return(function_call) part is to allow the
3080Sstevel@tonic-gate  * compiler to make the call be executed with tail recursion, which
3090Sstevel@tonic-gate  * saves a register window on sparc and slightly (not much) improves
3100Sstevel@tonic-gate  * the code for x86/x64 compilations.
3110Sstevel@tonic-gate  */
3120Sstevel@tonic-gate #define	PERFORM(function_call)						\
3130Sstevel@tonic-gate 	PROLOGUE							\
3140Sstevel@tonic-gate 	if (nocancel)							\
3150Sstevel@tonic-gate 		return (function_call);					\
3160Sstevel@tonic-gate 	rv = function_call;						\
3170Sstevel@tonic-gate 	EPILOGUE							\
3180Sstevel@tonic-gate 	return (rv);
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate /*
3210Sstevel@tonic-gate  * Specialized prologue for sigsuspend() and pollsys().
3220Sstevel@tonic-gate  * These system calls pass a signal mask to the kernel.
3230Sstevel@tonic-gate  * The kernel replaces the thread's signal mask with the
3240Sstevel@tonic-gate  * temporary mask before the thread goes to sleep.  If
3250Sstevel@tonic-gate  * a signal is received, the signal handler will execute
3260Sstevel@tonic-gate  * with the temporary mask, as modified by the sigaction
3270Sstevel@tonic-gate  * for the particular signal.
3280Sstevel@tonic-gate  *
3290Sstevel@tonic-gate  * We block all signals until we reach the kernel with the
3300Sstevel@tonic-gate  * temporary mask.  This eliminates race conditions with
3310Sstevel@tonic-gate  * setting the signal mask while signals are being posted.
3320Sstevel@tonic-gate  */
3330Sstevel@tonic-gate #define	PROLOGUE_MASK(sigmask)						\
3340Sstevel@tonic-gate {									\
3350Sstevel@tonic-gate 	ulwp_t *self = curthread;					\
3360Sstevel@tonic-gate 	int nocancel = (self->ul_vfork | self->ul_nocancel);		\
3370Sstevel@tonic-gate 	if (!self->ul_vfork) {						\
3380Sstevel@tonic-gate 		if (sigmask) {						\
3390Sstevel@tonic-gate 			block_all_signals(self);			\
3401111Sraf 			self->ul_tmpmask.__sigbits[0] = sigmask->__sigbits[0]; \
3411111Sraf 			self->ul_tmpmask.__sigbits[1] = sigmask->__sigbits[1]; \
3420Sstevel@tonic-gate 			delete_reserved_signals(&self->ul_tmpmask);	\
3430Sstevel@tonic-gate 			self->ul_sigsuspend = 1;			\
3440Sstevel@tonic-gate 		}							\
3450Sstevel@tonic-gate 		if (nocancel == 0) {					\
3460Sstevel@tonic-gate 			self->ul_save_async = self->ul_cancel_async;	\
3470Sstevel@tonic-gate 			if (!self->ul_cancel_disabled) {		\
3480Sstevel@tonic-gate 				self->ul_cancel_async = 1;		\
3490Sstevel@tonic-gate 				if (self->ul_cancel_pending) {		\
3500Sstevel@tonic-gate 					if (self->ul_sigsuspend) {	\
3510Sstevel@tonic-gate 						self->ul_sigsuspend = 0;\
3520Sstevel@tonic-gate 						restore_signals(self);	\
3530Sstevel@tonic-gate 					}				\
3540Sstevel@tonic-gate 					_pthread_exit(PTHREAD_CANCELED);\
3550Sstevel@tonic-gate 				}					\
3560Sstevel@tonic-gate 			}						\
3570Sstevel@tonic-gate 			self->ul_sp = stkptr();				\
3580Sstevel@tonic-gate 		}							\
3590Sstevel@tonic-gate 	}
3600Sstevel@tonic-gate 
3610Sstevel@tonic-gate /*
3620Sstevel@tonic-gate  * If a signal is taken, we return from the system call wrapper with
3630Sstevel@tonic-gate  * our original signal mask restored (see code in call_user_handler()).
3640Sstevel@tonic-gate  * If not (self->ul_sigsuspend is still non-zero), we must restore our
3650Sstevel@tonic-gate  * original signal mask ourself.
3660Sstevel@tonic-gate  */
3670Sstevel@tonic-gate #define	EPILOGUE_MASK							\
3680Sstevel@tonic-gate 	if (nocancel == 0) {						\
3690Sstevel@tonic-gate 		self->ul_sp = 0;					\
3700Sstevel@tonic-gate 		self->ul_cancel_async = self->ul_save_async;		\
3710Sstevel@tonic-gate 	}								\
3720Sstevel@tonic-gate 	if (self->ul_sigsuspend) {					\
3730Sstevel@tonic-gate 		self->ul_sigsuspend = 0;				\
3740Sstevel@tonic-gate 		restore_signals(self);					\
3750Sstevel@tonic-gate 	}								\
3760Sstevel@tonic-gate }
3770Sstevel@tonic-gate 
3780Sstevel@tonic-gate /*
3792248Sraf  * Cancellation prologue and epilogue functions,
3802248Sraf  * for cancellation points too complex to include here.
3811885Sraf  */
3821885Sraf void
3831885Sraf _cancel_prologue(void)
3841885Sraf {
3851885Sraf 	ulwp_t *self = curthread;
3861885Sraf 
3871885Sraf 	self->ul_cancel_prologue = (self->ul_vfork | self->ul_nocancel);
3881885Sraf 	if (self->ul_cancel_prologue == 0) {
3891885Sraf 		self->ul_save_async = self->ul_cancel_async;
3901885Sraf 		if (!self->ul_cancel_disabled) {
3911885Sraf 			self->ul_cancel_async = 1;
3921885Sraf 			if (self->ul_cancel_pending)
3931885Sraf 				_pthread_exit(PTHREAD_CANCELED);
3941885Sraf 		}
3951885Sraf 		self->ul_sp = stkptr();
3961885Sraf 	}
3971885Sraf }
3981885Sraf 
3991885Sraf void
4001885Sraf _cancel_epilogue(void)
4011885Sraf {
4021885Sraf 	ulwp_t *self = curthread;
4031885Sraf 
4041885Sraf 	if (self->ul_cancel_prologue == 0) {
4051885Sraf 		self->ul_sp = 0;
4061885Sraf 		self->ul_cancel_async = self->ul_save_async;
4071885Sraf 	}
4081885Sraf }
4091885Sraf 
4101885Sraf /*
4110Sstevel@tonic-gate  * Called from _thrp_join() (thr_join() is a cancellation point)
4120Sstevel@tonic-gate  */
4130Sstevel@tonic-gate int
4140Sstevel@tonic-gate lwp_wait(thread_t tid, thread_t *found)
4150Sstevel@tonic-gate {
4160Sstevel@tonic-gate 	int error;
4170Sstevel@tonic-gate 
4180Sstevel@tonic-gate 	PROLOGUE
4190Sstevel@tonic-gate 	while ((error = __lwp_wait(tid, found)) == EINTR)
4200Sstevel@tonic-gate 		;
4210Sstevel@tonic-gate 	EPILOGUE
4220Sstevel@tonic-gate 	return (error);
4230Sstevel@tonic-gate }
4240Sstevel@tonic-gate 
4250Sstevel@tonic-gate ssize_t
4260Sstevel@tonic-gate read(int fd, void *buf, size_t size)
4270Sstevel@tonic-gate {
4280Sstevel@tonic-gate 	extern ssize_t _read(int, void *, size_t);
4290Sstevel@tonic-gate 	ssize_t rv;
4300Sstevel@tonic-gate 
4310Sstevel@tonic-gate 	PERFORM(_read(fd, buf, size))
4320Sstevel@tonic-gate }
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate ssize_t
4350Sstevel@tonic-gate write(int fd, const void *buf, size_t size)
4360Sstevel@tonic-gate {
4370Sstevel@tonic-gate 	extern ssize_t _write(int, const void *, size_t);
4380Sstevel@tonic-gate 	ssize_t rv;
4390Sstevel@tonic-gate 
4400Sstevel@tonic-gate 	PERFORM(_write(fd, buf, size))
4410Sstevel@tonic-gate }
4420Sstevel@tonic-gate 
4430Sstevel@tonic-gate int
4440Sstevel@tonic-gate getmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr,
4450Sstevel@tonic-gate 	int *flagsp)
4460Sstevel@tonic-gate {
4470Sstevel@tonic-gate 	extern int _getmsg(int, struct strbuf *, struct strbuf *, int *);
4480Sstevel@tonic-gate 	int rv;
4490Sstevel@tonic-gate 
4500Sstevel@tonic-gate 	PERFORM(_getmsg(fd, ctlptr, dataptr, flagsp))
4510Sstevel@tonic-gate }
4520Sstevel@tonic-gate 
4530Sstevel@tonic-gate int
4540Sstevel@tonic-gate getpmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr,
4550Sstevel@tonic-gate 	int *bandp, int *flagsp)
4560Sstevel@tonic-gate {
4570Sstevel@tonic-gate 	extern int _getpmsg(int, struct strbuf *, struct strbuf *,
4584843Sraf 	    int *, int *);
4590Sstevel@tonic-gate 	int rv;
4600Sstevel@tonic-gate 
4610Sstevel@tonic-gate 	PERFORM(_getpmsg(fd, ctlptr, dataptr, bandp, flagsp))
4620Sstevel@tonic-gate }
4630Sstevel@tonic-gate 
4640Sstevel@tonic-gate int
4650Sstevel@tonic-gate putmsg(int fd, const struct strbuf *ctlptr,
4660Sstevel@tonic-gate 	const struct strbuf *dataptr, int flags)
4670Sstevel@tonic-gate {
4680Sstevel@tonic-gate 	extern int _putmsg(int, const struct strbuf *,
4694843Sraf 	    const struct strbuf *, int);
4700Sstevel@tonic-gate 	int rv;
4710Sstevel@tonic-gate 
4720Sstevel@tonic-gate 	PERFORM(_putmsg(fd, ctlptr, dataptr, flags))
4730Sstevel@tonic-gate }
4740Sstevel@tonic-gate 
4750Sstevel@tonic-gate int
4760Sstevel@tonic-gate __xpg4_putmsg(int fd, const struct strbuf *ctlptr,
4770Sstevel@tonic-gate 	const struct strbuf *dataptr, int flags)
4780Sstevel@tonic-gate {
4790Sstevel@tonic-gate 	extern int _putmsg(int, const struct strbuf *,
4804843Sraf 	    const struct strbuf *, int);
4810Sstevel@tonic-gate 	int rv;
4820Sstevel@tonic-gate 
4830Sstevel@tonic-gate 	PERFORM(_putmsg(fd, ctlptr, dataptr, flags|MSG_XPG4))
4840Sstevel@tonic-gate }
4850Sstevel@tonic-gate 
4860Sstevel@tonic-gate int
4870Sstevel@tonic-gate putpmsg(int fd, const struct strbuf *ctlptr,
4880Sstevel@tonic-gate 	const struct strbuf *dataptr, int band, int flags)
4890Sstevel@tonic-gate {
4900Sstevel@tonic-gate 	extern int _putpmsg(int, const struct strbuf *,
4914843Sraf 	    const struct strbuf *, int, int);
4920Sstevel@tonic-gate 	int rv;
4930Sstevel@tonic-gate 
4940Sstevel@tonic-gate 	PERFORM(_putpmsg(fd, ctlptr, dataptr, band, flags))
4950Sstevel@tonic-gate }
4960Sstevel@tonic-gate 
4970Sstevel@tonic-gate int
4980Sstevel@tonic-gate __xpg4_putpmsg(int fd, const struct strbuf *ctlptr,
4990Sstevel@tonic-gate 	const struct strbuf *dataptr, int band, int flags)
5000Sstevel@tonic-gate {
5010Sstevel@tonic-gate 	extern int _putpmsg(int, const struct strbuf *,
5024843Sraf 	    const struct strbuf *, int, int);
5030Sstevel@tonic-gate 	int rv;
5040Sstevel@tonic-gate 
5050Sstevel@tonic-gate 	PERFORM(_putpmsg(fd, ctlptr, dataptr, band, flags|MSG_XPG4))
5060Sstevel@tonic-gate }
5070Sstevel@tonic-gate 
5082248Sraf #pragma weak nanosleep = _nanosleep
5090Sstevel@tonic-gate int
5102248Sraf _nanosleep(const timespec_t *rqtp, timespec_t *rmtp)
5110Sstevel@tonic-gate {
5120Sstevel@tonic-gate 	int error;
5130Sstevel@tonic-gate 
5140Sstevel@tonic-gate 	PROLOGUE
5152248Sraf 	error = __nanosleep(rqtp, rmtp);
5160Sstevel@tonic-gate 	EPILOGUE
5170Sstevel@tonic-gate 	if (error) {
5180Sstevel@tonic-gate 		errno = error;
5190Sstevel@tonic-gate 		return (-1);
5200Sstevel@tonic-gate 	}
5210Sstevel@tonic-gate 	return (0);
5220Sstevel@tonic-gate }
5230Sstevel@tonic-gate 
5242248Sraf #pragma weak clock_nanosleep = _clock_nanosleep
5250Sstevel@tonic-gate int
5262248Sraf _clock_nanosleep(clockid_t clock_id, int flags,
5270Sstevel@tonic-gate 	const timespec_t *rqtp, timespec_t *rmtp)
5280Sstevel@tonic-gate {
5290Sstevel@tonic-gate 	timespec_t reltime;
5300Sstevel@tonic-gate 	hrtime_t start;
5310Sstevel@tonic-gate 	hrtime_t rqlapse;
5320Sstevel@tonic-gate 	hrtime_t lapse;
5330Sstevel@tonic-gate 	int error;
5340Sstevel@tonic-gate 
5350Sstevel@tonic-gate 	switch (clock_id) {
5360Sstevel@tonic-gate 	case CLOCK_VIRTUAL:
5370Sstevel@tonic-gate 	case CLOCK_PROCESS_CPUTIME_ID:
5380Sstevel@tonic-gate 	case CLOCK_THREAD_CPUTIME_ID:
5390Sstevel@tonic-gate 		return (ENOTSUP);
5400Sstevel@tonic-gate 	case CLOCK_REALTIME:
5410Sstevel@tonic-gate 	case CLOCK_HIGHRES:
5420Sstevel@tonic-gate 		break;
5430Sstevel@tonic-gate 	default:
5440Sstevel@tonic-gate 		return (EINVAL);
5450Sstevel@tonic-gate 	}
5460Sstevel@tonic-gate 	if (flags & TIMER_ABSTIME) {
5470Sstevel@tonic-gate 		abstime_to_reltime(clock_id, rqtp, &reltime);
5480Sstevel@tonic-gate 		rmtp = NULL;
5490Sstevel@tonic-gate 	} else {
5500Sstevel@tonic-gate 		reltime = *rqtp;
5510Sstevel@tonic-gate 		if (clock_id == CLOCK_HIGHRES)
5520Sstevel@tonic-gate 			start = gethrtime();
5530Sstevel@tonic-gate 	}
5540Sstevel@tonic-gate restart:
5550Sstevel@tonic-gate 	PROLOGUE
5562248Sraf 	error = __nanosleep(&reltime, rmtp);
5570Sstevel@tonic-gate 	EPILOGUE
5580Sstevel@tonic-gate 	if (error == 0 && clock_id == CLOCK_HIGHRES) {
5590Sstevel@tonic-gate 		/*
5600Sstevel@tonic-gate 		 * Don't return yet if we didn't really get a timeout.
5610Sstevel@tonic-gate 		 * This can happen if we return because someone resets
5620Sstevel@tonic-gate 		 * the system clock.
5630Sstevel@tonic-gate 		 */
5640Sstevel@tonic-gate 		if (flags & TIMER_ABSTIME) {
5650Sstevel@tonic-gate 			if ((hrtime_t)(uint32_t)rqtp->tv_sec * NANOSEC +
5660Sstevel@tonic-gate 			    rqtp->tv_nsec > gethrtime()) {
5670Sstevel@tonic-gate 				abstime_to_reltime(clock_id, rqtp, &reltime);
5680Sstevel@tonic-gate 				goto restart;
5690Sstevel@tonic-gate 			}
5700Sstevel@tonic-gate 		} else {
5710Sstevel@tonic-gate 			rqlapse = (hrtime_t)(uint32_t)rqtp->tv_sec * NANOSEC +
5724843Sraf 			    rqtp->tv_nsec;
5730Sstevel@tonic-gate 			lapse = gethrtime() - start;
5740Sstevel@tonic-gate 			if (rqlapse > lapse) {
5750Sstevel@tonic-gate 				hrt2ts(rqlapse - lapse, &reltime);
5760Sstevel@tonic-gate 				goto restart;
5770Sstevel@tonic-gate 			}
5780Sstevel@tonic-gate 		}
5790Sstevel@tonic-gate 	}
5800Sstevel@tonic-gate 	if (error == 0 && clock_id == CLOCK_REALTIME &&
5810Sstevel@tonic-gate 	    (flags & TIMER_ABSTIME)) {
5820Sstevel@tonic-gate 		/*
5830Sstevel@tonic-gate 		 * Don't return yet just because someone reset the
5840Sstevel@tonic-gate 		 * system clock.  Recompute the new relative time
5850Sstevel@tonic-gate 		 * and reissue the nanosleep() call if necessary.
5860Sstevel@tonic-gate 		 *
5870Sstevel@tonic-gate 		 * Resetting the system clock causes all sorts of
5880Sstevel@tonic-gate 		 * problems and the SUSV3 standards body should
5890Sstevel@tonic-gate 		 * have made the behavior of clock_nanosleep() be
5900Sstevel@tonic-gate 		 * implementation-defined in such a case rather than
5910Sstevel@tonic-gate 		 * being specific about honoring the new system time.
5920Sstevel@tonic-gate 		 * Standards bodies are filled with fools and idiots.
5930Sstevel@tonic-gate 		 */
5940Sstevel@tonic-gate 		abstime_to_reltime(clock_id, rqtp, &reltime);
5950Sstevel@tonic-gate 		if (reltime.tv_sec != 0 || reltime.tv_nsec != 0)
5960Sstevel@tonic-gate 			goto restart;
5970Sstevel@tonic-gate 	}
5980Sstevel@tonic-gate 	return (error);
5990Sstevel@tonic-gate }
6000Sstevel@tonic-gate 
6010Sstevel@tonic-gate #pragma weak sleep = _sleep
6020Sstevel@tonic-gate unsigned int
6030Sstevel@tonic-gate _sleep(unsigned int sec)
6040Sstevel@tonic-gate {
6050Sstevel@tonic-gate 	unsigned int rem = 0;
6060Sstevel@tonic-gate 	int error;
6070Sstevel@tonic-gate 	timespec_t ts;
6080Sstevel@tonic-gate 	timespec_t tsr;
6090Sstevel@tonic-gate 
6100Sstevel@tonic-gate 	ts.tv_sec = (time_t)sec;
6110Sstevel@tonic-gate 	ts.tv_nsec = 0;
6120Sstevel@tonic-gate 	PROLOGUE
6132248Sraf 	error = __nanosleep(&ts, &tsr);
6140Sstevel@tonic-gate 	EPILOGUE
6150Sstevel@tonic-gate 	if (error == EINTR) {
6160Sstevel@tonic-gate 		rem = (unsigned int)tsr.tv_sec;
6170Sstevel@tonic-gate 		if (tsr.tv_nsec >= NANOSEC / 2)
6180Sstevel@tonic-gate 			rem++;
6190Sstevel@tonic-gate 	}
6200Sstevel@tonic-gate 	return (rem);
6210Sstevel@tonic-gate }
6220Sstevel@tonic-gate 
6230Sstevel@tonic-gate #pragma weak usleep = _usleep
6240Sstevel@tonic-gate int
6250Sstevel@tonic-gate _usleep(useconds_t usec)
6260Sstevel@tonic-gate {
6270Sstevel@tonic-gate 	timespec_t ts;
6280Sstevel@tonic-gate 
6290Sstevel@tonic-gate 	ts.tv_sec = usec / MICROSEC;
6300Sstevel@tonic-gate 	ts.tv_nsec = (long)(usec % MICROSEC) * 1000;
6310Sstevel@tonic-gate 	PROLOGUE
6322248Sraf 	(void) __nanosleep(&ts, NULL);
6330Sstevel@tonic-gate 	EPILOGUE
6340Sstevel@tonic-gate 	return (0);
6350Sstevel@tonic-gate }
6360Sstevel@tonic-gate 
6370Sstevel@tonic-gate int
6380Sstevel@tonic-gate close(int fildes)
6390Sstevel@tonic-gate {
6402248Sraf 	extern void _aio_close(int);
6410Sstevel@tonic-gate 	extern int _close(int);
6420Sstevel@tonic-gate 	int rv;
6430Sstevel@tonic-gate 
6442248Sraf 	_aio_close(fildes);
6450Sstevel@tonic-gate 	PERFORM(_close(fildes))
6460Sstevel@tonic-gate }
6470Sstevel@tonic-gate 
6480Sstevel@tonic-gate int
6490Sstevel@tonic-gate creat(const char *path, mode_t mode)
6500Sstevel@tonic-gate {
6510Sstevel@tonic-gate 	extern int _creat(const char *, mode_t);
6520Sstevel@tonic-gate 	int rv;
6530Sstevel@tonic-gate 
6540Sstevel@tonic-gate 	PERFORM(_creat(path, mode))
6550Sstevel@tonic-gate }
6560Sstevel@tonic-gate 
6570Sstevel@tonic-gate #if !defined(_LP64)
6580Sstevel@tonic-gate int
6590Sstevel@tonic-gate creat64(const char *path, mode_t mode)
6600Sstevel@tonic-gate {
6610Sstevel@tonic-gate 	extern int _creat64(const char *, mode_t);
6620Sstevel@tonic-gate 	int rv;
6630Sstevel@tonic-gate 
6640Sstevel@tonic-gate 	PERFORM(_creat64(path, mode))
6650Sstevel@tonic-gate }
6660Sstevel@tonic-gate #endif	/* !_LP64 */
6670Sstevel@tonic-gate 
6680Sstevel@tonic-gate int
6690Sstevel@tonic-gate fcntl(int fildes, int cmd, ...)
6700Sstevel@tonic-gate {
6710Sstevel@tonic-gate 	extern int _fcntl(int, int, ...);
6720Sstevel@tonic-gate 	intptr_t arg;
6730Sstevel@tonic-gate 	int rv;
6740Sstevel@tonic-gate 	va_list ap;
6750Sstevel@tonic-gate 
6760Sstevel@tonic-gate 	va_start(ap, cmd);
6770Sstevel@tonic-gate 	arg = va_arg(ap, intptr_t);
6780Sstevel@tonic-gate 	va_end(ap);
6790Sstevel@tonic-gate 	if (cmd != F_SETLKW)
6800Sstevel@tonic-gate 		return (_fcntl(fildes, cmd, arg));
6810Sstevel@tonic-gate 	PERFORM(_fcntl(fildes, cmd, arg))
6820Sstevel@tonic-gate }
6830Sstevel@tonic-gate 
6840Sstevel@tonic-gate int
6854722Sraf fdatasync(int fildes)
6864722Sraf {
6874722Sraf 	extern int _fdatasync(int);
6884722Sraf 	int rv;
6894722Sraf 
6904722Sraf 	PERFORM(_fdatasync(fildes))
6914722Sraf }
6924722Sraf 
6934722Sraf int
6940Sstevel@tonic-gate fsync(int fildes)
6950Sstevel@tonic-gate {
6960Sstevel@tonic-gate 	extern int _fsync(int);
6970Sstevel@tonic-gate 	int rv;
6980Sstevel@tonic-gate 
6990Sstevel@tonic-gate 	PERFORM(_fsync(fildes))
7000Sstevel@tonic-gate }
7010Sstevel@tonic-gate 
7020Sstevel@tonic-gate int
7030Sstevel@tonic-gate lockf(int fildes, int function, off_t size)
7040Sstevel@tonic-gate {
7050Sstevel@tonic-gate 	extern int _lockf(int, int, off_t);
7060Sstevel@tonic-gate 	int rv;
7070Sstevel@tonic-gate 
7080Sstevel@tonic-gate 	PERFORM(_lockf(fildes, function, size))
7090Sstevel@tonic-gate }
7100Sstevel@tonic-gate 
7110Sstevel@tonic-gate #if !defined(_LP64)
7120Sstevel@tonic-gate int
7130Sstevel@tonic-gate lockf64(int fildes, int function, off64_t size)
7140Sstevel@tonic-gate {
7150Sstevel@tonic-gate 	extern int _lockf64(int, int, off64_t);
7160Sstevel@tonic-gate 	int rv;
7170Sstevel@tonic-gate 
7180Sstevel@tonic-gate 	PERFORM(_lockf64(fildes, function, size))
7190Sstevel@tonic-gate }
7200Sstevel@tonic-gate #endif	/* !_LP64 */
7210Sstevel@tonic-gate 
7220Sstevel@tonic-gate ssize_t
7230Sstevel@tonic-gate msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
7240Sstevel@tonic-gate {
7250Sstevel@tonic-gate 	extern ssize_t _msgrcv(int, void *, size_t, long, int);
7260Sstevel@tonic-gate 	ssize_t rv;
7270Sstevel@tonic-gate 
7280Sstevel@tonic-gate 	PERFORM(_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg))
7290Sstevel@tonic-gate }
7300Sstevel@tonic-gate 
7310Sstevel@tonic-gate int
7320Sstevel@tonic-gate msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg)
7330Sstevel@tonic-gate {
7340Sstevel@tonic-gate 	extern int _msgsnd(int, const void *, size_t, int);
7350Sstevel@tonic-gate 	int rv;
7360Sstevel@tonic-gate 
7370Sstevel@tonic-gate 	PERFORM(_msgsnd(msqid, msgp, msgsz, msgflg))
7380Sstevel@tonic-gate }
7390Sstevel@tonic-gate 
7400Sstevel@tonic-gate int
7410Sstevel@tonic-gate msync(caddr_t addr, size_t len, int flags)
7420Sstevel@tonic-gate {
7430Sstevel@tonic-gate 	extern int _msync(caddr_t, size_t, int);
7440Sstevel@tonic-gate 	int rv;
7450Sstevel@tonic-gate 
7460Sstevel@tonic-gate 	PERFORM(_msync(addr, len, flags))
7470Sstevel@tonic-gate }
7480Sstevel@tonic-gate 
7490Sstevel@tonic-gate int
7500Sstevel@tonic-gate open(const char *path, int oflag, ...)
7510Sstevel@tonic-gate {
7520Sstevel@tonic-gate 	extern int _open(const char *, int, ...);
7530Sstevel@tonic-gate 	mode_t mode;
7540Sstevel@tonic-gate 	int rv;
7550Sstevel@tonic-gate 	va_list ap;
7560Sstevel@tonic-gate 
7570Sstevel@tonic-gate 	va_start(ap, oflag);
7580Sstevel@tonic-gate 	mode = va_arg(ap, mode_t);
7590Sstevel@tonic-gate 	va_end(ap);
7600Sstevel@tonic-gate 	PERFORM(_open(path, oflag, mode))
7610Sstevel@tonic-gate }
7620Sstevel@tonic-gate 
7630Sstevel@tonic-gate #if !defined(_LP64)
7640Sstevel@tonic-gate int
7650Sstevel@tonic-gate open64(const char *path, int oflag, ...)
7660Sstevel@tonic-gate {
7670Sstevel@tonic-gate 	extern int _open64(const char *, int, ...);
7680Sstevel@tonic-gate 	mode_t mode;
7690Sstevel@tonic-gate 	int rv;
7700Sstevel@tonic-gate 	va_list ap;
7710Sstevel@tonic-gate 
7720Sstevel@tonic-gate 	va_start(ap, oflag);
7730Sstevel@tonic-gate 	mode = va_arg(ap, mode_t);
7740Sstevel@tonic-gate 	va_end(ap);
7750Sstevel@tonic-gate 	PERFORM(_open64(path, oflag, mode))
7760Sstevel@tonic-gate }
7770Sstevel@tonic-gate #endif	/* !_LP64 */
7780Sstevel@tonic-gate 
7790Sstevel@tonic-gate int
7800Sstevel@tonic-gate pause(void)
7810Sstevel@tonic-gate {
7820Sstevel@tonic-gate 	extern int _pause(void);
7830Sstevel@tonic-gate 	int rv;
7840Sstevel@tonic-gate 
7850Sstevel@tonic-gate 	PERFORM(_pause())
7860Sstevel@tonic-gate }
7870Sstevel@tonic-gate 
7880Sstevel@tonic-gate ssize_t
7890Sstevel@tonic-gate pread(int fildes, void *buf, size_t nbyte, off_t offset)
7900Sstevel@tonic-gate {
7910Sstevel@tonic-gate 	extern ssize_t _pread(int, void *, size_t, off_t);
7920Sstevel@tonic-gate 	ssize_t rv;
7930Sstevel@tonic-gate 
7940Sstevel@tonic-gate 	PERFORM(_pread(fildes, buf, nbyte, offset))
7950Sstevel@tonic-gate }
7960Sstevel@tonic-gate 
7970Sstevel@tonic-gate #if !defined(_LP64)
7980Sstevel@tonic-gate ssize_t
7990Sstevel@tonic-gate pread64(int fildes, void *buf, size_t nbyte, off64_t offset)
8000Sstevel@tonic-gate {
8010Sstevel@tonic-gate 	extern ssize_t _pread64(int, void *, size_t, off64_t);
8020Sstevel@tonic-gate 	ssize_t rv;
8030Sstevel@tonic-gate 
8040Sstevel@tonic-gate 	PERFORM(_pread64(fildes, buf, nbyte, offset))
8050Sstevel@tonic-gate }
8060Sstevel@tonic-gate #endif	/* !_LP64 */
8070Sstevel@tonic-gate 
8080Sstevel@tonic-gate ssize_t
8090Sstevel@tonic-gate pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
8100Sstevel@tonic-gate {
8110Sstevel@tonic-gate 	extern ssize_t _pwrite(int, const void *, size_t, off_t);
8120Sstevel@tonic-gate 	ssize_t rv;
8130Sstevel@tonic-gate 
8140Sstevel@tonic-gate 	PERFORM(_pwrite(fildes, buf, nbyte, offset))
8150Sstevel@tonic-gate }
8160Sstevel@tonic-gate 
8170Sstevel@tonic-gate #if !defined(_LP64)
8180Sstevel@tonic-gate ssize_t
8190Sstevel@tonic-gate pwrite64(int fildes, const void *buf, size_t nbyte, off64_t offset)
8200Sstevel@tonic-gate {
8210Sstevel@tonic-gate 	extern ssize_t _pwrite64(int, const void *, size_t, off64_t);
8220Sstevel@tonic-gate 	ssize_t rv;
8230Sstevel@tonic-gate 
8240Sstevel@tonic-gate 	PERFORM(_pwrite64(fildes, buf, nbyte, offset))
8250Sstevel@tonic-gate }
8260Sstevel@tonic-gate #endif	/* !_LP64 */
8270Sstevel@tonic-gate 
8280Sstevel@tonic-gate ssize_t
8290Sstevel@tonic-gate readv(int fildes, const struct iovec *iov, int iovcnt)
8300Sstevel@tonic-gate {
8310Sstevel@tonic-gate 	extern ssize_t _readv(int, const struct iovec *, int);
8320Sstevel@tonic-gate 	ssize_t rv;
8330Sstevel@tonic-gate 
8340Sstevel@tonic-gate 	PERFORM(_readv(fildes, iov, iovcnt))
8350Sstevel@tonic-gate }
8360Sstevel@tonic-gate 
8370Sstevel@tonic-gate int
8380Sstevel@tonic-gate sigpause(int sig)
8390Sstevel@tonic-gate {
8400Sstevel@tonic-gate 	extern int _sigpause(int);
8410Sstevel@tonic-gate 	int rv;
8420Sstevel@tonic-gate 
8430Sstevel@tonic-gate 	PERFORM(_sigpause(sig))
8440Sstevel@tonic-gate }
8450Sstevel@tonic-gate 
8460Sstevel@tonic-gate #pragma weak sigsuspend = _sigsuspend
8470Sstevel@tonic-gate int
8480Sstevel@tonic-gate _sigsuspend(const sigset_t *set)
8490Sstevel@tonic-gate {
8500Sstevel@tonic-gate 	extern int __sigsuspend(const sigset_t *);
8510Sstevel@tonic-gate 	int rv;
8520Sstevel@tonic-gate 
8530Sstevel@tonic-gate 	PROLOGUE_MASK(set)
8540Sstevel@tonic-gate 	rv = __sigsuspend(set);
8550Sstevel@tonic-gate 	EPILOGUE_MASK
8560Sstevel@tonic-gate 	return (rv);
8570Sstevel@tonic-gate }
8580Sstevel@tonic-gate 
8590Sstevel@tonic-gate int
8600Sstevel@tonic-gate _pollsys(struct pollfd *fds, nfds_t nfd, const timespec_t *timeout,
8610Sstevel@tonic-gate 	const sigset_t *sigmask)
8620Sstevel@tonic-gate {
8630Sstevel@tonic-gate 	extern int __pollsys(struct pollfd *, nfds_t, const timespec_t *,
8644843Sraf 	    const sigset_t *);
8650Sstevel@tonic-gate 	int rv;
8660Sstevel@tonic-gate 
8670Sstevel@tonic-gate 	PROLOGUE_MASK(sigmask)
8680Sstevel@tonic-gate 	rv = __pollsys(fds, nfd, timeout, sigmask);
8690Sstevel@tonic-gate 	EPILOGUE_MASK
8700Sstevel@tonic-gate 	return (rv);
8710Sstevel@tonic-gate }
8720Sstevel@tonic-gate 
8732248Sraf #pragma weak sigtimedwait = _sigtimedwait
8740Sstevel@tonic-gate int
8752248Sraf _sigtimedwait(const sigset_t *set, siginfo_t *infop, const timespec_t *timeout)
8760Sstevel@tonic-gate {
8772248Sraf 	extern int __sigtimedwait(const sigset_t *, siginfo_t *,
8784843Sraf 	    const timespec_t *);
8790Sstevel@tonic-gate 	siginfo_t info;
8800Sstevel@tonic-gate 	int sig;
8810Sstevel@tonic-gate 
8820Sstevel@tonic-gate 	PROLOGUE
8832248Sraf 	sig = __sigtimedwait(set, &info, timeout);
8840Sstevel@tonic-gate 	if (sig == SIGCANCEL &&
8850Sstevel@tonic-gate 	    (SI_FROMKERNEL(&info) || info.si_code == SI_LWP)) {
8860Sstevel@tonic-gate 		do_sigcancel();
8870Sstevel@tonic-gate 		errno = EINTR;
8880Sstevel@tonic-gate 		sig = -1;
8890Sstevel@tonic-gate 	}
8900Sstevel@tonic-gate 	EPILOGUE
8910Sstevel@tonic-gate 	if (sig != -1 && infop)
8921111Sraf 		(void) _private_memcpy(infop, &info, sizeof (*infop));
8930Sstevel@tonic-gate 	return (sig);
8940Sstevel@tonic-gate }
8950Sstevel@tonic-gate 
8960Sstevel@tonic-gate #pragma weak sigwait = _sigwait
8970Sstevel@tonic-gate int
8980Sstevel@tonic-gate _sigwait(sigset_t *set)
8990Sstevel@tonic-gate {
9002248Sraf 	return (_sigtimedwait(set, NULL, NULL));
9012248Sraf }
9022248Sraf 
9032248Sraf #pragma weak sigwaitinfo = _sigwaitinfo
9042248Sraf int
9052248Sraf _sigwaitinfo(const sigset_t *set, siginfo_t *info)
9062248Sraf {
9072248Sraf 	return (_sigtimedwait(set, info, NULL));
9082248Sraf }
9092248Sraf 
9102248Sraf #pragma weak sigqueue = _sigqueue
9112248Sraf int
9122248Sraf _sigqueue(pid_t pid, int signo, const union sigval value)
9132248Sraf {
9142248Sraf 	extern int __sigqueue(pid_t pid, int signo,
9154843Sraf 	    /* const union sigval */ void *value, int si_code, int block);
9162248Sraf 	return (__sigqueue(pid, signo, value.sival_ptr, SI_QUEUE, 0));
9170Sstevel@tonic-gate }
9180Sstevel@tonic-gate 
9190Sstevel@tonic-gate int
9200Sstevel@tonic-gate tcdrain(int fildes)
9210Sstevel@tonic-gate {
9220Sstevel@tonic-gate 	extern int _tcdrain(int);
9230Sstevel@tonic-gate 	int rv;
9240Sstevel@tonic-gate 
9250Sstevel@tonic-gate 	PERFORM(_tcdrain(fildes))
9260Sstevel@tonic-gate }
9270Sstevel@tonic-gate 
9280Sstevel@tonic-gate pid_t
9290Sstevel@tonic-gate wait(int *stat_loc)
9300Sstevel@tonic-gate {
9310Sstevel@tonic-gate 	extern pid_t _wait(int *);
9320Sstevel@tonic-gate 	pid_t rv;
9330Sstevel@tonic-gate 
9340Sstevel@tonic-gate 	PERFORM(_wait(stat_loc))
9350Sstevel@tonic-gate }
9360Sstevel@tonic-gate 
9370Sstevel@tonic-gate pid_t
9380Sstevel@tonic-gate wait3(int *statusp, int options, struct rusage *rusage)
9390Sstevel@tonic-gate {
9400Sstevel@tonic-gate 	extern pid_t _wait3(int *, int, struct rusage *);
9410Sstevel@tonic-gate 	pid_t rv;
9420Sstevel@tonic-gate 
9430Sstevel@tonic-gate 	PERFORM(_wait3(statusp, options, rusage))
9440Sstevel@tonic-gate }
9450Sstevel@tonic-gate 
9460Sstevel@tonic-gate int
9470Sstevel@tonic-gate waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options)
9480Sstevel@tonic-gate {
9490Sstevel@tonic-gate 	extern int _waitid(idtype_t, id_t, siginfo_t *, int);
9500Sstevel@tonic-gate 	int rv;
9510Sstevel@tonic-gate 
9520Sstevel@tonic-gate 	PERFORM(_waitid(idtype, id, infop, options))
9530Sstevel@tonic-gate }
9540Sstevel@tonic-gate 
9551219Sraf /*
9561219Sraf  * waitpid_cancel() is a libc-private symbol for internal use
9571219Sraf  * where cancellation semantics is desired (see system()).
9581219Sraf  */
9591219Sraf #pragma weak waitpid_cancel = waitpid
9600Sstevel@tonic-gate pid_t
9610Sstevel@tonic-gate waitpid(pid_t pid, int *stat_loc, int options)
9620Sstevel@tonic-gate {
9630Sstevel@tonic-gate 	extern pid_t _waitpid(pid_t, int *, int);
9640Sstevel@tonic-gate 	pid_t rv;
9650Sstevel@tonic-gate 
9660Sstevel@tonic-gate 	PERFORM(_waitpid(pid, stat_loc, options))
9670Sstevel@tonic-gate }
9680Sstevel@tonic-gate 
9690Sstevel@tonic-gate ssize_t
9700Sstevel@tonic-gate writev(int fildes, const struct iovec *iov, int iovcnt)
9710Sstevel@tonic-gate {
9720Sstevel@tonic-gate 	extern ssize_t _writev(int, const struct iovec *, int);
9730Sstevel@tonic-gate 	ssize_t rv;
9740Sstevel@tonic-gate 
9750Sstevel@tonic-gate 	PERFORM(_writev(fildes, iov, iovcnt))
9760Sstevel@tonic-gate }
977