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 /* 23*11798SRoger.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 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 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 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 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 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 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 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 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); \ 4161111Sraf self->ul_tmpmask.__sigbits[0] = sigmask->__sigbits[0]; \ 4171111Sraf self->ul_tmpmask.__sigbits[1] = sigmask->__sigbits[1]; \ 4180Sstevel@tonic-gate delete_reserved_signals(&self->ul_tmpmask); \ 4190Sstevel@tonic-gate self->ul_sigsuspend = 1; \ 4200Sstevel@tonic-gate } \ 4210Sstevel@tonic-gate if (nocancel == 0) { \ 4220Sstevel@tonic-gate self->ul_save_async = self->ul_cancel_async; \ 4230Sstevel@tonic-gate if (!self->ul_cancel_disabled) { \ 4240Sstevel@tonic-gate self->ul_cancel_async = 1; \ 4250Sstevel@tonic-gate if (self->ul_cancel_pending) { \ 4260Sstevel@tonic-gate if (self->ul_sigsuspend) { \ 4270Sstevel@tonic-gate self->ul_sigsuspend = 0;\ 4280Sstevel@tonic-gate restore_signals(self); \ 4290Sstevel@tonic-gate } \ 4306812Sraf pthread_exit(PTHREAD_CANCELED); \ 4310Sstevel@tonic-gate } \ 4320Sstevel@tonic-gate } \ 4330Sstevel@tonic-gate self->ul_sp = stkptr(); \ 4340Sstevel@tonic-gate } \ 4350Sstevel@tonic-gate } 4360Sstevel@tonic-gate 4370Sstevel@tonic-gate /* 4380Sstevel@tonic-gate * If a signal is taken, we return from the system call wrapper with 4390Sstevel@tonic-gate * our original signal mask restored (see code in call_user_handler()). 4400Sstevel@tonic-gate * If not (self->ul_sigsuspend is still non-zero), we must restore our 4410Sstevel@tonic-gate * original signal mask ourself. 4420Sstevel@tonic-gate */ 4430Sstevel@tonic-gate #define EPILOGUE_MASK \ 4440Sstevel@tonic-gate if (nocancel == 0) { \ 4450Sstevel@tonic-gate self->ul_sp = 0; \ 4460Sstevel@tonic-gate self->ul_cancel_async = self->ul_save_async; \ 4470Sstevel@tonic-gate } \ 4480Sstevel@tonic-gate if (self->ul_sigsuspend) { \ 4490Sstevel@tonic-gate self->ul_sigsuspend = 0; \ 4500Sstevel@tonic-gate restore_signals(self); \ 4510Sstevel@tonic-gate } \ 4520Sstevel@tonic-gate } 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate /* 4552248Sraf * Cancellation prologue and epilogue functions, 4562248Sraf * for cancellation points too complex to include here. 4571885Sraf */ 4581885Sraf void 4591885Sraf _cancel_prologue(void) 4601885Sraf { 4611885Sraf ulwp_t *self = curthread; 4621885Sraf 4635891Sraf self->ul_cancel_prologue = 4645891Sraf (self->ul_vfork | self->ul_nocancel | self->ul_libc_locks | 4655891Sraf self->ul_critical | self->ul_sigdefer) != 0; 4661885Sraf if (self->ul_cancel_prologue == 0) { 4671885Sraf self->ul_save_async = self->ul_cancel_async; 4681885Sraf if (!self->ul_cancel_disabled) { 4691885Sraf self->ul_cancel_async = 1; 4701885Sraf if (self->ul_cancel_pending) 4716812Sraf pthread_exit(PTHREAD_CANCELED); 4721885Sraf } 4731885Sraf self->ul_sp = stkptr(); 4745891Sraf } else if (self->ul_cancel_pending && 4755891Sraf !self->ul_cancel_disabled) { 4765891Sraf set_cancel_eintr_flag(self); 4771885Sraf } 4781885Sraf } 4791885Sraf 4801885Sraf void 4811885Sraf _cancel_epilogue(void) 4821885Sraf { 4831885Sraf ulwp_t *self = curthread; 4841885Sraf 4851885Sraf if (self->ul_cancel_prologue == 0) { 4861885Sraf self->ul_sp = 0; 4871885Sraf self->ul_cancel_async = self->ul_save_async; 4881885Sraf } 4891885Sraf } 4901885Sraf 4911885Sraf /* 4920Sstevel@tonic-gate * Called from _thrp_join() (thr_join() is a cancellation point) 4930Sstevel@tonic-gate */ 4940Sstevel@tonic-gate int 4950Sstevel@tonic-gate lwp_wait(thread_t tid, thread_t *found) 4960Sstevel@tonic-gate { 4970Sstevel@tonic-gate int error; 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate PROLOGUE 5005891Sraf if (abort) 5015891Sraf return (EINTR); 5025891Sraf while ((error = __lwp_wait(tid, found)) == EINTR && !cancel_active()) 5035891Sraf continue; 5040Sstevel@tonic-gate EPILOGUE 5050Sstevel@tonic-gate return (error); 5060Sstevel@tonic-gate } 5070Sstevel@tonic-gate 5080Sstevel@tonic-gate ssize_t 5096812Sraf read(int fd, void *buf, size_t size) 5100Sstevel@tonic-gate { 5115891Sraf extern ssize_t __read(int, void *, size_t); 5120Sstevel@tonic-gate ssize_t rv; 5130Sstevel@tonic-gate 5145891Sraf PERFORM(__read(fd, buf, size)) 5150Sstevel@tonic-gate } 5160Sstevel@tonic-gate 5170Sstevel@tonic-gate ssize_t 5186812Sraf write(int fd, const void *buf, size_t size) 5190Sstevel@tonic-gate { 5205891Sraf extern ssize_t __write(int, const void *, size_t); 5210Sstevel@tonic-gate ssize_t rv; 5220Sstevel@tonic-gate 5235891Sraf PERFORM(__write(fd, buf, size)) 5240Sstevel@tonic-gate } 5250Sstevel@tonic-gate 5260Sstevel@tonic-gate int 5276812Sraf getmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr, 5280Sstevel@tonic-gate int *flagsp) 5290Sstevel@tonic-gate { 5305891Sraf extern int __getmsg(int, struct strbuf *, struct strbuf *, int *); 5310Sstevel@tonic-gate int rv; 5320Sstevel@tonic-gate 5335891Sraf PERFORM(__getmsg(fd, ctlptr, dataptr, flagsp)) 5340Sstevel@tonic-gate } 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate int 5376812Sraf getpmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr, 5380Sstevel@tonic-gate int *bandp, int *flagsp) 5390Sstevel@tonic-gate { 5405891Sraf extern int __getpmsg(int, struct strbuf *, struct strbuf *, 5414843Sraf int *, int *); 5420Sstevel@tonic-gate int rv; 5430Sstevel@tonic-gate 5445891Sraf PERFORM(__getpmsg(fd, ctlptr, dataptr, bandp, flagsp)) 5450Sstevel@tonic-gate } 5460Sstevel@tonic-gate 5470Sstevel@tonic-gate int 5486812Sraf putmsg(int fd, const struct strbuf *ctlptr, 5490Sstevel@tonic-gate const struct strbuf *dataptr, int flags) 5500Sstevel@tonic-gate { 5515891Sraf extern int __putmsg(int, const struct strbuf *, 5524843Sraf const struct strbuf *, int); 5530Sstevel@tonic-gate int rv; 5540Sstevel@tonic-gate 5555891Sraf PERFORM(__putmsg(fd, ctlptr, dataptr, flags)) 5560Sstevel@tonic-gate } 5570Sstevel@tonic-gate 5580Sstevel@tonic-gate int 5590Sstevel@tonic-gate __xpg4_putmsg(int fd, const struct strbuf *ctlptr, 5600Sstevel@tonic-gate const struct strbuf *dataptr, int flags) 5610Sstevel@tonic-gate { 5625891Sraf extern int __putmsg(int, const struct strbuf *, 5634843Sraf const struct strbuf *, int); 5640Sstevel@tonic-gate int rv; 5650Sstevel@tonic-gate 5665891Sraf PERFORM(__putmsg(fd, ctlptr, dataptr, flags|MSG_XPG4)) 5670Sstevel@tonic-gate } 5680Sstevel@tonic-gate 5690Sstevel@tonic-gate int 5706812Sraf putpmsg(int fd, const struct strbuf *ctlptr, 5710Sstevel@tonic-gate const struct strbuf *dataptr, int band, int flags) 5720Sstevel@tonic-gate { 5735891Sraf extern int __putpmsg(int, const struct strbuf *, 5744843Sraf const struct strbuf *, int, int); 5750Sstevel@tonic-gate int rv; 5760Sstevel@tonic-gate 5775891Sraf PERFORM(__putpmsg(fd, ctlptr, dataptr, band, flags)) 5780Sstevel@tonic-gate } 5790Sstevel@tonic-gate 5800Sstevel@tonic-gate int 5810Sstevel@tonic-gate __xpg4_putpmsg(int fd, const struct strbuf *ctlptr, 5820Sstevel@tonic-gate const struct strbuf *dataptr, int band, int flags) 5830Sstevel@tonic-gate { 5845891Sraf extern int __putpmsg(int, const struct strbuf *, 5854843Sraf const struct strbuf *, int, int); 5860Sstevel@tonic-gate int rv; 5870Sstevel@tonic-gate 5885891Sraf PERFORM(__putpmsg(fd, ctlptr, dataptr, band, flags|MSG_XPG4)) 5890Sstevel@tonic-gate } 5900Sstevel@tonic-gate 5910Sstevel@tonic-gate int 5926812Sraf nanosleep(const timespec_t *rqtp, timespec_t *rmtp) 5930Sstevel@tonic-gate { 5940Sstevel@tonic-gate int error; 5950Sstevel@tonic-gate 5960Sstevel@tonic-gate PROLOGUE 5975891Sraf error = abort? EINTR : __nanosleep(rqtp, rmtp); 5980Sstevel@tonic-gate EPILOGUE 5990Sstevel@tonic-gate if (error) { 6000Sstevel@tonic-gate errno = error; 6010Sstevel@tonic-gate return (-1); 6020Sstevel@tonic-gate } 6030Sstevel@tonic-gate return (0); 6040Sstevel@tonic-gate } 6050Sstevel@tonic-gate 6060Sstevel@tonic-gate int 6076812Sraf clock_nanosleep(clockid_t clock_id, int flags, 6080Sstevel@tonic-gate const timespec_t *rqtp, timespec_t *rmtp) 6090Sstevel@tonic-gate { 6100Sstevel@tonic-gate timespec_t reltime; 6110Sstevel@tonic-gate hrtime_t start; 6120Sstevel@tonic-gate hrtime_t rqlapse; 6130Sstevel@tonic-gate hrtime_t lapse; 6140Sstevel@tonic-gate int error; 6150Sstevel@tonic-gate 6160Sstevel@tonic-gate switch (clock_id) { 6170Sstevel@tonic-gate case CLOCK_VIRTUAL: 6180Sstevel@tonic-gate case CLOCK_PROCESS_CPUTIME_ID: 6190Sstevel@tonic-gate case CLOCK_THREAD_CPUTIME_ID: 6200Sstevel@tonic-gate return (ENOTSUP); 6210Sstevel@tonic-gate case CLOCK_REALTIME: 6220Sstevel@tonic-gate case CLOCK_HIGHRES: 6230Sstevel@tonic-gate break; 6240Sstevel@tonic-gate default: 6250Sstevel@tonic-gate return (EINVAL); 6260Sstevel@tonic-gate } 6270Sstevel@tonic-gate if (flags & TIMER_ABSTIME) { 6280Sstevel@tonic-gate abstime_to_reltime(clock_id, rqtp, &reltime); 6290Sstevel@tonic-gate rmtp = NULL; 6300Sstevel@tonic-gate } else { 6310Sstevel@tonic-gate reltime = *rqtp; 6320Sstevel@tonic-gate if (clock_id == CLOCK_HIGHRES) 6330Sstevel@tonic-gate start = gethrtime(); 6340Sstevel@tonic-gate } 6350Sstevel@tonic-gate restart: 6360Sstevel@tonic-gate PROLOGUE 6375891Sraf error = abort? EINTR : __nanosleep(&reltime, rmtp); 6380Sstevel@tonic-gate EPILOGUE 6390Sstevel@tonic-gate if (error == 0 && clock_id == CLOCK_HIGHRES) { 6400Sstevel@tonic-gate /* 6410Sstevel@tonic-gate * Don't return yet if we didn't really get a timeout. 6420Sstevel@tonic-gate * This can happen if we return because someone resets 6430Sstevel@tonic-gate * the system clock. 6440Sstevel@tonic-gate */ 6450Sstevel@tonic-gate if (flags & TIMER_ABSTIME) { 6460Sstevel@tonic-gate if ((hrtime_t)(uint32_t)rqtp->tv_sec * NANOSEC + 6470Sstevel@tonic-gate rqtp->tv_nsec > gethrtime()) { 6480Sstevel@tonic-gate abstime_to_reltime(clock_id, rqtp, &reltime); 6490Sstevel@tonic-gate goto restart; 6500Sstevel@tonic-gate } 6510Sstevel@tonic-gate } else { 6520Sstevel@tonic-gate rqlapse = (hrtime_t)(uint32_t)rqtp->tv_sec * NANOSEC + 6534843Sraf rqtp->tv_nsec; 6540Sstevel@tonic-gate lapse = gethrtime() - start; 6550Sstevel@tonic-gate if (rqlapse > lapse) { 6560Sstevel@tonic-gate hrt2ts(rqlapse - lapse, &reltime); 6570Sstevel@tonic-gate goto restart; 6580Sstevel@tonic-gate } 6590Sstevel@tonic-gate } 6600Sstevel@tonic-gate } 6610Sstevel@tonic-gate if (error == 0 && clock_id == CLOCK_REALTIME && 6620Sstevel@tonic-gate (flags & TIMER_ABSTIME)) { 6630Sstevel@tonic-gate /* 6640Sstevel@tonic-gate * Don't return yet just because someone reset the 6650Sstevel@tonic-gate * system clock. Recompute the new relative time 6660Sstevel@tonic-gate * and reissue the nanosleep() call if necessary. 6670Sstevel@tonic-gate * 6680Sstevel@tonic-gate * Resetting the system clock causes all sorts of 6690Sstevel@tonic-gate * problems and the SUSV3 standards body should 6700Sstevel@tonic-gate * have made the behavior of clock_nanosleep() be 6710Sstevel@tonic-gate * implementation-defined in such a case rather than 6720Sstevel@tonic-gate * being specific about honoring the new system time. 6730Sstevel@tonic-gate * Standards bodies are filled with fools and idiots. 6740Sstevel@tonic-gate */ 6750Sstevel@tonic-gate abstime_to_reltime(clock_id, rqtp, &reltime); 6760Sstevel@tonic-gate if (reltime.tv_sec != 0 || reltime.tv_nsec != 0) 6770Sstevel@tonic-gate goto restart; 6780Sstevel@tonic-gate } 6790Sstevel@tonic-gate return (error); 6800Sstevel@tonic-gate } 6810Sstevel@tonic-gate 6820Sstevel@tonic-gate unsigned int 6836812Sraf sleep(unsigned int sec) 6840Sstevel@tonic-gate { 6850Sstevel@tonic-gate unsigned int rem = 0; 6860Sstevel@tonic-gate timespec_t ts; 6870Sstevel@tonic-gate timespec_t tsr; 6880Sstevel@tonic-gate 6890Sstevel@tonic-gate ts.tv_sec = (time_t)sec; 6900Sstevel@tonic-gate ts.tv_nsec = 0; 6916812Sraf if (nanosleep(&ts, &tsr) == -1 && errno == EINTR) { 6920Sstevel@tonic-gate rem = (unsigned int)tsr.tv_sec; 6930Sstevel@tonic-gate if (tsr.tv_nsec >= NANOSEC / 2) 6940Sstevel@tonic-gate rem++; 6950Sstevel@tonic-gate } 6960Sstevel@tonic-gate return (rem); 6970Sstevel@tonic-gate } 6980Sstevel@tonic-gate 6990Sstevel@tonic-gate int 7006812Sraf usleep(useconds_t usec) 7010Sstevel@tonic-gate { 7020Sstevel@tonic-gate timespec_t ts; 7030Sstevel@tonic-gate 7040Sstevel@tonic-gate ts.tv_sec = usec / MICROSEC; 7050Sstevel@tonic-gate ts.tv_nsec = (long)(usec % MICROSEC) * 1000; 7066812Sraf (void) nanosleep(&ts, NULL); 7070Sstevel@tonic-gate return (0); 7080Sstevel@tonic-gate } 7090Sstevel@tonic-gate 7100Sstevel@tonic-gate int 7116812Sraf close(int fildes) 7120Sstevel@tonic-gate { 7132248Sraf extern void _aio_close(int); 7145891Sraf extern int __close(int); 7150Sstevel@tonic-gate int rv; 7160Sstevel@tonic-gate 7176755Sraf /* 7186755Sraf * If we call _aio_close() while in a critical region, 7196755Sraf * we will draw an ASSERT() failure, so don't do it. 7206755Sraf * No calls to close() from within libc need _aio_close(); 7216755Sraf * only the application's calls to close() need this, 7226755Sraf * and such calls are never from a libc critical region. 7236755Sraf */ 7246755Sraf if (curthread->ul_critical == 0) 7256755Sraf _aio_close(fildes); 7265891Sraf PERFORM(__close(fildes)) 7270Sstevel@tonic-gate } 7280Sstevel@tonic-gate 7290Sstevel@tonic-gate int 7306812Sraf door_call(int d, door_arg_t *params) 7310Sstevel@tonic-gate { 7325891Sraf extern int __door_call(int, door_arg_t *); 7335891Sraf int rv; 7345891Sraf 7355891Sraf PERFORM(__door_call(d, params)) 7365891Sraf } 7375891Sraf 7385891Sraf int 7396812Sraf fcntl(int fildes, int cmd, ...) 7405891Sraf { 7415891Sraf extern int __fcntl(int, int, ...); 7420Sstevel@tonic-gate intptr_t arg; 7430Sstevel@tonic-gate int rv; 7440Sstevel@tonic-gate va_list ap; 7450Sstevel@tonic-gate 7460Sstevel@tonic-gate va_start(ap, cmd); 7470Sstevel@tonic-gate arg = va_arg(ap, intptr_t); 7480Sstevel@tonic-gate va_end(ap); 7490Sstevel@tonic-gate if (cmd != F_SETLKW) 7505891Sraf return (__fcntl(fildes, cmd, arg)); 7515891Sraf PERFORM(__fcntl(fildes, cmd, arg)) 7520Sstevel@tonic-gate } 7530Sstevel@tonic-gate 7540Sstevel@tonic-gate int 7556812Sraf fdatasync(int fildes) 7564722Sraf { 7575891Sraf extern int __fdsync(int, int); 7584722Sraf int rv; 7594722Sraf 7605891Sraf PERFORM(__fdsync(fildes, FDSYNC)) 7614722Sraf } 7624722Sraf 7634722Sraf int 7646812Sraf fsync(int fildes) 7650Sstevel@tonic-gate { 7665891Sraf extern int __fdsync(int, int); 7670Sstevel@tonic-gate int rv; 7680Sstevel@tonic-gate 7695891Sraf PERFORM(__fdsync(fildes, FSYNC)) 7700Sstevel@tonic-gate } 7710Sstevel@tonic-gate 7720Sstevel@tonic-gate int 7736812Sraf lockf(int fildes, int function, off_t size) 7740Sstevel@tonic-gate { 7755891Sraf extern int __lockf(int, int, off_t); 7760Sstevel@tonic-gate int rv; 7770Sstevel@tonic-gate 7785891Sraf PERFORM(__lockf(fildes, function, size)) 7790Sstevel@tonic-gate } 7800Sstevel@tonic-gate 7810Sstevel@tonic-gate #if !defined(_LP64) 7820Sstevel@tonic-gate int 7836812Sraf lockf64(int fildes, int function, off64_t size) 7840Sstevel@tonic-gate { 7855891Sraf extern int __lockf64(int, int, off64_t); 7860Sstevel@tonic-gate int rv; 7870Sstevel@tonic-gate 7885891Sraf PERFORM(__lockf64(fildes, function, size)) 7890Sstevel@tonic-gate } 7900Sstevel@tonic-gate #endif /* !_LP64 */ 7910Sstevel@tonic-gate 7920Sstevel@tonic-gate ssize_t 7936812Sraf msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg) 7940Sstevel@tonic-gate { 7955891Sraf extern ssize_t __msgrcv(int, void *, size_t, long, int); 7960Sstevel@tonic-gate ssize_t rv; 7970Sstevel@tonic-gate 7985891Sraf PERFORM(__msgrcv(msqid, msgp, msgsz, msgtyp, msgflg)) 7990Sstevel@tonic-gate } 8000Sstevel@tonic-gate 8010Sstevel@tonic-gate int 8026812Sraf msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg) 8030Sstevel@tonic-gate { 8045891Sraf extern int __msgsnd(int, const void *, size_t, int); 8050Sstevel@tonic-gate int rv; 8060Sstevel@tonic-gate 8075891Sraf PERFORM(__msgsnd(msqid, msgp, msgsz, msgflg)) 8085891Sraf } 8095891Sraf 8105891Sraf int 8116812Sraf msync(caddr_t addr, size_t len, int flags) 8125891Sraf { 8135891Sraf extern int __msync(caddr_t, size_t, int); 8145891Sraf int rv; 8155891Sraf 8165891Sraf PERFORM(__msync(addr, len, flags)) 8170Sstevel@tonic-gate } 8180Sstevel@tonic-gate 8190Sstevel@tonic-gate int 820*11798SRoger.Faulkner@Sun.COM openat(int fd, const char *path, int oflag, ...) 821*11798SRoger.Faulkner@Sun.COM { 822*11798SRoger.Faulkner@Sun.COM mode_t mode; 823*11798SRoger.Faulkner@Sun.COM int rv; 824*11798SRoger.Faulkner@Sun.COM va_list ap; 825*11798SRoger.Faulkner@Sun.COM 826*11798SRoger.Faulkner@Sun.COM va_start(ap, oflag); 827*11798SRoger.Faulkner@Sun.COM mode = va_arg(ap, mode_t); 828*11798SRoger.Faulkner@Sun.COM va_end(ap); 829*11798SRoger.Faulkner@Sun.COM PERFORM(__openat(fd, path, oflag, mode)) 830*11798SRoger.Faulkner@Sun.COM } 831*11798SRoger.Faulkner@Sun.COM 832*11798SRoger.Faulkner@Sun.COM int 8336812Sraf open(const char *path, int oflag, ...) 8340Sstevel@tonic-gate { 8355891Sraf mode_t mode; 8360Sstevel@tonic-gate int rv; 8375891Sraf va_list ap; 8380Sstevel@tonic-gate 8395891Sraf va_start(ap, oflag); 8405891Sraf mode = va_arg(ap, mode_t); 8415891Sraf va_end(ap); 8425891Sraf PERFORM(__open(path, oflag, mode)) 8430Sstevel@tonic-gate } 8440Sstevel@tonic-gate 8450Sstevel@tonic-gate int 846*11798SRoger.Faulkner@Sun.COM creat(const char *path, mode_t mode) 8470Sstevel@tonic-gate { 848*11798SRoger.Faulkner@Sun.COM return (open(path, O_WRONLY | O_CREAT | O_TRUNC, mode)); 849*11798SRoger.Faulkner@Sun.COM } 850*11798SRoger.Faulkner@Sun.COM 851*11798SRoger.Faulkner@Sun.COM #if !defined(_LP64) 852*11798SRoger.Faulkner@Sun.COM int 853*11798SRoger.Faulkner@Sun.COM openat64(int fd, const char *path, int oflag, ...) 854*11798SRoger.Faulkner@Sun.COM { 8550Sstevel@tonic-gate mode_t mode; 8560Sstevel@tonic-gate int rv; 8570Sstevel@tonic-gate va_list ap; 8580Sstevel@tonic-gate 8590Sstevel@tonic-gate va_start(ap, oflag); 8600Sstevel@tonic-gate mode = va_arg(ap, mode_t); 8610Sstevel@tonic-gate va_end(ap); 862*11798SRoger.Faulkner@Sun.COM PERFORM(__openat64(fd, path, oflag, mode)) 8630Sstevel@tonic-gate } 8640Sstevel@tonic-gate 8650Sstevel@tonic-gate int 8666812Sraf open64(const char *path, int oflag, ...) 8670Sstevel@tonic-gate { 8685891Sraf mode_t mode; 8695891Sraf int rv; 8705891Sraf va_list ap; 8715891Sraf 8725891Sraf va_start(ap, oflag); 8735891Sraf mode = va_arg(ap, mode_t); 8745891Sraf va_end(ap); 8755891Sraf PERFORM(__open64(path, oflag, mode)) 8765891Sraf } 8775891Sraf 8785891Sraf int 879*11798SRoger.Faulkner@Sun.COM creat64(const char *path, mode_t mode) 8805891Sraf { 881*11798SRoger.Faulkner@Sun.COM return (open64(path, O_WRONLY | O_CREAT | O_TRUNC, mode)); 8820Sstevel@tonic-gate } 8830Sstevel@tonic-gate #endif /* !_LP64 */ 8840Sstevel@tonic-gate 8850Sstevel@tonic-gate int 8866812Sraf pause(void) 8870Sstevel@tonic-gate { 8885891Sraf extern int __pause(void); 8890Sstevel@tonic-gate int rv; 8900Sstevel@tonic-gate 8915891Sraf PERFORM(__pause()) 8920Sstevel@tonic-gate } 8930Sstevel@tonic-gate 8940Sstevel@tonic-gate ssize_t 8956812Sraf pread(int fildes, void *buf, size_t nbyte, off_t offset) 8960Sstevel@tonic-gate { 8975891Sraf extern ssize_t __pread(int, void *, size_t, off_t); 8980Sstevel@tonic-gate ssize_t rv; 8990Sstevel@tonic-gate 9005891Sraf PERFORM(__pread(fildes, buf, nbyte, offset)) 9010Sstevel@tonic-gate } 9020Sstevel@tonic-gate 9030Sstevel@tonic-gate #if !defined(_LP64) 9040Sstevel@tonic-gate ssize_t 9056812Sraf pread64(int fildes, void *buf, size_t nbyte, off64_t offset) 9060Sstevel@tonic-gate { 9075891Sraf extern ssize_t __pread64(int, void *, size_t, off64_t); 9080Sstevel@tonic-gate ssize_t rv; 9090Sstevel@tonic-gate 9105891Sraf PERFORM(__pread64(fildes, buf, nbyte, offset)) 9110Sstevel@tonic-gate } 9120Sstevel@tonic-gate #endif /* !_LP64 */ 9130Sstevel@tonic-gate 9140Sstevel@tonic-gate ssize_t 9156812Sraf pwrite(int fildes, const void *buf, size_t nbyte, off_t offset) 9160Sstevel@tonic-gate { 9175891Sraf extern ssize_t __pwrite(int, const void *, size_t, off_t); 9180Sstevel@tonic-gate ssize_t rv; 9190Sstevel@tonic-gate 9205891Sraf PERFORM(__pwrite(fildes, buf, nbyte, offset)) 9210Sstevel@tonic-gate } 9220Sstevel@tonic-gate 9230Sstevel@tonic-gate #if !defined(_LP64) 9240Sstevel@tonic-gate ssize_t 9256812Sraf pwrite64(int fildes, const void *buf, size_t nbyte, off64_t offset) 9260Sstevel@tonic-gate { 9275891Sraf extern ssize_t __pwrite64(int, const void *, size_t, off64_t); 9280Sstevel@tonic-gate ssize_t rv; 9290Sstevel@tonic-gate 9305891Sraf PERFORM(__pwrite64(fildes, buf, nbyte, offset)) 9310Sstevel@tonic-gate } 9320Sstevel@tonic-gate #endif /* !_LP64 */ 9330Sstevel@tonic-gate 9340Sstevel@tonic-gate ssize_t 9356812Sraf readv(int fildes, const struct iovec *iov, int iovcnt) 9360Sstevel@tonic-gate { 9375891Sraf extern ssize_t __readv(int, const struct iovec *, int); 9380Sstevel@tonic-gate ssize_t rv; 9390Sstevel@tonic-gate 9405891Sraf PERFORM(__readv(fildes, iov, iovcnt)) 9410Sstevel@tonic-gate } 9420Sstevel@tonic-gate 9430Sstevel@tonic-gate int 9446812Sraf sigpause(int sig) 9450Sstevel@tonic-gate { 9465891Sraf extern int __sigpause(int); 9470Sstevel@tonic-gate int rv; 9480Sstevel@tonic-gate 9495891Sraf PERFORM(__sigpause(sig)) 9500Sstevel@tonic-gate } 9510Sstevel@tonic-gate 9520Sstevel@tonic-gate int 9536812Sraf sigsuspend(const sigset_t *set) 9540Sstevel@tonic-gate { 9550Sstevel@tonic-gate extern int __sigsuspend(const sigset_t *); 9560Sstevel@tonic-gate int rv; 9570Sstevel@tonic-gate 9580Sstevel@tonic-gate PROLOGUE_MASK(set) 9590Sstevel@tonic-gate rv = __sigsuspend(set); 9600Sstevel@tonic-gate EPILOGUE_MASK 9610Sstevel@tonic-gate return (rv); 9620Sstevel@tonic-gate } 9630Sstevel@tonic-gate 9640Sstevel@tonic-gate int 9650Sstevel@tonic-gate _pollsys(struct pollfd *fds, nfds_t nfd, const timespec_t *timeout, 9660Sstevel@tonic-gate const sigset_t *sigmask) 9670Sstevel@tonic-gate { 9680Sstevel@tonic-gate extern int __pollsys(struct pollfd *, nfds_t, const timespec_t *, 9694843Sraf const sigset_t *); 9700Sstevel@tonic-gate int rv; 9710Sstevel@tonic-gate 9720Sstevel@tonic-gate PROLOGUE_MASK(sigmask) 9730Sstevel@tonic-gate rv = __pollsys(fds, nfd, timeout, sigmask); 9740Sstevel@tonic-gate EPILOGUE_MASK 9750Sstevel@tonic-gate return (rv); 9760Sstevel@tonic-gate } 9770Sstevel@tonic-gate 9780Sstevel@tonic-gate int 9796812Sraf sigtimedwait(const sigset_t *set, siginfo_t *infop, const timespec_t *timeout) 9800Sstevel@tonic-gate { 9812248Sraf extern int __sigtimedwait(const sigset_t *, siginfo_t *, 9824843Sraf const timespec_t *); 9830Sstevel@tonic-gate siginfo_t info; 9840Sstevel@tonic-gate int sig; 9850Sstevel@tonic-gate 9860Sstevel@tonic-gate PROLOGUE 9875891Sraf if (abort) { 9885891Sraf *self->ul_errnop = EINTR; 9890Sstevel@tonic-gate sig = -1; 9905891Sraf } else { 9915891Sraf sig = __sigtimedwait(set, &info, timeout); 9925891Sraf if (sig == SIGCANCEL && 9935891Sraf (SI_FROMKERNEL(&info) || info.si_code == SI_LWP)) { 9945891Sraf do_sigcancel(); 9955891Sraf *self->ul_errnop = EINTR; 9965891Sraf sig = -1; 9975891Sraf } 9980Sstevel@tonic-gate } 9990Sstevel@tonic-gate EPILOGUE 10000Sstevel@tonic-gate if (sig != -1 && infop) 10016515Sraf (void) memcpy(infop, &info, sizeof (*infop)); 10020Sstevel@tonic-gate return (sig); 10030Sstevel@tonic-gate } 10040Sstevel@tonic-gate 10050Sstevel@tonic-gate int 10066812Sraf sigwait(sigset_t *set) 10070Sstevel@tonic-gate { 10086812Sraf return (sigtimedwait(set, NULL, NULL)); 10092248Sraf } 10102248Sraf 10112248Sraf int 10126812Sraf sigwaitinfo(const sigset_t *set, siginfo_t *info) 10132248Sraf { 10146812Sraf return (sigtimedwait(set, info, NULL)); 10152248Sraf } 10162248Sraf 10172248Sraf int 10186812Sraf sigqueue(pid_t pid, int signo, const union sigval value) 10192248Sraf { 10202248Sraf extern int __sigqueue(pid_t pid, int signo, 10214843Sraf /* const union sigval */ void *value, int si_code, int block); 10222248Sraf return (__sigqueue(pid, signo, value.sival_ptr, SI_QUEUE, 0)); 10230Sstevel@tonic-gate } 10240Sstevel@tonic-gate 10250Sstevel@tonic-gate int 10265891Sraf _so_accept(int sock, struct sockaddr *addr, uint_t *addrlen, int version) 10270Sstevel@tonic-gate { 10285891Sraf extern int __so_accept(int, struct sockaddr *, uint_t *, int); 10290Sstevel@tonic-gate int rv; 10300Sstevel@tonic-gate 10315891Sraf PERFORM(__so_accept(sock, addr, addrlen, version)) 10325891Sraf } 10335891Sraf 10345891Sraf int 10355891Sraf _so_connect(int sock, struct sockaddr *addr, uint_t addrlen, int version) 10365891Sraf { 10375891Sraf extern int __so_connect(int, struct sockaddr *, uint_t, int); 10385891Sraf int rv; 10395891Sraf 10405891Sraf PERFORM(__so_connect(sock, addr, addrlen, version)) 10410Sstevel@tonic-gate } 10420Sstevel@tonic-gate 10435891Sraf int 10445891Sraf _so_recv(int sock, void *buf, size_t len, int flags) 10450Sstevel@tonic-gate { 10465891Sraf extern int __so_recv(int, void *, size_t, int); 10475891Sraf int rv; 10480Sstevel@tonic-gate 10495891Sraf PERFORM(__so_recv(sock, buf, len, flags)) 10500Sstevel@tonic-gate } 10510Sstevel@tonic-gate 10525891Sraf int 10535891Sraf _so_recvfrom(int sock, void *buf, size_t len, int flags, 10545891Sraf struct sockaddr *addr, int *addrlen) 10550Sstevel@tonic-gate { 10565891Sraf extern int __so_recvfrom(int, void *, size_t, int, 10575891Sraf struct sockaddr *, int *); 10585891Sraf int rv; 10595891Sraf 10605891Sraf PERFORM(__so_recvfrom(sock, buf, len, flags, addr, addrlen)) 10615891Sraf } 10620Sstevel@tonic-gate 10635891Sraf int 10645891Sraf _so_recvmsg(int sock, struct msghdr *msg, int flags) 10655891Sraf { 10665891Sraf extern int __so_recvmsg(int, struct msghdr *, int); 10675891Sraf int rv; 10685891Sraf 10695891Sraf PERFORM(__so_recvmsg(sock, msg, flags)) 10700Sstevel@tonic-gate } 10710Sstevel@tonic-gate 10720Sstevel@tonic-gate int 10735891Sraf _so_send(int sock, const void *buf, size_t len, int flags) 10740Sstevel@tonic-gate { 10755891Sraf extern int __so_send(int, const void *, size_t, int); 10760Sstevel@tonic-gate int rv; 10770Sstevel@tonic-gate 10785891Sraf PERFORM(__so_send(sock, buf, len, flags)) 10795891Sraf } 10805891Sraf 10815891Sraf int 10825891Sraf _so_sendmsg(int sock, const struct msghdr *msg, int flags) 10835891Sraf { 10845891Sraf extern int __so_sendmsg(int, const struct msghdr *, int); 10855891Sraf int rv; 10865891Sraf 10875891Sraf PERFORM(__so_sendmsg(sock, msg, flags)) 10885891Sraf } 10895891Sraf 10905891Sraf int 10915891Sraf _so_sendto(int sock, const void *buf, size_t len, int flags, 10925891Sraf const struct sockaddr *addr, int *addrlen) 10935891Sraf { 10945891Sraf extern int __so_sendto(int, const void *, size_t, int, 10955891Sraf const struct sockaddr *, int *); 10965891Sraf int rv; 10975891Sraf 10985891Sraf PERFORM(__so_sendto(sock, buf, len, flags, addr, addrlen)) 10990Sstevel@tonic-gate } 11000Sstevel@tonic-gate 11015891Sraf int 11026812Sraf tcdrain(int fildes) 11030Sstevel@tonic-gate { 11045891Sraf extern int __tcdrain(int); 11055891Sraf int rv; 11060Sstevel@tonic-gate 11075891Sraf PERFORM(__tcdrain(fildes)) 11080Sstevel@tonic-gate } 11090Sstevel@tonic-gate 11105891Sraf int 11116812Sraf waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) 11125891Sraf { 11135891Sraf extern int __waitid(idtype_t, id_t, siginfo_t *, int); 11145891Sraf int rv; 11155891Sraf 11165891Sraf if (options & WNOHANG) 11175891Sraf return (__waitid(idtype, id, infop, options)); 11185891Sraf PERFORM(__waitid(idtype, id, infop, options)) 11195891Sraf } 11205891Sraf 11210Sstevel@tonic-gate ssize_t 11226812Sraf writev(int fildes, const struct iovec *iov, int iovcnt) 11230Sstevel@tonic-gate { 11245891Sraf extern ssize_t __writev(int, const struct iovec *, int); 11250Sstevel@tonic-gate ssize_t rv; 11260Sstevel@tonic-gate 11275891Sraf PERFORM(__writev(fildes, iov, iovcnt)) 11280Sstevel@tonic-gate } 1129