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 /* 425002Sraf * atfork_lock protects the pthread_atfork() data structures. 435002Sraf * 444914Sraf * fork_lock does double-duty. Not only does it (and atfork_lock) 454914Sraf * serialize calls to fork() and forkall(), but it also serializes calls 464914Sraf * to thr_suspend() and thr_continue() (because fork() and forkall() also 474914Sraf * suspend and continue other threads and they want no competition). 484914Sraf * 495002Sraf * Functions called in dlopen()ed L10N objects can do anything, including 505002Sraf * call malloc() and free(). Such calls are not fork-safe when protected 515002Sraf * by an ordinary mutex that is acquired in libc's prefork processing 525002Sraf * because, with an interposed malloc library present, there would be a 535002Sraf * lock ordering violation due to the pthread_atfork() prefork function 545002Sraf * in the interposition library acquiring its malloc lock(s) before the 554914Sraf * ordinary mutex in libc being acquired by libc's prefork functions. 564914Sraf * 575002Sraf * Within libc, calls to malloc() and free() are fork-safe if the calls 585002Sraf * are made while holding no other libc locks. This covers almost all 595002Sraf * of libc's malloc() and free() calls. For those libc code paths, such 605002Sraf * as the above-mentioned L10N calls, that require serialization and that 615002Sraf * may call malloc() or free(), libc uses callout_lock_enter() to perform 625002Sraf * the serialization. This works because callout_lock is not acquired as 635002Sraf * part of running the pthread_atfork() prefork handlers (to avoid the 645002Sraf * lock ordering violation described above). Rather, it is simply 655002Sraf * reinitialized in postfork1_child() to cover the case that some 665002Sraf * now-defunct thread might have been suspended while holding it. 670Sstevel@tonic-gate */ 684914Sraf 694843Sraf void 704843Sraf fork_lock_enter(void) 710Sstevel@tonic-gate { 724914Sraf ASSERT(curthread->ul_critical == 0); 736515Sraf (void) mutex_lock(&curthread->ul_uberdata->fork_lock); 740Sstevel@tonic-gate } 750Sstevel@tonic-gate 760Sstevel@tonic-gate void 770Sstevel@tonic-gate fork_lock_exit(void) 780Sstevel@tonic-gate { 794914Sraf ASSERT(curthread->ul_critical == 0); 806515Sraf (void) mutex_unlock(&curthread->ul_uberdata->fork_lock); 814914Sraf } 820Sstevel@tonic-gate 835891Sraf /* 845891Sraf * Use cancel_safe_mutex_lock() to protect against being cancelled while 855891Sraf * holding callout_lock and calling outside of libc (via L10N plugins). 865891Sraf * We will honor a pending cancellation request when callout_lock_exit() 875891Sraf * is called, by calling cancel_safe_mutex_unlock(). 885891Sraf */ 894914Sraf void 905002Sraf callout_lock_enter(void) 914914Sraf { 924914Sraf ASSERT(curthread->ul_critical == 0); 935891Sraf cancel_safe_mutex_lock(&curthread->ul_uberdata->callout_lock); 944914Sraf } 954914Sraf 964914Sraf void 975002Sraf callout_lock_exit(void) 984914Sraf { 994914Sraf ASSERT(curthread->ul_critical == 0); 1005891Sraf cancel_safe_mutex_unlock(&curthread->ul_uberdata->callout_lock); 1010Sstevel@tonic-gate } 1020Sstevel@tonic-gate 1036515Sraf #pragma weak forkx = _forkx 1044292Sab196087 pid_t 1056515Sraf _forkx(int flags) 1060Sstevel@tonic-gate { 1070Sstevel@tonic-gate ulwp_t *self = curthread; 1080Sstevel@tonic-gate uberdata_t *udp = self->ul_uberdata; 1090Sstevel@tonic-gate pid_t pid; 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate if (self->ul_vfork) { 1120Sstevel@tonic-gate /* 1130Sstevel@tonic-gate * We are a child of vfork(); omit all of the fork 1140Sstevel@tonic-gate * logic and go straight to the system call trap. 1150Sstevel@tonic-gate * A vfork() child of a multithreaded parent 1160Sstevel@tonic-gate * must never call fork(). 1170Sstevel@tonic-gate */ 1180Sstevel@tonic-gate if (udp->uberflags.uf_mt) { 1190Sstevel@tonic-gate errno = ENOTSUP; 1200Sstevel@tonic-gate return (-1); 1210Sstevel@tonic-gate } 1223235Sraf pid = __forkx(flags); 1230Sstevel@tonic-gate if (pid == 0) { /* child */ 1246515Sraf udp->pid = getpid(); 1250Sstevel@tonic-gate self->ul_vfork = 0; 1260Sstevel@tonic-gate } 1270Sstevel@tonic-gate return (pid); 1280Sstevel@tonic-gate } 1290Sstevel@tonic-gate 1304843Sraf sigoff(self); 1314843Sraf if (self->ul_fork) { 1320Sstevel@tonic-gate /* 1330Sstevel@tonic-gate * Cannot call fork() from a fork handler. 1340Sstevel@tonic-gate */ 1354843Sraf sigon(self); 1364843Sraf errno = EDEADLK; 1370Sstevel@tonic-gate return (-1); 1380Sstevel@tonic-gate } 1390Sstevel@tonic-gate self->ul_fork = 1; 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate /* 1420Sstevel@tonic-gate * The functions registered by pthread_atfork() are defined by 1430Sstevel@tonic-gate * the application and its libraries and we must not hold any 1444843Sraf * internal lmutex_lock()-acquired locks while invoking them. 1454843Sraf * We hold only udp->atfork_lock to protect the atfork linkages. 1464843Sraf * If one of these pthread_atfork() functions attempts to fork 1474914Sraf * or to call pthread_atfork(), libc will detect the error and 1484914Sraf * fail the call with EDEADLK. Otherwise, the pthread_atfork() 1494914Sraf * functions are free to do anything they please (except they 1504914Sraf * will not receive any signals). 1510Sstevel@tonic-gate */ 1526515Sraf (void) mutex_lock(&udp->atfork_lock); 1530Sstevel@tonic-gate _prefork_handler(); 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate /* 1564843Sraf * Block every other thread attempting thr_suspend() or thr_continue(). 1574843Sraf */ 1586515Sraf (void) mutex_lock(&udp->fork_lock); 1594843Sraf 1604843Sraf /* 1610Sstevel@tonic-gate * Block all signals. 1624843Sraf * Just deferring them via sigoff() is not enough. 1630Sstevel@tonic-gate * We have to avoid taking a deferred signal in the child 1643235Sraf * that was actually sent to the parent before __forkx(). 1650Sstevel@tonic-gate */ 1660Sstevel@tonic-gate block_all_signals(self); 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate /* 1690Sstevel@tonic-gate * This suspends all threads but this one, leaving them 1700Sstevel@tonic-gate * suspended outside of any critical regions in the library. 1714914Sraf * Thus, we are assured that no lmutex_lock()-acquired library 1724914Sraf * locks are held while we invoke fork() from the current thread. 1730Sstevel@tonic-gate */ 1740Sstevel@tonic-gate suspend_fork(); 1750Sstevel@tonic-gate 1763235Sraf pid = __forkx(flags); 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate if (pid == 0) { /* child */ 1790Sstevel@tonic-gate /* 1800Sstevel@tonic-gate * Clear our schedctl pointer. 1810Sstevel@tonic-gate * Discard any deferred signal that was sent to the parent. 1823235Sraf * Because we blocked all signals before __forkx(), a 1830Sstevel@tonic-gate * deferred signal cannot have been taken by the child. 1840Sstevel@tonic-gate */ 1850Sstevel@tonic-gate self->ul_schedctl_called = NULL; 1860Sstevel@tonic-gate self->ul_schedctl = NULL; 1870Sstevel@tonic-gate self->ul_cursig = 0; 1880Sstevel@tonic-gate self->ul_siginfo.si_signo = 0; 1896515Sraf udp->pid = getpid(); 1900Sstevel@tonic-gate /* reset the library's data structures to reflect one thread */ 1914574Sraf unregister_locks(); 1922248Sraf postfork1_child(); 1930Sstevel@tonic-gate restore_signals(self); 1946515Sraf (void) mutex_unlock(&udp->fork_lock); 1950Sstevel@tonic-gate _postfork_child_handler(); 1960Sstevel@tonic-gate } else { 1973235Sraf /* restart all threads that were suspended for fork() */ 1980Sstevel@tonic-gate continue_fork(0); 1990Sstevel@tonic-gate restore_signals(self); 2006515Sraf (void) mutex_unlock(&udp->fork_lock); 2010Sstevel@tonic-gate _postfork_parent_handler(); 2020Sstevel@tonic-gate } 2030Sstevel@tonic-gate 2046515Sraf (void) mutex_unlock(&udp->atfork_lock); 2050Sstevel@tonic-gate self->ul_fork = 0; 2064843Sraf sigon(self); 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate return (pid); 2090Sstevel@tonic-gate } 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate /* 2123235Sraf * fork() is fork1() for both Posix threads and Solaris threads. 2133235Sraf * The forkall() interface exists for applications that require 2143235Sraf * the semantics of replicating all threads. 2150Sstevel@tonic-gate */ 2163235Sraf #pragma weak fork1 = _fork 2173235Sraf #pragma weak _fork1 = _fork 2183235Sraf #pragma weak fork = _fork 2190Sstevel@tonic-gate pid_t 2203235Sraf _fork(void) 2213235Sraf { 2226515Sraf return (_forkx(0)); 2233235Sraf } 2243235Sraf 2253235Sraf /* 2263235Sraf * Much of the logic here is the same as in forkx(). 2273235Sraf * See the comments in forkx(), above. 2283235Sraf */ 2296515Sraf #pragma weak forkallx = _forkallx 2304292Sab196087 pid_t 2316515Sraf _forkallx(int flags) 2320Sstevel@tonic-gate { 2330Sstevel@tonic-gate ulwp_t *self = curthread; 2340Sstevel@tonic-gate uberdata_t *udp = self->ul_uberdata; 2350Sstevel@tonic-gate pid_t pid; 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate if (self->ul_vfork) { 2380Sstevel@tonic-gate if (udp->uberflags.uf_mt) { 2390Sstevel@tonic-gate errno = ENOTSUP; 2400Sstevel@tonic-gate return (-1); 2410Sstevel@tonic-gate } 2423235Sraf pid = __forkallx(flags); 2430Sstevel@tonic-gate if (pid == 0) { /* child */ 2446515Sraf udp->pid = getpid(); 2450Sstevel@tonic-gate self->ul_vfork = 0; 2460Sstevel@tonic-gate } 2470Sstevel@tonic-gate return (pid); 2480Sstevel@tonic-gate } 2490Sstevel@tonic-gate 2504843Sraf sigoff(self); 2514843Sraf if (self->ul_fork) { 2524843Sraf sigon(self); 2534843Sraf errno = EDEADLK; 2540Sstevel@tonic-gate return (-1); 2550Sstevel@tonic-gate } 2560Sstevel@tonic-gate self->ul_fork = 1; 2576515Sraf (void) mutex_lock(&udp->atfork_lock); 2586515Sraf (void) mutex_lock(&udp->fork_lock); 2590Sstevel@tonic-gate block_all_signals(self); 2600Sstevel@tonic-gate suspend_fork(); 2610Sstevel@tonic-gate 2623235Sraf pid = __forkallx(flags); 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate if (pid == 0) { 2650Sstevel@tonic-gate self->ul_schedctl_called = NULL; 2660Sstevel@tonic-gate self->ul_schedctl = NULL; 2670Sstevel@tonic-gate self->ul_cursig = 0; 2680Sstevel@tonic-gate self->ul_siginfo.si_signo = 0; 2696515Sraf udp->pid = getpid(); 2704574Sraf unregister_locks(); 2710Sstevel@tonic-gate continue_fork(1); 2720Sstevel@tonic-gate } else { 2730Sstevel@tonic-gate continue_fork(0); 2740Sstevel@tonic-gate } 2750Sstevel@tonic-gate restore_signals(self); 2766515Sraf (void) mutex_unlock(&udp->fork_lock); 2776515Sraf (void) mutex_unlock(&udp->atfork_lock); 2780Sstevel@tonic-gate self->ul_fork = 0; 2794843Sraf sigon(self); 2800Sstevel@tonic-gate 2810Sstevel@tonic-gate return (pid); 2820Sstevel@tonic-gate } 2830Sstevel@tonic-gate 2843235Sraf #pragma weak forkall = _forkall 2853235Sraf pid_t 2863235Sraf _forkall(void) 2873235Sraf { 2886515Sraf return (_forkallx(0)); 2893235Sraf } 2903235Sraf 2910Sstevel@tonic-gate /* 2925891Sraf * For the implementation of cancellation at cancellation points. 2930Sstevel@tonic-gate */ 2940Sstevel@tonic-gate #define PROLOGUE \ 2950Sstevel@tonic-gate { \ 2960Sstevel@tonic-gate ulwp_t *self = curthread; \ 2975891Sraf int nocancel = \ 2985891Sraf (self->ul_vfork | self->ul_nocancel | self->ul_libc_locks | \ 2995891Sraf self->ul_critical | self->ul_sigdefer); \ 3005891Sraf int abort = 0; \ 3010Sstevel@tonic-gate if (nocancel == 0) { \ 3020Sstevel@tonic-gate self->ul_save_async = self->ul_cancel_async; \ 3030Sstevel@tonic-gate if (!self->ul_cancel_disabled) { \ 3040Sstevel@tonic-gate self->ul_cancel_async = 1; \ 3050Sstevel@tonic-gate if (self->ul_cancel_pending) \ 3060Sstevel@tonic-gate _pthread_exit(PTHREAD_CANCELED); \ 3070Sstevel@tonic-gate } \ 3080Sstevel@tonic-gate self->ul_sp = stkptr(); \ 3095891Sraf } else if (self->ul_cancel_pending && \ 3105891Sraf !self->ul_cancel_disabled) { \ 3115891Sraf set_cancel_eintr_flag(self); \ 3125891Sraf abort = 1; \ 3130Sstevel@tonic-gate } 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate #define EPILOGUE \ 3160Sstevel@tonic-gate if (nocancel == 0) { \ 3170Sstevel@tonic-gate self->ul_sp = 0; \ 3180Sstevel@tonic-gate self->ul_cancel_async = self->ul_save_async; \ 3190Sstevel@tonic-gate } \ 3200Sstevel@tonic-gate } 3210Sstevel@tonic-gate 3220Sstevel@tonic-gate /* 3230Sstevel@tonic-gate * Perform the body of the action required by most of the cancelable 3240Sstevel@tonic-gate * function calls. The return(function_call) part is to allow the 3250Sstevel@tonic-gate * compiler to make the call be executed with tail recursion, which 3260Sstevel@tonic-gate * saves a register window on sparc and slightly (not much) improves 3270Sstevel@tonic-gate * the code for x86/x64 compilations. 3280Sstevel@tonic-gate */ 3290Sstevel@tonic-gate #define PERFORM(function_call) \ 3300Sstevel@tonic-gate PROLOGUE \ 3315891Sraf if (abort) { \ 3325891Sraf *self->ul_errnop = EINTR; \ 3335891Sraf return (-1); \ 3345891Sraf } \ 3350Sstevel@tonic-gate if (nocancel) \ 3360Sstevel@tonic-gate return (function_call); \ 3370Sstevel@tonic-gate rv = function_call; \ 3380Sstevel@tonic-gate EPILOGUE \ 3390Sstevel@tonic-gate return (rv); 3400Sstevel@tonic-gate 3410Sstevel@tonic-gate /* 3420Sstevel@tonic-gate * Specialized prologue for sigsuspend() and pollsys(). 3430Sstevel@tonic-gate * These system calls pass a signal mask to the kernel. 3440Sstevel@tonic-gate * The kernel replaces the thread's signal mask with the 3450Sstevel@tonic-gate * temporary mask before the thread goes to sleep. If 3460Sstevel@tonic-gate * a signal is received, the signal handler will execute 3470Sstevel@tonic-gate * with the temporary mask, as modified by the sigaction 3480Sstevel@tonic-gate * for the particular signal. 3490Sstevel@tonic-gate * 3500Sstevel@tonic-gate * We block all signals until we reach the kernel with the 3510Sstevel@tonic-gate * temporary mask. This eliminates race conditions with 3520Sstevel@tonic-gate * setting the signal mask while signals are being posted. 3530Sstevel@tonic-gate */ 3540Sstevel@tonic-gate #define PROLOGUE_MASK(sigmask) \ 3550Sstevel@tonic-gate { \ 3560Sstevel@tonic-gate ulwp_t *self = curthread; \ 3575891Sraf int nocancel = \ 3585891Sraf (self->ul_vfork | self->ul_nocancel | self->ul_libc_locks | \ 3595891Sraf self->ul_critical | self->ul_sigdefer); \ 3600Sstevel@tonic-gate if (!self->ul_vfork) { \ 3610Sstevel@tonic-gate if (sigmask) { \ 3620Sstevel@tonic-gate block_all_signals(self); \ 3631111Sraf self->ul_tmpmask.__sigbits[0] = sigmask->__sigbits[0]; \ 3641111Sraf self->ul_tmpmask.__sigbits[1] = sigmask->__sigbits[1]; \ 3650Sstevel@tonic-gate delete_reserved_signals(&self->ul_tmpmask); \ 3660Sstevel@tonic-gate self->ul_sigsuspend = 1; \ 3670Sstevel@tonic-gate } \ 3680Sstevel@tonic-gate if (nocancel == 0) { \ 3690Sstevel@tonic-gate self->ul_save_async = self->ul_cancel_async; \ 3700Sstevel@tonic-gate if (!self->ul_cancel_disabled) { \ 3710Sstevel@tonic-gate self->ul_cancel_async = 1; \ 3720Sstevel@tonic-gate if (self->ul_cancel_pending) { \ 3730Sstevel@tonic-gate if (self->ul_sigsuspend) { \ 3740Sstevel@tonic-gate self->ul_sigsuspend = 0;\ 3750Sstevel@tonic-gate restore_signals(self); \ 3760Sstevel@tonic-gate } \ 3770Sstevel@tonic-gate _pthread_exit(PTHREAD_CANCELED);\ 3780Sstevel@tonic-gate } \ 3790Sstevel@tonic-gate } \ 3800Sstevel@tonic-gate self->ul_sp = stkptr(); \ 3810Sstevel@tonic-gate } \ 3820Sstevel@tonic-gate } 3830Sstevel@tonic-gate 3840Sstevel@tonic-gate /* 3850Sstevel@tonic-gate * If a signal is taken, we return from the system call wrapper with 3860Sstevel@tonic-gate * our original signal mask restored (see code in call_user_handler()). 3870Sstevel@tonic-gate * If not (self->ul_sigsuspend is still non-zero), we must restore our 3880Sstevel@tonic-gate * original signal mask ourself. 3890Sstevel@tonic-gate */ 3900Sstevel@tonic-gate #define EPILOGUE_MASK \ 3910Sstevel@tonic-gate if (nocancel == 0) { \ 3920Sstevel@tonic-gate self->ul_sp = 0; \ 3930Sstevel@tonic-gate self->ul_cancel_async = self->ul_save_async; \ 3940Sstevel@tonic-gate } \ 3950Sstevel@tonic-gate if (self->ul_sigsuspend) { \ 3960Sstevel@tonic-gate self->ul_sigsuspend = 0; \ 3970Sstevel@tonic-gate restore_signals(self); \ 3980Sstevel@tonic-gate } \ 3990Sstevel@tonic-gate } 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate /* 4022248Sraf * Cancellation prologue and epilogue functions, 4032248Sraf * for cancellation points too complex to include here. 4041885Sraf */ 4051885Sraf void 4061885Sraf _cancel_prologue(void) 4071885Sraf { 4081885Sraf ulwp_t *self = curthread; 4091885Sraf 4105891Sraf self->ul_cancel_prologue = 4115891Sraf (self->ul_vfork | self->ul_nocancel | self->ul_libc_locks | 4125891Sraf self->ul_critical | self->ul_sigdefer) != 0; 4131885Sraf if (self->ul_cancel_prologue == 0) { 4141885Sraf self->ul_save_async = self->ul_cancel_async; 4151885Sraf if (!self->ul_cancel_disabled) { 4161885Sraf self->ul_cancel_async = 1; 4171885Sraf if (self->ul_cancel_pending) 4181885Sraf _pthread_exit(PTHREAD_CANCELED); 4191885Sraf } 4201885Sraf self->ul_sp = stkptr(); 4215891Sraf } else if (self->ul_cancel_pending && 4225891Sraf !self->ul_cancel_disabled) { 4235891Sraf set_cancel_eintr_flag(self); 4241885Sraf } 4251885Sraf } 4261885Sraf 4271885Sraf void 4281885Sraf _cancel_epilogue(void) 4291885Sraf { 4301885Sraf ulwp_t *self = curthread; 4311885Sraf 4321885Sraf if (self->ul_cancel_prologue == 0) { 4331885Sraf self->ul_sp = 0; 4341885Sraf self->ul_cancel_async = self->ul_save_async; 4351885Sraf } 4361885Sraf } 4371885Sraf 4381885Sraf /* 4390Sstevel@tonic-gate * Called from _thrp_join() (thr_join() is a cancellation point) 4400Sstevel@tonic-gate */ 4410Sstevel@tonic-gate int 4420Sstevel@tonic-gate lwp_wait(thread_t tid, thread_t *found) 4430Sstevel@tonic-gate { 4440Sstevel@tonic-gate int error; 4450Sstevel@tonic-gate 4460Sstevel@tonic-gate PROLOGUE 4475891Sraf if (abort) 4485891Sraf return (EINTR); 4495891Sraf while ((error = __lwp_wait(tid, found)) == EINTR && !cancel_active()) 4505891Sraf continue; 4510Sstevel@tonic-gate EPILOGUE 4520Sstevel@tonic-gate return (error); 4530Sstevel@tonic-gate } 4540Sstevel@tonic-gate 4555891Sraf #pragma weak read = _read 4560Sstevel@tonic-gate ssize_t 4575891Sraf _read(int fd, void *buf, size_t size) 4580Sstevel@tonic-gate { 4595891Sraf extern ssize_t __read(int, void *, size_t); 4600Sstevel@tonic-gate ssize_t rv; 4610Sstevel@tonic-gate 4625891Sraf PERFORM(__read(fd, buf, size)) 4630Sstevel@tonic-gate } 4640Sstevel@tonic-gate 4655891Sraf #pragma weak write = _write 4660Sstevel@tonic-gate ssize_t 4675891Sraf _write(int fd, const void *buf, size_t size) 4680Sstevel@tonic-gate { 4695891Sraf extern ssize_t __write(int, const void *, size_t); 4700Sstevel@tonic-gate ssize_t rv; 4710Sstevel@tonic-gate 4725891Sraf PERFORM(__write(fd, buf, size)) 4730Sstevel@tonic-gate } 4740Sstevel@tonic-gate 4755891Sraf #pragma weak getmsg = _getmsg 4760Sstevel@tonic-gate int 4775891Sraf _getmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr, 4780Sstevel@tonic-gate int *flagsp) 4790Sstevel@tonic-gate { 4805891Sraf extern int __getmsg(int, struct strbuf *, struct strbuf *, int *); 4810Sstevel@tonic-gate int rv; 4820Sstevel@tonic-gate 4835891Sraf PERFORM(__getmsg(fd, ctlptr, dataptr, flagsp)) 4840Sstevel@tonic-gate } 4850Sstevel@tonic-gate 4865891Sraf #pragma weak getpmsg = _getpmsg 4870Sstevel@tonic-gate int 4885891Sraf _getpmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr, 4890Sstevel@tonic-gate int *bandp, int *flagsp) 4900Sstevel@tonic-gate { 4915891Sraf extern int __getpmsg(int, struct strbuf *, struct strbuf *, 4924843Sraf int *, int *); 4930Sstevel@tonic-gate int rv; 4940Sstevel@tonic-gate 4955891Sraf PERFORM(__getpmsg(fd, ctlptr, dataptr, bandp, flagsp)) 4960Sstevel@tonic-gate } 4970Sstevel@tonic-gate 4985891Sraf #pragma weak putmsg = _putmsg 4990Sstevel@tonic-gate int 5005891Sraf _putmsg(int fd, const struct strbuf *ctlptr, 5010Sstevel@tonic-gate const struct strbuf *dataptr, int flags) 5020Sstevel@tonic-gate { 5035891Sraf extern int __putmsg(int, const struct strbuf *, 5044843Sraf const struct strbuf *, int); 5050Sstevel@tonic-gate int rv; 5060Sstevel@tonic-gate 5075891Sraf PERFORM(__putmsg(fd, ctlptr, dataptr, flags)) 5080Sstevel@tonic-gate } 5090Sstevel@tonic-gate 5100Sstevel@tonic-gate int 5110Sstevel@tonic-gate __xpg4_putmsg(int fd, const struct strbuf *ctlptr, 5120Sstevel@tonic-gate const struct strbuf *dataptr, int flags) 5130Sstevel@tonic-gate { 5145891Sraf extern int __putmsg(int, const struct strbuf *, 5154843Sraf const struct strbuf *, int); 5160Sstevel@tonic-gate int rv; 5170Sstevel@tonic-gate 5185891Sraf PERFORM(__putmsg(fd, ctlptr, dataptr, flags|MSG_XPG4)) 5190Sstevel@tonic-gate } 5200Sstevel@tonic-gate 5215891Sraf #pragma weak putpmsg = _putpmsg 5220Sstevel@tonic-gate int 5235891Sraf _putpmsg(int fd, const struct strbuf *ctlptr, 5240Sstevel@tonic-gate const struct strbuf *dataptr, int band, int flags) 5250Sstevel@tonic-gate { 5265891Sraf extern int __putpmsg(int, const struct strbuf *, 5274843Sraf const struct strbuf *, int, int); 5280Sstevel@tonic-gate int rv; 5290Sstevel@tonic-gate 5305891Sraf PERFORM(__putpmsg(fd, ctlptr, dataptr, band, flags)) 5310Sstevel@tonic-gate } 5320Sstevel@tonic-gate 5330Sstevel@tonic-gate int 5340Sstevel@tonic-gate __xpg4_putpmsg(int fd, const struct strbuf *ctlptr, 5350Sstevel@tonic-gate const struct strbuf *dataptr, int band, int flags) 5360Sstevel@tonic-gate { 5375891Sraf extern int __putpmsg(int, const struct strbuf *, 5384843Sraf const struct strbuf *, int, int); 5390Sstevel@tonic-gate int rv; 5400Sstevel@tonic-gate 5415891Sraf PERFORM(__putpmsg(fd, ctlptr, dataptr, band, flags|MSG_XPG4)) 5420Sstevel@tonic-gate } 5430Sstevel@tonic-gate 5442248Sraf #pragma weak nanosleep = _nanosleep 5450Sstevel@tonic-gate int 5462248Sraf _nanosleep(const timespec_t *rqtp, timespec_t *rmtp) 5470Sstevel@tonic-gate { 5480Sstevel@tonic-gate int error; 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate PROLOGUE 5515891Sraf error = abort? EINTR : __nanosleep(rqtp, rmtp); 5520Sstevel@tonic-gate EPILOGUE 5530Sstevel@tonic-gate if (error) { 5540Sstevel@tonic-gate errno = error; 5550Sstevel@tonic-gate return (-1); 5560Sstevel@tonic-gate } 5570Sstevel@tonic-gate return (0); 5580Sstevel@tonic-gate } 5590Sstevel@tonic-gate 5602248Sraf #pragma weak clock_nanosleep = _clock_nanosleep 5610Sstevel@tonic-gate int 5622248Sraf _clock_nanosleep(clockid_t clock_id, int flags, 5630Sstevel@tonic-gate const timespec_t *rqtp, timespec_t *rmtp) 5640Sstevel@tonic-gate { 5650Sstevel@tonic-gate timespec_t reltime; 5660Sstevel@tonic-gate hrtime_t start; 5670Sstevel@tonic-gate hrtime_t rqlapse; 5680Sstevel@tonic-gate hrtime_t lapse; 5690Sstevel@tonic-gate int error; 5700Sstevel@tonic-gate 5710Sstevel@tonic-gate switch (clock_id) { 5720Sstevel@tonic-gate case CLOCK_VIRTUAL: 5730Sstevel@tonic-gate case CLOCK_PROCESS_CPUTIME_ID: 5740Sstevel@tonic-gate case CLOCK_THREAD_CPUTIME_ID: 5750Sstevel@tonic-gate return (ENOTSUP); 5760Sstevel@tonic-gate case CLOCK_REALTIME: 5770Sstevel@tonic-gate case CLOCK_HIGHRES: 5780Sstevel@tonic-gate break; 5790Sstevel@tonic-gate default: 5800Sstevel@tonic-gate return (EINVAL); 5810Sstevel@tonic-gate } 5820Sstevel@tonic-gate if (flags & TIMER_ABSTIME) { 5830Sstevel@tonic-gate abstime_to_reltime(clock_id, rqtp, &reltime); 5840Sstevel@tonic-gate rmtp = NULL; 5850Sstevel@tonic-gate } else { 5860Sstevel@tonic-gate reltime = *rqtp; 5870Sstevel@tonic-gate if (clock_id == CLOCK_HIGHRES) 5880Sstevel@tonic-gate start = gethrtime(); 5890Sstevel@tonic-gate } 5900Sstevel@tonic-gate restart: 5910Sstevel@tonic-gate PROLOGUE 5925891Sraf error = abort? EINTR : __nanosleep(&reltime, rmtp); 5930Sstevel@tonic-gate EPILOGUE 5940Sstevel@tonic-gate if (error == 0 && clock_id == CLOCK_HIGHRES) { 5950Sstevel@tonic-gate /* 5960Sstevel@tonic-gate * Don't return yet if we didn't really get a timeout. 5970Sstevel@tonic-gate * This can happen if we return because someone resets 5980Sstevel@tonic-gate * the system clock. 5990Sstevel@tonic-gate */ 6000Sstevel@tonic-gate if (flags & TIMER_ABSTIME) { 6010Sstevel@tonic-gate if ((hrtime_t)(uint32_t)rqtp->tv_sec * NANOSEC + 6020Sstevel@tonic-gate rqtp->tv_nsec > gethrtime()) { 6030Sstevel@tonic-gate abstime_to_reltime(clock_id, rqtp, &reltime); 6040Sstevel@tonic-gate goto restart; 6050Sstevel@tonic-gate } 6060Sstevel@tonic-gate } else { 6070Sstevel@tonic-gate rqlapse = (hrtime_t)(uint32_t)rqtp->tv_sec * NANOSEC + 6084843Sraf rqtp->tv_nsec; 6090Sstevel@tonic-gate lapse = gethrtime() - start; 6100Sstevel@tonic-gate if (rqlapse > lapse) { 6110Sstevel@tonic-gate hrt2ts(rqlapse - lapse, &reltime); 6120Sstevel@tonic-gate goto restart; 6130Sstevel@tonic-gate } 6140Sstevel@tonic-gate } 6150Sstevel@tonic-gate } 6160Sstevel@tonic-gate if (error == 0 && clock_id == CLOCK_REALTIME && 6170Sstevel@tonic-gate (flags & TIMER_ABSTIME)) { 6180Sstevel@tonic-gate /* 6190Sstevel@tonic-gate * Don't return yet just because someone reset the 6200Sstevel@tonic-gate * system clock. Recompute the new relative time 6210Sstevel@tonic-gate * and reissue the nanosleep() call if necessary. 6220Sstevel@tonic-gate * 6230Sstevel@tonic-gate * Resetting the system clock causes all sorts of 6240Sstevel@tonic-gate * problems and the SUSV3 standards body should 6250Sstevel@tonic-gate * have made the behavior of clock_nanosleep() be 6260Sstevel@tonic-gate * implementation-defined in such a case rather than 6270Sstevel@tonic-gate * being specific about honoring the new system time. 6280Sstevel@tonic-gate * Standards bodies are filled with fools and idiots. 6290Sstevel@tonic-gate */ 6300Sstevel@tonic-gate abstime_to_reltime(clock_id, rqtp, &reltime); 6310Sstevel@tonic-gate if (reltime.tv_sec != 0 || reltime.tv_nsec != 0) 6320Sstevel@tonic-gate goto restart; 6330Sstevel@tonic-gate } 6340Sstevel@tonic-gate return (error); 6350Sstevel@tonic-gate } 6360Sstevel@tonic-gate 6370Sstevel@tonic-gate #pragma weak sleep = _sleep 6380Sstevel@tonic-gate unsigned int 6390Sstevel@tonic-gate _sleep(unsigned int sec) 6400Sstevel@tonic-gate { 6410Sstevel@tonic-gate unsigned int rem = 0; 6420Sstevel@tonic-gate timespec_t ts; 6430Sstevel@tonic-gate timespec_t tsr; 6440Sstevel@tonic-gate 6450Sstevel@tonic-gate ts.tv_sec = (time_t)sec; 6460Sstevel@tonic-gate ts.tv_nsec = 0; 6475891Sraf if (_nanosleep(&ts, &tsr) == -1 && errno == EINTR) { 6480Sstevel@tonic-gate rem = (unsigned int)tsr.tv_sec; 6490Sstevel@tonic-gate if (tsr.tv_nsec >= NANOSEC / 2) 6500Sstevel@tonic-gate rem++; 6510Sstevel@tonic-gate } 6520Sstevel@tonic-gate return (rem); 6530Sstevel@tonic-gate } 6540Sstevel@tonic-gate 6550Sstevel@tonic-gate #pragma weak usleep = _usleep 6560Sstevel@tonic-gate int 6570Sstevel@tonic-gate _usleep(useconds_t usec) 6580Sstevel@tonic-gate { 6590Sstevel@tonic-gate timespec_t ts; 6600Sstevel@tonic-gate 6610Sstevel@tonic-gate ts.tv_sec = usec / MICROSEC; 6620Sstevel@tonic-gate ts.tv_nsec = (long)(usec % MICROSEC) * 1000; 6635891Sraf (void) _nanosleep(&ts, NULL); 6640Sstevel@tonic-gate return (0); 6650Sstevel@tonic-gate } 6660Sstevel@tonic-gate 6675891Sraf #pragma weak close = _close 6680Sstevel@tonic-gate int 6695891Sraf _close(int fildes) 6700Sstevel@tonic-gate { 6712248Sraf extern void _aio_close(int); 6725891Sraf extern int __close(int); 6730Sstevel@tonic-gate int rv; 6740Sstevel@tonic-gate 675*6755Sraf /* 676*6755Sraf * If we call _aio_close() while in a critical region, 677*6755Sraf * we will draw an ASSERT() failure, so don't do it. 678*6755Sraf * No calls to close() from within libc need _aio_close(); 679*6755Sraf * only the application's calls to close() need this, 680*6755Sraf * and such calls are never from a libc critical region. 681*6755Sraf */ 682*6755Sraf if (curthread->ul_critical == 0) 683*6755Sraf _aio_close(fildes); 6845891Sraf PERFORM(__close(fildes)) 6850Sstevel@tonic-gate } 6860Sstevel@tonic-gate 6875891Sraf #pragma weak creat = _creat 6880Sstevel@tonic-gate int 6895891Sraf _creat(const char *path, mode_t mode) 6900Sstevel@tonic-gate { 6915891Sraf extern int __creat(const char *, mode_t); 6920Sstevel@tonic-gate int rv; 6930Sstevel@tonic-gate 6945891Sraf PERFORM(__creat(path, mode)) 6950Sstevel@tonic-gate } 6960Sstevel@tonic-gate 6970Sstevel@tonic-gate #if !defined(_LP64) 6985891Sraf #pragma weak creat64 = _creat64 6990Sstevel@tonic-gate int 7005891Sraf _creat64(const char *path, mode_t mode) 7010Sstevel@tonic-gate { 7025891Sraf extern int __creat64(const char *, mode_t); 7030Sstevel@tonic-gate int rv; 7040Sstevel@tonic-gate 7055891Sraf PERFORM(__creat64(path, mode)) 7060Sstevel@tonic-gate } 7070Sstevel@tonic-gate #endif /* !_LP64 */ 7080Sstevel@tonic-gate 7095891Sraf #pragma weak door_call = _door_call 7100Sstevel@tonic-gate int 7115891Sraf _door_call(int d, door_arg_t *params) 7120Sstevel@tonic-gate { 7135891Sraf extern int __door_call(int, door_arg_t *); 7145891Sraf int rv; 7155891Sraf 7165891Sraf PERFORM(__door_call(d, params)) 7175891Sraf } 7185891Sraf 7195891Sraf #pragma weak fcntl = _fcntl 7205891Sraf int 7215891Sraf _fcntl(int fildes, int cmd, ...) 7225891Sraf { 7235891Sraf extern int __fcntl(int, int, ...); 7240Sstevel@tonic-gate intptr_t arg; 7250Sstevel@tonic-gate int rv; 7260Sstevel@tonic-gate va_list ap; 7270Sstevel@tonic-gate 7280Sstevel@tonic-gate va_start(ap, cmd); 7290Sstevel@tonic-gate arg = va_arg(ap, intptr_t); 7300Sstevel@tonic-gate va_end(ap); 7310Sstevel@tonic-gate if (cmd != F_SETLKW) 7325891Sraf return (__fcntl(fildes, cmd, arg)); 7335891Sraf PERFORM(__fcntl(fildes, cmd, arg)) 7340Sstevel@tonic-gate } 7350Sstevel@tonic-gate 7365891Sraf #pragma weak fdatasync = _fdatasync 7370Sstevel@tonic-gate int 7385891Sraf _fdatasync(int fildes) 7394722Sraf { 7405891Sraf extern int __fdsync(int, int); 7414722Sraf int rv; 7424722Sraf 7435891Sraf PERFORM(__fdsync(fildes, FDSYNC)) 7444722Sraf } 7454722Sraf 7465891Sraf #pragma weak fsync = _fsync 7474722Sraf int 7485891Sraf _fsync(int fildes) 7490Sstevel@tonic-gate { 7505891Sraf extern int __fdsync(int, int); 7510Sstevel@tonic-gate int rv; 7520Sstevel@tonic-gate 7535891Sraf PERFORM(__fdsync(fildes, FSYNC)) 7540Sstevel@tonic-gate } 7550Sstevel@tonic-gate 7565891Sraf #pragma weak lockf = _lockf 7570Sstevel@tonic-gate int 7585891Sraf _lockf(int fildes, int function, off_t size) 7590Sstevel@tonic-gate { 7605891Sraf extern int __lockf(int, int, off_t); 7610Sstevel@tonic-gate int rv; 7620Sstevel@tonic-gate 7635891Sraf PERFORM(__lockf(fildes, function, size)) 7640Sstevel@tonic-gate } 7650Sstevel@tonic-gate 7660Sstevel@tonic-gate #if !defined(_LP64) 7675891Sraf #pragma weak lockf64 = _lockf64 7680Sstevel@tonic-gate int 7695891Sraf _lockf64(int fildes, int function, off64_t size) 7700Sstevel@tonic-gate { 7715891Sraf extern int __lockf64(int, int, off64_t); 7720Sstevel@tonic-gate int rv; 7730Sstevel@tonic-gate 7745891Sraf PERFORM(__lockf64(fildes, function, size)) 7750Sstevel@tonic-gate } 7760Sstevel@tonic-gate #endif /* !_LP64 */ 7770Sstevel@tonic-gate 7785891Sraf #pragma weak msgrcv = _msgrcv 7790Sstevel@tonic-gate ssize_t 7805891Sraf _msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg) 7810Sstevel@tonic-gate { 7825891Sraf extern ssize_t __msgrcv(int, void *, size_t, long, int); 7830Sstevel@tonic-gate ssize_t rv; 7840Sstevel@tonic-gate 7855891Sraf PERFORM(__msgrcv(msqid, msgp, msgsz, msgtyp, msgflg)) 7860Sstevel@tonic-gate } 7870Sstevel@tonic-gate 7885891Sraf #pragma weak msgsnd = _msgsnd 7890Sstevel@tonic-gate int 7905891Sraf _msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg) 7910Sstevel@tonic-gate { 7925891Sraf extern int __msgsnd(int, const void *, size_t, int); 7930Sstevel@tonic-gate int rv; 7940Sstevel@tonic-gate 7955891Sraf PERFORM(__msgsnd(msqid, msgp, msgsz, msgflg)) 7965891Sraf } 7975891Sraf 7985891Sraf #pragma weak msync = _msync 7995891Sraf int 8005891Sraf _msync(caddr_t addr, size_t len, int flags) 8015891Sraf { 8025891Sraf extern int __msync(caddr_t, size_t, int); 8035891Sraf int rv; 8045891Sraf 8055891Sraf PERFORM(__msync(addr, len, flags)) 8060Sstevel@tonic-gate } 8070Sstevel@tonic-gate 8085891Sraf #pragma weak open = _open 8090Sstevel@tonic-gate int 8105891Sraf _open(const char *path, int oflag, ...) 8110Sstevel@tonic-gate { 8125891Sraf extern int __open(const char *, int, ...); 8135891Sraf mode_t mode; 8140Sstevel@tonic-gate int rv; 8155891Sraf va_list ap; 8160Sstevel@tonic-gate 8175891Sraf va_start(ap, oflag); 8185891Sraf mode = va_arg(ap, mode_t); 8195891Sraf va_end(ap); 8205891Sraf PERFORM(__open(path, oflag, mode)) 8210Sstevel@tonic-gate } 8220Sstevel@tonic-gate 8235891Sraf #pragma weak openat = _openat 8240Sstevel@tonic-gate int 8255891Sraf _openat(int fd, const char *path, int oflag, ...) 8260Sstevel@tonic-gate { 8275891Sraf extern int __openat(int, const char *, int, ...); 8280Sstevel@tonic-gate mode_t mode; 8290Sstevel@tonic-gate int rv; 8300Sstevel@tonic-gate va_list ap; 8310Sstevel@tonic-gate 8320Sstevel@tonic-gate va_start(ap, oflag); 8330Sstevel@tonic-gate mode = va_arg(ap, mode_t); 8340Sstevel@tonic-gate va_end(ap); 8355891Sraf PERFORM(__openat(fd, path, oflag, mode)) 8360Sstevel@tonic-gate } 8370Sstevel@tonic-gate 8380Sstevel@tonic-gate #if !defined(_LP64) 8395891Sraf #pragma weak open64 = _open64 8400Sstevel@tonic-gate int 8415891Sraf _open64(const char *path, int oflag, ...) 8420Sstevel@tonic-gate { 8435891Sraf extern int __open64(const char *, int, ...); 8445891Sraf mode_t mode; 8455891Sraf int rv; 8465891Sraf va_list ap; 8475891Sraf 8485891Sraf va_start(ap, oflag); 8495891Sraf mode = va_arg(ap, mode_t); 8505891Sraf va_end(ap); 8515891Sraf PERFORM(__open64(path, oflag, mode)) 8525891Sraf } 8535891Sraf 8545891Sraf #pragma weak openat64 = _openat64 8555891Sraf int 8565891Sraf _openat64(int fd, const char *path, int oflag, ...) 8575891Sraf { 8585891Sraf extern int __openat64(int, const char *, int, ...); 8590Sstevel@tonic-gate mode_t mode; 8600Sstevel@tonic-gate int rv; 8610Sstevel@tonic-gate va_list ap; 8620Sstevel@tonic-gate 8630Sstevel@tonic-gate va_start(ap, oflag); 8640Sstevel@tonic-gate mode = va_arg(ap, mode_t); 8650Sstevel@tonic-gate va_end(ap); 8665891Sraf PERFORM(__openat64(fd, path, oflag, mode)) 8670Sstevel@tonic-gate } 8680Sstevel@tonic-gate #endif /* !_LP64 */ 8690Sstevel@tonic-gate 8705891Sraf #pragma weak pause = _pause 8710Sstevel@tonic-gate int 8725891Sraf _pause(void) 8730Sstevel@tonic-gate { 8745891Sraf extern int __pause(void); 8750Sstevel@tonic-gate int rv; 8760Sstevel@tonic-gate 8775891Sraf PERFORM(__pause()) 8780Sstevel@tonic-gate } 8790Sstevel@tonic-gate 8805891Sraf #pragma weak pread = _pread 8810Sstevel@tonic-gate ssize_t 8825891Sraf _pread(int fildes, void *buf, size_t nbyte, off_t offset) 8830Sstevel@tonic-gate { 8845891Sraf extern ssize_t __pread(int, void *, size_t, off_t); 8850Sstevel@tonic-gate ssize_t rv; 8860Sstevel@tonic-gate 8875891Sraf PERFORM(__pread(fildes, buf, nbyte, offset)) 8880Sstevel@tonic-gate } 8890Sstevel@tonic-gate 8900Sstevel@tonic-gate #if !defined(_LP64) 8915891Sraf #pragma weak pread64 = _pread64 8920Sstevel@tonic-gate ssize_t 8935891Sraf _pread64(int fildes, void *buf, size_t nbyte, off64_t offset) 8940Sstevel@tonic-gate { 8955891Sraf extern ssize_t __pread64(int, void *, size_t, off64_t); 8960Sstevel@tonic-gate ssize_t rv; 8970Sstevel@tonic-gate 8985891Sraf PERFORM(__pread64(fildes, buf, nbyte, offset)) 8990Sstevel@tonic-gate } 9000Sstevel@tonic-gate #endif /* !_LP64 */ 9010Sstevel@tonic-gate 9025891Sraf #pragma weak pwrite = _pwrite 9030Sstevel@tonic-gate ssize_t 9045891Sraf _pwrite(int fildes, const void *buf, size_t nbyte, off_t offset) 9050Sstevel@tonic-gate { 9065891Sraf extern ssize_t __pwrite(int, const void *, size_t, off_t); 9070Sstevel@tonic-gate ssize_t rv; 9080Sstevel@tonic-gate 9095891Sraf PERFORM(__pwrite(fildes, buf, nbyte, offset)) 9100Sstevel@tonic-gate } 9110Sstevel@tonic-gate 9120Sstevel@tonic-gate #if !defined(_LP64) 9135891Sraf #pragma weak pwrite64 = _pwrite64 9140Sstevel@tonic-gate ssize_t 9155891Sraf _pwrite64(int fildes, const void *buf, size_t nbyte, off64_t offset) 9160Sstevel@tonic-gate { 9175891Sraf extern ssize_t __pwrite64(int, const void *, size_t, off64_t); 9180Sstevel@tonic-gate ssize_t rv; 9190Sstevel@tonic-gate 9205891Sraf PERFORM(__pwrite64(fildes, buf, nbyte, offset)) 9210Sstevel@tonic-gate } 9220Sstevel@tonic-gate #endif /* !_LP64 */ 9230Sstevel@tonic-gate 9245891Sraf #pragma weak readv = _readv 9250Sstevel@tonic-gate ssize_t 9265891Sraf _readv(int fildes, const struct iovec *iov, int iovcnt) 9270Sstevel@tonic-gate { 9285891Sraf extern ssize_t __readv(int, const struct iovec *, int); 9290Sstevel@tonic-gate ssize_t rv; 9300Sstevel@tonic-gate 9315891Sraf PERFORM(__readv(fildes, iov, iovcnt)) 9320Sstevel@tonic-gate } 9330Sstevel@tonic-gate 9345891Sraf #pragma weak sigpause = _sigpause 9350Sstevel@tonic-gate int 9365891Sraf _sigpause(int sig) 9370Sstevel@tonic-gate { 9385891Sraf extern int __sigpause(int); 9390Sstevel@tonic-gate int rv; 9400Sstevel@tonic-gate 9415891Sraf PERFORM(__sigpause(sig)) 9420Sstevel@tonic-gate } 9430Sstevel@tonic-gate 9440Sstevel@tonic-gate #pragma weak sigsuspend = _sigsuspend 9450Sstevel@tonic-gate int 9460Sstevel@tonic-gate _sigsuspend(const sigset_t *set) 9470Sstevel@tonic-gate { 9480Sstevel@tonic-gate extern int __sigsuspend(const sigset_t *); 9490Sstevel@tonic-gate int rv; 9500Sstevel@tonic-gate 9510Sstevel@tonic-gate PROLOGUE_MASK(set) 9520Sstevel@tonic-gate rv = __sigsuspend(set); 9530Sstevel@tonic-gate EPILOGUE_MASK 9540Sstevel@tonic-gate return (rv); 9550Sstevel@tonic-gate } 9560Sstevel@tonic-gate 9570Sstevel@tonic-gate int 9580Sstevel@tonic-gate _pollsys(struct pollfd *fds, nfds_t nfd, const timespec_t *timeout, 9590Sstevel@tonic-gate const sigset_t *sigmask) 9600Sstevel@tonic-gate { 9610Sstevel@tonic-gate extern int __pollsys(struct pollfd *, nfds_t, const timespec_t *, 9624843Sraf const sigset_t *); 9630Sstevel@tonic-gate int rv; 9640Sstevel@tonic-gate 9650Sstevel@tonic-gate PROLOGUE_MASK(sigmask) 9660Sstevel@tonic-gate rv = __pollsys(fds, nfd, timeout, sigmask); 9670Sstevel@tonic-gate EPILOGUE_MASK 9680Sstevel@tonic-gate return (rv); 9690Sstevel@tonic-gate } 9700Sstevel@tonic-gate 9712248Sraf #pragma weak sigtimedwait = _sigtimedwait 9720Sstevel@tonic-gate int 9732248Sraf _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 9806515Sraf if (!primary_link_map) { 9816515Sraf errno = ENOTSUP; 9826515Sraf return (-1); 9836515Sraf } 9846515Sraf 9850Sstevel@tonic-gate PROLOGUE 9865891Sraf if (abort) { 9875891Sraf *self->ul_errnop = EINTR; 9880Sstevel@tonic-gate sig = -1; 9895891Sraf } else { 9905891Sraf sig = __sigtimedwait(set, &info, timeout); 9915891Sraf if (sig == SIGCANCEL && 9925891Sraf (SI_FROMKERNEL(&info) || info.si_code == SI_LWP)) { 9935891Sraf do_sigcancel(); 9945891Sraf *self->ul_errnop = EINTR; 9955891Sraf sig = -1; 9965891Sraf } 9970Sstevel@tonic-gate } 9980Sstevel@tonic-gate EPILOGUE 9990Sstevel@tonic-gate if (sig != -1 && infop) 10006515Sraf (void) memcpy(infop, &info, sizeof (*infop)); 10010Sstevel@tonic-gate return (sig); 10020Sstevel@tonic-gate } 10030Sstevel@tonic-gate 10040Sstevel@tonic-gate #pragma weak sigwait = _sigwait 10050Sstevel@tonic-gate int 10060Sstevel@tonic-gate _sigwait(sigset_t *set) 10070Sstevel@tonic-gate { 10082248Sraf return (_sigtimedwait(set, NULL, NULL)); 10092248Sraf } 10102248Sraf 10112248Sraf #pragma weak sigwaitinfo = _sigwaitinfo 10122248Sraf int 10132248Sraf _sigwaitinfo(const sigset_t *set, siginfo_t *info) 10142248Sraf { 10152248Sraf return (_sigtimedwait(set, info, NULL)); 10162248Sraf } 10172248Sraf 10182248Sraf #pragma weak sigqueue = _sigqueue 10192248Sraf int 10202248Sraf _sigqueue(pid_t pid, int signo, const union sigval value) 10212248Sraf { 10222248Sraf extern int __sigqueue(pid_t pid, int signo, 10234843Sraf /* const union sigval */ void *value, int si_code, int block); 10242248Sraf return (__sigqueue(pid, signo, value.sival_ptr, SI_QUEUE, 0)); 10250Sstevel@tonic-gate } 10260Sstevel@tonic-gate 10270Sstevel@tonic-gate int 10285891Sraf _so_accept(int sock, struct sockaddr *addr, uint_t *addrlen, int version) 10290Sstevel@tonic-gate { 10305891Sraf extern int __so_accept(int, struct sockaddr *, uint_t *, int); 10310Sstevel@tonic-gate int rv; 10320Sstevel@tonic-gate 10335891Sraf PERFORM(__so_accept(sock, addr, addrlen, version)) 10345891Sraf } 10355891Sraf 10365891Sraf int 10375891Sraf _so_connect(int sock, struct sockaddr *addr, uint_t addrlen, int version) 10385891Sraf { 10395891Sraf extern int __so_connect(int, struct sockaddr *, uint_t, int); 10405891Sraf int rv; 10415891Sraf 10425891Sraf PERFORM(__so_connect(sock, addr, addrlen, version)) 10430Sstevel@tonic-gate } 10440Sstevel@tonic-gate 10455891Sraf int 10465891Sraf _so_recv(int sock, void *buf, size_t len, int flags) 10470Sstevel@tonic-gate { 10485891Sraf extern int __so_recv(int, void *, size_t, int); 10495891Sraf int rv; 10500Sstevel@tonic-gate 10515891Sraf PERFORM(__so_recv(sock, buf, len, flags)) 10520Sstevel@tonic-gate } 10530Sstevel@tonic-gate 10545891Sraf int 10555891Sraf _so_recvfrom(int sock, void *buf, size_t len, int flags, 10565891Sraf struct sockaddr *addr, int *addrlen) 10570Sstevel@tonic-gate { 10585891Sraf extern int __so_recvfrom(int, void *, size_t, int, 10595891Sraf struct sockaddr *, int *); 10605891Sraf int rv; 10615891Sraf 10625891Sraf PERFORM(__so_recvfrom(sock, buf, len, flags, addr, addrlen)) 10635891Sraf } 10640Sstevel@tonic-gate 10655891Sraf int 10665891Sraf _so_recvmsg(int sock, struct msghdr *msg, int flags) 10675891Sraf { 10685891Sraf extern int __so_recvmsg(int, struct msghdr *, int); 10695891Sraf int rv; 10705891Sraf 10715891Sraf PERFORM(__so_recvmsg(sock, msg, flags)) 10720Sstevel@tonic-gate } 10730Sstevel@tonic-gate 10740Sstevel@tonic-gate int 10755891Sraf _so_send(int sock, const void *buf, size_t len, int flags) 10760Sstevel@tonic-gate { 10775891Sraf extern int __so_send(int, const void *, size_t, int); 10780Sstevel@tonic-gate int rv; 10790Sstevel@tonic-gate 10805891Sraf PERFORM(__so_send(sock, buf, len, flags)) 10815891Sraf } 10825891Sraf 10835891Sraf int 10845891Sraf _so_sendmsg(int sock, const struct msghdr *msg, int flags) 10855891Sraf { 10865891Sraf extern int __so_sendmsg(int, const struct msghdr *, int); 10875891Sraf int rv; 10885891Sraf 10895891Sraf PERFORM(__so_sendmsg(sock, msg, flags)) 10905891Sraf } 10915891Sraf 10925891Sraf int 10935891Sraf _so_sendto(int sock, const void *buf, size_t len, int flags, 10945891Sraf const struct sockaddr *addr, int *addrlen) 10955891Sraf { 10965891Sraf extern int __so_sendto(int, const void *, size_t, int, 10975891Sraf const struct sockaddr *, int *); 10985891Sraf int rv; 10995891Sraf 11005891Sraf PERFORM(__so_sendto(sock, buf, len, flags, addr, addrlen)) 11010Sstevel@tonic-gate } 11020Sstevel@tonic-gate 11035891Sraf #pragma weak tcdrain = _tcdrain 11045891Sraf int 11055891Sraf _tcdrain(int fildes) 11060Sstevel@tonic-gate { 11075891Sraf extern int __tcdrain(int); 11085891Sraf int rv; 11090Sstevel@tonic-gate 11105891Sraf PERFORM(__tcdrain(fildes)) 11110Sstevel@tonic-gate } 11120Sstevel@tonic-gate 11135891Sraf #pragma weak waitid = _waitid 11145891Sraf int 11155891Sraf _waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) 11165891Sraf { 11175891Sraf extern int __waitid(idtype_t, id_t, siginfo_t *, int); 11185891Sraf int rv; 11195891Sraf 11205891Sraf if (options & WNOHANG) 11215891Sraf return (__waitid(idtype, id, infop, options)); 11225891Sraf PERFORM(__waitid(idtype, id, infop, options)) 11235891Sraf } 11245891Sraf 11255891Sraf #pragma weak writev = _writev 11260Sstevel@tonic-gate ssize_t 11275891Sraf _writev(int fildes, const struct iovec *iov, int iovcnt) 11280Sstevel@tonic-gate { 11295891Sraf extern ssize_t __writev(int, const struct iovec *, int); 11300Sstevel@tonic-gate ssize_t rv; 11310Sstevel@tonic-gate 11325891Sraf PERFORM(__writev(fildes, iov, iovcnt)) 11330Sstevel@tonic-gate } 1134