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
25int
26__ppoll64 (struct pollfd *fds, nfds_t nfds, const struct __timespec64 *timeout,
27 const sigset_t *sigmask)
28{
29 /* The Linux kernel can in some situations update the timeout value.
30 We do not want that so use a local variable. */
31 struct __timespec64 tval;
32 if (timeout != NULL)
33 {
34 tval = *timeout;
35 timeout = &tval;
36 }
37
38#ifndef __NR_ppoll_time64
39# define __NR_ppoll_time64 __NR_ppoll
40#endif
41
42#ifdef __ASSUME_TIME64_SYSCALLS
43 return SYSCALL_CANCEL (ppoll_time64, fds, nfds, timeout, sigmask,
44 __NSIG_BYTES);
45#else
46 int ret;
47 bool need_time64 = timeout != NULL && !in_time_t_range (timeout->tv_sec);
48 if (need_time64)
49 {
50 ret = SYSCALL_CANCEL (ppoll_time64, fds, nfds, timeout, sigmask,
51 __NSIG_BYTES);
52 if (ret == 0 || errno != ENOSYS)
53 return ret;
54 __set_errno (EOVERFLOW);
55 return -1;
56 }
57
58 struct timespec ts32;
59 if (timeout != NULL)
60 ts32 = valid_timespec64_to_timespec (*timeout);
61
62 return SYSCALL_CANCEL (ppoll, fds, nfds, timeout ? &ts32 : NULL, sigmask,
63 __NSIG_BYTES);
64#endif
65}
66
67#if __TIMESIZE != 64
68libc_hidden_def (__ppoll64)
69
70int
71__ppoll (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout,
72 const sigset_t *sigmask)
73{
74 struct __timespec64 ts64;
75 if (timeout)
76 ts64 = valid_timespec_to_timespec64 (*timeout);
77
78 return __ppoll64 (fds, nfds, timeout ? &ts64 : NULL, sigmask);
79}
80#endif
81strong_alias (__ppoll, ppoll)
82libc_hidden_def (ppoll)
83