Home | History | Annotate | Line # | Download | only in libpthread
pthread_cancelstub.c revision 1.28.2.1
      1  1.28.2.1    bouyer /*	$NetBSD: pthread_cancelstub.c,v 1.28.2.1 2011/02/08 16:19:01 bouyer 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.5     lukem #include <sys/cdefs.h>
     33  1.28.2.1    bouyer __RCSID("$NetBSD: pthread_cancelstub.c,v 1.28.2.1 2011/02/08 16:19:01 bouyer Exp $");
     34      1.20        ad 
     35      1.20        ad #ifndef lint
     36      1.20        ad 
     37       1.6   thorpej 
     38       1.6   thorpej /*
     39      1.11    kleink  * This is necessary because the names are always weak (they are not
     40      1.11    kleink  * POSIX functions).
     41       1.6   thorpej  */
     42       1.6   thorpej #define	fsync_range	_fsync_range
     43      1.11    kleink #define	pollts		_pollts
     44       1.2   thorpej 
     45      1.10    kleink /*
     46      1.10    kleink  * XXX this is necessary to get the prototypes for the __sigsuspend14
     47      1.10    kleink  * XXX and __msync13 internal names, instead of the application-visible
     48      1.10    kleink  * XXX sigsuspend and msync names. It's kind of gross, but we're pretty
     49      1.10    kleink  * XXX intimate with libc already.
     50      1.10    kleink  */
     51      1.10    kleink #define __LIBC12_SOURCE__
     52      1.10    kleink 
     53  1.28.2.1    bouyer #define __ssp_weak_name(fun)	_cancelstub_ ## fun
     54  1.28.2.1    bouyer 
     55       1.2   thorpej #include <sys/msg.h>
     56       1.2   thorpej #include <sys/types.h>
     57       1.2   thorpej #include <sys/uio.h>
     58       1.2   thorpej #include <sys/wait.h>
     59      1.15     rmind #include <aio.h>
     60       1.2   thorpej #include <fcntl.h>
     61      1.15     rmind #include <mqueue.h>
     62       1.2   thorpej #include <poll.h>
     63       1.2   thorpej #include <stdarg.h>
     64       1.2   thorpej #include <unistd.h>
     65       1.2   thorpej 
     66       1.2   thorpej #include <signal.h>
     67       1.2   thorpej #include <sys/mman.h>
     68      1.12    kleink #include <sys/select.h>
     69       1.3   nathanw #include <sys/socket.h>
     70      1.28  christos #include <sys/event.h>
     71       1.2   thorpej 
     72      1.13  christos #include <compat/sys/mman.h>
     73      1.25  christos #include <compat/sys/poll.h>
     74      1.25  christos #include <compat/sys/select.h>
     75      1.28  christos #include <compat/sys/event.h>
     76      1.25  christos #include <compat/sys/wait.h>
     77      1.25  christos #include <compat/include/mqueue.h>
     78      1.25  christos #include <compat/include/signal.h>
     79      1.13  christos 
     80       1.2   thorpej #include "pthread.h"
     81       1.2   thorpej #include "pthread_int.h"
     82       1.2   thorpej 
     83      1.10    kleink int	pthread__cancel_stub_binder;
     84      1.10    kleink 
     85       1.3   nathanw int	_sys_accept(int, struct sockaddr *, socklen_t *);
     86      1.25  christos int	_sys___aio_suspend50(const struct aiocb * const [], int,
     87      1.25  christos 	    const struct timespec *);
     88      1.25  christos int	__aio_suspend50(const struct aiocb * const [], int,
     89      1.15     rmind 	    const struct timespec *);
     90       1.2   thorpej int	_sys_close(int);
     91       1.3   nathanw int	_sys_connect(int, const struct sockaddr *, socklen_t);
     92       1.2   thorpej int	_sys_fcntl(int, int, ...);
     93       1.9    kleink int	_sys_fdatasync(int);
     94       1.2   thorpej int	_sys_fsync(int);
     95       1.6   thorpej int	_sys_fsync_range(int, int, off_t, off_t);
     96      1.28  christos int	_sys___kevent50(int, const struct kevent *, size_t, struct kevent *,
     97      1.28  christos 	    size_t, const struct timespec *);
     98      1.15     rmind int	_sys_mq_send(mqd_t, const char *, size_t, unsigned);
     99      1.15     rmind ssize_t	_sys_mq_receive(mqd_t, char *, size_t, unsigned *);
    100      1.25  christos int	_sys___mq_timedsend50(mqd_t, const char *, size_t, unsigned,
    101      1.15     rmind 	    const struct timespec *);
    102      1.25  christos ssize_t	_sys___mq_timedreceive50(mqd_t, char *, size_t, unsigned *,
    103      1.15     rmind 	    const struct timespec *);
    104       1.2   thorpej ssize_t	_sys_msgrcv(int, void *, size_t, long, int);
    105       1.2   thorpej int	_sys_msgsnd(int, const void *, size_t, int);
    106       1.2   thorpej int	_sys___msync13(void *, size_t, int);
    107      1.27     enami int	_sys___nanosleep50(const struct timespec *, struct timespec *);
    108      1.27     enami int	__nanosleep50(const struct timespec *, struct timespec *);
    109       1.2   thorpej int	_sys_open(const char *, int, ...);
    110       1.2   thorpej int	_sys_poll(struct pollfd *, nfds_t, int);
    111      1.25  christos int	_sys___pollts50(struct pollfd *, nfds_t, const struct timespec *,
    112      1.11    kleink 	    const sigset_t *);
    113       1.2   thorpej ssize_t	_sys_pread(int, void *, size_t, off_t);
    114      1.25  christos int	_sys___pselect50(int, fd_set *, fd_set *, fd_set *,
    115      1.11    kleink 	    const struct timespec *, const sigset_t *);
    116       1.2   thorpej ssize_t	_sys_pwrite(int, const void *, size_t, off_t);
    117       1.2   thorpej ssize_t	_sys_read(int, void *, size_t);
    118       1.2   thorpej ssize_t	_sys_readv(int, const struct iovec *, int);
    119      1.25  christos int	_sys___select50(int, fd_set *, fd_set *, fd_set *, struct timeval *);
    120      1.25  christos int	_sys___wait450(pid_t, int *, int, struct rusage *);
    121       1.2   thorpej ssize_t	_sys_write(int, const void *, size_t);
    122       1.2   thorpej ssize_t	_sys_writev(int, const struct iovec *, int);
    123      1.14        ad int	_sys___sigsuspend14(const sigset_t *);
    124      1.26  christos int	____sigtimedwait50(const sigset_t * __restrict, siginfo_t * __restrict,
    125      1.26  christos 	    struct timespec * __restrict);
    126      1.14        ad int	__sigsuspend14(const sigset_t *);
    127       1.2   thorpej 
    128       1.7   nathanw #define TESTCANCEL(id) 	do {						\
    129       1.7   nathanw 	if (__predict_false((id)->pt_cancel))				\
    130      1.17        ad 		pthread__cancelled();					\
    131       1.8        cl 	} while (/*CONSTCOND*/0)
    132       1.7   nathanw 
    133       1.2   thorpej 
    134       1.2   thorpej int
    135       1.3   nathanw accept(int s, struct sockaddr *addr, socklen_t *addrlen)
    136       1.3   nathanw {
    137       1.3   nathanw 	int retval;
    138       1.3   nathanw 	pthread_t self;
    139       1.3   nathanw 
    140       1.3   nathanw 	self = pthread__self();
    141       1.7   nathanw 	TESTCANCEL(self);
    142       1.3   nathanw 	retval = _sys_accept(s, addr, addrlen);
    143       1.7   nathanw 	TESTCANCEL(self);
    144       1.3   nathanw 
    145       1.3   nathanw 	return retval;
    146       1.3   nathanw }
    147       1.3   nathanw 
    148       1.3   nathanw int
    149      1.25  christos __aio_suspend50(const struct aiocb * const list[], int nent,
    150      1.22        ad     const struct timespec *timeout)
    151      1.22        ad {
    152      1.22        ad 	int retval;
    153      1.22        ad 	pthread_t self;
    154      1.22        ad 
    155      1.22        ad 	self = pthread__self();
    156      1.22        ad 	TESTCANCEL(self);
    157      1.25  christos 	retval = _sys___aio_suspend50(list, nent, timeout);
    158      1.22        ad 	TESTCANCEL(self);
    159      1.22        ad 
    160      1.22        ad 	return retval;
    161      1.22        ad }
    162      1.22        ad 
    163      1.22        ad int
    164      1.28  christos __kevent50(int fd, const struct kevent *ev, size_t nev, struct kevent *rev,
    165      1.28  christos     size_t nrev, const struct timespec *ts)
    166      1.28  christos {
    167      1.28  christos 	int retval;
    168      1.28  christos 	pthread_t self;
    169      1.28  christos 
    170      1.28  christos 	self = pthread__self();
    171      1.28  christos 	TESTCANCEL(self);
    172      1.28  christos 	retval = _sys___kevent50(fd, ev, nev, rev, nrev, ts);
    173      1.28  christos 	TESTCANCEL(self);
    174      1.28  christos 
    175      1.28  christos 	return retval;
    176      1.28  christos }
    177      1.28  christos 
    178      1.28  christos int
    179       1.2   thorpej close(int d)
    180       1.2   thorpej {
    181       1.2   thorpej 	int retval;
    182       1.2   thorpej 	pthread_t self;
    183       1.2   thorpej 
    184       1.2   thorpej 	self = pthread__self();
    185       1.7   nathanw 	TESTCANCEL(self);
    186       1.2   thorpej 	retval = _sys_close(d);
    187       1.7   nathanw 	TESTCANCEL(self);
    188       1.3   nathanw 
    189       1.3   nathanw 	return retval;
    190       1.3   nathanw }
    191       1.3   nathanw 
    192       1.3   nathanw int
    193       1.3   nathanw connect(int s, const struct sockaddr *addr, socklen_t namelen)
    194       1.3   nathanw {
    195       1.3   nathanw 	int retval;
    196       1.3   nathanw 	pthread_t self;
    197       1.3   nathanw 
    198       1.3   nathanw 	self = pthread__self();
    199       1.7   nathanw 	TESTCANCEL(self);
    200       1.3   nathanw 	retval = _sys_connect(s, addr, namelen);
    201       1.7   nathanw 	TESTCANCEL(self);
    202       1.2   thorpej 
    203       1.2   thorpej 	return retval;
    204       1.2   thorpej }
    205       1.2   thorpej 
    206       1.2   thorpej int
    207       1.2   thorpej fcntl(int fd, int cmd, ...)
    208       1.2   thorpej {
    209       1.2   thorpej 	int retval;
    210       1.2   thorpej 	pthread_t self;
    211       1.2   thorpej 	va_list ap;
    212       1.2   thorpej 
    213       1.2   thorpej 	self = pthread__self();
    214       1.7   nathanw 	TESTCANCEL(self);
    215       1.2   thorpej 	va_start(ap, cmd);
    216       1.2   thorpej 	retval = _sys_fcntl(fd, cmd, va_arg(ap, void *));
    217       1.2   thorpej 	va_end(ap);
    218       1.7   nathanw 	TESTCANCEL(self);
    219       1.2   thorpej 
    220       1.2   thorpej 	return retval;
    221       1.2   thorpej }
    222       1.2   thorpej 
    223       1.2   thorpej int
    224       1.9    kleink fdatasync(int d)
    225       1.9    kleink {
    226       1.9    kleink 	int retval;
    227       1.9    kleink 	pthread_t self;
    228       1.9    kleink 
    229       1.9    kleink 	self = pthread__self();
    230       1.9    kleink 	TESTCANCEL(self);
    231       1.9    kleink 	retval = _sys_fdatasync(d);
    232       1.9    kleink 	TESTCANCEL(self);
    233       1.9    kleink 
    234       1.9    kleink 	return retval;
    235       1.9    kleink }
    236       1.9    kleink 
    237       1.9    kleink int
    238       1.2   thorpej fsync(int d)
    239       1.2   thorpej {
    240       1.2   thorpej 	int retval;
    241       1.2   thorpej 	pthread_t self;
    242       1.2   thorpej 
    243       1.2   thorpej 	self = pthread__self();
    244       1.7   nathanw 	TESTCANCEL(self);
    245       1.2   thorpej 	retval = _sys_fsync(d);
    246       1.7   nathanw 	TESTCANCEL(self);
    247       1.2   thorpej 
    248       1.2   thorpej 	return retval;
    249       1.2   thorpej }
    250       1.2   thorpej 
    251       1.6   thorpej int
    252       1.6   thorpej fsync_range(int d, int f, off_t s, off_t e)
    253       1.6   thorpej {
    254       1.6   thorpej 	int retval;
    255       1.6   thorpej 	pthread_t self;
    256       1.6   thorpej 
    257       1.6   thorpej 	self = pthread__self();
    258       1.7   nathanw 	TESTCANCEL(self);
    259       1.6   thorpej 	retval = _sys_fsync_range(d, f, s, e);
    260       1.7   nathanw 	TESTCANCEL(self);
    261       1.6   thorpej 
    262       1.6   thorpej 	return retval;
    263       1.6   thorpej }
    264       1.6   thorpej 
    265      1.22        ad int
    266      1.22        ad mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio)
    267      1.22        ad {
    268      1.22        ad 	int retval;
    269      1.22        ad 	pthread_t self;
    270      1.22        ad 
    271      1.22        ad 	self = pthread__self();
    272      1.22        ad 	TESTCANCEL(self);
    273      1.22        ad 	retval = _sys_mq_send(mqdes, msg_ptr, msg_len, msg_prio);
    274      1.22        ad 	TESTCANCEL(self);
    275      1.22        ad 
    276      1.22        ad 	return retval;
    277      1.22        ad }
    278      1.22        ad 
    279      1.22        ad ssize_t
    280      1.22        ad mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio)
    281      1.22        ad {
    282      1.22        ad 	ssize_t retval;
    283      1.22        ad 	pthread_t self;
    284      1.22        ad 
    285      1.22        ad 	self = pthread__self();
    286      1.22        ad 	TESTCANCEL(self);
    287      1.22        ad 	retval = _sys_mq_receive(mqdes, msg_ptr, msg_len, msg_prio);
    288      1.22        ad 	TESTCANCEL(self);
    289      1.22        ad 
    290      1.22        ad 	return retval;
    291      1.22        ad }
    292      1.22        ad 
    293      1.22        ad int
    294      1.25  christos __mq_timedsend50(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
    295      1.22        ad     unsigned msg_prio, const struct timespec *abst)
    296      1.22        ad {
    297      1.22        ad 	int retval;
    298      1.22        ad 	pthread_t self;
    299      1.22        ad 
    300      1.22        ad 	self = pthread__self();
    301      1.22        ad 	TESTCANCEL(self);
    302      1.25  christos 	retval = _sys___mq_timedsend50(mqdes, msg_ptr, msg_len, msg_prio, abst);
    303      1.22        ad 	TESTCANCEL(self);
    304      1.22        ad 
    305      1.22        ad 	return retval;
    306      1.22        ad }
    307      1.22        ad 
    308      1.22        ad ssize_t
    309      1.25  christos __mq_timedreceive50(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio,
    310      1.22        ad     const struct timespec *abst)
    311      1.22        ad {
    312      1.22        ad 	ssize_t retval;
    313      1.22        ad 	pthread_t self;
    314      1.22        ad 
    315      1.22        ad 	self = pthread__self();
    316      1.22        ad 	TESTCANCEL(self);
    317      1.25  christos 	retval = _sys___mq_timedreceive50(mqdes, msg_ptr, msg_len, msg_prio, abst);
    318      1.22        ad 	TESTCANCEL(self);
    319      1.22        ad 
    320      1.22        ad 	return retval;
    321      1.22        ad }
    322      1.22        ad 
    323       1.2   thorpej ssize_t
    324       1.2   thorpej msgrcv(int msgid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
    325       1.2   thorpej {
    326       1.2   thorpej 	ssize_t retval;
    327       1.2   thorpej 	pthread_t self;
    328       1.2   thorpej 
    329       1.2   thorpej 	self = pthread__self();
    330       1.7   nathanw 	TESTCANCEL(self);
    331       1.2   thorpej 	retval = _sys_msgrcv(msgid, msgp, msgsz, msgtyp, msgflg);
    332       1.7   nathanw 	TESTCANCEL(self);
    333       1.2   thorpej 
    334       1.2   thorpej 	return retval;
    335       1.2   thorpej }
    336       1.2   thorpej 
    337       1.2   thorpej int
    338       1.2   thorpej msgsnd(int msgid, const void *msgp, size_t msgsz, int msgflg)
    339       1.2   thorpej {
    340       1.2   thorpej 	int retval;
    341       1.2   thorpej 	pthread_t self;
    342       1.2   thorpej 
    343       1.2   thorpej 	self = pthread__self();
    344       1.7   nathanw 	TESTCANCEL(self);
    345       1.2   thorpej 	retval = _sys_msgsnd(msgid, msgp, msgsz, msgflg);
    346       1.7   nathanw 	TESTCANCEL(self);
    347       1.2   thorpej 
    348       1.2   thorpej 	return retval;
    349       1.2   thorpej }
    350       1.2   thorpej 
    351       1.2   thorpej int
    352       1.2   thorpej __msync13(void *addr, size_t len, int flags)
    353       1.2   thorpej {
    354       1.2   thorpej 	int retval;
    355       1.2   thorpej 	pthread_t self;
    356       1.2   thorpej 
    357       1.2   thorpej 	self = pthread__self();
    358       1.7   nathanw 	TESTCANCEL(self);
    359       1.2   thorpej 	retval = _sys___msync13(addr, len, flags);
    360       1.7   nathanw 	TESTCANCEL(self);
    361       1.2   thorpej 
    362       1.2   thorpej 	return retval;
    363       1.2   thorpej }
    364       1.2   thorpej 
    365       1.2   thorpej int
    366       1.2   thorpej open(const char *path, int flags, ...)
    367       1.2   thorpej {
    368       1.2   thorpej 	int retval;
    369       1.2   thorpej 	pthread_t self;
    370       1.2   thorpej 	va_list ap;
    371       1.2   thorpej 
    372       1.2   thorpej 	self = pthread__self();
    373       1.7   nathanw 	TESTCANCEL(self);
    374       1.2   thorpej 	va_start(ap, flags);
    375       1.2   thorpej 	retval = _sys_open(path, flags, va_arg(ap, mode_t));
    376       1.2   thorpej 	va_end(ap);
    377       1.7   nathanw 	TESTCANCEL(self);
    378       1.2   thorpej 
    379       1.2   thorpej 	return retval;
    380       1.2   thorpej }
    381       1.2   thorpej 
    382       1.2   thorpej int
    383      1.27     enami __nanosleep50(const struct timespec *rqtp, struct timespec *rmtp)
    384      1.27     enami {
    385      1.27     enami 	int retval;
    386      1.27     enami 	pthread_t self;
    387      1.27     enami 
    388      1.27     enami 	self = pthread__self();
    389      1.27     enami 	TESTCANCEL(self);
    390      1.27     enami 	/*
    391      1.27     enami 	 * For now, just nanosleep.  In the future, maybe pass a ucontext_t
    392      1.27     enami 	 * to _lwp_nanosleep() and allow it to recycle our kernel stack.
    393      1.27     enami 	 */
    394      1.27     enami 	retval = _sys___nanosleep50(rqtp, rmtp);
    395      1.27     enami 	TESTCANCEL(self);
    396      1.27     enami 
    397      1.27     enami 	return retval;
    398      1.27     enami }
    399      1.27     enami 
    400      1.27     enami int
    401       1.2   thorpej poll(struct pollfd *fds, nfds_t nfds, int timeout)
    402       1.2   thorpej {
    403       1.2   thorpej 	int retval;
    404       1.2   thorpej 	pthread_t self;
    405       1.2   thorpej 
    406       1.2   thorpej 	self = pthread__self();
    407       1.7   nathanw 	TESTCANCEL(self);
    408       1.2   thorpej 	retval = _sys_poll(fds, nfds, timeout);
    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.11    kleink int
    415      1.25  christos __pollts50(struct pollfd *fds, nfds_t nfds, const struct timespec *ts,
    416      1.11    kleink     const sigset_t *sigmask)
    417      1.11    kleink {
    418      1.11    kleink 	int retval;
    419      1.11    kleink 	pthread_t self;
    420      1.11    kleink 
    421      1.11    kleink 	self = pthread__self();
    422      1.11    kleink 	TESTCANCEL(self);
    423      1.25  christos 	retval = _sys___pollts50(fds, nfds, ts, sigmask);
    424      1.11    kleink 	TESTCANCEL(self);
    425      1.11    kleink 
    426      1.11    kleink 	return retval;
    427      1.11    kleink }
    428      1.11    kleink 
    429       1.2   thorpej ssize_t
    430       1.2   thorpej pread(int d, void *buf, size_t nbytes, off_t offset)
    431       1.2   thorpej {
    432       1.2   thorpej 	ssize_t retval;
    433       1.2   thorpej 	pthread_t self;
    434       1.2   thorpej 
    435       1.2   thorpej 	self = pthread__self();
    436       1.7   nathanw 	TESTCANCEL(self);
    437       1.2   thorpej 	retval = _sys_pread(d, buf, nbytes, offset);
    438       1.7   nathanw 	TESTCANCEL(self);
    439       1.2   thorpej 
    440       1.2   thorpej 	return retval;
    441       1.2   thorpej }
    442       1.2   thorpej 
    443      1.11    kleink int
    444      1.25  christos __pselect50(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
    445      1.11    kleink     const struct timespec *timeout, const sigset_t *sigmask)
    446      1.11    kleink {
    447      1.11    kleink 	int retval;
    448      1.11    kleink 	pthread_t self;
    449      1.11    kleink 
    450      1.11    kleink 	self = pthread__self();
    451      1.11    kleink 	TESTCANCEL(self);
    452      1.25  christos 	retval = _sys___pselect50(nfds, readfds, writefds, exceptfds, timeout,
    453      1.11    kleink 	    sigmask);
    454      1.11    kleink 	TESTCANCEL(self);
    455      1.11    kleink 
    456      1.11    kleink 	return retval;
    457      1.11    kleink }
    458      1.11    kleink 
    459       1.2   thorpej ssize_t
    460       1.2   thorpej pwrite(int d, const void *buf, size_t nbytes, off_t offset)
    461       1.2   thorpej {
    462       1.2   thorpej 	ssize_t retval;
    463       1.2   thorpej 	pthread_t self;
    464       1.2   thorpej 
    465       1.2   thorpej 	self = pthread__self();
    466       1.7   nathanw 	TESTCANCEL(self);
    467       1.2   thorpej 	retval = _sys_pwrite(d, buf, nbytes, offset);
    468       1.7   nathanw 	TESTCANCEL(self);
    469       1.2   thorpej 
    470       1.2   thorpej 	return retval;
    471       1.2   thorpej }
    472       1.2   thorpej 
    473  1.28.2.1    bouyer #if _FORTIFY_SOURCE > 0
    474  1.28.2.1    bouyer #define STUB(fun) __ssp_weak_name(fun)
    475  1.28.2.1    bouyer ssize_t _sys_readlink(const char * __restrict, char * __restrict, size_t);
    476  1.28.2.1    bouyer ssize_t
    477  1.28.2.1    bouyer STUB(readlink)(const char * __restrict path, char * __restrict buf,
    478  1.28.2.1    bouyer     size_t bufsiz)
    479  1.28.2.1    bouyer {
    480  1.28.2.1    bouyer 	return _sys_readlink(path, buf, bufsiz);
    481  1.28.2.1    bouyer }
    482  1.28.2.1    bouyer 
    483  1.28.2.1    bouyer char *_sys_getcwd(char *, size_t);
    484  1.28.2.1    bouyer char *
    485  1.28.2.1    bouyer STUB(getcwd)(char *buf, size_t size)
    486  1.28.2.1    bouyer {
    487  1.28.2.1    bouyer 	return _sys_getcwd(buf, size);
    488  1.28.2.1    bouyer }
    489  1.28.2.1    bouyer #else
    490  1.28.2.1    bouyer #define STUB(fun) fun
    491      1.18  christos #endif
    492      1.18  christos 
    493       1.2   thorpej ssize_t
    494  1.28.2.1    bouyer STUB(read)(int d, void *buf, size_t nbytes)
    495       1.2   thorpej {
    496       1.2   thorpej 	ssize_t retval;
    497       1.2   thorpej 	pthread_t self;
    498       1.2   thorpej 
    499       1.2   thorpej 	self = pthread__self();
    500       1.7   nathanw 	TESTCANCEL(self);
    501       1.2   thorpej 	retval = _sys_read(d, buf, nbytes);
    502       1.7   nathanw 	TESTCANCEL(self);
    503       1.2   thorpej 
    504       1.2   thorpej 	return retval;
    505       1.2   thorpej }
    506       1.2   thorpej 
    507       1.2   thorpej ssize_t
    508       1.2   thorpej readv(int d, const struct iovec *iov, int iovcnt)
    509       1.2   thorpej {
    510       1.2   thorpej 	ssize_t retval;
    511       1.2   thorpej 	pthread_t self;
    512       1.2   thorpej 
    513       1.2   thorpej 	self = pthread__self();
    514       1.7   nathanw 	TESTCANCEL(self);
    515       1.2   thorpej 	retval = _sys_readv(d, iov, iovcnt);
    516       1.7   nathanw 	TESTCANCEL(self);
    517       1.2   thorpej 
    518       1.2   thorpej 	return retval;
    519       1.2   thorpej }
    520       1.2   thorpej 
    521       1.2   thorpej int
    522      1.25  christos __select50(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
    523       1.2   thorpej     struct timeval *timeout)
    524       1.2   thorpej {
    525       1.2   thorpej 	int retval;
    526       1.2   thorpej 	pthread_t self;
    527       1.2   thorpej 
    528       1.2   thorpej 	self = pthread__self();
    529       1.7   nathanw 	TESTCANCEL(self);
    530      1.25  christos 	retval = _sys___select50(nfds, readfds, writefds, exceptfds, timeout);
    531       1.7   nathanw 	TESTCANCEL(self);
    532       1.2   thorpej 
    533       1.2   thorpej 	return retval;
    534       1.2   thorpej }
    535       1.2   thorpej 
    536       1.2   thorpej pid_t
    537      1.25  christos __wait450(pid_t wpid, int *status, int options, struct rusage *rusage)
    538       1.2   thorpej {
    539       1.2   thorpej 	pid_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.25  christos 	retval = _sys___wait450(wpid, status, options, rusage);
    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.2   thorpej ssize_t
    551       1.2   thorpej write(int d, const void *buf, size_t nbytes)
    552       1.2   thorpej {
    553       1.2   thorpej 	ssize_t retval;
    554       1.2   thorpej 	pthread_t self;
    555       1.2   thorpej 
    556       1.2   thorpej 	self = pthread__self();
    557       1.7   nathanw 	TESTCANCEL(self);
    558       1.2   thorpej 	retval = _sys_write(d, buf, nbytes);
    559       1.7   nathanw 	TESTCANCEL(self);
    560       1.2   thorpej 
    561       1.2   thorpej 	return retval;
    562       1.2   thorpej }
    563       1.2   thorpej 
    564       1.2   thorpej ssize_t
    565       1.2   thorpej writev(int d, const struct iovec *iov, int iovcnt)
    566       1.2   thorpej {
    567       1.2   thorpej 	ssize_t retval;
    568       1.2   thorpej 	pthread_t self;
    569       1.2   thorpej 
    570       1.2   thorpej 	self = pthread__self();
    571       1.7   nathanw 	TESTCANCEL(self);
    572       1.2   thorpej 	retval = _sys_writev(d, iov, iovcnt);
    573       1.7   nathanw 	TESTCANCEL(self);
    574       1.2   thorpej 
    575       1.2   thorpej 	return retval;
    576       1.2   thorpej }
    577       1.2   thorpej 
    578      1.14        ad int
    579      1.14        ad __sigsuspend14(const sigset_t *sigmask)
    580      1.14        ad {
    581      1.14        ad 	pthread_t self;
    582      1.14        ad 	int retval;
    583      1.14        ad 
    584      1.14        ad 	self = pthread__self();
    585      1.14        ad 	TESTCANCEL(self);
    586      1.14        ad 	retval = _sys___sigsuspend14(sigmask);
    587      1.14        ad 	TESTCANCEL(self);
    588      1.14        ad 
    589      1.14        ad 	return retval;
    590      1.14        ad }
    591      1.14        ad 
    592      1.14        ad int
    593      1.25  christos __sigtimedwait50(const sigset_t * __restrict set, siginfo_t * __restrict info,
    594      1.25  christos     const struct timespec * __restrict timeout)
    595      1.14        ad {
    596      1.14        ad 	pthread_t self;
    597      1.14        ad 	int retval;
    598      1.26  christos 	struct timespec tout, *tp;
    599      1.26  christos 	if (timeout) {
    600      1.26  christos 		tout = *timeout;
    601      1.26  christos 		tp = &tout;
    602      1.26  christos 	} else
    603      1.26  christos 		tp = NULL;
    604      1.14        ad 
    605      1.14        ad 	self = pthread__self();
    606      1.14        ad 	TESTCANCEL(self);
    607      1.26  christos 	retval = ____sigtimedwait50(set, info, tp);
    608      1.14        ad 	TESTCANCEL(self);
    609      1.14        ad 
    610      1.14        ad 	return retval;
    611      1.14        ad }
    612       1.2   thorpej 
    613       1.2   thorpej __strong_alias(_close, close)
    614       1.2   thorpej __strong_alias(_fcntl, fcntl)
    615       1.9    kleink __strong_alias(_fdatasync, fdatasync)
    616       1.2   thorpej __strong_alias(_fsync, fsync)
    617       1.6   thorpej __weak_alias(fsync_range, _fsync_range)
    618      1.22        ad __strong_alias(_mq_send, mq_send)
    619      1.22        ad __strong_alias(_mq_receive, mq_receive)
    620       1.2   thorpej __strong_alias(_msgrcv, msgrcv)
    621       1.2   thorpej __strong_alias(_msgsnd, msgsnd)
    622       1.2   thorpej __strong_alias(___msync13, __msync13)
    623      1.27     enami __strong_alias(___nanosleep50, __nanosleep50)
    624       1.2   thorpej __strong_alias(_open, open)
    625       1.2   thorpej __strong_alias(_poll, poll)
    626       1.2   thorpej __strong_alias(_pread, pread)
    627       1.2   thorpej __strong_alias(_pwrite, pwrite)
    628       1.2   thorpej __strong_alias(_read, read)
    629       1.2   thorpej __strong_alias(_readv, readv)
    630       1.2   thorpej __strong_alias(_write, write)
    631       1.2   thorpej __strong_alias(_writev, writev)
    632      1.20        ad 
    633      1.20        ad #endif	/* !lint */
    634