not-cancel.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. #ifdef NOT_IN_libc
  19. /* Uncancelable open. */
  20. #define open_not_cancel(name, flags, mode) \
  21. INLINE_SYSCALL (open, 3, (const char *) (name), (flags), (mode))
  22. #define open_not_cancel_2(name, flags) \
  23. INLINE_SYSCALL (open, 2, (const char *) (name), (flags))
  24. #if 0
  25. /* Uncancelable openat. */
  26. #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
  27. extern int __openat_nocancel (int fd, const char *fname, int oflag,
  28. mode_t mode) attribute_hidden;
  29. extern int __openat64_nocancel (int fd, const char *fname, int oflag,
  30. mode_t mode) attribute_hidden;
  31. #else
  32. # define __openat_nocancel(fd, fname, oflag, mode) \
  33. openat (fd, fname, oflag, mode)
  34. # define __openat64_nocancel(fd, fname, oflag, mode) \
  35. openat64 (fd, fname, oflag, mode)
  36. #endif
  37. #define openat_not_cancel(fd, fname, oflag, mode) \
  38. __openat_nocancel (fd, fname, oflag, mode)
  39. #define openat_not_cancel_3(fd, fname, oflag) \
  40. __openat_nocancel (fd, fname, oflag, 0)
  41. #define openat64_not_cancel(fd, fname, oflag, mode) \
  42. __openat64_nocancel (fd, fname, oflag, mode)
  43. #define openat64_not_cancel_3(fd, fname, oflag) \
  44. __openat64_nocancel (fd, fname, oflag, 0)
  45. #endif
  46. /* Uncancelable close. */
  47. #define close_not_cancel(fd) \
  48. INLINE_SYSCALL (close, 1, fd)
  49. #define close_not_cancel_no_status(fd) \
  50. (void) ({ INTERNAL_SYSCALL_DECL (err); \
  51. INTERNAL_SYSCALL (close, err, 1, (fd)); })
  52. /* Uncancelable read. */
  53. #define read_not_cancel(fd, buf, n) \
  54. INLINE_SYSCALL (read, 3, (fd), (buf), (n))
  55. #ifdef __LINUXTHREADS_NEW__
  56. /* Uncancelable write. */
  57. #define write_not_cancel(fd, buf, n) \
  58. INLINE_SYSCALL (write, 3, (fd), (buf), (n))
  59. #endif
  60. #if 0
  61. /* Uncancelable writev. */
  62. #define writev_not_cancel_no_status(fd, iov, n) \
  63. (void) ({ INTERNAL_SYSCALL_DECL (err); \
  64. INTERNAL_SYSCALL (writev, err, 3, (fd), (iov), (n)); })
  65. /* Uncancelable fcntl. */
  66. #define fcntl_not_cancel(fd, cmd, val) \
  67. __fcntl_nocancel (fd, cmd, val)
  68. #endif
  69. #ifdef __LINUXTHREADS_NEW__
  70. /* Uncancelable waitpid. */
  71. #if 0 /*def __NR_waitpid*/
  72. # define waitpid_not_cancel(pid, stat_loc, options) \
  73. INLINE_SYSCALL (waitpid, 3, pid, stat_loc, options)
  74. #else
  75. # define waitpid_not_cancel(pid, stat_loc, options) \
  76. INLINE_SYSCALL (wait4, 4, pid, stat_loc, options, NULL)
  77. #endif
  78. #endif
  79. /* Uncancelable pause. */
  80. #ifdef __NR_pause
  81. # define pause_not_cancel() \
  82. INLINE_SYSCALL (pause, 0)
  83. /*#else
  84. # define pause_not_cancel() \
  85. __pause_nocancel ()*/
  86. #endif
  87. /* Uncancelable nanosleep. */
  88. #ifdef __NR_nanosleep
  89. # define nanosleep_not_cancel(requested_time, remaining) \
  90. INLINE_SYSCALL (nanosleep, 2, requested_time, remaining)
  91. /*#else
  92. # define nanosleep_not_cancel(requested_time, remaining) \
  93. __nanosleep_nocancel (requested_time, remaining)*/
  94. #endif
  95. #if 0
  96. /* Uncancelable sigsuspend. */
  97. #define sigsuspend_not_cancel(set) \
  98. __sigsuspend_nocancel (set)
  99. #endif
  100. #elif !defined NOT_IN_libc
  101. #include <cancel.h>
  102. #include <fcntl.h>
  103. #include <unistd.h>
  104. #define open_not_cancel(name, flags, mode) \
  105. __NC(open)(name, flags, mode)
  106. #define open_not_cancel_2(name, flags) \
  107. __NC(open2)(name, flags)
  108. #define close_not_cancel(fd) \
  109. __NC(close)(fd)
  110. #define close_not_cancel_no_status(fd) \
  111. __close_nocancel_no_status(fd)
  112. #define read_not_cancel(fd, buf, n) \
  113. __NC(read)(fd, buf, n)
  114. #define write_not_cancel(fd, buf, n) \
  115. __NC(write)(fd, buf, n)
  116. #define fcntl_not_cancel(fd, cmd, val) \
  117. __NC(fcntl)(fd, cmd, val)
  118. #endif