1 /* Wrapper around 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
)
85 CANCELABLE_SYSCALL_VA (int, fcntl64
, (int fd
, int cmd
, ...),
86 (fd
, cmd
, va_arg (ap
, long int)), cmd
)
90 CANCELABLE_SYSCALL (int, fsync
, (int fd
), (fd
))
94 CANCELABLE_SYSCALL (off_t
, lseek
, (int fd
, off_t offset
, int whence
),
98 CANCELABLE_SYSCALL (off64_t
, lseek64
, (int fd
, off64_t offset
, int whence
),
101 #if defined(__NR_msync) && defined(__ARCH_USE_MMU__)
104 CANCELABLE_SYSCALL (int, msync
, (void *addr
, size_t length
, int flags
),
105 (addr
, length
, flags
))
110 libpthread_hidden_proto(nanosleep
)
111 CANCELABLE_SYSCALL (int, nanosleep
, (const struct timespec
*requested_time
,
112 struct timespec
*remaining
),
113 (requested_time
, remaining
))
114 libpthread_hidden_def(nanosleep
)
118 CANCELABLE_SYSCALL_VA (int, open
, (const char *pathname
, int flags
, ...),
119 (pathname
, flags
, va_arg (ap
, mode_t
)), flags
)
123 CANCELABLE_SYSCALL_VA (int, open64
, (const char *pathname
, int flags
, ...),
124 (pathname
, flags
, va_arg (ap
, mode_t
)), flags
)
127 CANCELABLE_SYSCALL (int, pause
, (void), ())
130 /* Enable this if enabling these in syscalls.c */
132 CANCELABLE_SYSCALL (ssize_t
, pread
, (int fd
, void *buf
, size_t count
,
134 (fd
, buf
, count
, offset
))
137 #if defined __NR_pread64
139 CANCELABLE_SYSCALL (ssize_t
, pread64
, (int fd
, void *buf
, size_t count
,
141 (fd
, buf
, count
, offset
))
145 CANCELABLE_SYSCALL (ssize_t
, pwrite
, (int fd
, const void *buf
, size_t n
,
147 (fd
, buf
, n
, offset
))
150 #if defined __NR_pwrited64
152 CANCELABLE_SYSCALL (ssize_t
, pwrite64
, (int fd
, const void *buf
, size_t n
,
154 (fd
, buf
, n
, offset
))
158 CANCELABLE_SYSCALL (ssize_t
, read
, (int fd
, void *buf
, size_t count
),
163 CANCELABLE_SYSCALL (int, system
, (const char *line
), (line
))
167 CANCELABLE_SYSCALL (int, tcdrain
, (int fd
), (fd
))
171 CANCELABLE_SYSCALL (__pid_t
, wait
, (__WAIT_STATUS_DEFN stat_loc
), (stat_loc
))
175 libpthread_hidden_proto(waitpid
)
176 CANCELABLE_SYSCALL (__pid_t
, waitpid
, (__pid_t pid
, int *stat_loc
,
178 (pid
, stat_loc
, options
))
179 libpthread_hidden_def(waitpid
)
183 CANCELABLE_SYSCALL (ssize_t
, write
, (int fd
, const void *buf
, size_t n
),
186 #if defined __UCLIBC_HAS_SOCKET__
187 /* The following system calls are thread cancellation points specified
191 CANCELABLE_SYSCALL (int, accept
, (int fd
, __SOCKADDR_ARG addr
,
192 socklen_t
*addr_len
),
193 (fd
, addr
, addr_len
))
195 #if defined __UCLIBC_LINUX_SPECIFIC__
197 CANCELABLE_SYSCALL (int, accept4
, (int fd
, __SOCKADDR_ARG addr
,
198 socklen_t
*addr_len
, int flags
),
199 (fd
, addr
, addr_len
, flags
))
203 CANCELABLE_SYSCALL (int, connect
, (int fd
, __CONST_SOCKADDR_ARG addr
,
208 CANCELABLE_SYSCALL (ssize_t
, recv
, (int fd
, __ptr_t buf
, size_t n
, int flags
),
212 CANCELABLE_SYSCALL (ssize_t
, recvfrom
, (int fd
, __ptr_t buf
, size_t n
, int flags
,
213 __SOCKADDR_ARG addr
, socklen_t
*addr_len
),
214 (fd
, buf
, n
, flags
, addr
, addr_len
))
217 CANCELABLE_SYSCALL (ssize_t
, recvmsg
, (int fd
, struct msghdr
*message
, int flags
),
218 (fd
, message
, flags
))
221 CANCELABLE_SYSCALL (ssize_t
, send
, (int fd
, const __ptr_t buf
, size_t n
,
226 CANCELABLE_SYSCALL (ssize_t
, sendmsg
, (int fd
, const struct msghdr
*message
,
228 (fd
, message
, flags
))
231 CANCELABLE_SYSCALL (ssize_t
, sendto
, (int fd
, const __ptr_t buf
, size_t n
,
232 int flags
, __CONST_SOCKADDR_ARG addr
,
234 (fd
, buf
, n
, flags
, addr
, addr_len
))
235 #endif /* __UCLIBC_HAS_SOCKET__ */
237 #ifdef __UCLIBC_HAS_EPOLL__
238 # include <sys/epoll.h>
239 # ifdef __NR_epoll_wait
240 CANCELABLE_SYSCALL (int, epoll_wait
, (int epfd
, struct epoll_event
*events
, int maxevents
, int timeout
),
241 (epfd
, events
, maxevents
, timeout
))
243 # ifdef __NR_epoll_pwait
244 CANCELABLE_SYSCALL (int, epoll_pwait
, (int epfd
, struct epoll_event
*events
, int maxevents
, int timeout
,
245 const sigset_t
*set
),
246 (epfd
, events
, maxevents
, timeout
, set
))