Skip to content

fix(libkernel): prevent POSIX timed-lock deadline overflow - #2111

Closed
STUPIDCONTEM wants to merge 1 commit into
boykopovar:mainfrom
STUPIDCONTEM:fix/posix-deadline-overflow
Closed

STUPIDCONTEM wants to merge 1 commit into
boykopovar:mainfrom
STUPIDCONTEM:fix/posix-deadline-overflow

Conversation

@STUPIDCONTEM

Copy link
Copy Markdown
Contributor

What

Avoid signed nanosecond overflow when converting absolute POSIX timed-lock deadlines. The shared condition/rwlock/semaphore helper now compares seconds and nanoseconds, computes their nonnegative difference, and clamps before converting to microseconds. The mutex timed-lock wrapper uses the same conversion instead of duplicating the overflowing chrono expression.

A valid distant deadline could previously become negative and cause an immediate ETIMEDOUT. This preserves the existing 32-bit microsecond wait cap, positive submicrosecond truncation, and argument-validation order; it does not extend that maximum wait interval.

FreeBSD stable/11 condition waiting carries the validated absolute timespec into the wait rather than narrowing the epoch to signed nanoseconds. The project represents both timespec fields as signed 64-bit values. Open #2064 and #2067 fix separate equeue/nanosleep conversions; searches found no competing implementation of this helper or the mutex correction.

Tested

Windows 10 Pro 19045, WinLibs GCC 15.2 UCRT posix SEH r7, Release, BUILD_TESTING=ON, main 6cc0503.

  • A blocked rwlock with an INT64_MAX-second deadline fails against unchanged upstream with guest ETIMEDOUT (60), although its holder releases after 20 ms.
  • Fixing only the shared helper exposes the independent mutex path: the matching blocked-mutex regression still returns 60. With both paths corrected, five focused runs pass. Workers are released and joined before reporting errors.
  • Existing ordinary/past/invalid timeout tests remain; an added short subsecond deadline times out as expected. Parent reviewed unsigned subtraction, nanosecond borrowing, clamping and the real condition/rwlock/semaphore callers.
  • With the separate build repair fix(build): declare SPIRV headers for Vulkan helper tests #2093, default and explicit libs builds passed and full CTest passed 494/494 in 34.62 seconds, with no skipped tests (combined head 018ad968). Conventions, whitespace and registration checks passed.

No Linux or title execution is claimed for this change.

Checklist

  • Based on current main; no other open PR implements this correction
  • One deadline-conversion topic
  • No code comments added
  • No silent stubs added
  • No notes, reports or images added to the repository
  • No third-party code added
  • Generic behavior, not title-specific
  • Depends on: fix(build): declare SPIRV headers for Vulkan helper tests #2093 for the full current-main graphics test build
  • AI-assisted: yes; independently reviewed and tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant