pthread_cancelstub.c revision 1.1.2.5 1 /* $NetBSD: pthread_cancelstub.c,v 1.1.2.5 2002/11/03 12:29:02 skrll 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 /*
49 * XXX this is necessary to get the prototypes for the __sigsuspend14
50 * XXX and __msync13 internal names, instead of the application-visible
51 * XXX sigsuspend and msync names. It's kind of gross, but we're pretty
52 * XXX intimate with libc already.
53 */
54 #define __LIBC12_SOURCE__
55 #include <signal.h>
56 #include <sys/mman.h>
57
58 #include "pthread.h"
59 #include "pthread_int.h"
60
61 int _sys_close(int);
62 int _sys_fcntl(int, int, ...);
63 int _sys_fsync(int);
64 ssize_t _sys_msgrcv(int, void *, size_t, long, int);
65 int _sys_msgsnd(int, const void *, size_t, int);
66 int _sys___msync13(void *, size_t, int);
67 int _sys_nanosleep(const struct timespec *, struct timespec *);
68 int _sys_open(const char *, int, ...);
69 int _sys_poll(struct pollfd *, nfds_t, int);
70 ssize_t _sys_pread(int, void *, size_t, off_t);
71 ssize_t _sys_pwrite(int, const void *, size_t, off_t);
72 ssize_t _sys_read(int, void *, size_t);
73 ssize_t _sys_readv(int, const struct iovec *, int);
74 int _sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
75 int _sys_wait4(pid_t, int *, int, struct rusage *);
76 ssize_t _sys_write(int, const void *, size_t);
77 ssize_t _sys_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 = _sys_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 = _sys_fcntl(fd, cmd, va_arg(ap, void *));
105 va_end(ap);
106 pthread__testcancel(self);
107
108 return retval;
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 = _sys_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 = _sys_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 = _sys_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 = _sys___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 = _sys_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 = _sys_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 = _sys_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 = _sys_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 = _sys_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 = _sys_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 = _sys_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 = _sys_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 = _sys_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 = _sys_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 = _sys_writev(d, iov, iovcnt);
320 pthread__testcancel(self);
321
322 return retval;
323 }
324
325
326 __strong_alias(_close, close)
327 __strong_alias(_fcntl, fcntl)
328 __strong_alias(_fsync, fsync)
329 __strong_alias(_msgrcv, msgrcv)
330 __strong_alias(_msgsnd, msgsnd)
331 __strong_alias(___msync13, __msync13)
332 __strong_alias(_nanosleep, nanosleep)
333 __strong_alias(_open, open)
334 __strong_alias(_poll, poll)
335 __strong_alias(_pread, pread)
336 __strong_alias(_pwrite, pwrite)
337 __strong_alias(_read, read)
338 __strong_alias(_readv, readv)
339 __strong_alias(_select, select)
340 __strong_alias(_wait4, wait4)
341 __strong_alias(_write, write)
342 __strong_alias(_writev, writev)
343