xref: /titanic_41/usr/src/lib/libc/port/threads/scalls.c (revision fa9e4066f08beec538e775443c5be79dd423fcab)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include "lint.h"
30 #include "thr_uberdata.h"
31 #include <stdarg.h>
32 #include <poll.h>
33 #include <stropts.h>
34 #include <dlfcn.h>
35 #include <sys/uio.h>
36 
37 /*
38  * fork_lock is special -- We can't use lmutex_lock() (and thereby enter
39  * a critical region) because the second thread to reach this point would
40  * become unstoppable and the first thread would hang waiting for the
41  * second thread to stop itself.  Therefore we don't use lmutex_lock() in
42  * fork_lock_enter(), but we do defer signals (the other form of concurrency).
43  *
44  * fork_lock_enter() does triple-duty.  Not only does it serialize
45  * calls to fork() and forkall(), but it also serializes calls to
46  * thr_suspend() (fork() and forkall() also suspend other threads),
47  * and furthermore it serializes I18N calls to functions in other
48  * dlopen()ed L10N objects that might be calling malloc()/free().
49  */
50 
51 static void
52 fork_lock_error(const char *who)
53 {
54 	char msg[200];
55 
56 	(void) strlcpy(msg, "deadlock condition: ", sizeof (msg));
57 	(void) strlcat(msg, who, sizeof (msg));
58 	(void) strlcat(msg, "() called from a fork handler", sizeof (msg));
59 	thread_error(msg);
60 }
61 
62 int
63 fork_lock_enter(const char *who)
64 {
65 	ulwp_t *self = curthread;
66 	uberdata_t *udp = self->ul_uberdata;
67 	int error = 0;
68 
69 	ASSERT(self->ul_critical == 0);
70 	sigoff(self);
71 	(void) _private_mutex_lock(&udp->fork_lock);
72 	while (udp->fork_count) {
73 		if (udp->fork_owner == self) {
74 			/*
75 			 * This is like a recursive lock except that we
76 			 * inform the caller if we have been called from
77 			 * a fork handler and let it deal with that fact.
78 			 */
79 			if (self->ul_fork) {
80 				/*
81 				 * We have been called from a fork handler.
82 				 */
83 				if (who != NULL &&
84 				    udp->uberflags.uf_thread_error_detection)
85 					fork_lock_error(who);
86 				error = EDEADLK;
87 			}
88 			break;
89 		}
90 		ASSERT(self->ul_fork == 0);
91 		(void) _cond_wait(&udp->fork_cond, &udp->fork_lock);
92 	}
93 	udp->fork_owner = self;
94 	udp->fork_count++;
95 	(void) _private_mutex_unlock(&udp->fork_lock);
96 	return (error);
97 }
98 
99 void
100 fork_lock_exit(void)
101 {
102 	ulwp_t *self = curthread;
103 	uberdata_t *udp = self->ul_uberdata;
104 
105 	ASSERT(self->ul_critical == 0);
106 	(void) _private_mutex_lock(&udp->fork_lock);
107 	ASSERT(udp->fork_count != 0 && udp->fork_owner == self);
108 	if (--udp->fork_count == 0) {
109 		udp->fork_owner = NULL;
110 		(void) _cond_signal(&udp->fork_cond);
111 	}
112 	(void) _private_mutex_unlock(&udp->fork_lock);
113 	sigon(self);
114 }
115 
116 /*
117  * fork() is fork1() for both Posix threads and Solaris threads.
118  * The forkall() interface exists for applications that require
119  * the semantics of replicating all threads.
120  */
121 #pragma weak fork = _fork1
122 #pragma weak _fork = _fork1
123 #pragma weak fork1 = _fork1
124 pid_t
125 _fork1(void)
126 {
127 	ulwp_t *self = curthread;
128 	uberdata_t *udp = self->ul_uberdata;
129 	pid_t pid;
130 	int error;
131 
132 	if (self->ul_vfork) {
133 		/*
134 		 * We are a child of vfork(); omit all of the fork
135 		 * logic and go straight to the system call trap.
136 		 * A vfork() child of a multithreaded parent
137 		 * must never call fork().
138 		 */
139 		if (udp->uberflags.uf_mt) {
140 			errno = ENOTSUP;
141 			return (-1);
142 		}
143 		pid = __fork1();
144 		if (pid == 0) {		/* child */
145 			udp->pid = _private_getpid();
146 			self->ul_vfork = 0;
147 		}
148 		return (pid);
149 	}
150 
151 	if ((error = fork_lock_enter("fork")) != 0) {
152 		/*
153 		 * Cannot call fork() from a fork handler.
154 		 */
155 		fork_lock_exit();
156 		errno = error;
157 		return (-1);
158 	}
159 	self->ul_fork = 1;
160 
161 	/*
162 	 * The functions registered by pthread_atfork() are defined by
163 	 * the application and its libraries and we must not hold any
164 	 * internal libc locks while invoking them.  The fork_lock_enter()
165 	 * function serializes fork(), thr_suspend(), pthread_atfork() and
166 	 * dlclose() (which destroys whatever pthread_atfork() functions
167 	 * the library may have set up).  If one of these pthread_atfork()
168 	 * functions attempts to fork or suspend another thread or call
169 	 * pthread_atfork() or dlclose a library, it will detect a deadlock
170 	 * in fork_lock_enter().  Otherwise, the pthread_atfork() functions
171 	 * are free to do anything they please (except they will not
172 	 * receive any signals).
173 	 */
174 	_prefork_handler();
175 
176 	/*
177 	 * Block all signals.
178 	 * Just deferring them via sigon() is not enough.
179 	 * We have to avoid taking a deferred signal in the child
180 	 * that was actually sent to the parent before __fork1().
181 	 */
182 	block_all_signals(self);
183 
184 	/*
185 	 * This suspends all threads but this one, leaving them
186 	 * suspended outside of any critical regions in the library.
187 	 * Thus, we are assured that no library locks are held
188 	 * while we invoke fork1() from the current thread.
189 	 */
190 	(void) _private_mutex_lock(&udp->fork_lock);
191 	suspend_fork();
192 	(void) _private_mutex_unlock(&udp->fork_lock);
193 
194 	pid = __fork1();
195 
196 	if (pid == 0) {		/* child */
197 		/*
198 		 * Clear our schedctl pointer.
199 		 * Discard any deferred signal that was sent to the parent.
200 		 * Because we blocked all signals before __fork1(), a
201 		 * deferred signal cannot have been taken by the child.
202 		 */
203 		self->ul_schedctl_called = NULL;
204 		self->ul_schedctl = NULL;
205 		self->ul_cursig = 0;
206 		self->ul_siginfo.si_signo = 0;
207 		udp->pid = _private_getpid();
208 		/* reset the library's data structures to reflect one thread */
209 		_postfork1_child();
210 		restore_signals(self);
211 		_postfork_child_handler();
212 	} else {
213 		/* restart all threads that were suspended for fork1() */
214 		continue_fork(0);
215 		restore_signals(self);
216 		_postfork_parent_handler();
217 	}
218 
219 	self->ul_fork = 0;
220 	fork_lock_exit();
221 
222 	return (pid);
223 }
224 
225 /*
226  * Much of the logic here is the same as in fork1().
227  * See the comments in fork1(), above.
228  */
229 #pragma weak forkall = _forkall
230 pid_t
231 _forkall(void)
232 {
233 	ulwp_t *self = curthread;
234 	uberdata_t *udp = self->ul_uberdata;
235 	pid_t pid;
236 	int error;
237 
238 	if (self->ul_vfork) {
239 		if (udp->uberflags.uf_mt) {
240 			errno = ENOTSUP;
241 			return (-1);
242 		}
243 		pid = __forkall();
244 		if (pid == 0) {		/* child */
245 			udp->pid = _private_getpid();
246 			self->ul_vfork = 0;
247 		}
248 		return (pid);
249 	}
250 
251 	if ((error = fork_lock_enter("forkall")) != 0) {
252 		fork_lock_exit();
253 		errno = error;
254 		return (-1);
255 	}
256 	self->ul_fork = 1;
257 	block_all_signals(self);
258 	suspend_fork();
259 
260 	pid = __forkall();
261 
262 	if (pid == 0) {
263 		self->ul_schedctl_called = NULL;
264 		self->ul_schedctl = NULL;
265 		self->ul_cursig = 0;
266 		self->ul_siginfo.si_signo = 0;
267 		udp->pid = _private_getpid();
268 		continue_fork(1);
269 	} else {
270 		continue_fork(0);
271 	}
272 	restore_signals(self);
273 	self->ul_fork = 0;
274 	fork_lock_exit();
275 
276 	return (pid);
277 }
278 
279 /*
280  * Hacks for system calls to provide cancellation
281  * and improve java garbage collection.
282  */
283 #define	PROLOGUE							\
284 {									\
285 	ulwp_t *self = curthread;					\
286 	int nocancel = (self->ul_vfork | self->ul_nocancel);		\
287 	if (nocancel == 0) {						\
288 		self->ul_save_async = self->ul_cancel_async;		\
289 		if (!self->ul_cancel_disabled) {			\
290 			self->ul_cancel_async = 1;			\
291 			if (self->ul_cancel_pending)			\
292 				_pthread_exit(PTHREAD_CANCELED);	\
293 		}							\
294 		self->ul_sp = stkptr();					\
295 	}
296 
297 #define	EPILOGUE							\
298 	if (nocancel == 0) {						\
299 		self->ul_sp = 0;					\
300 		self->ul_cancel_async = self->ul_save_async;		\
301 	}								\
302 }
303 
304 /*
305  * Perform the body of the action required by most of the cancelable
306  * function calls.  The return(function_call) part is to allow the
307  * compiler to make the call be executed with tail recursion, which
308  * saves a register window on sparc and slightly (not much) improves
309  * the code for x86/x64 compilations.
310  */
311 #define	PERFORM(function_call)						\
312 	PROLOGUE							\
313 	if (nocancel)							\
314 		return (function_call);					\
315 	rv = function_call;						\
316 	EPILOGUE							\
317 	return (rv);
318 
319 /*
320  * Specialized prologue for sigsuspend() and pollsys().
321  * These system calls pass a signal mask to the kernel.
322  * The kernel replaces the thread's signal mask with the
323  * temporary mask before the thread goes to sleep.  If
324  * a signal is received, the signal handler will execute
325  * with the temporary mask, as modified by the sigaction
326  * for the particular signal.
327  *
328  * We block all signals until we reach the kernel with the
329  * temporary mask.  This eliminates race conditions with
330  * setting the signal mask while signals are being posted.
331  */
332 #define	PROLOGUE_MASK(sigmask)						\
333 {									\
334 	ulwp_t *self = curthread;					\
335 	int nocancel = (self->ul_vfork | self->ul_nocancel);		\
336 	if (!self->ul_vfork) {						\
337 		if (sigmask) {						\
338 			block_all_signals(self);			\
339 			self->ul_tmpmask = *sigmask;			\
340 			delete_reserved_signals(&self->ul_tmpmask);	\
341 			self->ul_sigsuspend = 1;			\
342 		}							\
343 		if (nocancel == 0) {					\
344 			self->ul_save_async = self->ul_cancel_async;	\
345 			if (!self->ul_cancel_disabled) {		\
346 				self->ul_cancel_async = 1;		\
347 				if (self->ul_cancel_pending) {		\
348 					if (self->ul_sigsuspend) {	\
349 						self->ul_sigsuspend = 0;\
350 						restore_signals(self);	\
351 					}				\
352 					_pthread_exit(PTHREAD_CANCELED);\
353 				}					\
354 			}						\
355 			self->ul_sp = stkptr();				\
356 		}							\
357 	}
358 
359 /*
360  * If a signal is taken, we return from the system call wrapper with
361  * our original signal mask restored (see code in call_user_handler()).
362  * If not (self->ul_sigsuspend is still non-zero), we must restore our
363  * original signal mask ourself.
364  */
365 #define	EPILOGUE_MASK							\
366 	if (nocancel == 0) {						\
367 		self->ul_sp = 0;					\
368 		self->ul_cancel_async = self->ul_save_async;		\
369 	}								\
370 	if (self->ul_sigsuspend) {					\
371 		self->ul_sigsuspend = 0;				\
372 		restore_signals(self);					\
373 	}								\
374 }
375 
376 /*
377  * Called from _thrp_join() (thr_join() is a cancellation point)
378  */
379 int
380 lwp_wait(thread_t tid, thread_t *found)
381 {
382 	int error;
383 
384 	PROLOGUE
385 	while ((error = __lwp_wait(tid, found)) == EINTR)
386 		;
387 	EPILOGUE
388 	return (error);
389 }
390 
391 ssize_t
392 read(int fd, void *buf, size_t size)
393 {
394 	extern ssize_t _read(int, void *, size_t);
395 	ssize_t rv;
396 
397 	PERFORM(_read(fd, buf, size))
398 }
399 
400 ssize_t
401 write(int fd, const void *buf, size_t size)
402 {
403 	extern ssize_t _write(int, const void *, size_t);
404 	ssize_t rv;
405 
406 	PERFORM(_write(fd, buf, size))
407 }
408 
409 int
410 getmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr,
411 	int *flagsp)
412 {
413 	extern int _getmsg(int, struct strbuf *, struct strbuf *, int *);
414 	int rv;
415 
416 	PERFORM(_getmsg(fd, ctlptr, dataptr, flagsp))
417 }
418 
419 int
420 getpmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr,
421 	int *bandp, int *flagsp)
422 {
423 	extern int _getpmsg(int, struct strbuf *, struct strbuf *,
424 		int *, int *);
425 	int rv;
426 
427 	PERFORM(_getpmsg(fd, ctlptr, dataptr, bandp, flagsp))
428 }
429 
430 int
431 putmsg(int fd, const struct strbuf *ctlptr,
432 	const struct strbuf *dataptr, int flags)
433 {
434 	extern int _putmsg(int, const struct strbuf *,
435 		const struct strbuf *, int);
436 	int rv;
437 
438 	PERFORM(_putmsg(fd, ctlptr, dataptr, flags))
439 }
440 
441 int
442 __xpg4_putmsg(int fd, const struct strbuf *ctlptr,
443 	const struct strbuf *dataptr, int flags)
444 {
445 	extern int _putmsg(int, const struct strbuf *,
446 		const struct strbuf *, int);
447 	int rv;
448 
449 	PERFORM(_putmsg(fd, ctlptr, dataptr, flags|MSG_XPG4))
450 }
451 
452 int
453 putpmsg(int fd, const struct strbuf *ctlptr,
454 	const struct strbuf *dataptr, int band, int flags)
455 {
456 	extern int _putpmsg(int, const struct strbuf *,
457 		const struct strbuf *, int, int);
458 	int rv;
459 
460 	PERFORM(_putpmsg(fd, ctlptr, dataptr, band, flags))
461 }
462 
463 int
464 __xpg4_putpmsg(int fd, const struct strbuf *ctlptr,
465 	const struct strbuf *dataptr, int band, int flags)
466 {
467 	extern int _putpmsg(int, const struct strbuf *,
468 		const struct strbuf *, int, int);
469 	int rv;
470 
471 	PERFORM(_putpmsg(fd, ctlptr, dataptr, band, flags|MSG_XPG4))
472 }
473 
474 int
475 __nanosleep(const timespec_t *rqtp, timespec_t *rmtp)
476 {
477 	int error;
478 
479 	PROLOGUE
480 	error = ___nanosleep(rqtp, rmtp);
481 	EPILOGUE
482 	if (error) {
483 		errno = error;
484 		return (-1);
485 	}
486 	return (0);
487 }
488 
489 int
490 __clock_nanosleep(clockid_t clock_id, int flags,
491 	const timespec_t *rqtp, timespec_t *rmtp)
492 {
493 	timespec_t reltime;
494 	hrtime_t start;
495 	hrtime_t rqlapse;
496 	hrtime_t lapse;
497 	int error;
498 
499 	switch (clock_id) {
500 	case CLOCK_VIRTUAL:
501 	case CLOCK_PROCESS_CPUTIME_ID:
502 	case CLOCK_THREAD_CPUTIME_ID:
503 		return (ENOTSUP);
504 	case CLOCK_REALTIME:
505 	case CLOCK_HIGHRES:
506 		break;
507 	default:
508 		return (EINVAL);
509 	}
510 	if (flags & TIMER_ABSTIME) {
511 		abstime_to_reltime(clock_id, rqtp, &reltime);
512 		rmtp = NULL;
513 	} else {
514 		reltime = *rqtp;
515 		if (clock_id == CLOCK_HIGHRES)
516 			start = gethrtime();
517 	}
518 restart:
519 	PROLOGUE
520 	error = ___nanosleep(&reltime, rmtp);
521 	EPILOGUE
522 	if (error == 0 && clock_id == CLOCK_HIGHRES) {
523 		/*
524 		 * Don't return yet if we didn't really get a timeout.
525 		 * This can happen if we return because someone resets
526 		 * the system clock.
527 		 */
528 		if (flags & TIMER_ABSTIME) {
529 			if ((hrtime_t)(uint32_t)rqtp->tv_sec * NANOSEC +
530 			    rqtp->tv_nsec > gethrtime()) {
531 				abstime_to_reltime(clock_id, rqtp, &reltime);
532 				goto restart;
533 			}
534 		} else {
535 			rqlapse = (hrtime_t)(uint32_t)rqtp->tv_sec * NANOSEC +
536 				rqtp->tv_nsec;
537 			lapse = gethrtime() - start;
538 			if (rqlapse > lapse) {
539 				hrt2ts(rqlapse - lapse, &reltime);
540 				goto restart;
541 			}
542 		}
543 	}
544 	if (error == 0 && clock_id == CLOCK_REALTIME &&
545 	    (flags & TIMER_ABSTIME)) {
546 		/*
547 		 * Don't return yet just because someone reset the
548 		 * system clock.  Recompute the new relative time
549 		 * and reissue the nanosleep() call if necessary.
550 		 *
551 		 * Resetting the system clock causes all sorts of
552 		 * problems and the SUSV3 standards body should
553 		 * have made the behavior of clock_nanosleep() be
554 		 * implementation-defined in such a case rather than
555 		 * being specific about honoring the new system time.
556 		 * Standards bodies are filled with fools and idiots.
557 		 */
558 		abstime_to_reltime(clock_id, rqtp, &reltime);
559 		if (reltime.tv_sec != 0 || reltime.tv_nsec != 0)
560 			goto restart;
561 	}
562 	return (error);
563 }
564 
565 #pragma weak sleep = _sleep
566 unsigned int
567 _sleep(unsigned int sec)
568 {
569 	unsigned int rem = 0;
570 	int error;
571 	timespec_t ts;
572 	timespec_t tsr;
573 
574 	ts.tv_sec = (time_t)sec;
575 	ts.tv_nsec = 0;
576 	PROLOGUE
577 	error = ___nanosleep(&ts, &tsr);
578 	EPILOGUE
579 	if (error == EINTR) {
580 		rem = (unsigned int)tsr.tv_sec;
581 		if (tsr.tv_nsec >= NANOSEC / 2)
582 			rem++;
583 	}
584 	return (rem);
585 }
586 
587 #pragma weak usleep = _usleep
588 int
589 _usleep(useconds_t usec)
590 {
591 	timespec_t ts;
592 
593 	ts.tv_sec = usec / MICROSEC;
594 	ts.tv_nsec = (long)(usec % MICROSEC) * 1000;
595 	PROLOGUE
596 	(void) ___nanosleep(&ts, NULL);
597 	EPILOGUE
598 	return (0);
599 }
600 
601 int
602 close(int fildes)
603 {
604 	extern int _close(int);
605 	int rv;
606 
607 	PERFORM(_close(fildes))
608 }
609 
610 int
611 creat(const char *path, mode_t mode)
612 {
613 	extern int _creat(const char *, mode_t);
614 	int rv;
615 
616 	PERFORM(_creat(path, mode))
617 }
618 
619 #if !defined(_LP64)
620 int
621 creat64(const char *path, mode_t mode)
622 {
623 	extern int _creat64(const char *, mode_t);
624 	int rv;
625 
626 	PERFORM(_creat64(path, mode))
627 }
628 #endif	/* !_LP64 */
629 
630 int
631 fcntl(int fildes, int cmd, ...)
632 {
633 	extern int _fcntl(int, int, ...);
634 	intptr_t arg;
635 	int rv;
636 	va_list ap;
637 
638 	va_start(ap, cmd);
639 	arg = va_arg(ap, intptr_t);
640 	va_end(ap);
641 	if (cmd != F_SETLKW)
642 		return (_fcntl(fildes, cmd, arg));
643 	PERFORM(_fcntl(fildes, cmd, arg))
644 }
645 
646 int
647 fsync(int fildes)
648 {
649 	extern int _fsync(int);
650 	int rv;
651 
652 	PERFORM(_fsync(fildes))
653 }
654 
655 int
656 lockf(int fildes, int function, off_t size)
657 {
658 	extern int _lockf(int, int, off_t);
659 	int rv;
660 
661 	PERFORM(_lockf(fildes, function, size))
662 }
663 
664 #if !defined(_LP64)
665 int
666 lockf64(int fildes, int function, off64_t size)
667 {
668 	extern int _lockf64(int, int, off64_t);
669 	int rv;
670 
671 	PERFORM(_lockf64(fildes, function, size))
672 }
673 #endif	/* !_LP64 */
674 
675 ssize_t
676 msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
677 {
678 	extern ssize_t _msgrcv(int, void *, size_t, long, int);
679 	ssize_t rv;
680 
681 	PERFORM(_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg))
682 }
683 
684 int
685 msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg)
686 {
687 	extern int _msgsnd(int, const void *, size_t, int);
688 	int rv;
689 
690 	PERFORM(_msgsnd(msqid, msgp, msgsz, msgflg))
691 }
692 
693 int
694 msync(caddr_t addr, size_t len, int flags)
695 {
696 	extern int _msync(caddr_t, size_t, int);
697 	int rv;
698 
699 	PERFORM(_msync(addr, len, flags))
700 }
701 
702 int
703 open(const char *path, int oflag, ...)
704 {
705 	extern int _open(const char *, int, ...);
706 	mode_t mode;
707 	int rv;
708 	va_list ap;
709 
710 	va_start(ap, oflag);
711 	mode = va_arg(ap, mode_t);
712 	va_end(ap);
713 	PERFORM(_open(path, oflag, mode))
714 }
715 
716 #if !defined(_LP64)
717 int
718 open64(const char *path, int oflag, ...)
719 {
720 	extern int _open64(const char *, int, ...);
721 	mode_t mode;
722 	int rv;
723 	va_list ap;
724 
725 	va_start(ap, oflag);
726 	mode = va_arg(ap, mode_t);
727 	va_end(ap);
728 	PERFORM(_open64(path, oflag, mode))
729 }
730 #endif	/* !_LP64 */
731 
732 int
733 pause(void)
734 {
735 	extern int _pause(void);
736 	int rv;
737 
738 	PERFORM(_pause())
739 }
740 
741 ssize_t
742 pread(int fildes, void *buf, size_t nbyte, off_t offset)
743 {
744 	extern ssize_t _pread(int, void *, size_t, off_t);
745 	ssize_t rv;
746 
747 	PERFORM(_pread(fildes, buf, nbyte, offset))
748 }
749 
750 #if !defined(_LP64)
751 ssize_t
752 pread64(int fildes, void *buf, size_t nbyte, off64_t offset)
753 {
754 	extern ssize_t _pread64(int, void *, size_t, off64_t);
755 	ssize_t rv;
756 
757 	PERFORM(_pread64(fildes, buf, nbyte, offset))
758 }
759 #endif	/* !_LP64 */
760 
761 ssize_t
762 pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
763 {
764 	extern ssize_t _pwrite(int, const void *, size_t, off_t);
765 	ssize_t rv;
766 
767 	PERFORM(_pwrite(fildes, buf, nbyte, offset))
768 }
769 
770 #if !defined(_LP64)
771 ssize_t
772 pwrite64(int fildes, const void *buf, size_t nbyte, off64_t offset)
773 {
774 	extern ssize_t _pwrite64(int, const void *, size_t, off64_t);
775 	ssize_t rv;
776 
777 	PERFORM(_pwrite64(fildes, buf, nbyte, offset))
778 }
779 #endif	/* !_LP64 */
780 
781 ssize_t
782 readv(int fildes, const struct iovec *iov, int iovcnt)
783 {
784 	extern ssize_t _readv(int, const struct iovec *, int);
785 	ssize_t rv;
786 
787 	PERFORM(_readv(fildes, iov, iovcnt))
788 }
789 
790 int
791 sigpause(int sig)
792 {
793 	extern int _sigpause(int);
794 	int rv;
795 
796 	PERFORM(_sigpause(sig))
797 }
798 
799 #pragma weak sigsuspend = _sigsuspend
800 int
801 _sigsuspend(const sigset_t *set)
802 {
803 	extern int __sigsuspend(const sigset_t *);
804 	int rv;
805 
806 	PROLOGUE_MASK(set)
807 	rv = __sigsuspend(set);
808 	EPILOGUE_MASK
809 	return (rv);
810 }
811 
812 int
813 _pollsys(struct pollfd *fds, nfds_t nfd, const timespec_t *timeout,
814 	const sigset_t *sigmask)
815 {
816 	extern int __pollsys(struct pollfd *, nfds_t, const timespec_t *,
817 		const sigset_t *);
818 	int rv;
819 
820 	PROLOGUE_MASK(sigmask)
821 	rv = __pollsys(fds, nfd, timeout, sigmask);
822 	EPILOGUE_MASK
823 	return (rv);
824 }
825 
826 int
827 __sigtimedwait(const sigset_t *set, siginfo_t *infop,
828 	const timespec_t *timeout)
829 {
830 	extern int ___sigtimedwait(const sigset_t *, siginfo_t *,
831 		const timespec_t *);
832 	siginfo_t info;
833 	int sig;
834 
835 	PROLOGUE
836 	sig = ___sigtimedwait(set, &info, timeout);
837 	if (sig == SIGCANCEL &&
838 	    (SI_FROMKERNEL(&info) || info.si_code == SI_LWP)) {
839 		do_sigcancel();
840 		errno = EINTR;
841 		sig = -1;
842 	}
843 	EPILOGUE
844 	if (sig != -1 && infop)
845 		*infop = info;
846 	return (sig);
847 }
848 
849 #pragma weak sigwait = _sigwait
850 int
851 _sigwait(sigset_t *set)
852 {
853 	return (__sigtimedwait(set, NULL, NULL));
854 }
855 
856 int
857 tcdrain(int fildes)
858 {
859 	extern int _tcdrain(int);
860 	int rv;
861 
862 	PERFORM(_tcdrain(fildes))
863 }
864 
865 pid_t
866 wait(int *stat_loc)
867 {
868 	extern pid_t _wait(int *);
869 	pid_t rv;
870 
871 	PERFORM(_wait(stat_loc))
872 }
873 
874 pid_t
875 wait3(int *statusp, int options, struct rusage *rusage)
876 {
877 	extern pid_t _wait3(int *, int, struct rusage *);
878 	pid_t rv;
879 
880 	PERFORM(_wait3(statusp, options, rusage))
881 }
882 
883 int
884 waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options)
885 {
886 	extern int _waitid(idtype_t, id_t, siginfo_t *, int);
887 	int rv;
888 
889 	PERFORM(_waitid(idtype, id, infop, options))
890 }
891 
892 pid_t
893 waitpid(pid_t pid, int *stat_loc, int options)
894 {
895 	extern pid_t _waitpid(pid_t, int *, int);
896 	pid_t rv;
897 
898 	PERFORM(_waitpid(pid, stat_loc, options))
899 }
900 
901 ssize_t
902 writev(int fildes, const struct iovec *iov, int iovcnt)
903 {
904 	extern ssize_t _writev(int, const struct iovec *, int);
905 	ssize_t rv;
906 
907 	PERFORM(_writev(fildes, iov, iovcnt))
908 }
909