mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Peter Hurley <peter@meraki.com>
To: musl@lists.openwall.com
Cc: Peter Hurley <peter@meraki.com>
Subject: [PATCH] Preserve select() behavior on arm64
Date: Fri, 25 May 2018 13:52:40 -0700	[thread overview]
Message-ID: <20180525205240.20319-1-peter@meraki.com> (raw)

On Linux, all the select-related syscalls update the timeout value to
indicate how much elapsed time the syscall consumed, and many programs
expect this behavior when running on Linux.

Newer archs like arm64 have deprecated the select syscall because the
pselect syscall is a superset implementation of the select syscall.

A complication of implementing select() with the pselect syscall is
that the timeouts are specified in different units; select() accepts
a struct timeval ptr whereas the pselect syscall takes a struct
timespec ptr. These are trivial convertible; struct timeval is
specified in seconds + microseconds and struct timespec is in
seconds + nanoseconds.

For kernel configurations without select syscall available, update the
caller's struct timeval argument after the pselect syscall.
---
 src/select/select.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/select/select.c b/src/select/select.c
index 7b5f6dcf7a53..45d4cb7a3d0a 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -12,15 +12,16 @@ int select(int n, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restrict
 #else
 	syscall_arg_t data[2] = { 0, _NSIG/8 };
 	struct timespec ts;
+	int result;
 	if (tv) {
-		if (tv->tv_sec < 0 || tv->tv_usec < 0)
-			return __syscall_ret(-EINVAL);
-		time_t extra_secs = tv->tv_usec / 1000000;
-		ts.tv_nsec = tv->tv_usec % 1000000 * 1000;
-		const time_t max_time = (1ULL<<8*sizeof(time_t)-1)-1;
-		ts.tv_sec = extra_secs > max_time - tv->tv_sec ?
-			max_time : tv->tv_sec + extra_secs;
+		ts->tv_sec = tv->tv_sec;
+		ts->tv_nsec = tv->usec * 1000;
 	}
-	return syscall_cp(SYS_pselect6, n, rfds, wfds, efds, tv ? &ts : 0, data);
+	result = syscall_cp(SYS_pselect6, n, rfds, wfds, efds, tv ? &ts : 0, data);
+	if (tv) {
+		tv->tv_sec = ts->tv_sec;
+		tv->tv_usec = ts->tv_nsec / 1000;
+	}
+	return result;
 #endif
 }
-- 
2.14.2



             reply	other threads:[~2018-05-25 20:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-25 20:52 Peter Hurley [this message]
2018-08-29  6:11 ` Peter Hurley
2018-08-29 22:42 ` Rich Felker
2018-08-29 22:56   ` Rich Felker
2018-08-30 14:30     ` Peter Hurley
2018-08-30 14:31   ` Peter Hurley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180525205240.20319-1-peter@meraki.com \
    --to=peter@meraki.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).