1 /* Wrapper arpund system calls to provide cancellation points.
2 Copyright (C) 1996,1997,1998,1999,2000,2001 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 see <http://www.gnu.org/licenses/>. */
28 #include <sys/epoll.h>
29 #include <sys/resource.h>
31 #include <sys/socket.h>
32 #include <sys/syscall.h>
36 /* We need a hook to force this file to be linked in when static
37 libpthread is used. */
38 const char __pthread_provide_wrappers = 0;
41 /* Using private interface to libc (__libc_foo) to implement
42 * cancellable versions of some libc functions */
43 #define CANCELABLE_SYSCALL(res_type, name, param_list, params) \
44 res_type __libc_##name param_list; \
46 __attribute__ ((weak)) \
51 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); \
52 result = __libc_##name params; \
53 pthread_setcanceltype (oldtype, NULL); \
57 #define CANCELABLE_SYSCALL_VA(res_type, name, param_list, params, last_arg) \
58 res_type __libc_##name param_list; \
60 __attribute__ ((weak)) \
66 pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); \
67 va_start (ap, last_arg); \
68 result = __libc_##name params; \
70 pthread_setcanceltype (oldtype, NULL); \
76 CANCELABLE_SYSCALL (int, close, (int fd), (fd))
80 CANCELABLE_SYSCALL_VA (int, fcntl, (int fd, int cmd, ...),
81 (fd, cmd, va_arg (ap, long int)), cmd)
83 #ifdef __UCLIBC_HAS_LFS__
85 CANCELABLE_SYSCALL_VA (int, fcntl64, (int fd, int cmd, ...),
86 (fd, cmd, va_arg (ap, long int)), cmd)
91 CANCELABLE_SYSCALL (int, fsync, (int fd), (fd))
95 CANCELABLE_SYSCALL (off_t, lseek, (int fd, off_t offset, int whence),
98 #ifdef __UCLIBC_HAS_LFS__
100 CANCELABLE_SYSCALL (off64_t, lseek64, (int fd, off64_t offset, int whence),
101 (fd, offset, whence))
104 #if defined(__NR_msync) && defined(__ARCH_USE_MMU__)
107 CANCELABLE_SYSCALL (int, msync, (void *addr, size_t length, int flags),
108 (addr, length, flags))
113 libpthread_hidden_proto(nanosleep)
114 CANCELABLE_SYSCALL (int, nanosleep, (const struct timespec *requested_time,
115 struct timespec *remaining),
116 (requested_time, remaining))
117 libpthread_hidden_def(nanosleep)
121 CANCELABLE_SYSCALL_VA (int, open, (const char *pathname, int flags, ...),
122 (pathname, flags, va_arg (ap, mode_t)), flags)
125 #ifdef __UCLIBC_HAS_LFS__
127 CANCELABLE_SYSCALL_VA (int, open64, (const char *pathname, int flags, ...),
128 (pathname, flags, va_arg (ap, mode_t)), flags)
132 CANCELABLE_SYSCALL (int, pause, (void), ())
135 /* Enable this if enabling these in syscalls.c */
137 CANCELABLE_SYSCALL (ssize_t, pread, (int fd, void *buf, size_t count,
139 (fd, buf, count, offset))
142 #if defined __UCLIBC_HAS_LFS__ && defined __NR_pread64
144 CANCELABLE_SYSCALL (ssize_t, pread64, (int fd, void *buf, size_t count,
146 (fd, buf, count, offset))
150 CANCELABLE_SYSCALL (ssize_t, pwrite, (int fd, const void *buf, size_t n,
152 (fd, buf, n, offset))
155 #if defined __UCLIBC_HAS_LFS__ && defined __NR_pwrited64
157 CANCELABLE_SYSCALL (ssize_t, pwrite64, (int fd, const void *buf, size_t n,
159 (fd, buf, n, offset))
163 CANCELABLE_SYSCALL (ssize_t, read, (int fd, void *buf, size_t count),
168 CANCELABLE_SYSCALL (int, system, (const char *line), (line))
172 CANCELABLE_SYSCALL (int, tcdrain, (int fd), (fd))
176 CANCELABLE_SYSCALL (__pid_t, wait, (__WAIT_STATUS_DEFN stat_loc), (stat_loc))
180 libpthread_hidden_proto(waitpid)
181 CANCELABLE_SYSCALL (__pid_t, waitpid, (__pid_t pid, int *stat_loc,
183 (pid, stat_loc, options))
184 libpthread_hidden_def(waitpid)
188 CANCELABLE_SYSCALL (ssize_t, write, (int fd, const void *buf, size_t n),
191 #if defined __UCLIBC_HAS_SOCKET__
192 /* The following system calls are thread cancellation points specified
196 CANCELABLE_SYSCALL (int, accept, (int fd, __SOCKADDR_ARG addr,
197 socklen_t *addr_len),
198 (fd, addr, addr_len))
201 CANCELABLE_SYSCALL (int, connect, (int fd, __CONST_SOCKADDR_ARG addr,
206 CANCELABLE_SYSCALL (ssize_t, recv, (int fd, __ptr_t buf, size_t n, int flags),
210 CANCELABLE_SYSCALL (ssize_t, recvfrom, (int fd, __ptr_t buf, size_t n, int flags,
211 __SOCKADDR_ARG addr, socklen_t *addr_len),
212 (fd, buf, n, flags, addr, addr_len))
215 CANCELABLE_SYSCALL (ssize_t, recvmsg, (int fd, struct msghdr *message, int flags),
216 (fd, message, flags))
219 CANCELABLE_SYSCALL (ssize_t, send, (int fd, const __ptr_t buf, size_t n,
224 CANCELABLE_SYSCALL (ssize_t, sendmsg, (int fd, const struct msghdr *message,
226 (fd, message, flags))
229 CANCELABLE_SYSCALL (ssize_t, sendto, (int fd, const __ptr_t buf, size_t n,
230 int flags, __CONST_SOCKADDR_ARG addr,
232 (fd, buf, n, flags, addr, addr_len))
233 #endif /* __UCLIBC_HAS_SOCKET__ */
235 #ifdef __UCLIBC_HAS_EPOLL__
236 # include <sys/epoll.h>
237 # ifdef __NR_epoll_wait
238 CANCELABLE_SYSCALL (int, epoll_wait, (int epfd, struct epoll_event *events, int maxevents, int timeout),
239 (epfd, events, maxevents, timeout))
241 # ifdef __NR_epoll_pwait
242 CANCELABLE_SYSCALL (int, epoll_pwait, (int epfd, struct epoll_event *events, int maxevents, int timeout,
243 const sigset_t *set),
244 (epfd, events, maxevents, timeout, set))