not-cancel.h 4.2 KB

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