1/* Uncancelable versions of cancelable interfaces. Linux/NPTL version.
2 Copyright (C) 2003-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
19
20#ifndef NOT_CANCEL_H
21# define NOT_CANCEL_H
22
23#include <sysdep.h>
24#include <errno.h>
25#include <unistd.h>
26#include <sys/syscall.h>
27
28/* Uncancelable open. */
29#ifdef __NR_open
30# define open_not_cancel(name, flags, mode) \
31 INLINE_SYSCALL (open, 3, name, flags, mode)
32# define open_not_cancel_2(name, flags) \
33 INLINE_SYSCALL (open, 2, name, flags)
34#else
35# define open_not_cancel(name, flags, mode) \
36 INLINE_SYSCALL (openat, 4, AT_FDCWD, name, flags, mode)
37# define open_not_cancel_2(name, flags) \
38 INLINE_SYSCALL (openat, 3, AT_FDCWD, name, flags)
39#endif
40
41/* Uncancelable read. */
42#define __read_nocancel(fd, buf, len) \
43 INLINE_SYSCALL (read, 3, fd, buf, len)
44
45/* Uncancelable write. */
46#define __write_nocancel(fd, buf, len) \
47 INLINE_SYSCALL (write, 3, fd, buf, len)
48
49/* Uncancelable openat. */
50#define openat_not_cancel(fd, fname, oflag, mode) \
51 INLINE_SYSCALL (openat, 4, fd, fname, oflag, mode)
52#define openat_not_cancel_3(fd, fname, oflag) \
53 INLINE_SYSCALL (openat, 3, fd, fname, oflag)
54#define openat64_not_cancel(fd, fname, oflag, mode) \
55 INLINE_SYSCALL (openat, 4, fd, fname, oflag | O_LARGEFILE, mode)
56#define openat64_not_cancel_3(fd, fname, oflag) \
57 INLINE_SYSCALL (openat, 3, fd, fname, oflag | O_LARGEFILE)
58
59/* Uncancelable close. */
60#define __close_nocancel(fd) \
61 INLINE_SYSCALL (close, 1, fd)
62#define close_not_cancel(fd) \
63 __close_nocancel (fd)
64#define close_not_cancel_no_status(fd) \
65 (void) ({ INTERNAL_SYSCALL_DECL (err); \
66 INTERNAL_SYSCALL (close, err, 1, (fd)); })
67
68/* Uncancelable read. */
69#define read_not_cancel(fd, buf, n) \
70 __read_nocancel (fd, buf, n)
71
72/* Uncancelable write. */
73#define write_not_cancel(fd, buf, n) \
74 __write_nocancel (fd, buf, n)
75
76/* Uncancelable writev. */
77#define writev_not_cancel_no_status(fd, iov, n) \
78 (void) ({ INTERNAL_SYSCALL_DECL (err); \
79 INTERNAL_SYSCALL (writev, err, 3, (fd), (iov), (n)); })
80
81/* Uncancelable fcntl. */
82#define fcntl_not_cancel(fd, cmd, val) \
83 __fcntl_nocancel (fd, cmd, val)
84
85/* Uncancelable waitpid. */
86#define __waitpid_nocancel(pid, stat_loc, options) \
87 INLINE_SYSCALL (wait4, 4, pid, stat_loc, options, NULL)
88#define waitpid_not_cancel(pid, stat_loc, options) \
89 __waitpid_nocancel(pid, stat_loc, options)
90
91/* Uncancelable pause. */
92#define pause_not_cancel() \
93 ({ sigset_t set; \
94 int __rc = INLINE_SYSCALL (rt_sigprocmask, 4, SIG_BLOCK, NULL, &set, \
95 _NSIG / 8); \
96 if (__rc == 0) \
97 __rc = INLINE_SYSCALL (rt_sigsuspend, 2, &set, _NSIG / 8); \
98 __rc; \
99 })
100
101/* Uncancelable nanosleep. */
102#define nanosleep_not_cancel(requested_time, remaining) \
103 INLINE_SYSCALL (nanosleep, 2, requested_time, remaining)
104
105/* Uncancelable sigsuspend. */
106#define sigsuspend_not_cancel(set) \
107 INLINE_SYSCALL (rt_sigsuspend, 2, set, _NSIG / 8)
108
109#endif /* NOT_CANCEL_H */
110