pthread_cancelstub.c revision 1.47 1 1.47 riastrad /* $NetBSD: pthread_cancelstub.c,v 1.47 2025/03/31 14:23:11 riastradh Exp $ */
2 1.2 thorpej
3 1.2 thorpej /*-
4 1.14 ad * Copyright (c) 2002, 2007 The NetBSD Foundation, Inc.
5 1.2 thorpej * All rights reserved.
6 1.2 thorpej *
7 1.2 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.14 ad * by Nathan J. Williams and Andrew Doran.
9 1.2 thorpej *
10 1.2 thorpej * Redistribution and use in source and binary forms, with or without
11 1.2 thorpej * modification, are permitted provided that the following conditions
12 1.2 thorpej * are met:
13 1.2 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.2 thorpej * notice, this list of conditions and the following disclaimer.
15 1.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.2 thorpej * documentation and/or other materials provided with the distribution.
18 1.2 thorpej *
19 1.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
30 1.2 thorpej */
31 1.5 lukem
32 1.34 joerg /* Disable namespace mangling, Fortification is useless here anyway. */
33 1.34 joerg #undef _FORTIFY_SOURCE
34 1.34 joerg
35 1.5 lukem #include <sys/cdefs.h>
36 1.47 riastrad __RCSID("$NetBSD: pthread_cancelstub.c,v 1.47 2025/03/31 14:23:11 riastradh Exp $");
37 1.41 riastrad
38 1.41 riastrad /* Need to use libc-private names for atomic operations. */
39 1.41 riastrad #include "../../common/lib/libc/atomic/atomic_op_namespace.h"
40 1.20 ad
41 1.20 ad #ifndef lint
42 1.20 ad
43 1.6 thorpej
44 1.6 thorpej /*
45 1.11 kleink * This is necessary because the names are always weak (they are not
46 1.11 kleink * POSIX functions).
47 1.6 thorpej */
48 1.6 thorpej #define fsync_range _fsync_range
49 1.11 kleink #define pollts _pollts
50 1.2 thorpej
51 1.10 kleink /*
52 1.10 kleink * XXX this is necessary to get the prototypes for the __sigsuspend14
53 1.10 kleink * XXX and __msync13 internal names, instead of the application-visible
54 1.10 kleink * XXX sigsuspend and msync names. It's kind of gross, but we're pretty
55 1.10 kleink * XXX intimate with libc already.
56 1.10 kleink */
57 1.10 kleink #define __LIBC12_SOURCE__
58 1.10 kleink
59 1.2 thorpej #include <sys/msg.h>
60 1.2 thorpej #include <sys/types.h>
61 1.2 thorpej #include <sys/uio.h>
62 1.2 thorpej #include <sys/wait.h>
63 1.15 rmind #include <aio.h>
64 1.36 agc #include <errno.h>
65 1.2 thorpej #include <fcntl.h>
66 1.15 rmind #include <mqueue.h>
67 1.2 thorpej #include <poll.h>
68 1.46 riastrad #include <stdatomic.h>
69 1.2 thorpej #include <stdarg.h>
70 1.47 riastrad #include <termios.h>
71 1.2 thorpej #include <unistd.h>
72 1.2 thorpej
73 1.2 thorpej #include <signal.h>
74 1.2 thorpej #include <sys/mman.h>
75 1.12 kleink #include <sys/select.h>
76 1.3 nathanw #include <sys/socket.h>
77 1.28 christos #include <sys/event.h>
78 1.45 christos #include <sys/resource.h>
79 1.2 thorpej
80 1.13 christos #include <compat/sys/mman.h>
81 1.25 christos #include <compat/sys/poll.h>
82 1.25 christos #include <compat/sys/select.h>
83 1.28 christos #include <compat/sys/event.h>
84 1.25 christos #include <compat/sys/wait.h>
85 1.45 christos #include <compat/sys/resource.h>
86 1.25 christos #include <compat/include/mqueue.h>
87 1.25 christos #include <compat/include/signal.h>
88 1.13 christos
89 1.2 thorpej #include "pthread.h"
90 1.2 thorpej #include "pthread_int.h"
91 1.38 christos #include "reentrant.h"
92 1.2 thorpej
93 1.46 riastrad #define atomic_load_relaxed(p) \
94 1.46 riastrad atomic_load_explicit(p, memory_order_relaxed)
95 1.46 riastrad
96 1.10 kleink int pthread__cancel_stub_binder;
97 1.10 kleink
98 1.3 nathanw int _sys_accept(int, struct sockaddr *, socklen_t *);
99 1.25 christos int _sys___aio_suspend50(const struct aiocb * const [], int,
100 1.25 christos const struct timespec *);
101 1.25 christos int __aio_suspend50(const struct aiocb * const [], int,
102 1.15 rmind const struct timespec *);
103 1.39 christos int _sys_clock_nanosleep(clockid_t clock_id, int flags,
104 1.39 christos const struct timespec *rqtp, struct timespec *rmtp);
105 1.2 thorpej int _sys_close(int);
106 1.3 nathanw int _sys_connect(int, const struct sockaddr *, socklen_t);
107 1.2 thorpej int _sys_fcntl(int, int, ...);
108 1.9 kleink int _sys_fdatasync(int);
109 1.2 thorpej int _sys_fsync(int);
110 1.6 thorpej int _sys_fsync_range(int, int, off_t, off_t);
111 1.44 christos int _sys___kevent100(int, const struct kevent *, size_t, struct kevent *,
112 1.28 christos size_t, const struct timespec *);
113 1.15 rmind int _sys_mq_send(mqd_t, const char *, size_t, unsigned);
114 1.15 rmind ssize_t _sys_mq_receive(mqd_t, char *, size_t, unsigned *);
115 1.25 christos int _sys___mq_timedsend50(mqd_t, const char *, size_t, unsigned,
116 1.15 rmind const struct timespec *);
117 1.25 christos ssize_t _sys___mq_timedreceive50(mqd_t, char *, size_t, unsigned *,
118 1.15 rmind const struct timespec *);
119 1.2 thorpej ssize_t _sys_msgrcv(int, void *, size_t, long, int);
120 1.2 thorpej int _sys_msgsnd(int, const void *, size_t, int);
121 1.2 thorpej int _sys___msync13(void *, size_t, int);
122 1.27 enami int _sys___nanosleep50(const struct timespec *, struct timespec *);
123 1.27 enami int __nanosleep50(const struct timespec *, struct timespec *);
124 1.2 thorpej int _sys_open(const char *, int, ...);
125 1.39 christos int _sys_openat(int, const char *, int, ...);
126 1.47 riastrad int _sys_paccept(int, struct sockaddr *, socklen_t *, int);
127 1.2 thorpej int _sys_poll(struct pollfd *, nfds_t, int);
128 1.25 christos int _sys___pollts50(struct pollfd *, nfds_t, const struct timespec *,
129 1.11 kleink const sigset_t *);
130 1.2 thorpej ssize_t _sys_pread(int, void *, size_t, off_t);
131 1.25 christos int _sys___pselect50(int, fd_set *, fd_set *, fd_set *,
132 1.11 kleink const struct timespec *, const sigset_t *);
133 1.2 thorpej ssize_t _sys_pwrite(int, const void *, size_t, off_t);
134 1.2 thorpej ssize_t _sys_read(int, void *, size_t);
135 1.2 thorpej ssize_t _sys_readv(int, const struct iovec *, int);
136 1.39 christos ssize_t _sys_recvfrom(int, void * restrict, size_t, int,
137 1.39 christos struct sockaddr * restrict, socklen_t * restrict);
138 1.39 christos ssize_t _sys_recvmsg(int, struct msghdr *, int);
139 1.39 christos int _sys_recvmmsg(int, struct mmsghdr *, unsigned int, unsigned int,
140 1.39 christos struct timespec *);
141 1.40 christos ssize_t _sys_sendto(int, const void *, size_t, int, const struct sockaddr *,
142 1.40 christos socklen_t);
143 1.40 christos ssize_t _sys_sendmsg(int, const struct msghdr *, int);
144 1.40 christos int _sys_sendmmsg(int, struct mmsghdr *, unsigned int, unsigned int);
145 1.25 christos int _sys___select50(int, fd_set *, fd_set *, fd_set *, struct timeval *);
146 1.25 christos int _sys___wait450(pid_t, int *, int, struct rusage *);
147 1.2 thorpej ssize_t _sys_write(int, const void *, size_t);
148 1.2 thorpej ssize_t _sys_writev(int, const struct iovec *, int);
149 1.14 ad int _sys___sigsuspend14(const sigset_t *);
150 1.26 christos int ____sigtimedwait50(const sigset_t * __restrict, siginfo_t * __restrict,
151 1.26 christos struct timespec * __restrict);
152 1.14 ad int __sigsuspend14(const sigset_t *);
153 1.2 thorpej
154 1.7 nathanw #define TESTCANCEL(id) do { \
155 1.38 christos if (__predict_true(!__uselibcstub) && \
156 1.46 riastrad __predict_false(atomic_load_relaxed(&(id)->pt_cancel) & \
157 1.46 riastrad PT_CANCEL_CANCELLED)) { \
158 1.46 riastrad membar_acquire(); \
159 1.17 ad pthread__cancelled(); \
160 1.46 riastrad } \
161 1.43 rillig } while (0)
162 1.7 nathanw
163 1.2 thorpej
164 1.2 thorpej int
165 1.3 nathanw accept(int s, struct sockaddr *addr, socklen_t *addrlen)
166 1.3 nathanw {
167 1.3 nathanw int retval;
168 1.3 nathanw pthread_t self;
169 1.3 nathanw
170 1.3 nathanw self = pthread__self();
171 1.7 nathanw TESTCANCEL(self);
172 1.3 nathanw retval = _sys_accept(s, addr, addrlen);
173 1.7 nathanw TESTCANCEL(self);
174 1.42 riastrad
175 1.3 nathanw return retval;
176 1.3 nathanw }
177 1.3 nathanw
178 1.3 nathanw int
179 1.47 riastrad accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags)
180 1.47 riastrad {
181 1.47 riastrad int retval;
182 1.47 riastrad pthread_t self;
183 1.47 riastrad
184 1.47 riastrad self = pthread__self();
185 1.47 riastrad TESTCANCEL(self);
186 1.47 riastrad retval = _sys_paccept(s, addr, addrlen, flags);
187 1.47 riastrad TESTCANCEL(self);
188 1.47 riastrad
189 1.47 riastrad return retval;
190 1.47 riastrad }
191 1.47 riastrad
192 1.47 riastrad int
193 1.25 christos __aio_suspend50(const struct aiocb * const list[], int nent,
194 1.22 ad const struct timespec *timeout)
195 1.22 ad {
196 1.22 ad int retval;
197 1.22 ad pthread_t self;
198 1.22 ad
199 1.22 ad self = pthread__self();
200 1.22 ad TESTCANCEL(self);
201 1.25 christos retval = _sys___aio_suspend50(list, nent, timeout);
202 1.22 ad TESTCANCEL(self);
203 1.22 ad
204 1.22 ad return retval;
205 1.22 ad }
206 1.22 ad
207 1.22 ad int
208 1.44 christos __kevent100(int fd, const struct kevent *ev, size_t nev, struct kevent *rev,
209 1.28 christos size_t nrev, const struct timespec *ts)
210 1.28 christos {
211 1.28 christos int retval;
212 1.28 christos pthread_t self;
213 1.28 christos
214 1.28 christos self = pthread__self();
215 1.28 christos TESTCANCEL(self);
216 1.44 christos retval = _sys___kevent100(fd, ev, nev, rev, nrev, ts);
217 1.28 christos TESTCANCEL(self);
218 1.28 christos
219 1.28 christos return retval;
220 1.28 christos }
221 1.28 christos
222 1.28 christos int
223 1.39 christos clock_nanosleep(clockid_t clock_id, int flags,
224 1.39 christos const struct timespec *rqtp, struct timespec *rmtp)
225 1.39 christos {
226 1.39 christos int retval;
227 1.39 christos pthread_t self;
228 1.39 christos
229 1.39 christos self = pthread__self();
230 1.39 christos TESTCANCEL(self);
231 1.39 christos retval = _sys_clock_nanosleep(clock_id, flags, rqtp, rmtp);
232 1.39 christos TESTCANCEL(self);
233 1.42 riastrad
234 1.39 christos return retval;
235 1.39 christos }
236 1.39 christos
237 1.39 christos int
238 1.2 thorpej close(int d)
239 1.2 thorpej {
240 1.2 thorpej int retval;
241 1.2 thorpej pthread_t self;
242 1.2 thorpej
243 1.2 thorpej self = pthread__self();
244 1.7 nathanw TESTCANCEL(self);
245 1.2 thorpej retval = _sys_close(d);
246 1.7 nathanw TESTCANCEL(self);
247 1.42 riastrad
248 1.3 nathanw return retval;
249 1.3 nathanw }
250 1.3 nathanw
251 1.3 nathanw int
252 1.3 nathanw connect(int s, const struct sockaddr *addr, socklen_t namelen)
253 1.3 nathanw {
254 1.3 nathanw int retval;
255 1.3 nathanw pthread_t self;
256 1.3 nathanw
257 1.3 nathanw self = pthread__self();
258 1.7 nathanw TESTCANCEL(self);
259 1.3 nathanw retval = _sys_connect(s, addr, namelen);
260 1.7 nathanw TESTCANCEL(self);
261 1.42 riastrad
262 1.2 thorpej return retval;
263 1.2 thorpej }
264 1.2 thorpej
265 1.2 thorpej int
266 1.2 thorpej fcntl(int fd, int cmd, ...)
267 1.2 thorpej {
268 1.2 thorpej int retval;
269 1.2 thorpej pthread_t self;
270 1.2 thorpej va_list ap;
271 1.2 thorpej
272 1.2 thorpej self = pthread__self();
273 1.7 nathanw TESTCANCEL(self);
274 1.2 thorpej va_start(ap, cmd);
275 1.2 thorpej retval = _sys_fcntl(fd, cmd, va_arg(ap, void *));
276 1.2 thorpej va_end(ap);
277 1.7 nathanw TESTCANCEL(self);
278 1.2 thorpej
279 1.2 thorpej return retval;
280 1.2 thorpej }
281 1.2 thorpej
282 1.2 thorpej int
283 1.9 kleink fdatasync(int d)
284 1.9 kleink {
285 1.9 kleink int retval;
286 1.9 kleink pthread_t self;
287 1.9 kleink
288 1.9 kleink self = pthread__self();
289 1.9 kleink TESTCANCEL(self);
290 1.9 kleink retval = _sys_fdatasync(d);
291 1.9 kleink TESTCANCEL(self);
292 1.42 riastrad
293 1.9 kleink return retval;
294 1.9 kleink }
295 1.9 kleink
296 1.9 kleink int
297 1.2 thorpej fsync(int d)
298 1.2 thorpej {
299 1.2 thorpej int retval;
300 1.2 thorpej pthread_t self;
301 1.2 thorpej
302 1.2 thorpej self = pthread__self();
303 1.7 nathanw TESTCANCEL(self);
304 1.2 thorpej retval = _sys_fsync(d);
305 1.7 nathanw TESTCANCEL(self);
306 1.42 riastrad
307 1.2 thorpej return retval;
308 1.2 thorpej }
309 1.2 thorpej
310 1.6 thorpej int
311 1.6 thorpej fsync_range(int d, int f, off_t s, off_t e)
312 1.6 thorpej {
313 1.6 thorpej int retval;
314 1.6 thorpej pthread_t self;
315 1.6 thorpej
316 1.6 thorpej self = pthread__self();
317 1.7 nathanw TESTCANCEL(self);
318 1.6 thorpej retval = _sys_fsync_range(d, f, s, e);
319 1.7 nathanw TESTCANCEL(self);
320 1.6 thorpej
321 1.6 thorpej return retval;
322 1.6 thorpej }
323 1.6 thorpej
324 1.22 ad int
325 1.22 ad mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio)
326 1.22 ad {
327 1.22 ad int retval;
328 1.22 ad pthread_t self;
329 1.22 ad
330 1.22 ad self = pthread__self();
331 1.22 ad TESTCANCEL(self);
332 1.22 ad retval = _sys_mq_send(mqdes, msg_ptr, msg_len, msg_prio);
333 1.22 ad TESTCANCEL(self);
334 1.22 ad
335 1.22 ad return retval;
336 1.22 ad }
337 1.22 ad
338 1.22 ad ssize_t
339 1.22 ad mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio)
340 1.22 ad {
341 1.22 ad ssize_t retval;
342 1.22 ad pthread_t self;
343 1.22 ad
344 1.22 ad self = pthread__self();
345 1.22 ad TESTCANCEL(self);
346 1.22 ad retval = _sys_mq_receive(mqdes, msg_ptr, msg_len, msg_prio);
347 1.22 ad TESTCANCEL(self);
348 1.22 ad
349 1.22 ad return retval;
350 1.22 ad }
351 1.22 ad
352 1.22 ad int
353 1.25 christos __mq_timedsend50(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
354 1.22 ad unsigned msg_prio, const struct timespec *abst)
355 1.22 ad {
356 1.22 ad int retval;
357 1.22 ad pthread_t self;
358 1.22 ad
359 1.22 ad self = pthread__self();
360 1.22 ad TESTCANCEL(self);
361 1.25 christos retval = _sys___mq_timedsend50(mqdes, msg_ptr, msg_len, msg_prio, abst);
362 1.22 ad TESTCANCEL(self);
363 1.22 ad
364 1.22 ad return retval;
365 1.22 ad }
366 1.22 ad
367 1.22 ad ssize_t
368 1.25 christos __mq_timedreceive50(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio,
369 1.22 ad const struct timespec *abst)
370 1.22 ad {
371 1.22 ad ssize_t retval;
372 1.22 ad pthread_t self;
373 1.22 ad
374 1.22 ad self = pthread__self();
375 1.22 ad TESTCANCEL(self);
376 1.25 christos retval = _sys___mq_timedreceive50(mqdes, msg_ptr, msg_len, msg_prio, abst);
377 1.22 ad TESTCANCEL(self);
378 1.22 ad
379 1.22 ad return retval;
380 1.22 ad }
381 1.22 ad
382 1.2 thorpej ssize_t
383 1.2 thorpej msgrcv(int msgid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
384 1.2 thorpej {
385 1.2 thorpej ssize_t retval;
386 1.2 thorpej pthread_t self;
387 1.2 thorpej
388 1.2 thorpej self = pthread__self();
389 1.7 nathanw TESTCANCEL(self);
390 1.2 thorpej retval = _sys_msgrcv(msgid, msgp, msgsz, msgtyp, msgflg);
391 1.7 nathanw TESTCANCEL(self);
392 1.2 thorpej
393 1.2 thorpej return retval;
394 1.2 thorpej }
395 1.2 thorpej
396 1.2 thorpej int
397 1.2 thorpej msgsnd(int msgid, const void *msgp, size_t msgsz, int msgflg)
398 1.2 thorpej {
399 1.2 thorpej int retval;
400 1.2 thorpej pthread_t self;
401 1.2 thorpej
402 1.2 thorpej self = pthread__self();
403 1.7 nathanw TESTCANCEL(self);
404 1.2 thorpej retval = _sys_msgsnd(msgid, msgp, msgsz, msgflg);
405 1.7 nathanw TESTCANCEL(self);
406 1.2 thorpej
407 1.2 thorpej return retval;
408 1.2 thorpej }
409 1.2 thorpej
410 1.2 thorpej int
411 1.2 thorpej __msync13(void *addr, size_t len, int flags)
412 1.2 thorpej {
413 1.2 thorpej int retval;
414 1.2 thorpej pthread_t self;
415 1.2 thorpej
416 1.2 thorpej self = pthread__self();
417 1.7 nathanw TESTCANCEL(self);
418 1.2 thorpej retval = _sys___msync13(addr, len, flags);
419 1.7 nathanw TESTCANCEL(self);
420 1.2 thorpej
421 1.2 thorpej return retval;
422 1.2 thorpej }
423 1.2 thorpej
424 1.2 thorpej int
425 1.2 thorpej open(const char *path, int flags, ...)
426 1.2 thorpej {
427 1.2 thorpej int retval;
428 1.2 thorpej pthread_t self;
429 1.2 thorpej va_list ap;
430 1.2 thorpej
431 1.2 thorpej self = pthread__self();
432 1.7 nathanw TESTCANCEL(self);
433 1.2 thorpej va_start(ap, flags);
434 1.2 thorpej retval = _sys_open(path, flags, va_arg(ap, mode_t));
435 1.2 thorpej va_end(ap);
436 1.7 nathanw TESTCANCEL(self);
437 1.2 thorpej
438 1.2 thorpej return retval;
439 1.2 thorpej }
440 1.2 thorpej
441 1.2 thorpej int
442 1.39 christos openat(int fd, const char *path, int flags, ...)
443 1.39 christos {
444 1.39 christos int retval;
445 1.39 christos pthread_t self;
446 1.39 christos va_list ap;
447 1.39 christos
448 1.39 christos self = pthread__self();
449 1.39 christos TESTCANCEL(self);
450 1.39 christos va_start(ap, flags);
451 1.39 christos retval = _sys_openat(fd, path, flags, va_arg(ap, mode_t));
452 1.39 christos va_end(ap);
453 1.39 christos TESTCANCEL(self);
454 1.39 christos
455 1.39 christos return retval;
456 1.39 christos }
457 1.39 christos
458 1.39 christos int
459 1.27 enami __nanosleep50(const struct timespec *rqtp, struct timespec *rmtp)
460 1.27 enami {
461 1.27 enami int retval;
462 1.27 enami pthread_t self;
463 1.27 enami
464 1.27 enami self = pthread__self();
465 1.27 enami TESTCANCEL(self);
466 1.27 enami /*
467 1.27 enami * For now, just nanosleep. In the future, maybe pass a ucontext_t
468 1.27 enami * to _lwp_nanosleep() and allow it to recycle our kernel stack.
469 1.27 enami */
470 1.27 enami retval = _sys___nanosleep50(rqtp, rmtp);
471 1.27 enami TESTCANCEL(self);
472 1.27 enami
473 1.27 enami return retval;
474 1.27 enami }
475 1.27 enami
476 1.27 enami int
477 1.2 thorpej poll(struct pollfd *fds, nfds_t nfds, int timeout)
478 1.2 thorpej {
479 1.2 thorpej int retval;
480 1.2 thorpej pthread_t self;
481 1.2 thorpej
482 1.2 thorpej self = pthread__self();
483 1.7 nathanw TESTCANCEL(self);
484 1.2 thorpej retval = _sys_poll(fds, nfds, timeout);
485 1.7 nathanw TESTCANCEL(self);
486 1.2 thorpej
487 1.2 thorpej return retval;
488 1.2 thorpej }
489 1.2 thorpej
490 1.11 kleink int
491 1.25 christos __pollts50(struct pollfd *fds, nfds_t nfds, const struct timespec *ts,
492 1.11 kleink const sigset_t *sigmask)
493 1.11 kleink {
494 1.11 kleink int retval;
495 1.11 kleink pthread_t self;
496 1.11 kleink
497 1.11 kleink self = pthread__self();
498 1.11 kleink TESTCANCEL(self);
499 1.25 christos retval = _sys___pollts50(fds, nfds, ts, sigmask);
500 1.11 kleink TESTCANCEL(self);
501 1.11 kleink
502 1.11 kleink return retval;
503 1.11 kleink }
504 1.11 kleink
505 1.2 thorpej ssize_t
506 1.2 thorpej pread(int d, void *buf, size_t nbytes, off_t offset)
507 1.2 thorpej {
508 1.2 thorpej ssize_t retval;
509 1.2 thorpej pthread_t self;
510 1.2 thorpej
511 1.2 thorpej self = pthread__self();
512 1.7 nathanw TESTCANCEL(self);
513 1.2 thorpej retval = _sys_pread(d, buf, nbytes, offset);
514 1.7 nathanw TESTCANCEL(self);
515 1.2 thorpej
516 1.2 thorpej return retval;
517 1.2 thorpej }
518 1.2 thorpej
519 1.11 kleink int
520 1.42 riastrad __pselect50(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
521 1.11 kleink const struct timespec *timeout, const sigset_t *sigmask)
522 1.11 kleink {
523 1.11 kleink int retval;
524 1.11 kleink pthread_t self;
525 1.11 kleink
526 1.11 kleink self = pthread__self();
527 1.11 kleink TESTCANCEL(self);
528 1.25 christos retval = _sys___pselect50(nfds, readfds, writefds, exceptfds, timeout,
529 1.11 kleink sigmask);
530 1.11 kleink TESTCANCEL(self);
531 1.11 kleink
532 1.11 kleink return retval;
533 1.11 kleink }
534 1.11 kleink
535 1.2 thorpej ssize_t
536 1.2 thorpej pwrite(int d, const void *buf, size_t nbytes, off_t offset)
537 1.2 thorpej {
538 1.2 thorpej ssize_t retval;
539 1.2 thorpej pthread_t self;
540 1.2 thorpej
541 1.2 thorpej self = pthread__self();
542 1.7 nathanw TESTCANCEL(self);
543 1.2 thorpej retval = _sys_pwrite(d, buf, nbytes, offset);
544 1.7 nathanw TESTCANCEL(self);
545 1.2 thorpej
546 1.2 thorpej return retval;
547 1.2 thorpej }
548 1.2 thorpej
549 1.2 thorpej ssize_t
550 1.35 joerg read(int d, void *buf, size_t nbytes)
551 1.35 joerg {
552 1.35 joerg ssize_t retval;
553 1.35 joerg pthread_t self;
554 1.35 joerg
555 1.35 joerg self = pthread__self();
556 1.35 joerg TESTCANCEL(self);
557 1.35 joerg retval = _sys_read(d, buf, nbytes);
558 1.35 joerg TESTCANCEL(self);
559 1.35 joerg
560 1.35 joerg return retval;
561 1.35 joerg }
562 1.35 joerg
563 1.35 joerg ssize_t
564 1.2 thorpej readv(int d, const struct iovec *iov, int iovcnt)
565 1.2 thorpej {
566 1.2 thorpej ssize_t retval;
567 1.2 thorpej pthread_t self;
568 1.2 thorpej
569 1.2 thorpej self = pthread__self();
570 1.7 nathanw TESTCANCEL(self);
571 1.2 thorpej retval = _sys_readv(d, iov, iovcnt);
572 1.7 nathanw TESTCANCEL(self);
573 1.2 thorpej
574 1.2 thorpej return retval;
575 1.2 thorpej }
576 1.2 thorpej
577 1.39 christos ssize_t
578 1.39 christos recvfrom(int s, void * restrict buf, size_t len, int flags,
579 1.39 christos struct sockaddr * restrict from, socklen_t * restrict fromlen)
580 1.39 christos {
581 1.39 christos ssize_t retval;
582 1.39 christos pthread_t self;
583 1.39 christos
584 1.39 christos self = pthread__self();
585 1.39 christos TESTCANCEL(self);
586 1.39 christos retval = _sys_recvfrom(s, buf, len, flags, from, fromlen);
587 1.39 christos TESTCANCEL(self);
588 1.39 christos
589 1.39 christos return retval;
590 1.39 christos }
591 1.39 christos
592 1.39 christos ssize_t
593 1.39 christos recvmsg(int s, struct msghdr *msg, int flags)
594 1.39 christos {
595 1.39 christos ssize_t retval;
596 1.39 christos pthread_t self;
597 1.39 christos
598 1.39 christos self = pthread__self();
599 1.39 christos TESTCANCEL(self);
600 1.39 christos retval = _sys_recvmsg(s, msg, flags);
601 1.39 christos TESTCANCEL(self);
602 1.39 christos
603 1.39 christos return retval;
604 1.39 christos }
605 1.39 christos
606 1.39 christos int
607 1.39 christos recvmmsg(int s, struct mmsghdr *mmsg, unsigned int vlen,
608 1.39 christos unsigned int flags, struct timespec *timeout)
609 1.39 christos {
610 1.39 christos ssize_t retval;
611 1.39 christos pthread_t self;
612 1.39 christos
613 1.39 christos self = pthread__self();
614 1.39 christos TESTCANCEL(self);
615 1.39 christos retval = _sys_recvmmsg(s, mmsg, vlen, flags, timeout);
616 1.39 christos TESTCANCEL(self);
617 1.39 christos
618 1.39 christos return retval;
619 1.39 christos }
620 1.39 christos
621 1.2 thorpej int
622 1.42 riastrad __select50(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
623 1.2 thorpej struct timeval *timeout)
624 1.2 thorpej {
625 1.2 thorpej int retval;
626 1.2 thorpej pthread_t self;
627 1.2 thorpej
628 1.2 thorpej self = pthread__self();
629 1.7 nathanw TESTCANCEL(self);
630 1.25 christos retval = _sys___select50(nfds, readfds, writefds, exceptfds, timeout);
631 1.7 nathanw TESTCANCEL(self);
632 1.2 thorpej
633 1.2 thorpej return retval;
634 1.2 thorpej }
635 1.2 thorpej
636 1.39 christos ssize_t
637 1.39 christos sendto(int s, const void *msg, size_t len, int flags,
638 1.39 christos const struct sockaddr *to, socklen_t tolen)
639 1.39 christos {
640 1.39 christos int retval;
641 1.39 christos pthread_t self;
642 1.39 christos
643 1.39 christos self = pthread__self();
644 1.39 christos TESTCANCEL(self);
645 1.39 christos retval = _sys_sendto(s, msg, len, flags, to, tolen);
646 1.39 christos TESTCANCEL(self);
647 1.39 christos
648 1.39 christos return retval;
649 1.39 christos }
650 1.39 christos
651 1.39 christos ssize_t
652 1.39 christos sendmsg(int s, const struct msghdr *msg, int flags)
653 1.39 christos {
654 1.39 christos int retval;
655 1.39 christos pthread_t self;
656 1.39 christos
657 1.39 christos self = pthread__self();
658 1.39 christos TESTCANCEL(self);
659 1.39 christos retval = _sys_sendmsg(s, msg, flags);
660 1.39 christos TESTCANCEL(self);
661 1.39 christos
662 1.39 christos return retval;
663 1.39 christos }
664 1.39 christos
665 1.39 christos int
666 1.39 christos sendmmsg(int s, struct mmsghdr *mmsg, unsigned int vlen,
667 1.39 christos unsigned int flags)
668 1.39 christos {
669 1.39 christos int retval;
670 1.39 christos pthread_t self;
671 1.39 christos
672 1.39 christos self = pthread__self();
673 1.39 christos TESTCANCEL(self);
674 1.39 christos retval = _sys_sendmmsg(s, mmsg, vlen, flags);
675 1.39 christos TESTCANCEL(self);
676 1.39 christos
677 1.39 christos return retval;
678 1.39 christos }
679 1.39 christos
680 1.47 riastrad int
681 1.47 riastrad tcdrain(int fd)
682 1.47 riastrad {
683 1.47 riastrad int retval;
684 1.47 riastrad pthread_t self;
685 1.47 riastrad
686 1.47 riastrad self = pthread__self();
687 1.47 riastrad TESTCANCEL(self);
688 1.47 riastrad retval = ioctl(fd, TIOCDRAIN, 0);
689 1.47 riastrad TESTCANCEL(self);
690 1.47 riastrad
691 1.47 riastrad return retval;
692 1.47 riastrad }
693 1.39 christos
694 1.2 thorpej pid_t
695 1.25 christos __wait450(pid_t wpid, int *status, int options, struct rusage *rusage)
696 1.2 thorpej {
697 1.2 thorpej pid_t retval;
698 1.2 thorpej pthread_t self;
699 1.2 thorpej
700 1.2 thorpej self = pthread__self();
701 1.7 nathanw TESTCANCEL(self);
702 1.25 christos retval = _sys___wait450(wpid, status, options, rusage);
703 1.7 nathanw TESTCANCEL(self);
704 1.2 thorpej
705 1.2 thorpej return retval;
706 1.2 thorpej }
707 1.2 thorpej
708 1.2 thorpej ssize_t
709 1.2 thorpej write(int d, const void *buf, size_t nbytes)
710 1.2 thorpej {
711 1.2 thorpej ssize_t retval;
712 1.2 thorpej pthread_t self;
713 1.2 thorpej
714 1.2 thorpej self = pthread__self();
715 1.7 nathanw TESTCANCEL(self);
716 1.2 thorpej retval = _sys_write(d, buf, nbytes);
717 1.7 nathanw TESTCANCEL(self);
718 1.2 thorpej
719 1.2 thorpej return retval;
720 1.2 thorpej }
721 1.2 thorpej
722 1.2 thorpej ssize_t
723 1.2 thorpej writev(int d, const struct iovec *iov, int iovcnt)
724 1.2 thorpej {
725 1.2 thorpej ssize_t retval;
726 1.2 thorpej pthread_t self;
727 1.2 thorpej
728 1.2 thorpej self = pthread__self();
729 1.7 nathanw TESTCANCEL(self);
730 1.2 thorpej retval = _sys_writev(d, iov, iovcnt);
731 1.7 nathanw TESTCANCEL(self);
732 1.2 thorpej
733 1.2 thorpej return retval;
734 1.2 thorpej }
735 1.2 thorpej
736 1.14 ad int
737 1.14 ad __sigsuspend14(const sigset_t *sigmask)
738 1.14 ad {
739 1.14 ad pthread_t self;
740 1.14 ad int retval;
741 1.14 ad
742 1.14 ad self = pthread__self();
743 1.14 ad TESTCANCEL(self);
744 1.14 ad retval = _sys___sigsuspend14(sigmask);
745 1.14 ad TESTCANCEL(self);
746 1.14 ad
747 1.14 ad return retval;
748 1.14 ad }
749 1.14 ad
750 1.14 ad int
751 1.25 christos __sigtimedwait50(const sigset_t * __restrict set, siginfo_t * __restrict info,
752 1.25 christos const struct timespec * __restrict timeout)
753 1.14 ad {
754 1.14 ad pthread_t self;
755 1.14 ad int retval;
756 1.26 christos struct timespec tout, *tp;
757 1.36 agc
758 1.26 christos if (timeout) {
759 1.26 christos tout = *timeout;
760 1.26 christos tp = &tout;
761 1.26 christos } else
762 1.26 christos tp = NULL;
763 1.14 ad
764 1.14 ad self = pthread__self();
765 1.14 ad TESTCANCEL(self);
766 1.26 christos retval = ____sigtimedwait50(set, info, tp);
767 1.14 ad TESTCANCEL(self);
768 1.14 ad
769 1.14 ad return retval;
770 1.14 ad }
771 1.2 thorpej
772 1.37 christos int
773 1.36 agc sigwait(const sigset_t * __restrict set, int * __restrict sig)
774 1.36 agc {
775 1.36 agc pthread_t self;
776 1.36 agc int saved_errno;
777 1.36 agc int new_errno;
778 1.36 agc int retval;
779 1.36 agc
780 1.36 agc self = pthread__self();
781 1.36 agc saved_errno = errno;
782 1.36 agc TESTCANCEL(self);
783 1.36 agc retval = ____sigtimedwait50(set, NULL, NULL);
784 1.36 agc TESTCANCEL(self);
785 1.36 agc new_errno = errno;
786 1.36 agc errno = saved_errno;
787 1.36 agc if (retval < 0) {
788 1.36 agc return new_errno;
789 1.36 agc }
790 1.36 agc *sig = retval;
791 1.36 agc return 0;
792 1.36 agc }
793 1.36 agc
794 1.2 thorpej __strong_alias(_close, close)
795 1.39 christos __strong_alias(_clock_nanosleep, clock_nanosleep)
796 1.2 thorpej __strong_alias(_fcntl, fcntl)
797 1.9 kleink __strong_alias(_fdatasync, fdatasync)
798 1.2 thorpej __strong_alias(_fsync, fsync)
799 1.6 thorpej __weak_alias(fsync_range, _fsync_range)
800 1.22 ad __strong_alias(_mq_send, mq_send)
801 1.22 ad __strong_alias(_mq_receive, mq_receive)
802 1.2 thorpej __strong_alias(_msgrcv, msgrcv)
803 1.2 thorpej __strong_alias(_msgsnd, msgsnd)
804 1.2 thorpej __strong_alias(___msync13, __msync13)
805 1.27 enami __strong_alias(___nanosleep50, __nanosleep50)
806 1.2 thorpej __strong_alias(_open, open)
807 1.39 christos __strong_alias(_openat, openat)
808 1.2 thorpej __strong_alias(_poll, poll)
809 1.2 thorpej __strong_alias(_pread, pread)
810 1.2 thorpej __strong_alias(_pwrite, pwrite)
811 1.2 thorpej __strong_alias(_read, read)
812 1.2 thorpej __strong_alias(_readv, readv)
813 1.39 christos __strong_alias(_recvfrom, recvfrom)
814 1.39 christos __strong_alias(_recvmsg, recvmsg)
815 1.39 christos __strong_alias(_recvmmsg, recvmmsg)
816 1.39 christos __strong_alias(_sendmsg, sendmsg)
817 1.39 christos __strong_alias(_sendmmsg, sendmmsg)
818 1.39 christos __strong_alias(_sendto, sendto)
819 1.36 agc __strong_alias(_sigwait, sigwait)
820 1.2 thorpej __strong_alias(_write, write)
821 1.2 thorpej __strong_alias(_writev, writev)
822 1.20 ad
823 1.20 ad #endif /* !lint */
824