not-cancel.h 3.6 KB

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