wrapsyscall.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* Wrapper arpund system calls to provide cancelation points.
  2. Copyright (C) 1996, 1997, 1998 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. name param_list \
  39. { \
  40. res_type result; \
  41. int oldtype; \
  42. pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); \
  43. result = __libc_##name params; \
  44. pthread_setcanceltype (oldtype, NULL); \
  45. return result; \
  46. }
  47. #define CANCELABLE_SYSCALL_VA(res_type, name, param_list, params, last_arg) \
  48. res_type __libc_##name param_list; \
  49. res_type \
  50. name param_list \
  51. { \
  52. res_type result; \
  53. int oldtype; \
  54. va_list ap; \
  55. pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype); \
  56. va_start (ap, last_arg); \
  57. result = __libc_##name params; \
  58. va_end (ap); \
  59. pthread_setcanceltype (oldtype, NULL); \
  60. return result; \
  61. }
  62. /* close(2). */
  63. CANCELABLE_SYSCALL (int, close, (int fd), (fd))
  64. /* fcntl(2). */
  65. CANCELABLE_SYSCALL_VA (int, fcntl, (int fd, int cmd, ...),
  66. (fd, cmd, va_arg (ap, long int)), cmd)
  67. /* fsync(2). */
  68. CANCELABLE_SYSCALL (int, fsync, (int fd), (fd))
  69. /* lseek(2). */
  70. CANCELABLE_SYSCALL (off_t, lseek, (int fd, off_t offset, int whence),
  71. (fd, offset, whence))
  72. /* msync(2). */
  73. /* This syscall not implemented in uClibc
  74. CANCELABLE_SYSCALL (int, msync, (__ptr_t addr, size_t length, int flags),
  75. (addr, length, flags))
  76. */
  77. /* nanosleep(2). */
  78. CANCELABLE_SYSCALL (int, nanosleep, (const struct timespec *requested_time,
  79. struct timespec *remaining),
  80. (requested_time, remaining))
  81. /* open(2). */
  82. CANCELABLE_SYSCALL_VA (int, open, (const char *pathname, int flags, ...),
  83. (pathname, flags, va_arg (ap, mode_t)), flags)
  84. /* pause(2). */
  85. CANCELABLE_SYSCALL (int, pause, (void), ())
  86. /* read(2). */
  87. CANCELABLE_SYSCALL (ssize_t, read, (int fd, void *buf, size_t count),
  88. (fd, buf, count))
  89. /* system(3). */
  90. CANCELABLE_SYSCALL (int, system, (const char *line), (line))
  91. /* tcdrain(2). */
  92. CANCELABLE_SYSCALL (int, tcdrain, (int fd), (fd))
  93. /* wait(2). */
  94. CANCELABLE_SYSCALL (__pid_t, wait, (__WAIT_STATUS_DEFN stat_loc), (stat_loc))
  95. /* waitpid(2). */
  96. CANCELABLE_SYSCALL (__pid_t, waitpid, (__pid_t pid, int *stat_loc,
  97. int options),
  98. (pid, stat_loc, options))
  99. /* write(2). */
  100. CANCELABLE_SYSCALL (ssize_t, write, (int fd, const void *buf, size_t n),
  101. (fd, buf, n))
  102. /* The following system calls are thread cancellation points specified
  103. in XNS. */
  104. /* accept(2). */
  105. CANCELABLE_SYSCALL (int, accept, (int fd, __SOCKADDR_ARG addr,
  106. socklen_t *addr_len),
  107. (fd, addr, addr_len))
  108. /* connect(2). */
  109. CANCELABLE_SYSCALL (int, connect, (int fd, __CONST_SOCKADDR_ARG addr,
  110. socklen_t len),
  111. (fd, addr, len))
  112. /* recv(2). */
  113. CANCELABLE_SYSCALL (int, recv, (int fd, __ptr_t buf, size_t n, int flags),
  114. (fd, buf, n, flags))
  115. /* recvfrom(2). */
  116. CANCELABLE_SYSCALL (int, recvfrom, (int fd, __ptr_t buf, size_t n, int flags,
  117. __SOCKADDR_ARG addr, socklen_t *addr_len),
  118. (fd, buf, n, flags, addr, addr_len))
  119. /* recvmsg(2). */
  120. CANCELABLE_SYSCALL (int, recvmsg, (int fd, struct msghdr *message, int flags),
  121. (fd, message, flags))
  122. /* send(2). */
  123. CANCELABLE_SYSCALL (int, send, (int fd, const __ptr_t buf, size_t n,
  124. int flags),
  125. (fd, buf, n, flags))
  126. /* sendmsg(2). */
  127. CANCELABLE_SYSCALL (int, sendmsg, (int fd, const struct msghdr *message,
  128. int flags),
  129. (fd, message, flags))
  130. /* sendto(2). */
  131. CANCELABLE_SYSCALL (int, sendto, (int fd, const __ptr_t buf, size_t n,
  132. int flags, __CONST_SOCKADDR_ARG addr,
  133. socklen_t addr_len),
  134. (fd, buf, n, flags, addr, addr_len))