]>
Commit | Line | Data |
---|---|---|
5afdca00 | 1 | /* Wrapper arpund system calls to provide cancelation points. |
c2063191 | 2 | Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc. |
5afdca00 UD |
3 | This file is part of the GNU C Library. |
4 | Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. | |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
7 | modify it under the terms of the GNU Library General Public License as | |
8 | published by the Free Software Foundation; either version 2 of the | |
9 | License, or (at your option) any later version. | |
10 | ||
11 | The GNU C Library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Library General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Library General Public | |
17 | License along with the GNU C Library; see the file COPYING.LIB. If not, | |
18 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #include <fcntl.h> | |
628a0aa1 | 22 | #include <sys/mman.h> |
5afdca00 UD |
23 | #include <pthread.h> |
24 | #include <unistd.h> | |
25 | #include <stdarg.h> | |
26 | #include <stddef.h> | |
628a0aa1 UD |
27 | #include <stdlib.h> |
28 | #include <termios.h> | |
5afdca00 UD |
29 | #include <sys/resource.h> |
30 | #include <sys/wait.h> | |
31 | #include <sys/socket.h> | |
32 | ||
33 | ||
b5567b2a | 34 | #ifndef SHARED |
5afdca00 UD |
35 | /* We need a hook to force this file to be linked in when static |
36 | libpthread is used. */ | |
37 | const int __pthread_provide_wrappers = 0; | |
38 | #endif | |
39 | ||
40 | ||
41 | #define CANCELABLE_SYSCALL(res_type, name, param_list, params) \ | |
42 | res_type __libc_##name param_list; \ | |
43 | res_type \ | |
f218b5f5 | 44 | __attribute__ ((weak)) \ |
5afdca00 UD |
45 | name param_list \ |
46 | { \ | |
47 | res_type result; \ | |
48 | int oldtype; \ | |
49 | pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); \ | |
50 | result = __libc_##name params; \ | |
51 | pthread_setcanceltype (oldtype, NULL); \ | |
52 | return result; \ | |
53 | } | |
54 | ||
55 | #define CANCELABLE_SYSCALL_VA(res_type, name, param_list, params, last_arg) \ | |
56 | res_type __libc_##name param_list; \ | |
57 | res_type \ | |
f218b5f5 | 58 | __attribute__ ((weak)) \ |
5afdca00 UD |
59 | name param_list \ |
60 | { \ | |
61 | res_type result; \ | |
62 | int oldtype; \ | |
63 | va_list ap; \ | |
64 | pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); \ | |
65 | va_start (ap, last_arg); \ | |
66 | result = __libc_##name params; \ | |
67 | va_end (ap); \ | |
68 | pthread_setcanceltype (oldtype, NULL); \ | |
69 | return result; \ | |
70 | } | |
71 | ||
72 | ||
73 | /* close(2). */ | |
74 | CANCELABLE_SYSCALL (int, close, (int fd), (fd)) | |
75 | strong_alias (close, __close) | |
76 | ||
77 | ||
78 | /* fcntl(2). */ | |
79 | CANCELABLE_SYSCALL_VA (int, fcntl, (int fd, int cmd, ...), | |
80 | (fd, cmd, va_arg (ap, long int)), cmd) | |
81 | strong_alias (fcntl, __fcntl) | |
82 | ||
83 | ||
84 | /* fsync(2). */ | |
85 | CANCELABLE_SYSCALL (int, fsync, (int fd), (fd)) | |
86 | ||
87 | ||
88 | /* lseek(2). */ | |
89 | CANCELABLE_SYSCALL (off_t, lseek, (int fd, off_t offset, int whence), | |
90 | (fd, offset, whence)) | |
91 | strong_alias (lseek, __lseek) | |
92 | ||
93 | ||
778c59c8 UD |
94 | /* lseek64(2). */ |
95 | CANCELABLE_SYSCALL (off64_t, lseek64, (int fd, off64_t offset, int whence), | |
96 | (fd, offset, whence)) | |
97 | ||
98 | ||
5afdca00 | 99 | /* msync(2). */ |
628a0aa1 UD |
100 | CANCELABLE_SYSCALL (int, msync, (__ptr_t addr, size_t length, int flags), |
101 | (addr, length, flags)) | |
5afdca00 UD |
102 | |
103 | ||
104 | /* nanosleep(2). */ | |
105 | CANCELABLE_SYSCALL (int, nanosleep, (const struct timespec *requested_time, | |
106 | struct timespec *remaining), | |
107 | (requested_time, remaining)) | |
108 | ||
109 | ||
110 | /* open(2). */ | |
111 | CANCELABLE_SYSCALL_VA (int, open, (const char *pathname, int flags, ...), | |
112 | (pathname, flags, va_arg (ap, mode_t)), flags) | |
113 | strong_alias (open, __open) | |
114 | ||
115 | ||
778c59c8 UD |
116 | /* open64(3). */ |
117 | CANCELABLE_SYSCALL_VA (int, open64, (const char *pathname, int flags, ...), | |
118 | (pathname, flags, va_arg (ap, mode_t)), flags) | |
119 | strong_alias (open64, __open64) | |
120 | ||
121 | ||
5afdca00 UD |
122 | /* pause(2). */ |
123 | CANCELABLE_SYSCALL (int, pause, (void), ()) | |
124 | ||
125 | ||
778c59c8 UD |
126 | /* pread(3). */ |
127 | CANCELABLE_SYSCALL (ssize_t, pread, (int fd, void *buf, size_t count, | |
128 | off_t offset), | |
129 | (fd, buf, count, offset)) | |
130 | ||
131 | ||
132 | /* pread64(3). */ | |
133 | CANCELABLE_SYSCALL (ssize_t, pread64, (int fd, void *buf, size_t count, | |
134 | off64_t offset), | |
135 | (fd, buf, count, offset)) | |
136 | strong_alias (pread64, __pread64) | |
137 | ||
138 | ||
139 | /* pwrite(3). */ | |
140 | CANCELABLE_SYSCALL (ssize_t, pwrite, (int fd, const void *buf, size_t n, | |
141 | off_t offset), | |
142 | (fd, buf, n, offset)) | |
143 | ||
144 | ||
145 | /* pwrite64(3). */ | |
146 | CANCELABLE_SYSCALL (ssize_t, pwrite64, (int fd, const void *buf, size_t n, | |
147 | off64_t offset), | |
148 | (fd, buf, n, offset)) | |
149 | strong_alias (pwrite64, __pwrite64) | |
150 | ||
151 | ||
5afdca00 UD |
152 | /* read(2). */ |
153 | CANCELABLE_SYSCALL (ssize_t, read, (int fd, void *buf, size_t count), | |
154 | (fd, buf, count)) | |
155 | strong_alias (read, __read) | |
156 | ||
157 | ||
158 | /* system(3). */ | |
159 | CANCELABLE_SYSCALL (int, system, (const char *line), (line)) | |
160 | ||
161 | ||
162 | /* tcdrain(2). */ | |
163 | CANCELABLE_SYSCALL (int, tcdrain, (int fd), (fd)) | |
164 | ||
165 | ||
166 | /* wait(2). */ | |
167 | CANCELABLE_SYSCALL (__pid_t, wait, (__WAIT_STATUS_DEFN stat_loc), (stat_loc)) | |
168 | strong_alias (wait, __wait) | |
169 | ||
170 | ||
171 | /* waitpid(2). */ | |
172 | CANCELABLE_SYSCALL (__pid_t, waitpid, (__pid_t pid, int *stat_loc, | |
173 | int options), | |
174 | (pid, stat_loc, options)) | |
175 | ||
176 | ||
177 | /* write(2). */ | |
178 | CANCELABLE_SYSCALL (ssize_t, write, (int fd, const void *buf, size_t n), | |
179 | (fd, buf, n)) | |
180 | strong_alias (write, __write) | |
181 | ||
182 | ||
183 | /* The following system calls are thread cancellation points specified | |
184 | in XNS. */ | |
185 | ||
186 | /* accept(2). */ | |
187 | CANCELABLE_SYSCALL (int, accept, (int fd, __SOCKADDR_ARG addr, | |
188 | socklen_t *addr_len), | |
189 | (fd, addr, addr_len)) | |
190 | ||
191 | /* connect(2). */ | |
192 | CANCELABLE_SYSCALL (int, connect, (int fd, __CONST_SOCKADDR_ARG addr, | |
193 | socklen_t len), | |
194 | (fd, addr, len)) | |
195 | strong_alias (connect, __connect) | |
196 | ||
197 | /* recv(2). */ | |
c2063191 | 198 | CANCELABLE_SYSCALL (ssize_t, recv, (int fd, __ptr_t buf, size_t n, int flags), |
5afdca00 UD |
199 | (fd, buf, n, flags)) |
200 | ||
201 | /* recvfrom(2). */ | |
c2063191 AJ |
202 | CANCELABLE_SYSCALL (ssize_t, recvfrom, (int fd, __ptr_t buf, size_t n, int flags, |
203 | __SOCKADDR_ARG addr, socklen_t *addr_len), | |
5afdca00 UD |
204 | (fd, buf, n, flags, addr, addr_len)) |
205 | ||
206 | /* recvmsg(2). */ | |
c2063191 | 207 | CANCELABLE_SYSCALL (ssize_t, recvmsg, (int fd, struct msghdr *message, int flags), |
5afdca00 UD |
208 | (fd, message, flags)) |
209 | ||
210 | /* send(2). */ | |
c2063191 AJ |
211 | CANCELABLE_SYSCALL (ssize_t, send, (ssize_t fd, const __ptr_t buf, size_t n, |
212 | int flags), | |
5afdca00 UD |
213 | (fd, buf, n, flags)) |
214 | strong_alias (send, __send) | |
215 | ||
216 | /* sendmsg(2). */ | |
c2063191 AJ |
217 | CANCELABLE_SYSCALL (ssize_t, sendmsg, (int fd, const struct msghdr *message, |
218 | int flags), | |
5afdca00 UD |
219 | (fd, message, flags)) |
220 | ||
221 | /* sendto(2). */ | |
c2063191 AJ |
222 | CANCELABLE_SYSCALL (ssize_t, sendto, (ssize_t fd, const __ptr_t buf, size_t n, |
223 | int flags, __CONST_SOCKADDR_ARG addr, | |
224 | socklen_t addr_len), | |
5afdca00 | 225 | (fd, buf, n, flags, addr, addr_len)) |