wrapsyscall.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. #ifndef PIC
  31. /* We need a hook to force this file to be linked in when static
  32. libpthread is used. */
  33. const int __pthread_provide_wrappers = 0;
  34. #endif
  35. #define CANCELABLE_SYSCALL(res_type, name, param_list, params) \
  36. res_type __libc_##name param_list; \
  37. res_type \
  38. __attribute__ ((weak)) \
  39. name param_list \
  40. { \
  41. res_type result; \
  42. int oldtype; \
  43. pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); \
  44. result = __libc_##name params; \
  45. pthread_setcanceltype (oldtype, NULL); \
  46. return result; \
  47. }
  48. #define CANCELABLE_SYSCALL_VA(res_type, name, param_list, params, last_arg) \
  49. res_type __libc_##name param_list; \
  50. res_type \
  51. __attribute__ ((weak)) \
  52. name param_list \
  53. { \
  54. res_type result; \
  55. int oldtype; \
  56. va_list ap; \
  57. pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); \
  58. va_start (ap, last_arg); \
  59. result = __libc_##name params; \
  60. va_end (ap); \
  61. pthread_setcanceltype (oldtype, NULL); \
  62. return result; \
  63. }
  64. /* close(2). */
  65. CANCELABLE_SYSCALL (int, close, (int fd), (fd))
  66. strong_alias (close, __close)
  67. /* fcntl(2). */
  68. CANCELABLE_SYSCALL_VA (int, fcntl, (int fd, int cmd, ...),
  69. (fd, cmd, va_arg (ap, long int)), cmd)
  70. strong_alias (fcntl, __fcntl)
  71. /* fsync(2). */
  72. CANCELABLE_SYSCALL (int, fsync, (int fd), (fd))
  73. /* lseek(2). */
  74. CANCELABLE_SYSCALL (off_t, lseek, (int fd, off_t offset, int whence),
  75. (fd, offset, whence))
  76. strong_alias (lseek, __lseek)
  77. #ifdef __UCLIBC_HAVE_LFS__
  78. /* lseek64(2). */
  79. CANCELABLE_SYSCALL (off64_t, lseek64, (int fd, off64_t offset, int whence),
  80. (fd, offset, whence))
  81. #endif
  82. /* msync(2). */
  83. CANCELABLE_SYSCALL (int, msync, (__ptr_t addr, size_t length, int flags),
  84. (addr, length, flags))
  85. /* nanosleep(2). */
  86. CANCELABLE_SYSCALL (int, nanosleep, (const struct timespec *requested_time,
  87. struct timespec *remaining),
  88. (requested_time, remaining))
  89. /* open(2). */
  90. CANCELABLE_SYSCALL_VA (int, open, (const char *pathname, int flags, ...),
  91. (pathname, flags, va_arg (ap, mode_t)), flags)
  92. strong_alias (open, __open)
  93. #ifdef __UCLIBC_HAVE_LFS__
  94. /* open64(3). */
  95. CANCELABLE_SYSCALL_VA (int, open64, (const char *pathname, int flags, ...),
  96. (pathname, flags, va_arg (ap, mode_t)), flags)
  97. strong_alias (open64, __open64)
  98. #endif
  99. /* pause(2). */
  100. CANCELABLE_SYSCALL (int, pause, (void), ())
  101. #if 0
  102. /* Enable this if enabling these in syscalls.c */
  103. /* pread(3). */
  104. CANCELABLE_SYSCALL (ssize_t, pread, (int fd, void *buf, size_t count,
  105. off_t offset),
  106. (fd, buf, count, offset))
  107. #ifdef __UCLIBC_HAVE_LFS__
  108. /* pread64(3). */
  109. CANCELABLE_SYSCALL (ssize_t, pread64, (int fd, void *buf, size_t count,
  110. off64_t offset),
  111. (fd, buf, count, offset))
  112. strong_alias (pread64, __pread64)
  113. #endif
  114. /* pwrite(3). */
  115. CANCELABLE_SYSCALL (ssize_t, pwrite, (int fd, const void *buf, size_t n,
  116. off_t offset),
  117. (fd, buf, n, offset))
  118. #ifdef __UCLIBC_HAVE_LFS__
  119. /* pwrite64(3). */
  120. CANCELABLE_SYSCALL (ssize_t, pwrite64, (int fd, const void *buf, size_t n,
  121. off64_t offset),
  122. (fd, buf, n, offset))
  123. strong_alias (pwrite64, __pwrite64)
  124. #endif
  125. #endif
  126. /* read(2). */
  127. CANCELABLE_SYSCALL (ssize_t, read, (int fd, void *buf, size_t count),
  128. (fd, buf, count))
  129. strong_alias (read, __read)
  130. /* system(3). */
  131. CANCELABLE_SYSCALL (int, system, (const char *line), (line))
  132. /* tcdrain(2). */
  133. CANCELABLE_SYSCALL (int, tcdrain, (int fd), (fd))
  134. /* wait(2). */
  135. CANCELABLE_SYSCALL (__pid_t, wait, (__WAIT_STATUS_DEFN stat_loc), (stat_loc))
  136. strong_alias (wait, __wait)
  137. /* waitpid(2). */
  138. CANCELABLE_SYSCALL (__pid_t, waitpid, (__pid_t pid, int *stat_loc,
  139. int options),
  140. (pid, stat_loc, options))
  141. /* write(2). */
  142. CANCELABLE_SYSCALL (ssize_t, write, (int fd, const void *buf, size_t n),
  143. (fd, buf, n))
  144. strong_alias (write, __write)
  145. /* The following system calls are thread cancellation points specified
  146. in XNS. */
  147. /* accept(2). */
  148. CANCELABLE_SYSCALL (int, accept, (int fd, __SOCKADDR_ARG addr,
  149. socklen_t *addr_len),
  150. (fd, addr, addr_len))
  151. /* connect(2). */
  152. CANCELABLE_SYSCALL (int, connect, (int fd, __CONST_SOCKADDR_ARG addr,
  153. socklen_t len),
  154. (fd, addr, len))
  155. strong_alias (connect, __connect)
  156. /* recv(2). */
  157. CANCELABLE_SYSCALL (ssize_t, recv, (int fd, __ptr_t buf, size_t n, int flags),
  158. (fd, buf, n, flags))
  159. /* recvfrom(2). */
  160. CANCELABLE_SYSCALL (ssize_t, recvfrom, (int fd, __ptr_t buf, size_t n, int flags,
  161. __SOCKADDR_ARG addr, socklen_t *addr_len),
  162. (fd, buf, n, flags, addr, addr_len))
  163. /* recvmsg(2). */
  164. CANCELABLE_SYSCALL (ssize_t, recvmsg, (int fd, struct msghdr *message, int flags),
  165. (fd, message, flags))
  166. /* send(2). */
  167. CANCELABLE_SYSCALL (ssize_t, send, (int fd, const __ptr_t buf, size_t n,
  168. int flags),
  169. (fd, buf, n, flags))
  170. strong_alias (send, __send)
  171. /* sendmsg(2). */
  172. CANCELABLE_SYSCALL (ssize_t, sendmsg, (int fd, const struct msghdr *message,
  173. int flags),
  174. (fd, message, flags))
  175. /* sendto(2). */
  176. CANCELABLE_SYSCALL (ssize_t, sendto, (int fd, const __ptr_t buf, size_t n,
  177. int flags, __CONST_SOCKADDR_ARG addr,
  178. socklen_t addr_len),
  179. (fd, buf, n, flags, addr, addr_len))