fix(libkernel): return ESRCH for a null semaphore handle #9005
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9005"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T09:25:38Z.
What
sceKernelWaitSema,sceKernelPollSema,sceKernelSignalSema,sceKernelCancelSemaandsceKernelDeleteSemathrewinvalid argumentfor a null handle. They now returnSCE_KERNEL_ERROR_ESRCH(0x80020003), as shadPS4 does for a handle it has not allocated, and asEventFlag.cppalready does for a null event flag. A non-positive count, a negative signal count and the other argument checks are unchanged.Earthion (PPSA28061) depends on this. Its init function (
0x44xxineboot.bin) starts a worker thread (entry0x48d0) before it callssceKernelCreateSema(&sem /* 0x1fc0a8 */, ..., 1, 0, 1, NULL)at0x4506. The worker loop at0x4a06callssceKernelWaitSema(sem, 1, NULL), prints an error on any non-zero result and loops back. When the worker gets there first, it passes a null handle and expects an error it can retry. Onmain, 1 of 14 clean starts aborted about 2 s in withsceKernelWaitSema: invalid argument. The abort never occurred under GDB, which slows the start.Recorded in
docs/dev/debt/libkernel.md: the code is from the PS4 reference and unverified on PS5. Handles are pointers, so a non-null handle that is not a live semaphore is still not detected.Tested
Linux 7.2.9 (Arch), Ryzen 9 7950X, GCC, Release.
guest_semaphoregains null-handle checks for all five calls, including that a timed wait leaves its timeout untouched and a cancel leaves its waiter count untouched. Withmain'sSemaphore.cpprestored and only the test kept, it aborts withsceKernelWaitSema: invalid argument. With this PR it passes.ctest -R 'guest_semaphore|semaphore|guest_kernel_errors|guest_umtx': 5/5.Earthion 01.006.000 on this PR (
2fc26b970f, Radeon RX 6650 XT, RADV Mesa 26.2.4): a 180 s run through the in-game menu and the intro cinematic, and 8 starts of 12 s each, with no stop. Onmain, the 1-in-14 abort above. The race is intermittent, so these runs cannot show the abort is gone. They do show the title still starts and plays with the change. Bring-up report: #9004.Independent check by @clairtonmichel (comment): clean build on Fedora with a Ryzen 7 9800X3D and Mesa 26.2.5. The kernel synchronization, error and semaphore tests, including
guest_semaphoreandguest_semaphore_trace, pass 33/33. No title run or negative control there.Independent check by @xXPBSXx (comment): at
2fc26b970fon WSL2 Ubuntu 24.04 (a virtualised kernel) with GCC 13.3.0,guest_semaphorepasses 3/3. WithSemaphore.cpprestored to the merge base and the new test kept, it aborts. No title run, macOS or Windows there.Independent check by @valenciana-nc (comment): on Windows 11 with WinLibs GCC 15.2.0, against
maina6dcea9279. With only this PR'sGuestSemaphore.cppregression added,guest_semaphoreaborts withsceKernelWaitSema: invalid argument. With2fc26b970fcherry-picked, the semaphore and kernel tests pass 5/5 andguest_semaphorepasses 25 runs in a row. Their full-suite failures, the threeagc_driver_sample_order*tests, match their control run on unchangedmain.tools/check_conventions.py --base origin/mainpasses. The PR overlap tool reports only adjacent lines indocs/dev/debt/libkernel.md, and #6044's test reorganisation, which movesGuestSemaphore.cpp.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by clairtonmichel on 2026-10-21T09:31:45Z.
Tested on AMD Ryzen 7 9800X3D and AMD Radeon RX 7900 XTX (Fedora Linux, Mesa 26.2.5):
guest_semaphore,guest_semaphore_trace,guest_kernel_sync, rwlocks, etc.): 100% passed successfully (33/33 green in 8.41s).ESRCH. Ready to merge!Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T09:46:02Z.
Linux data point for
2fc26b970f: WSL2 Ubuntu 24.04 (a virtualised kernel, not bare-metal Linux), GCC 13.3.0, Release,BUILD_TESTING=ON, PR head alone (not merged ontomain).ctest -R '^guest_semaphore$'passes 3 of 3.core/libs/prx/libkernel/Semaphore/src/Semaphore.cpprestored to the merge-base (new test kept): fails (Subprocess aborted).Not tested: macOS, Windows, a title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by valenciana-nc on 2026-10-21T23:29:35Z.
Independent Windows validation of this existing fix on current main
a6dcea9279.I first added only this PR's
GuestSemaphore.cppregression, leaving all runtime-library sources identical to main. Builtguest_semaphore_testsand ran:It aborts with exit
0xc0000409and the same reported Earthion failure:Then cherry-picked your original
2fc26b970fonto that main, preserving authorship (1f625e0f64onvalenciana-nc/AnyPS5, branchgame/earthion-startup). No extra implementation changes and no duplicate PR.cmake --build build --target libs relinker -j 6: passed, including patched runtime libraries.ctest --test-dir build -R 'guest_semaphore|semaphore|guest_kernel_errors|guest_umtx' --output-on-failure --parallel 4: 5/5 passed.guest_semaphorewith--repeat until-fail:25: 25 consecutive passes.-k 0: all buildable targets completed; unchangedImageArrayWindowPastLayerLimit.cpp:33still fails withrequested alignment '65536' exceeds object file maximum 8192.ctest --test-dir build --output-on-failure --parallel 4): 1,853 passed, 18 skipped, 3 failed, 1 not run; 324.55 s, exit 8. The missing test isagc_driver_image_array_window_past_layer_limit. The failures areagc_driver_sample_order,agc_driver_sample_order_grid_reference, andagc_driver_sample_order_recipe_depth_locations; all three diagnostics match an earlier control on the same machine with runtime-library sources identical to this same main. No new executed-test failure was observed.origin/mainandgit diff --checkpassed.Windows 11 x86-64 build 26300.9711, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON; the incidental GPU tests selected an NVIDIA GeForce RTX 4060 Laptop GPU. No Earthion, other title, console, Linux or macOS run in this validation. This independently reproduces the failing API call and verifies the fix on Windows; it is not a new gameplay result or PS5 error-code measurement.AI-assisted validation and report.
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T23:32:00Z.
@valenciana-nc thanks, that's a thorough check: the regression test failing on unchanged
mainwith the samesceKernelWaitSema: invalid argumenterror, then the fix passing 25 runs in a row on Windows. I've added it to the Tested section of the description.