1 | /* Copyright (C) 2006-2021 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. |
3 | Contributed by Ulrich Drepper <drepper@redhat.com>, 2006. |
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 | #include <errno.h> |
20 | #include <signal.h> |
21 | #include <time.h> |
22 | #include <sys/poll.h> |
23 | #include <sysdep-cancel.h> |
24 | #include <kernel-features.h> |
25 | #include <time64-support.h> |
26 | |
27 | |
28 | int |
29 | __ppoll64 (struct pollfd *fds, nfds_t nfds, const struct __timespec64 *timeout, |
30 | const sigset_t *sigmask) |
31 | { |
32 | /* The Linux kernel can in some situations update the timeout value. |
33 | We do not want that so use a local variable. */ |
34 | struct __timespec64 tval; |
35 | if (timeout != NULL) |
36 | { |
37 | tval = *timeout; |
38 | timeout = &tval; |
39 | } |
40 | |
41 | int ret; |
42 | |
43 | if (supports_time64 ()) |
44 | { |
45 | #ifndef __NR_ppoll_time64 |
46 | # define __NR_ppoll_time64 __NR_ppoll |
47 | #endif |
48 | ret = SYSCALL_CANCEL (ppoll_time64, fds, nfds, timeout, sigmask, |
49 | __NSIG_BYTES); |
50 | |
51 | if (ret == 0 || errno != ENOSYS) |
52 | return ret; |
53 | |
54 | mark_time64_unsupported (); |
55 | } |
56 | |
57 | #ifndef __ASSUME_TIME64_SYSCALLS |
58 | struct timespec ts32; |
59 | if (timeout) |
60 | { |
61 | if (! in_time_t_range (timeout->tv_sec)) |
62 | { |
63 | __set_errno (EOVERFLOW); |
64 | return -1; |
65 | } |
66 | |
67 | ts32 = valid_timespec64_to_timespec (*timeout); |
68 | } |
69 | |
70 | ret = SYSCALL_CANCEL (ppoll, fds, nfds, timeout ? &ts32 : NULL, sigmask, |
71 | __NSIG_BYTES); |
72 | #endif |
73 | |
74 | return ret; |
75 | } |
76 | |
77 | #if __TIMESIZE != 64 |
78 | libc_hidden_def (__ppoll64) |
79 | |
80 | int |
81 | __ppoll (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, |
82 | const sigset_t *sigmask) |
83 | { |
84 | struct __timespec64 ts64; |
85 | if (timeout) |
86 | ts64 = valid_timespec_to_timespec64 (*timeout); |
87 | |
88 | return __ppoll64 (fds, nfds, timeout ? &ts64 : NULL, sigmask); |
89 | } |
90 | #endif |
91 | strong_alias (__ppoll, ppoll) |
92 | libc_hidden_def (ppoll) |
93 | |