Update.
[glibc.git] / linuxthreads / wrapsyscall.c
blobc5180355b246b62ef63830ef067f6ecf4ca9b81d
1 /* Wrapper arpund system calls to provide cancelation points.
2 Copyright (C) 1996-1999,2000-2002 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 Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser 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 __attribute__ ((weak)) \
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; \
55 #define CANCELABLE_SYSCALL_VA(res_type, name, param_list, params, last_arg) \
56 res_type __libc_##name param_list; \
57 res_type \
58 __attribute__ ((weak)) \
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; \
72 #define PROMOTE_INTEGRAL_TYPE(type) __typeof__ ((type) 0 + 0)
75 /* close(2). */
76 CANCELABLE_SYSCALL (int, close, (int fd), (fd))
77 strong_alias (close, __close)
80 /* fcntl(2). */
81 CANCELABLE_SYSCALL_VA (int, fcntl, (int fd, int cmd, ...),
82 (fd, cmd, va_arg (ap, long int)), cmd)
83 strong_alias (fcntl, __fcntl)
86 /* fsync(2). */
87 CANCELABLE_SYSCALL (int, fsync, (int fd), (fd))
90 /* lseek(2). */
91 CANCELABLE_SYSCALL (off_t, lseek, (int fd, off_t offset, int whence),
92 (fd, offset, whence))
93 strong_alias (lseek, __lseek)
96 /* lseek64(2). */
97 CANCELABLE_SYSCALL (off64_t, lseek64, (int fd, off64_t offset, int whence),
98 (fd, offset, whence))
101 /* msync(2). */
102 CANCELABLE_SYSCALL (int, msync, (__ptr_t addr, size_t length, int flags),
103 (addr, length, flags))
106 /* nanosleep(2). */
107 CANCELABLE_SYSCALL (int, nanosleep, (const struct timespec *requested_time,
108 struct timespec *remaining),
109 (requested_time, remaining))
110 strong_alias (nanosleep, __nanosleep)
113 /* open(2). */
114 CANCELABLE_SYSCALL_VA (int, open, (const char *pathname, int flags, ...),
115 (pathname, flags,
116 va_arg (ap, PROMOTE_INTEGRAL_TYPE (mode_t))),
117 flags)
118 strong_alias (open, __open)
121 /* open64(3). */
122 CANCELABLE_SYSCALL_VA (int, open64, (const char *pathname, int flags, ...),
123 (pathname, flags,
124 va_arg (ap, PROMOTE_INTEGRAL_TYPE (mode_t))),
125 flags)
126 strong_alias (open64, __open64)
129 /* pause(2). */
130 CANCELABLE_SYSCALL (int, pause, (void), ())
133 /* pread(3). */
134 CANCELABLE_SYSCALL (ssize_t, pread, (int fd, void *buf, size_t count,
135 off_t offset),
136 (fd, buf, count, offset))
139 /* pread64(3). */
140 CANCELABLE_SYSCALL (ssize_t, pread64, (int fd, void *buf, size_t count,
141 off64_t offset),
142 (fd, buf, count, offset))
143 strong_alias (pread64, __pread64)
146 /* pwrite(3). */
147 CANCELABLE_SYSCALL (ssize_t, pwrite, (int fd, const void *buf, size_t n,
148 off_t offset),
149 (fd, buf, n, offset))
152 /* pwrite64(3). */
153 CANCELABLE_SYSCALL (ssize_t, pwrite64, (int fd, const void *buf, size_t n,
154 off64_t offset),
155 (fd, buf, n, offset))
156 strong_alias (pwrite64, __pwrite64)
159 /* read(2). */
160 CANCELABLE_SYSCALL (ssize_t, read, (int fd, void *buf, size_t count),
161 (fd, buf, count))
162 strong_alias (read, __read)
165 /* system(3). */
166 CANCELABLE_SYSCALL (int, system, (const char *line), (line))
169 /* tcdrain(2). */
170 CANCELABLE_SYSCALL (int, tcdrain, (int fd), (fd))
173 /* wait(2). */
174 CANCELABLE_SYSCALL (__pid_t, wait, (__WAIT_STATUS_DEFN stat_loc), (stat_loc))
175 strong_alias (wait, __wait)
178 /* waitpid(2). */
179 CANCELABLE_SYSCALL (__pid_t, waitpid, (__pid_t pid, int *stat_loc,
180 int options),
181 (pid, stat_loc, options))
184 /* write(2). */
185 CANCELABLE_SYSCALL (ssize_t, write, (int fd, const void *buf, size_t n),
186 (fd, buf, n))
187 strong_alias (write, __write)
190 /* The following system calls are thread cancellation points specified
191 in XNS. */
193 /* accept(2). */
194 CANCELABLE_SYSCALL (int, accept, (int fd, __SOCKADDR_ARG addr,
195 socklen_t *addr_len),
196 (fd, addr, addr_len))
198 /* connect(2). */
199 CANCELABLE_SYSCALL (int, connect, (int fd, __CONST_SOCKADDR_ARG addr,
200 socklen_t len),
201 (fd, addr, len))
202 strong_alias (connect, __connect)
204 /* recv(2). */
205 CANCELABLE_SYSCALL (ssize_t, recv, (int fd, __ptr_t buf, size_t n, int flags),
206 (fd, buf, n, flags))
208 /* recvfrom(2). */
209 CANCELABLE_SYSCALL (ssize_t, recvfrom, (int fd, __ptr_t buf, size_t n, int flags,
210 __SOCKADDR_ARG addr, socklen_t *addr_len),
211 (fd, buf, n, flags, addr, addr_len))
213 /* recvmsg(2). */
214 CANCELABLE_SYSCALL (ssize_t, recvmsg, (int fd, struct msghdr *message, int flags),
215 (fd, message, flags))
217 /* send(2). */
218 CANCELABLE_SYSCALL (ssize_t, send, (int fd, const __ptr_t buf, size_t n,
219 int flags),
220 (fd, buf, n, flags))
221 strong_alias (send, __send)
223 /* sendmsg(2). */
224 CANCELABLE_SYSCALL (ssize_t, sendmsg, (int fd, const struct msghdr *message,
225 int flags),
226 (fd, message, flags))
228 /* sendto(2). */
229 CANCELABLE_SYSCALL (ssize_t, sendto, (int fd, const __ptr_t buf, size_t n,
230 int flags, __CONST_SOCKADDR_ARG addr,
231 socklen_t addr_len),
232 (fd, buf, n, flags, addr, addr_len))