pthread_cancelstub.c revision 1.1.2.2 1 /* $NetBSD: pthread_cancelstub.c,v 1.1.2.2 2002/05/20 19:18:44 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_wait4(pid_t, int *, int, struct rusage *);
75 ssize_t _syscall_write(int, const void *, size_t);
76 ssize_t _syscall_writev(int, const struct iovec *, int);
77
78
79 int
80 close(int d)
81 {
82 int retval;
83 pthread_t self;
84
85 self = pthread__self();
86 pthread__testcancel(self);
87 retval = _syscall_close(d);
88 pthread__testcancel(self);
89
90 return retval;
91 }
92
93 int
94 fcntl(int fd, int cmd, ...)
95 {
96 int retval;
97 pthread_t self;
98 va_list ap;
99
100 self = pthread__self();
101 pthread__testcancel(self);
102 va_start(ap, cmd);
103 retval = _syscall_fcntl(fd, cmd, va_arg(ap, void *));
104 va_end(ap);
105 pthread__testcancel(self);
106
107 return retval;
108 }
109
110
111 int
112 fsync(int d)
113 {
114 int retval;
115 pthread_t self;
116
117 self = pthread__self();
118 pthread__testcancel(self);
119 retval = _syscall_fsync(d);
120 pthread__testcancel(self);
121
122 return retval;
123 }
124
125 ssize_t
126 msgrcv(int msgid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
127 {
128 ssize_t retval;
129 pthread_t self;
130
131 self = pthread__self();
132 pthread__testcancel(self);
133 retval = _syscall_msgrcv(msgid, msgp, msgsz, msgtyp, msgflg);
134 pthread__testcancel(self);
135
136 return retval;
137 }
138
139 int
140 msgsnd(int msgid, const void *msgp, size_t msgsz, int msgflg)
141 {
142 int retval;
143 pthread_t self;
144
145 self = pthread__self();
146 pthread__testcancel(self);
147 retval = _syscall_msgsnd(msgid, msgp, msgsz, msgflg);
148 pthread__testcancel(self);
149
150 return retval;
151 }
152
153 int
154 __msync13(void *addr, size_t len, int flags)
155 {
156 int retval;
157 pthread_t self;
158
159 self = pthread__self();
160 pthread__testcancel(self);
161 retval = _syscall___msync13(addr, len, flags);
162 pthread__testcancel(self);
163
164 return retval;
165 }
166
167 int
168 nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
169 {
170 int retval;
171 pthread_t self;
172
173 self = pthread__self();
174 pthread__testcancel(self);
175 retval = _syscall_nanosleep(rqtp, rmtp);
176 pthread__testcancel(self);
177
178 return retval;
179 }
180
181 int
182 open(const char *path, int flags, ...)
183 {
184 int retval;
185 pthread_t self;
186 va_list ap;
187
188 self = pthread__self();
189 pthread__testcancel(self);
190 va_start(ap, flags);
191 retval = _syscall_open(path, flags, va_arg(ap, mode_t));
192 va_end(ap);
193 pthread__testcancel(self);
194
195 return retval;
196 }
197
198 int
199 poll(struct pollfd *fds, nfds_t nfds, int timeout)
200 {
201 int retval;
202 pthread_t self;
203
204 self = pthread__self();
205 pthread__testcancel(self);
206 retval = _syscall_poll(fds, nfds, timeout);
207 pthread__testcancel(self);
208
209 return retval;
210 }
211
212 ssize_t
213 pread(int d, void *buf, size_t nbytes, off_t offset)
214 {
215 ssize_t retval;
216 pthread_t self;
217
218 self = pthread__self();
219 pthread__testcancel(self);
220 retval = _syscall_pread(d, buf, nbytes, offset);
221 pthread__testcancel(self);
222
223 return retval;
224 }
225
226 ssize_t
227 pwrite(int d, const void *buf, size_t nbytes, off_t offset)
228 {
229 ssize_t retval;
230 pthread_t self;
231
232 self = pthread__self();
233 pthread__testcancel(self);
234 retval = _syscall_pwrite(d, buf, nbytes, offset);
235 pthread__testcancel(self);
236
237 return retval;
238 }
239
240 ssize_t
241 read(int d, void *buf, size_t nbytes)
242 {
243 ssize_t retval;
244 pthread_t self;
245
246 self = pthread__self();
247 pthread__testcancel(self);
248 retval = _syscall_read(d, buf, nbytes);
249 pthread__testcancel(self);
250
251 return retval;
252 }
253
254 ssize_t
255 readv(int d, const struct iovec *iov, int iovcnt)
256 {
257 ssize_t retval;
258 pthread_t self;
259
260 self = pthread__self();
261 pthread__testcancel(self);
262 retval = _syscall_readv(d, iov, iovcnt);
263 pthread__testcancel(self);
264
265 return retval;
266 }
267
268 int
269 select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
270 struct timeval *timeout)
271 {
272 int retval;
273 pthread_t self;
274
275 self = pthread__self();
276 pthread__testcancel(self);
277 retval = _syscall_select(nfds, readfds, writefds, exceptfds, timeout);
278 pthread__testcancel(self);
279
280 return retval;
281 }
282
283 pid_t
284 wait4(pid_t wpid, int *status, int options, struct rusage *rusage)
285 {
286 pid_t retval;
287 pthread_t self;
288
289 self = pthread__self();
290 pthread__testcancel(self);
291 retval = _syscall_wait4(wpid, status, options, rusage);
292 pthread__testcancel(self);
293
294 return retval;
295 }
296
297 ssize_t
298 write(int d, const void *buf, size_t nbytes)
299 {
300 ssize_t retval;
301 pthread_t self;
302
303 self = pthread__self();
304 pthread__testcancel(self);
305 retval = _syscall_write(d, buf, nbytes);
306 pthread__testcancel(self);
307
308 return retval;
309 }
310
311 ssize_t
312 writev(int d, const struct iovec *iov, int iovcnt)
313 {
314 ssize_t retval;
315 pthread_t self;
316
317 self = pthread__self();
318 pthread__testcancel(self);
319 retval = _syscall_writev(d, iov, iovcnt);
320 pthread__testcancel(self);
321
322 return retval;
323 }
324