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