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