123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- #include <fcntl.h>
- #include <sys/mman.h>
- #include <pthread.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stddef.h>
- #include <stdlib.h>
- #include <termios.h>
- #include <sys/epoll.h>
- #include <sys/resource.h>
- #include <sys/wait.h>
- #include <sys/socket.h>
- #include <sys/syscall.h>
- #ifndef __PIC__
- const char __pthread_provide_wrappers = 0;
- #endif
- #define CANCELABLE_SYSCALL(res_type, name, param_list, params) \
- res_type __libc_##name param_list; \
- res_type \
- __attribute__ ((weak)) \
- name param_list \
- { \
- res_type result; \
- int oldtype; \
- pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); \
- result = __libc_##name params; \
- pthread_setcanceltype (oldtype, NULL); \
- return result; \
- }
- #define CANCELABLE_SYSCALL_VA(res_type, name, param_list, params, last_arg) \
- res_type __libc_##name param_list; \
- res_type \
- __attribute__ ((weak)) \
- name param_list \
- { \
- res_type result; \
- int oldtype; \
- va_list ap; \
- pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); \
- va_start (ap, last_arg); \
- result = __libc_##name params; \
- va_end (ap); \
- pthread_setcanceltype (oldtype, NULL); \
- return result; \
- }
- CANCELABLE_SYSCALL (int, close, (int fd), (fd))
- CANCELABLE_SYSCALL_VA (int, fcntl, (int fd, int cmd, ...),
- (fd, cmd, va_arg (ap, long int)), cmd)
- #if __WORDSIZE == 32
- CANCELABLE_SYSCALL_VA (int, fcntl64, (int fd, int cmd, ...),
- (fd, cmd, va_arg (ap, long int)), cmd)
- #endif
- CANCELABLE_SYSCALL (int, fsync, (int fd), (fd))
- CANCELABLE_SYSCALL (off_t, lseek, (int fd, off_t offset, int whence),
- (fd, offset, whence))
- CANCELABLE_SYSCALL (off64_t, lseek64, (int fd, off64_t offset, int whence),
- (fd, offset, whence))
- #if defined(__NR_msync) && defined(__ARCH_USE_MMU__)
- CANCELABLE_SYSCALL (int, msync, (void *addr, size_t length, int flags),
- (addr, length, flags))
- #endif
- libpthread_hidden_proto(nanosleep)
- CANCELABLE_SYSCALL (int, nanosleep, (const struct timespec *requested_time,
- struct timespec *remaining),
- (requested_time, remaining))
- libpthread_hidden_def(nanosleep)
- CANCELABLE_SYSCALL_VA (int, open, (const char *pathname, int flags, ...),
- (pathname, flags, va_arg (ap, mode_t)), flags)
- CANCELABLE_SYSCALL_VA (int, open64, (const char *pathname, int flags, ...),
- (pathname, flags, va_arg (ap, mode_t)), flags)
- CANCELABLE_SYSCALL (int, pause, (void), ())
- CANCELABLE_SYSCALL (ssize_t, pread, (int fd, void *buf, size_t count,
- off_t offset),
- (fd, buf, count, offset))
- #if defined __NR_pread64
- CANCELABLE_SYSCALL (ssize_t, pread64, (int fd, void *buf, size_t count,
- off64_t offset),
- (fd, buf, count, offset))
- #endif
- CANCELABLE_SYSCALL (ssize_t, pwrite, (int fd, const void *buf, size_t n,
- off_t offset),
- (fd, buf, n, offset))
- #if defined __NR_pwrited64
- CANCELABLE_SYSCALL (ssize_t, pwrite64, (int fd, const void *buf, size_t n,
- off64_t offset),
- (fd, buf, n, offset))
- #endif
- CANCELABLE_SYSCALL (ssize_t, read, (int fd, void *buf, size_t count),
- (fd, buf, count))
- CANCELABLE_SYSCALL (int, system, (const char *line), (line))
- CANCELABLE_SYSCALL (int, tcdrain, (int fd), (fd))
- CANCELABLE_SYSCALL (__pid_t, wait, (__WAIT_STATUS_DEFN stat_loc), (stat_loc))
- libpthread_hidden_proto(waitpid)
- CANCELABLE_SYSCALL (__pid_t, waitpid, (__pid_t pid, int *stat_loc,
- int options),
- (pid, stat_loc, options))
- libpthread_hidden_def(waitpid)
- CANCELABLE_SYSCALL (ssize_t, write, (int fd, const void *buf, size_t n),
- (fd, buf, n))
- #if defined __UCLIBC_HAS_SOCKET__
- CANCELABLE_SYSCALL (int, accept, (int fd, __SOCKADDR_ARG addr,
- socklen_t *addr_len),
- (fd, addr, addr_len))
- CANCELABLE_SYSCALL (int, connect, (int fd, __CONST_SOCKADDR_ARG addr,
- socklen_t len),
- (fd, addr, len))
- CANCELABLE_SYSCALL (ssize_t, recv, (int fd, __ptr_t buf, size_t n, int flags),
- (fd, buf, n, flags))
- CANCELABLE_SYSCALL (ssize_t, recvfrom, (int fd, __ptr_t buf, size_t n, int flags,
- __SOCKADDR_ARG addr, socklen_t *addr_len),
- (fd, buf, n, flags, addr, addr_len))
- CANCELABLE_SYSCALL (ssize_t, recvmsg, (int fd, struct msghdr *message, int flags),
- (fd, message, flags))
- CANCELABLE_SYSCALL (ssize_t, send, (int fd, const __ptr_t buf, size_t n,
- int flags),
- (fd, buf, n, flags))
- CANCELABLE_SYSCALL (ssize_t, sendmsg, (int fd, const struct msghdr *message,
- int flags),
- (fd, message, flags))
- CANCELABLE_SYSCALL (ssize_t, sendto, (int fd, const __ptr_t buf, size_t n,
- int flags, __CONST_SOCKADDR_ARG addr,
- socklen_t addr_len),
- (fd, buf, n, flags, addr, addr_len))
- #endif
- #ifdef __UCLIBC_HAS_EPOLL__
- # include <sys/epoll.h>
- # ifdef __NR_epoll_wait
- CANCELABLE_SYSCALL (int, epoll_wait, (int epfd, struct epoll_event *events, int maxevents, int timeout),
- (epfd, events, maxevents, timeout))
- # endif
- # ifdef __NR_epoll_pwait
- CANCELABLE_SYSCALL (int, epoll_pwait, (int epfd, struct epoll_event *events, int maxevents, int timeout,
- const sigset_t *set),
- (epfd, events, maxevents, timeout, set))
- # endif
- #endif
|