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 /*
2311798SRoger.Faulkner@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #include "lint.h"
280Sstevel@tonic-gate #include "thr_uberdata.h"
290Sstevel@tonic-gate #include <stdarg.h>
300Sstevel@tonic-gate #include <poll.h>
310Sstevel@tonic-gate #include <stropts.h>
320Sstevel@tonic-gate #include <dlfcn.h>
335891Sraf #include <wait.h>
345891Sraf #include <sys/socket.h>
350Sstevel@tonic-gate #include <sys/uio.h>
365891Sraf #include <sys/file.h>
375891Sraf #include <sys/door.h>
380Sstevel@tonic-gate
390Sstevel@tonic-gate /*
406812Sraf * These leading-underbar symbols exist because mistakes were made
416812Sraf * in the past that put them into non-SUNWprivate versions of
426812Sraf * the libc mapfiles. They should be eliminated, but oh well...
436812Sraf */
446812Sraf #pragma weak _fork = fork
456812Sraf #pragma weak _read = read
466812Sraf #pragma weak _write = write
476812Sraf #pragma weak _getmsg = getmsg
486812Sraf #pragma weak _getpmsg = getpmsg
496812Sraf #pragma weak _putmsg = putmsg
506812Sraf #pragma weak _putpmsg = putpmsg
516812Sraf #pragma weak _sleep = sleep
526812Sraf #pragma weak _close = close
536812Sraf #pragma weak _creat = creat
546812Sraf #pragma weak _fcntl = fcntl
556812Sraf #pragma weak _fsync = fsync
566812Sraf #pragma weak _lockf = lockf
576812Sraf #pragma weak _msgrcv = msgrcv
586812Sraf #pragma weak _msgsnd = msgsnd
596812Sraf #pragma weak _msync = msync
606812Sraf #pragma weak _open = open
616812Sraf #pragma weak _openat = openat
626812Sraf #pragma weak _pause = pause
636812Sraf #pragma weak _readv = readv
646812Sraf #pragma weak _sigpause = sigpause
656812Sraf #pragma weak _sigsuspend = sigsuspend
666812Sraf #pragma weak _tcdrain = tcdrain
676812Sraf #pragma weak _waitid = waitid
686812Sraf #pragma weak _writev = writev
696812Sraf
706812Sraf #if !defined(_LP64)
716812Sraf #pragma weak _creat64 = creat64
726812Sraf #pragma weak _lockf64 = lockf64
736812Sraf #pragma weak _open64 = open64
746812Sraf #pragma weak _openat64 = openat64
756812Sraf #pragma weak _pread64 = pread64
766812Sraf #pragma weak _pwrite64 = pwrite64
776812Sraf #endif
786812Sraf
796812Sraf /*
806933Sraf * These are SUNWprivate, but they are being used by Sun Studio libcollector.
816933Sraf */
826933Sraf #pragma weak _fork1 = fork1
836933Sraf #pragma weak _forkall = forkall
846933Sraf
856933Sraf /*
865002Sraf * atfork_lock protects the pthread_atfork() data structures.
875002Sraf *
884914Sraf * fork_lock does double-duty. Not only does it (and atfork_lock)
894914Sraf * serialize calls to fork() and forkall(), but it also serializes calls
904914Sraf * to thr_suspend() and thr_continue() (because fork() and forkall() also
914914Sraf * suspend and continue other threads and they want no competition).
924914Sraf *
935002Sraf * Functions called in dlopen()ed L10N objects can do anything, including
945002Sraf * call malloc() and free(). Such calls are not fork-safe when protected
955002Sraf * by an ordinary mutex that is acquired in libc's prefork processing
965002Sraf * because, with an interposed malloc library present, there would be a
975002Sraf * lock ordering violation due to the pthread_atfork() prefork function
985002Sraf * in the interposition library acquiring its malloc lock(s) before the
994914Sraf * ordinary mutex in libc being acquired by libc's prefork functions.
1004914Sraf *
1015002Sraf * Within libc, calls to malloc() and free() are fork-safe if the calls
1025002Sraf * are made while holding no other libc locks. This covers almost all
1035002Sraf * of libc's malloc() and free() calls. For those libc code paths, such
1045002Sraf * as the above-mentioned L10N calls, that require serialization and that
1055002Sraf * may call malloc() or free(), libc uses callout_lock_enter() to perform
1065002Sraf * the serialization. This works because callout_lock is not acquired as
1075002Sraf * part of running the pthread_atfork() prefork handlers (to avoid the
1085002Sraf * lock ordering violation described above). Rather, it is simply
1095002Sraf * reinitialized in postfork1_child() to cover the case that some
1105002Sraf * now-defunct thread might have been suspended while holding it.
1110Sstevel@tonic-gate */
1124914Sraf
1134843Sraf void
fork_lock_enter(void)1144843Sraf fork_lock_enter(void)
1150Sstevel@tonic-gate {
1164914Sraf ASSERT(curthread->ul_critical == 0);
1176515Sraf (void) mutex_lock(&curthread->ul_uberdata->fork_lock);
1180Sstevel@tonic-gate }
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate void
fork_lock_exit(void)1210Sstevel@tonic-gate fork_lock_exit(void)
1220Sstevel@tonic-gate {
1234914Sraf ASSERT(curthread->ul_critical == 0);
1246515Sraf (void) mutex_unlock(&curthread->ul_uberdata->fork_lock);
1254914Sraf }
1260Sstevel@tonic-gate
1275891Sraf /*
1285891Sraf * Use cancel_safe_mutex_lock() to protect against being cancelled while
1295891Sraf * holding callout_lock and calling outside of libc (via L10N plugins).
1305891Sraf * We will honor a pending cancellation request when callout_lock_exit()
1315891Sraf * is called, by calling cancel_safe_mutex_unlock().
1325891Sraf */
1334914Sraf void
callout_lock_enter(void)1345002Sraf callout_lock_enter(void)
1354914Sraf {
1364914Sraf ASSERT(curthread->ul_critical == 0);
1375891Sraf cancel_safe_mutex_lock(&curthread->ul_uberdata->callout_lock);
1384914Sraf }
1394914Sraf
1404914Sraf void
callout_lock_exit(void)1415002Sraf callout_lock_exit(void)
1424914Sraf {
1434914Sraf ASSERT(curthread->ul_critical == 0);
1445891Sraf cancel_safe_mutex_unlock(&curthread->ul_uberdata->callout_lock);
1450Sstevel@tonic-gate }
1460Sstevel@tonic-gate
1474292Sab196087 pid_t
forkx(int flags)1486812Sraf forkx(int flags)
1490Sstevel@tonic-gate {
1500Sstevel@tonic-gate ulwp_t *self = curthread;
1510Sstevel@tonic-gate uberdata_t *udp = self->ul_uberdata;
1520Sstevel@tonic-gate pid_t pid;
1530Sstevel@tonic-gate
1540Sstevel@tonic-gate if (self->ul_vfork) {
1550Sstevel@tonic-gate /*
1560Sstevel@tonic-gate * We are a child of vfork(); omit all of the fork
1570Sstevel@tonic-gate * logic and go straight to the system call trap.
1580Sstevel@tonic-gate * A vfork() child of a multithreaded parent
1590Sstevel@tonic-gate * must never call fork().
1600Sstevel@tonic-gate */
1610Sstevel@tonic-gate if (udp->uberflags.uf_mt) {
1620Sstevel@tonic-gate errno = ENOTSUP;
1630Sstevel@tonic-gate return (-1);
1640Sstevel@tonic-gate }
1653235Sraf pid = __forkx(flags);
1660Sstevel@tonic-gate if (pid == 0) { /* child */
1676515Sraf udp->pid = getpid();
1680Sstevel@tonic-gate self->ul_vfork = 0;
1690Sstevel@tonic-gate }
1700Sstevel@tonic-gate return (pid);
1710Sstevel@tonic-gate }
1720Sstevel@tonic-gate
1734843Sraf sigoff(self);
1744843Sraf if (self->ul_fork) {
1750Sstevel@tonic-gate /*
1760Sstevel@tonic-gate * Cannot call fork() from a fork handler.
1770Sstevel@tonic-gate */
1784843Sraf sigon(self);
1794843Sraf errno = EDEADLK;
1800Sstevel@tonic-gate return (-1);
1810Sstevel@tonic-gate }
1820Sstevel@tonic-gate self->ul_fork = 1;
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate /*
1850Sstevel@tonic-gate * The functions registered by pthread_atfork() are defined by
1860Sstevel@tonic-gate * the application and its libraries and we must not hold any
1874843Sraf * internal lmutex_lock()-acquired locks while invoking them.
1884843Sraf * We hold only udp->atfork_lock to protect the atfork linkages.
1894843Sraf * If one of these pthread_atfork() functions attempts to fork
1904914Sraf * or to call pthread_atfork(), libc will detect the error and
1914914Sraf * fail the call with EDEADLK. Otherwise, the pthread_atfork()
1924914Sraf * functions are free to do anything they please (except they
1934914Sraf * will not receive any signals).
1940Sstevel@tonic-gate */
1956515Sraf (void) mutex_lock(&udp->atfork_lock);
1967901SRoger.Faulkner@Sun.COM
1977901SRoger.Faulkner@Sun.COM /*
1987901SRoger.Faulkner@Sun.COM * Posix (SUSv3) requires fork() to be async-signal-safe.
1997901SRoger.Faulkner@Sun.COM * This cannot be made to happen with fork handlers in place
2007901SRoger.Faulkner@Sun.COM * (they grab locks). To be in nominal compliance, don't run
2017901SRoger.Faulkner@Sun.COM * any fork handlers if we are called within a signal context.
2027901SRoger.Faulkner@Sun.COM * This leaves the child process in a questionable state with
2037901SRoger.Faulkner@Sun.COM * respect to its locks, but at least the parent process does
2047901SRoger.Faulkner@Sun.COM * not become deadlocked due to the calling thread attempting
2057901SRoger.Faulkner@Sun.COM * to acquire a lock that it already owns.
2067901SRoger.Faulkner@Sun.COM */
2077901SRoger.Faulkner@Sun.COM if (self->ul_siglink == NULL)
2087901SRoger.Faulkner@Sun.COM _prefork_handler();
2090Sstevel@tonic-gate
2100Sstevel@tonic-gate /*
2114843Sraf * Block every other thread attempting thr_suspend() or thr_continue().
2124843Sraf */
2136515Sraf (void) mutex_lock(&udp->fork_lock);
2144843Sraf
2154843Sraf /*
2160Sstevel@tonic-gate * Block all signals.
2174843Sraf * Just deferring them via sigoff() is not enough.
2180Sstevel@tonic-gate * We have to avoid taking a deferred signal in the child
2193235Sraf * that was actually sent to the parent before __forkx().
2200Sstevel@tonic-gate */
2210Sstevel@tonic-gate block_all_signals(self);
2220Sstevel@tonic-gate
2230Sstevel@tonic-gate /*
2240Sstevel@tonic-gate * This suspends all threads but this one, leaving them
2250Sstevel@tonic-gate * suspended outside of any critical regions in the library.
2264914Sraf * Thus, we are assured that no lmutex_lock()-acquired library
2274914Sraf * locks are held while we invoke fork() from the current thread.
2280Sstevel@tonic-gate */
2290Sstevel@tonic-gate suspend_fork();
2300Sstevel@tonic-gate
2313235Sraf pid = __forkx(flags);
2320Sstevel@tonic-gate
2330Sstevel@tonic-gate if (pid == 0) { /* child */
2340Sstevel@tonic-gate /*
2350Sstevel@tonic-gate * Clear our schedctl pointer.
2360Sstevel@tonic-gate * Discard any deferred signal that was sent to the parent.
2373235Sraf * Because we blocked all signals before __forkx(), a
2380Sstevel@tonic-gate * deferred signal cannot have been taken by the child.
2390Sstevel@tonic-gate */
2400Sstevel@tonic-gate self->ul_schedctl_called = NULL;
2410Sstevel@tonic-gate self->ul_schedctl = NULL;
2420Sstevel@tonic-gate self->ul_cursig = 0;
2430Sstevel@tonic-gate self->ul_siginfo.si_signo = 0;
2446515Sraf udp->pid = getpid();
2450Sstevel@tonic-gate /* reset the library's data structures to reflect one thread */
2469264SRoger.Faulkner@Sun.COM unregister_locks();
2472248Sraf postfork1_child();
2480Sstevel@tonic-gate restore_signals(self);
2496515Sraf (void) mutex_unlock(&udp->fork_lock);
2507901SRoger.Faulkner@Sun.COM if (self->ul_siglink == NULL)
2517901SRoger.Faulkner@Sun.COM _postfork_child_handler();
2520Sstevel@tonic-gate } else {
2533235Sraf /* restart all threads that were suspended for fork() */
2540Sstevel@tonic-gate continue_fork(0);
2550Sstevel@tonic-gate restore_signals(self);
2566515Sraf (void) mutex_unlock(&udp->fork_lock);
2577901SRoger.Faulkner@Sun.COM if (self->ul_siglink == NULL)
2587901SRoger.Faulkner@Sun.COM _postfork_parent_handler();
2590Sstevel@tonic-gate }
2600Sstevel@tonic-gate
2616515Sraf (void) mutex_unlock(&udp->atfork_lock);
2620Sstevel@tonic-gate self->ul_fork = 0;
2634843Sraf sigon(self);
2640Sstevel@tonic-gate
2650Sstevel@tonic-gate return (pid);
2660Sstevel@tonic-gate }
2670Sstevel@tonic-gate
2680Sstevel@tonic-gate /*
2693235Sraf * fork() is fork1() for both Posix threads and Solaris threads.
2703235Sraf * The forkall() interface exists for applications that require
2713235Sraf * the semantics of replicating all threads.
2720Sstevel@tonic-gate */
2736812Sraf #pragma weak fork1 = fork
2740Sstevel@tonic-gate pid_t
fork(void)2756812Sraf fork(void)
2763235Sraf {
2776812Sraf return (forkx(0));
2783235Sraf }
2793235Sraf
2803235Sraf /*
2813235Sraf * Much of the logic here is the same as in forkx().
2823235Sraf * See the comments in forkx(), above.
2833235Sraf */
2844292Sab196087 pid_t
forkallx(int flags)2856812Sraf forkallx(int flags)
2860Sstevel@tonic-gate {
2870Sstevel@tonic-gate ulwp_t *self = curthread;
2880Sstevel@tonic-gate uberdata_t *udp = self->ul_uberdata;
2890Sstevel@tonic-gate pid_t pid;
2900Sstevel@tonic-gate
2910Sstevel@tonic-gate if (self->ul_vfork) {
2920Sstevel@tonic-gate if (udp->uberflags.uf_mt) {
2930Sstevel@tonic-gate errno = ENOTSUP;
2940Sstevel@tonic-gate return (-1);
2950Sstevel@tonic-gate }
2963235Sraf pid = __forkallx(flags);
2970Sstevel@tonic-gate if (pid == 0) { /* child */
2986515Sraf udp->pid = getpid();
2990Sstevel@tonic-gate self->ul_vfork = 0;
3000Sstevel@tonic-gate }
3010Sstevel@tonic-gate return (pid);
3020Sstevel@tonic-gate }
3030Sstevel@tonic-gate
3044843Sraf sigoff(self);
3054843Sraf if (self->ul_fork) {
3064843Sraf sigon(self);
3074843Sraf errno = EDEADLK;
3080Sstevel@tonic-gate return (-1);
3090Sstevel@tonic-gate }
3100Sstevel@tonic-gate self->ul_fork = 1;
3116515Sraf (void) mutex_lock(&udp->atfork_lock);
3126515Sraf (void) mutex_lock(&udp->fork_lock);
3130Sstevel@tonic-gate block_all_signals(self);
3140Sstevel@tonic-gate suspend_fork();
3150Sstevel@tonic-gate
3163235Sraf pid = __forkallx(flags);
3170Sstevel@tonic-gate
3180Sstevel@tonic-gate if (pid == 0) {
3190Sstevel@tonic-gate self->ul_schedctl_called = NULL;
3200Sstevel@tonic-gate self->ul_schedctl = NULL;
3210Sstevel@tonic-gate self->ul_cursig = 0;
3220Sstevel@tonic-gate self->ul_siginfo.si_signo = 0;
3236515Sraf udp->pid = getpid();
3249264SRoger.Faulkner@Sun.COM unregister_locks();
3250Sstevel@tonic-gate continue_fork(1);
3260Sstevel@tonic-gate } else {
3270Sstevel@tonic-gate continue_fork(0);
3280Sstevel@tonic-gate }
3290Sstevel@tonic-gate restore_signals(self);
3306515Sraf (void) mutex_unlock(&udp->fork_lock);
3316515Sraf (void) mutex_unlock(&udp->atfork_lock);
3320Sstevel@tonic-gate self->ul_fork = 0;
3334843Sraf sigon(self);
3340Sstevel@tonic-gate
3350Sstevel@tonic-gate return (pid);
3360Sstevel@tonic-gate }
3370Sstevel@tonic-gate
3383235Sraf pid_t
forkall(void)3396812Sraf forkall(void)
3403235Sraf {
3416812Sraf return (forkallx(0));
3423235Sraf }
3433235Sraf
3440Sstevel@tonic-gate /*
3455891Sraf * For the implementation of cancellation at cancellation points.
3460Sstevel@tonic-gate */
3470Sstevel@tonic-gate #define PROLOGUE \
3480Sstevel@tonic-gate { \
3490Sstevel@tonic-gate ulwp_t *self = curthread; \
3505891Sraf int nocancel = \
3515891Sraf (self->ul_vfork | self->ul_nocancel | self->ul_libc_locks | \
3525891Sraf self->ul_critical | self->ul_sigdefer); \
3535891Sraf int abort = 0; \
3540Sstevel@tonic-gate if (nocancel == 0) { \
3550Sstevel@tonic-gate self->ul_save_async = self->ul_cancel_async; \
3560Sstevel@tonic-gate if (!self->ul_cancel_disabled) { \
3570Sstevel@tonic-gate self->ul_cancel_async = 1; \
3580Sstevel@tonic-gate if (self->ul_cancel_pending) \
3596812Sraf pthread_exit(PTHREAD_CANCELED); \
3600Sstevel@tonic-gate } \
3610Sstevel@tonic-gate self->ul_sp = stkptr(); \
3625891Sraf } else if (self->ul_cancel_pending && \
3635891Sraf !self->ul_cancel_disabled) { \
3645891Sraf set_cancel_eintr_flag(self); \
3655891Sraf abort = 1; \
3660Sstevel@tonic-gate }
3670Sstevel@tonic-gate
3680Sstevel@tonic-gate #define EPILOGUE \
3690Sstevel@tonic-gate if (nocancel == 0) { \
3700Sstevel@tonic-gate self->ul_sp = 0; \
3710Sstevel@tonic-gate self->ul_cancel_async = self->ul_save_async; \
3720Sstevel@tonic-gate } \
3730Sstevel@tonic-gate }
3740Sstevel@tonic-gate
3750Sstevel@tonic-gate /*
3760Sstevel@tonic-gate * Perform the body of the action required by most of the cancelable
3770Sstevel@tonic-gate * function calls. The return(function_call) part is to allow the
3780Sstevel@tonic-gate * compiler to make the call be executed with tail recursion, which
3790Sstevel@tonic-gate * saves a register window on sparc and slightly (not much) improves
3800Sstevel@tonic-gate * the code for x86/x64 compilations.
3810Sstevel@tonic-gate */
3820Sstevel@tonic-gate #define PERFORM(function_call) \
3830Sstevel@tonic-gate PROLOGUE \
3845891Sraf if (abort) { \
3855891Sraf *self->ul_errnop = EINTR; \
3865891Sraf return (-1); \
3875891Sraf } \
3880Sstevel@tonic-gate if (nocancel) \
3890Sstevel@tonic-gate return (function_call); \
3900Sstevel@tonic-gate rv = function_call; \
3910Sstevel@tonic-gate EPILOGUE \
3920Sstevel@tonic-gate return (rv);
3930Sstevel@tonic-gate
3940Sstevel@tonic-gate /*
3950Sstevel@tonic-gate * Specialized prologue for sigsuspend() and pollsys().
3960Sstevel@tonic-gate * These system calls pass a signal mask to the kernel.
3970Sstevel@tonic-gate * The kernel replaces the thread's signal mask with the
3980Sstevel@tonic-gate * temporary mask before the thread goes to sleep. If
3990Sstevel@tonic-gate * a signal is received, the signal handler will execute
4000Sstevel@tonic-gate * with the temporary mask, as modified by the sigaction
4010Sstevel@tonic-gate * for the particular signal.
4020Sstevel@tonic-gate *
4030Sstevel@tonic-gate * We block all signals until we reach the kernel with the
4040Sstevel@tonic-gate * temporary mask. This eliminates race conditions with
4050Sstevel@tonic-gate * setting the signal mask while signals are being posted.
4060Sstevel@tonic-gate */
4070Sstevel@tonic-gate #define PROLOGUE_MASK(sigmask) \
4080Sstevel@tonic-gate { \
4090Sstevel@tonic-gate ulwp_t *self = curthread; \
4105891Sraf int nocancel = \
4115891Sraf (self->ul_vfork | self->ul_nocancel | self->ul_libc_locks | \
4125891Sraf self->ul_critical | self->ul_sigdefer); \
4130Sstevel@tonic-gate if (!self->ul_vfork) { \
4140Sstevel@tonic-gate if (sigmask) { \
4150Sstevel@tonic-gate block_all_signals(self); \
416*11913SRoger.Faulkner@Sun.COM self->ul_tmpmask = *sigmask; \
4170Sstevel@tonic-gate delete_reserved_signals(&self->ul_tmpmask); \
4180Sstevel@tonic-gate self->ul_sigsuspend = 1; \
4190Sstevel@tonic-gate } \
4200Sstevel@tonic-gate if (nocancel == 0) { \
4210Sstevel@tonic-gate self->ul_save_async = self->ul_cancel_async; \
4220Sstevel@tonic-gate if (!self->ul_cancel_disabled) { \
4230Sstevel@tonic-gate self->ul_cancel_async = 1; \
4240Sstevel@tonic-gate if (self->ul_cancel_pending) { \
4250Sstevel@tonic-gate if (self->ul_sigsuspend) { \
4260Sstevel@tonic-gate self->ul_sigsuspend = 0;\
4270Sstevel@tonic-gate restore_signals(self); \
4280Sstevel@tonic-gate } \
4296812Sraf pthread_exit(PTHREAD_CANCELED); \
4300Sstevel@tonic-gate } \
4310Sstevel@tonic-gate } \
4320Sstevel@tonic-gate self->ul_sp = stkptr(); \
4330Sstevel@tonic-gate } \
4340Sstevel@tonic-gate }
4350Sstevel@tonic-gate
4360Sstevel@tonic-gate /*
4370Sstevel@tonic-gate * If a signal is taken, we return from the system call wrapper with
4380Sstevel@tonic-gate * our original signal mask restored (see code in call_user_handler()).
4390Sstevel@tonic-gate * If not (self->ul_sigsuspend is still non-zero), we must restore our
4400Sstevel@tonic-gate * original signal mask ourself.
4410Sstevel@tonic-gate */
4420Sstevel@tonic-gate #define EPILOGUE_MASK \
4430Sstevel@tonic-gate if (nocancel == 0) { \
4440Sstevel@tonic-gate self->ul_sp = 0; \
4450Sstevel@tonic-gate self->ul_cancel_async = self->ul_save_async; \
4460Sstevel@tonic-gate } \
4470Sstevel@tonic-gate if (self->ul_sigsuspend) { \
4480Sstevel@tonic-gate self->ul_sigsuspend = 0; \
4490Sstevel@tonic-gate restore_signals(self); \
4500Sstevel@tonic-gate } \
4510Sstevel@tonic-gate }
4520Sstevel@tonic-gate
4530Sstevel@tonic-gate /*
4542248Sraf * Cancellation prologue and epilogue functions,
4552248Sraf * for cancellation points too complex to include here.
4561885Sraf */
4571885Sraf void
_cancel_prologue(void)4581885Sraf _cancel_prologue(void)
4591885Sraf {
4601885Sraf ulwp_t *self = curthread;
4611885Sraf
4625891Sraf self->ul_cancel_prologue =
4635891Sraf (self->ul_vfork | self->ul_nocancel | self->ul_libc_locks |
4645891Sraf self->ul_critical | self->ul_sigdefer) != 0;
4651885Sraf if (self->ul_cancel_prologue == 0) {
4661885Sraf self->ul_save_async = self->ul_cancel_async;
4671885Sraf if (!self->ul_cancel_disabled) {
4681885Sraf self->ul_cancel_async = 1;
4691885Sraf if (self->ul_cancel_pending)
4706812Sraf pthread_exit(PTHREAD_CANCELED);
4711885Sraf }
4721885Sraf self->ul_sp = stkptr();
4735891Sraf } else if (self->ul_cancel_pending &&
4745891Sraf !self->ul_cancel_disabled) {
4755891Sraf set_cancel_eintr_flag(self);
4761885Sraf }
4771885Sraf }
4781885Sraf
4791885Sraf void
_cancel_epilogue(void)4801885Sraf _cancel_epilogue(void)
4811885Sraf {
4821885Sraf ulwp_t *self = curthread;
4831885Sraf
4841885Sraf if (self->ul_cancel_prologue == 0) {
4851885Sraf self->ul_sp = 0;
4861885Sraf self->ul_cancel_async = self->ul_save_async;
4871885Sraf }
4881885Sraf }
4891885Sraf
4901885Sraf /*
4910Sstevel@tonic-gate * Called from _thrp_join() (thr_join() is a cancellation point)
4920Sstevel@tonic-gate */
4930Sstevel@tonic-gate int
lwp_wait(thread_t tid,thread_t * found)4940Sstevel@tonic-gate lwp_wait(thread_t tid, thread_t *found)
4950Sstevel@tonic-gate {
4960Sstevel@tonic-gate int error;
4970Sstevel@tonic-gate
4980Sstevel@tonic-gate PROLOGUE
4995891Sraf if (abort)
5005891Sraf return (EINTR);
5015891Sraf while ((error = __lwp_wait(tid, found)) == EINTR && !cancel_active())
5025891Sraf continue;
5030Sstevel@tonic-gate EPILOGUE
5040Sstevel@tonic-gate return (error);
5050Sstevel@tonic-gate }
5060Sstevel@tonic-gate
5070Sstevel@tonic-gate ssize_t
read(int fd,void * buf,size_t size)5086812Sraf read(int fd, void *buf, size_t size)
5090Sstevel@tonic-gate {
5105891Sraf extern ssize_t __read(int, void *, size_t);
5110Sstevel@tonic-gate ssize_t rv;
5120Sstevel@tonic-gate
5135891Sraf PERFORM(__read(fd, buf, size))
5140Sstevel@tonic-gate }
5150Sstevel@tonic-gate
5160Sstevel@tonic-gate ssize_t
write(int fd,const void * buf,size_t size)5176812Sraf write(int fd, const void *buf, size_t size)
5180Sstevel@tonic-gate {
5195891Sraf extern ssize_t __write(int, const void *, size_t);
5200Sstevel@tonic-gate ssize_t rv;
5210Sstevel@tonic-gate
5225891Sraf PERFORM(__write(fd, buf, size))
5230Sstevel@tonic-gate }
5240Sstevel@tonic-gate
5250Sstevel@tonic-gate int
getmsg(int fd,struct strbuf * ctlptr,struct strbuf * dataptr,int * flagsp)5266812Sraf getmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr,
5270Sstevel@tonic-gate int *flagsp)
5280Sstevel@tonic-gate {
5295891Sraf extern int __getmsg(int, struct strbuf *, struct strbuf *, int *);
5300Sstevel@tonic-gate int rv;
5310Sstevel@tonic-gate
5325891Sraf PERFORM(__getmsg(fd, ctlptr, dataptr, flagsp))
5330Sstevel@tonic-gate }
5340Sstevel@tonic-gate
5350Sstevel@tonic-gate int
getpmsg(int fd,struct strbuf * ctlptr,struct strbuf * dataptr,int * bandp,int * flagsp)5366812Sraf getpmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr,
5370Sstevel@tonic-gate int *bandp, int *flagsp)
5380Sstevel@tonic-gate {
5395891Sraf extern int __getpmsg(int, struct strbuf *, struct strbuf *,
5404843Sraf int *, int *);
5410Sstevel@tonic-gate int rv;
5420Sstevel@tonic-gate
5435891Sraf PERFORM(__getpmsg(fd, ctlptr, dataptr, bandp, flagsp))
5440Sstevel@tonic-gate }
5450Sstevel@tonic-gate
5460Sstevel@tonic-gate int
putmsg(int fd,const struct strbuf * ctlptr,const struct strbuf * dataptr,int flags)5476812Sraf putmsg(int fd, const struct strbuf *ctlptr,
5480Sstevel@tonic-gate const struct strbuf *dataptr, int flags)
5490Sstevel@tonic-gate {
5505891Sraf extern int __putmsg(int, const struct strbuf *,
5514843Sraf const struct strbuf *, int);
5520Sstevel@tonic-gate int rv;
5530Sstevel@tonic-gate
5545891Sraf PERFORM(__putmsg(fd, ctlptr, dataptr, flags))
5550Sstevel@tonic-gate }
5560Sstevel@tonic-gate
5570Sstevel@tonic-gate int
__xpg4_putmsg(int fd,const struct strbuf * ctlptr,const struct strbuf * dataptr,int flags)5580Sstevel@tonic-gate __xpg4_putmsg(int fd, const struct strbuf *ctlptr,
5590Sstevel@tonic-gate const struct strbuf *dataptr, int flags)
5600Sstevel@tonic-gate {
5615891Sraf extern int __putmsg(int, const struct strbuf *,
5624843Sraf const struct strbuf *, int);
5630Sstevel@tonic-gate int rv;
5640Sstevel@tonic-gate
5655891Sraf PERFORM(__putmsg(fd, ctlptr, dataptr, flags|MSG_XPG4))
5660Sstevel@tonic-gate }
5670Sstevel@tonic-gate
5680Sstevel@tonic-gate int
putpmsg(int fd,const struct strbuf * ctlptr,const struct strbuf * dataptr,int band,int flags)5696812Sraf putpmsg(int fd, const struct strbuf *ctlptr,
5700Sstevel@tonic-gate const struct strbuf *dataptr, int band, int flags)
5710Sstevel@tonic-gate {
5725891Sraf extern int __putpmsg(int, const struct strbuf *,
5734843Sraf const struct strbuf *, int, int);
5740Sstevel@tonic-gate int rv;
5750Sstevel@tonic-gate
5765891Sraf PERFORM(__putpmsg(fd, ctlptr, dataptr, band, flags))
5770Sstevel@tonic-gate }
5780Sstevel@tonic-gate
5790Sstevel@tonic-gate int
__xpg4_putpmsg(int fd,const struct strbuf * ctlptr,const struct strbuf * dataptr,int band,int flags)5800Sstevel@tonic-gate __xpg4_putpmsg(int fd, const struct strbuf *ctlptr,
5810Sstevel@tonic-gate const struct strbuf *dataptr, int band, int flags)
5820Sstevel@tonic-gate {
5835891Sraf extern int __putpmsg(int, const struct strbuf *,
5844843Sraf const struct strbuf *, int, int);
5850Sstevel@tonic-gate int rv;
5860Sstevel@tonic-gate
5875891Sraf PERFORM(__putpmsg(fd, ctlptr, dataptr, band, flags|MSG_XPG4))
5880Sstevel@tonic-gate }
5890Sstevel@tonic-gate
5900Sstevel@tonic-gate int
nanosleep(const timespec_t * rqtp,timespec_t * rmtp)5916812Sraf nanosleep(const timespec_t *rqtp, timespec_t *rmtp)
5920Sstevel@tonic-gate {
5930Sstevel@tonic-gate int error;
5940Sstevel@tonic-gate
5950Sstevel@tonic-gate PROLOGUE
5965891Sraf error = abort? EINTR : __nanosleep(rqtp, rmtp);
5970Sstevel@tonic-gate EPILOGUE
5980Sstevel@tonic-gate if (error) {
5990Sstevel@tonic-gate errno = error;
6000Sstevel@tonic-gate return (-1);
6010Sstevel@tonic-gate }
6020Sstevel@tonic-gate return (0);
6030Sstevel@tonic-gate }
6040Sstevel@tonic-gate
6050Sstevel@tonic-gate int
clock_nanosleep(clockid_t clock_id,int flags,const timespec_t * rqtp,timespec_t * rmtp)6066812Sraf clock_nanosleep(clockid_t clock_id, int flags,
6070Sstevel@tonic-gate const timespec_t *rqtp, timespec_t *rmtp)
6080Sstevel@tonic-gate {
6090Sstevel@tonic-gate timespec_t reltime;
6100Sstevel@tonic-gate hrtime_t start;
6110Sstevel@tonic-gate hrtime_t rqlapse;
6120Sstevel@tonic-gate hrtime_t lapse;
6130Sstevel@tonic-gate int error;
6140Sstevel@tonic-gate
6150Sstevel@tonic-gate switch (clock_id) {
6160Sstevel@tonic-gate case CLOCK_VIRTUAL:
6170Sstevel@tonic-gate case CLOCK_PROCESS_CPUTIME_ID:
6180Sstevel@tonic-gate case CLOCK_THREAD_CPUTIME_ID:
6190Sstevel@tonic-gate return (ENOTSUP);
6200Sstevel@tonic-gate case CLOCK_REALTIME:
6210Sstevel@tonic-gate case CLOCK_HIGHRES:
6220Sstevel@tonic-gate break;
6230Sstevel@tonic-gate default:
6240Sstevel@tonic-gate return (EINVAL);
6250Sstevel@tonic-gate }
6260Sstevel@tonic-gate if (flags & TIMER_ABSTIME) {
6270Sstevel@tonic-gate abstime_to_reltime(clock_id, rqtp, &reltime);
6280Sstevel@tonic-gate rmtp = NULL;
6290Sstevel@tonic-gate } else {
6300Sstevel@tonic-gate reltime = *rqtp;
6310Sstevel@tonic-gate if (clock_id == CLOCK_HIGHRES)
6320Sstevel@tonic-gate start = gethrtime();
6330Sstevel@tonic-gate }
6340Sstevel@tonic-gate restart:
6350Sstevel@tonic-gate PROLOGUE
6365891Sraf error = abort? EINTR : __nanosleep(&reltime, rmtp);
6370Sstevel@tonic-gate EPILOGUE
6380Sstevel@tonic-gate if (error == 0 && clock_id == CLOCK_HIGHRES) {
6390Sstevel@tonic-gate /*
6400Sstevel@tonic-gate * Don't return yet if we didn't really get a timeout.
6410Sstevel@tonic-gate * This can happen if we return because someone resets
6420Sstevel@tonic-gate * the system clock.
6430Sstevel@tonic-gate */
6440Sstevel@tonic-gate if (flags & TIMER_ABSTIME) {
6450Sstevel@tonic-gate if ((hrtime_t)(uint32_t)rqtp->tv_sec * NANOSEC +
6460Sstevel@tonic-gate rqtp->tv_nsec > gethrtime()) {
6470Sstevel@tonic-gate abstime_to_reltime(clock_id, rqtp, &reltime);
6480Sstevel@tonic-gate goto restart;
6490Sstevel@tonic-gate }
6500Sstevel@tonic-gate } else {
6510Sstevel@tonic-gate rqlapse = (hrtime_t)(uint32_t)rqtp->tv_sec * NANOSEC +
6524843Sraf rqtp->tv_nsec;
6530Sstevel@tonic-gate lapse = gethrtime() - start;
6540Sstevel@tonic-gate if (rqlapse > lapse) {
6550Sstevel@tonic-gate hrt2ts(rqlapse - lapse, &reltime);
6560Sstevel@tonic-gate goto restart;
6570Sstevel@tonic-gate }
6580Sstevel@tonic-gate }
6590Sstevel@tonic-gate }
6600Sstevel@tonic-gate if (error == 0 && clock_id == CLOCK_REALTIME &&
6610Sstevel@tonic-gate (flags & TIMER_ABSTIME)) {
6620Sstevel@tonic-gate /*
6630Sstevel@tonic-gate * Don't return yet just because someone reset the
6640Sstevel@tonic-gate * system clock. Recompute the new relative time
6650Sstevel@tonic-gate * and reissue the nanosleep() call if necessary.
6660Sstevel@tonic-gate *
6670Sstevel@tonic-gate * Resetting the system clock causes all sorts of
6680Sstevel@tonic-gate * problems and the SUSV3 standards body should
6690Sstevel@tonic-gate * have made the behavior of clock_nanosleep() be
6700Sstevel@tonic-gate * implementation-defined in such a case rather than
6710Sstevel@tonic-gate * being specific about honoring the new system time.
6720Sstevel@tonic-gate * Standards bodies are filled with fools and idiots.
6730Sstevel@tonic-gate */
6740Sstevel@tonic-gate abstime_to_reltime(clock_id, rqtp, &reltime);
6750Sstevel@tonic-gate if (reltime.tv_sec != 0 || reltime.tv_nsec != 0)
6760Sstevel@tonic-gate goto restart;
6770Sstevel@tonic-gate }
6780Sstevel@tonic-gate return (error);
6790Sstevel@tonic-gate }
6800Sstevel@tonic-gate
6810Sstevel@tonic-gate unsigned int
sleep(unsigned int sec)6826812Sraf sleep(unsigned int sec)
6830Sstevel@tonic-gate {
6840Sstevel@tonic-gate unsigned int rem = 0;
6850Sstevel@tonic-gate timespec_t ts;
6860Sstevel@tonic-gate timespec_t tsr;
6870Sstevel@tonic-gate
6880Sstevel@tonic-gate ts.tv_sec = (time_t)sec;
6890Sstevel@tonic-gate ts.tv_nsec = 0;
6906812Sraf if (nanosleep(&ts, &tsr) == -1 && errno == EINTR) {
6910Sstevel@tonic-gate rem = (unsigned int)tsr.tv_sec;
6920Sstevel@tonic-gate if (tsr.tv_nsec >= NANOSEC / 2)
6930Sstevel@tonic-gate rem++;
6940Sstevel@tonic-gate }
6950Sstevel@tonic-gate return (rem);
6960Sstevel@tonic-gate }
6970Sstevel@tonic-gate
6980Sstevel@tonic-gate int
usleep(useconds_t usec)6996812Sraf usleep(useconds_t usec)
7000Sstevel@tonic-gate {
7010Sstevel@tonic-gate timespec_t ts;
7020Sstevel@tonic-gate
7030Sstevel@tonic-gate ts.tv_sec = usec / MICROSEC;
7040Sstevel@tonic-gate ts.tv_nsec = (long)(usec % MICROSEC) * 1000;
7056812Sraf (void) nanosleep(&ts, NULL);
7060Sstevel@tonic-gate return (0);
7070Sstevel@tonic-gate }
7080Sstevel@tonic-gate
7090Sstevel@tonic-gate int
close(int fildes)7106812Sraf close(int fildes)
7110Sstevel@tonic-gate {
7122248Sraf extern void _aio_close(int);
7135891Sraf extern int __close(int);
7140Sstevel@tonic-gate int rv;
7150Sstevel@tonic-gate
7166755Sraf /*
7176755Sraf * If we call _aio_close() while in a critical region,
7186755Sraf * we will draw an ASSERT() failure, so don't do it.
7196755Sraf * No calls to close() from within libc need _aio_close();
7206755Sraf * only the application's calls to close() need this,
7216755Sraf * and such calls are never from a libc critical region.
7226755Sraf */
7236755Sraf if (curthread->ul_critical == 0)
7246755Sraf _aio_close(fildes);
7255891Sraf PERFORM(__close(fildes))
7260Sstevel@tonic-gate }
7270Sstevel@tonic-gate
7280Sstevel@tonic-gate int
door_call(int d,door_arg_t * params)7296812Sraf door_call(int d, door_arg_t *params)
7300Sstevel@tonic-gate {
7315891Sraf extern int __door_call(int, door_arg_t *);
7325891Sraf int rv;
7335891Sraf
7345891Sraf PERFORM(__door_call(d, params))
7355891Sraf }
7365891Sraf
7375891Sraf int
fcntl(int fildes,int cmd,...)7386812Sraf fcntl(int fildes, int cmd, ...)
7395891Sraf {
7405891Sraf extern int __fcntl(int, int, ...);
7410Sstevel@tonic-gate intptr_t arg;
7420Sstevel@tonic-gate int rv;
7430Sstevel@tonic-gate va_list ap;
7440Sstevel@tonic-gate
7450Sstevel@tonic-gate va_start(ap, cmd);
7460Sstevel@tonic-gate arg = va_arg(ap, intptr_t);
7470Sstevel@tonic-gate va_end(ap);
7480Sstevel@tonic-gate if (cmd != F_SETLKW)
7495891Sraf return (__fcntl(fildes, cmd, arg));
7505891Sraf PERFORM(__fcntl(fildes, cmd, arg))
7510Sstevel@tonic-gate }
7520Sstevel@tonic-gate
7530Sstevel@tonic-gate int
fdatasync(int fildes)7546812Sraf fdatasync(int fildes)
7554722Sraf {
7565891Sraf extern int __fdsync(int, int);
7574722Sraf int rv;
7584722Sraf
7595891Sraf PERFORM(__fdsync(fildes, FDSYNC))
7604722Sraf }
7614722Sraf
7624722Sraf int
fsync(int fildes)7636812Sraf fsync(int fildes)
7640Sstevel@tonic-gate {
7655891Sraf extern int __fdsync(int, int);
7660Sstevel@tonic-gate int rv;
7670Sstevel@tonic-gate
7685891Sraf PERFORM(__fdsync(fildes, FSYNC))
7690Sstevel@tonic-gate }
7700Sstevel@tonic-gate
7710Sstevel@tonic-gate int
lockf(int fildes,int function,off_t size)7726812Sraf lockf(int fildes, int function, off_t size)
7730Sstevel@tonic-gate {
7745891Sraf extern int __lockf(int, int, off_t);
7750Sstevel@tonic-gate int rv;
7760Sstevel@tonic-gate
7775891Sraf PERFORM(__lockf(fildes, function, size))
7780Sstevel@tonic-gate }
7790Sstevel@tonic-gate
7800Sstevel@tonic-gate #if !defined(_LP64)
7810Sstevel@tonic-gate int
lockf64(int fildes,int function,off64_t size)7826812Sraf lockf64(int fildes, int function, off64_t size)
7830Sstevel@tonic-gate {
7845891Sraf extern int __lockf64(int, int, off64_t);
7850Sstevel@tonic-gate int rv;
7860Sstevel@tonic-gate
7875891Sraf PERFORM(__lockf64(fildes, function, size))
7880Sstevel@tonic-gate }
7890Sstevel@tonic-gate #endif /* !_LP64 */
7900Sstevel@tonic-gate
7910Sstevel@tonic-gate ssize_t
msgrcv(int msqid,void * msgp,size_t msgsz,long msgtyp,int msgflg)7926812Sraf msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
7930Sstevel@tonic-gate {
7945891Sraf extern ssize_t __msgrcv(int, void *, size_t, long, int);
7950Sstevel@tonic-gate ssize_t rv;
7960Sstevel@tonic-gate
7975891Sraf PERFORM(__msgrcv(msqid, msgp, msgsz, msgtyp, msgflg))
7980Sstevel@tonic-gate }
7990Sstevel@tonic-gate
8000Sstevel@tonic-gate int
msgsnd(int msqid,const void * msgp,size_t msgsz,int msgflg)8016812Sraf msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg)
8020Sstevel@tonic-gate {
8035891Sraf extern int __msgsnd(int, const void *, size_t, int);
8040Sstevel@tonic-gate int rv;
8050Sstevel@tonic-gate
8065891Sraf PERFORM(__msgsnd(msqid, msgp, msgsz, msgflg))
8075891Sraf }
8085891Sraf
8095891Sraf int
msync(caddr_t addr,size_t len,int flags)8106812Sraf msync(caddr_t addr, size_t len, int flags)
8115891Sraf {
8125891Sraf extern int __msync(caddr_t, size_t, int);
8135891Sraf int rv;
8145891Sraf
8155891Sraf PERFORM(__msync(addr, len, flags))
8160Sstevel@tonic-gate }
8170Sstevel@tonic-gate
8180Sstevel@tonic-gate int
openat(int fd,const char * path,int oflag,...)81911798SRoger.Faulkner@Sun.COM openat(int fd, const char *path, int oflag, ...)
82011798SRoger.Faulkner@Sun.COM {
82111798SRoger.Faulkner@Sun.COM mode_t mode;
82211798SRoger.Faulkner@Sun.COM int rv;
82311798SRoger.Faulkner@Sun.COM va_list ap;
82411798SRoger.Faulkner@Sun.COM
82511798SRoger.Faulkner@Sun.COM va_start(ap, oflag);
82611798SRoger.Faulkner@Sun.COM mode = va_arg(ap, mode_t);
82711798SRoger.Faulkner@Sun.COM va_end(ap);
82811798SRoger.Faulkner@Sun.COM PERFORM(__openat(fd, path, oflag, mode))
82911798SRoger.Faulkner@Sun.COM }
83011798SRoger.Faulkner@Sun.COM
83111798SRoger.Faulkner@Sun.COM int
open(const char * path,int oflag,...)8326812Sraf open(const char *path, int oflag, ...)
8330Sstevel@tonic-gate {
8345891Sraf mode_t mode;
8350Sstevel@tonic-gate int rv;
8365891Sraf va_list ap;
8370Sstevel@tonic-gate
8385891Sraf va_start(ap, oflag);
8395891Sraf mode = va_arg(ap, mode_t);
8405891Sraf va_end(ap);
8415891Sraf PERFORM(__open(path, oflag, mode))
8420Sstevel@tonic-gate }
8430Sstevel@tonic-gate
8440Sstevel@tonic-gate int
creat(const char * path,mode_t mode)84511798SRoger.Faulkner@Sun.COM creat(const char *path, mode_t mode)
8460Sstevel@tonic-gate {
84711798SRoger.Faulkner@Sun.COM return (open(path, O_WRONLY | O_CREAT | O_TRUNC, mode));
84811798SRoger.Faulkner@Sun.COM }
84911798SRoger.Faulkner@Sun.COM
85011798SRoger.Faulkner@Sun.COM #if !defined(_LP64)
85111798SRoger.Faulkner@Sun.COM int
openat64(int fd,const char * path,int oflag,...)85211798SRoger.Faulkner@Sun.COM openat64(int fd, const char *path, int oflag, ...)
85311798SRoger.Faulkner@Sun.COM {
8540Sstevel@tonic-gate mode_t mode;
8550Sstevel@tonic-gate int rv;
8560Sstevel@tonic-gate va_list ap;
8570Sstevel@tonic-gate
8580Sstevel@tonic-gate va_start(ap, oflag);
8590Sstevel@tonic-gate mode = va_arg(ap, mode_t);
8600Sstevel@tonic-gate va_end(ap);
86111798SRoger.Faulkner@Sun.COM PERFORM(__openat64(fd, path, oflag, mode))
8620Sstevel@tonic-gate }
8630Sstevel@tonic-gate
8640Sstevel@tonic-gate int
open64(const char * path,int oflag,...)8656812Sraf open64(const char *path, int oflag, ...)
8660Sstevel@tonic-gate {
8675891Sraf mode_t mode;
8685891Sraf int rv;
8695891Sraf va_list ap;
8705891Sraf
8715891Sraf va_start(ap, oflag);
8725891Sraf mode = va_arg(ap, mode_t);
8735891Sraf va_end(ap);
8745891Sraf PERFORM(__open64(path, oflag, mode))
8755891Sraf }
8765891Sraf
8775891Sraf int
creat64(const char * path,mode_t mode)87811798SRoger.Faulkner@Sun.COM creat64(const char *path, mode_t mode)
8795891Sraf {
88011798SRoger.Faulkner@Sun.COM return (open64(path, O_WRONLY | O_CREAT | O_TRUNC, mode));
8810Sstevel@tonic-gate }
8820Sstevel@tonic-gate #endif /* !_LP64 */
8830Sstevel@tonic-gate
8840Sstevel@tonic-gate int
pause(void)8856812Sraf pause(void)
8860Sstevel@tonic-gate {
8875891Sraf extern int __pause(void);
8880Sstevel@tonic-gate int rv;
8890Sstevel@tonic-gate
8905891Sraf PERFORM(__pause())
8910Sstevel@tonic-gate }
8920Sstevel@tonic-gate
8930Sstevel@tonic-gate ssize_t
pread(int fildes,void * buf,size_t nbyte,off_t offset)8946812Sraf pread(int fildes, void *buf, size_t nbyte, off_t offset)
8950Sstevel@tonic-gate {
8965891Sraf extern ssize_t __pread(int, void *, size_t, off_t);
8970Sstevel@tonic-gate ssize_t rv;
8980Sstevel@tonic-gate
8995891Sraf PERFORM(__pread(fildes, buf, nbyte, offset))
9000Sstevel@tonic-gate }
9010Sstevel@tonic-gate
9020Sstevel@tonic-gate #if !defined(_LP64)
9030Sstevel@tonic-gate ssize_t
pread64(int fildes,void * buf,size_t nbyte,off64_t offset)9046812Sraf pread64(int fildes, void *buf, size_t nbyte, off64_t offset)
9050Sstevel@tonic-gate {
9065891Sraf extern ssize_t __pread64(int, void *, size_t, off64_t);
9070Sstevel@tonic-gate ssize_t rv;
9080Sstevel@tonic-gate
9095891Sraf PERFORM(__pread64(fildes, buf, nbyte, offset))
9100Sstevel@tonic-gate }
9110Sstevel@tonic-gate #endif /* !_LP64 */
9120Sstevel@tonic-gate
9130Sstevel@tonic-gate ssize_t
pwrite(int fildes,const void * buf,size_t nbyte,off_t offset)9146812Sraf pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
9150Sstevel@tonic-gate {
9165891Sraf extern ssize_t __pwrite(int, const void *, size_t, off_t);
9170Sstevel@tonic-gate ssize_t rv;
9180Sstevel@tonic-gate
9195891Sraf PERFORM(__pwrite(fildes, buf, nbyte, offset))
9200Sstevel@tonic-gate }
9210Sstevel@tonic-gate
9220Sstevel@tonic-gate #if !defined(_LP64)
9230Sstevel@tonic-gate ssize_t
pwrite64(int fildes,const void * buf,size_t nbyte,off64_t offset)9246812Sraf pwrite64(int fildes, const void *buf, size_t nbyte, off64_t offset)
9250Sstevel@tonic-gate {
9265891Sraf extern ssize_t __pwrite64(int, const void *, size_t, off64_t);
9270Sstevel@tonic-gate ssize_t rv;
9280Sstevel@tonic-gate
9295891Sraf PERFORM(__pwrite64(fildes, buf, nbyte, offset))
9300Sstevel@tonic-gate }
9310Sstevel@tonic-gate #endif /* !_LP64 */
9320Sstevel@tonic-gate
9330Sstevel@tonic-gate ssize_t
readv(int fildes,const struct iovec * iov,int iovcnt)9346812Sraf readv(int fildes, const struct iovec *iov, int iovcnt)
9350Sstevel@tonic-gate {
9365891Sraf extern ssize_t __readv(int, const struct iovec *, int);
9370Sstevel@tonic-gate ssize_t rv;
9380Sstevel@tonic-gate
9395891Sraf PERFORM(__readv(fildes, iov, iovcnt))
9400Sstevel@tonic-gate }
9410Sstevel@tonic-gate
9420Sstevel@tonic-gate int
sigpause(int sig)9436812Sraf sigpause(int sig)
9440Sstevel@tonic-gate {
9455891Sraf extern int __sigpause(int);
9460Sstevel@tonic-gate int rv;
9470Sstevel@tonic-gate
9485891Sraf PERFORM(__sigpause(sig))
9490Sstevel@tonic-gate }
9500Sstevel@tonic-gate
9510Sstevel@tonic-gate int
sigsuspend(const sigset_t * set)9526812Sraf sigsuspend(const sigset_t *set)
9530Sstevel@tonic-gate {
9540Sstevel@tonic-gate extern int __sigsuspend(const sigset_t *);
9550Sstevel@tonic-gate int rv;
9560Sstevel@tonic-gate
9570Sstevel@tonic-gate PROLOGUE_MASK(set)
9580Sstevel@tonic-gate rv = __sigsuspend(set);
9590Sstevel@tonic-gate EPILOGUE_MASK
9600Sstevel@tonic-gate return (rv);
9610Sstevel@tonic-gate }
9620Sstevel@tonic-gate
9630Sstevel@tonic-gate int
_pollsys(struct pollfd * fds,nfds_t nfd,const timespec_t * timeout,const sigset_t * sigmask)9640Sstevel@tonic-gate _pollsys(struct pollfd *fds, nfds_t nfd, const timespec_t *timeout,
9650Sstevel@tonic-gate const sigset_t *sigmask)
9660Sstevel@tonic-gate {
9670Sstevel@tonic-gate extern int __pollsys(struct pollfd *, nfds_t, const timespec_t *,
9684843Sraf const sigset_t *);
9690Sstevel@tonic-gate int rv;
9700Sstevel@tonic-gate
9710Sstevel@tonic-gate PROLOGUE_MASK(sigmask)
9720Sstevel@tonic-gate rv = __pollsys(fds, nfd, timeout, sigmask);
9730Sstevel@tonic-gate EPILOGUE_MASK
9740Sstevel@tonic-gate return (rv);
9750Sstevel@tonic-gate }
9760Sstevel@tonic-gate
9770Sstevel@tonic-gate int
sigtimedwait(const sigset_t * set,siginfo_t * infop,const timespec_t * timeout)9786812Sraf sigtimedwait(const sigset_t *set, siginfo_t *infop, const timespec_t *timeout)
9790Sstevel@tonic-gate {
9802248Sraf extern int __sigtimedwait(const sigset_t *, siginfo_t *,
9814843Sraf const timespec_t *);
9820Sstevel@tonic-gate siginfo_t info;
9830Sstevel@tonic-gate int sig;
9840Sstevel@tonic-gate
9850Sstevel@tonic-gate PROLOGUE
9865891Sraf if (abort) {
9875891Sraf *self->ul_errnop = EINTR;
9880Sstevel@tonic-gate sig = -1;
9895891Sraf } else {
9905891Sraf sig = __sigtimedwait(set, &info, timeout);
9915891Sraf if (sig == SIGCANCEL &&
9925891Sraf (SI_FROMKERNEL(&info) || info.si_code == SI_LWP)) {
9935891Sraf do_sigcancel();
9945891Sraf *self->ul_errnop = EINTR;
9955891Sraf sig = -1;
9965891Sraf }
9970Sstevel@tonic-gate }
9980Sstevel@tonic-gate EPILOGUE
9990Sstevel@tonic-gate if (sig != -1 && infop)
10006515Sraf (void) memcpy(infop, &info, sizeof (*infop));
10010Sstevel@tonic-gate return (sig);
10020Sstevel@tonic-gate }
10030Sstevel@tonic-gate
10040Sstevel@tonic-gate int
sigwait(sigset_t * set)10056812Sraf sigwait(sigset_t *set)
10060Sstevel@tonic-gate {
10076812Sraf return (sigtimedwait(set, NULL, NULL));
10082248Sraf }
10092248Sraf
10102248Sraf int
sigwaitinfo(const sigset_t * set,siginfo_t * info)10116812Sraf sigwaitinfo(const sigset_t *set, siginfo_t *info)
10122248Sraf {
10136812Sraf return (sigtimedwait(set, info, NULL));
10142248Sraf }
10152248Sraf
10162248Sraf int
sigqueue(pid_t pid,int signo,const union sigval value)10176812Sraf sigqueue(pid_t pid, int signo, const union sigval value)
10182248Sraf {
10192248Sraf extern int __sigqueue(pid_t pid, int signo,
10204843Sraf /* const union sigval */ void *value, int si_code, int block);
10212248Sraf return (__sigqueue(pid, signo, value.sival_ptr, SI_QUEUE, 0));
10220Sstevel@tonic-gate }
10230Sstevel@tonic-gate
10240Sstevel@tonic-gate int
_so_accept(int sock,struct sockaddr * addr,uint_t * addrlen,int version)10255891Sraf _so_accept(int sock, struct sockaddr *addr, uint_t *addrlen, int version)
10260Sstevel@tonic-gate {
10275891Sraf extern int __so_accept(int, struct sockaddr *, uint_t *, int);
10280Sstevel@tonic-gate int rv;
10290Sstevel@tonic-gate
10305891Sraf PERFORM(__so_accept(sock, addr, addrlen, version))
10315891Sraf }
10325891Sraf
10335891Sraf int
_so_connect(int sock,struct sockaddr * addr,uint_t addrlen,int version)10345891Sraf _so_connect(int sock, struct sockaddr *addr, uint_t addrlen, int version)
10355891Sraf {
10365891Sraf extern int __so_connect(int, struct sockaddr *, uint_t, int);
10375891Sraf int rv;
10385891Sraf
10395891Sraf PERFORM(__so_connect(sock, addr, addrlen, version))
10400Sstevel@tonic-gate }
10410Sstevel@tonic-gate
10425891Sraf int
_so_recv(int sock,void * buf,size_t len,int flags)10435891Sraf _so_recv(int sock, void *buf, size_t len, int flags)
10440Sstevel@tonic-gate {
10455891Sraf extern int __so_recv(int, void *, size_t, int);
10465891Sraf int rv;
10470Sstevel@tonic-gate
10485891Sraf PERFORM(__so_recv(sock, buf, len, flags))
10490Sstevel@tonic-gate }
10500Sstevel@tonic-gate
10515891Sraf int
_so_recvfrom(int sock,void * buf,size_t len,int flags,struct sockaddr * addr,int * addrlen)10525891Sraf _so_recvfrom(int sock, void *buf, size_t len, int flags,
10535891Sraf struct sockaddr *addr, int *addrlen)
10540Sstevel@tonic-gate {
10555891Sraf extern int __so_recvfrom(int, void *, size_t, int,
10565891Sraf struct sockaddr *, int *);
10575891Sraf int rv;
10585891Sraf
10595891Sraf PERFORM(__so_recvfrom(sock, buf, len, flags, addr, addrlen))
10605891Sraf }
10610Sstevel@tonic-gate
10625891Sraf int
_so_recvmsg(int sock,struct msghdr * msg,int flags)10635891Sraf _so_recvmsg(int sock, struct msghdr *msg, int flags)
10645891Sraf {
10655891Sraf extern int __so_recvmsg(int, struct msghdr *, int);
10665891Sraf int rv;
10675891Sraf
10685891Sraf PERFORM(__so_recvmsg(sock, msg, flags))
10690Sstevel@tonic-gate }
10700Sstevel@tonic-gate
10710Sstevel@tonic-gate int
_so_send(int sock,const void * buf,size_t len,int flags)10725891Sraf _so_send(int sock, const void *buf, size_t len, int flags)
10730Sstevel@tonic-gate {
10745891Sraf extern int __so_send(int, const void *, size_t, int);
10750Sstevel@tonic-gate int rv;
10760Sstevel@tonic-gate
10775891Sraf PERFORM(__so_send(sock, buf, len, flags))
10785891Sraf }
10795891Sraf
10805891Sraf int
_so_sendmsg(int sock,const struct msghdr * msg,int flags)10815891Sraf _so_sendmsg(int sock, const struct msghdr *msg, int flags)
10825891Sraf {
10835891Sraf extern int __so_sendmsg(int, const struct msghdr *, int);
10845891Sraf int rv;
10855891Sraf
10865891Sraf PERFORM(__so_sendmsg(sock, msg, flags))
10875891Sraf }
10885891Sraf
10895891Sraf int
_so_sendto(int sock,const void * buf,size_t len,int flags,const struct sockaddr * addr,int * addrlen)10905891Sraf _so_sendto(int sock, const void *buf, size_t len, int flags,
10915891Sraf const struct sockaddr *addr, int *addrlen)
10925891Sraf {
10935891Sraf extern int __so_sendto(int, const void *, size_t, int,
10945891Sraf const struct sockaddr *, int *);
10955891Sraf int rv;
10965891Sraf
10975891Sraf PERFORM(__so_sendto(sock, buf, len, flags, addr, addrlen))
10980Sstevel@tonic-gate }
10990Sstevel@tonic-gate
11005891Sraf int
tcdrain(int fildes)11016812Sraf tcdrain(int fildes)
11020Sstevel@tonic-gate {
11035891Sraf extern int __tcdrain(int);
11045891Sraf int rv;
11050Sstevel@tonic-gate
11065891Sraf PERFORM(__tcdrain(fildes))
11070Sstevel@tonic-gate }
11080Sstevel@tonic-gate
11095891Sraf int
waitid(idtype_t idtype,id_t id,siginfo_t * infop,int options)11106812Sraf waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options)
11115891Sraf {
11125891Sraf extern int __waitid(idtype_t, id_t, siginfo_t *, int);
11135891Sraf int rv;
11145891Sraf
11155891Sraf if (options & WNOHANG)
11165891Sraf return (__waitid(idtype, id, infop, options));
11175891Sraf PERFORM(__waitid(idtype, id, infop, options))
11185891Sraf }
11195891Sraf
11200Sstevel@tonic-gate ssize_t
writev(int fildes,const struct iovec * iov,int iovcnt)11216812Sraf writev(int fildes, const struct iovec *iov, int iovcnt)
11220Sstevel@tonic-gate {
11235891Sraf extern ssize_t __writev(int, const struct iovec *, int);
11240Sstevel@tonic-gate ssize_t rv;
11250Sstevel@tonic-gate
11265891Sraf PERFORM(__writev(fildes, iov, iovcnt))
11270Sstevel@tonic-gate }
1128