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