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 /* 235891Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include "lint.h" 300Sstevel@tonic-gate #include "thr_uberdata.h" 310Sstevel@tonic-gate #include <stdarg.h> 320Sstevel@tonic-gate #include <poll.h> 330Sstevel@tonic-gate #include <stropts.h> 340Sstevel@tonic-gate #include <dlfcn.h> 355891Sraf #include <wait.h> 365891Sraf #include <sys/socket.h> 370Sstevel@tonic-gate #include <sys/uio.h> 385891Sraf #include <sys/file.h> 395891Sraf #include <sys/door.h> 400Sstevel@tonic-gate 410Sstevel@tonic-gate /* 42*6812Sraf * These leading-underbar symbols exist because mistakes were made 43*6812Sraf * in the past that put them into non-SUNWprivate versions of 44*6812Sraf * the libc mapfiles. They should be eliminated, but oh well... 45*6812Sraf */ 46*6812Sraf #pragma weak _fork = fork 47*6812Sraf #pragma weak _read = read 48*6812Sraf #pragma weak _write = write 49*6812Sraf #pragma weak _getmsg = getmsg 50*6812Sraf #pragma weak _getpmsg = getpmsg 51*6812Sraf #pragma weak _putmsg = putmsg 52*6812Sraf #pragma weak _putpmsg = putpmsg 53*6812Sraf #pragma weak _sleep = sleep 54*6812Sraf #pragma weak _close = close 55*6812Sraf #pragma weak _creat = creat 56*6812Sraf #pragma weak _fcntl = fcntl 57*6812Sraf #pragma weak _fsync = fsync 58*6812Sraf #pragma weak _lockf = lockf 59*6812Sraf #pragma weak _msgrcv = msgrcv 60*6812Sraf #pragma weak _msgsnd = msgsnd 61*6812Sraf #pragma weak _msync = msync 62*6812Sraf #pragma weak _open = open 63*6812Sraf #pragma weak _openat = openat 64*6812Sraf #pragma weak _pause = pause 65*6812Sraf #pragma weak _readv = readv 66*6812Sraf #pragma weak _sigpause = sigpause 67*6812Sraf #pragma weak _sigsuspend = sigsuspend 68*6812Sraf #pragma weak _tcdrain = tcdrain 69*6812Sraf #pragma weak _waitid = waitid 70*6812Sraf #pragma weak _writev = writev 71*6812Sraf 72*6812Sraf #if !defined(_LP64) 73*6812Sraf #pragma weak _creat64 = creat64 74*6812Sraf #pragma weak _lockf64 = lockf64 75*6812Sraf #pragma weak _open64 = open64 76*6812Sraf #pragma weak _openat64 = openat64 77*6812Sraf #pragma weak _pread64 = pread64 78*6812Sraf #pragma weak _pwrite64 = pwrite64 79*6812Sraf #endif 80*6812Sraf 81*6812Sraf /* 825002Sraf * atfork_lock protects the pthread_atfork() data structures. 835002Sraf * 844914Sraf * fork_lock does double-duty. Not only does it (and atfork_lock) 854914Sraf * serialize calls to fork() and forkall(), but it also serializes calls 864914Sraf * to thr_suspend() and thr_continue() (because fork() and forkall() also 874914Sraf * suspend and continue other threads and they want no competition). 884914Sraf * 895002Sraf * Functions called in dlopen()ed L10N objects can do anything, including 905002Sraf * call malloc() and free(). Such calls are not fork-safe when protected 915002Sraf * by an ordinary mutex that is acquired in libc's prefork processing 925002Sraf * because, with an interposed malloc library present, there would be a 935002Sraf * lock ordering violation due to the pthread_atfork() prefork function 945002Sraf * in the interposition library acquiring its malloc lock(s) before the 954914Sraf * ordinary mutex in libc being acquired by libc's prefork functions. 964914Sraf * 975002Sraf * Within libc, calls to malloc() and free() are fork-safe if the calls 985002Sraf * are made while holding no other libc locks. This covers almost all 995002Sraf * of libc's malloc() and free() calls. For those libc code paths, such 1005002Sraf * as the above-mentioned L10N calls, that require serialization and that 1015002Sraf * may call malloc() or free(), libc uses callout_lock_enter() to perform 1025002Sraf * the serialization. This works because callout_lock is not acquired as 1035002Sraf * part of running the pthread_atfork() prefork handlers (to avoid the 1045002Sraf * lock ordering violation described above). Rather, it is simply 1055002Sraf * reinitialized in postfork1_child() to cover the case that some 1065002Sraf * now-defunct thread might have been suspended while holding it. 1070Sstevel@tonic-gate */ 1084914Sraf 1094843Sraf void 1104843Sraf fork_lock_enter(void) 1110Sstevel@tonic-gate { 1124914Sraf ASSERT(curthread->ul_critical == 0); 1136515Sraf (void) mutex_lock(&curthread->ul_uberdata->fork_lock); 1140Sstevel@tonic-gate } 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate void 1170Sstevel@tonic-gate fork_lock_exit(void) 1180Sstevel@tonic-gate { 1194914Sraf ASSERT(curthread->ul_critical == 0); 1206515Sraf (void) mutex_unlock(&curthread->ul_uberdata->fork_lock); 1214914Sraf } 1220Sstevel@tonic-gate 1235891Sraf /* 1245891Sraf * Use cancel_safe_mutex_lock() to protect against being cancelled while 1255891Sraf * holding callout_lock and calling outside of libc (via L10N plugins). 1265891Sraf * We will honor a pending cancellation request when callout_lock_exit() 1275891Sraf * is called, by calling cancel_safe_mutex_unlock(). 1285891Sraf */ 1294914Sraf void 1305002Sraf callout_lock_enter(void) 1314914Sraf { 1324914Sraf ASSERT(curthread->ul_critical == 0); 1335891Sraf cancel_safe_mutex_lock(&curthread->ul_uberdata->callout_lock); 1344914Sraf } 1354914Sraf 1364914Sraf void 1375002Sraf callout_lock_exit(void) 1384914Sraf { 1394914Sraf ASSERT(curthread->ul_critical == 0); 1405891Sraf cancel_safe_mutex_unlock(&curthread->ul_uberdata->callout_lock); 1410Sstevel@tonic-gate } 1420Sstevel@tonic-gate 1434292Sab196087 pid_t 144*6812Sraf forkx(int flags) 1450Sstevel@tonic-gate { 1460Sstevel@tonic-gate ulwp_t *self = curthread; 1470Sstevel@tonic-gate uberdata_t *udp = self->ul_uberdata; 1480Sstevel@tonic-gate pid_t pid; 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate if (self->ul_vfork) { 1510Sstevel@tonic-gate /* 1520Sstevel@tonic-gate * We are a child of vfork(); omit all of the fork 1530Sstevel@tonic-gate * logic and go straight to the system call trap. 1540Sstevel@tonic-gate * A vfork() child of a multithreaded parent 1550Sstevel@tonic-gate * must never call fork(). 1560Sstevel@tonic-gate */ 1570Sstevel@tonic-gate if (udp->uberflags.uf_mt) { 1580Sstevel@tonic-gate errno = ENOTSUP; 1590Sstevel@tonic-gate return (-1); 1600Sstevel@tonic-gate } 1613235Sraf pid = __forkx(flags); 1620Sstevel@tonic-gate if (pid == 0) { /* child */ 1636515Sraf udp->pid = getpid(); 1640Sstevel@tonic-gate self->ul_vfork = 0; 1650Sstevel@tonic-gate } 1660Sstevel@tonic-gate return (pid); 1670Sstevel@tonic-gate } 1680Sstevel@tonic-gate 1694843Sraf sigoff(self); 1704843Sraf if (self->ul_fork) { 1710Sstevel@tonic-gate /* 1720Sstevel@tonic-gate * Cannot call fork() from a fork handler. 1730Sstevel@tonic-gate */ 1744843Sraf sigon(self); 1754843Sraf errno = EDEADLK; 1760Sstevel@tonic-gate return (-1); 1770Sstevel@tonic-gate } 1780Sstevel@tonic-gate self->ul_fork = 1; 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate /* 1810Sstevel@tonic-gate * The functions registered by pthread_atfork() are defined by 1820Sstevel@tonic-gate * the application and its libraries and we must not hold any 1834843Sraf * internal lmutex_lock()-acquired locks while invoking them. 1844843Sraf * We hold only udp->atfork_lock to protect the atfork linkages. 1854843Sraf * If one of these pthread_atfork() functions attempts to fork 1864914Sraf * or to call pthread_atfork(), libc will detect the error and 1874914Sraf * fail the call with EDEADLK. Otherwise, the pthread_atfork() 1884914Sraf * functions are free to do anything they please (except they 1894914Sraf * will not receive any signals). 1900Sstevel@tonic-gate */ 1916515Sraf (void) mutex_lock(&udp->atfork_lock); 1920Sstevel@tonic-gate _prefork_handler(); 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate /* 1954843Sraf * Block every other thread attempting thr_suspend() or thr_continue(). 1964843Sraf */ 1976515Sraf (void) mutex_lock(&udp->fork_lock); 1984843Sraf 1994843Sraf /* 2000Sstevel@tonic-gate * Block all signals. 2014843Sraf * Just deferring them via sigoff() is not enough. 2020Sstevel@tonic-gate * We have to avoid taking a deferred signal in the child 2033235Sraf * that was actually sent to the parent before __forkx(). 2040Sstevel@tonic-gate */ 2050Sstevel@tonic-gate block_all_signals(self); 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate /* 2080Sstevel@tonic-gate * This suspends all threads but this one, leaving them 2090Sstevel@tonic-gate * suspended outside of any critical regions in the library. 2104914Sraf * Thus, we are assured that no lmutex_lock()-acquired library 2114914Sraf * locks are held while we invoke fork() from the current thread. 2120Sstevel@tonic-gate */ 2130Sstevel@tonic-gate suspend_fork(); 2140Sstevel@tonic-gate 2153235Sraf pid = __forkx(flags); 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate if (pid == 0) { /* child */ 2180Sstevel@tonic-gate /* 2190Sstevel@tonic-gate * Clear our schedctl pointer. 2200Sstevel@tonic-gate * Discard any deferred signal that was sent to the parent. 2213235Sraf * Because we blocked all signals before __forkx(), a 2220Sstevel@tonic-gate * deferred signal cannot have been taken by the child. 2230Sstevel@tonic-gate */ 2240Sstevel@tonic-gate self->ul_schedctl_called = NULL; 2250Sstevel@tonic-gate self->ul_schedctl = NULL; 2260Sstevel@tonic-gate self->ul_cursig = 0; 2270Sstevel@tonic-gate self->ul_siginfo.si_signo = 0; 2286515Sraf udp->pid = getpid(); 2290Sstevel@tonic-gate /* reset the library's data structures to reflect one thread */ 2304574Sraf unregister_locks(); 2312248Sraf postfork1_child(); 2320Sstevel@tonic-gate restore_signals(self); 2336515Sraf (void) mutex_unlock(&udp->fork_lock); 2340Sstevel@tonic-gate _postfork_child_handler(); 2350Sstevel@tonic-gate } else { 2363235Sraf /* restart all threads that were suspended for fork() */ 2370Sstevel@tonic-gate continue_fork(0); 2380Sstevel@tonic-gate restore_signals(self); 2396515Sraf (void) mutex_unlock(&udp->fork_lock); 2400Sstevel@tonic-gate _postfork_parent_handler(); 2410Sstevel@tonic-gate } 2420Sstevel@tonic-gate 2436515Sraf (void) mutex_unlock(&udp->atfork_lock); 2440Sstevel@tonic-gate self->ul_fork = 0; 2454843Sraf sigon(self); 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate return (pid); 2480Sstevel@tonic-gate } 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate /* 2513235Sraf * fork() is fork1() for both Posix threads and Solaris threads. 2523235Sraf * The forkall() interface exists for applications that require 2533235Sraf * the semantics of replicating all threads. 2540Sstevel@tonic-gate */ 255*6812Sraf #pragma weak fork1 = fork 2560Sstevel@tonic-gate pid_t 257*6812Sraf fork(void) 2583235Sraf { 259*6812Sraf return (forkx(0)); 2603235Sraf } 2613235Sraf 2623235Sraf /* 2633235Sraf * Much of the logic here is the same as in forkx(). 2643235Sraf * See the comments in forkx(), above. 2653235Sraf */ 2664292Sab196087 pid_t 267*6812Sraf forkallx(int flags) 2680Sstevel@tonic-gate { 2690Sstevel@tonic-gate ulwp_t *self = curthread; 2700Sstevel@tonic-gate uberdata_t *udp = self->ul_uberdata; 2710Sstevel@tonic-gate pid_t pid; 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate if (self->ul_vfork) { 2740Sstevel@tonic-gate if (udp->uberflags.uf_mt) { 2750Sstevel@tonic-gate errno = ENOTSUP; 2760Sstevel@tonic-gate return (-1); 2770Sstevel@tonic-gate } 2783235Sraf pid = __forkallx(flags); 2790Sstevel@tonic-gate if (pid == 0) { /* child */ 2806515Sraf udp->pid = getpid(); 2810Sstevel@tonic-gate self->ul_vfork = 0; 2820Sstevel@tonic-gate } 2830Sstevel@tonic-gate return (pid); 2840Sstevel@tonic-gate } 2850Sstevel@tonic-gate 2864843Sraf sigoff(self); 2874843Sraf if (self->ul_fork) { 2884843Sraf sigon(self); 2894843Sraf errno = EDEADLK; 2900Sstevel@tonic-gate return (-1); 2910Sstevel@tonic-gate } 2920Sstevel@tonic-gate self->ul_fork = 1; 2936515Sraf (void) mutex_lock(&udp->atfork_lock); 2946515Sraf (void) mutex_lock(&udp->fork_lock); 2950Sstevel@tonic-gate block_all_signals(self); 2960Sstevel@tonic-gate suspend_fork(); 2970Sstevel@tonic-gate 2983235Sraf pid = __forkallx(flags); 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate if (pid == 0) { 3010Sstevel@tonic-gate self->ul_schedctl_called = NULL; 3020Sstevel@tonic-gate self->ul_schedctl = NULL; 3030Sstevel@tonic-gate self->ul_cursig = 0; 3040Sstevel@tonic-gate self->ul_siginfo.si_signo = 0; 3056515Sraf udp->pid = getpid(); 3064574Sraf unregister_locks(); 3070Sstevel@tonic-gate continue_fork(1); 3080Sstevel@tonic-gate } else { 3090Sstevel@tonic-gate continue_fork(0); 3100Sstevel@tonic-gate } 3110Sstevel@tonic-gate restore_signals(self); 3126515Sraf (void) mutex_unlock(&udp->fork_lock); 3136515Sraf (void) mutex_unlock(&udp->atfork_lock); 3140Sstevel@tonic-gate self->ul_fork = 0; 3154843Sraf sigon(self); 3160Sstevel@tonic-gate 3170Sstevel@tonic-gate return (pid); 3180Sstevel@tonic-gate } 3190Sstevel@tonic-gate 3203235Sraf pid_t 321*6812Sraf forkall(void) 3223235Sraf { 323*6812Sraf return (forkallx(0)); 3243235Sraf } 3253235Sraf 3260Sstevel@tonic-gate /* 3275891Sraf * For the implementation of cancellation at cancellation points. 3280Sstevel@tonic-gate */ 3290Sstevel@tonic-gate #define PROLOGUE \ 3300Sstevel@tonic-gate { \ 3310Sstevel@tonic-gate ulwp_t *self = curthread; \ 3325891Sraf int nocancel = \ 3335891Sraf (self->ul_vfork | self->ul_nocancel | self->ul_libc_locks | \ 3345891Sraf self->ul_critical | self->ul_sigdefer); \ 3355891Sraf int abort = 0; \ 3360Sstevel@tonic-gate if (nocancel == 0) { \ 3370Sstevel@tonic-gate self->ul_save_async = self->ul_cancel_async; \ 3380Sstevel@tonic-gate if (!self->ul_cancel_disabled) { \ 3390Sstevel@tonic-gate self->ul_cancel_async = 1; \ 3400Sstevel@tonic-gate if (self->ul_cancel_pending) \ 341*6812Sraf pthread_exit(PTHREAD_CANCELED); \ 3420Sstevel@tonic-gate } \ 3430Sstevel@tonic-gate self->ul_sp = stkptr(); \ 3445891Sraf } else if (self->ul_cancel_pending && \ 3455891Sraf !self->ul_cancel_disabled) { \ 3465891Sraf set_cancel_eintr_flag(self); \ 3475891Sraf abort = 1; \ 3480Sstevel@tonic-gate } 3490Sstevel@tonic-gate 3500Sstevel@tonic-gate #define EPILOGUE \ 3510Sstevel@tonic-gate if (nocancel == 0) { \ 3520Sstevel@tonic-gate self->ul_sp = 0; \ 3530Sstevel@tonic-gate self->ul_cancel_async = self->ul_save_async; \ 3540Sstevel@tonic-gate } \ 3550Sstevel@tonic-gate } 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate /* 3580Sstevel@tonic-gate * Perform the body of the action required by most of the cancelable 3590Sstevel@tonic-gate * function calls. The return(function_call) part is to allow the 3600Sstevel@tonic-gate * compiler to make the call be executed with tail recursion, which 3610Sstevel@tonic-gate * saves a register window on sparc and slightly (not much) improves 3620Sstevel@tonic-gate * the code for x86/x64 compilations. 3630Sstevel@tonic-gate */ 3640Sstevel@tonic-gate #define PERFORM(function_call) \ 3650Sstevel@tonic-gate PROLOGUE \ 3665891Sraf if (abort) { \ 3675891Sraf *self->ul_errnop = EINTR; \ 3685891Sraf return (-1); \ 3695891Sraf } \ 3700Sstevel@tonic-gate if (nocancel) \ 3710Sstevel@tonic-gate return (function_call); \ 3720Sstevel@tonic-gate rv = function_call; \ 3730Sstevel@tonic-gate EPILOGUE \ 3740Sstevel@tonic-gate return (rv); 3750Sstevel@tonic-gate 3760Sstevel@tonic-gate /* 3770Sstevel@tonic-gate * Specialized prologue for sigsuspend() and pollsys(). 3780Sstevel@tonic-gate * These system calls pass a signal mask to the kernel. 3790Sstevel@tonic-gate * The kernel replaces the thread's signal mask with the 3800Sstevel@tonic-gate * temporary mask before the thread goes to sleep. If 3810Sstevel@tonic-gate * a signal is received, the signal handler will execute 3820Sstevel@tonic-gate * with the temporary mask, as modified by the sigaction 3830Sstevel@tonic-gate * for the particular signal. 3840Sstevel@tonic-gate * 3850Sstevel@tonic-gate * We block all signals until we reach the kernel with the 3860Sstevel@tonic-gate * temporary mask. This eliminates race conditions with 3870Sstevel@tonic-gate * setting the signal mask while signals are being posted. 3880Sstevel@tonic-gate */ 3890Sstevel@tonic-gate #define PROLOGUE_MASK(sigmask) \ 3900Sstevel@tonic-gate { \ 3910Sstevel@tonic-gate ulwp_t *self = curthread; \ 3925891Sraf int nocancel = \ 3935891Sraf (self->ul_vfork | self->ul_nocancel | self->ul_libc_locks | \ 3945891Sraf self->ul_critical | self->ul_sigdefer); \ 3950Sstevel@tonic-gate if (!self->ul_vfork) { \ 3960Sstevel@tonic-gate if (sigmask) { \ 3970Sstevel@tonic-gate block_all_signals(self); \ 3981111Sraf self->ul_tmpmask.__sigbits[0] = sigmask->__sigbits[0]; \ 3991111Sraf self->ul_tmpmask.__sigbits[1] = sigmask->__sigbits[1]; \ 4000Sstevel@tonic-gate delete_reserved_signals(&self->ul_tmpmask); \ 4010Sstevel@tonic-gate self->ul_sigsuspend = 1; \ 4020Sstevel@tonic-gate } \ 4030Sstevel@tonic-gate if (nocancel == 0) { \ 4040Sstevel@tonic-gate self->ul_save_async = self->ul_cancel_async; \ 4050Sstevel@tonic-gate if (!self->ul_cancel_disabled) { \ 4060Sstevel@tonic-gate self->ul_cancel_async = 1; \ 4070Sstevel@tonic-gate if (self->ul_cancel_pending) { \ 4080Sstevel@tonic-gate if (self->ul_sigsuspend) { \ 4090Sstevel@tonic-gate self->ul_sigsuspend = 0;\ 4100Sstevel@tonic-gate restore_signals(self); \ 4110Sstevel@tonic-gate } \ 412*6812Sraf pthread_exit(PTHREAD_CANCELED); \ 4130Sstevel@tonic-gate } \ 4140Sstevel@tonic-gate } \ 4150Sstevel@tonic-gate self->ul_sp = stkptr(); \ 4160Sstevel@tonic-gate } \ 4170Sstevel@tonic-gate } 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate /* 4200Sstevel@tonic-gate * If a signal is taken, we return from the system call wrapper with 4210Sstevel@tonic-gate * our original signal mask restored (see code in call_user_handler()). 4220Sstevel@tonic-gate * If not (self->ul_sigsuspend is still non-zero), we must restore our 4230Sstevel@tonic-gate * original signal mask ourself. 4240Sstevel@tonic-gate */ 4250Sstevel@tonic-gate #define EPILOGUE_MASK \ 4260Sstevel@tonic-gate if (nocancel == 0) { \ 4270Sstevel@tonic-gate self->ul_sp = 0; \ 4280Sstevel@tonic-gate self->ul_cancel_async = self->ul_save_async; \ 4290Sstevel@tonic-gate } \ 4300Sstevel@tonic-gate if (self->ul_sigsuspend) { \ 4310Sstevel@tonic-gate self->ul_sigsuspend = 0; \ 4320Sstevel@tonic-gate restore_signals(self); \ 4330Sstevel@tonic-gate } \ 4340Sstevel@tonic-gate } 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate /* 4372248Sraf * Cancellation prologue and epilogue functions, 4382248Sraf * for cancellation points too complex to include here. 4391885Sraf */ 4401885Sraf void 4411885Sraf _cancel_prologue(void) 4421885Sraf { 4431885Sraf ulwp_t *self = curthread; 4441885Sraf 4455891Sraf self->ul_cancel_prologue = 4465891Sraf (self->ul_vfork | self->ul_nocancel | self->ul_libc_locks | 4475891Sraf self->ul_critical | self->ul_sigdefer) != 0; 4481885Sraf if (self->ul_cancel_prologue == 0) { 4491885Sraf self->ul_save_async = self->ul_cancel_async; 4501885Sraf if (!self->ul_cancel_disabled) { 4511885Sraf self->ul_cancel_async = 1; 4521885Sraf if (self->ul_cancel_pending) 453*6812Sraf pthread_exit(PTHREAD_CANCELED); 4541885Sraf } 4551885Sraf self->ul_sp = stkptr(); 4565891Sraf } else if (self->ul_cancel_pending && 4575891Sraf !self->ul_cancel_disabled) { 4585891Sraf set_cancel_eintr_flag(self); 4591885Sraf } 4601885Sraf } 4611885Sraf 4621885Sraf void 4631885Sraf _cancel_epilogue(void) 4641885Sraf { 4651885Sraf ulwp_t *self = curthread; 4661885Sraf 4671885Sraf if (self->ul_cancel_prologue == 0) { 4681885Sraf self->ul_sp = 0; 4691885Sraf self->ul_cancel_async = self->ul_save_async; 4701885Sraf } 4711885Sraf } 4721885Sraf 4731885Sraf /* 4740Sstevel@tonic-gate * Called from _thrp_join() (thr_join() is a cancellation point) 4750Sstevel@tonic-gate */ 4760Sstevel@tonic-gate int 4770Sstevel@tonic-gate lwp_wait(thread_t tid, thread_t *found) 4780Sstevel@tonic-gate { 4790Sstevel@tonic-gate int error; 4800Sstevel@tonic-gate 4810Sstevel@tonic-gate PROLOGUE 4825891Sraf if (abort) 4835891Sraf return (EINTR); 4845891Sraf while ((error = __lwp_wait(tid, found)) == EINTR && !cancel_active()) 4855891Sraf continue; 4860Sstevel@tonic-gate EPILOGUE 4870Sstevel@tonic-gate return (error); 4880Sstevel@tonic-gate } 4890Sstevel@tonic-gate 4900Sstevel@tonic-gate ssize_t 491*6812Sraf read(int fd, void *buf, size_t size) 4920Sstevel@tonic-gate { 4935891Sraf extern ssize_t __read(int, void *, size_t); 4940Sstevel@tonic-gate ssize_t rv; 4950Sstevel@tonic-gate 4965891Sraf PERFORM(__read(fd, buf, size)) 4970Sstevel@tonic-gate } 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate ssize_t 500*6812Sraf write(int fd, const void *buf, size_t size) 5010Sstevel@tonic-gate { 5025891Sraf extern ssize_t __write(int, const void *, size_t); 5030Sstevel@tonic-gate ssize_t rv; 5040Sstevel@tonic-gate 5055891Sraf PERFORM(__write(fd, buf, size)) 5060Sstevel@tonic-gate } 5070Sstevel@tonic-gate 5080Sstevel@tonic-gate int 509*6812Sraf getmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr, 5100Sstevel@tonic-gate int *flagsp) 5110Sstevel@tonic-gate { 5125891Sraf extern int __getmsg(int, struct strbuf *, struct strbuf *, int *); 5130Sstevel@tonic-gate int rv; 5140Sstevel@tonic-gate 5155891Sraf PERFORM(__getmsg(fd, ctlptr, dataptr, flagsp)) 5160Sstevel@tonic-gate } 5170Sstevel@tonic-gate 5180Sstevel@tonic-gate int 519*6812Sraf getpmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr, 5200Sstevel@tonic-gate int *bandp, int *flagsp) 5210Sstevel@tonic-gate { 5225891Sraf extern int __getpmsg(int, struct strbuf *, struct strbuf *, 5234843Sraf int *, int *); 5240Sstevel@tonic-gate int rv; 5250Sstevel@tonic-gate 5265891Sraf PERFORM(__getpmsg(fd, ctlptr, dataptr, bandp, flagsp)) 5270Sstevel@tonic-gate } 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate int 530*6812Sraf putmsg(int fd, const struct strbuf *ctlptr, 5310Sstevel@tonic-gate const struct strbuf *dataptr, int flags) 5320Sstevel@tonic-gate { 5335891Sraf extern int __putmsg(int, const struct strbuf *, 5344843Sraf const struct strbuf *, int); 5350Sstevel@tonic-gate int rv; 5360Sstevel@tonic-gate 5375891Sraf PERFORM(__putmsg(fd, ctlptr, dataptr, flags)) 5380Sstevel@tonic-gate } 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate int 5410Sstevel@tonic-gate __xpg4_putmsg(int fd, const struct strbuf *ctlptr, 5420Sstevel@tonic-gate const struct strbuf *dataptr, int flags) 5430Sstevel@tonic-gate { 5445891Sraf extern int __putmsg(int, const struct strbuf *, 5454843Sraf const struct strbuf *, int); 5460Sstevel@tonic-gate int rv; 5470Sstevel@tonic-gate 5485891Sraf PERFORM(__putmsg(fd, ctlptr, dataptr, flags|MSG_XPG4)) 5490Sstevel@tonic-gate } 5500Sstevel@tonic-gate 5510Sstevel@tonic-gate int 552*6812Sraf putpmsg(int fd, const struct strbuf *ctlptr, 5530Sstevel@tonic-gate const struct strbuf *dataptr, int band, int flags) 5540Sstevel@tonic-gate { 5555891Sraf extern int __putpmsg(int, const struct strbuf *, 5564843Sraf const struct strbuf *, int, int); 5570Sstevel@tonic-gate int rv; 5580Sstevel@tonic-gate 5595891Sraf PERFORM(__putpmsg(fd, ctlptr, dataptr, band, flags)) 5600Sstevel@tonic-gate } 5610Sstevel@tonic-gate 5620Sstevel@tonic-gate int 5630Sstevel@tonic-gate __xpg4_putpmsg(int fd, const struct strbuf *ctlptr, 5640Sstevel@tonic-gate const struct strbuf *dataptr, int band, int flags) 5650Sstevel@tonic-gate { 5665891Sraf extern int __putpmsg(int, const struct strbuf *, 5674843Sraf const struct strbuf *, int, int); 5680Sstevel@tonic-gate int rv; 5690Sstevel@tonic-gate 5705891Sraf PERFORM(__putpmsg(fd, ctlptr, dataptr, band, flags|MSG_XPG4)) 5710Sstevel@tonic-gate } 5720Sstevel@tonic-gate 5730Sstevel@tonic-gate int 574*6812Sraf nanosleep(const timespec_t *rqtp, timespec_t *rmtp) 5750Sstevel@tonic-gate { 5760Sstevel@tonic-gate int error; 5770Sstevel@tonic-gate 5780Sstevel@tonic-gate PROLOGUE 5795891Sraf error = abort? EINTR : __nanosleep(rqtp, rmtp); 5800Sstevel@tonic-gate EPILOGUE 5810Sstevel@tonic-gate if (error) { 5820Sstevel@tonic-gate errno = error; 5830Sstevel@tonic-gate return (-1); 5840Sstevel@tonic-gate } 5850Sstevel@tonic-gate return (0); 5860Sstevel@tonic-gate } 5870Sstevel@tonic-gate 5880Sstevel@tonic-gate int 589*6812Sraf clock_nanosleep(clockid_t clock_id, int flags, 5900Sstevel@tonic-gate const timespec_t *rqtp, timespec_t *rmtp) 5910Sstevel@tonic-gate { 5920Sstevel@tonic-gate timespec_t reltime; 5930Sstevel@tonic-gate hrtime_t start; 5940Sstevel@tonic-gate hrtime_t rqlapse; 5950Sstevel@tonic-gate hrtime_t lapse; 5960Sstevel@tonic-gate int error; 5970Sstevel@tonic-gate 5980Sstevel@tonic-gate switch (clock_id) { 5990Sstevel@tonic-gate case CLOCK_VIRTUAL: 6000Sstevel@tonic-gate case CLOCK_PROCESS_CPUTIME_ID: 6010Sstevel@tonic-gate case CLOCK_THREAD_CPUTIME_ID: 6020Sstevel@tonic-gate return (ENOTSUP); 6030Sstevel@tonic-gate case CLOCK_REALTIME: 6040Sstevel@tonic-gate case CLOCK_HIGHRES: 6050Sstevel@tonic-gate break; 6060Sstevel@tonic-gate default: 6070Sstevel@tonic-gate return (EINVAL); 6080Sstevel@tonic-gate } 6090Sstevel@tonic-gate if (flags & TIMER_ABSTIME) { 6100Sstevel@tonic-gate abstime_to_reltime(clock_id, rqtp, &reltime); 6110Sstevel@tonic-gate rmtp = NULL; 6120Sstevel@tonic-gate } else { 6130Sstevel@tonic-gate reltime = *rqtp; 6140Sstevel@tonic-gate if (clock_id == CLOCK_HIGHRES) 6150Sstevel@tonic-gate start = gethrtime(); 6160Sstevel@tonic-gate } 6170Sstevel@tonic-gate restart: 6180Sstevel@tonic-gate PROLOGUE 6195891Sraf error = abort? EINTR : __nanosleep(&reltime, rmtp); 6200Sstevel@tonic-gate EPILOGUE 6210Sstevel@tonic-gate if (error == 0 && clock_id == CLOCK_HIGHRES) { 6220Sstevel@tonic-gate /* 6230Sstevel@tonic-gate * Don't return yet if we didn't really get a timeout. 6240Sstevel@tonic-gate * This can happen if we return because someone resets 6250Sstevel@tonic-gate * the system clock. 6260Sstevel@tonic-gate */ 6270Sstevel@tonic-gate if (flags & TIMER_ABSTIME) { 6280Sstevel@tonic-gate if ((hrtime_t)(uint32_t)rqtp->tv_sec * NANOSEC + 6290Sstevel@tonic-gate rqtp->tv_nsec > gethrtime()) { 6300Sstevel@tonic-gate abstime_to_reltime(clock_id, rqtp, &reltime); 6310Sstevel@tonic-gate goto restart; 6320Sstevel@tonic-gate } 6330Sstevel@tonic-gate } else { 6340Sstevel@tonic-gate rqlapse = (hrtime_t)(uint32_t)rqtp->tv_sec * NANOSEC + 6354843Sraf rqtp->tv_nsec; 6360Sstevel@tonic-gate lapse = gethrtime() - start; 6370Sstevel@tonic-gate if (rqlapse > lapse) { 6380Sstevel@tonic-gate hrt2ts(rqlapse - lapse, &reltime); 6390Sstevel@tonic-gate goto restart; 6400Sstevel@tonic-gate } 6410Sstevel@tonic-gate } 6420Sstevel@tonic-gate } 6430Sstevel@tonic-gate if (error == 0 && clock_id == CLOCK_REALTIME && 6440Sstevel@tonic-gate (flags & TIMER_ABSTIME)) { 6450Sstevel@tonic-gate /* 6460Sstevel@tonic-gate * Don't return yet just because someone reset the 6470Sstevel@tonic-gate * system clock. Recompute the new relative time 6480Sstevel@tonic-gate * and reissue the nanosleep() call if necessary. 6490Sstevel@tonic-gate * 6500Sstevel@tonic-gate * Resetting the system clock causes all sorts of 6510Sstevel@tonic-gate * problems and the SUSV3 standards body should 6520Sstevel@tonic-gate * have made the behavior of clock_nanosleep() be 6530Sstevel@tonic-gate * implementation-defined in such a case rather than 6540Sstevel@tonic-gate * being specific about honoring the new system time. 6550Sstevel@tonic-gate * Standards bodies are filled with fools and idiots. 6560Sstevel@tonic-gate */ 6570Sstevel@tonic-gate abstime_to_reltime(clock_id, rqtp, &reltime); 6580Sstevel@tonic-gate if (reltime.tv_sec != 0 || reltime.tv_nsec != 0) 6590Sstevel@tonic-gate goto restart; 6600Sstevel@tonic-gate } 6610Sstevel@tonic-gate return (error); 6620Sstevel@tonic-gate } 6630Sstevel@tonic-gate 6640Sstevel@tonic-gate unsigned int 665*6812Sraf sleep(unsigned int sec) 6660Sstevel@tonic-gate { 6670Sstevel@tonic-gate unsigned int rem = 0; 6680Sstevel@tonic-gate timespec_t ts; 6690Sstevel@tonic-gate timespec_t tsr; 6700Sstevel@tonic-gate 6710Sstevel@tonic-gate ts.tv_sec = (time_t)sec; 6720Sstevel@tonic-gate ts.tv_nsec = 0; 673*6812Sraf if (nanosleep(&ts, &tsr) == -1 && errno == EINTR) { 6740Sstevel@tonic-gate rem = (unsigned int)tsr.tv_sec; 6750Sstevel@tonic-gate if (tsr.tv_nsec >= NANOSEC / 2) 6760Sstevel@tonic-gate rem++; 6770Sstevel@tonic-gate } 6780Sstevel@tonic-gate return (rem); 6790Sstevel@tonic-gate } 6800Sstevel@tonic-gate 6810Sstevel@tonic-gate int 682*6812Sraf usleep(useconds_t usec) 6830Sstevel@tonic-gate { 6840Sstevel@tonic-gate timespec_t ts; 6850Sstevel@tonic-gate 6860Sstevel@tonic-gate ts.tv_sec = usec / MICROSEC; 6870Sstevel@tonic-gate ts.tv_nsec = (long)(usec % MICROSEC) * 1000; 688*6812Sraf (void) nanosleep(&ts, NULL); 6890Sstevel@tonic-gate return (0); 6900Sstevel@tonic-gate } 6910Sstevel@tonic-gate 6920Sstevel@tonic-gate int 693*6812Sraf close(int fildes) 6940Sstevel@tonic-gate { 6952248Sraf extern void _aio_close(int); 6965891Sraf extern int __close(int); 6970Sstevel@tonic-gate int rv; 6980Sstevel@tonic-gate 6996755Sraf /* 7006755Sraf * If we call _aio_close() while in a critical region, 7016755Sraf * we will draw an ASSERT() failure, so don't do it. 7026755Sraf * No calls to close() from within libc need _aio_close(); 7036755Sraf * only the application's calls to close() need this, 7046755Sraf * and such calls are never from a libc critical region. 7056755Sraf */ 7066755Sraf if (curthread->ul_critical == 0) 7076755Sraf _aio_close(fildes); 7085891Sraf PERFORM(__close(fildes)) 7090Sstevel@tonic-gate } 7100Sstevel@tonic-gate 7110Sstevel@tonic-gate int 712*6812Sraf creat(const char *path, mode_t mode) 7130Sstevel@tonic-gate { 7145891Sraf extern int __creat(const char *, mode_t); 7150Sstevel@tonic-gate int rv; 7160Sstevel@tonic-gate 7175891Sraf PERFORM(__creat(path, mode)) 7180Sstevel@tonic-gate } 7190Sstevel@tonic-gate 7200Sstevel@tonic-gate #if !defined(_LP64) 7210Sstevel@tonic-gate int 722*6812Sraf creat64(const char *path, mode_t mode) 7230Sstevel@tonic-gate { 7245891Sraf extern int __creat64(const char *, mode_t); 7250Sstevel@tonic-gate int rv; 7260Sstevel@tonic-gate 7275891Sraf PERFORM(__creat64(path, mode)) 7280Sstevel@tonic-gate } 7290Sstevel@tonic-gate #endif /* !_LP64 */ 7300Sstevel@tonic-gate 7310Sstevel@tonic-gate int 732*6812Sraf door_call(int d, door_arg_t *params) 7330Sstevel@tonic-gate { 7345891Sraf extern int __door_call(int, door_arg_t *); 7355891Sraf int rv; 7365891Sraf 7375891Sraf PERFORM(__door_call(d, params)) 7385891Sraf } 7395891Sraf 7405891Sraf int 741*6812Sraf fcntl(int fildes, int cmd, ...) 7425891Sraf { 7435891Sraf extern int __fcntl(int, int, ...); 7440Sstevel@tonic-gate intptr_t arg; 7450Sstevel@tonic-gate int rv; 7460Sstevel@tonic-gate va_list ap; 7470Sstevel@tonic-gate 7480Sstevel@tonic-gate va_start(ap, cmd); 7490Sstevel@tonic-gate arg = va_arg(ap, intptr_t); 7500Sstevel@tonic-gate va_end(ap); 7510Sstevel@tonic-gate if (cmd != F_SETLKW) 7525891Sraf return (__fcntl(fildes, cmd, arg)); 7535891Sraf PERFORM(__fcntl(fildes, cmd, arg)) 7540Sstevel@tonic-gate } 7550Sstevel@tonic-gate 7560Sstevel@tonic-gate int 757*6812Sraf fdatasync(int fildes) 7584722Sraf { 7595891Sraf extern int __fdsync(int, int); 7604722Sraf int rv; 7614722Sraf 7625891Sraf PERFORM(__fdsync(fildes, FDSYNC)) 7634722Sraf } 7644722Sraf 7654722Sraf int 766*6812Sraf fsync(int fildes) 7670Sstevel@tonic-gate { 7685891Sraf extern int __fdsync(int, int); 7690Sstevel@tonic-gate int rv; 7700Sstevel@tonic-gate 7715891Sraf PERFORM(__fdsync(fildes, FSYNC)) 7720Sstevel@tonic-gate } 7730Sstevel@tonic-gate 7740Sstevel@tonic-gate int 775*6812Sraf lockf(int fildes, int function, off_t size) 7760Sstevel@tonic-gate { 7775891Sraf extern int __lockf(int, int, off_t); 7780Sstevel@tonic-gate int rv; 7790Sstevel@tonic-gate 7805891Sraf PERFORM(__lockf(fildes, function, size)) 7810Sstevel@tonic-gate } 7820Sstevel@tonic-gate 7830Sstevel@tonic-gate #if !defined(_LP64) 7840Sstevel@tonic-gate int 785*6812Sraf lockf64(int fildes, int function, off64_t size) 7860Sstevel@tonic-gate { 7875891Sraf extern int __lockf64(int, int, off64_t); 7880Sstevel@tonic-gate int rv; 7890Sstevel@tonic-gate 7905891Sraf PERFORM(__lockf64(fildes, function, size)) 7910Sstevel@tonic-gate } 7920Sstevel@tonic-gate #endif /* !_LP64 */ 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate ssize_t 795*6812Sraf msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg) 7960Sstevel@tonic-gate { 7975891Sraf extern ssize_t __msgrcv(int, void *, size_t, long, int); 7980Sstevel@tonic-gate ssize_t rv; 7990Sstevel@tonic-gate 8005891Sraf PERFORM(__msgrcv(msqid, msgp, msgsz, msgtyp, msgflg)) 8010Sstevel@tonic-gate } 8020Sstevel@tonic-gate 8030Sstevel@tonic-gate int 804*6812Sraf msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg) 8050Sstevel@tonic-gate { 8065891Sraf extern int __msgsnd(int, const void *, size_t, int); 8070Sstevel@tonic-gate int rv; 8080Sstevel@tonic-gate 8095891Sraf PERFORM(__msgsnd(msqid, msgp, msgsz, msgflg)) 8105891Sraf } 8115891Sraf 8125891Sraf int 813*6812Sraf msync(caddr_t addr, size_t len, int flags) 8145891Sraf { 8155891Sraf extern int __msync(caddr_t, size_t, int); 8165891Sraf int rv; 8175891Sraf 8185891Sraf PERFORM(__msync(addr, len, flags)) 8190Sstevel@tonic-gate } 8200Sstevel@tonic-gate 8210Sstevel@tonic-gate int 822*6812Sraf open(const char *path, int oflag, ...) 8230Sstevel@tonic-gate { 8245891Sraf extern int __open(const char *, int, ...); 8255891Sraf mode_t mode; 8260Sstevel@tonic-gate int rv; 8275891Sraf va_list ap; 8280Sstevel@tonic-gate 8295891Sraf va_start(ap, oflag); 8305891Sraf mode = va_arg(ap, mode_t); 8315891Sraf va_end(ap); 8325891Sraf PERFORM(__open(path, oflag, mode)) 8330Sstevel@tonic-gate } 8340Sstevel@tonic-gate 8350Sstevel@tonic-gate int 836*6812Sraf openat(int fd, const char *path, int oflag, ...) 8370Sstevel@tonic-gate { 8385891Sraf extern int __openat(int, const char *, int, ...); 8390Sstevel@tonic-gate mode_t mode; 8400Sstevel@tonic-gate int rv; 8410Sstevel@tonic-gate va_list ap; 8420Sstevel@tonic-gate 8430Sstevel@tonic-gate va_start(ap, oflag); 8440Sstevel@tonic-gate mode = va_arg(ap, mode_t); 8450Sstevel@tonic-gate va_end(ap); 8465891Sraf PERFORM(__openat(fd, path, oflag, mode)) 8470Sstevel@tonic-gate } 8480Sstevel@tonic-gate 8490Sstevel@tonic-gate #if !defined(_LP64) 8500Sstevel@tonic-gate int 851*6812Sraf open64(const char *path, int oflag, ...) 8520Sstevel@tonic-gate { 8535891Sraf extern int __open64(const char *, int, ...); 8545891Sraf mode_t mode; 8555891Sraf int rv; 8565891Sraf va_list ap; 8575891Sraf 8585891Sraf va_start(ap, oflag); 8595891Sraf mode = va_arg(ap, mode_t); 8605891Sraf va_end(ap); 8615891Sraf PERFORM(__open64(path, oflag, mode)) 8625891Sraf } 8635891Sraf 8645891Sraf int 865*6812Sraf openat64(int fd, const char *path, int oflag, ...) 8665891Sraf { 8675891Sraf extern int __openat64(int, const char *, int, ...); 8680Sstevel@tonic-gate mode_t mode; 8690Sstevel@tonic-gate int rv; 8700Sstevel@tonic-gate va_list ap; 8710Sstevel@tonic-gate 8720Sstevel@tonic-gate va_start(ap, oflag); 8730Sstevel@tonic-gate mode = va_arg(ap, mode_t); 8740Sstevel@tonic-gate va_end(ap); 8755891Sraf PERFORM(__openat64(fd, path, oflag, mode)) 8760Sstevel@tonic-gate } 8770Sstevel@tonic-gate #endif /* !_LP64 */ 8780Sstevel@tonic-gate 8790Sstevel@tonic-gate int 880*6812Sraf pause(void) 8810Sstevel@tonic-gate { 8825891Sraf extern int __pause(void); 8830Sstevel@tonic-gate int rv; 8840Sstevel@tonic-gate 8855891Sraf PERFORM(__pause()) 8860Sstevel@tonic-gate } 8870Sstevel@tonic-gate 8880Sstevel@tonic-gate ssize_t 889*6812Sraf pread(int fildes, void *buf, size_t nbyte, off_t offset) 8900Sstevel@tonic-gate { 8915891Sraf extern ssize_t __pread(int, void *, size_t, off_t); 8920Sstevel@tonic-gate ssize_t rv; 8930Sstevel@tonic-gate 8945891Sraf PERFORM(__pread(fildes, buf, nbyte, offset)) 8950Sstevel@tonic-gate } 8960Sstevel@tonic-gate 8970Sstevel@tonic-gate #if !defined(_LP64) 8980Sstevel@tonic-gate ssize_t 899*6812Sraf pread64(int fildes, void *buf, size_t nbyte, off64_t offset) 9000Sstevel@tonic-gate { 9015891Sraf extern ssize_t __pread64(int, void *, size_t, off64_t); 9020Sstevel@tonic-gate ssize_t rv; 9030Sstevel@tonic-gate 9045891Sraf PERFORM(__pread64(fildes, buf, nbyte, offset)) 9050Sstevel@tonic-gate } 9060Sstevel@tonic-gate #endif /* !_LP64 */ 9070Sstevel@tonic-gate 9080Sstevel@tonic-gate ssize_t 909*6812Sraf pwrite(int fildes, const void *buf, size_t nbyte, off_t offset) 9100Sstevel@tonic-gate { 9115891Sraf extern ssize_t __pwrite(int, const void *, size_t, off_t); 9120Sstevel@tonic-gate ssize_t rv; 9130Sstevel@tonic-gate 9145891Sraf PERFORM(__pwrite(fildes, buf, nbyte, offset)) 9150Sstevel@tonic-gate } 9160Sstevel@tonic-gate 9170Sstevel@tonic-gate #if !defined(_LP64) 9180Sstevel@tonic-gate ssize_t 919*6812Sraf pwrite64(int fildes, const void *buf, size_t nbyte, off64_t offset) 9200Sstevel@tonic-gate { 9215891Sraf extern ssize_t __pwrite64(int, const void *, size_t, off64_t); 9220Sstevel@tonic-gate ssize_t rv; 9230Sstevel@tonic-gate 9245891Sraf PERFORM(__pwrite64(fildes, buf, nbyte, offset)) 9250Sstevel@tonic-gate } 9260Sstevel@tonic-gate #endif /* !_LP64 */ 9270Sstevel@tonic-gate 9280Sstevel@tonic-gate ssize_t 929*6812Sraf readv(int fildes, const struct iovec *iov, int iovcnt) 9300Sstevel@tonic-gate { 9315891Sraf extern ssize_t __readv(int, const struct iovec *, int); 9320Sstevel@tonic-gate ssize_t rv; 9330Sstevel@tonic-gate 9345891Sraf PERFORM(__readv(fildes, iov, iovcnt)) 9350Sstevel@tonic-gate } 9360Sstevel@tonic-gate 9370Sstevel@tonic-gate int 938*6812Sraf sigpause(int sig) 9390Sstevel@tonic-gate { 9405891Sraf extern int __sigpause(int); 9410Sstevel@tonic-gate int rv; 9420Sstevel@tonic-gate 9435891Sraf PERFORM(__sigpause(sig)) 9440Sstevel@tonic-gate } 9450Sstevel@tonic-gate 9460Sstevel@tonic-gate int 947*6812Sraf sigsuspend(const sigset_t *set) 9480Sstevel@tonic-gate { 9490Sstevel@tonic-gate extern int __sigsuspend(const sigset_t *); 9500Sstevel@tonic-gate int rv; 9510Sstevel@tonic-gate 9520Sstevel@tonic-gate PROLOGUE_MASK(set) 9530Sstevel@tonic-gate rv = __sigsuspend(set); 9540Sstevel@tonic-gate EPILOGUE_MASK 9550Sstevel@tonic-gate return (rv); 9560Sstevel@tonic-gate } 9570Sstevel@tonic-gate 9580Sstevel@tonic-gate int 9590Sstevel@tonic-gate _pollsys(struct pollfd *fds, nfds_t nfd, const timespec_t *timeout, 9600Sstevel@tonic-gate const sigset_t *sigmask) 9610Sstevel@tonic-gate { 9620Sstevel@tonic-gate extern int __pollsys(struct pollfd *, nfds_t, const timespec_t *, 9634843Sraf const sigset_t *); 9640Sstevel@tonic-gate int rv; 9650Sstevel@tonic-gate 9660Sstevel@tonic-gate PROLOGUE_MASK(sigmask) 9670Sstevel@tonic-gate rv = __pollsys(fds, nfd, timeout, sigmask); 9680Sstevel@tonic-gate EPILOGUE_MASK 9690Sstevel@tonic-gate return (rv); 9700Sstevel@tonic-gate } 9710Sstevel@tonic-gate 9720Sstevel@tonic-gate int 973*6812Sraf sigtimedwait(const sigset_t *set, siginfo_t *infop, const timespec_t *timeout) 9740Sstevel@tonic-gate { 9752248Sraf extern int __sigtimedwait(const sigset_t *, siginfo_t *, 9764843Sraf const timespec_t *); 9770Sstevel@tonic-gate siginfo_t info; 9780Sstevel@tonic-gate int sig; 9790Sstevel@tonic-gate 9800Sstevel@tonic-gate PROLOGUE 9815891Sraf if (abort) { 9825891Sraf *self->ul_errnop = EINTR; 9830Sstevel@tonic-gate sig = -1; 9845891Sraf } else { 9855891Sraf sig = __sigtimedwait(set, &info, timeout); 9865891Sraf if (sig == SIGCANCEL && 9875891Sraf (SI_FROMKERNEL(&info) || info.si_code == SI_LWP)) { 9885891Sraf do_sigcancel(); 9895891Sraf *self->ul_errnop = EINTR; 9905891Sraf sig = -1; 9915891Sraf } 9920Sstevel@tonic-gate } 9930Sstevel@tonic-gate EPILOGUE 9940Sstevel@tonic-gate if (sig != -1 && infop) 9956515Sraf (void) memcpy(infop, &info, sizeof (*infop)); 9960Sstevel@tonic-gate return (sig); 9970Sstevel@tonic-gate } 9980Sstevel@tonic-gate 9990Sstevel@tonic-gate int 1000*6812Sraf sigwait(sigset_t *set) 10010Sstevel@tonic-gate { 1002*6812Sraf return (sigtimedwait(set, NULL, NULL)); 10032248Sraf } 10042248Sraf 10052248Sraf int 1006*6812Sraf sigwaitinfo(const sigset_t *set, siginfo_t *info) 10072248Sraf { 1008*6812Sraf return (sigtimedwait(set, info, NULL)); 10092248Sraf } 10102248Sraf 10112248Sraf int 1012*6812Sraf sigqueue(pid_t pid, int signo, const union sigval value) 10132248Sraf { 10142248Sraf extern int __sigqueue(pid_t pid, int signo, 10154843Sraf /* const union sigval */ void *value, int si_code, int block); 10162248Sraf return (__sigqueue(pid, signo, value.sival_ptr, SI_QUEUE, 0)); 10170Sstevel@tonic-gate } 10180Sstevel@tonic-gate 10190Sstevel@tonic-gate int 10205891Sraf _so_accept(int sock, struct sockaddr *addr, uint_t *addrlen, int version) 10210Sstevel@tonic-gate { 10225891Sraf extern int __so_accept(int, struct sockaddr *, uint_t *, int); 10230Sstevel@tonic-gate int rv; 10240Sstevel@tonic-gate 10255891Sraf PERFORM(__so_accept(sock, addr, addrlen, version)) 10265891Sraf } 10275891Sraf 10285891Sraf int 10295891Sraf _so_connect(int sock, struct sockaddr *addr, uint_t addrlen, int version) 10305891Sraf { 10315891Sraf extern int __so_connect(int, struct sockaddr *, uint_t, int); 10325891Sraf int rv; 10335891Sraf 10345891Sraf PERFORM(__so_connect(sock, addr, addrlen, version)) 10350Sstevel@tonic-gate } 10360Sstevel@tonic-gate 10375891Sraf int 10385891Sraf _so_recv(int sock, void *buf, size_t len, int flags) 10390Sstevel@tonic-gate { 10405891Sraf extern int __so_recv(int, void *, size_t, int); 10415891Sraf int rv; 10420Sstevel@tonic-gate 10435891Sraf PERFORM(__so_recv(sock, buf, len, flags)) 10440Sstevel@tonic-gate } 10450Sstevel@tonic-gate 10465891Sraf int 10475891Sraf _so_recvfrom(int sock, void *buf, size_t len, int flags, 10485891Sraf struct sockaddr *addr, int *addrlen) 10490Sstevel@tonic-gate { 10505891Sraf extern int __so_recvfrom(int, void *, size_t, int, 10515891Sraf struct sockaddr *, int *); 10525891Sraf int rv; 10535891Sraf 10545891Sraf PERFORM(__so_recvfrom(sock, buf, len, flags, addr, addrlen)) 10555891Sraf } 10560Sstevel@tonic-gate 10575891Sraf int 10585891Sraf _so_recvmsg(int sock, struct msghdr *msg, int flags) 10595891Sraf { 10605891Sraf extern int __so_recvmsg(int, struct msghdr *, int); 10615891Sraf int rv; 10625891Sraf 10635891Sraf PERFORM(__so_recvmsg(sock, msg, flags)) 10640Sstevel@tonic-gate } 10650Sstevel@tonic-gate 10660Sstevel@tonic-gate int 10675891Sraf _so_send(int sock, const void *buf, size_t len, int flags) 10680Sstevel@tonic-gate { 10695891Sraf extern int __so_send(int, const void *, size_t, int); 10700Sstevel@tonic-gate int rv; 10710Sstevel@tonic-gate 10725891Sraf PERFORM(__so_send(sock, buf, len, flags)) 10735891Sraf } 10745891Sraf 10755891Sraf int 10765891Sraf _so_sendmsg(int sock, const struct msghdr *msg, int flags) 10775891Sraf { 10785891Sraf extern int __so_sendmsg(int, const struct msghdr *, int); 10795891Sraf int rv; 10805891Sraf 10815891Sraf PERFORM(__so_sendmsg(sock, msg, flags)) 10825891Sraf } 10835891Sraf 10845891Sraf int 10855891Sraf _so_sendto(int sock, const void *buf, size_t len, int flags, 10865891Sraf const struct sockaddr *addr, int *addrlen) 10875891Sraf { 10885891Sraf extern int __so_sendto(int, const void *, size_t, int, 10895891Sraf const struct sockaddr *, int *); 10905891Sraf int rv; 10915891Sraf 10925891Sraf PERFORM(__so_sendto(sock, buf, len, flags, addr, addrlen)) 10930Sstevel@tonic-gate } 10940Sstevel@tonic-gate 10955891Sraf int 1096*6812Sraf tcdrain(int fildes) 10970Sstevel@tonic-gate { 10985891Sraf extern int __tcdrain(int); 10995891Sraf int rv; 11000Sstevel@tonic-gate 11015891Sraf PERFORM(__tcdrain(fildes)) 11020Sstevel@tonic-gate } 11030Sstevel@tonic-gate 11045891Sraf int 1105*6812Sraf waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) 11065891Sraf { 11075891Sraf extern int __waitid(idtype_t, id_t, siginfo_t *, int); 11085891Sraf int rv; 11095891Sraf 11105891Sraf if (options & WNOHANG) 11115891Sraf return (__waitid(idtype, id, infop, options)); 11125891Sraf PERFORM(__waitid(idtype, id, infop, options)) 11135891Sraf } 11145891Sraf 11150Sstevel@tonic-gate ssize_t 1116*6812Sraf writev(int fildes, const struct iovec *iov, int iovcnt) 11170Sstevel@tonic-gate { 11185891Sraf extern ssize_t __writev(int, const struct iovec *, int); 11190Sstevel@tonic-gate ssize_t rv; 11200Sstevel@tonic-gate 11215891Sraf PERFORM(__writev(fildes, iov, iovcnt)) 11220Sstevel@tonic-gate } 1123