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