Home | History | Annotate | Line # | Download | only in libpthread
pthread_cancelstub.c revision 1.4
      1  1.4  nathanw /*	$NetBSD: pthread_cancelstub.c,v 1.4 2003/02/15 22:15:50 nathanw Exp $	*/
      2  1.2  thorpej 
      3  1.2  thorpej /*-
      4  1.2  thorpej  * Copyright (c) 2002 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.2  thorpej  * by Nathan J. Williams.
      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  * 3. All advertising materials mentioning features or use of this software
     19  1.2  thorpej  *    must display the following acknowledgement:
     20  1.2  thorpej  *        This product includes software developed by the NetBSD
     21  1.2  thorpej  *        Foundation, Inc. and its contributors.
     22  1.2  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.2  thorpej  *    contributors may be used to endorse or promote products derived
     24  1.2  thorpej  *    from this software without specific prior written permission.
     25  1.2  thorpej  *
     26  1.2  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.2  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.2  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.2  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.2  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.2  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.2  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.2  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.2  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.2  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.2  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37  1.2  thorpej  */
     38  1.2  thorpej 
     39  1.2  thorpej #include <sys/msg.h>
     40  1.2  thorpej #include <sys/types.h>
     41  1.2  thorpej #include <sys/uio.h>
     42  1.2  thorpej #include <sys/wait.h>
     43  1.2  thorpej #include <fcntl.h>
     44  1.2  thorpej #include <poll.h>
     45  1.2  thorpej #include <stdarg.h>
     46  1.2  thorpej #include <unistd.h>
     47  1.2  thorpej 
     48  1.2  thorpej int	pthread__cancel_stub_binder;
     49  1.2  thorpej 
     50  1.2  thorpej /*
     51  1.2  thorpej  * XXX this is necessary to get the prototypes for the __sigsuspend14
     52  1.2  thorpej  * XXX and __msync13 internal names, instead of the application-visible
     53  1.2  thorpej  * XXX sigsuspend and msync names. It's kind of gross, but we're pretty
     54  1.2  thorpej  * XXX intimate with libc already.
     55  1.2  thorpej  */
     56  1.2  thorpej #define __LIBC12_SOURCE__
     57  1.2  thorpej #include <signal.h>
     58  1.2  thorpej #include <sys/mman.h>
     59  1.3  nathanw #include <sys/socket.h>
     60  1.2  thorpej 
     61  1.2  thorpej #include "pthread.h"
     62  1.2  thorpej #include "pthread_int.h"
     63  1.2  thorpej 
     64  1.3  nathanw int	_sys_accept(int, struct sockaddr *, socklen_t *);
     65  1.2  thorpej int	_sys_close(int);
     66  1.3  nathanw int	_sys_connect(int, const struct sockaddr *, socklen_t);
     67  1.2  thorpej int	_sys_fcntl(int, int, ...);
     68  1.2  thorpej int	_sys_fsync(int);
     69  1.2  thorpej ssize_t	_sys_msgrcv(int, void *, size_t, long, int);
     70  1.2  thorpej int	_sys_msgsnd(int, const void *, size_t, int);
     71  1.2  thorpej int	_sys___msync13(void *, size_t, int);
     72  1.2  thorpej int	_sys_open(const char *, int, ...);
     73  1.2  thorpej int	_sys_poll(struct pollfd *, nfds_t, int);
     74  1.2  thorpej ssize_t	_sys_pread(int, void *, size_t, off_t);
     75  1.2  thorpej ssize_t	_sys_pwrite(int, const void *, size_t, off_t);
     76  1.2  thorpej ssize_t	_sys_read(int, void *, size_t);
     77  1.2  thorpej ssize_t	_sys_readv(int, const struct iovec *, int);
     78  1.2  thorpej int	_sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
     79  1.2  thorpej int	_sys_wait4(pid_t, int *, int, struct rusage *);
     80  1.2  thorpej ssize_t	_sys_write(int, const void *, size_t);
     81  1.2  thorpej ssize_t	_sys_writev(int, const struct iovec *, int);
     82  1.2  thorpej 
     83  1.2  thorpej 
     84  1.2  thorpej int
     85  1.3  nathanw accept(int s, struct sockaddr *addr, socklen_t *addrlen)
     86  1.3  nathanw {
     87  1.3  nathanw 	int retval;
     88  1.3  nathanw 	pthread_t self;
     89  1.3  nathanw 
     90  1.3  nathanw 	self = pthread__self();
     91  1.3  nathanw 	pthread__testcancel(self);
     92  1.3  nathanw 	retval = _sys_accept(s, addr, addrlen);
     93  1.3  nathanw 	pthread__testcancel(self);
     94  1.3  nathanw 
     95  1.3  nathanw 	return retval;
     96  1.3  nathanw }
     97  1.3  nathanw 
     98  1.3  nathanw int
     99  1.2  thorpej close(int d)
    100  1.2  thorpej {
    101  1.2  thorpej 	int retval;
    102  1.2  thorpej 	pthread_t self;
    103  1.2  thorpej 
    104  1.2  thorpej 	self = pthread__self();
    105  1.2  thorpej 	pthread__testcancel(self);
    106  1.2  thorpej 	retval = _sys_close(d);
    107  1.3  nathanw 	pthread__testcancel(self);
    108  1.3  nathanw 
    109  1.3  nathanw 	return retval;
    110  1.3  nathanw }
    111  1.3  nathanw 
    112  1.3  nathanw int
    113  1.3  nathanw connect(int s, const struct sockaddr *addr, socklen_t namelen)
    114  1.3  nathanw {
    115  1.3  nathanw 	int retval;
    116  1.3  nathanw 	pthread_t self;
    117  1.3  nathanw 
    118  1.3  nathanw 	self = pthread__self();
    119  1.3  nathanw 	pthread__testcancel(self);
    120  1.3  nathanw 	retval = _sys_connect(s, addr, namelen);
    121  1.2  thorpej 	pthread__testcancel(self);
    122  1.2  thorpej 
    123  1.2  thorpej 	return retval;
    124  1.2  thorpej }
    125  1.2  thorpej 
    126  1.2  thorpej int
    127  1.2  thorpej fcntl(int fd, int cmd, ...)
    128  1.2  thorpej {
    129  1.2  thorpej 	int retval;
    130  1.2  thorpej 	pthread_t self;
    131  1.2  thorpej 	va_list ap;
    132  1.2  thorpej 
    133  1.2  thorpej 	self = pthread__self();
    134  1.2  thorpej 	pthread__testcancel(self);
    135  1.2  thorpej 	va_start(ap, cmd);
    136  1.2  thorpej 	retval = _sys_fcntl(fd, cmd, va_arg(ap, void *));
    137  1.2  thorpej 	va_end(ap);
    138  1.2  thorpej 	pthread__testcancel(self);
    139  1.2  thorpej 
    140  1.2  thorpej 	return retval;
    141  1.2  thorpej }
    142  1.2  thorpej 
    143  1.2  thorpej int
    144  1.2  thorpej fsync(int d)
    145  1.2  thorpej {
    146  1.2  thorpej 	int retval;
    147  1.2  thorpej 	pthread_t self;
    148  1.2  thorpej 
    149  1.2  thorpej 	self = pthread__self();
    150  1.2  thorpej 	pthread__testcancel(self);
    151  1.2  thorpej 	retval = _sys_fsync(d);
    152  1.2  thorpej 	pthread__testcancel(self);
    153  1.2  thorpej 
    154  1.2  thorpej 	return retval;
    155  1.2  thorpej }
    156  1.2  thorpej 
    157  1.2  thorpej ssize_t
    158  1.2  thorpej msgrcv(int msgid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
    159  1.2  thorpej {
    160  1.2  thorpej 	ssize_t retval;
    161  1.2  thorpej 	pthread_t self;
    162  1.2  thorpej 
    163  1.2  thorpej 	self = pthread__self();
    164  1.2  thorpej 	pthread__testcancel(self);
    165  1.2  thorpej 	retval = _sys_msgrcv(msgid, msgp, msgsz, msgtyp, msgflg);
    166  1.2  thorpej 	pthread__testcancel(self);
    167  1.2  thorpej 
    168  1.2  thorpej 	return retval;
    169  1.2  thorpej }
    170  1.2  thorpej 
    171  1.2  thorpej int
    172  1.2  thorpej msgsnd(int msgid, const void *msgp, size_t msgsz, int msgflg)
    173  1.2  thorpej {
    174  1.2  thorpej 	int retval;
    175  1.2  thorpej 	pthread_t self;
    176  1.2  thorpej 
    177  1.2  thorpej 	self = pthread__self();
    178  1.2  thorpej 	pthread__testcancel(self);
    179  1.2  thorpej 	retval = _sys_msgsnd(msgid, msgp, msgsz, msgflg);
    180  1.2  thorpej 	pthread__testcancel(self);
    181  1.2  thorpej 
    182  1.2  thorpej 	return retval;
    183  1.2  thorpej }
    184  1.2  thorpej 
    185  1.2  thorpej int
    186  1.2  thorpej __msync13(void *addr, size_t len, int flags)
    187  1.2  thorpej {
    188  1.2  thorpej 	int retval;
    189  1.2  thorpej 	pthread_t self;
    190  1.2  thorpej 
    191  1.2  thorpej 	self = pthread__self();
    192  1.2  thorpej 	pthread__testcancel(self);
    193  1.2  thorpej 	retval = _sys___msync13(addr, len, flags);
    194  1.2  thorpej 	pthread__testcancel(self);
    195  1.2  thorpej 
    196  1.2  thorpej 	return retval;
    197  1.2  thorpej }
    198  1.2  thorpej 
    199  1.2  thorpej int
    200  1.2  thorpej open(const char *path, int flags, ...)
    201  1.2  thorpej {
    202  1.2  thorpej 	int retval;
    203  1.2  thorpej 	pthread_t self;
    204  1.2  thorpej 	va_list ap;
    205  1.2  thorpej 
    206  1.2  thorpej 	self = pthread__self();
    207  1.2  thorpej 	pthread__testcancel(self);
    208  1.2  thorpej 	va_start(ap, flags);
    209  1.2  thorpej 	retval = _sys_open(path, flags, va_arg(ap, mode_t));
    210  1.2  thorpej 	va_end(ap);
    211  1.2  thorpej 	pthread__testcancel(self);
    212  1.2  thorpej 
    213  1.2  thorpej 	return retval;
    214  1.2  thorpej }
    215  1.2  thorpej 
    216  1.2  thorpej int
    217  1.2  thorpej poll(struct pollfd *fds, nfds_t nfds, int timeout)
    218  1.2  thorpej {
    219  1.2  thorpej 	int retval;
    220  1.2  thorpej 	pthread_t self;
    221  1.2  thorpej 
    222  1.2  thorpej 	self = pthread__self();
    223  1.2  thorpej 	pthread__testcancel(self);
    224  1.2  thorpej 	retval = _sys_poll(fds, nfds, timeout);
    225  1.2  thorpej 	pthread__testcancel(self);
    226  1.2  thorpej 
    227  1.2  thorpej 	return retval;
    228  1.2  thorpej }
    229  1.2  thorpej 
    230  1.2  thorpej ssize_t
    231  1.2  thorpej pread(int d, void *buf, size_t nbytes, off_t offset)
    232  1.2  thorpej {
    233  1.2  thorpej 	ssize_t retval;
    234  1.2  thorpej 	pthread_t self;
    235  1.2  thorpej 
    236  1.2  thorpej 	self = pthread__self();
    237  1.2  thorpej 	pthread__testcancel(self);
    238  1.2  thorpej 	retval = _sys_pread(d, buf, nbytes, offset);
    239  1.2  thorpej 	pthread__testcancel(self);
    240  1.2  thorpej 
    241  1.2  thorpej 	return retval;
    242  1.2  thorpej }
    243  1.2  thorpej 
    244  1.2  thorpej ssize_t
    245  1.2  thorpej pwrite(int d, const void *buf, size_t nbytes, off_t offset)
    246  1.2  thorpej {
    247  1.2  thorpej 	ssize_t retval;
    248  1.2  thorpej 	pthread_t self;
    249  1.2  thorpej 
    250  1.2  thorpej 	self = pthread__self();
    251  1.2  thorpej 	pthread__testcancel(self);
    252  1.2  thorpej 	retval = _sys_pwrite(d, buf, nbytes, offset);
    253  1.2  thorpej 	pthread__testcancel(self);
    254  1.2  thorpej 
    255  1.2  thorpej 	return retval;
    256  1.2  thorpej }
    257  1.2  thorpej 
    258  1.2  thorpej ssize_t
    259  1.2  thorpej read(int d, void *buf, size_t nbytes)
    260  1.2  thorpej {
    261  1.2  thorpej 	ssize_t retval;
    262  1.2  thorpej 	pthread_t self;
    263  1.2  thorpej 
    264  1.2  thorpej 	self = pthread__self();
    265  1.2  thorpej 	pthread__testcancel(self);
    266  1.2  thorpej 	retval = _sys_read(d, buf, nbytes);
    267  1.2  thorpej 	pthread__testcancel(self);
    268  1.2  thorpej 
    269  1.2  thorpej 	return retval;
    270  1.2  thorpej }
    271  1.2  thorpej 
    272  1.2  thorpej ssize_t
    273  1.2  thorpej readv(int d, const struct iovec *iov, int iovcnt)
    274  1.2  thorpej {
    275  1.2  thorpej 	ssize_t retval;
    276  1.2  thorpej 	pthread_t self;
    277  1.2  thorpej 
    278  1.2  thorpej 	self = pthread__self();
    279  1.2  thorpej 	pthread__testcancel(self);
    280  1.2  thorpej 	retval = _sys_readv(d, iov, iovcnt);
    281  1.2  thorpej 	pthread__testcancel(self);
    282  1.2  thorpej 
    283  1.2  thorpej 	return retval;
    284  1.2  thorpej }
    285  1.2  thorpej 
    286  1.2  thorpej int
    287  1.2  thorpej select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
    288  1.2  thorpej     struct timeval *timeout)
    289  1.2  thorpej {
    290  1.2  thorpej 	int retval;
    291  1.2  thorpej 	pthread_t self;
    292  1.2  thorpej 
    293  1.2  thorpej 	self = pthread__self();
    294  1.2  thorpej 	pthread__testcancel(self);
    295  1.2  thorpej 	retval = _sys_select(nfds, readfds, writefds, exceptfds, timeout);
    296  1.2  thorpej 	pthread__testcancel(self);
    297  1.2  thorpej 
    298  1.2  thorpej 	return retval;
    299  1.2  thorpej }
    300  1.2  thorpej 
    301  1.2  thorpej pid_t
    302  1.2  thorpej wait4(pid_t wpid, int *status, int options, struct rusage *rusage)
    303  1.2  thorpej {
    304  1.2  thorpej 	pid_t retval;
    305  1.2  thorpej 	pthread_t self;
    306  1.2  thorpej 
    307  1.2  thorpej 	self = pthread__self();
    308  1.2  thorpej 	pthread__testcancel(self);
    309  1.2  thorpej 	retval = _sys_wait4(wpid, status, options, rusage);
    310  1.2  thorpej 	pthread__testcancel(self);
    311  1.2  thorpej 
    312  1.2  thorpej 	return retval;
    313  1.2  thorpej }
    314  1.2  thorpej 
    315  1.2  thorpej ssize_t
    316  1.2  thorpej write(int d, const void *buf, size_t nbytes)
    317  1.2  thorpej {
    318  1.2  thorpej 	ssize_t retval;
    319  1.2  thorpej 	pthread_t self;
    320  1.2  thorpej 
    321  1.2  thorpej 	self = pthread__self();
    322  1.2  thorpej 	pthread__testcancel(self);
    323  1.2  thorpej 	retval = _sys_write(d, buf, nbytes);
    324  1.2  thorpej 	pthread__testcancel(self);
    325  1.2  thorpej 
    326  1.2  thorpej 	return retval;
    327  1.2  thorpej }
    328  1.2  thorpej 
    329  1.2  thorpej ssize_t
    330  1.2  thorpej writev(int d, const struct iovec *iov, int iovcnt)
    331  1.2  thorpej {
    332  1.2  thorpej 	ssize_t retval;
    333  1.2  thorpej 	pthread_t self;
    334  1.2  thorpej 
    335  1.2  thorpej 	self = pthread__self();
    336  1.2  thorpej 	pthread__testcancel(self);
    337  1.2  thorpej 	retval = _sys_writev(d, iov, iovcnt);
    338  1.2  thorpej 	pthread__testcancel(self);
    339  1.2  thorpej 
    340  1.2  thorpej 	return retval;
    341  1.2  thorpej }
    342  1.2  thorpej 
    343  1.2  thorpej 
    344  1.2  thorpej __strong_alias(_close, close)
    345  1.2  thorpej __strong_alias(_fcntl, fcntl)
    346  1.2  thorpej __strong_alias(_fsync, fsync)
    347  1.2  thorpej __strong_alias(_msgrcv, msgrcv)
    348  1.2  thorpej __strong_alias(_msgsnd, msgsnd)
    349  1.2  thorpej __strong_alias(___msync13, __msync13)
    350  1.2  thorpej __strong_alias(_open, open)
    351  1.2  thorpej __strong_alias(_poll, poll)
    352  1.2  thorpej __strong_alias(_pread, pread)
    353  1.2  thorpej __strong_alias(_pwrite, pwrite)
    354  1.2  thorpej __strong_alias(_read, read)
    355  1.2  thorpej __strong_alias(_readv, readv)
    356  1.2  thorpej __strong_alias(_select, select)
    357  1.2  thorpej __strong_alias(_wait4, wait4)
    358  1.2  thorpej __strong_alias(_write, write)
    359  1.2  thorpej __strong_alias(_writev, writev)
    360