Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20260817123202.GD23438@brightrain.aerifal.cx>
Date: Mon, 17 Aug 2026 08:32:03 -0400
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: [PATCH] clock_nanosleep: define SYS_nanosleep to fix
 riscv32

On Mon, Jul 13, 2026 at 04:26:29PM +0200, Szabolcs Nagy wrote:
> * Rich Felker <dalias@...c.org> [2026-07-13 09:41:52 -0400]:
> > Being that there's only one file using the syscall, I think maybe I'd
> > rather put the conditional there.
> 
> makes sense

> >From e28fefd3e46c5e7537a2901a9c3494e946eaae85 Mon Sep 17 00:00:00 2001
> From: Szabolcs Nagy <nsz@...t70.net>
> Date: Mon, 13 Jul 2026 06:44:27 +0000
> Subject: [PATCH] clock_nanosleep: define SYS_nanosleep to fix riscv32
> 
> riscv32 does not have SYS_nanosleep, but it is used in unreachable
> fallback code.
> ---
>  src/time/clock_nanosleep.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/src/time/clock_nanosleep.c b/src/time/clock_nanosleep.c
> index e195499c..f75f7f2a 100644
> --- a/src/time/clock_nanosleep.c
> +++ b/src/time/clock_nanosleep.c
> @@ -19,6 +19,9 @@ int __clock_nanosleep(clockid_t clk, int flags, const struct timespec *req, stru
>  		return -r;
>  	long long extra = s - CLAMP(s);
>  	long ts32[2] = { CLAMP(s), ns };
> +#ifndef SYS_nanosleep
> +#define SYS_nanosleep -1
> +#endif
>  	if (clk == CLOCK_REALTIME && !flags)
>  		r = __syscall_cp(SYS_nanosleep, &ts32, &ts32);
>  	else
> -- 
> 2.52.0
> 

Sorry for letting this slide! I'm think going to apply a bit of a
different fix, because I noticed SYS_nanosleep is also used in the
#else case for 64-bit archs, and it seems plausible that future ones
might omit SYS_nanosleep since it's redundant.

I started off just trying to move the fake SYS_nanosleep definition to
the top of the file, but then I realized this was something of a
footgun because the only way it works is that the code that would use
the -1 was unreachable/dead code. But that's not the case in the
64-bit #else codepath.

So I just wrote a __sys_nanosleep_cp() function that conditionally
uses SYS_clock_nanosleep instead if SYS_nanosleep isn't available, and
used it both places.

Alternatively we could just put separate #ifdef SYS_nanosleep around
both places that use it; in some ways this is "better" because the
compiler doesn't have to do slightly nontrivial CSE for the case where
the if/else paths have the same code on hypothetical future archs. But
I didn't like (and I think you probably didn't like) the "wrong
indentation" with the if/else but not the else-body being #ifdef'd
out.

Rich

View attachment "nanosleep_fix.diff" of type "text/plain" (1454 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.