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