From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10493 Path: news.gmane.org!.POSTED!not-for-mail From: Daniel Sabogal Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH v2] fix clock_nanosleep error case Date: Sun, 18 Sep 2016 15:01:47 -0400 Message-ID: References: <20160917160545.4348-1-dsabogalcc@gmail.com> <20160918033840.GZ15995@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: blaine.gmane.org 1474225332 23262 195.159.176.226 (18 Sep 2016 19:02:12 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 18 Sep 2016 19:02:12 +0000 (UTC) Cc: musl@lists.openwall.com To: Rich Felker Original-X-From: musl-return-10506-gllmg-musl=m.gmane.org@lists.openwall.com Sun Sep 18 21:02:07 2016 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 1blhLm-0004m9-VL for gllmg-musl@m.gmane.org; Sun, 18 Sep 2016 21:02:03 +0200 Original-Received: (qmail 22060 invoked by uid 550); 18 Sep 2016 19:02:00 -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 22039 invoked from network); 18 Sep 2016 19:02:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=AyfZ05ijmuEbHm53ehMuDU2pZ970wwYEMXJsI5blUMM=; b=07nOlOkPpLN/vB+RlI5J8Tp8dsKElwbtvQD2B7wkuQQshM1dvXp7wEiRoaozWRczB3 ikP0RLZfNQNQuTMuJRWV2r6L0T7xyqJ/USa7zAHoxN1SpbkzRW7XCQUf5IgM6i4glY82 3OjsNqvARyD5MCUxSaBKnnOXh50jP9vzMuL5oWqDj/PUXkg3tl0xCwW30BZjcJWYy7xm DrYa/RowOLGcIgKpmK9lhCer29BbInXSfa41eVdi7C6WkGg9Ir4DoHk1dKlm78u/cI/v y8h8JI2AROsnAOdjl6y3YhSsrgrWrGniIASAf6xo0o/MhXJhzbjcONe4IOSWL9fatWgl OX4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=AyfZ05ijmuEbHm53ehMuDU2pZ970wwYEMXJsI5blUMM=; b=PkNdYPb4sR6pX+m7Hqoi57a/ckpygmda8pZY766jKmsxvzVXhg/GD8NHbKXmTmANPb Mp33mzn5E4cIxQLRIT244OsrCqkMpfEylVXlHfbz9WIRmIp6zPicekZ02Kmo7oR/TZKa o4oTx04dn2bLZwwy0u6CE/X9S+YvSFv6Uq+jmfuNewTQEZ2zeu+6YXPloAT1U2VlU5XT p8WDvKhpTaxm91jZHCBP29KALMyD3D9UmV4BaeTxONppj9VQKtAP8mWxDedcjlFWH6aV 7ZfhBlE9CXUAVzmD3mXOUoojsZ2Q1yRkXaoJ+wxXmD64M8VzoCtjf567jRzWqBynnkcD sikQ== X-Gm-Message-State: AE9vXwON+XboJ9aWluFsvifQtR98kaO0XLOdqoF3PhDEj6to1q7pJcylcrcuCVSsOIk01jvj520EV2MNbK9OSQ== X-Received: by 10.202.172.214 with SMTP id v205mr24180164oie.22.1474225308466; Sun, 18 Sep 2016 12:01:48 -0700 (PDT) In-Reply-To: <20160918033840.GZ15995@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:10493 Archived-At: On Sat, Sep 17, 2016 at 11:38 PM, Rich Felker wrote: > On Sat, Sep 17, 2016 at 12:05:45PM -0400, Daniel Sabogal wrote: >> posix requires that EINVAL be returned if the first parameter specifies >> the cpu-time clock of the calling thread (CLOCK_THREAD_CPUTIME_ID). >> linux returns ENOTSUP instead so we handle this. >> --- >> Applied Szabolcs' suggestion for remapping the return value. >> clock_nanosleep is required to be a cancellation point. >> --- >> src/time/clock_nanosleep.c | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/src/time/clock_nanosleep.c b/src/time/clock_nanosleep.c >> index ec87b9e..9e4d9f1 100644 >> --- a/src/time/clock_nanosleep.c >> +++ b/src/time/clock_nanosleep.c >> @@ -1,8 +1,10 @@ >> #include >> +#include >> #include "syscall.h" >> #include "libc.h" >> >> int clock_nanosleep(clockid_t clk, int flags, const struct timespec *req, struct timespec *rem) >> { >> - return -__syscall_cp(SYS_clock_nanosleep, clk, flags, req, rem); >> + int r = -__syscall_cp(SYS_clock_nanosleep, clk, flags, req, rem); >> + return clk == CLOCK_THREAD_CPUTIME_ID ? EINVAL : r; >> } > > See: > > On Sat, Sep 17, 2016 at 04:57:09PM +0200, Szabolcs Nagy wrote: >> you elide a cancellation point here. >> >> i think you should check and remap the return value instead. > > "Remap the return value" would be more like: > > return r==ENOTSUP ? EINVAL : r; I wasn't sure about remapping all return values of ENOTSUP to EINVAL. There are other clocks (extensions) where linux and glibc return ENOTSUP. I looked through Debian Code Search, but didn't really find anything that actually uses or depends on such behavior for those extensions. I suppose this might be fine. > I don't know if it makes a big difference, but in principle it's > better to base conditions on a return value than an argument, since > basing them on an argument requires the value of that argument to be > preserved across the call and can thereby require spilling registers, > etc. I don't think that actually happens on any of the Linux syscall > ABIs but I'm not sure. OK.