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 <sys/select.h>
20#include <sysdep-cancel.h>
21
22static int
23pselect64_syscall (int nfds, fd_set *readfds, fd_set *writefds,
24 fd_set *exceptfds, const struct __timespec64 *timeout,
25 const sigset_t *sigmask)
26{
27#ifndef __NR_pselect6_time64
28# define __NR_pselect6_time64 __NR_pselect6
29#endif
30 /* NB: This is required by ARGIFY used in x32 internal_syscallN. */
31 __syscall_ulong_t data[2] =
32 {
33 (uintptr_t) sigmask, __NSIG_BYTES
34 };
35 return SYSCALL_CANCEL (pselect6_time64, nfds, readfds, writefds, exceptfds,
36 timeout, data);
37}
38
39int
40__pselect64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
41 const struct __timespec64 *timeout, const sigset_t *sigmask)
42{
43 /* The Linux kernel can in some situations update the timeout value.
44 We do not want that so use a local variable. */
45 struct __timespec64 tval;
46 if (timeout != NULL)
47 {
48 tval = *timeout;
49 timeout = &tval;
50 }
51
52 /* Note: the system call expects 7 values but on most architectures
53 we can only pass in 6 directly. If there is an architecture with
54 support for more parameters a new version of this file needs to
55 be created. */
56#ifdef __ASSUME_TIME64_SYSCALLS
57 return pselect64_syscall (nfds, readfds, writefds, exceptfds, timeout,
58 sigmask);
59#else
60 bool need_time64 = timeout != NULL && !in_time_t_range (timeout->tv_sec);
61 if (need_time64)
62 {
63 int r = pselect64_syscall (nfds, readfds, writefds, exceptfds, timeout,
64 sigmask);
65 if (r == 0 || errno != ENOSYS)
66 return r;
67 __set_errno (EOVERFLOW);
68 return -1;
69 }
70
71 return __pselect32 (nfds, readfds, writefds, exceptfds, timeout, sigmask);
72#endif
73}
74
75#if __TIMESIZE != 64
76libc_hidden_def (__pselect64)
77
78int
79__pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
80 const struct timespec *timeout, const sigset_t *sigmask)
81{
82 struct __timespec64 ts64, *pts64 = NULL;
83 if (timeout != NULL)
84 {
85 ts64 = valid_timespec_to_timespec64 (*timeout);
86 pts64 = &ts64;
87 }
88 return __pselect64 (nfds, readfds, writefds, exceptfds, pts64, sigmask);
89}
90#endif
91
92#ifndef __pselect
93weak_alias (__pselect, pselect)
94#endif
95