not-cancel.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* Uncancelable versions of cancelable interfaces. Linux version.
  2. Copyright (C) 2003, 2006 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the 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. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <sys/types.h>
  17. #include <sysdep.h>
  18. #include <time.h>
  19. #ifdef NOT_IN_libc
  20. /* Uncancelable open. */
  21. #if defined __NR_openat && !defined __NR_open
  22. #define open_not_cancel(name, flags, mode) \
  23. INLINE_SYSCALL (openat, 4, AT_FDCWD, (const char *) (name), (flags), (mode))
  24. #define open_not_cancel_2(name, flags) \
  25. INLINE_SYSCALL (openat, 3, AT_FDCWD, (const char *) (name), (flags))
  26. #else
  27. #define open_not_cancel(name, flags, mode) \
  28. INLINE_SYSCALL (open, 3, (const char *) (name), (flags), (mode))
  29. #define open_not_cancel_2(name, flags) \
  30. INLINE_SYSCALL (open, 2, (const char *) (name), (flags))
  31. #endif
  32. #if 0
  33. /* Uncancelable openat. */
  34. #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
  35. extern int __openat_nocancel (int fd, const char *fname, int oflag,
  36. mode_t mode) attribute_hidden;
  37. extern int __openat64_nocancel (int fd, const char *fname, int oflag,
  38. mode_t mode) attribute_hidden;
  39. #else
  40. # define __openat_nocancel(fd, fname, oflag, mode) \
  41. openat (fd, fname, oflag, mode)
  42. # define __openat64_nocancel(fd, fname, oflag, mode) \
  43. openat64 (fd, fname, oflag, mode)
  44. #endif
  45. #define openat_not_cancel(fd, fname, oflag, mode) \
  46. __openat_nocancel (fd, fname, oflag, mode)
  47. #define openat_not_cancel_3(fd, fname, oflag) \
  48. __openat_nocancel (fd, fname, oflag, 0)
  49. #define openat64_not_cancel(fd, fname, oflag, mode) \
  50. __openat64_nocancel (fd, fname, oflag, mode)
  51. #define openat64_not_cancel_3(fd, fname, oflag) \
  52. __openat64_nocancel (fd, fname, oflag, 0)
  53. #endif
  54. /* Uncancelable close. */
  55. #define close_not_cancel(fd) \
  56. INLINE_SYSCALL (close, 1, fd)
  57. #define close_not_cancel_no_status(fd) \
  58. (void) ({ INTERNAL_SYSCALL_DECL (err); \
  59. INTERNAL_SYSCALL (close, err, 1, (fd)); })
  60. /* Uncancelable read. */
  61. #define read_not_cancel(fd, buf, n) \
  62. INLINE_SYSCALL (read, 3, (fd), (buf), (n))
  63. #ifdef __UCLIBC_HAS_THREADS__
  64. /* Uncancelable write. */
  65. #define write_not_cancel(fd, buf, n) \
  66. INLINE_SYSCALL (write, 3, (fd), (buf), (n))
  67. #endif
  68. #if 0
  69. /* Uncancelable writev. */
  70. #define writev_not_cancel_no_status(fd, iov, n) \
  71. (void) ({ INTERNAL_SYSCALL_DECL (err); \
  72. INTERNAL_SYSCALL (writev, err, 3, (fd), (iov), (n)); })
  73. /* Uncancelable fcntl. */
  74. #define fcntl_not_cancel(fd, cmd, val) \
  75. __fcntl_nocancel (fd, cmd, val)
  76. #endif
  77. #ifdef __UCLIBC_HAS_LINUXTHREADS__
  78. /* Uncancelable waitpid. */
  79. #if 0 /*def __NR_waitpid*/
  80. # define waitpid_not_cancel(pid, stat_loc, options) \
  81. INLINE_SYSCALL (waitpid, 3, pid, stat_loc, options)
  82. #else
  83. # define waitpid_not_cancel(pid, stat_loc, options) \
  84. INLINE_SYSCALL (wait4, 4, pid, stat_loc, options, NULL)
  85. #endif
  86. #endif
  87. /* Uncancelable pause. */
  88. #ifdef __NR_pause
  89. # define pause_not_cancel() \
  90. INLINE_SYSCALL (pause, 0)
  91. #else
  92. # include <unistd.h>
  93. extern __typeof(pause) __pause_nocancel;
  94. # define pause_not_cancel() \
  95. __pause_nocancel ()
  96. #endif
  97. /* Uncancelable nanosleep. */
  98. #ifdef __NR_nanosleep
  99. # define nanosleep_not_cancel(requested_time, remaining) \
  100. INLINE_SYSCALL (nanosleep, 2, requested_time, remaining)
  101. #else
  102. extern int __nanosleep_nocancel (const struct timespec *requested_time, struct timespec *remaining);
  103. # define nanosleep_not_cancel(requested_time, remaining) \
  104. __nanosleep_nocancel (requested_time, remaining)
  105. #endif
  106. #if 0
  107. /* Uncancelable sigsuspend. */
  108. #define sigsuspend_not_cancel(set) \
  109. __sigsuspend_nocancel (set)
  110. #endif
  111. #elif !defined NOT_IN_libc
  112. #include <cancel.h>
  113. #include <fcntl.h>
  114. #include <unistd.h>
  115. #define open_not_cancel(name, flags, mode) \
  116. __NC(open)(name, flags, mode)
  117. #define open_not_cancel_2(name, flags) \
  118. __NC(open2)(name, flags)
  119. #define close_not_cancel(fd) \
  120. __NC(close)(fd)
  121. #define close_not_cancel_no_status(fd) \
  122. __close_nocancel_no_status(fd)
  123. #define read_not_cancel(fd, buf, n) \
  124. __NC(read)(fd, buf, n)
  125. #define write_not_cancel(fd, buf, n) \
  126. __NC(write)(fd, buf, n)
  127. #define fcntl_not_cancel(fd, cmd, val) \
  128. __NC(fcntl)(fd, cmd, val)
  129. #endif