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 /* 239170SRoger.Faulkner@Sun.COM * Copyright 2009 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 */ 246*9264SRoger.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(); 324*9264SRoger.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 creat(const char *path, mode_t mode) 7310Sstevel@tonic-gate { 7325891Sraf extern int __creat(const char *, mode_t); 7330Sstevel@tonic-gate int rv; 7340Sstevel@tonic-gate 7355891Sraf PERFORM(__creat(path, mode)) 7360Sstevel@tonic-gate } 7370Sstevel@tonic-gate 7380Sstevel@tonic-gate #if !defined(_LP64) 7390Sstevel@tonic-gate int 7406812Sraf creat64(const char *path, mode_t mode) 7410Sstevel@tonic-gate { 7425891Sraf extern int __creat64(const char *, mode_t); 7430Sstevel@tonic-gate int rv; 7440Sstevel@tonic-gate 7455891Sraf PERFORM(__creat64(path, mode)) 7460Sstevel@tonic-gate } 7470Sstevel@tonic-gate #endif /* !_LP64 */ 7480Sstevel@tonic-gate 7490Sstevel@tonic-gate int 7506812Sraf door_call(int d, door_arg_t *params) 7510Sstevel@tonic-gate { 7525891Sraf extern int __door_call(int, door_arg_t *); 7535891Sraf int rv; 7545891Sraf 7555891Sraf PERFORM(__door_call(d, params)) 7565891Sraf } 7575891Sraf 7585891Sraf int 7596812Sraf fcntl(int fildes, int cmd, ...) 7605891Sraf { 7615891Sraf extern int __fcntl(int, int, ...); 7620Sstevel@tonic-gate intptr_t arg; 7630Sstevel@tonic-gate int rv; 7640Sstevel@tonic-gate va_list ap; 7650Sstevel@tonic-gate 7660Sstevel@tonic-gate va_start(ap, cmd); 7670Sstevel@tonic-gate arg = va_arg(ap, intptr_t); 7680Sstevel@tonic-gate va_end(ap); 7690Sstevel@tonic-gate if (cmd != F_SETLKW) 7705891Sraf return (__fcntl(fildes, cmd, arg)); 7715891Sraf PERFORM(__fcntl(fildes, cmd, arg)) 7720Sstevel@tonic-gate } 7730Sstevel@tonic-gate 7740Sstevel@tonic-gate int 7756812Sraf fdatasync(int fildes) 7764722Sraf { 7775891Sraf extern int __fdsync(int, int); 7784722Sraf int rv; 7794722Sraf 7805891Sraf PERFORM(__fdsync(fildes, FDSYNC)) 7814722Sraf } 7824722Sraf 7834722Sraf int 7846812Sraf fsync(int fildes) 7850Sstevel@tonic-gate { 7865891Sraf extern int __fdsync(int, int); 7870Sstevel@tonic-gate int rv; 7880Sstevel@tonic-gate 7895891Sraf PERFORM(__fdsync(fildes, FSYNC)) 7900Sstevel@tonic-gate } 7910Sstevel@tonic-gate 7920Sstevel@tonic-gate int 7936812Sraf lockf(int fildes, int function, off_t size) 7940Sstevel@tonic-gate { 7955891Sraf extern int __lockf(int, int, off_t); 7960Sstevel@tonic-gate int rv; 7970Sstevel@tonic-gate 7985891Sraf PERFORM(__lockf(fildes, function, size)) 7990Sstevel@tonic-gate } 8000Sstevel@tonic-gate 8010Sstevel@tonic-gate #if !defined(_LP64) 8020Sstevel@tonic-gate int 8036812Sraf lockf64(int fildes, int function, off64_t size) 8040Sstevel@tonic-gate { 8055891Sraf extern int __lockf64(int, int, off64_t); 8060Sstevel@tonic-gate int rv; 8070Sstevel@tonic-gate 8085891Sraf PERFORM(__lockf64(fildes, function, size)) 8090Sstevel@tonic-gate } 8100Sstevel@tonic-gate #endif /* !_LP64 */ 8110Sstevel@tonic-gate 8120Sstevel@tonic-gate ssize_t 8136812Sraf msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg) 8140Sstevel@tonic-gate { 8155891Sraf extern ssize_t __msgrcv(int, void *, size_t, long, int); 8160Sstevel@tonic-gate ssize_t rv; 8170Sstevel@tonic-gate 8185891Sraf PERFORM(__msgrcv(msqid, msgp, msgsz, msgtyp, msgflg)) 8190Sstevel@tonic-gate } 8200Sstevel@tonic-gate 8210Sstevel@tonic-gate int 8226812Sraf msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg) 8230Sstevel@tonic-gate { 8245891Sraf extern int __msgsnd(int, const void *, size_t, int); 8250Sstevel@tonic-gate int rv; 8260Sstevel@tonic-gate 8275891Sraf PERFORM(__msgsnd(msqid, msgp, msgsz, msgflg)) 8285891Sraf } 8295891Sraf 8305891Sraf int 8316812Sraf msync(caddr_t addr, size_t len, int flags) 8325891Sraf { 8335891Sraf extern int __msync(caddr_t, size_t, int); 8345891Sraf int rv; 8355891Sraf 8365891Sraf PERFORM(__msync(addr, len, flags)) 8370Sstevel@tonic-gate } 8380Sstevel@tonic-gate 8390Sstevel@tonic-gate int 8406812Sraf open(const char *path, int oflag, ...) 8410Sstevel@tonic-gate { 8425891Sraf extern int __open(const char *, int, ...); 8435891Sraf mode_t mode; 8440Sstevel@tonic-gate int rv; 8455891Sraf va_list ap; 8460Sstevel@tonic-gate 8475891Sraf va_start(ap, oflag); 8485891Sraf mode = va_arg(ap, mode_t); 8495891Sraf va_end(ap); 8505891Sraf PERFORM(__open(path, oflag, mode)) 8510Sstevel@tonic-gate } 8520Sstevel@tonic-gate 8530Sstevel@tonic-gate int 8546812Sraf openat(int fd, const char *path, int oflag, ...) 8550Sstevel@tonic-gate { 8565891Sraf extern int __openat(int, const char *, int, ...); 8570Sstevel@tonic-gate mode_t mode; 8580Sstevel@tonic-gate int rv; 8590Sstevel@tonic-gate va_list ap; 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate va_start(ap, oflag); 8620Sstevel@tonic-gate mode = va_arg(ap, mode_t); 8630Sstevel@tonic-gate va_end(ap); 8645891Sraf PERFORM(__openat(fd, path, oflag, mode)) 8650Sstevel@tonic-gate } 8660Sstevel@tonic-gate 8670Sstevel@tonic-gate #if !defined(_LP64) 8680Sstevel@tonic-gate int 8696812Sraf open64(const char *path, int oflag, ...) 8700Sstevel@tonic-gate { 8715891Sraf extern int __open64(const char *, int, ...); 8725891Sraf mode_t mode; 8735891Sraf int rv; 8745891Sraf va_list ap; 8755891Sraf 8765891Sraf va_start(ap, oflag); 8775891Sraf mode = va_arg(ap, mode_t); 8785891Sraf va_end(ap); 8795891Sraf PERFORM(__open64(path, oflag, mode)) 8805891Sraf } 8815891Sraf 8825891Sraf int 8836812Sraf openat64(int fd, const char *path, int oflag, ...) 8845891Sraf { 8855891Sraf extern int __openat64(int, const char *, int, ...); 8860Sstevel@tonic-gate mode_t mode; 8870Sstevel@tonic-gate int rv; 8880Sstevel@tonic-gate va_list ap; 8890Sstevel@tonic-gate 8900Sstevel@tonic-gate va_start(ap, oflag); 8910Sstevel@tonic-gate mode = va_arg(ap, mode_t); 8920Sstevel@tonic-gate va_end(ap); 8935891Sraf PERFORM(__openat64(fd, path, oflag, mode)) 8940Sstevel@tonic-gate } 8950Sstevel@tonic-gate #endif /* !_LP64 */ 8960Sstevel@tonic-gate 8970Sstevel@tonic-gate int 8986812Sraf pause(void) 8990Sstevel@tonic-gate { 9005891Sraf extern int __pause(void); 9010Sstevel@tonic-gate int rv; 9020Sstevel@tonic-gate 9035891Sraf PERFORM(__pause()) 9040Sstevel@tonic-gate } 9050Sstevel@tonic-gate 9060Sstevel@tonic-gate ssize_t 9076812Sraf pread(int fildes, void *buf, size_t nbyte, off_t offset) 9080Sstevel@tonic-gate { 9095891Sraf extern ssize_t __pread(int, void *, size_t, off_t); 9100Sstevel@tonic-gate ssize_t rv; 9110Sstevel@tonic-gate 9125891Sraf PERFORM(__pread(fildes, buf, nbyte, offset)) 9130Sstevel@tonic-gate } 9140Sstevel@tonic-gate 9150Sstevel@tonic-gate #if !defined(_LP64) 9160Sstevel@tonic-gate ssize_t 9176812Sraf pread64(int fildes, void *buf, size_t nbyte, off64_t offset) 9180Sstevel@tonic-gate { 9195891Sraf extern ssize_t __pread64(int, void *, size_t, off64_t); 9200Sstevel@tonic-gate ssize_t rv; 9210Sstevel@tonic-gate 9225891Sraf PERFORM(__pread64(fildes, buf, nbyte, offset)) 9230Sstevel@tonic-gate } 9240Sstevel@tonic-gate #endif /* !_LP64 */ 9250Sstevel@tonic-gate 9260Sstevel@tonic-gate ssize_t 9276812Sraf pwrite(int fildes, const void *buf, size_t nbyte, off_t offset) 9280Sstevel@tonic-gate { 9295891Sraf extern ssize_t __pwrite(int, const void *, size_t, off_t); 9300Sstevel@tonic-gate ssize_t rv; 9310Sstevel@tonic-gate 9325891Sraf PERFORM(__pwrite(fildes, buf, nbyte, offset)) 9330Sstevel@tonic-gate } 9340Sstevel@tonic-gate 9350Sstevel@tonic-gate #if !defined(_LP64) 9360Sstevel@tonic-gate ssize_t 9376812Sraf pwrite64(int fildes, const void *buf, size_t nbyte, off64_t offset) 9380Sstevel@tonic-gate { 9395891Sraf extern ssize_t __pwrite64(int, const void *, size_t, off64_t); 9400Sstevel@tonic-gate ssize_t rv; 9410Sstevel@tonic-gate 9425891Sraf PERFORM(__pwrite64(fildes, buf, nbyte, offset)) 9430Sstevel@tonic-gate } 9440Sstevel@tonic-gate #endif /* !_LP64 */ 9450Sstevel@tonic-gate 9460Sstevel@tonic-gate ssize_t 9476812Sraf readv(int fildes, const struct iovec *iov, int iovcnt) 9480Sstevel@tonic-gate { 9495891Sraf extern ssize_t __readv(int, const struct iovec *, int); 9500Sstevel@tonic-gate ssize_t rv; 9510Sstevel@tonic-gate 9525891Sraf PERFORM(__readv(fildes, iov, iovcnt)) 9530Sstevel@tonic-gate } 9540Sstevel@tonic-gate 9550Sstevel@tonic-gate int 9566812Sraf sigpause(int sig) 9570Sstevel@tonic-gate { 9585891Sraf extern int __sigpause(int); 9590Sstevel@tonic-gate int rv; 9600Sstevel@tonic-gate 9615891Sraf PERFORM(__sigpause(sig)) 9620Sstevel@tonic-gate } 9630Sstevel@tonic-gate 9640Sstevel@tonic-gate int 9656812Sraf sigsuspend(const sigset_t *set) 9660Sstevel@tonic-gate { 9670Sstevel@tonic-gate extern int __sigsuspend(const sigset_t *); 9680Sstevel@tonic-gate int rv; 9690Sstevel@tonic-gate 9700Sstevel@tonic-gate PROLOGUE_MASK(set) 9710Sstevel@tonic-gate rv = __sigsuspend(set); 9720Sstevel@tonic-gate EPILOGUE_MASK 9730Sstevel@tonic-gate return (rv); 9740Sstevel@tonic-gate } 9750Sstevel@tonic-gate 9760Sstevel@tonic-gate int 9770Sstevel@tonic-gate _pollsys(struct pollfd *fds, nfds_t nfd, const timespec_t *timeout, 9780Sstevel@tonic-gate const sigset_t *sigmask) 9790Sstevel@tonic-gate { 9800Sstevel@tonic-gate extern int __pollsys(struct pollfd *, nfds_t, const timespec_t *, 9814843Sraf const sigset_t *); 9820Sstevel@tonic-gate int rv; 9830Sstevel@tonic-gate 9840Sstevel@tonic-gate PROLOGUE_MASK(sigmask) 9850Sstevel@tonic-gate rv = __pollsys(fds, nfd, timeout, sigmask); 9860Sstevel@tonic-gate EPILOGUE_MASK 9870Sstevel@tonic-gate return (rv); 9880Sstevel@tonic-gate } 9890Sstevel@tonic-gate 9900Sstevel@tonic-gate int 9916812Sraf sigtimedwait(const sigset_t *set, siginfo_t *infop, const timespec_t *timeout) 9920Sstevel@tonic-gate { 9932248Sraf extern int __sigtimedwait(const sigset_t *, siginfo_t *, 9944843Sraf const timespec_t *); 9950Sstevel@tonic-gate siginfo_t info; 9960Sstevel@tonic-gate int sig; 9970Sstevel@tonic-gate 9980Sstevel@tonic-gate PROLOGUE 9995891Sraf if (abort) { 10005891Sraf *self->ul_errnop = EINTR; 10010Sstevel@tonic-gate sig = -1; 10025891Sraf } else { 10035891Sraf sig = __sigtimedwait(set, &info, timeout); 10045891Sraf if (sig == SIGCANCEL && 10055891Sraf (SI_FROMKERNEL(&info) || info.si_code == SI_LWP)) { 10065891Sraf do_sigcancel(); 10075891Sraf *self->ul_errnop = EINTR; 10085891Sraf sig = -1; 10095891Sraf } 10100Sstevel@tonic-gate } 10110Sstevel@tonic-gate EPILOGUE 10120Sstevel@tonic-gate if (sig != -1 && infop) 10136515Sraf (void) memcpy(infop, &info, sizeof (*infop)); 10140Sstevel@tonic-gate return (sig); 10150Sstevel@tonic-gate } 10160Sstevel@tonic-gate 10170Sstevel@tonic-gate int 10186812Sraf sigwait(sigset_t *set) 10190Sstevel@tonic-gate { 10206812Sraf return (sigtimedwait(set, NULL, NULL)); 10212248Sraf } 10222248Sraf 10232248Sraf int 10246812Sraf sigwaitinfo(const sigset_t *set, siginfo_t *info) 10252248Sraf { 10266812Sraf return (sigtimedwait(set, info, NULL)); 10272248Sraf } 10282248Sraf 10292248Sraf int 10306812Sraf sigqueue(pid_t pid, int signo, const union sigval value) 10312248Sraf { 10322248Sraf extern int __sigqueue(pid_t pid, int signo, 10334843Sraf /* const union sigval */ void *value, int si_code, int block); 10342248Sraf return (__sigqueue(pid, signo, value.sival_ptr, SI_QUEUE, 0)); 10350Sstevel@tonic-gate } 10360Sstevel@tonic-gate 10370Sstevel@tonic-gate int 10385891Sraf _so_accept(int sock, struct sockaddr *addr, uint_t *addrlen, int version) 10390Sstevel@tonic-gate { 10405891Sraf extern int __so_accept(int, struct sockaddr *, uint_t *, int); 10410Sstevel@tonic-gate int rv; 10420Sstevel@tonic-gate 10435891Sraf PERFORM(__so_accept(sock, addr, addrlen, version)) 10445891Sraf } 10455891Sraf 10465891Sraf int 10475891Sraf _so_connect(int sock, struct sockaddr *addr, uint_t addrlen, int version) 10485891Sraf { 10495891Sraf extern int __so_connect(int, struct sockaddr *, uint_t, int); 10505891Sraf int rv; 10515891Sraf 10525891Sraf PERFORM(__so_connect(sock, addr, addrlen, version)) 10530Sstevel@tonic-gate } 10540Sstevel@tonic-gate 10555891Sraf int 10565891Sraf _so_recv(int sock, void *buf, size_t len, int flags) 10570Sstevel@tonic-gate { 10585891Sraf extern int __so_recv(int, void *, size_t, int); 10595891Sraf int rv; 10600Sstevel@tonic-gate 10615891Sraf PERFORM(__so_recv(sock, buf, len, flags)) 10620Sstevel@tonic-gate } 10630Sstevel@tonic-gate 10645891Sraf int 10655891Sraf _so_recvfrom(int sock, void *buf, size_t len, int flags, 10665891Sraf struct sockaddr *addr, int *addrlen) 10670Sstevel@tonic-gate { 10685891Sraf extern int __so_recvfrom(int, void *, size_t, int, 10695891Sraf struct sockaddr *, int *); 10705891Sraf int rv; 10715891Sraf 10725891Sraf PERFORM(__so_recvfrom(sock, buf, len, flags, addr, addrlen)) 10735891Sraf } 10740Sstevel@tonic-gate 10755891Sraf int 10765891Sraf _so_recvmsg(int sock, struct msghdr *msg, int flags) 10775891Sraf { 10785891Sraf extern int __so_recvmsg(int, struct msghdr *, int); 10795891Sraf int rv; 10805891Sraf 10815891Sraf PERFORM(__so_recvmsg(sock, msg, flags)) 10820Sstevel@tonic-gate } 10830Sstevel@tonic-gate 10840Sstevel@tonic-gate int 10855891Sraf _so_send(int sock, const void *buf, size_t len, int flags) 10860Sstevel@tonic-gate { 10875891Sraf extern int __so_send(int, const void *, size_t, int); 10880Sstevel@tonic-gate int rv; 10890Sstevel@tonic-gate 10905891Sraf PERFORM(__so_send(sock, buf, len, flags)) 10915891Sraf } 10925891Sraf 10935891Sraf int 10945891Sraf _so_sendmsg(int sock, const struct msghdr *msg, int flags) 10955891Sraf { 10965891Sraf extern int __so_sendmsg(int, const struct msghdr *, int); 10975891Sraf int rv; 10985891Sraf 10995891Sraf PERFORM(__so_sendmsg(sock, msg, flags)) 11005891Sraf } 11015891Sraf 11025891Sraf int 11035891Sraf _so_sendto(int sock, const void *buf, size_t len, int flags, 11045891Sraf const struct sockaddr *addr, int *addrlen) 11055891Sraf { 11065891Sraf extern int __so_sendto(int, const void *, size_t, int, 11075891Sraf const struct sockaddr *, int *); 11085891Sraf int rv; 11095891Sraf 11105891Sraf PERFORM(__so_sendto(sock, buf, len, flags, addr, addrlen)) 11110Sstevel@tonic-gate } 11120Sstevel@tonic-gate 11135891Sraf int 11146812Sraf tcdrain(int fildes) 11150Sstevel@tonic-gate { 11165891Sraf extern int __tcdrain(int); 11175891Sraf int rv; 11180Sstevel@tonic-gate 11195891Sraf PERFORM(__tcdrain(fildes)) 11200Sstevel@tonic-gate } 11210Sstevel@tonic-gate 11225891Sraf int 11236812Sraf waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) 11245891Sraf { 11255891Sraf extern int __waitid(idtype_t, id_t, siginfo_t *, int); 11265891Sraf int rv; 11275891Sraf 11285891Sraf if (options & WNOHANG) 11295891Sraf return (__waitid(idtype, id, infop, options)); 11305891Sraf PERFORM(__waitid(idtype, id, infop, options)) 11315891Sraf } 11325891Sraf 11330Sstevel@tonic-gate ssize_t 11346812Sraf writev(int fildes, const struct iovec *iov, int iovcnt) 11350Sstevel@tonic-gate { 11365891Sraf extern ssize_t __writev(int, const struct iovec *, int); 11370Sstevel@tonic-gate ssize_t rv; 11380Sstevel@tonic-gate 11395891Sraf PERFORM(__writev(fildes, iov, iovcnt)) 11400Sstevel@tonic-gate } 1141