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