From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10492 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH v2] fix clock_nanosleep error case Date: Sat, 17 Sep 2016 23:38:40 -0400 Message-ID: <20160918033840.GZ15995@brightrain.aerifal.cx> References: <20160917160545.4348-1-dsabogalcc@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1474169992 27016 195.159.176.226 (18 Sep 2016 03:39:52 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 18 Sep 2016 03:39:52 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) Cc: musl@lists.openwall.com To: Daniel Sabogal Original-X-From: musl-return-10505-gllmg-musl=m.gmane.org@lists.openwall.com Sun Sep 18 05:39:48 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 1blSx9-0005Us-II for gllmg-musl@m.gmane.org; Sun, 18 Sep 2016 05:39:39 +0200 Original-Received: (qmail 5351 invoked by uid 550); 18 Sep 2016 03:39:38 -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 5328 invoked from network); 18 Sep 2016 03:39:37 -0000 Content-Disposition: inline In-Reply-To: <20160917160545.4348-1-dsabogalcc@gmail.com> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:10492 Archived-At: 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 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. Rich