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