pthread_cancelstub.c revision 1.45 1 1.45 christos /* $NetBSD: pthread_cancelstub.c,v 1.45 2024/01/19 19:55:03 christos 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.45 christos __RCSID("$NetBSD: pthread_cancelstub.c,v 1.45 2024/01/19 19:55:03 christos 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.2 thorpej #include <stdarg.h>
69 1.2 thorpej #include <unistd.h>
70 1.2 thorpej
71 1.2 thorpej #include <signal.h>
72 1.2 thorpej #include <sys/mman.h>
73 1.12 kleink #include <sys/select.h>
74 1.3 nathanw #include <sys/socket.h>
75 1.28 christos #include <sys/event.h>
76 1.45 christos #include <sys/resource.h>
77 1.2 thorpej
78 1.13 christos #include <compat/sys/mman.h>
79 1.25 christos #include <compat/sys/poll.h>
80 1.25 christos #include <compat/sys/select.h>
81 1.28 christos #include <compat/sys/event.h>
82 1.25 christos #include <compat/sys/wait.h>
83 1.45 christos #include <compat/sys/resource.h>
84 1.25 christos #include <compat/include/mqueue.h>
85 1.25 christos #include <compat/include/signal.h>
86 1.13 christos
87 1.2 thorpej #include "pthread.h"
88 1.2 thorpej #include "pthread_int.h"
89 1.38 christos #include "reentrant.h"
90 1.2 thorpej
91 1.10 kleink int pthread__cancel_stub_binder;
92 1.10 kleink
93 1.3 nathanw int _sys_accept(int, struct sockaddr *, socklen_t *);
94 1.25 christos int _sys___aio_suspend50(const struct aiocb * const [], int,
95 1.25 christos const struct timespec *);
96 1.25 christos int __aio_suspend50(const struct aiocb * const [], int,
97 1.15 rmind const struct timespec *);
98 1.39 christos int _sys_clock_nanosleep(clockid_t clock_id, int flags,
99 1.39 christos const struct timespec *rqtp, struct timespec *rmtp);
100 1.2 thorpej int _sys_close(int);
101 1.3 nathanw int _sys_connect(int, const struct sockaddr *, socklen_t);
102 1.2 thorpej int _sys_fcntl(int, int, ...);
103 1.9 kleink int _sys_fdatasync(int);
104 1.2 thorpej int _sys_fsync(int);
105 1.6 thorpej int _sys_fsync_range(int, int, off_t, off_t);
106 1.44 christos int _sys___kevent100(int, const struct kevent *, size_t, struct kevent *,
107 1.28 christos size_t, const struct timespec *);
108 1.15 rmind int _sys_mq_send(mqd_t, const char *, size_t, unsigned);
109 1.15 rmind ssize_t _sys_mq_receive(mqd_t, char *, size_t, unsigned *);
110 1.25 christos int _sys___mq_timedsend50(mqd_t, const char *, size_t, unsigned,
111 1.15 rmind const struct timespec *);
112 1.25 christos ssize_t _sys___mq_timedreceive50(mqd_t, char *, size_t, unsigned *,
113 1.15 rmind const struct timespec *);
114 1.2 thorpej ssize_t _sys_msgrcv(int, void *, size_t, long, int);
115 1.2 thorpej int _sys_msgsnd(int, const void *, size_t, int);
116 1.2 thorpej int _sys___msync13(void *, size_t, int);
117 1.27 enami int _sys___nanosleep50(const struct timespec *, struct timespec *);
118 1.27 enami int __nanosleep50(const struct timespec *, struct timespec *);
119 1.2 thorpej int _sys_open(const char *, int, ...);
120 1.39 christos int _sys_openat(int, const char *, int, ...);
121 1.2 thorpej int _sys_poll(struct pollfd *, nfds_t, int);
122 1.25 christos int _sys___pollts50(struct pollfd *, nfds_t, const struct timespec *,
123 1.11 kleink const sigset_t *);
124 1.2 thorpej ssize_t _sys_pread(int, void *, size_t, off_t);
125 1.25 christos int _sys___pselect50(int, fd_set *, fd_set *, fd_set *,
126 1.11 kleink const struct timespec *, const sigset_t *);
127 1.2 thorpej ssize_t _sys_pwrite(int, const void *, size_t, off_t);
128 1.2 thorpej ssize_t _sys_read(int, void *, size_t);
129 1.2 thorpej ssize_t _sys_readv(int, const struct iovec *, int);
130 1.39 christos ssize_t _sys_recvfrom(int, void * restrict, size_t, int,
131 1.39 christos struct sockaddr * restrict, socklen_t * restrict);
132 1.39 christos ssize_t _sys_recvmsg(int, struct msghdr *, int);
133 1.39 christos int _sys_recvmmsg(int, struct mmsghdr *, unsigned int, unsigned int,
134 1.39 christos struct timespec *);
135 1.40 christos ssize_t _sys_sendto(int, const void *, size_t, int, const struct sockaddr *,
136 1.40 christos socklen_t);
137 1.40 christos ssize_t _sys_sendmsg(int, const struct msghdr *, int);
138 1.40 christos int _sys_sendmmsg(int, struct mmsghdr *, unsigned int, unsigned int);
139 1.25 christos int _sys___select50(int, fd_set *, fd_set *, fd_set *, struct timeval *);
140 1.25 christos int _sys___wait450(pid_t, int *, int, struct rusage *);
141 1.2 thorpej ssize_t _sys_write(int, const void *, size_t);
142 1.2 thorpej ssize_t _sys_writev(int, const struct iovec *, int);
143 1.14 ad int _sys___sigsuspend14(const sigset_t *);
144 1.26 christos int ____sigtimedwait50(const sigset_t * __restrict, siginfo_t * __restrict,
145 1.26 christos struct timespec * __restrict);
146 1.14 ad int __sigsuspend14(const sigset_t *);
147 1.2 thorpej
148 1.7 nathanw #define TESTCANCEL(id) do { \
149 1.38 christos if (__predict_true(!__uselibcstub) && \
150 1.38 christos __predict_false((id)->pt_cancel)) \
151 1.17 ad pthread__cancelled(); \
152 1.43 rillig } while (0)
153 1.7 nathanw
154 1.2 thorpej
155 1.2 thorpej int
156 1.3 nathanw accept(int s, struct sockaddr *addr, socklen_t *addrlen)
157 1.3 nathanw {
158 1.3 nathanw int retval;
159 1.3 nathanw pthread_t self;
160 1.3 nathanw
161 1.3 nathanw self = pthread__self();
162 1.7 nathanw TESTCANCEL(self);
163 1.3 nathanw retval = _sys_accept(s, addr, addrlen);
164 1.7 nathanw TESTCANCEL(self);
165 1.42 riastrad
166 1.3 nathanw return retval;
167 1.3 nathanw }
168 1.3 nathanw
169 1.3 nathanw int
170 1.25 christos __aio_suspend50(const struct aiocb * const list[], int nent,
171 1.22 ad const struct timespec *timeout)
172 1.22 ad {
173 1.22 ad int retval;
174 1.22 ad pthread_t self;
175 1.22 ad
176 1.22 ad self = pthread__self();
177 1.22 ad TESTCANCEL(self);
178 1.25 christos retval = _sys___aio_suspend50(list, nent, timeout);
179 1.22 ad TESTCANCEL(self);
180 1.22 ad
181 1.22 ad return retval;
182 1.22 ad }
183 1.22 ad
184 1.22 ad int
185 1.44 christos __kevent100(int fd, const struct kevent *ev, size_t nev, struct kevent *rev,
186 1.28 christos size_t nrev, const struct timespec *ts)
187 1.28 christos {
188 1.28 christos int retval;
189 1.28 christos pthread_t self;
190 1.28 christos
191 1.28 christos self = pthread__self();
192 1.28 christos TESTCANCEL(self);
193 1.44 christos retval = _sys___kevent100(fd, ev, nev, rev, nrev, ts);
194 1.28 christos TESTCANCEL(self);
195 1.28 christos
196 1.28 christos return retval;
197 1.28 christos }
198 1.28 christos
199 1.28 christos int
200 1.39 christos clock_nanosleep(clockid_t clock_id, int flags,
201 1.39 christos const struct timespec *rqtp, struct timespec *rmtp)
202 1.39 christos {
203 1.39 christos int retval;
204 1.39 christos pthread_t self;
205 1.39 christos
206 1.39 christos self = pthread__self();
207 1.39 christos TESTCANCEL(self);
208 1.39 christos retval = _sys_clock_nanosleep(clock_id, flags, rqtp, rmtp);
209 1.39 christos TESTCANCEL(self);
210 1.42 riastrad
211 1.39 christos return retval;
212 1.39 christos }
213 1.39 christos
214 1.39 christos int
215 1.2 thorpej close(int d)
216 1.2 thorpej {
217 1.2 thorpej int retval;
218 1.2 thorpej pthread_t self;
219 1.2 thorpej
220 1.2 thorpej self = pthread__self();
221 1.7 nathanw TESTCANCEL(self);
222 1.2 thorpej retval = _sys_close(d);
223 1.7 nathanw TESTCANCEL(self);
224 1.42 riastrad
225 1.3 nathanw return retval;
226 1.3 nathanw }
227 1.3 nathanw
228 1.3 nathanw int
229 1.3 nathanw connect(int s, const struct sockaddr *addr, socklen_t namelen)
230 1.3 nathanw {
231 1.3 nathanw int retval;
232 1.3 nathanw pthread_t self;
233 1.3 nathanw
234 1.3 nathanw self = pthread__self();
235 1.7 nathanw TESTCANCEL(self);
236 1.3 nathanw retval = _sys_connect(s, addr, namelen);
237 1.7 nathanw TESTCANCEL(self);
238 1.42 riastrad
239 1.2 thorpej return retval;
240 1.2 thorpej }
241 1.2 thorpej
242 1.2 thorpej int
243 1.2 thorpej fcntl(int fd, int cmd, ...)
244 1.2 thorpej {
245 1.2 thorpej int retval;
246 1.2 thorpej pthread_t self;
247 1.2 thorpej va_list ap;
248 1.2 thorpej
249 1.2 thorpej self = pthread__self();
250 1.7 nathanw TESTCANCEL(self);
251 1.2 thorpej va_start(ap, cmd);
252 1.2 thorpej retval = _sys_fcntl(fd, cmd, va_arg(ap, void *));
253 1.2 thorpej va_end(ap);
254 1.7 nathanw TESTCANCEL(self);
255 1.2 thorpej
256 1.2 thorpej return retval;
257 1.2 thorpej }
258 1.2 thorpej
259 1.2 thorpej int
260 1.9 kleink fdatasync(int d)
261 1.9 kleink {
262 1.9 kleink int retval;
263 1.9 kleink pthread_t self;
264 1.9 kleink
265 1.9 kleink self = pthread__self();
266 1.9 kleink TESTCANCEL(self);
267 1.9 kleink retval = _sys_fdatasync(d);
268 1.9 kleink TESTCANCEL(self);
269 1.42 riastrad
270 1.9 kleink return retval;
271 1.9 kleink }
272 1.9 kleink
273 1.9 kleink int
274 1.2 thorpej fsync(int d)
275 1.2 thorpej {
276 1.2 thorpej int retval;
277 1.2 thorpej pthread_t self;
278 1.2 thorpej
279 1.2 thorpej self = pthread__self();
280 1.7 nathanw TESTCANCEL(self);
281 1.2 thorpej retval = _sys_fsync(d);
282 1.7 nathanw TESTCANCEL(self);
283 1.42 riastrad
284 1.2 thorpej return retval;
285 1.2 thorpej }
286 1.2 thorpej
287 1.6 thorpej int
288 1.6 thorpej fsync_range(int d, int f, off_t s, off_t e)
289 1.6 thorpej {
290 1.6 thorpej int retval;
291 1.6 thorpej pthread_t self;
292 1.6 thorpej
293 1.6 thorpej self = pthread__self();
294 1.7 nathanw TESTCANCEL(self);
295 1.6 thorpej retval = _sys_fsync_range(d, f, s, e);
296 1.7 nathanw TESTCANCEL(self);
297 1.6 thorpej
298 1.6 thorpej return retval;
299 1.6 thorpej }
300 1.6 thorpej
301 1.22 ad int
302 1.22 ad mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio)
303 1.22 ad {
304 1.22 ad int retval;
305 1.22 ad pthread_t self;
306 1.22 ad
307 1.22 ad self = pthread__self();
308 1.22 ad TESTCANCEL(self);
309 1.22 ad retval = _sys_mq_send(mqdes, msg_ptr, msg_len, msg_prio);
310 1.22 ad TESTCANCEL(self);
311 1.22 ad
312 1.22 ad return retval;
313 1.22 ad }
314 1.22 ad
315 1.22 ad ssize_t
316 1.22 ad mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio)
317 1.22 ad {
318 1.22 ad ssize_t retval;
319 1.22 ad pthread_t self;
320 1.22 ad
321 1.22 ad self = pthread__self();
322 1.22 ad TESTCANCEL(self);
323 1.22 ad retval = _sys_mq_receive(mqdes, msg_ptr, msg_len, msg_prio);
324 1.22 ad TESTCANCEL(self);
325 1.22 ad
326 1.22 ad return retval;
327 1.22 ad }
328 1.22 ad
329 1.22 ad int
330 1.25 christos __mq_timedsend50(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
331 1.22 ad unsigned msg_prio, const struct timespec *abst)
332 1.22 ad {
333 1.22 ad int retval;
334 1.22 ad pthread_t self;
335 1.22 ad
336 1.22 ad self = pthread__self();
337 1.22 ad TESTCANCEL(self);
338 1.25 christos retval = _sys___mq_timedsend50(mqdes, msg_ptr, msg_len, msg_prio, abst);
339 1.22 ad TESTCANCEL(self);
340 1.22 ad
341 1.22 ad return retval;
342 1.22 ad }
343 1.22 ad
344 1.22 ad ssize_t
345 1.25 christos __mq_timedreceive50(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio,
346 1.22 ad const struct timespec *abst)
347 1.22 ad {
348 1.22 ad ssize_t retval;
349 1.22 ad pthread_t self;
350 1.22 ad
351 1.22 ad self = pthread__self();
352 1.22 ad TESTCANCEL(self);
353 1.25 christos retval = _sys___mq_timedreceive50(mqdes, msg_ptr, msg_len, msg_prio, abst);
354 1.22 ad TESTCANCEL(self);
355 1.22 ad
356 1.22 ad return retval;
357 1.22 ad }
358 1.22 ad
359 1.2 thorpej ssize_t
360 1.2 thorpej msgrcv(int msgid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
361 1.2 thorpej {
362 1.2 thorpej ssize_t retval;
363 1.2 thorpej pthread_t self;
364 1.2 thorpej
365 1.2 thorpej self = pthread__self();
366 1.7 nathanw TESTCANCEL(self);
367 1.2 thorpej retval = _sys_msgrcv(msgid, msgp, msgsz, msgtyp, msgflg);
368 1.7 nathanw TESTCANCEL(self);
369 1.2 thorpej
370 1.2 thorpej return retval;
371 1.2 thorpej }
372 1.2 thorpej
373 1.2 thorpej int
374 1.2 thorpej msgsnd(int msgid, const void *msgp, size_t msgsz, int msgflg)
375 1.2 thorpej {
376 1.2 thorpej int retval;
377 1.2 thorpej pthread_t self;
378 1.2 thorpej
379 1.2 thorpej self = pthread__self();
380 1.7 nathanw TESTCANCEL(self);
381 1.2 thorpej retval = _sys_msgsnd(msgid, msgp, msgsz, msgflg);
382 1.7 nathanw TESTCANCEL(self);
383 1.2 thorpej
384 1.2 thorpej return retval;
385 1.2 thorpej }
386 1.2 thorpej
387 1.2 thorpej int
388 1.2 thorpej __msync13(void *addr, size_t len, int flags)
389 1.2 thorpej {
390 1.2 thorpej int retval;
391 1.2 thorpej pthread_t self;
392 1.2 thorpej
393 1.2 thorpej self = pthread__self();
394 1.7 nathanw TESTCANCEL(self);
395 1.2 thorpej retval = _sys___msync13(addr, len, flags);
396 1.7 nathanw TESTCANCEL(self);
397 1.2 thorpej
398 1.2 thorpej return retval;
399 1.2 thorpej }
400 1.2 thorpej
401 1.2 thorpej int
402 1.2 thorpej open(const char *path, int flags, ...)
403 1.2 thorpej {
404 1.2 thorpej int retval;
405 1.2 thorpej pthread_t self;
406 1.2 thorpej va_list ap;
407 1.2 thorpej
408 1.2 thorpej self = pthread__self();
409 1.7 nathanw TESTCANCEL(self);
410 1.2 thorpej va_start(ap, flags);
411 1.2 thorpej retval = _sys_open(path, flags, va_arg(ap, mode_t));
412 1.2 thorpej va_end(ap);
413 1.7 nathanw TESTCANCEL(self);
414 1.2 thorpej
415 1.2 thorpej return retval;
416 1.2 thorpej }
417 1.2 thorpej
418 1.2 thorpej int
419 1.39 christos openat(int fd, const char *path, int flags, ...)
420 1.39 christos {
421 1.39 christos int retval;
422 1.39 christos pthread_t self;
423 1.39 christos va_list ap;
424 1.39 christos
425 1.39 christos self = pthread__self();
426 1.39 christos TESTCANCEL(self);
427 1.39 christos va_start(ap, flags);
428 1.39 christos retval = _sys_openat(fd, path, flags, va_arg(ap, mode_t));
429 1.39 christos va_end(ap);
430 1.39 christos TESTCANCEL(self);
431 1.39 christos
432 1.39 christos return retval;
433 1.39 christos }
434 1.39 christos
435 1.39 christos int
436 1.27 enami __nanosleep50(const struct timespec *rqtp, struct timespec *rmtp)
437 1.27 enami {
438 1.27 enami int retval;
439 1.27 enami pthread_t self;
440 1.27 enami
441 1.27 enami self = pthread__self();
442 1.27 enami TESTCANCEL(self);
443 1.27 enami /*
444 1.27 enami * For now, just nanosleep. In the future, maybe pass a ucontext_t
445 1.27 enami * to _lwp_nanosleep() and allow it to recycle our kernel stack.
446 1.27 enami */
447 1.27 enami retval = _sys___nanosleep50(rqtp, rmtp);
448 1.27 enami TESTCANCEL(self);
449 1.27 enami
450 1.27 enami return retval;
451 1.27 enami }
452 1.27 enami
453 1.27 enami int
454 1.2 thorpej poll(struct pollfd *fds, nfds_t nfds, int timeout)
455 1.2 thorpej {
456 1.2 thorpej int retval;
457 1.2 thorpej pthread_t self;
458 1.2 thorpej
459 1.2 thorpej self = pthread__self();
460 1.7 nathanw TESTCANCEL(self);
461 1.2 thorpej retval = _sys_poll(fds, nfds, timeout);
462 1.7 nathanw TESTCANCEL(self);
463 1.2 thorpej
464 1.2 thorpej return retval;
465 1.2 thorpej }
466 1.2 thorpej
467 1.11 kleink int
468 1.25 christos __pollts50(struct pollfd *fds, nfds_t nfds, const struct timespec *ts,
469 1.11 kleink const sigset_t *sigmask)
470 1.11 kleink {
471 1.11 kleink int retval;
472 1.11 kleink pthread_t self;
473 1.11 kleink
474 1.11 kleink self = pthread__self();
475 1.11 kleink TESTCANCEL(self);
476 1.25 christos retval = _sys___pollts50(fds, nfds, ts, sigmask);
477 1.11 kleink TESTCANCEL(self);
478 1.11 kleink
479 1.11 kleink return retval;
480 1.11 kleink }
481 1.11 kleink
482 1.2 thorpej ssize_t
483 1.2 thorpej pread(int d, void *buf, size_t nbytes, off_t offset)
484 1.2 thorpej {
485 1.2 thorpej ssize_t retval;
486 1.2 thorpej pthread_t self;
487 1.2 thorpej
488 1.2 thorpej self = pthread__self();
489 1.7 nathanw TESTCANCEL(self);
490 1.2 thorpej retval = _sys_pread(d, buf, nbytes, offset);
491 1.7 nathanw TESTCANCEL(self);
492 1.2 thorpej
493 1.2 thorpej return retval;
494 1.2 thorpej }
495 1.2 thorpej
496 1.11 kleink int
497 1.42 riastrad __pselect50(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
498 1.11 kleink const struct timespec *timeout, const sigset_t *sigmask)
499 1.11 kleink {
500 1.11 kleink int retval;
501 1.11 kleink pthread_t self;
502 1.11 kleink
503 1.11 kleink self = pthread__self();
504 1.11 kleink TESTCANCEL(self);
505 1.25 christos retval = _sys___pselect50(nfds, readfds, writefds, exceptfds, timeout,
506 1.11 kleink sigmask);
507 1.11 kleink TESTCANCEL(self);
508 1.11 kleink
509 1.11 kleink return retval;
510 1.11 kleink }
511 1.11 kleink
512 1.2 thorpej ssize_t
513 1.2 thorpej pwrite(int d, const void *buf, size_t nbytes, off_t offset)
514 1.2 thorpej {
515 1.2 thorpej ssize_t retval;
516 1.2 thorpej pthread_t self;
517 1.2 thorpej
518 1.2 thorpej self = pthread__self();
519 1.7 nathanw TESTCANCEL(self);
520 1.2 thorpej retval = _sys_pwrite(d, buf, nbytes, offset);
521 1.7 nathanw TESTCANCEL(self);
522 1.2 thorpej
523 1.2 thorpej return retval;
524 1.2 thorpej }
525 1.2 thorpej
526 1.2 thorpej ssize_t
527 1.35 joerg read(int d, void *buf, size_t nbytes)
528 1.35 joerg {
529 1.35 joerg ssize_t retval;
530 1.35 joerg pthread_t self;
531 1.35 joerg
532 1.35 joerg self = pthread__self();
533 1.35 joerg TESTCANCEL(self);
534 1.35 joerg retval = _sys_read(d, buf, nbytes);
535 1.35 joerg TESTCANCEL(self);
536 1.35 joerg
537 1.35 joerg return retval;
538 1.35 joerg }
539 1.35 joerg
540 1.35 joerg ssize_t
541 1.2 thorpej readv(int d, const struct iovec *iov, int iovcnt)
542 1.2 thorpej {
543 1.2 thorpej ssize_t retval;
544 1.2 thorpej pthread_t self;
545 1.2 thorpej
546 1.2 thorpej self = pthread__self();
547 1.7 nathanw TESTCANCEL(self);
548 1.2 thorpej retval = _sys_readv(d, iov, iovcnt);
549 1.7 nathanw TESTCANCEL(self);
550 1.2 thorpej
551 1.2 thorpej return retval;
552 1.2 thorpej }
553 1.2 thorpej
554 1.39 christos ssize_t
555 1.39 christos recvfrom(int s, void * restrict buf, size_t len, int flags,
556 1.39 christos struct sockaddr * restrict from, socklen_t * restrict fromlen)
557 1.39 christos {
558 1.39 christos ssize_t retval;
559 1.39 christos pthread_t self;
560 1.39 christos
561 1.39 christos self = pthread__self();
562 1.39 christos TESTCANCEL(self);
563 1.39 christos retval = _sys_recvfrom(s, buf, len, flags, from, fromlen);
564 1.39 christos TESTCANCEL(self);
565 1.39 christos
566 1.39 christos return retval;
567 1.39 christos }
568 1.39 christos
569 1.39 christos ssize_t
570 1.39 christos recvmsg(int s, struct msghdr *msg, int flags)
571 1.39 christos {
572 1.39 christos ssize_t retval;
573 1.39 christos pthread_t self;
574 1.39 christos
575 1.39 christos self = pthread__self();
576 1.39 christos TESTCANCEL(self);
577 1.39 christos retval = _sys_recvmsg(s, msg, flags);
578 1.39 christos TESTCANCEL(self);
579 1.39 christos
580 1.39 christos return retval;
581 1.39 christos }
582 1.39 christos
583 1.39 christos int
584 1.39 christos recvmmsg(int s, struct mmsghdr *mmsg, unsigned int vlen,
585 1.39 christos unsigned int flags, struct timespec *timeout)
586 1.39 christos {
587 1.39 christos ssize_t retval;
588 1.39 christos pthread_t self;
589 1.39 christos
590 1.39 christos self = pthread__self();
591 1.39 christos TESTCANCEL(self);
592 1.39 christos retval = _sys_recvmmsg(s, mmsg, vlen, flags, timeout);
593 1.39 christos TESTCANCEL(self);
594 1.39 christos
595 1.39 christos return retval;
596 1.39 christos }
597 1.39 christos
598 1.2 thorpej int
599 1.42 riastrad __select50(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
600 1.2 thorpej struct timeval *timeout)
601 1.2 thorpej {
602 1.2 thorpej int retval;
603 1.2 thorpej pthread_t self;
604 1.2 thorpej
605 1.2 thorpej self = pthread__self();
606 1.7 nathanw TESTCANCEL(self);
607 1.25 christos retval = _sys___select50(nfds, readfds, writefds, exceptfds, timeout);
608 1.7 nathanw TESTCANCEL(self);
609 1.2 thorpej
610 1.2 thorpej return retval;
611 1.2 thorpej }
612 1.2 thorpej
613 1.39 christos ssize_t
614 1.39 christos sendto(int s, const void *msg, size_t len, int flags,
615 1.39 christos const struct sockaddr *to, socklen_t tolen)
616 1.39 christos {
617 1.39 christos int retval;
618 1.39 christos pthread_t self;
619 1.39 christos
620 1.39 christos self = pthread__self();
621 1.39 christos TESTCANCEL(self);
622 1.39 christos retval = _sys_sendto(s, msg, len, flags, to, tolen);
623 1.39 christos TESTCANCEL(self);
624 1.39 christos
625 1.39 christos return retval;
626 1.39 christos }
627 1.39 christos
628 1.39 christos ssize_t
629 1.39 christos sendmsg(int s, const struct msghdr *msg, int flags)
630 1.39 christos {
631 1.39 christos int retval;
632 1.39 christos pthread_t self;
633 1.39 christos
634 1.39 christos self = pthread__self();
635 1.39 christos TESTCANCEL(self);
636 1.39 christos retval = _sys_sendmsg(s, msg, flags);
637 1.39 christos TESTCANCEL(self);
638 1.39 christos
639 1.39 christos return retval;
640 1.39 christos }
641 1.39 christos
642 1.39 christos int
643 1.39 christos sendmmsg(int s, struct mmsghdr *mmsg, unsigned int vlen,
644 1.39 christos unsigned int flags)
645 1.39 christos {
646 1.39 christos int retval;
647 1.39 christos pthread_t self;
648 1.39 christos
649 1.39 christos self = pthread__self();
650 1.39 christos TESTCANCEL(self);
651 1.39 christos retval = _sys_sendmmsg(s, mmsg, vlen, flags);
652 1.39 christos TESTCANCEL(self);
653 1.39 christos
654 1.39 christos return retval;
655 1.39 christos }
656 1.39 christos
657 1.39 christos
658 1.2 thorpej pid_t
659 1.25 christos __wait450(pid_t wpid, int *status, int options, struct rusage *rusage)
660 1.2 thorpej {
661 1.2 thorpej pid_t retval;
662 1.2 thorpej pthread_t self;
663 1.2 thorpej
664 1.2 thorpej self = pthread__self();
665 1.7 nathanw TESTCANCEL(self);
666 1.25 christos retval = _sys___wait450(wpid, status, options, rusage);
667 1.7 nathanw TESTCANCEL(self);
668 1.2 thorpej
669 1.2 thorpej return retval;
670 1.2 thorpej }
671 1.2 thorpej
672 1.2 thorpej ssize_t
673 1.2 thorpej write(int d, const void *buf, size_t nbytes)
674 1.2 thorpej {
675 1.2 thorpej ssize_t retval;
676 1.2 thorpej pthread_t self;
677 1.2 thorpej
678 1.2 thorpej self = pthread__self();
679 1.7 nathanw TESTCANCEL(self);
680 1.2 thorpej retval = _sys_write(d, buf, nbytes);
681 1.7 nathanw TESTCANCEL(self);
682 1.2 thorpej
683 1.2 thorpej return retval;
684 1.2 thorpej }
685 1.2 thorpej
686 1.2 thorpej ssize_t
687 1.2 thorpej writev(int d, const struct iovec *iov, int iovcnt)
688 1.2 thorpej {
689 1.2 thorpej ssize_t retval;
690 1.2 thorpej pthread_t self;
691 1.2 thorpej
692 1.2 thorpej self = pthread__self();
693 1.7 nathanw TESTCANCEL(self);
694 1.2 thorpej retval = _sys_writev(d, iov, iovcnt);
695 1.7 nathanw TESTCANCEL(self);
696 1.2 thorpej
697 1.2 thorpej return retval;
698 1.2 thorpej }
699 1.2 thorpej
700 1.14 ad int
701 1.14 ad __sigsuspend14(const sigset_t *sigmask)
702 1.14 ad {
703 1.14 ad pthread_t self;
704 1.14 ad int retval;
705 1.14 ad
706 1.14 ad self = pthread__self();
707 1.14 ad TESTCANCEL(self);
708 1.14 ad retval = _sys___sigsuspend14(sigmask);
709 1.14 ad TESTCANCEL(self);
710 1.14 ad
711 1.14 ad return retval;
712 1.14 ad }
713 1.14 ad
714 1.14 ad int
715 1.25 christos __sigtimedwait50(const sigset_t * __restrict set, siginfo_t * __restrict info,
716 1.25 christos const struct timespec * __restrict timeout)
717 1.14 ad {
718 1.14 ad pthread_t self;
719 1.14 ad int retval;
720 1.26 christos struct timespec tout, *tp;
721 1.36 agc
722 1.26 christos if (timeout) {
723 1.26 christos tout = *timeout;
724 1.26 christos tp = &tout;
725 1.26 christos } else
726 1.26 christos tp = NULL;
727 1.14 ad
728 1.14 ad self = pthread__self();
729 1.14 ad TESTCANCEL(self);
730 1.26 christos retval = ____sigtimedwait50(set, info, tp);
731 1.14 ad TESTCANCEL(self);
732 1.14 ad
733 1.14 ad return retval;
734 1.14 ad }
735 1.2 thorpej
736 1.37 christos int
737 1.36 agc sigwait(const sigset_t * __restrict set, int * __restrict sig)
738 1.36 agc {
739 1.36 agc pthread_t self;
740 1.36 agc int saved_errno;
741 1.36 agc int new_errno;
742 1.36 agc int retval;
743 1.36 agc
744 1.36 agc self = pthread__self();
745 1.36 agc saved_errno = errno;
746 1.36 agc TESTCANCEL(self);
747 1.36 agc retval = ____sigtimedwait50(set, NULL, NULL);
748 1.36 agc TESTCANCEL(self);
749 1.36 agc new_errno = errno;
750 1.36 agc errno = saved_errno;
751 1.36 agc if (retval < 0) {
752 1.36 agc return new_errno;
753 1.36 agc }
754 1.36 agc *sig = retval;
755 1.36 agc return 0;
756 1.36 agc }
757 1.36 agc
758 1.2 thorpej __strong_alias(_close, close)
759 1.39 christos __strong_alias(_clock_nanosleep, clock_nanosleep)
760 1.2 thorpej __strong_alias(_fcntl, fcntl)
761 1.9 kleink __strong_alias(_fdatasync, fdatasync)
762 1.2 thorpej __strong_alias(_fsync, fsync)
763 1.6 thorpej __weak_alias(fsync_range, _fsync_range)
764 1.22 ad __strong_alias(_mq_send, mq_send)
765 1.22 ad __strong_alias(_mq_receive, mq_receive)
766 1.2 thorpej __strong_alias(_msgrcv, msgrcv)
767 1.2 thorpej __strong_alias(_msgsnd, msgsnd)
768 1.2 thorpej __strong_alias(___msync13, __msync13)
769 1.27 enami __strong_alias(___nanosleep50, __nanosleep50)
770 1.2 thorpej __strong_alias(_open, open)
771 1.39 christos __strong_alias(_openat, openat)
772 1.2 thorpej __strong_alias(_poll, poll)
773 1.2 thorpej __strong_alias(_pread, pread)
774 1.2 thorpej __strong_alias(_pwrite, pwrite)
775 1.2 thorpej __strong_alias(_read, read)
776 1.2 thorpej __strong_alias(_readv, readv)
777 1.39 christos __strong_alias(_recvfrom, recvfrom)
778 1.39 christos __strong_alias(_recvmsg, recvmsg)
779 1.39 christos __strong_alias(_recvmmsg, recvmmsg)
780 1.39 christos __strong_alias(_sendmsg, sendmsg)
781 1.39 christos __strong_alias(_sendmmsg, sendmmsg)
782 1.39 christos __strong_alias(_sendto, sendto)
783 1.36 agc __strong_alias(_sigwait, sigwait)
784 1.2 thorpej __strong_alias(_write, write)
785 1.2 thorpej __strong_alias(_writev, writev)
786 1.20 ad
787 1.20 ad #endif /* !lint */
788