pthread_cancelstub.c revision 1.1.2.1 1 /* $NetBSD: pthread_cancelstub.c,v 1.1.2.1 2002/01/28 18:48:51 nathanw 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/msg.h>
40 #include <sys/types.h>
41 #include <sys/uio.h>
42 #include <sys/wait.h>
43 #include <fcntl.h>
44 #include <poll.h>
45 #include <stdarg.h>
46 #include <unistd.h>
47
48 /* XXX this is necessary to get the prototypes for the __sigsuspend14
49 * XXX and __msync13 internal names, instead of the application-visible
50 * XXX sigsuspend and msync names. It's kind of gross, but we're pretty
51 * XXX intimate with libc already.
52 */
53 #define __LIBC12_SOURCE__
54 #include <signal.h>
55 #include <sys/mman.h>
56
57 #include "pthread.h"
58 #include "pthread_int.h"
59
60 int _syscall_close(int);
61 int _syscall_fcntl(int, int, ...);
62 int _syscall_fsync(int);
63 ssize_t _syscall_msgrcv(int, void *, size_t, long, int);
64 int _syscall_msgsnd(int, const void *, size_t, int);
65 int _syscall___msync13(void *, size_t, int);
66 int _syscall_nanosleep(const struct timespec *, struct timespec *);
67 int _syscall_open(const char *, int, ...);
68 int _syscall_poll(struct pollfd *, nfds_t, int);
69 ssize_t _syscall_pread(int, void *, size_t, off_t);
70 ssize_t _syscall_pwrite(int, const void *, size_t, off_t);
71 ssize_t _syscall_read(int, void *, size_t);
72 ssize_t _syscall_readv(int, const struct iovec *, int);
73 int _syscall_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
74 int _syscall___sigsuspend14(const sigset_t *);
75 int _syscall_wait4(pid_t, int *, int, struct rusage *);
76 ssize_t _syscall_write(int, const void *, size_t);
77 ssize_t _syscall_writev(int, const struct iovec *, int);
78
79
80 int
81 close(int d)
82 {
83 int retval;
84 pthread_t self;
85
86 self = pthread__self();
87 pthread__testcancel(self);
88 retval = _syscall_close(d);
89 pthread__testcancel(self);
90
91 return retval;
92 }
93
94 int
95 fcntl(int fd, int cmd, ...)
96 {
97 int retval;
98 pthread_t self;
99 va_list ap;
100
101 self = pthread__self();
102 pthread__testcancel(self);
103 va_start(ap, cmd);
104 retval = _syscall_fcntl(fd, cmd, va_arg(ap, void *));
105 va_end(ap);
106 pthread__testcancel(self);
107
108 return retval;
109 }
110
111
112 int
113 fsync(int d)
114 {
115 int retval;
116 pthread_t self;
117
118 self = pthread__self();
119 pthread__testcancel(self);
120 retval = _syscall_fsync(d);
121 pthread__testcancel(self);
122
123 return retval;
124 }
125
126 ssize_t
127 msgrcv(int msgid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
128 {
129 ssize_t retval;
130 pthread_t self;
131
132 self = pthread__self();
133 pthread__testcancel(self);
134 retval = _syscall_msgrcv(msgid, msgp, msgsz, msgtyp, msgflg);
135 pthread__testcancel(self);
136
137 return retval;
138 }
139
140 int
141 msgsnd(int msgid, const void *msgp, size_t msgsz, int msgflg)
142 {
143 int retval;
144 pthread_t self;
145
146 self = pthread__self();
147 pthread__testcancel(self);
148 retval = _syscall_msgsnd(msgid, msgp, msgsz, msgflg);
149 pthread__testcancel(self);
150
151 return retval;
152 }
153
154 int
155 __msync13(void *addr, size_t len, int flags)
156 {
157 int retval;
158 pthread_t self;
159
160 self = pthread__self();
161 pthread__testcancel(self);
162 retval = _syscall___msync13(addr, len, flags);
163 pthread__testcancel(self);
164
165 return retval;
166 }
167
168 int
169 nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
170 {
171 int retval;
172 pthread_t self;
173
174 self = pthread__self();
175 pthread__testcancel(self);
176 retval = _syscall_nanosleep(rqtp, rmtp);
177 pthread__testcancel(self);
178
179 return retval;
180 }
181
182 int
183 open(const char *path, int flags, ...)
184 {
185 int retval;
186 pthread_t self;
187 va_list ap;
188
189 self = pthread__self();
190 pthread__testcancel(self);
191 va_start(ap, flags);
192 retval = _syscall_open(path, flags, va_arg(ap, mode_t));
193 va_end(ap);
194 pthread__testcancel(self);
195
196 return retval;
197 }
198
199 int
200 poll(struct pollfd *fds, nfds_t nfds, int timeout)
201 {
202 int retval;
203 pthread_t self;
204
205 self = pthread__self();
206 pthread__testcancel(self);
207 retval = _syscall_poll(fds, nfds, timeout);
208 pthread__testcancel(self);
209
210 return retval;
211 }
212
213 ssize_t
214 pread(int d, void *buf, size_t nbytes, off_t offset)
215 {
216 ssize_t retval;
217 pthread_t self;
218
219 self = pthread__self();
220 pthread__testcancel(self);
221 retval = _syscall_pread(d, buf, nbytes, offset);
222 pthread__testcancel(self);
223
224 return retval;
225 }
226
227 ssize_t
228 pwrite(int d, const void *buf, size_t nbytes, off_t offset)
229 {
230 ssize_t retval;
231 pthread_t self;
232
233 self = pthread__self();
234 pthread__testcancel(self);
235 retval = _syscall_pwrite(d, buf, nbytes, offset);
236 pthread__testcancel(self);
237
238 return retval;
239 }
240
241 ssize_t
242 read(int d, void *buf, size_t nbytes)
243 {
244 ssize_t retval;
245 pthread_t self;
246
247 self = pthread__self();
248 pthread__testcancel(self);
249 retval = _syscall_read(d, buf, nbytes);
250 pthread__testcancel(self);
251
252 return retval;
253 }
254
255 ssize_t
256 readv(int d, const struct iovec *iov, int iovcnt)
257 {
258 ssize_t retval;
259 pthread_t self;
260
261 self = pthread__self();
262 pthread__testcancel(self);
263 retval = _syscall_readv(d, iov, iovcnt);
264 pthread__testcancel(self);
265
266 return retval;
267 }
268
269 int
270 select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
271 struct timeval *timeout)
272 {
273 int retval;
274 pthread_t self;
275
276 self = pthread__self();
277 pthread__testcancel(self);
278 retval = _syscall_select(nfds, readfds, writefds, exceptfds, timeout);
279 pthread__testcancel(self);
280
281 return retval;
282 }
283
284 int
285 __sigsuspend14(const sigset_t *sigmask)
286 {
287 int retval;
288 pthread_t self;
289
290 self = pthread__self();
291 pthread__testcancel(self);
292 retval = _syscall___sigsuspend14(sigmask);
293 pthread__testcancel(self);
294
295 return retval;
296 }
297
298 pid_t
299 wait4(pid_t wpid, int *status, int options, struct rusage *rusage)
300 {
301 pid_t retval;
302 pthread_t self;
303
304 self = pthread__self();
305 pthread__testcancel(self);
306 retval = _syscall_wait4(wpid, status, options, rusage);
307 pthread__testcancel(self);
308
309 return retval;
310 }
311
312 ssize_t
313 write(int d, const void *buf, size_t nbytes)
314 {
315 ssize_t retval;
316 pthread_t self;
317
318 self = pthread__self();
319 pthread__testcancel(self);
320 retval = _syscall_write(d, buf, nbytes);
321 pthread__testcancel(self);
322
323 return retval;
324 }
325
326 ssize_t
327 writev(int d, const struct iovec *iov, int iovcnt)
328 {
329 ssize_t retval;
330 pthread_t self;
331
332 self = pthread__self();
333 pthread__testcancel(self);
334 retval = _syscall_writev(d, iov, iovcnt);
335 pthread__testcancel(self);
336
337 return retval;
338 }
339