Home | History | Annotate | Line # | Download | only in libpthread
pthread_cancelstub.c revision 1.5
      1 /*	$NetBSD: pthread_cancelstub.c,v 1.5 2003/03/08 08:03:35 lukem 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/cdefs.h>
     40 __RCSID("$NetBSD: pthread_cancelstub.c,v 1.5 2003/03/08 08:03:35 lukem Exp $");
     41 
     42 #include <sys/msg.h>
     43 #include <sys/types.h>
     44 #include <sys/uio.h>
     45 #include <sys/wait.h>
     46 #include <fcntl.h>
     47 #include <poll.h>
     48 #include <stdarg.h>
     49 #include <unistd.h>
     50 
     51 int	pthread__cancel_stub_binder;
     52 
     53 /*
     54  * XXX this is necessary to get the prototypes for the __sigsuspend14
     55  * XXX and __msync13 internal names, instead of the application-visible
     56  * XXX sigsuspend and msync names. It's kind of gross, but we're pretty
     57  * XXX intimate with libc already.
     58  */
     59 #define __LIBC12_SOURCE__
     60 #include <signal.h>
     61 #include <sys/mman.h>
     62 #include <sys/socket.h>
     63 
     64 #include "pthread.h"
     65 #include "pthread_int.h"
     66 
     67 int	_sys_accept(int, struct sockaddr *, socklen_t *);
     68 int	_sys_close(int);
     69 int	_sys_connect(int, const struct sockaddr *, socklen_t);
     70 int	_sys_fcntl(int, int, ...);
     71 int	_sys_fsync(int);
     72 ssize_t	_sys_msgrcv(int, void *, size_t, long, int);
     73 int	_sys_msgsnd(int, const void *, size_t, int);
     74 int	_sys___msync13(void *, size_t, int);
     75 int	_sys_open(const char *, int, ...);
     76 int	_sys_poll(struct pollfd *, nfds_t, int);
     77 ssize_t	_sys_pread(int, void *, size_t, off_t);
     78 ssize_t	_sys_pwrite(int, const void *, size_t, off_t);
     79 ssize_t	_sys_read(int, void *, size_t);
     80 ssize_t	_sys_readv(int, const struct iovec *, int);
     81 int	_sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
     82 int	_sys_wait4(pid_t, int *, int, struct rusage *);
     83 ssize_t	_sys_write(int, const void *, size_t);
     84 ssize_t	_sys_writev(int, const struct iovec *, int);
     85 
     86 
     87 int
     88 accept(int s, struct sockaddr *addr, socklen_t *addrlen)
     89 {
     90 	int retval;
     91 	pthread_t self;
     92 
     93 	self = pthread__self();
     94 	pthread__testcancel(self);
     95 	retval = _sys_accept(s, addr, addrlen);
     96 	pthread__testcancel(self);
     97 
     98 	return retval;
     99 }
    100 
    101 int
    102 close(int d)
    103 {
    104 	int retval;
    105 	pthread_t self;
    106 
    107 	self = pthread__self();
    108 	pthread__testcancel(self);
    109 	retval = _sys_close(d);
    110 	pthread__testcancel(self);
    111 
    112 	return retval;
    113 }
    114 
    115 int
    116 connect(int s, const struct sockaddr *addr, socklen_t namelen)
    117 {
    118 	int retval;
    119 	pthread_t self;
    120 
    121 	self = pthread__self();
    122 	pthread__testcancel(self);
    123 	retval = _sys_connect(s, addr, namelen);
    124 	pthread__testcancel(self);
    125 
    126 	return retval;
    127 }
    128 
    129 int
    130 fcntl(int fd, int cmd, ...)
    131 {
    132 	int retval;
    133 	pthread_t self;
    134 	va_list ap;
    135 
    136 	self = pthread__self();
    137 	pthread__testcancel(self);
    138 	va_start(ap, cmd);
    139 	retval = _sys_fcntl(fd, cmd, va_arg(ap, void *));
    140 	va_end(ap);
    141 	pthread__testcancel(self);
    142 
    143 	return retval;
    144 }
    145 
    146 int
    147 fsync(int d)
    148 {
    149 	int retval;
    150 	pthread_t self;
    151 
    152 	self = pthread__self();
    153 	pthread__testcancel(self);
    154 	retval = _sys_fsync(d);
    155 	pthread__testcancel(self);
    156 
    157 	return retval;
    158 }
    159 
    160 ssize_t
    161 msgrcv(int msgid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
    162 {
    163 	ssize_t retval;
    164 	pthread_t self;
    165 
    166 	self = pthread__self();
    167 	pthread__testcancel(self);
    168 	retval = _sys_msgrcv(msgid, msgp, msgsz, msgtyp, msgflg);
    169 	pthread__testcancel(self);
    170 
    171 	return retval;
    172 }
    173 
    174 int
    175 msgsnd(int msgid, const void *msgp, size_t msgsz, int msgflg)
    176 {
    177 	int retval;
    178 	pthread_t self;
    179 
    180 	self = pthread__self();
    181 	pthread__testcancel(self);
    182 	retval = _sys_msgsnd(msgid, msgp, msgsz, msgflg);
    183 	pthread__testcancel(self);
    184 
    185 	return retval;
    186 }
    187 
    188 int
    189 __msync13(void *addr, size_t len, int flags)
    190 {
    191 	int retval;
    192 	pthread_t self;
    193 
    194 	self = pthread__self();
    195 	pthread__testcancel(self);
    196 	retval = _sys___msync13(addr, len, flags);
    197 	pthread__testcancel(self);
    198 
    199 	return retval;
    200 }
    201 
    202 int
    203 open(const char *path, int flags, ...)
    204 {
    205 	int retval;
    206 	pthread_t self;
    207 	va_list ap;
    208 
    209 	self = pthread__self();
    210 	pthread__testcancel(self);
    211 	va_start(ap, flags);
    212 	retval = _sys_open(path, flags, va_arg(ap, mode_t));
    213 	va_end(ap);
    214 	pthread__testcancel(self);
    215 
    216 	return retval;
    217 }
    218 
    219 int
    220 poll(struct pollfd *fds, nfds_t nfds, int timeout)
    221 {
    222 	int retval;
    223 	pthread_t self;
    224 
    225 	self = pthread__self();
    226 	pthread__testcancel(self);
    227 	retval = _sys_poll(fds, nfds, timeout);
    228 	pthread__testcancel(self);
    229 
    230 	return retval;
    231 }
    232 
    233 ssize_t
    234 pread(int d, void *buf, size_t nbytes, off_t offset)
    235 {
    236 	ssize_t retval;
    237 	pthread_t self;
    238 
    239 	self = pthread__self();
    240 	pthread__testcancel(self);
    241 	retval = _sys_pread(d, buf, nbytes, offset);
    242 	pthread__testcancel(self);
    243 
    244 	return retval;
    245 }
    246 
    247 ssize_t
    248 pwrite(int d, const void *buf, size_t nbytes, off_t offset)
    249 {
    250 	ssize_t retval;
    251 	pthread_t self;
    252 
    253 	self = pthread__self();
    254 	pthread__testcancel(self);
    255 	retval = _sys_pwrite(d, buf, nbytes, offset);
    256 	pthread__testcancel(self);
    257 
    258 	return retval;
    259 }
    260 
    261 ssize_t
    262 read(int d, void *buf, size_t nbytes)
    263 {
    264 	ssize_t retval;
    265 	pthread_t self;
    266 
    267 	self = pthread__self();
    268 	pthread__testcancel(self);
    269 	retval = _sys_read(d, buf, nbytes);
    270 	pthread__testcancel(self);
    271 
    272 	return retval;
    273 }
    274 
    275 ssize_t
    276 readv(int d, const struct iovec *iov, int iovcnt)
    277 {
    278 	ssize_t retval;
    279 	pthread_t self;
    280 
    281 	self = pthread__self();
    282 	pthread__testcancel(self);
    283 	retval = _sys_readv(d, iov, iovcnt);
    284 	pthread__testcancel(self);
    285 
    286 	return retval;
    287 }
    288 
    289 int
    290 select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
    291     struct timeval *timeout)
    292 {
    293 	int retval;
    294 	pthread_t self;
    295 
    296 	self = pthread__self();
    297 	pthread__testcancel(self);
    298 	retval = _sys_select(nfds, readfds, writefds, exceptfds, timeout);
    299 	pthread__testcancel(self);
    300 
    301 	return retval;
    302 }
    303 
    304 pid_t
    305 wait4(pid_t wpid, int *status, int options, struct rusage *rusage)
    306 {
    307 	pid_t retval;
    308 	pthread_t self;
    309 
    310 	self = pthread__self();
    311 	pthread__testcancel(self);
    312 	retval = _sys_wait4(wpid, status, options, rusage);
    313 	pthread__testcancel(self);
    314 
    315 	return retval;
    316 }
    317 
    318 ssize_t
    319 write(int d, const void *buf, size_t nbytes)
    320 {
    321 	ssize_t retval;
    322 	pthread_t self;
    323 
    324 	self = pthread__self();
    325 	pthread__testcancel(self);
    326 	retval = _sys_write(d, buf, nbytes);
    327 	pthread__testcancel(self);
    328 
    329 	return retval;
    330 }
    331 
    332 ssize_t
    333 writev(int d, const struct iovec *iov, int iovcnt)
    334 {
    335 	ssize_t retval;
    336 	pthread_t self;
    337 
    338 	self = pthread__self();
    339 	pthread__testcancel(self);
    340 	retval = _sys_writev(d, iov, iovcnt);
    341 	pthread__testcancel(self);
    342 
    343 	return retval;
    344 }
    345 
    346 
    347 __strong_alias(_close, close)
    348 __strong_alias(_fcntl, fcntl)
    349 __strong_alias(_fsync, fsync)
    350 __strong_alias(_msgrcv, msgrcv)
    351 __strong_alias(_msgsnd, msgsnd)
    352 __strong_alias(___msync13, __msync13)
    353 __strong_alias(_open, open)
    354 __strong_alias(_poll, poll)
    355 __strong_alias(_pread, pread)
    356 __strong_alias(_pwrite, pwrite)
    357 __strong_alias(_read, read)
    358 __strong_alias(_readv, readv)
    359 __strong_alias(_select, select)
    360 __strong_alias(_wait4, wait4)
    361 __strong_alias(_write, write)
    362 __strong_alias(_writev, writev)
    363