xref: /titanic_41/usr/src/lib/libc/port/threads/scalls.c (revision 88df2d76721d60b8b7cad14f9380446d06569f7c)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 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.__sigbits[0] = sigmask->__sigbits[0]; \
340 			self->ul_tmpmask.__sigbits[1] = sigmask->__sigbits[1]; \
341 			delete_reserved_signals(&self->ul_tmpmask);	\
342 			self->ul_sigsuspend = 1;			\
343 		}							\
344 		if (nocancel == 0) {					\
345 			self->ul_save_async = self->ul_cancel_async;	\
346 			if (!self->ul_cancel_disabled) {		\
347 				self->ul_cancel_async = 1;		\
348 				if (self->ul_cancel_pending) {		\
349 					if (self->ul_sigsuspend) {	\
350 						self->ul_sigsuspend = 0;\
351 						restore_signals(self);	\
352 					}				\
353 					_pthread_exit(PTHREAD_CANCELED);\
354 				}					\
355 			}						\
356 			self->ul_sp = stkptr();				\
357 		}							\
358 	}
359 
360 /*
361  * If a signal is taken, we return from the system call wrapper with
362  * our original signal mask restored (see code in call_user_handler()).
363  * If not (self->ul_sigsuspend is still non-zero), we must restore our
364  * original signal mask ourself.
365  */
366 #define	EPILOGUE_MASK							\
367 	if (nocancel == 0) {						\
368 		self->ul_sp = 0;					\
369 		self->ul_cancel_async = self->ul_save_async;		\
370 	}								\
371 	if (self->ul_sigsuspend) {					\
372 		self->ul_sigsuspend = 0;				\
373 		restore_signals(self);					\
374 	}								\
375 }
376 
377 /*
378  * Externally-callable cancellation prologue and epilogue
379  * functions, for cancellation points outside of libc.
380  */
381 void
382 _cancel_prologue(void)
383 {
384 	ulwp_t *self = curthread;
385 
386 	self->ul_cancel_prologue = (self->ul_vfork | self->ul_nocancel);
387 	if (self->ul_cancel_prologue == 0) {
388 		self->ul_save_async = self->ul_cancel_async;
389 		if (!self->ul_cancel_disabled) {
390 			self->ul_cancel_async = 1;
391 			if (self->ul_cancel_pending)
392 				_pthread_exit(PTHREAD_CANCELED);
393 		}
394 		self->ul_sp = stkptr();
395 	}
396 }
397 
398 void
399 _cancel_epilogue(void)
400 {
401 	ulwp_t *self = curthread;
402 
403 	if (self->ul_cancel_prologue == 0) {
404 		self->ul_sp = 0;
405 		self->ul_cancel_async = self->ul_save_async;
406 	}
407 }
408 
409 /*
410  * Called from _thrp_join() (thr_join() is a cancellation point)
411  */
412 int
413 lwp_wait(thread_t tid, thread_t *found)
414 {
415 	int error;
416 
417 	PROLOGUE
418 	while ((error = __lwp_wait(tid, found)) == EINTR)
419 		;
420 	EPILOGUE
421 	return (error);
422 }
423 
424 ssize_t
425 read(int fd, void *buf, size_t size)
426 {
427 	extern ssize_t _read(int, void *, size_t);
428 	ssize_t rv;
429 
430 	PERFORM(_read(fd, buf, size))
431 }
432 
433 ssize_t
434 write(int fd, const void *buf, size_t size)
435 {
436 	extern ssize_t _write(int, const void *, size_t);
437 	ssize_t rv;
438 
439 	PERFORM(_write(fd, buf, size))
440 }
441 
442 int
443 getmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr,
444 	int *flagsp)
445 {
446 	extern int _getmsg(int, struct strbuf *, struct strbuf *, int *);
447 	int rv;
448 
449 	PERFORM(_getmsg(fd, ctlptr, dataptr, flagsp))
450 }
451 
452 int
453 getpmsg(int fd, struct strbuf *ctlptr, struct strbuf *dataptr,
454 	int *bandp, int *flagsp)
455 {
456 	extern int _getpmsg(int, struct strbuf *, struct strbuf *,
457 		int *, int *);
458 	int rv;
459 
460 	PERFORM(_getpmsg(fd, ctlptr, dataptr, bandp, flagsp))
461 }
462 
463 int
464 putmsg(int fd, const struct strbuf *ctlptr,
465 	const struct strbuf *dataptr, int flags)
466 {
467 	extern int _putmsg(int, const struct strbuf *,
468 		const struct strbuf *, int);
469 	int rv;
470 
471 	PERFORM(_putmsg(fd, ctlptr, dataptr, flags))
472 }
473 
474 int
475 __xpg4_putmsg(int fd, const struct strbuf *ctlptr,
476 	const struct strbuf *dataptr, int flags)
477 {
478 	extern int _putmsg(int, const struct strbuf *,
479 		const struct strbuf *, int);
480 	int rv;
481 
482 	PERFORM(_putmsg(fd, ctlptr, dataptr, flags|MSG_XPG4))
483 }
484 
485 int
486 putpmsg(int fd, const struct strbuf *ctlptr,
487 	const struct strbuf *dataptr, int band, int flags)
488 {
489 	extern int _putpmsg(int, const struct strbuf *,
490 		const struct strbuf *, int, int);
491 	int rv;
492 
493 	PERFORM(_putpmsg(fd, ctlptr, dataptr, band, flags))
494 }
495 
496 int
497 __xpg4_putpmsg(int fd, const struct strbuf *ctlptr,
498 	const struct strbuf *dataptr, int band, int flags)
499 {
500 	extern int _putpmsg(int, const struct strbuf *,
501 		const struct strbuf *, int, int);
502 	int rv;
503 
504 	PERFORM(_putpmsg(fd, ctlptr, dataptr, band, flags|MSG_XPG4))
505 }
506 
507 int
508 __nanosleep(const timespec_t *rqtp, timespec_t *rmtp)
509 {
510 	int error;
511 
512 	PROLOGUE
513 	error = ___nanosleep(rqtp, rmtp);
514 	EPILOGUE
515 	if (error) {
516 		errno = error;
517 		return (-1);
518 	}
519 	return (0);
520 }
521 
522 int
523 __clock_nanosleep(clockid_t clock_id, int flags,
524 	const timespec_t *rqtp, timespec_t *rmtp)
525 {
526 	timespec_t reltime;
527 	hrtime_t start;
528 	hrtime_t rqlapse;
529 	hrtime_t lapse;
530 	int error;
531 
532 	switch (clock_id) {
533 	case CLOCK_VIRTUAL:
534 	case CLOCK_PROCESS_CPUTIME_ID:
535 	case CLOCK_THREAD_CPUTIME_ID:
536 		return (ENOTSUP);
537 	case CLOCK_REALTIME:
538 	case CLOCK_HIGHRES:
539 		break;
540 	default:
541 		return (EINVAL);
542 	}
543 	if (flags & TIMER_ABSTIME) {
544 		abstime_to_reltime(clock_id, rqtp, &reltime);
545 		rmtp = NULL;
546 	} else {
547 		reltime = *rqtp;
548 		if (clock_id == CLOCK_HIGHRES)
549 			start = gethrtime();
550 	}
551 restart:
552 	PROLOGUE
553 	error = ___nanosleep(&reltime, rmtp);
554 	EPILOGUE
555 	if (error == 0 && clock_id == CLOCK_HIGHRES) {
556 		/*
557 		 * Don't return yet if we didn't really get a timeout.
558 		 * This can happen if we return because someone resets
559 		 * the system clock.
560 		 */
561 		if (flags & TIMER_ABSTIME) {
562 			if ((hrtime_t)(uint32_t)rqtp->tv_sec * NANOSEC +
563 			    rqtp->tv_nsec > gethrtime()) {
564 				abstime_to_reltime(clock_id, rqtp, &reltime);
565 				goto restart;
566 			}
567 		} else {
568 			rqlapse = (hrtime_t)(uint32_t)rqtp->tv_sec * NANOSEC +
569 				rqtp->tv_nsec;
570 			lapse = gethrtime() - start;
571 			if (rqlapse > lapse) {
572 				hrt2ts(rqlapse - lapse, &reltime);
573 				goto restart;
574 			}
575 		}
576 	}
577 	if (error == 0 && clock_id == CLOCK_REALTIME &&
578 	    (flags & TIMER_ABSTIME)) {
579 		/*
580 		 * Don't return yet just because someone reset the
581 		 * system clock.  Recompute the new relative time
582 		 * and reissue the nanosleep() call if necessary.
583 		 *
584 		 * Resetting the system clock causes all sorts of
585 		 * problems and the SUSV3 standards body should
586 		 * have made the behavior of clock_nanosleep() be
587 		 * implementation-defined in such a case rather than
588 		 * being specific about honoring the new system time.
589 		 * Standards bodies are filled with fools and idiots.
590 		 */
591 		abstime_to_reltime(clock_id, rqtp, &reltime);
592 		if (reltime.tv_sec != 0 || reltime.tv_nsec != 0)
593 			goto restart;
594 	}
595 	return (error);
596 }
597 
598 #pragma weak sleep = _sleep
599 unsigned int
600 _sleep(unsigned int sec)
601 {
602 	unsigned int rem = 0;
603 	int error;
604 	timespec_t ts;
605 	timespec_t tsr;
606 
607 	ts.tv_sec = (time_t)sec;
608 	ts.tv_nsec = 0;
609 	PROLOGUE
610 	error = ___nanosleep(&ts, &tsr);
611 	EPILOGUE
612 	if (error == EINTR) {
613 		rem = (unsigned int)tsr.tv_sec;
614 		if (tsr.tv_nsec >= NANOSEC / 2)
615 			rem++;
616 	}
617 	return (rem);
618 }
619 
620 #pragma weak usleep = _usleep
621 int
622 _usleep(useconds_t usec)
623 {
624 	timespec_t ts;
625 
626 	ts.tv_sec = usec / MICROSEC;
627 	ts.tv_nsec = (long)(usec % MICROSEC) * 1000;
628 	PROLOGUE
629 	(void) ___nanosleep(&ts, NULL);
630 	EPILOGUE
631 	return (0);
632 }
633 
634 int
635 close(int fildes)
636 {
637 	extern int _close(int);
638 	int rv;
639 
640 	PERFORM(_close(fildes))
641 }
642 
643 int
644 creat(const char *path, mode_t mode)
645 {
646 	extern int _creat(const char *, mode_t);
647 	int rv;
648 
649 	PERFORM(_creat(path, mode))
650 }
651 
652 #if !defined(_LP64)
653 int
654 creat64(const char *path, mode_t mode)
655 {
656 	extern int _creat64(const char *, mode_t);
657 	int rv;
658 
659 	PERFORM(_creat64(path, mode))
660 }
661 #endif	/* !_LP64 */
662 
663 int
664 fcntl(int fildes, int cmd, ...)
665 {
666 	extern int _fcntl(int, int, ...);
667 	intptr_t arg;
668 	int rv;
669 	va_list ap;
670 
671 	va_start(ap, cmd);
672 	arg = va_arg(ap, intptr_t);
673 	va_end(ap);
674 	if (cmd != F_SETLKW)
675 		return (_fcntl(fildes, cmd, arg));
676 	PERFORM(_fcntl(fildes, cmd, arg))
677 }
678 
679 int
680 fsync(int fildes)
681 {
682 	extern int _fsync(int);
683 	int rv;
684 
685 	PERFORM(_fsync(fildes))
686 }
687 
688 int
689 lockf(int fildes, int function, off_t size)
690 {
691 	extern int _lockf(int, int, off_t);
692 	int rv;
693 
694 	PERFORM(_lockf(fildes, function, size))
695 }
696 
697 #if !defined(_LP64)
698 int
699 lockf64(int fildes, int function, off64_t size)
700 {
701 	extern int _lockf64(int, int, off64_t);
702 	int rv;
703 
704 	PERFORM(_lockf64(fildes, function, size))
705 }
706 #endif	/* !_LP64 */
707 
708 ssize_t
709 msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
710 {
711 	extern ssize_t _msgrcv(int, void *, size_t, long, int);
712 	ssize_t rv;
713 
714 	PERFORM(_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg))
715 }
716 
717 int
718 msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg)
719 {
720 	extern int _msgsnd(int, const void *, size_t, int);
721 	int rv;
722 
723 	PERFORM(_msgsnd(msqid, msgp, msgsz, msgflg))
724 }
725 
726 int
727 msync(caddr_t addr, size_t len, int flags)
728 {
729 	extern int _msync(caddr_t, size_t, int);
730 	int rv;
731 
732 	PERFORM(_msync(addr, len, flags))
733 }
734 
735 int
736 open(const char *path, int oflag, ...)
737 {
738 	extern int _open(const char *, int, ...);
739 	mode_t mode;
740 	int rv;
741 	va_list ap;
742 
743 	va_start(ap, oflag);
744 	mode = va_arg(ap, mode_t);
745 	va_end(ap);
746 	PERFORM(_open(path, oflag, mode))
747 }
748 
749 #if !defined(_LP64)
750 int
751 open64(const char *path, int oflag, ...)
752 {
753 	extern int _open64(const char *, int, ...);
754 	mode_t mode;
755 	int rv;
756 	va_list ap;
757 
758 	va_start(ap, oflag);
759 	mode = va_arg(ap, mode_t);
760 	va_end(ap);
761 	PERFORM(_open64(path, oflag, mode))
762 }
763 #endif	/* !_LP64 */
764 
765 int
766 pause(void)
767 {
768 	extern int _pause(void);
769 	int rv;
770 
771 	PERFORM(_pause())
772 }
773 
774 ssize_t
775 pread(int fildes, void *buf, size_t nbyte, off_t offset)
776 {
777 	extern ssize_t _pread(int, void *, size_t, off_t);
778 	ssize_t rv;
779 
780 	PERFORM(_pread(fildes, buf, nbyte, offset))
781 }
782 
783 #if !defined(_LP64)
784 ssize_t
785 pread64(int fildes, void *buf, size_t nbyte, off64_t offset)
786 {
787 	extern ssize_t _pread64(int, void *, size_t, off64_t);
788 	ssize_t rv;
789 
790 	PERFORM(_pread64(fildes, buf, nbyte, offset))
791 }
792 #endif	/* !_LP64 */
793 
794 ssize_t
795 pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
796 {
797 	extern ssize_t _pwrite(int, const void *, size_t, off_t);
798 	ssize_t rv;
799 
800 	PERFORM(_pwrite(fildes, buf, nbyte, offset))
801 }
802 
803 #if !defined(_LP64)
804 ssize_t
805 pwrite64(int fildes, const void *buf, size_t nbyte, off64_t offset)
806 {
807 	extern ssize_t _pwrite64(int, const void *, size_t, off64_t);
808 	ssize_t rv;
809 
810 	PERFORM(_pwrite64(fildes, buf, nbyte, offset))
811 }
812 #endif	/* !_LP64 */
813 
814 ssize_t
815 readv(int fildes, const struct iovec *iov, int iovcnt)
816 {
817 	extern ssize_t _readv(int, const struct iovec *, int);
818 	ssize_t rv;
819 
820 	PERFORM(_readv(fildes, iov, iovcnt))
821 }
822 
823 int
824 sigpause(int sig)
825 {
826 	extern int _sigpause(int);
827 	int rv;
828 
829 	PERFORM(_sigpause(sig))
830 }
831 
832 #pragma weak sigsuspend = _sigsuspend
833 int
834 _sigsuspend(const sigset_t *set)
835 {
836 	extern int __sigsuspend(const sigset_t *);
837 	int rv;
838 
839 	PROLOGUE_MASK(set)
840 	rv = __sigsuspend(set);
841 	EPILOGUE_MASK
842 	return (rv);
843 }
844 
845 int
846 _pollsys(struct pollfd *fds, nfds_t nfd, const timespec_t *timeout,
847 	const sigset_t *sigmask)
848 {
849 	extern int __pollsys(struct pollfd *, nfds_t, const timespec_t *,
850 		const sigset_t *);
851 	int rv;
852 
853 	PROLOGUE_MASK(sigmask)
854 	rv = __pollsys(fds, nfd, timeout, sigmask);
855 	EPILOGUE_MASK
856 	return (rv);
857 }
858 
859 int
860 __sigtimedwait(const sigset_t *set, siginfo_t *infop,
861 	const timespec_t *timeout)
862 {
863 	extern int ___sigtimedwait(const sigset_t *, siginfo_t *,
864 		const timespec_t *);
865 	siginfo_t info;
866 	int sig;
867 
868 	PROLOGUE
869 	sig = ___sigtimedwait(set, &info, timeout);
870 	if (sig == SIGCANCEL &&
871 	    (SI_FROMKERNEL(&info) || info.si_code == SI_LWP)) {
872 		do_sigcancel();
873 		errno = EINTR;
874 		sig = -1;
875 	}
876 	EPILOGUE
877 	if (sig != -1 && infop)
878 		(void) _private_memcpy(infop, &info, sizeof (*infop));
879 	return (sig);
880 }
881 
882 #pragma weak sigwait = _sigwait
883 int
884 _sigwait(sigset_t *set)
885 {
886 	return (__sigtimedwait(set, NULL, NULL));
887 }
888 
889 int
890 tcdrain(int fildes)
891 {
892 	extern int _tcdrain(int);
893 	int rv;
894 
895 	PERFORM(_tcdrain(fildes))
896 }
897 
898 pid_t
899 wait(int *stat_loc)
900 {
901 	extern pid_t _wait(int *);
902 	pid_t rv;
903 
904 	PERFORM(_wait(stat_loc))
905 }
906 
907 pid_t
908 wait3(int *statusp, int options, struct rusage *rusage)
909 {
910 	extern pid_t _wait3(int *, int, struct rusage *);
911 	pid_t rv;
912 
913 	PERFORM(_wait3(statusp, options, rusage))
914 }
915 
916 int
917 waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options)
918 {
919 	extern int _waitid(idtype_t, id_t, siginfo_t *, int);
920 	int rv;
921 
922 	PERFORM(_waitid(idtype, id, infop, options))
923 }
924 
925 /*
926  * waitpid_cancel() is a libc-private symbol for internal use
927  * where cancellation semantics is desired (see system()).
928  */
929 #pragma weak waitpid_cancel = waitpid
930 pid_t
931 waitpid(pid_t pid, int *stat_loc, int options)
932 {
933 	extern pid_t _waitpid(pid_t, int *, int);
934 	pid_t rv;
935 
936 	PERFORM(_waitpid(pid, stat_loc, options))
937 }
938 
939 ssize_t
940 writev(int fildes, const struct iovec *iov, int iovcnt)
941 {
942 	extern ssize_t _writev(int, const struct iovec *, int);
943 	ssize_t rv;
944 
945 	PERFORM(_writev(fildes, iov, iovcnt))
946 }
947