From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12837 Path: news.gmane.org!.POSTED!not-for-mail From: Peter Hurley Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] Preserve select() behavior on arm64 Date: Fri, 25 May 2018 13:52:40 -0700 Message-ID: <20180525205240.20319-1-peter@meraki.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1527281470 21257 195.159.176.226 (25 May 2018 20:51:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 25 May 2018 20:51:10 +0000 (UTC) Cc: Peter Hurley To: musl@lists.openwall.com Original-X-From: musl-return-12853-gllmg-musl=m.gmane.org@lists.openwall.com Fri May 25 22:51:06 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1fMJg0-0005PI-UZ for gllmg-musl@m.gmane.org; Fri, 25 May 2018 22:51:05 +0200 Original-Received: (qmail 7469 invoked by uid 550); 25 May 2018 20:53:13 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 7436 invoked from network); 25 May 2018 20:53:12 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meraki.com; s=google; h=from:to:cc:subject:date:message-id; bh=ueKR2/lMS9y9X31jYapm/ANTPTpY1G4NhrWVdlFb6vc=; b=lRgydZRJOEfgzfkF4Fn7RE5wuJgMKvUJN3RuaT8G0ZdnRCX7tnn0fhMsibLr5XNn3R 7WmwEzTJYIp4H0QJQpGgbblLe1hQFECDgd26PNL7WGmtJHPqm5KWKKY+i6xp/uthJnYL Cis323AM5LZqo18IuQDLe/HHod8MFrJSHNfXA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ueKR2/lMS9y9X31jYapm/ANTPTpY1G4NhrWVdlFb6vc=; b=gWZGgJAcUA+qa9ftTmOF81b43FsSXUGYeOBaCwpHvIH+t4mkTO6MvxOsbWhyyi+jDv HjawvDbuOe9u1vNYSWqgiBx0evXJw6D74PbjTwWDSUML0/bfYCUCDYj1EfhvFOAqtIX7 ymlpTy6tQL+x2KhOWrgfJ9pFTazEnvavxvbK8sdL/7FAYEwpdEG3FeMRmnLjZzf48M+V XVbPeS/01McL6/TOCn68y/gXCWnHRzK+EJT87aORTPUOwTgq9Nhl81+T+cQBwIHjThDO O0o0FgunVf7MDlwo81LibdFbsLD5O4FL44dSYK1o4oesWuXqTS1rJHRzUeegAPFzbVEs RmGQ== X-Gm-Message-State: ALKqPweY7OlJFrTnrlXeiQqUFDGTnVnESL5gOfVMldF301NsYh/iq3DN YSqm9h1gppZ+garGDxd8+N6TUYWD63E= X-Google-Smtp-Source: AB8JxZqvMg0GPsGjDL/oXOs4WeFt4WjG2xeITN3TuX6yWCRn/rxw9Dv2XMC8fDTm2XMljPF6ELi8VQ== X-Received: by 2002:aa7:8084:: with SMTP id v4-v6mr4036697pff.105.1527281580068; Fri, 25 May 2018 13:53:00 -0700 (PDT) X-Mailer: git-send-email 2.17.0 Xref: news.gmane.org gmane.linux.lib.musl.general:12837 Archived-At: 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