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