fix(libkernel): enforce POSIX semaphore count limits #428

Merged
RomainROCH merged 1 commit from upstream-pr/428 into main 2026-10-04 01:03:07 +00:00
RomainROCH commented 2026-10-03 02:27:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by RomainROCH on 2026-10-03T02:27:45Z.


What

Enforce the guest POSIX semaphore maximum of 0x7fffffff. Reject larger initial values with guest EINVAL. Reject sem_post at the maximum with guest EOVERFLOW (84), under the existing lock and before incrementing or notifying.

Invalid initialization preserves the caller's storage. Rejected posts preserve the count, which remains readable through sem_getvalue.

Tested

Tested commit: eae05782afa6be74497b14381670a607376684db, based on main at 7d40a57d185b30735fbc519a9bdf2548d4bcb87f.

The full fork Build workflow succeeded on both platforms: Release configuration, default build, libs target, and CTest with --repeat until-fail:3.

Platform Passed tests Skipped tests Failed tests
Linux 125 2 0
Windows 117 11 0

The focused guest_posix_sem_init and guest_posix_sem_post regressions passed on both platforms in all three repetitions. The skipped tests are GPU execution tests: two on Linux and eleven on Windows.

The initial Linux attempt failed only on agc_driver_vopc_compare (thread 1, compare 39), while both semaphore regressions passed. Windows succeeded on that attempt. Only Linux was rerun, without changing the commit or workflow, and the second attempt succeeded. GPU and shader sources are unchanged by this PR; the base and the independent Unicode branch also passed their Linux workflows. The cause of the first GPU failure is unconfirmed.

These are fork results on the specified commit. An upstream workflow requiring maintainer approval has not executed until approved.

Both regressions failed before the correction. Coverage includes initial values above the maximum, successful initialization at the maximum, unchanged output and count on failure, repeated overflow, decrement and increment at the boundary, and normal empty/nonempty semaphore operations.

This changes the POSIX semaphore implementation, independently of #315 (sceKernelSignalSema). All fixtures are synthetic. No game or homebrew title was tested; these results do not establish game compatibility.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stub added
  • No investigation notes, reports or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4723469616 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/428). Originally posted by [RomainROCH](https://github.com/RomainROCH) on 2026-10-03T02:27:45Z. --- ### What Enforce the guest POSIX semaphore maximum of `0x7fffffff`. Reject larger initial values with guest `EINVAL`. Reject `sem_post` at the maximum with guest `EOVERFLOW` (84), under the existing lock and before incrementing or notifying. Invalid initialization preserves the caller's storage. Rejected posts preserve the count, which remains readable through `sem_getvalue`. ### Tested Tested commit: `eae05782afa6be74497b14381670a607376684db`, based on `main` at `7d40a57d185b30735fbc519a9bdf2548d4bcb87f`. The full [fork Build workflow](https://github.com/RomainROCH/AnyPS5/actions/runs/37088538109) succeeded on both platforms: Release configuration, default build, `libs` target, and CTest with `--repeat until-fail:3`. | Platform | Passed tests | Skipped tests | Failed tests | | --- | ---: | ---: | ---: | | Linux | 125 | 2 | 0 | | Windows | 117 | 11 | 0 | The focused `guest_posix_sem_init` and `guest_posix_sem_post` regressions passed on both platforms in all three repetitions. The skipped tests are GPU execution tests: two on Linux and eleven on Windows. The [initial Linux attempt](https://github.com/RomainROCH/AnyPS5/actions/runs/37088538109/attempts/1) failed only on `agc_driver_vopc_compare` (thread 1, compare 39), while both semaphore regressions passed. Windows succeeded on that attempt. Only Linux was rerun, without changing the commit or workflow, and the [second attempt](https://github.com/RomainROCH/AnyPS5/actions/runs/37088538109/attempts/2) succeeded. GPU and shader sources are unchanged by this PR; the base and the independent Unicode branch also passed their Linux workflows. The cause of the first GPU failure is unconfirmed. These are fork results on the specified commit. An upstream workflow requiring maintainer approval has not executed until approved. Both regressions failed before the correction. Coverage includes initial values above the maximum, successful initialization at the maximum, unchanged output and count on failure, repeated overflow, decrement and increment at the boundary, and normal empty/nonempty semaphore operations. This changes the POSIX semaphore implementation, independently of #315 (`sceKernelSignalSema`). All fixtures are synthetic. No game or homebrew title was tested; these results do not establish game compatibility. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stub added - [x] No investigation notes, reports or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
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!428
No description provided.