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