1 /*
2  * Copyright (C) 2005 David Xu <davidxu@freebsd.org>.
3  * Copyright (c) 2003 Daniel Eischen <deischen@freebsd.org>.
4  * Copyright (C) 2000 Jason Evans <jasone@freebsd.org>.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice(s), this list of conditions and the following disclaimer as
12  *    the first lines of this file unmodified other than the possible
13  *    addition of one or more copyright notices.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice(s), this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the
17  *    distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
20  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
26  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
28  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
34  * All rights reserved.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
39  * 1. Redistributions of source code must retain the above copyright
40  *    notice, this list of conditions and the following disclaimer.
41  * 2. Redistributions in binary form must reproduce the above copyright
42  *    notice, this list of conditions and the following disclaimer in the
43  *    documentation and/or other materials provided with the distribution.
44  * 3. Neither the name of the author nor the names of any co-contributors
45  *    may be used to endorse or promote products derived from this software
46  *    without specific prior written permission.
47  *
48  * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
49  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
52  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58  * SUCH DAMAGE.
59  *
60  */
61 
62 
63 #include "namespace.h"
64 #include <sys/types.h>
65 #include <sys/mman.h>
66 #include <sys/param.h>
67 #include <sys/select.h>
68 #include <sys/signalvar.h>
69 #include <sys/socket.h>
70 #include <sys/stat.h>
71 #include <sys/time.h>
72 #include <sys/uio.h>
73 #include <sys/wait.h>
74 #include <machine/tls.h>
75 #include <aio.h>
76 #include <dirent.h>
77 #include <errno.h>
78 #include <fcntl.h>
79 #include <poll.h>
80 #include <signal.h>
81 #include <stdarg.h>
82 #include <stdio.h>
83 #include <stdlib.h>
84 #include <string.h>
85 #include <termios.h>
86 #include <unistd.h>
87 #include <pthread.h>
88 #include "un-namespace.h"
89 
90 #include "thr_private.h"
91 
92 extern int	__creat(const char *, mode_t);
93 extern int	__pause(void);
94 extern int	__sys_pselect(int, fd_set *, fd_set *, fd_set *,
95 			const struct timespec *, const sigset_t *);
96 extern unsigned	__sleep(unsigned int);
97 extern int	__system(const char *);
98 extern int	__tcdrain(int);
99 extern int	__usleep(unsigned);
100 extern pid_t	__wait(int *);
101 extern pid_t	__waitpid(pid_t, int *, int);
102 extern int	__sys_aio_suspend(const struct aiocb * const[], int,
103 			const struct timespec *);
104 extern int	__sys_accept(int, struct sockaddr *, socklen_t *);
105 extern int	__sys_connect(int, const struct sockaddr *, socklen_t);
106 extern int	__sys_fsync(int);
107 extern int	__sys_msync(void *, size_t, int);
108 extern int	__sys_poll(struct pollfd *, unsigned, int);
109 extern int	__sys_ppoll(struct pollfd *, unsigned, const struct timespec *,
110 			const sigset_t *);
111 extern ssize_t	__sys_recv(int, void *, size_t, int);
112 extern ssize_t	__sys_recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *);
113 extern ssize_t	__sys_recvmsg(int, struct msghdr *, int);
114 extern int	__sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
115 extern int	__sys_sendfile(int, int, off_t, size_t, struct sf_hdtr *,
116 			off_t *, int);
117 extern ssize_t	__sys_sendmsg(int, const struct msghdr *, int);
118 extern ssize_t	__sys_sendto(int, const void *,size_t, int, const struct sockaddr *, socklen_t);
119 extern ssize_t	__sys_readv(int, const struct iovec *, int);
120 extern pid_t	__sys_wait4(pid_t, int *, int, struct rusage *);
121 extern ssize_t	__sys_writev(int, const struct iovec *, int);
122 
123 int	___creat(const char *, mode_t);
124 int	___usleep(unsigned);
125 int	__accept(int, struct sockaddr *, socklen_t *);
126 int	__close(int);
127 int	__connect(int, const struct sockaddr *, socklen_t);
128 int	__fcntl(int, int,...);
129 int	__fsync(int);
130 int	__msync(void *, size_t, int);
131 int	__nanosleep(const struct timespec *, struct timespec *);
132 int	__clock_nanosleep(clock_t, int, const struct timespec *,
133 		struct timespec *);
134 int	__open(const char *, int,...);
135 int	__openat(int fd, const char *, int,...);
136 int	__poll(struct pollfd *, unsigned int, int);
137 int	__ppoll(struct pollfd *, unsigned int, const struct timespec *,
138 		const sigset_t *);
139 ssize_t	__read(int, void *buf, size_t);
140 ssize_t	__readv(int, const struct iovec *, int);
141 ssize_t	__recvfrom(int, void *, size_t, int f, struct sockaddr *, socklen_t *);
142 ssize_t	__recvmsg(int, struct msghdr *, int);
143 int	__select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
144 ssize_t	__sendmsg(int, const struct msghdr *, int);
145 ssize_t	__sendto(int, const void *, size_t, int,
146 		const struct sockaddr *, socklen_t);
147 pid_t	__wait4(pid_t, int *, int, struct rusage *);
148 ssize_t	__write(int, const void *, size_t);
149 ssize_t	__writev(int, const struct iovec *, int);
150 int	_aio_suspend(const struct aiocb * const iocbs[], int,
151 		const struct timespec *);
152 int	_pause(void);
153 int	__pselect(int, fd_set *, fd_set *, fd_set *,
154 		const struct timespec *, const sigset_t *);
155 int	_raise(int);
156 unsigned	_sleep(unsigned);
157 int	_system(const char *);
158 int	_tcdrain(int);
159 #if 0
160 int	_vfork(void);
161 #endif
162 pid_t	_wait(int *);
163 
164 int
165 __accept(int s, struct sockaddr *addr, socklen_t *addrlen)
166 {
167 	pthread_t curthread;
168 	int oldcancel;
169 	int ret;
170 
171 	curthread = tls_get_curthread();
172 	oldcancel = _thr_cancel_enter(curthread);
173 	ret = __sys_accept(s, addr, addrlen);
174 	_thr_cancel_leave(curthread, oldcancel);
175 
176 	return (ret);
177 }
178 
179 __strong_reference(__accept, accept);
180 
181 int
182 _aio_suspend(const struct aiocb * const iocbs[], int niocb, const struct
183     timespec *timeout)
184 {
185 	pthread_t curthread = tls_get_curthread();
186 	int oldcancel;
187 	int ret;
188 
189 	oldcancel = _thr_cancel_enter(curthread);
190 	ret = __sys_aio_suspend(iocbs, niocb, timeout);
191 	_thr_cancel_leave(curthread, oldcancel);
192 
193 	return (ret);
194 }
195 
196 __strong_reference(_aio_suspend, aio_suspend);
197 
198 int
199 __close(int fd)
200 {
201 	pthread_t curthread = tls_get_curthread();
202 	int	oldcancel;
203 	int	ret;
204 
205 	oldcancel = _thr_cancel_enter(curthread);
206 	ret = __sys_close(fd);
207 	_thr_cancel_leave(curthread, oldcancel);
208 
209 	return (ret);
210 }
211 
212 __strong_reference(__close, close);
213 
214 int
215 __connect(int fd, const struct sockaddr *name, socklen_t namelen)
216 {
217 	pthread_t curthread = tls_get_curthread();
218 	int oldcancel;
219 	int ret;
220 
221 	oldcancel = _thr_cancel_enter(curthread);
222 	ret = __sys_connect(fd, name, namelen);
223 	_thr_cancel_leave(curthread, oldcancel);
224 
225 	return (ret);
226 }
227 
228 __strong_reference(__connect, connect);
229 
230 int
231 ___creat(const char *path, mode_t mode)
232 {
233 	pthread_t curthread = tls_get_curthread();
234 	int oldcancel;
235 	int ret;
236 
237 	oldcancel = _thr_cancel_enter(curthread);
238 	ret = __creat(path, mode);
239 	_thr_cancel_leave(curthread, oldcancel);
240 
241 	return ret;
242 }
243 
244 __strong_reference(___creat, creat);
245 
246 int
247 __fcntl(int fd, int cmd,...)
248 {
249 	pthread_t curthread = tls_get_curthread();
250 	int	oldcancel;
251 	int	ret;
252 	va_list	ap;
253 
254 	oldcancel = _thr_cancel_enter(curthread);
255 
256 	va_start(ap, cmd);
257 	switch (cmd) {
258 	case F_DUPFD:
259 		ret = __sys_fcntl(fd, cmd, va_arg(ap, int));
260 		break;
261 	case F_SETFD:
262 	case F_SETFL:
263 		ret = __sys_fcntl(fd, cmd, va_arg(ap, int));
264 		break;
265 	case F_GETFD:
266 	case F_GETFL:
267 		ret = __sys_fcntl(fd, cmd);
268 		break;
269 	default:
270 		ret = __sys_fcntl(fd, cmd, va_arg(ap, void *));
271 	}
272 	va_end(ap);
273 
274 	_thr_cancel_leave(curthread, oldcancel);
275 
276 	return (ret);
277 }
278 
279 __strong_reference(__fcntl, fcntl);
280 
281 int
282 __fsync(int fd)
283 {
284 	pthread_t curthread = tls_get_curthread();
285 	int	oldcancel;
286 	int	ret;
287 
288 	oldcancel = _thr_cancel_enter(curthread);
289 	ret = __sys_fsync(fd);
290 	_thr_cancel_leave(curthread, oldcancel);
291 
292 	return (ret);
293 }
294 
295 __strong_reference(__fsync, fsync);
296 
297 int
298 __msync(void *addr, size_t len, int flags)
299 {
300 	pthread_t curthread = tls_get_curthread();
301 	int	oldcancel;
302 	int	ret;
303 
304 	oldcancel = _thr_cancel_enter(curthread);
305 	ret = __sys_msync(addr, len, flags);
306 	_thr_cancel_leave(curthread, oldcancel);
307 
308 	return ret;
309 }
310 
311 __strong_reference(__msync, msync);
312 
313 int
314 __nanosleep(const struct timespec *time_to_sleep,
315     struct timespec *time_remaining)
316 {
317 	pthread_t curthread = tls_get_curthread();
318 	int		oldcancel;
319 	int		ret;
320 
321 	oldcancel = _thr_cancel_enter(curthread);
322 	ret = __sys_nanosleep(time_to_sleep, time_remaining);
323 	_thr_cancel_leave(curthread, oldcancel);
324 
325 	return (ret);
326 }
327 
328 __strong_reference(__nanosleep, nanosleep);
329 
330 int
331 __clock_nanosleep(clock_t clock_id, int flags,
332     const struct timespec *time_to_sleep, struct timespec *time_remaining)
333 {
334 	pthread_t curthread = tls_get_curthread();
335 	int		oldcancel;
336 	int		ret;
337 
338 	oldcancel = _thr_cancel_enter(curthread);
339 	ret = __sys_clock_nanosleep(clock_id, flags, time_to_sleep,
340 			time_remaining);
341 	_thr_cancel_leave(curthread, oldcancel);
342 
343 	return (ret);
344 }
345 
346 __strong_reference(__clock_nanosleep, clock_nanosleep);
347 
348 int
349 __open(const char *path, int flags,...)
350 {
351 	pthread_t curthread = tls_get_curthread();
352 	int	oldcancel;
353 	int	ret;
354 	int	mode = 0;
355 	va_list	ap;
356 
357 	oldcancel = _thr_cancel_enter(curthread);
358 
359 	/* Check if the file is being created: */
360 	if (flags & O_CREAT) {
361 		/* Get the creation mode: */
362 		va_start(ap, flags);
363 		mode = va_arg(ap, int);
364 		va_end(ap);
365 	}
366 
367 	ret = __sys_open(path, flags, mode);
368 
369 	_thr_cancel_leave(curthread, oldcancel);
370 
371 	return ret;
372 }
373 
374 __strong_reference(__open, open);
375 
376 int
377 __openat(int fd, const char *path, int flags,...)
378 {
379 	pthread_t curthread = tls_get_curthread();
380 	int	oldcancel;
381 	int	ret;
382 	int	mode = 0;
383 	va_list	ap;
384 
385 	oldcancel = _thr_cancel_enter(curthread);
386 
387 	/* Check if the file is being created: */
388 	if (flags & O_CREAT) {
389 		/* Get the creation mode: */
390 		va_start(ap, flags);
391 		mode = va_arg(ap, int);
392 		va_end(ap);
393 	}
394 
395 	ret = __sys_openat(fd, path, flags, mode);
396 
397 	_thr_cancel_leave(curthread, oldcancel);
398 
399 	return ret;
400 }
401 
402 __strong_reference(__openat, openat);
403 
404 int
405 _pause(void)
406 {
407 	pthread_t curthread = tls_get_curthread();
408 	int	oldcancel;
409 	int	ret;
410 
411 	oldcancel = _thr_cancel_enter(curthread);
412 	ret = __pause();
413 	_thr_cancel_leave(curthread, oldcancel);
414 
415 	return ret;
416 }
417 
418 __strong_reference(_pause, pause);
419 
420 int
421 __poll(struct pollfd *fds, unsigned int nfds, int timeout)
422 {
423 	pthread_t curthread = tls_get_curthread();
424 	int oldcancel;
425 	int ret;
426 
427 	oldcancel = _thr_cancel_enter(curthread);
428 	ret = __sys_poll(fds, nfds, timeout);
429 	_thr_cancel_leave(curthread, oldcancel);
430 
431 	return ret;
432 }
433 
434 __strong_reference(__poll, poll);
435 
436 int
437 __ppoll(struct pollfd *fds, unsigned int nfds, const struct timespec *ts,
438 	const sigset_t *mask)
439 {
440 	pthread_t curthread = tls_get_curthread();
441 	int oldcancel;
442 	int ret;
443 
444 	oldcancel = _thr_cancel_enter(curthread);
445 	ret = __sys_ppoll(fds, nfds, ts, mask);
446 	_thr_cancel_leave(curthread, oldcancel);
447 
448 	return ret;
449 }
450 
451 __strong_reference(__ppoll, ppoll);
452 
453 int
454 __pselect(int count, fd_set *rfds, fd_set *wfds, fd_set *efds,
455 	const struct timespec *timo, const sigset_t *mask)
456 {
457 	pthread_t curthread = tls_get_curthread();
458 	int oldcancel;
459 	int ret;
460 
461 	oldcancel = _thr_cancel_enter(curthread);
462 	ret = __sys_pselect(count, rfds, wfds, efds, timo, mask);
463 	_thr_cancel_leave(curthread, oldcancel);
464 
465 	return (ret);
466 }
467 __strong_reference(__pselect, pselect);
468 
469 
470 int
471 _raise(int sig)
472 {
473 	int ret;
474 
475 	if (!_thr_isthreaded())
476 		ret = kill(getpid(), sig);
477 	else
478 		ret = _thr_send_sig(tls_get_curthread(), sig);
479 	return (ret);
480 }
481 
482 __strong_reference(_raise, raise);
483 
484 ssize_t
485 __read(int fd, void *buf, size_t nbytes)
486 {
487 	pthread_t curthread = tls_get_curthread();
488 	int oldcancel;
489 	ssize_t	ret;
490 
491 	oldcancel = _thr_cancel_enter(curthread);
492 	ret = __sys_read(fd, buf, nbytes);
493 	_thr_cancel_leave(curthread, oldcancel);
494 	return ret;
495 }
496 
497 __strong_reference(__read, read);
498 
499 ssize_t
500 __readv(int fd, const struct iovec *iov, int iovcnt)
501 {
502 	pthread_t curthread = tls_get_curthread();
503 	int oldcancel;
504 	ssize_t ret;
505 
506 	oldcancel = _thr_cancel_enter(curthread);
507 	ret = __sys_readv(fd, iov, iovcnt);
508 	_thr_cancel_leave(curthread, oldcancel);
509 	return ret;
510 }
511 
512 __strong_reference(__readv, readv);
513 
514 ssize_t
515 __recvfrom(int s, void *b, size_t l, int f, struct sockaddr *from,
516     socklen_t *fl)
517 {
518 	pthread_t curthread = tls_get_curthread();
519 	int oldcancel;
520 	ssize_t ret;
521 
522 	oldcancel = _thr_cancel_enter(curthread);
523 	ret = __sys_recvfrom(s, b, l, f, from, fl);
524 	_thr_cancel_leave(curthread, oldcancel);
525 	return (ret);
526 }
527 
528 __strong_reference(__recvfrom, recvfrom);
529 
530 ssize_t
531 __recvmsg(int s, struct msghdr *m, int f)
532 {
533 	pthread_t curthread = tls_get_curthread();
534 	ssize_t ret;
535 	int oldcancel;
536 
537 	oldcancel = _thr_cancel_enter(curthread);
538 	ret = __sys_recvmsg(s, m, f);
539 	_thr_cancel_leave(curthread, oldcancel);
540 	return (ret);
541 }
542 
543 __strong_reference(__recvmsg, recvmsg);
544 
545 int
546 __select(int numfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
547 	struct timeval *timeout)
548 {
549 	pthread_t curthread = tls_get_curthread();
550 	int oldcancel;
551 	int ret;
552 
553 	oldcancel = _thr_cancel_enter(curthread);
554 	ret = __sys_select(numfds, readfds, writefds, exceptfds, timeout);
555 	_thr_cancel_leave(curthread, oldcancel);
556 	return ret;
557 }
558 
559 __strong_reference(__select, select);
560 
561 ssize_t
562 __sendmsg(int s, const struct msghdr *m, int f)
563 {
564 	pthread_t curthread = tls_get_curthread();
565 	ssize_t ret;
566 	int oldcancel;
567 
568 	oldcancel = _thr_cancel_enter(curthread);
569 	ret = __sys_sendmsg(s, m, f);
570 	_thr_cancel_leave(curthread, oldcancel);
571 	return (ret);
572 }
573 
574 __strong_reference(__sendmsg, sendmsg);
575 
576 ssize_t
577 __sendto(int s, const void *m, size_t l, int f, const struct sockaddr *t,
578     socklen_t tl)
579 {
580 	pthread_t curthread = tls_get_curthread();
581 	ssize_t ret;
582 	int oldcancel;
583 
584 	oldcancel = _thr_cancel_enter(curthread);
585 	ret = __sys_sendto(s, m, l, f, t, tl);
586 	_thr_cancel_leave(curthread, oldcancel);
587 	return (ret);
588 }
589 
590 __strong_reference(__sendto, sendto);
591 
592 unsigned int
593 _sleep(unsigned int seconds)
594 {
595 	pthread_t	curthread = tls_get_curthread();
596 	int		oldcancel;
597 	unsigned int	ret;
598 
599 	oldcancel = _thr_cancel_enter(curthread);
600 	ret = __sleep(seconds);
601 	_thr_cancel_leave(curthread, oldcancel);
602 	return (ret);
603 }
604 
605 __strong_reference(_sleep, sleep);
606 
607 int
608 _system(const char *string)
609 {
610 	pthread_t curthread = tls_get_curthread();
611 	int	oldcancel;
612 	int	ret;
613 
614 	oldcancel = _thr_cancel_enter(curthread);
615 	ret = __system(string);
616 	_thr_cancel_leave(curthread, oldcancel);
617 	return ret;
618 }
619 
620 __strong_reference(_system, system);
621 
622 int
623 _tcdrain(int fd)
624 {
625 	pthread_t curthread = tls_get_curthread();
626 	int	oldcancel;
627 	int	ret;
628 
629 	oldcancel = _thr_cancel_enter(curthread);
630 	ret = __tcdrain(fd);
631 	_thr_cancel_leave(curthread, oldcancel);
632 	return (ret);
633 }
634 
635 __strong_reference(_tcdrain, tcdrain);
636 
637 int
638 ___usleep(unsigned int useconds)
639 {
640 	pthread_t	curthread = tls_get_curthread();
641 	int		oldcancel;
642 	int		ret;
643 
644 	oldcancel = _thr_cancel_enter(curthread);
645 	ret = __usleep(useconds);
646 	_thr_cancel_leave(curthread, oldcancel);
647 	return (ret);
648 }
649 
650 __strong_reference(___usleep, usleep);
651 
652 #if 0
653 /*
654  * REMOVED - vfork() works as per normal.  In a threaded environment vfork()
655  *	     blocks the calling thread only and not other threads.
656  */
657 int
658 _vfork(void)
659 {
660 	return (fork());
661 }
662 
663 __strong_reference(_vfork, vfork);
664 #endif
665 
666 pid_t
667 _wait(int *istat)
668 {
669 	pthread_t curthread = tls_get_curthread();
670 	int	oldcancel;
671 	pid_t	ret;
672 
673 	oldcancel = _thr_cancel_enter(curthread);
674 	ret = __wait(istat);
675 	_thr_cancel_leave(curthread, oldcancel);
676 	return ret;
677 }
678 
679 __strong_reference(_wait, wait);
680 
681 pid_t
682 __wait4(pid_t pid, int *istat, int options, struct rusage *rusage)
683 {
684 	pthread_t curthread = tls_get_curthread();
685 	int oldcancel;
686 	pid_t ret;
687 
688 	oldcancel = _thr_cancel_enter(curthread);
689 	ret = __sys_wait4(pid, istat, options, rusage);
690 	_thr_cancel_leave(curthread, oldcancel);
691 	return ret;
692 }
693 
694 __strong_reference(__wait4, wait4);
695 
696 pid_t
697 _waitpid(pid_t wpid, int *status, int options)
698 {
699 	pthread_t curthread = tls_get_curthread();
700 	int	oldcancel;
701 	pid_t	ret;
702 
703 	oldcancel = _thr_cancel_enter(curthread);
704 	ret = __waitpid(wpid, status, options);
705 	_thr_cancel_leave(curthread, oldcancel);
706 	return ret;
707 }
708 
709 __strong_reference(_waitpid, waitpid);
710 
711 ssize_t
712 __write(int fd, const void *buf, size_t nbytes)
713 {
714 	pthread_t curthread = tls_get_curthread();
715 	int	oldcancel;
716 	ssize_t	ret;
717 
718 	oldcancel = _thr_cancel_enter(curthread);
719 	ret = __sys_write(fd, buf, nbytes);
720 	_thr_cancel_leave(curthread, oldcancel);
721 	return ret;
722 }
723 
724 __strong_reference(__write, write);
725 
726 ssize_t
727 __writev(int fd, const struct iovec *iov, int iovcnt)
728 {
729 	pthread_t curthread = tls_get_curthread();
730 	int	oldcancel;
731 	ssize_t ret;
732 
733 	oldcancel = _thr_cancel_enter(curthread);
734 	ret = __sys_writev(fd, iov, iovcnt);
735 	_thr_cancel_leave(curthread, oldcancel);
736 	return ret;
737 }
738 
739 __strong_reference(__writev, writev);
740