fix(libkernel): reject negative cond timedwait seconds #5566

Closed
MarcZX10 wants to merge 2 commits from upstream-pr/5566 into main
MarcZX10 commented 2026-10-14 00:03:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T00:03:19Z.


What

Fixes #5561. pthread_cond_timedwait now returns EINVAL when the absolute deadline has a negative tv_sec, matching FreeBSD and the existing validation of null deadlines and invalid tv_nsec values. Previously, a negative seconds value was treated as a deadline in the past and returned ETIMEDOUT (or reached the mutex ownership check first).

The implementation commit is Hussein Kadhim's original commit, cherry-picked onto current main with his author attribution preserved. A follow-up test by MarcZX100 checks the error precedence with both a held and an unowned mutex.

#4953 edits the same test file and currently expects {-1, 0} to return ETIMEDOUT; that expectation conflicts with this FreeBSD-compatible result and should become EINVAL. The production changes are otherwise independent (#4953 validates condition-attribute clock IDs), so Depends on: none; whichever merges second needs a rebase and the shared test expectation updated.

Tested

Linux, GCC 12.2, Ninja Release, BUILD_TESTING=ON, current main d1670009fbfdfe57f8f26ee09ced77fe6b18c2ca:

  • Built guest_cond_timedwait_tests, guest_cond_recursive_mutex_tests, and guest_cond_unowned_mutex_tests.
  • guest_cond_timedwait, guest_cond_recursive_mutex, and guest_cond_unowned_mutex each passed three consecutive CTest runs (9/9).
  • Baseline control: with the new test retained but the tv_sec guard restored to current main, guest_cond_timedwait failed as expected; with the fix restored, all three tests passed.
  • tools/check_conventions.py --base upstream/main and git diff --check upstream/main...HEAD passed.
  • Windows was not run locally. The issue records the source author's Windows focused tests and validation matrix.

Checklist

  • Based on current main; no other open PR implements the same behavior
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes; reviewed and tested by MarcZX100
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4851041466 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5566). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-14T00:03:19Z. --- ### What Fixes #5561. `pthread_cond_timedwait` now returns `EINVAL` when the absolute deadline has a negative `tv_sec`, matching FreeBSD and the existing validation of null deadlines and invalid `tv_nsec` values. Previously, a negative seconds value was treated as a deadline in the past and returned `ETIMEDOUT` (or reached the mutex ownership check first). The implementation commit is Hussein Kadhim's original commit, cherry-picked onto current `main` with his author attribution preserved. A follow-up test by MarcZX100 checks the error precedence with both a held and an unowned mutex. #4953 edits the same test file and currently expects `{-1, 0}` to return `ETIMEDOUT`; that expectation conflicts with this FreeBSD-compatible result and should become `EINVAL`. The production changes are otherwise independent (`#4953` validates condition-attribute clock IDs), so `Depends on: none`; whichever merges second needs a rebase and the shared test expectation updated. ### Tested Linux, GCC 12.2, Ninja Release, `BUILD_TESTING=ON`, current `main` `d1670009fbfdfe57f8f26ee09ced77fe6b18c2ca`: - Built `guest_cond_timedwait_tests`, `guest_cond_recursive_mutex_tests`, and `guest_cond_unowned_mutex_tests`. - `guest_cond_timedwait`, `guest_cond_recursive_mutex`, and `guest_cond_unowned_mutex` each passed three consecutive CTest runs (9/9). - Baseline control: with the new test retained but the `tv_sec` guard restored to current `main`, `guest_cond_timedwait` failed as expected; with the fix restored, all three tests passed. - `tools/check_conventions.py --base upstream/main` and `git diff --check upstream/main...HEAD` passed. - Windows was not run locally. The issue records the source author's Windows focused tests and validation matrix. ### Checklist - [x] Based on current `main`; no other open PR implements the same behavior - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes; reviewed and tested by MarcZX100
github-actions[bot] commented 2026-10-14 00:22:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T00:22:33Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4953 core/libs/tests/GuestCondTimedwait.cpp L19, L31, L106-108
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158042717 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5566#issuecomment-6158042717). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T00:22:33Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4953 | `core/libs/tests/GuestCondTimedwait.cpp` [L19](https://github.com/boykopovar/AnyPS5/blob/604ce71864f952cc8cf6fb1f4966cc905e0c1466/core/libs/tests/GuestCondTimedwait.cpp#L19), [L31](https://github.com/boykopovar/AnyPS5/blob/604ce71864f952cc8cf6fb1f4966cc905e0c1466/core/libs/tests/GuestCondTimedwait.cpp#L31), [L106-108](https://github.com/boykopovar/AnyPS5/blob/604ce71864f952cc8cf6fb1f4966cc905e0c1466/core/libs/tests/GuestCondTimedwait.cpp#L106-L108) | | |
oneandonlydean commented 2026-10-14 01:08:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T01:08:07Z.


Closing: no title is known to reach this. With the queue at 750 open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158590802 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5566#issuecomment-6158590802). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T01:08:07Z. --- Closing: no title is known to reach this. With the queue at 750 open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!5566
No description provided.