https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93421

            Bug ID: 93421
           Summary: futex.cc use of futex syscall is not time64-compatible
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugdal at aerifal dot cx
  Target Milestone: ---

Created attachment 47704
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47704&action=edit
simple fix, not necessarily right for upstream

This code directly passes a userspace timespec struct to the SYS_futex syscall,
which does not work if the userspace type is 64-bit but the syscall expects
legacy 32-bit timespec.

I'm attaching the patch we're using in musl-cross-make to fix this. It does not
attempt to use the SYS_futex_time64 syscall, since that would require fallback
logic with cost tradeoffs for which to try first, and since the timeout is
relative and therefore doesn't even need to be 64-bit. Instead it just uses the
existence of SYS_futex_time64 to infer that the plain SYS_futex uses a pair of
longs, and converts the relative timestamp into that. This assumes that any
system where the libc timespec type has been changed for time64 will also have
had its headers updated to define SYS_futex_time64.

Error handling for extreme out-of-bound values should probably be added.

Reply via email to