1/* Uncancelable versions of cancelable interfaces. Linux/NPTL version.
2 Copyright (C) 2003-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef NOT_CANCEL_H
20# define NOT_CANCEL_H
21
22#include <fcntl.h>
23#include <sysdep.h>
24#include <errno.h>
25#include <unistd.h>
26#include <sys/poll.h>
27#include <sys/syscall.h>
28#include <sys/wait.h>
29#include <time.h>
30
31/* Non cancellable open syscall. */
32__typeof (open) __open_nocancel;
33
34/* Non cancellable open syscall (LFS version). */
35__typeof (open64) __open64_nocancel;
36
37/* Non cancellable openat syscall. */
38__typeof (openat) __openat_nocancel;
39
40/* Non cacellable openat syscall (LFS version). */
41__typeof (openat64) __openat64_nocancel;
42
43/* Non cancellable read syscall. */
44__typeof (__read) __read_nocancel;
45
46/* Non cancellable pread syscall (LFS version). */
47__typeof (__pread64) __pread64_nocancel;
48
49/* Uncancelable write. */
50__typeof (__write) __write_nocancel;
51
52/* Uncancelable close. */
53__typeof (__close) __close_nocancel;
54
55/* Uncancelable fcntl. */
56__typeof (__fcntl) __fcntl64_nocancel;
57
58#if IS_IN (libc) || IS_IN (rtld)
59hidden_proto (__open_nocancel)
60hidden_proto (__open64_nocancel)
61hidden_proto (__openat_nocancel)
62hidden_proto (__openat64_nocancel)
63hidden_proto (__read_nocancel)
64hidden_proto (__pread64_nocancel)
65hidden_proto (__write_nocancel)
66hidden_proto (__close_nocancel)
67hidden_proto (__fcntl64_nocancel)
68#endif
69
70/* Non cancellable close syscall that does not also set errno in case of
71 failure. */
72static inline void
73__close_nocancel_nostatus (int fd)
74{
75 __close_nocancel (fd);
76}
77
78/* Non cancellable writev syscall that does not also set errno in case of
79 failure. */
80static inline void
81__writev_nocancel_nostatus (int fd, const struct iovec *iov, int iovcnt)
82{
83 INTERNAL_SYSCALL_CALL (writev, fd, iov, iovcnt);
84}
85
86static inline ssize_t
87__getrandom_nocancel (void *buf, size_t buflen, unsigned int flags)
88{
89 return INLINE_SYSCALL_CALL (getrandom, buf, buflen, flags);
90}
91
92/* Non cancellable getrandom syscall that does not also set errno in case of
93 failure. */
94static inline ssize_t
95__getrandom_nocancel_nostatus (void *buf, size_t buflen, unsigned int flags)
96{
97 return INTERNAL_SYSCALL_CALL (getrandom, buf, buflen, flags);
98}
99
100static inline int
101__poll_infinity_nocancel (struct pollfd *fds, nfds_t nfds)
102{
103 return INLINE_SYSCALL_CALL (ppoll, fds, nfds, NULL, NULL, 0);
104}
105
106#endif /* NOT_CANCEL_H */
107

source code of glibc/sysdeps/unix/sysv/linux/not-cancel.h