Skip to content

thread: fix 32-bit legacy sleep fallbacks - #1719

Open
kmehltretter82 wants to merge 2 commits into
bytecodealliance:mainfrom
kmehltretter82:fix/time32-sleep-fallbacks
Open

kmehltretter82 wants to merge 2 commits into
bytecodealliance:mainfrom
kmehltretter82:fix/time32-sleep-fallbacks

Conversation

@kmehltretter82

Copy link
Copy Markdown
Contributor

On 32-bit Linux with the linux_raw backend, Rustix falls back to the legacy
sleep syscalls when clock_nanosleep_time64 returns ENOSYS.

The relative fallbacks currently return on EINTR before copying the
old-timespec remainder and read that remainder after successful calls, when it
is not initialized. The absolute fallback passes flags 0, so the kernel
treats its deadline as a relative duration.

This series copies legacy remainders only on EINTR and preserves
TIMER_ABSTIME in the absolute fallback.

Testing

On a physical ARMv5 SAM9X75 running Linux 6.18, a process-local seccomp filter
returned ENOSYS only for clock_nanosleep_time64 to exercise the legacy
paths. The unpatched absolute call slept for about 50 ms instead of returning
immediately, and both interrupted relative calls returned corrupt remainders.
All three cases passed with this series. strace confirmed the transition to
the legacy syscalls.

  • cargo +stable check --locked --offline --target armv5te-unknown-linux-musleabi --features=all-apis --lib
  • cargo +stable check --locked --offline --target i686-unknown-linux-musl --features=all-apis --lib
  • cargo +stable fmt --check

On 32-bit Linux, the legacy clock_nanosleep and nanosleep
fallbacks return on EINTR before copying the old-timespec remainder.
They also read the remainder after success, when the kernel need not
initialize it.

Convert and copy the old remainder only when the syscall returns EINTR,
then return the syscall result.
On 32-bit Linux, the legacy clock_nanosleep fallback omits
TIMER_ABSTIME, so the kernel interprets the absolute deadline as a
relative duration.

Pass TIMER_ABSTIME, matching the time64 and 64-bit paths.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant