sceKernelSignalSema throws on a zero count (Marvel's Wolverine) #2748

Closed
opened 2026-10-10 12:45:33 +00:00 by tv7 · 2 comments
tv7 commented 2026-10-10 12:45:33 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-10T12:45:33Z.


Title: Marvel's Wolverine (PPSA03671).
Build: Windows 11 Pro (10.0.26200), MinGW GCC 15.2.0 (WinLibs UCRT), Release, RTX 3070. Still present on main b69270dd9.

A few minutes in, the title ends with:

terminate called after throwing an instance of 'std::invalid_argument'
  what():  sceKernelSignalSema: invalid argument

A Job Lo 2 thread calls sceKernelSignalSema(sem, count) with a valid semaphore and a count computed as min(a, b) - c (ELF 0x3ccc1eb..0x3ccc20c), which is 0 here, and ignores the return value. sceKernelSignalSema throws for count <= 0.

Other implementations do not stop on a zero count: shadPS4 (semaphore.cpp, Signal) and Kyty (Kernel/Semaphore.cpp) treat it as a no-op that returns OK; fpPS4's older ps4_sema.pas returns EINVAL. Not checked on hardware.

Fix ready

I can't open PRs while intake is paused, so it is on my fork for anyone who can take it:
tv7/AnyPS5 fix/signal-sema-zero-count

  • Semaphore.cpp: count <= 0 becomes count < 0, so a zero count adds no tokens and returns SCE_OK. A null semaphore and a negative count still throw.
  • guest_kernel_errors signals 0 on a full and on an empty semaphore and checks that the count did not change. It fails on main with the exception above and passes with the fix; full ctest 706/706 on b5f5362d3, check_conventions passes.
  • With it, Wolverine gets past the signal and starts issuing draws (it later stops on draw and shader gaps that open PRs cover; other open PRs were merged locally for that run).

Investigated and written by Claude (AI assistant) on a contributor's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5791335509 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2748). Originally posted by [tv7](https://github.com/tv7) on 2026-10-10T12:45:33Z. --- **Title:** Marvel's Wolverine (PPSA03671). **Build:** Windows 11 Pro (10.0.26200), MinGW GCC 15.2.0 (WinLibs UCRT), Release, RTX 3070. Still present on `main` b69270dd9. A few minutes in, the title ends with: ``` terminate called after throwing an instance of 'std::invalid_argument' what(): sceKernelSignalSema: invalid argument ``` A `Job Lo 2` thread calls `sceKernelSignalSema(sem, count)` with a valid semaphore and a count computed as `min(a, b) - c` (ELF 0x3ccc1eb..0x3ccc20c), which is 0 here, and ignores the return value. `sceKernelSignalSema` throws for `count <= 0`. Other implementations do not stop on a zero count: shadPS4 ([`semaphore.cpp`](https://github.com/shadps4-emu/shadPS4/blob/06e813ff8c/src/core/libraries/kernel/threads/semaphore.cpp), `Signal`) and Kyty (`Kernel/Semaphore.cpp`) treat it as a no-op that returns OK; fpPS4's older `ps4_sema.pas` returns `EINVAL`. Not checked on hardware. ### Fix ready I can't open PRs while intake is paused, so it is on my fork for anyone who can take it: [tv7/AnyPS5 `fix/signal-sema-zero-count`](https://github.com/boykopovar/AnyPS5/compare/main...tv7:AnyPS5:fix/signal-sema-zero-count) - `Semaphore.cpp`: `count <= 0` becomes `count < 0`, so a zero count adds no tokens and returns `SCE_OK`. A null semaphore and a negative count still throw. - `guest_kernel_errors` signals 0 on a full and on an empty semaphore and checks that the count did not change. It fails on `main` with the exception above and passes with the fix; full `ctest` 706/706 on b5f5362d3, `check_conventions` passes. - With it, Wolverine gets past the signal and starts issuing draws (it later stops on draw and shader gaps that open PRs cover; other open PRs were merged locally for that run). *Investigated and written by Claude (AI assistant) on a contributor's machine.*
MarcZX10 commented 2026-10-10 12:57:41 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T12:57:41Z.


I refreshed Lexroid’s author-attributed sceKernelSignalSema change onto current upstream main (de5e541d) at 22964a33924fb5ed26609839409c5a627c6c3563. A zero count now succeeds without changing semaphore state; null semaphores and negative counts still follow the invalid-argument path.

Validation: Linux x86-64, GCC 12.2 Release; rebuilt libkernel.prx and guest_kernel_error_tests; guest_kernel_errors passed (1/1). Conventions and git diff --check pass. The issue’s Windows red/green and full-suite results are from TheTerr4 on an earlier base; they have not been rerun on this refreshed head.

The refreshed branch is codex/signal-sema-zero-count-2748. I have not opened an upstream PR because intake still requires 20 merged PRs and my count is 15.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6097739576 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2748#issuecomment-6097739576). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T12:57:41Z. --- I refreshed Lexroid’s author-attributed `sceKernelSignalSema` change onto current upstream `main` (`de5e541d`) at [`22964a33924fb5ed26609839409c5a627c6c3563`](https://github.com/MarcZX100/AnyPS5/commit/22964a33924fb5ed26609839409c5a627c6c3563). A zero count now succeeds without changing semaphore state; null semaphores and negative counts still follow the invalid-argument path. **Validation:** Linux x86-64, GCC 12.2 Release; rebuilt `libkernel.prx` and `guest_kernel_error_tests`; `guest_kernel_errors` passed (1/1). Conventions and `git diff --check` pass. The issue’s Windows red/green and full-suite results are from TheTerr4 on an earlier base; they have not been rerun on this refreshed head. The refreshed branch is [`codex/signal-sema-zero-count-2748`](https://github.com/MarcZX100/AnyPS5/tree/codex/signal-sema-zero-count-2748). I have not opened an upstream PR because intake still requires 20 merged PRs and my count is 15.
TheTerr4 commented 2026-10-10 13:51:17 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by TheTerr4 on 2026-10-10T13:51:17Z.


Verified the patch on Windows, the platform the issue was reported on.

Setup: Windows 11 Pro 10.0.26200, MinGW-w64 GCC 15.2.0 (WinLibs x86_64-ucrt-posix-seh, r7), Release, NVIDIA RTX 4080 SUPER. 935bddc1 cherry-picked onto main ba2a0a31 without conflicts.

  • The new guest_kernel_errors assertions fail on unmodified ba2a0a31 with std::invalid_argument: sceKernelSignalSema: invalid argument, and pass with the patch.
  • Full ctest: 702/709 pass. The 7 failures (agc_driver_flat_loads*, agc_driver_global_loads*, agc_driver_pixel_interlock) also fail on unpatched main on this machine, with the same errors, so the patch does not cause them. guest_semaphore passes.
  • tools/check_conventions.py and git diff --check pass.

I did not run Wolverine.

Verification run with AI assistance (Claude).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6098180651 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2748#issuecomment-6098180651). Originally posted by [TheTerr4](https://github.com/TheTerr4) on 2026-10-10T13:51:17Z. --- Verified the patch on Windows, the platform the issue was reported on. **Setup:** Windows 11 Pro 10.0.26200, MinGW-w64 GCC 15.2.0 (WinLibs `x86_64-ucrt-posix-seh`, r7), Release, NVIDIA RTX 4080 SUPER. `935bddc1` cherry-picked onto `main` `ba2a0a31` without conflicts. - The new `guest_kernel_errors` assertions fail on unmodified `ba2a0a31` with `std::invalid_argument: sceKernelSignalSema: invalid argument`, and pass with the patch. - Full `ctest`: 702/709 pass. The 7 failures (`agc_driver_flat_loads*`, `agc_driver_global_loads*`, `agc_driver_pixel_interlock`) also fail on unpatched `main` on this machine, with the same errors, so the patch does not cause them. `guest_semaphore` passes. - `tools/check_conventions.py` and `git diff --check` pass. I did not run Wolverine. *Verification run with AI assistance (Claude).*
Sign in to join this conversation.
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#2748
No description provided.