Home | History | Annotate | Line # | Download | only in libpthread
pthread_cancelstub.c revision 1.48
      1 /*	$NetBSD: pthread_cancelstub.c,v 1.48 2025/04/02 17:18:44 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.48 2025/04/02 17:18:44 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 *, const sigset_t *,
    127 	    int);
    128 int	_sys_poll(struct pollfd *, nfds_t, int);
    129 int	_sys___pollts50(struct pollfd *, nfds_t, const struct timespec *,
    130 	    const sigset_t *);
    131 ssize_t	_sys_pread(int, void *, size_t, off_t);
    132 int	_sys___pselect50(int, fd_set *, fd_set *, fd_set *,
    133 	    const struct timespec *, const sigset_t *);
    134 ssize_t	_sys_pwrite(int, const void *, size_t, off_t);
    135 ssize_t	_sys_read(int, void *, size_t);
    136 ssize_t	_sys_readv(int, const struct iovec *, int);
    137 ssize_t	_sys_recvfrom(int, void * restrict, size_t, int,
    138     struct sockaddr * restrict, socklen_t * restrict);
    139 ssize_t _sys_recvmsg(int, struct msghdr *, int);
    140 int _sys_recvmmsg(int, struct mmsghdr *, unsigned int, unsigned int,
    141     struct timespec *);
    142 ssize_t _sys_sendto(int, const void *, size_t, int, const struct sockaddr *,
    143     socklen_t);
    144 ssize_t _sys_sendmsg(int, const struct msghdr *, int);
    145 int _sys_sendmmsg(int, struct mmsghdr *, unsigned int, unsigned int);
    146 int	_sys___select50(int, fd_set *, fd_set *, fd_set *, struct timeval *);
    147 int	_sys___wait450(pid_t, int *, int, struct rusage *);
    148 ssize_t	_sys_write(int, const void *, size_t);
    149 ssize_t	_sys_writev(int, const struct iovec *, int);
    150 int	_sys___sigsuspend14(const sigset_t *);
    151 int	____sigtimedwait50(const sigset_t * __restrict, siginfo_t * __restrict,
    152 	    struct timespec * __restrict);
    153 int	__sigsuspend14(const sigset_t *);
    154 
    155 #define TESTCANCEL(id) 	do {						\
    156 	if (__predict_true(!__uselibcstub) &&				\
    157 	    __predict_false(atomic_load_relaxed(&(id)->pt_cancel) &	\
    158 		PT_CANCEL_CANCELLED)) {					\
    159 		membar_acquire();					\
    160 		pthread__cancelled();					\
    161 	}								\
    162 	} while (0)
    163 
    164 
    165 int
    166 accept(int s, struct sockaddr *addr, socklen_t *addrlen)
    167 {
    168 	int retval;
    169 	pthread_t self;
    170 
    171 	self = pthread__self();
    172 	TESTCANCEL(self);
    173 	retval = _sys_accept(s, addr, addrlen);
    174 	TESTCANCEL(self);
    175 
    176 	return retval;
    177 }
    178 
    179 int
    180 accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags)
    181 {
    182 	int retval;
    183 	pthread_t self;
    184 
    185 	self = pthread__self();
    186 	TESTCANCEL(self);
    187 	retval = _sys_paccept(s, addr, addrlen, NULL, flags);
    188 	TESTCANCEL(self);
    189 
    190 	return retval;
    191 }
    192 
    193 int
    194 __aio_suspend50(const struct aiocb * const list[], int nent,
    195     const struct timespec *timeout)
    196 {
    197 	int retval;
    198 	pthread_t self;
    199 
    200 	self = pthread__self();
    201 	TESTCANCEL(self);
    202 	retval = _sys___aio_suspend50(list, nent, timeout);
    203 	TESTCANCEL(self);
    204 
    205 	return retval;
    206 }
    207 
    208 int
    209 __kevent100(int fd, const struct kevent *ev, size_t nev, struct kevent *rev,
    210     size_t nrev, const struct timespec *ts)
    211 {
    212 	int retval;
    213 	pthread_t self;
    214 
    215 	self = pthread__self();
    216 	TESTCANCEL(self);
    217 	retval = _sys___kevent100(fd, ev, nev, rev, nrev, ts);
    218 	TESTCANCEL(self);
    219 
    220 	return retval;
    221 }
    222 
    223 int
    224 clock_nanosleep(clockid_t clock_id, int flags,
    225     const struct timespec *rqtp, struct timespec *rmtp)
    226 {
    227 	int retval;
    228 	pthread_t self;
    229 
    230 	self = pthread__self();
    231 	TESTCANCEL(self);
    232 	retval = _sys_clock_nanosleep(clock_id, flags, rqtp, rmtp);
    233 	TESTCANCEL(self);
    234 
    235 	return retval;
    236 }
    237 
    238 int
    239 close(int d)
    240 {
    241 	int retval;
    242 	pthread_t self;
    243 
    244 	self = pthread__self();
    245 	TESTCANCEL(self);
    246 	retval = _sys_close(d);
    247 	TESTCANCEL(self);
    248 
    249 	return retval;
    250 }
    251 
    252 int
    253 connect(int s, const struct sockaddr *addr, socklen_t namelen)
    254 {
    255 	int retval;
    256 	pthread_t self;
    257 
    258 	self = pthread__self();
    259 	TESTCANCEL(self);
    260 	retval = _sys_connect(s, addr, namelen);
    261 	TESTCANCEL(self);
    262 
    263 	return retval;
    264 }
    265 
    266 int
    267 fcntl(int fd, int cmd, ...)
    268 {
    269 	int retval;
    270 	pthread_t self;
    271 	va_list ap;
    272 
    273 	self = pthread__self();
    274 	TESTCANCEL(self);
    275 	va_start(ap, cmd);
    276 	retval = _sys_fcntl(fd, cmd, va_arg(ap, void *));
    277 	va_end(ap);
    278 	TESTCANCEL(self);
    279 
    280 	return retval;
    281 }
    282 
    283 int
    284 fdatasync(int d)
    285 {
    286 	int retval;
    287 	pthread_t self;
    288 
    289 	self = pthread__self();
    290 	TESTCANCEL(self);
    291 	retval = _sys_fdatasync(d);
    292 	TESTCANCEL(self);
    293 
    294 	return retval;
    295 }
    296 
    297 int
    298 fsync(int d)
    299 {
    300 	int retval;
    301 	pthread_t self;
    302 
    303 	self = pthread__self();
    304 	TESTCANCEL(self);
    305 	retval = _sys_fsync(d);
    306 	TESTCANCEL(self);
    307 
    308 	return retval;
    309 }
    310 
    311 int
    312 fsync_range(int d, int f, off_t s, off_t e)
    313 {
    314 	int retval;
    315 	pthread_t self;
    316 
    317 	self = pthread__self();
    318 	TESTCANCEL(self);
    319 	retval = _sys_fsync_range(d, f, s, e);
    320 	TESTCANCEL(self);
    321 
    322 	return retval;
    323 }
    324 
    325 int
    326 mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio)
    327 {
    328 	int retval;
    329 	pthread_t self;
    330 
    331 	self = pthread__self();
    332 	TESTCANCEL(self);
    333 	retval = _sys_mq_send(mqdes, msg_ptr, msg_len, msg_prio);
    334 	TESTCANCEL(self);
    335 
    336 	return retval;
    337 }
    338 
    339 ssize_t
    340 mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio)
    341 {
    342 	ssize_t retval;
    343 	pthread_t self;
    344 
    345 	self = pthread__self();
    346 	TESTCANCEL(self);
    347 	retval = _sys_mq_receive(mqdes, msg_ptr, msg_len, msg_prio);
    348 	TESTCANCEL(self);
    349 
    350 	return retval;
    351 }
    352 
    353 int
    354 __mq_timedsend50(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
    355     unsigned msg_prio, const struct timespec *abst)
    356 {
    357 	int retval;
    358 	pthread_t self;
    359 
    360 	self = pthread__self();
    361 	TESTCANCEL(self);
    362 	retval = _sys___mq_timedsend50(mqdes, msg_ptr, msg_len, msg_prio, abst);
    363 	TESTCANCEL(self);
    364 
    365 	return retval;
    366 }
    367 
    368 ssize_t
    369 __mq_timedreceive50(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio,
    370     const struct timespec *abst)
    371 {
    372 	ssize_t retval;
    373 	pthread_t self;
    374 
    375 	self = pthread__self();
    376 	TESTCANCEL(self);
    377 	retval = _sys___mq_timedreceive50(mqdes, msg_ptr, msg_len, msg_prio, abst);
    378 	TESTCANCEL(self);
    379 
    380 	return retval;
    381 }
    382 
    383 ssize_t
    384 msgrcv(int msgid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
    385 {
    386 	ssize_t retval;
    387 	pthread_t self;
    388 
    389 	self = pthread__self();
    390 	TESTCANCEL(self);
    391 	retval = _sys_msgrcv(msgid, msgp, msgsz, msgtyp, msgflg);
    392 	TESTCANCEL(self);
    393 
    394 	return retval;
    395 }
    396 
    397 int
    398 msgsnd(int msgid, const void *msgp, size_t msgsz, int msgflg)
    399 {
    400 	int retval;
    401 	pthread_t self;
    402 
    403 	self = pthread__self();
    404 	TESTCANCEL(self);
    405 	retval = _sys_msgsnd(msgid, msgp, msgsz, msgflg);
    406 	TESTCANCEL(self);
    407 
    408 	return retval;
    409 }
    410 
    411 int
    412 __msync13(void *addr, size_t len, int flags)
    413 {
    414 	int retval;
    415 	pthread_t self;
    416 
    417 	self = pthread__self();
    418 	TESTCANCEL(self);
    419 	retval = _sys___msync13(addr, len, flags);
    420 	TESTCANCEL(self);
    421 
    422 	return retval;
    423 }
    424 
    425 int
    426 open(const char *path, int flags, ...)
    427 {
    428 	int retval;
    429 	pthread_t self;
    430 	va_list ap;
    431 
    432 	self = pthread__self();
    433 	TESTCANCEL(self);
    434 	va_start(ap, flags);
    435 	retval = _sys_open(path, flags, va_arg(ap, mode_t));
    436 	va_end(ap);
    437 	TESTCANCEL(self);
    438 
    439 	return retval;
    440 }
    441 
    442 int
    443 openat(int fd, const char *path, int flags, ...)
    444 {
    445 	int retval;
    446 	pthread_t self;
    447 	va_list ap;
    448 
    449 	self = pthread__self();
    450 	TESTCANCEL(self);
    451 	va_start(ap, flags);
    452 	retval = _sys_openat(fd, path, flags, va_arg(ap, mode_t));
    453 	va_end(ap);
    454 	TESTCANCEL(self);
    455 
    456 	return retval;
    457 }
    458 
    459 int
    460 __nanosleep50(const struct timespec *rqtp, struct timespec *rmtp)
    461 {
    462 	int retval;
    463 	pthread_t self;
    464 
    465 	self = pthread__self();
    466 	TESTCANCEL(self);
    467 	/*
    468 	 * For now, just nanosleep.  In the future, maybe pass a ucontext_t
    469 	 * to _lwp_nanosleep() and allow it to recycle our kernel stack.
    470 	 */
    471 	retval = _sys___nanosleep50(rqtp, rmtp);
    472 	TESTCANCEL(self);
    473 
    474 	return retval;
    475 }
    476 
    477 int
    478 poll(struct pollfd *fds, nfds_t nfds, int timeout)
    479 {
    480 	int retval;
    481 	pthread_t self;
    482 
    483 	self = pthread__self();
    484 	TESTCANCEL(self);
    485 	retval = _sys_poll(fds, nfds, timeout);
    486 	TESTCANCEL(self);
    487 
    488 	return retval;
    489 }
    490 
    491 int
    492 __pollts50(struct pollfd *fds, nfds_t nfds, const struct timespec *ts,
    493     const sigset_t *sigmask)
    494 {
    495 	int retval;
    496 	pthread_t self;
    497 
    498 	self = pthread__self();
    499 	TESTCANCEL(self);
    500 	retval = _sys___pollts50(fds, nfds, ts, sigmask);
    501 	TESTCANCEL(self);
    502 
    503 	return retval;
    504 }
    505 
    506 ssize_t
    507 pread(int d, void *buf, size_t nbytes, off_t offset)
    508 {
    509 	ssize_t retval;
    510 	pthread_t self;
    511 
    512 	self = pthread__self();
    513 	TESTCANCEL(self);
    514 	retval = _sys_pread(d, buf, nbytes, offset);
    515 	TESTCANCEL(self);
    516 
    517 	return retval;
    518 }
    519 
    520 int
    521 __pselect50(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
    522     const struct timespec *timeout, const sigset_t *sigmask)
    523 {
    524 	int retval;
    525 	pthread_t self;
    526 
    527 	self = pthread__self();
    528 	TESTCANCEL(self);
    529 	retval = _sys___pselect50(nfds, readfds, writefds, exceptfds, timeout,
    530 	    sigmask);
    531 	TESTCANCEL(self);
    532 
    533 	return retval;
    534 }
    535 
    536 ssize_t
    537 pwrite(int d, const void *buf, size_t nbytes, off_t offset)
    538 {
    539 	ssize_t retval;
    540 	pthread_t self;
    541 
    542 	self = pthread__self();
    543 	TESTCANCEL(self);
    544 	retval = _sys_pwrite(d, buf, nbytes, offset);
    545 	TESTCANCEL(self);
    546 
    547 	return retval;
    548 }
    549 
    550 ssize_t
    551 read(int d, void *buf, size_t nbytes)
    552 {
    553 	ssize_t retval;
    554 	pthread_t self;
    555 
    556 	self = pthread__self();
    557 	TESTCANCEL(self);
    558 	retval = _sys_read(d, buf, nbytes);
    559 	TESTCANCEL(self);
    560 
    561 	return retval;
    562 }
    563 
    564 ssize_t
    565 readv(int d, const struct iovec *iov, int iovcnt)
    566 {
    567 	ssize_t retval;
    568 	pthread_t self;
    569 
    570 	self = pthread__self();
    571 	TESTCANCEL(self);
    572 	retval = _sys_readv(d, iov, iovcnt);
    573 	TESTCANCEL(self);
    574 
    575 	return retval;
    576 }
    577 
    578 ssize_t
    579 recvfrom(int s, void * restrict buf, size_t len, int flags,
    580     struct sockaddr * restrict from, socklen_t * restrict fromlen)
    581 {
    582 	ssize_t retval;
    583 	pthread_t self;
    584 
    585 	self = pthread__self();
    586 	TESTCANCEL(self);
    587 	retval = _sys_recvfrom(s, buf, len, flags, from, fromlen);
    588 	TESTCANCEL(self);
    589 
    590 	return retval;
    591 }
    592 
    593 ssize_t
    594 recvmsg(int s, struct msghdr *msg, int flags)
    595 {
    596 	ssize_t retval;
    597 	pthread_t self;
    598 
    599 	self = pthread__self();
    600 	TESTCANCEL(self);
    601 	retval = _sys_recvmsg(s, msg, flags);
    602 	TESTCANCEL(self);
    603 
    604 	return retval;
    605 }
    606 
    607 int
    608 recvmmsg(int s, struct mmsghdr *mmsg, unsigned int vlen,
    609     unsigned int flags, struct timespec *timeout)
    610 {
    611 	ssize_t retval;
    612 	pthread_t self;
    613 
    614 	self = pthread__self();
    615 	TESTCANCEL(self);
    616 	retval = _sys_recvmmsg(s, mmsg, vlen, flags, timeout);
    617 	TESTCANCEL(self);
    618 
    619 	return retval;
    620 }
    621 
    622 int
    623 __select50(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
    624     struct timeval *timeout)
    625 {
    626 	int retval;
    627 	pthread_t self;
    628 
    629 	self = pthread__self();
    630 	TESTCANCEL(self);
    631 	retval = _sys___select50(nfds, readfds, writefds, exceptfds, timeout);
    632 	TESTCANCEL(self);
    633 
    634 	return retval;
    635 }
    636 
    637 ssize_t
    638 sendto(int s, const void *msg, size_t len, int flags,
    639     const struct sockaddr *to, socklen_t tolen)
    640 {
    641 	int retval;
    642 	pthread_t self;
    643 
    644 	self = pthread__self();
    645 	TESTCANCEL(self);
    646 	retval = _sys_sendto(s, msg, len, flags, to, tolen);
    647 	TESTCANCEL(self);
    648 
    649 	return retval;
    650 }
    651 
    652 ssize_t
    653 sendmsg(int s, const struct msghdr *msg, int flags)
    654 {
    655 	int retval;
    656 	pthread_t self;
    657 
    658 	self = pthread__self();
    659 	TESTCANCEL(self);
    660 	retval = _sys_sendmsg(s, msg, flags);
    661 	TESTCANCEL(self);
    662 
    663 	return retval;
    664 }
    665 
    666 int
    667 sendmmsg(int s, struct mmsghdr *mmsg, unsigned int vlen,
    668     unsigned int flags)
    669 {
    670 	int retval;
    671 	pthread_t self;
    672 
    673 	self = pthread__self();
    674 	TESTCANCEL(self);
    675 	retval = _sys_sendmmsg(s, mmsg, vlen, flags);
    676 	TESTCANCEL(self);
    677 
    678 	return retval;
    679 }
    680 
    681 int
    682 tcdrain(int fd)
    683 {
    684 	int retval;
    685 	pthread_t self;
    686 
    687 	self = pthread__self();
    688 	TESTCANCEL(self);
    689 	retval = ioctl(fd, TIOCDRAIN, 0);
    690 	TESTCANCEL(self);
    691 
    692 	return retval;
    693 }
    694 
    695 pid_t
    696 __wait450(pid_t wpid, int *status, int options, struct rusage *rusage)
    697 {
    698 	pid_t retval;
    699 	pthread_t self;
    700 
    701 	self = pthread__self();
    702 	TESTCANCEL(self);
    703 	retval = _sys___wait450(wpid, status, options, rusage);
    704 	TESTCANCEL(self);
    705 
    706 	return retval;
    707 }
    708 
    709 ssize_t
    710 write(int d, const void *buf, size_t nbytes)
    711 {
    712 	ssize_t retval;
    713 	pthread_t self;
    714 
    715 	self = pthread__self();
    716 	TESTCANCEL(self);
    717 	retval = _sys_write(d, buf, nbytes);
    718 	TESTCANCEL(self);
    719 
    720 	return retval;
    721 }
    722 
    723 ssize_t
    724 writev(int d, const struct iovec *iov, int iovcnt)
    725 {
    726 	ssize_t retval;
    727 	pthread_t self;
    728 
    729 	self = pthread__self();
    730 	TESTCANCEL(self);
    731 	retval = _sys_writev(d, iov, iovcnt);
    732 	TESTCANCEL(self);
    733 
    734 	return retval;
    735 }
    736 
    737 int
    738 __sigsuspend14(const sigset_t *sigmask)
    739 {
    740 	pthread_t self;
    741 	int retval;
    742 
    743 	self = pthread__self();
    744 	TESTCANCEL(self);
    745 	retval = _sys___sigsuspend14(sigmask);
    746 	TESTCANCEL(self);
    747 
    748 	return retval;
    749 }
    750 
    751 int
    752 __sigtimedwait50(const sigset_t * __restrict set, siginfo_t * __restrict info,
    753     const struct timespec * __restrict timeout)
    754 {
    755 	pthread_t self;
    756 	int retval;
    757 	struct timespec tout, *tp;
    758 
    759 	if (timeout) {
    760 		tout = *timeout;
    761 		tp = &tout;
    762 	} else
    763 		tp = NULL;
    764 
    765 	self = pthread__self();
    766 	TESTCANCEL(self);
    767 	retval = ____sigtimedwait50(set, info, tp);
    768 	TESTCANCEL(self);
    769 
    770 	return retval;
    771 }
    772 
    773 int
    774 sigwait(const sigset_t * __restrict set, int * __restrict sig)
    775 {
    776 	pthread_t	self;
    777 	int		saved_errno;
    778 	int		new_errno;
    779 	int		retval;
    780 
    781 	self = pthread__self();
    782 	saved_errno = errno;
    783 	TESTCANCEL(self);
    784 	retval = ____sigtimedwait50(set, NULL, NULL);
    785 	TESTCANCEL(self);
    786 	new_errno = errno;
    787 	errno = saved_errno;
    788 	if (retval < 0) {
    789 		return new_errno;
    790 	}
    791 	*sig = retval;
    792 	return 0;
    793 }
    794 
    795 __strong_alias(_close, close)
    796 __strong_alias(_clock_nanosleep, clock_nanosleep)
    797 __strong_alias(_fcntl, fcntl)
    798 __strong_alias(_fdatasync, fdatasync)
    799 __strong_alias(_fsync, fsync)
    800 __weak_alias(fsync_range, _fsync_range)
    801 __strong_alias(_mq_send, mq_send)
    802 __strong_alias(_mq_receive, mq_receive)
    803 __strong_alias(_msgrcv, msgrcv)
    804 __strong_alias(_msgsnd, msgsnd)
    805 __strong_alias(___msync13, __msync13)
    806 __strong_alias(___nanosleep50, __nanosleep50)
    807 __strong_alias(_open, open)
    808 __strong_alias(_openat, openat)
    809 __strong_alias(_poll, poll)
    810 __strong_alias(_pread, pread)
    811 __strong_alias(_pwrite, pwrite)
    812 __strong_alias(_read, read)
    813 __strong_alias(_readv, readv)
    814 __strong_alias(_recvfrom, recvfrom)
    815 __strong_alias(_recvmsg, recvmsg)
    816 __strong_alias(_recvmmsg, recvmmsg)
    817 __strong_alias(_sendmsg, sendmsg)
    818 __strong_alias(_sendmmsg, sendmmsg)
    819 __strong_alias(_sendto, sendto)
    820 __strong_alias(_sigwait, sigwait)
    821 __strong_alias(_write, write)
    822 __strong_alias(_writev, writev)
    823 
    824 #endif	/* !lint */
    825