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