From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10495 Path: news.gmane.org!.POSTED!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH v2] fix clock_nanosleep error case Date: Sun, 18 Sep 2016 21:44:21 +0200 Message-ID: <20160918194421.GY1280@port70.net> 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=us-ascii X-Trace: blaine.gmane.org 1474227882 4554 195.159.176.226 (18 Sep 2016 19:44:42 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 18 Sep 2016 19:44:42 +0000 (UTC) User-Agent: Mutt/1.6.0 (2016-04-01) Cc: Rich Felker To: musl@lists.openwall.com Original-X-From: musl-return-10508-gllmg-musl=m.gmane.org@lists.openwall.com Sun Sep 18 21:44:39 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 1bli0w-0000I7-Li for gllmg-musl@m.gmane.org; Sun, 18 Sep 2016 21:44:34 +0200 Original-Received: (qmail 24478 invoked by uid 550); 18 Sep 2016 19:44:33 -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 24457 invoked from network); 18 Sep 2016 19:44:33 -0000 Mail-Followup-To: musl@lists.openwall.com, Rich Felker Content-Disposition: inline In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:10495 Archived-At: * Daniel Sabogal [2016-09-18 15:01:47 -0400]: > 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. ah. i assumed ENOTSUP is always wrong, then i guess the patch is ok. > 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.