mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Hauke Mehrtens <hauke@hauke-m.de>
To: musl@lists.openwall.com
Cc: Hauke Mehrtens <hauke@hauke-m.de>
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	[thread overview]
Message-ID: <1453839994-7649-1-git-send-email-hauke@hauke-m.de> (raw)

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 <hauke@hauke-m.de>
---
 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



             reply	other threads:[~2016-01-26 20:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-26 20:26 Hauke Mehrtens [this message]
2016-01-26 20:26 ` [PATCH v3 2/2] mips: add vdso support Hauke Mehrtens
2016-01-27 17:11 ` [PATCH v3 1/2] vdso: clock_gettime: call normal syscall in case of an error Rich Felker

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=1453839994-7649-1-git-send-email-hauke@hauke-m.de \
    --to=hauke@hauke-m.de \
    --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).