From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/9205 Path: news.gmane.org!not-for-mail From: Hauke Mehrtens Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH v3 1/2] vdso: clock_gettime: call normal syscall in case of an error Date: Tue, 26 Jan 2016 21:26:33 +0100 Message-ID: <1453839994-7649-1-git-send-email-hauke@hauke-m.de> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1453840020 23683 80.91.229.3 (26 Jan 2016 20:27:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 26 Jan 2016 20:27:00 +0000 (UTC) Cc: Hauke Mehrtens To: musl@lists.openwall.com Original-X-From: musl-return-9219-gllmg-musl=m.gmane.org@lists.openwall.com Tue Jan 26 21:27:00 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1aOACX-0006Dk-Ba for gllmg-musl@m.gmane.org; Tue, 26 Jan 2016 21:26:57 +0100 Original-Received: (qmail 23896 invoked by uid 550); 26 Jan 2016 20:26:55 -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 23834 invoked from network); 26 Jan 2016 20:26:49 -0000 X-Mailer: git-send-email 2.7.0.rc3 X-Spam-Status: No, score=0.0 required=7.0 tests=UNPARSEABLE_RELAY, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on hauke-m.de Xref: news.gmane.org gmane.linux.lib.musl.general:9205 Archived-At: When the vdso call returns an error just call the normal syscall and return its result. clock_gettime() only fails with EFAULT if tp points to an inaccessible address space or with EINVAL if the clk_id is unknown. EFAULT is an implementation problem and performance for this case is not important. When it returns EINVAL a normal syscall could still work, so try it. This fixes a bug when an error occurred errno was not set and it was a value different than -1 returned. In addition on MIPS the Linux kernel 4.4 only supports some clk_ids and assumes the libc will call the original function if it gets a -ENOSYS, so do this for all error codes. Signed-off-by: Hauke Mehrtens --- src/time/clock_gettime.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/time/clock_gettime.c b/src/time/clock_gettime.c index 1572de0..9d3ff7e 100644 --- a/src/time/clock_gettime.c +++ b/src/time/clock_gettime.c @@ -26,16 +26,18 @@ void *__vdsosym(const char *, const char *); int __clock_gettime(clockid_t clk, struct timespec *ts) { #ifdef VDSO_CGT_SYM + int r; static int (*volatile cgt)(clockid_t, struct timespec *); if (!cgt) { void *f = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM); if (!f) f = (void *)sc_clock_gettime; a_cas_p(&cgt, 0, f); } - return cgt(clk, ts); -#else - return sc_clock_gettime(clk, ts); + r = cgt(clk, ts); + /* In case an error occurred try the normal syscall */ + if (!r) return r; #endif + return sc_clock_gettime(clk, ts); } weak_alias(__clock_gettime, clock_gettime); -- 2.7.0.rc3