Update.
[glibc.git] / linuxthreads / wrapsyscall.c
blob7d3f8ac483b644bef8c600e7c74e2d206af68695
1 /* Wrapper arpund system calls to provide cancelation points.
2 Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
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.
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.
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. */
21 #include <fcntl.h>
22 #include <sys/mman.h>
23 #include <pthread.h>
24 #include <unistd.h>
25 #include <stdarg.h>
26 #include <stddef.h>
27 #include <stdlib.h>
28 #include <termios.h>
29 #include <sys/resource.h>
30 #include <sys/wait.h>
31 #include <sys/socket.h>
34 #ifndef SHARED
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
41 #define CANCELABLE_SYSCALL(res_type, name, param_list, params) \
42 res_type __libc_##name param_list; \
43 res_type \
44 name param_list \
45 { \
46 res_type result; \
47 int oldtype; \
48 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); \
49 result = __libc_##name params; \
50 pthread_setcanceltype (oldtype, NULL); \
51 return result; \
54 #define CANCELABLE_SYSCALL_VA(res_type, name, param_list, params, last_arg) \
55 res_type __libc_##name param_list; \
56 res_type \
57 name param_list \
58 { \
59 res_type result; \
60 int oldtype; \
61 va_list ap; \
62 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); \
63 va_start (ap, last_arg); \
64 result = __libc_##name params; \
65 va_end (ap); \
66 pthread_setcanceltype (oldtype, NULL); \
67 return result; \
71 /* close(2). */
72 CANCELABLE_SYSCALL (int, close, (int fd), (fd))
73 strong_alias (close, __close)
76 /* fcntl(2). */
77 CANCELABLE_SYSCALL_VA (int, fcntl, (int fd, int cmd, ...),
78 (fd, cmd, va_arg (ap, long int)), cmd)
79 strong_alias (fcntl, __fcntl)
82 /* fsync(2). */
83 CANCELABLE_SYSCALL (int, fsync, (int fd), (fd))
86 /* lseek(2). */
87 CANCELABLE_SYSCALL (off_t, lseek, (int fd, off_t offset, int whence),
88 (fd, offset, whence))
89 strong_alias (lseek, __lseek)
92 /* lseek64(2). */
93 CANCELABLE_SYSCALL (off64_t, lseek64, (int fd, off64_t offset, int whence),
94 (fd, offset, whence))
97 /* msync(2). */
98 CANCELABLE_SYSCALL (int, msync, (__ptr_t addr, size_t length, int flags),
99 (addr, length, flags))
102 /* nanosleep(2). */
103 CANCELABLE_SYSCALL (int, nanosleep, (const struct timespec *requested_time,
104 struct timespec *remaining),
105 (requested_time, remaining))
108 /* open(2). */
109 CANCELABLE_SYSCALL_VA (int, open, (const char *pathname, int flags, ...),
110 (pathname, flags, va_arg (ap, mode_t)), flags)
111 strong_alias (open, __open)
114 /* open64(3). */
115 CANCELABLE_SYSCALL_VA (int, open64, (const char *pathname, int flags, ...),
116 (pathname, flags, va_arg (ap, mode_t)), flags)
117 strong_alias (open64, __open64)
120 /* pause(2). */
121 CANCELABLE_SYSCALL (int, pause, (void), ())
124 /* pread(3). */
125 CANCELABLE_SYSCALL (ssize_t, pread, (int fd, void *buf, size_t count,
126 off_t offset),
127 (fd, buf, count, offset))
130 /* pread64(3). */
131 CANCELABLE_SYSCALL (ssize_t, pread64, (int fd, void *buf, size_t count,
132 off64_t offset),
133 (fd, buf, count, offset))
134 strong_alias (pread64, __pread64)
137 /* pwrite(3). */
138 CANCELABLE_SYSCALL (ssize_t, pwrite, (int fd, const void *buf, size_t n,
139 off_t offset),
140 (fd, buf, n, offset))
143 /* pwrite64(3). */
144 CANCELABLE_SYSCALL (ssize_t, pwrite64, (int fd, const void *buf, size_t n,
145 off64_t offset),
146 (fd, buf, n, offset))
147 strong_alias (pwrite64, __pwrite64)
150 /* read(2). */
151 CANCELABLE_SYSCALL (ssize_t, read, (int fd, void *buf, size_t count),
152 (fd, buf, count))
153 strong_alias (read, __read)
156 /* system(3). */
157 CANCELABLE_SYSCALL (int, system, (const char *line), (line))
160 /* tcdrain(2). */
161 CANCELABLE_SYSCALL (int, tcdrain, (int fd), (fd))
164 /* wait(2). */
165 CANCELABLE_SYSCALL (__pid_t, wait, (__WAIT_STATUS_DEFN stat_loc), (stat_loc))
166 strong_alias (wait, __wait)
169 /* waitpid(2). */
170 CANCELABLE_SYSCALL (__pid_t, waitpid, (__pid_t pid, int *stat_loc,
171 int options),
172 (pid, stat_loc, options))
175 /* write(2). */
176 CANCELABLE_SYSCALL (ssize_t, write, (int fd, const void *buf, size_t n),
177 (fd, buf, n))
178 strong_alias (write, __write)
181 /* The following system calls are thread cancellation points specified
182 in XNS. */
184 /* accept(2). */
185 CANCELABLE_SYSCALL (int, accept, (int fd, __SOCKADDR_ARG addr,
186 socklen_t *addr_len),
187 (fd, addr, addr_len))
189 /* connect(2). */
190 CANCELABLE_SYSCALL (int, connect, (int fd, __CONST_SOCKADDR_ARG addr,
191 socklen_t len),
192 (fd, addr, len))
193 strong_alias (connect, __connect)
195 /* recv(2). */
196 CANCELABLE_SYSCALL (int, recv, (int fd, __ptr_t buf, size_t n, int flags),
197 (fd, buf, n, flags))
199 /* recvfrom(2). */
200 CANCELABLE_SYSCALL (int, recvfrom, (int fd, __ptr_t buf, size_t n, int flags,
201 __SOCKADDR_ARG addr, socklen_t *addr_len),
202 (fd, buf, n, flags, addr, addr_len))
204 /* recvmsg(2). */
205 CANCELABLE_SYSCALL (int, recvmsg, (int fd, struct msghdr *message, int flags),
206 (fd, message, flags))
208 /* send(2). */
209 CANCELABLE_SYSCALL (int, send, (int fd, const __ptr_t buf, size_t n,
210 int flags),
211 (fd, buf, n, flags))
212 strong_alias (send, __send)
214 /* sendmsg(2). */
215 CANCELABLE_SYSCALL (int, sendmsg, (int fd, const struct msghdr *message,
216 int flags),
217 (fd, message, flags))
219 /* sendto(2). */
220 CANCELABLE_SYSCALL (int, sendto, (int fd, const __ptr_t buf, size_t n,
221 int flags, __CONST_SOCKADDR_ARG addr,
222 socklen_t addr_len),
223 (fd, buf, n, flags, addr, addr_len))