Home | History | Annotate | Line # | Download | only in libpthread
pthread_cancelstub.c revision 1.47
      1 /*	$NetBSD: pthread_cancelstub.c,v 1.47 2025/03/31 14:23:11 riastradh Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2002, 2007 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Nathan J. Williams and Andrew Doran.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE 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 BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /* Disable namespace mangling, Fortification is useless here anyway. */
     33 #undef _FORTIFY_SOURCE
     34 
     35 #include <sys/cdefs.h>
     36 __RCSID("$NetBSD: pthread_cancelstub.c,v 1.47 2025/03/31 14:23:11 riastradh Exp $");
     37 
     38 /* Need to use libc-private names for atomic operations. */
     39 #include "../../common/lib/libc/atomic/atomic_op_namespace.h"
     40 
     41 #ifndef lint
     42 
     43 
     44 /*
     45  * This is necessary because the names are always weak (they are not
     46  * POSIX functions).
     47  */
     48 #define	fsync_range	_fsync_range
     49 #define	pollts		_pollts
     50 
     51 /*
     52  * XXX this is necessary to get the prototypes for the __sigsuspend14
     53  * XXX and __msync13 internal names, instead of the application-visible
     54  * XXX sigsuspend and msync names. It's kind of gross, but we're pretty
     55  * XXX intimate with libc already.
     56  */
     57 #define __LIBC12_SOURCE__
     58 
     59 #include <sys/msg.h>
     60 #include <sys/types.h>
     61 #include <sys/uio.h>
     62 #include <sys/wait.h>
     63 #include <aio.h>
     64 #include <errno.h>
     65 #include <fcntl.h>
     66 #include <mqueue.h>
     67 #include <poll.h>
     68 #include <stdatomic.h>
     69 #include <stdarg.h>
     70 #include <termios.h>
     71 #include <unistd.h>
     72 
     73 #include <signal.h>
     74 #include <sys/mman.h>
     75 #include <sys/select.h>
     76 #include <sys/socket.h>
     77 #include <sys/event.h>
     78 #include <sys/resource.h>
     79 
     80 #include <compat/sys/mman.h>
     81 #include <compat/sys/poll.h>
     82 #include <compat/sys/select.h>
     83 #include <compat/sys/event.h>
     84 #include <compat/sys/wait.h>
     85 #include <compat/sys/resource.h>
     86 #include <compat/include/mqueue.h>
     87 #include <compat/include/signal.h>
     88 
     89 #include "pthread.h"
     90 #include "pthread_int.h"
     91 #include "reentrant.h"
     92 
     93 #define	atomic_load_relaxed(p)						      \
     94 	atomic_load_explicit(p, memory_order_relaxed)
     95 
     96 int	pthread__cancel_stub_binder;
     97 
     98 int	_sys_accept(int, struct sockaddr *, socklen_t *);
     99 int	_sys___aio_suspend50(const struct aiocb * const [], int,
    100 	    const struct timespec *);
    101 int	__aio_suspend50(const struct aiocb * const [], int,
    102 	    const struct timespec *);
    103 int	_sys_clock_nanosleep(clockid_t clock_id, int flags,
    104 		   const struct timespec *rqtp, struct timespec *rmtp);
    105 int	_sys_close(int);
    106 int	_sys_connect(int, const struct sockaddr *, socklen_t);
    107 int	_sys_fcntl(int, int, ...);
    108 int	_sys_fdatasync(int);
    109 int	_sys_fsync(int);
    110 int	_sys_fsync_range(int, int, off_t, off_t);
    111 int	_sys___kevent100(int, const struct kevent *, size_t, struct kevent *,
    112 	    size_t, const struct timespec *);
    113 int	_sys_mq_send(mqd_t, const char *, size_t, unsigned);
    114 ssize_t	_sys_mq_receive(mqd_t, char *, size_t, unsigned *);
    115 int	_sys___mq_timedsend50(mqd_t, const char *, size_t, unsigned,
    116 	    const struct timespec *);
    117 ssize_t	_sys___mq_timedreceive50(mqd_t, char *, size_t, unsigned *,
    118 	    const struct timespec *);
    119 ssize_t	_sys_msgrcv(int, void *, size_t, long, int);
    120 int	_sys_msgsnd(int, const void *, size_t, int);
    121 int	_sys___msync13(void *, size_t, int);
    122 int	_sys___nanosleep50(const struct timespec *, struct timespec *);
    123 int	__nanosleep50(const struct timespec *, struct timespec *);
    124 int	_sys_open(const char *, int, ...);
    125 int	_sys_openat(int, const char *, int, ...);
    126 int	_sys_paccept(int, struct sockaddr *, socklen_t *, int);
    127 int	_sys_poll(struct pollfd *, nfds_t, int);
    128 int	_sys___pollts50(struct pollfd *, nfds_t, const struct timespec *,
    129 	    const sigset_t *);
    130 ssize_t	_sys_pread(int, void *, size_t, off_t);
    131 int	_sys___pselect50(int, fd_set *, fd_set *, fd_set *,
    132 	    const struct timespec *, const sigset_t *);
    133 ssize_t	_sys_pwrite(int, const void *, size_t, off_t);
    134 ssize_t	_sys_read(int, void *, size_t);
    135 ssize_t	_sys_readv(int, const struct iovec *, int);
    136 ssize_t	_sys_recvfrom(int, void * restrict, size_t, int,
    137     struct sockaddr * restrict, socklen_t * restrict);
    138 ssize_t _sys_recvmsg(int, struct msghdr *, int);
    139 int _sys_recvmmsg(int, struct mmsghdr *, unsigned int, unsigned int,
    140     struct timespec *);
    141 ssize_t _sys_sendto(int, const void *, size_t, int, const struct sockaddr *,
    142     socklen_t);
    143 ssize_t _sys_sendmsg(int, const struct msghdr *, int);
    144 int _sys_sendmmsg(int, struct mmsghdr *, unsigned int, unsigned int);
    145 int	_sys___select50(int, fd_set *, fd_set *, fd_set *, struct timeval *);
    146 int	_sys___wait450(pid_t, int *, int, struct rusage *);
    147 ssize_t	_sys_write(int, const void *, size_t);
    148 ssize_t	_sys_writev(int, const struct iovec *, int);
    149 int	_sys___sigsuspend14(const sigset_t *);
    150 int	____sigtimedwait50(const sigset_t * __restrict, siginfo_t * __restrict,
    151 	    struct timespec * __restrict);
    152 int	__sigsuspend14(const sigset_t *);
    153 
    154 #define TESTCANCEL(id) 	do {						\
    155 	if (__predict_true(!__uselibcstub) &&				\
    156 	    __predict_false(atomic_load_relaxed(&(id)->pt_cancel) &	\
    157 		PT_CANCEL_CANCELLED)) {					\
    158 		membar_acquire();					\
    159 		pthread__cancelled();					\
    160 	}								\
    161 	} while (0)
    162 
    163 
    164 int
    165 accept(int s, struct sockaddr *addr, socklen_t *addrlen)
    166 {
    167 	int retval;
    168 	pthread_t self;
    169 
    170 	self = pthread__self();
    171 	TESTCANCEL(self);
    172 	retval = _sys_accept(s, addr, addrlen);
    173 	TESTCANCEL(self);
    174 
    175 	return retval;
    176 }
    177 
    178 int
    179 accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags)
    180 {
    181 	int retval;
    182 	pthread_t self;
    183 
    184 	self = pthread__self();
    185 	TESTCANCEL(self);
    186 	retval = _sys_paccept(s, addr, addrlen, flags);
    187 	TESTCANCEL(self);
    188 
    189 	return retval;
    190 }
    191 
    192 int
    193 __aio_suspend50(const struct aiocb * const list[], int nent,
    194     const struct timespec *timeout)
    195 {
    196 	int retval;
    197 	pthread_t self;
    198 
    199 	self = pthread__self();
    200 	TESTCANCEL(self);
    201 	retval = _sys___aio_suspend50(list, nent, timeout);
    202 	TESTCANCEL(self);
    203 
    204 	return retval;
    205 }
    206 
    207 int
    208 __kevent100(int fd, const struct kevent *ev, size_t nev, struct kevent *rev,
    209     size_t nrev, const struct timespec *ts)
    210 {
    211 	int retval;
    212 	pthread_t self;
    213 
    214 	self = pthread__self();
    215 	TESTCANCEL(self);
    216 	retval = _sys___kevent100(fd, ev, nev, rev, nrev, ts);
    217 	TESTCANCEL(self);
    218 
    219 	return retval;
    220 }
    221 
    222 int
    223 clock_nanosleep(clockid_t clock_id, int flags,
    224     const struct timespec *rqtp, struct timespec *rmtp)
    225 {
    226 	int retval;
    227 	pthread_t self;
    228 
    229 	self = pthread__self();
    230 	TESTCANCEL(self);
    231 	retval = _sys_clock_nanosleep(clock_id, flags, rqtp, rmtp);
    232 	TESTCANCEL(self);
    233 
    234 	return retval;
    235 }
    236 
    237 int
    238 close(int d)
    239 {
    240 	int retval;
    241 	pthread_t self;
    242 
    243 	self = pthread__self();
    244 	TESTCANCEL(self);
    245 	retval = _sys_close(d);
    246 	TESTCANCEL(self);
    247 
    248 	return retval;
    249 }
    250 
    251 int
    252 connect(int s, const struct sockaddr *addr, socklen_t namelen)
    253 {
    254 	int retval;
    255 	pthread_t self;
    256 
    257 	self = pthread__self();
    258 	TESTCANCEL(self);
    259 	retval = _sys_connect(s, addr, namelen);
    260 	TESTCANCEL(self);
    261 
    262 	return retval;
    263 }
    264 
    265 int
    266 fcntl(int fd, int cmd, ...)
    267 {
    268 	int retval;
    269 	pthread_t self;
    270 	va_list ap;
    271 
    272 	self = pthread__self();
    273 	TESTCANCEL(self);
    274 	va_start(ap, cmd);
    275 	retval = _sys_fcntl(fd, cmd, va_arg(ap, void *));
    276 	va_end(ap);
    277 	TESTCANCEL(self);
    278 
    279 	return retval;
    280 }
    281 
    282 int
    283 fdatasync(int d)
    284 {
    285 	int retval;
    286 	pthread_t self;
    287 
    288 	self = pthread__self();
    289 	TESTCANCEL(self);
    290 	retval = _sys_fdatasync(d);
    291 	TESTCANCEL(self);
    292 
    293 	return retval;
    294 }
    295 
    296 int
    297 fsync(int d)
    298 {
    299 	int retval;
    300 	pthread_t self;
    301 
    302 	self = pthread__self();
    303 	TESTCANCEL(self);
    304 	retval = _sys_fsync(d);
    305 	TESTCANCEL(self);
    306 
    307 	return retval;
    308 }
    309 
    310 int
    311 fsync_range(int d, int f, off_t s, off_t e)
    312 {
    313 	int retval;
    314 	pthread_t self;
    315 
    316 	self = pthread__self();
    317 	TESTCANCEL(self);
    318 	retval = _sys_fsync_range(d, f, s, e);
    319 	TESTCANCEL(self);
    320 
    321 	return retval;
    322 }
    323 
    324 int
    325 mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio)
    326 {
    327 	int retval;
    328 	pthread_t self;
    329 
    330 	self = pthread__self();
    331 	TESTCANCEL(self);
    332 	retval = _sys_mq_send(mqdes, msg_ptr, msg_len, msg_prio);
    333 	TESTCANCEL(self);
    334 
    335 	return retval;
    336 }
    337 
    338 ssize_t
    339 mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio)
    340 {
    341 	ssize_t retval;
    342 	pthread_t self;
    343 
    344 	self = pthread__self();
    345 	TESTCANCEL(self);
    346 	retval = _sys_mq_receive(mqdes, msg_ptr, msg_len, msg_prio);
    347 	TESTCANCEL(self);
    348 
    349 	return retval;
    350 }
    351 
    352 int
    353 __mq_timedsend50(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
    354     unsigned msg_prio, const struct timespec *abst)
    355 {
    356 	int retval;
    357 	pthread_t self;
    358 
    359 	self = pthread__self();
    360 	TESTCANCEL(self);
    361 	retval = _sys___mq_timedsend50(mqdes, msg_ptr, msg_len, msg_prio, abst);
    362 	TESTCANCEL(self);
    363 
    364 	return retval;
    365 }
    366 
    367 ssize_t
    368 __mq_timedreceive50(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio,
    369     const struct timespec *abst)
    370 {
    371 	ssize_t retval;
    372 	pthread_t self;
    373 
    374 	self = pthread__self();
    375 	TESTCANCEL(self);
    376 	retval = _sys___mq_timedreceive50(mqdes, msg_ptr, msg_len, msg_prio, abst);
    377 	TESTCANCEL(self);
    378 
    379 	return retval;
    380 }
    381 
    382 ssize_t
    383 msgrcv(int msgid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
    384 {
    385 	ssize_t retval;
    386 	pthread_t self;
    387 
    388 	self = pthread__self();
    389 	TESTCANCEL(self);
    390 	retval = _sys_msgrcv(msgid, msgp, msgsz, msgtyp, msgflg);
    391 	TESTCANCEL(self);
    392 
    393 	return retval;
    394 }
    395 
    396 int
    397 msgsnd(int msgid, const void *msgp, size_t msgsz, int msgflg)
    398 {
    399 	int retval;
    400 	pthread_t self;
    401 
    402 	self = pthread__self();
    403 	TESTCANCEL(self);
    404 	retval = _sys_msgsnd(msgid, msgp, msgsz, msgflg);
    405 	TESTCANCEL(self);
    406 
    407 	return retval;
    408 }
    409 
    410 int
    411 __msync13(void *addr, size_t len, int flags)
    412 {
    413 	int retval;
    414 	pthread_t self;
    415 
    416 	self = pthread__self();
    417 	TESTCANCEL(self);
    418 	retval = _sys___msync13(addr, len, flags);
    419 	TESTCANCEL(self);
    420 
    421 	return retval;
    422 }
    423 
    424 int
    425 open(const char *path, int flags, ...)
    426 {
    427 	int retval;
    428 	pthread_t self;
    429 	va_list ap;
    430 
    431 	self = pthread__self();
    432 	TESTCANCEL(self);
    433 	va_start(ap, flags);
    434 	retval = _sys_open(path, flags, va_arg(ap, mode_t));
    435 	va_end(ap);
    436 	TESTCANCEL(self);
    437 
    438 	return retval;
    439 }
    440 
    441 int
    442 openat(int fd, const char *path, int flags, ...)
    443 {
    444 	int retval;
    445 	pthread_t self;
    446 	va_list ap;
    447 
    448 	self = pthread__self();
    449 	TESTCANCEL(self);
    450 	va_start(ap, flags);
    451 	retval = _sys_openat(fd, path, flags, va_arg(ap, mode_t));
    452 	va_end(ap);
    453 	TESTCANCEL(self);
    454 
    455 	return retval;
    456 }
    457 
    458 int
    459 __nanosleep50(const struct timespec *rqtp, struct timespec *rmtp)
    460 {
    461 	int retval;
    462 	pthread_t self;
    463 
    464 	self = pthread__self();
    465 	TESTCANCEL(self);
    466 	/*
    467 	 * For now, just nanosleep.  In the future, maybe pass a ucontext_t
    468 	 * to _lwp_nanosleep() and allow it to recycle our kernel stack.
    469 	 */
    470 	retval = _sys___nanosleep50(rqtp, rmtp);
    471 	TESTCANCEL(self);
    472 
    473 	return retval;
    474 }
    475 
    476 int
    477 poll(struct pollfd *fds, nfds_t nfds, int timeout)
    478 {
    479 	int retval;
    480 	pthread_t self;
    481 
    482 	self = pthread__self();
    483 	TESTCANCEL(self);
    484 	retval = _sys_poll(fds, nfds, timeout);
    485 	TESTCANCEL(self);
    486 
    487 	return retval;
    488 }
    489 
    490 int
    491 __pollts50(struct pollfd *fds, nfds_t nfds, const struct timespec *ts,
    492     const sigset_t *sigmask)
    493 {
    494 	int retval;
    495 	pthread_t self;
    496 
    497 	self = pthread__self();
    498 	TESTCANCEL(self);
    499 	retval = _sys___pollts50(fds, nfds, ts, sigmask);
    500 	TESTCANCEL(self);
    501 
    502 	return retval;
    503 }
    504 
    505 ssize_t
    506 pread(int d, void *buf, size_t nbytes, off_t offset)
    507 {
    508 	ssize_t retval;
    509 	pthread_t self;
    510 
    511 	self = pthread__self();
    512 	TESTCANCEL(self);
    513 	retval = _sys_pread(d, buf, nbytes, offset);
    514 	TESTCANCEL(self);
    515 
    516 	return retval;
    517 }
    518 
    519 int
    520 __pselect50(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
    521     const struct timespec *timeout, const sigset_t *sigmask)
    522 {
    523 	int retval;
    524 	pthread_t self;
    525 
    526 	self = pthread__self();
    527 	TESTCANCEL(self);
    528 	retval = _sys___pselect50(nfds, readfds, writefds, exceptfds, timeout,
    529 	    sigmask);
    530 	TESTCANCEL(self);
    531 
    532 	return retval;
    533 }
    534 
    535 ssize_t
    536 pwrite(int d, const void *buf, size_t nbytes, off_t offset)
    537 {
    538 	ssize_t retval;
    539 	pthread_t self;
    540 
    541 	self = pthread__self();
    542 	TESTCANCEL(self);
    543 	retval = _sys_pwrite(d, buf, nbytes, offset);
    544 	TESTCANCEL(self);
    545 
    546 	return retval;
    547 }
    548 
    549 ssize_t
    550 read(int d, void *buf, size_t nbytes)
    551 {
    552 	ssize_t retval;
    553 	pthread_t self;
    554 
    555 	self = pthread__self();
    556 	TESTCANCEL(self);
    557 	retval = _sys_read(d, buf, nbytes);
    558 	TESTCANCEL(self);
    559 
    560 	return retval;
    561 }
    562 
    563 ssize_t
    564 readv(int d, const struct iovec *iov, int iovcnt)
    565 {
    566 	ssize_t retval;
    567 	pthread_t self;
    568 
    569 	self = pthread__self();
    570 	TESTCANCEL(self);
    571 	retval = _sys_readv(d, iov, iovcnt);
    572 	TESTCANCEL(self);
    573 
    574 	return retval;
    575 }
    576 
    577 ssize_t
    578 recvfrom(int s, void * restrict buf, size_t len, int flags,
    579     struct sockaddr * restrict from, socklen_t * restrict fromlen)
    580 {
    581 	ssize_t retval;
    582 	pthread_t self;
    583 
    584 	self = pthread__self();
    585 	TESTCANCEL(self);
    586 	retval = _sys_recvfrom(s, buf, len, flags, from, fromlen);
    587 	TESTCANCEL(self);
    588 
    589 	return retval;
    590 }
    591 
    592 ssize_t
    593 recvmsg(int s, struct msghdr *msg, int flags)
    594 {
    595 	ssize_t retval;
    596 	pthread_t self;
    597 
    598 	self = pthread__self();
    599 	TESTCANCEL(self);
    600 	retval = _sys_recvmsg(s, msg, flags);
    601 	TESTCANCEL(self);
    602 
    603 	return retval;
    604 }
    605 
    606 int
    607 recvmmsg(int s, struct mmsghdr *mmsg, unsigned int vlen,
    608     unsigned int flags, struct timespec *timeout)
    609 {
    610 	ssize_t retval;
    611 	pthread_t self;
    612 
    613 	self = pthread__self();
    614 	TESTCANCEL(self);
    615 	retval = _sys_recvmmsg(s, mmsg, vlen, flags, timeout);
    616 	TESTCANCEL(self);
    617 
    618 	return retval;
    619 }
    620 
    621 int
    622 __select50(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
    623     struct timeval *timeout)
    624 {
    625 	int retval;
    626 	pthread_t self;
    627 
    628 	self = pthread__self();
    629 	TESTCANCEL(self);
    630 	retval = _sys___select50(nfds, readfds, writefds, exceptfds, timeout);
    631 	TESTCANCEL(self);
    632 
    633 	return retval;
    634 }
    635 
    636 ssize_t
    637 sendto(int s, const void *msg, size_t len, int flags,
    638     const struct sockaddr *to, socklen_t tolen)
    639 {
    640 	int retval;
    641 	pthread_t self;
    642 
    643 	self = pthread__self();
    644 	TESTCANCEL(self);
    645 	retval = _sys_sendto(s, msg, len, flags, to, tolen);
    646 	TESTCANCEL(self);
    647 
    648 	return retval;
    649 }
    650 
    651 ssize_t
    652 sendmsg(int s, const struct msghdr *msg, int flags)
    653 {
    654 	int retval;
    655 	pthread_t self;
    656 
    657 	self = pthread__self();
    658 	TESTCANCEL(self);
    659 	retval = _sys_sendmsg(s, msg, flags);
    660 	TESTCANCEL(self);
    661 
    662 	return retval;
    663 }
    664 
    665 int
    666 sendmmsg(int s, struct mmsghdr *mmsg, unsigned int vlen,
    667     unsigned int flags)
    668 {
    669 	int retval;
    670 	pthread_t self;
    671 
    672 	self = pthread__self();
    673 	TESTCANCEL(self);
    674 	retval = _sys_sendmmsg(s, mmsg, vlen, flags);
    675 	TESTCANCEL(self);
    676 
    677 	return retval;
    678 }
    679 
    680 int
    681 tcdrain(int fd)
    682 {
    683 	int retval;
    684 	pthread_t self;
    685 
    686 	self = pthread__self();
    687 	TESTCANCEL(self);
    688 	retval = ioctl(fd, TIOCDRAIN, 0);
    689 	TESTCANCEL(self);
    690 
    691 	return retval;
    692 }
    693 
    694 pid_t
    695 __wait450(pid_t wpid, int *status, int options, struct rusage *rusage)
    696 {
    697 	pid_t retval;
    698 	pthread_t self;
    699 
    700 	self = pthread__self();
    701 	TESTCANCEL(self);
    702 	retval = _sys___wait450(wpid, status, options, rusage);
    703 	TESTCANCEL(self);
    704 
    705 	return retval;
    706 }
    707 
    708 ssize_t
    709 write(int d, const void *buf, size_t nbytes)
    710 {
    711 	ssize_t retval;
    712 	pthread_t self;
    713 
    714 	self = pthread__self();
    715 	TESTCANCEL(self);
    716 	retval = _sys_write(d, buf, nbytes);
    717 	TESTCANCEL(self);
    718 
    719 	return retval;
    720 }
    721 
    722 ssize_t
    723 writev(int d, const struct iovec *iov, int iovcnt)
    724 {
    725 	ssize_t retval;
    726 	pthread_t self;
    727 
    728 	self = pthread__self();
    729 	TESTCANCEL(self);
    730 	retval = _sys_writev(d, iov, iovcnt);
    731 	TESTCANCEL(self);
    732 
    733 	return retval;
    734 }
    735 
    736 int
    737 __sigsuspend14(const sigset_t *sigmask)
    738 {
    739 	pthread_t self;
    740 	int retval;
    741 
    742 	self = pthread__self();
    743 	TESTCANCEL(self);
    744 	retval = _sys___sigsuspend14(sigmask);
    745 	TESTCANCEL(self);
    746 
    747 	return retval;
    748 }
    749 
    750 int
    751 __sigtimedwait50(const sigset_t * __restrict set, siginfo_t * __restrict info,
    752     const struct timespec * __restrict timeout)
    753 {
    754 	pthread_t self;
    755 	int retval;
    756 	struct timespec tout, *tp;
    757 
    758 	if (timeout) {
    759 		tout = *timeout;
    760 		tp = &tout;
    761 	} else
    762 		tp = NULL;
    763 
    764 	self = pthread__self();
    765 	TESTCANCEL(self);
    766 	retval = ____sigtimedwait50(set, info, tp);
    767 	TESTCANCEL(self);
    768 
    769 	return retval;
    770 }
    771 
    772 int
    773 sigwait(const sigset_t * __restrict set, int * __restrict sig)
    774 {
    775 	pthread_t	self;
    776 	int		saved_errno;
    777 	int		new_errno;
    778 	int		retval;
    779 
    780 	self = pthread__self();
    781 	saved_errno = errno;
    782 	TESTCANCEL(self);
    783 	retval = ____sigtimedwait50(set, NULL, NULL);
    784 	TESTCANCEL(self);
    785 	new_errno = errno;
    786 	errno = saved_errno;
    787 	if (retval < 0) {
    788 		return new_errno;
    789 	}
    790 	*sig = retval;
    791 	return 0;
    792 }
    793 
    794 __strong_alias(_close, close)
    795 __strong_alias(_clock_nanosleep, clock_nanosleep)
    796 __strong_alias(_fcntl, fcntl)
    797 __strong_alias(_fdatasync, fdatasync)
    798 __strong_alias(_fsync, fsync)
    799 __weak_alias(fsync_range, _fsync_range)
    800 __strong_alias(_mq_send, mq_send)
    801 __strong_alias(_mq_receive, mq_receive)
    802 __strong_alias(_msgrcv, msgrcv)
    803 __strong_alias(_msgsnd, msgsnd)
    804 __strong_alias(___msync13, __msync13)
    805 __strong_alias(___nanosleep50, __nanosleep50)
    806 __strong_alias(_open, open)
    807 __strong_alias(_openat, openat)
    808 __strong_alias(_poll, poll)
    809 __strong_alias(_pread, pread)
    810 __strong_alias(_pwrite, pwrite)
    811 __strong_alias(_read, read)
    812 __strong_alias(_readv, readv)
    813 __strong_alias(_recvfrom, recvfrom)
    814 __strong_alias(_recvmsg, recvmsg)
    815 __strong_alias(_recvmmsg, recvmmsg)
    816 __strong_alias(_sendmsg, sendmsg)
    817 __strong_alias(_sendmmsg, sendmmsg)
    818 __strong_alias(_sendto, sendto)
    819 __strong_alias(_sigwait, sigwait)
    820 __strong_alias(_write, write)
    821 __strong_alias(_writev, writev)
    822 
    823 #endif	/* !lint */
    824