wrapsyscall.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* Wrapper arpund system calls to provide cancelation 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.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with the GNU C Library; see the file COPYING.LIB. If not,
  15. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. Boston, MA 02111-1307, USA. */
  17. #define __FORCE_GLIBC
  18. #include <features.h>
  19. #include <fcntl.h>
  20. #include <sys/mman.h>
  21. #include <pthread.h>
  22. #include <unistd.h>
  23. #include <stdarg.h>
  24. #include <stddef.h>
  25. #include <stdlib.h>
  26. #include <termios.h>
  27. #include <sys/resource.h>
  28. #include <sys/wait.h>
  29. #include <sys/socket.h>
  30. #include <sys/syscall.h>
  31. #ifndef __PIC__
  32. /* We need a hook to force this file to be linked in when static
  33. libpthread is used. */
  34. const int __pthread_provide_wrappers = 0;
  35. #endif
  36. #define CANCELABLE_SYSCALL(res_type, name, param_list, params) \
  37. res_type __libc_##name param_list; \
  38. res_type \
  39. __attribute__ ((weak)) \
  40. name param_list \
  41. { \
  42. res_type result; \
  43. int oldtype; \
  44. pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); \
  45. result = __libc_##name params; \
  46. pthread_setcanceltype (oldtype, NULL); \
  47. return result; \
  48. }
  49. #define CANCELABLE_SYSCALL_VA(res_type, name, param_list, params, last_arg) \
  50. res_type __libc_##name param_list; \
  51. res_type \
  52. __attribute__ ((weak)) \
  53. name param_list \
  54. { \
  55. res_type result; \
  56. int oldtype; \
  57. va_list ap; \
  58. pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); \
  59. va_start (ap, last_arg); \
  60. result = __libc_##name params; \
  61. va_end (ap); \
  62. pthread_setcanceltype (oldtype, NULL); \
  63. return result; \
  64. }
  65. /* close(2). */
  66. CANCELABLE_SYSCALL (int, close, (int fd), (fd))
  67. /* fcntl(2). */
  68. CANCELABLE_SYSCALL_VA (int, fcntl, (int fd, int cmd, ...),
  69. (fd, cmd, va_arg (ap, long int)), cmd)
  70. /* fsync(2). */
  71. CANCELABLE_SYSCALL (int, fsync, (int fd), (fd))
  72. /* lseek(2). */
  73. CANCELABLE_SYSCALL (off_t, lseek, (int fd, off_t offset, int whence),
  74. (fd, offset, whence))
  75. #ifdef __UCLIBC_HAS_LFS__
  76. /* lseek64(2). */
  77. CANCELABLE_SYSCALL (off64_t, lseek64, (int fd, off64_t offset, int whence),
  78. (fd, offset, whence))
  79. #endif
  80. /* msync(2). */
  81. CANCELABLE_SYSCALL (int, msync, (__ptr_t addr, size_t length, int flags),
  82. (addr, length, flags))
  83. /* nanosleep(2). */
  84. CANCELABLE_SYSCALL (int, nanosleep, (const struct timespec *requested_time,
  85. struct timespec *remaining),
  86. (requested_time, remaining))
  87. /* open(2). */
  88. CANCELABLE_SYSCALL_VA (int, open, (const char *pathname, int flags, ...),
  89. (pathname, flags, va_arg (ap, mode_t)), flags)
  90. #ifdef __UCLIBC_HAS_LFS__
  91. /* open64(3). */
  92. CANCELABLE_SYSCALL_VA (int, open64, (const char *pathname, int flags, ...),
  93. (pathname, flags, va_arg (ap, mode_t)), flags)
  94. #endif
  95. /* pause(2). */
  96. CANCELABLE_SYSCALL (int, pause, (void), ())
  97. /* Enable this if enabling these in syscalls.c */
  98. /* pread(3). */
  99. CANCELABLE_SYSCALL (ssize_t, pread, (int fd, void *buf, size_t count,
  100. off_t offset),
  101. (fd, buf, count, offset))
  102. #if defined __UCLIBC_HAS_LFS__ && defined __NR_pread64
  103. /* pread64(3). */
  104. CANCELABLE_SYSCALL (ssize_t, pread64, (int fd, void *buf, size_t count,
  105. off64_t offset),
  106. (fd, buf, count, offset))
  107. #endif
  108. /* pwrite(3). */
  109. CANCELABLE_SYSCALL (ssize_t, pwrite, (int fd, const void *buf, size_t n,
  110. off_t offset),
  111. (fd, buf, n, offset))
  112. #if defined __UCLIBC_HAS_LFS__ && defined __NR_pwrited64
  113. /* pwrite64(3). */
  114. CANCELABLE_SYSCALL (ssize_t, pwrite64, (int fd, const void *buf, size_t n,
  115. off64_t offset),
  116. (fd, buf, n, offset))
  117. #endif
  118. /* read(2). */
  119. CANCELABLE_SYSCALL (ssize_t, read, (int fd, void *buf, size_t count),
  120. (fd, buf, count))
  121. /* system(3). */
  122. CANCELABLE_SYSCALL (int, system, (const char *line), (line))
  123. /* tcdrain(2). */
  124. CANCELABLE_SYSCALL (int, tcdrain, (int fd), (fd))
  125. /* wait(2). */
  126. CANCELABLE_SYSCALL (__pid_t, wait, (__WAIT_STATUS_DEFN stat_loc), (stat_loc))
  127. /* waitpid(2). */
  128. CANCELABLE_SYSCALL (__pid_t, waitpid, (__pid_t pid, int *stat_loc,
  129. int options),
  130. (pid, stat_loc, options))
  131. /* write(2). */
  132. CANCELABLE_SYSCALL (ssize_t, write, (int fd, const void *buf, size_t n),
  133. (fd, buf, n))
  134. /* The following system calls are thread cancellation points specified
  135. in XNS. */
  136. /* accept(2). */
  137. CANCELABLE_SYSCALL (int, accept, (int fd, __SOCKADDR_ARG addr,
  138. socklen_t *addr_len),
  139. (fd, addr, addr_len))
  140. /* connect(2). */
  141. CANCELABLE_SYSCALL (int, connect, (int fd, __CONST_SOCKADDR_ARG addr,
  142. socklen_t len),
  143. (fd, addr, len))
  144. /* recv(2). */
  145. CANCELABLE_SYSCALL (ssize_t, recv, (int fd, __ptr_t buf, size_t n, int flags),
  146. (fd, buf, n, flags))
  147. /* recvfrom(2). */
  148. CANCELABLE_SYSCALL (ssize_t, recvfrom, (int fd, __ptr_t buf, size_t n, int flags,
  149. __SOCKADDR_ARG addr, socklen_t *addr_len),
  150. (fd, buf, n, flags, addr, addr_len))
  151. /* recvmsg(2). */
  152. CANCELABLE_SYSCALL (ssize_t, recvmsg, (int fd, struct msghdr *message, int flags),
  153. (fd, message, flags))
  154. /* send(2). */
  155. CANCELABLE_SYSCALL (ssize_t, send, (int fd, const __ptr_t buf, size_t n,
  156. int flags),
  157. (fd, buf, n, flags))
  158. /* sendmsg(2). */
  159. CANCELABLE_SYSCALL (ssize_t, sendmsg, (int fd, const struct msghdr *message,
  160. int flags),
  161. (fd, message, flags))
  162. /* sendto(2). */
  163. CANCELABLE_SYSCALL (ssize_t, sendto, (int fd, const __ptr_t buf, size_t n,
  164. int flags, __CONST_SOCKADDR_ARG addr,
  165. socklen_t addr_len),
  166. (fd, buf, n, flags, addr, addr_len))