1 /* $NetBSD: pthread_cancelstub.c,v 1.26 2009/01/13 01:50:04 christos Exp $ */
4 * Copyright (c) 2002, 2007 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Nathan J. Williams and Andrew Doran.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __RCSID("$NetBSD: pthread_cancelstub.c,v 1.26 2009/01/13 01:50:04 christos Exp $");
39 * This is necessary because the names are always weak (they are not
42 #define fsync_range _fsync_range
43 #define pollts _pollts
46 * XXX this is necessary to get the prototypes for the __sigsuspend14
47 * XXX and __msync13 internal names, instead of the application-visible
48 * XXX sigsuspend and msync names. It's kind of gross, but we're pretty
49 * XXX intimate with libc already.
51 #define __LIBC12_SOURCE__
54 #include <sys/types.h>
66 #include <sys/select.h>
67 #include <sys/socket.h>
69 #include <compat/sys/mman.h>
70 #include <compat/sys/poll.h>
71 #include <compat/sys/select.h>
72 #include <compat/sys/wait.h>
73 #include <compat/include/mqueue.h>
74 #include <compat/include/signal.h>
77 #include "pthread_int.h"
79 int pthread__cancel_stub_binder
;
81 int _sys_accept(int, struct sockaddr
*, socklen_t
*);
82 int _sys___aio_suspend50(const struct aiocb
* const [], int,
83 const struct timespec
*);
84 int __aio_suspend50(const struct aiocb
* const [], int,
85 const struct timespec
*);
87 int _sys_connect(int, const struct sockaddr
*, socklen_t
);
88 int _sys_fcntl(int, int, ...);
89 int _sys_fdatasync(int);
91 int _sys_fsync_range(int, int, off_t
, off_t
);
92 int _sys_mq_send(mqd_t
, const char *, size_t, unsigned);
93 ssize_t
_sys_mq_receive(mqd_t
, char *, size_t, unsigned *);
94 int _sys___mq_timedsend50(mqd_t
, const char *, size_t, unsigned,
95 const struct timespec
*);
96 ssize_t
_sys___mq_timedreceive50(mqd_t
, char *, size_t, unsigned *,
97 const struct timespec
*);
98 ssize_t
_sys_msgrcv(int, void *, size_t, long, int);
99 int _sys_msgsnd(int, const void *, size_t, int);
100 int _sys___msync13(void *, size_t, int);
101 int _sys___nanosleep50(const struct timespec
*, struct timespec
*);
102 int __nanosleep50(const struct timespec
*, struct timespec
*);
103 int _sys_open(const char *, int, ...);
104 int _sys_poll(struct pollfd
*, nfds_t
, int);
105 int _sys___pollts50(struct pollfd
*, nfds_t
, const struct timespec
*,
107 ssize_t
_sys_pread(int, void *, size_t, off_t
);
108 int _sys___pselect50(int, fd_set
*, fd_set
*, fd_set
*,
109 const struct timespec
*, const sigset_t
*);
110 ssize_t
_sys_pwrite(int, const void *, size_t, off_t
);
111 ssize_t
_sys_read(int, void *, size_t);
112 ssize_t
_sys_readv(int, const struct iovec
*, int);
113 int _sys___select50(int, fd_set
*, fd_set
*, fd_set
*, struct timeval
*);
114 int _sys___wait450(pid_t
, int *, int, struct rusage
*);
115 ssize_t
_sys_write(int, const void *, size_t);
116 ssize_t
_sys_writev(int, const struct iovec
*, int);
117 int _sys___sigsuspend14(const sigset_t
*);
118 int ____sigtimedwait50(const sigset_t
* __restrict
, siginfo_t
* __restrict
,
119 struct timespec
* __restrict
);
120 int __sigsuspend14(const sigset_t
*);
122 #define TESTCANCEL(id) do { \
123 if (__predict_false((id)->pt_cancel)) \
124 pthread__cancelled(); \
125 } while (/*CONSTCOND*/0)
129 accept(int s
, struct sockaddr
*addr
, socklen_t
*addrlen
)
134 self
= pthread__self();
136 retval
= _sys_accept(s
, addr
, addrlen
);
143 __aio_suspend50(const struct aiocb
* const list
[], int nent
,
144 const struct timespec
*timeout
)
149 self
= pthread__self();
151 retval
= _sys___aio_suspend50(list
, nent
, timeout
);
163 self
= pthread__self();
165 retval
= _sys_close(d
);
172 connect(int s
, const struct sockaddr
*addr
, socklen_t namelen
)
177 self
= pthread__self();
179 retval
= _sys_connect(s
, addr
, namelen
);
186 fcntl(int fd
, int cmd
, ...)
192 self
= pthread__self();
195 retval
= _sys_fcntl(fd
, cmd
, va_arg(ap
, void *));
208 self
= pthread__self();
210 retval
= _sys_fdatasync(d
);
222 self
= pthread__self();
224 retval
= _sys_fsync(d
);
231 fsync_range(int d
, int f
, off_t s
, off_t e
)
236 self
= pthread__self();
238 retval
= _sys_fsync_range(d
, f
, s
, e
);
245 mq_send(mqd_t mqdes
, const char *msg_ptr
, size_t msg_len
, unsigned msg_prio
)
250 self
= pthread__self();
252 retval
= _sys_mq_send(mqdes
, msg_ptr
, msg_len
, msg_prio
);
259 mq_receive(mqd_t mqdes
, char *msg_ptr
, size_t msg_len
, unsigned *msg_prio
)
264 self
= pthread__self();
266 retval
= _sys_mq_receive(mqdes
, msg_ptr
, msg_len
, msg_prio
);
273 __mq_timedsend50(mqd_t mqdes
, const char *msg_ptr
, size_t msg_len
,
274 unsigned msg_prio
, const struct timespec
*abst
)
279 self
= pthread__self();
281 retval
= _sys___mq_timedsend50(mqdes
, msg_ptr
, msg_len
, msg_prio
, abst
);
288 __mq_timedreceive50(mqd_t mqdes
, char *msg_ptr
, size_t msg_len
, unsigned *msg_prio
,
289 const struct timespec
*abst
)
294 self
= pthread__self();
296 retval
= _sys___mq_timedreceive50(mqdes
, msg_ptr
, msg_len
, msg_prio
, abst
);
303 msgrcv(int msgid
, void *msgp
, size_t msgsz
, long msgtyp
, int msgflg
)
308 self
= pthread__self();
310 retval
= _sys_msgrcv(msgid
, msgp
, msgsz
, msgtyp
, msgflg
);
317 msgsnd(int msgid
, const void *msgp
, size_t msgsz
, int msgflg
)
322 self
= pthread__self();
324 retval
= _sys_msgsnd(msgid
, msgp
, msgsz
, msgflg
);
331 __msync13(void *addr
, size_t len
, int flags
)
336 self
= pthread__self();
338 retval
= _sys___msync13(addr
, len
, flags
);
345 open(const char *path
, int flags
, ...)
351 self
= pthread__self();
354 retval
= _sys_open(path
, flags
, va_arg(ap
, mode_t
));
362 __nanosleep50(const struct timespec
*rqtp
, struct timespec
*rmtp
)
367 self
= pthread__self();
370 * For now, just nanosleep. In the future, maybe pass a ucontext_t
371 * to _lwp_nanosleep() and allow it to recycle our kernel stack.
373 retval
= _sys___nanosleep50(rqtp
, rmtp
);
380 poll(struct pollfd
*fds
, nfds_t nfds
, int timeout
)
385 self
= pthread__self();
387 retval
= _sys_poll(fds
, nfds
, timeout
);
394 __pollts50(struct pollfd
*fds
, nfds_t nfds
, const struct timespec
*ts
,
395 const sigset_t
*sigmask
)
400 self
= pthread__self();
402 retval
= _sys___pollts50(fds
, nfds
, ts
, sigmask
);
409 pread(int d
, void *buf
, size_t nbytes
, off_t offset
)
414 self
= pthread__self();
416 retval
= _sys_pread(d
, buf
, nbytes
, offset
);
423 __pselect50(int nfds
, fd_set
*readfds
, fd_set
*writefds
, fd_set
*exceptfds
,
424 const struct timespec
*timeout
, const sigset_t
*sigmask
)
429 self
= pthread__self();
431 retval
= _sys___pselect50(nfds
, readfds
, writefds
, exceptfds
, timeout
,
439 pwrite(int d
, const void *buf
, size_t nbytes
, off_t offset
)
444 self
= pthread__self();
446 retval
= _sys_pwrite(d
, buf
, nbytes
, offset
);
452 #ifdef _FORTIFY_SOURCE
457 read(int d
, void *buf
, size_t nbytes
)
462 self
= pthread__self();
464 retval
= _sys_read(d
, buf
, nbytes
);
471 readv(int d
, const struct iovec
*iov
, int iovcnt
)
476 self
= pthread__self();
478 retval
= _sys_readv(d
, iov
, iovcnt
);
485 __select50(int nfds
, fd_set
*readfds
, fd_set
*writefds
, fd_set
*exceptfds
,
486 struct timeval
*timeout
)
491 self
= pthread__self();
493 retval
= _sys___select50(nfds
, readfds
, writefds
, exceptfds
, timeout
);
500 __wait450(pid_t wpid
, int *status
, int options
, struct rusage
*rusage
)
505 self
= pthread__self();
507 retval
= _sys___wait450(wpid
, status
, options
, rusage
);
514 write(int d
, const void *buf
, size_t nbytes
)
519 self
= pthread__self();
521 retval
= _sys_write(d
, buf
, nbytes
);
528 writev(int d
, const struct iovec
*iov
, int iovcnt
)
533 self
= pthread__self();
535 retval
= _sys_writev(d
, iov
, iovcnt
);
542 __sigsuspend14(const sigset_t
*sigmask
)
547 self
= pthread__self();
549 retval
= _sys___sigsuspend14(sigmask
);
556 __sigtimedwait50(const sigset_t
* __restrict set
, siginfo_t
* __restrict info
,
557 const struct timespec
* __restrict timeout
)
561 struct timespec tout
, *tp
;
568 self
= pthread__self();
570 retval
= ____sigtimedwait50(set
, info
, tp
);
576 __strong_alias(_close
, close
)
577 __strong_alias(_fcntl
, fcntl
)
578 __strong_alias(_fdatasync
, fdatasync
)
579 __strong_alias(_fsync
, fsync
)
580 __weak_alias(fsync_range
, _fsync_range
)
581 __strong_alias(_mq_send
, mq_send
)
582 __strong_alias(_mq_receive
, mq_receive
)
583 __strong_alias(_msgrcv
, msgrcv
)
584 __strong_alias(_msgsnd
, msgsnd
)
585 __strong_alias(___msync13
, __msync13
)
586 __strong_alias(___nanosleep50
, __nanosleep50
)
587 __strong_alias(_open
, open
)
588 __strong_alias(_poll
, poll
)
589 __strong_alias(_pread
, pread
)
590 __strong_alias(_pwrite
, pwrite
)
591 __strong_alias(_read
, read
)
592 __strong_alias(_readv
, readv
)
593 __strong_alias(_write
, write
)
594 __strong_alias(_writev
, writev
)