Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 27 Dec 2020 18:42:08 +0000
From: Alexander Lobakin <alobakin@...me>
To: Rich Felker <dalias@...ifal.cx>, musl@...ts.openwall.com
Cc: Alexander Lobakin <alobakin@...me>
Subject: [PATCH 12/18] poll, ppoll: prefer time64 variant of ppoll if available

Instead of using time64 variant "only when needed", use it as
a default and fallback to time32 only on -ENOSYS.
Also use ppoll as a default for poll and fallback to poll only
at last.

Signed-off-by: Alexander Lobakin <alobakin@...me>
---
 src/linux/ppoll.c |  8 +++-----
 src/select/poll.c | 23 ++++++++++++++++++-----
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/src/linux/ppoll.c b/src/linux/ppoll.c
index e614600ab8b7..88a5b91a47b5 100644
--- a/src/linux/ppoll.c
+++ b/src/linux/ppoll.c
@@ -12,11 +12,9 @@ int ppoll(struct pollfd *fds, nfds_t n, const struct timespec *to, const sigset_
 	time_t s = to ? to->tv_sec : 0;
 	long ns = to ? to->tv_nsec : 0;
 #ifdef SYS_ppoll_time64
-	int r = -ENOSYS;
-	if (SYS_ppoll == SYS_ppoll_time64 || !IS32BIT(s))
-		r = __syscall_cp(SYS_ppoll_time64, fds, n,
-			to ? ((long long[]){s, ns}) : 0,
-			mask, _NSIG/8);
+	int r = __syscall_cp(SYS_ppoll_time64, fds, n,
+		to ? ((long long[]){s, ns}) : 0,
+		mask, _NSIG/8);
 	if (SYS_ppoll == SYS_ppoll_time64 || r != -ENOSYS)
 		return __syscall_ret(r);
 	s = CLAMP(s);
diff --git a/src/select/poll.c b/src/select/poll.c
index c84c8a999ccc..e6b737081939 100644
--- a/src/select/poll.c
+++ b/src/select/poll.c
@@ -5,11 +5,24 @@
 
 int poll(struct pollfd *fds, nfds_t n, int timeout)
 {
+	time_t s = timeout >= 0 ? timeout / 1000 : 0;
+	long ns = timeout >= 0 ? timeout % 1000 * 1000000 : 0;
+	int r = -ENOSYS;
+#ifdef SYS_ppoll_time64
+	int r = __syscall_cp(SYS_ppoll_time64, fds, n,
+		timeout >= 0 ? ((long long[]){s, ns}) : 0,
+		0, _NSIG / 8);
+	if (SYS_ppoll == SYS_ppoll_time64 || r != -ENOSYS)
+		return __syscall_ret(r);
+#endif
+#ifdef SYS_ppoll
+	r = __syscall_cp(SYS_ppoll, fds, n,
+		timeout >= 0 ? ((long[]){s, ns}) : 0,
+		0, _NSIG / 8);
+#endif
 #ifdef SYS_poll
-	return syscall_cp(SYS_poll, fds, n, timeout);
-#else
-	return syscall_cp(SYS_ppoll, fds, n, timeout>=0 ?
-		&((struct timespec){ .tv_sec = timeout/1000,
-		.tv_nsec = timeout%1000*1000000 }) : 0, 0, _NSIG/8);
+	if (r == -ENOSYS)
+		r = __syscall_cp(SYS_poll, fds, n, timeout);
 #endif
+	return __syscall_ret(r);
 }
-- 
2.29.2


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.