fix(libkernel): fail scePthreadCondSignalto for a null or non-waiting thread as measured on a PS5 #11263
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11263"
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 orezraey on 2026-10-25T22:58:58Z.
What
scePthreadCondSignaltoandpthread_cond_signalto_npnow check the thread they are given, as a retail PS5 (firmware 13.60) does. A null thread returnsEINVAL. A thread that is not waiting on that condition variable returnsEPERM(1 for the POSIX form). Before, the thread was ignored and every call returned 0. Measured with a homebrew probe from a payload process; the source and console log are in this gist (pcondto).On the console, through both the sce and the POSIX form:
signalto(A). Returns 0. A wakes after about 110 ms with 0. B is not woken and times out at 600 ms.signalto(self)returns0x80020001(POSIX 1), with or without another waiter, and the other waiter still times out.0x80020016(22), and0x12345gives0x80020003(3).How this works here:
signaltolooks the target up there.EPERMhere instead ofESRCH, since handles are pointers and the record is only searched, never dereferenced.A code review noted the cost: every condition-variable wait now locks that mutex twice and allocates one map node. That is small next to the wait itself, and no performance claim is made.
Before and after
signalto(A)with A and B waitingsignaltoa thread that is not waiting0x80020001(POSIX 1)0x80020001(POSIX 1)0x80020016(22)0x80020016(22)0x12345as the thread0x80020003(3)0x80020001(1)Tested
Windows 11, WinLibs GCC 15.2, full build. The 88 tests matching
cond|pthread|thread|sema|mutexpass 3 times out of 3, withselect_testsexcluded: it is a Python tool test that fails here for an unrelated temporary-directory reason.guest_cond_timedwaitnow checks thatsignalto(self)with nobody waiting returns 1 (POSIX) and0x80020001(sce), and a null thread returns 22 and0x80020016. Its existing targeted signal to a waiting thread still returns 0 and wakes it.tools/check_conventions.pypasses.Those runs were at head
9797a214b0onmain49d1f9b07e.Head
d06b45fba5addsSignalToEveryRound, which repeats the targeted signal 200 times with a normal mutex and 200 times with a recursive one locked twice: the main thread waits with a 2 spthread_cond_reltimedwait_np, and a helper locks the mutex, setsreadyand callssignalto(main), which must return 0, and every wait must return 0 before its timeout. WithNotifyAllremoved fromscePthreadCondSignaltothe test fails (timeout), so it catches a lost wakeup.guest_cond_timedwaitandguest_cond_recursive_mutexpass 3 times out of 3 on Windows 11 (WinLibs GCC 15.2) and on Linux (WSL), andtools/check_conventions.pypasses.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)signaltoentry; merge order onlyImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T23:02:35Z.
Review: CHANGES_REQUESTED
The console evidence and return-code mapping are useful, but I found a blocking lost-wakeup race in the waiter registry. I posted the detailed finding inline on the registration path; please synchronize the registry state with the transition into the actual condition wait and cover the race with a regression before this is ready to merge.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T23:46:15Z.
Review: APPROVED
Re-reviewed exact head
d06b45fba5eae8a325cc8b94facc7a625762283dand the author’s explanation. I withdraw my earlier lost-wakeup blocker: when the signaler follows the condition-variable mutex protocol, that mutex prevents it from running in the registration-to-block interval; signaling without the mutex has the same race as ordinary condition signaling. The focused stress tests and the documented limitation are consistent with that model. The overlap with #10725 is limited to the debt document; I left a coordination comment because the current checklist saysDepends on: none, but I do not consider that a code blocker. Hosted policy checks pass and product jobs are skipped; the Windows/Linux focused results are author-reported. No blocking correctness finding remains.