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