Repository navigation
Conversation
…a null handle A payload process on firmware 11.60 returns 4 for the handle of a destroyed mutex and 0 for a pointer to a null handle; both threw here. The test expects both, so it fails until the next commit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… a pointer to a null handle Both threw here. A pointer to a null handle gets a plain mutex that the call locks; a handle whose tag is not a live mutex's returns _Thrd_error. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…process The entry now says what a payload process on firmware 11.60 returned for a destroyed handle, a pointer to a null handle and a null pointer, and what this does for each. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…same handle Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…_Mtx_trylock returns 4 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…andle Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e-exchange Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…k-null-and-destroyed-handle
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… _Mtx_trylock Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…t page Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… publishes a mutex Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix Merge Risk:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
_Mtx_trylockthrew for the handle of a destroyed mutex and for a pointer to a null handle. On a PS5 it returns 4 (_Thrd_error) for the destroyed mutex's stale handle and 0 for a pointer to a null handle (cases 1.9 and 4.2, lines 11 and 22 of the raw output). A null pointer makes the console fault (case 4.1, line 21)._Mtx_destroynow leaves the address of a static marker in the handle, and_Mtx_trylockreturns 4 for the marker and for a handle whose tag is not a live mutex's, which is what the console returned for the destroyed one. For a pointer to a null handle in writable memory it creates a plain mutex, stores it and locks it, returning 0; a null pointer and a null handle slot that cannot be written still throw, as onmain. The handle is read with__atomic_load_nnext to the compare-exchange that publishes the new mutex (Threads.cpp,ResolveMutexand_Mtx_trylock), and the slot is opened for a guest write withGuestArena::HostWritebefore the writability check, asGuestCopyOutdoes for a write-watched guest page. The tests pin both answers, a null handle in a read-only slot and a null handle in a write-watched page, and the entry for_Mtx_trylockis in the fragmentdocs/dev/debt/changes/fix-libc-mtx-trylock-null-and-destroyed-handle.md(the entry is 964 characters with its list marker);docs/dev/debt/libc.mdis not changed.That a pointer to a null handle gets a mutex made on demand is a guess: the probe measured only the return value 0, not what the console does with the handle. The tests pin the real sequence
_Mtx_init,_Mtx_destroy,_Mtx_trylockon one handle and, with zeroed storage, a handle that is not a live mutex; a handle that points to freed memory is not tested. That_Mtx_destroyleaves a marker is an implementation choice that gives the measured return value 4: what the console leaves in the handle after the destroy is not measured. PPSA06465 imports_Mtx_trylockfrom the system library at one call site (a registry read, not a run); 14 more titles import it but ship their ownlibc.prx. Whether PPSA06465 reaches the call with a destroyed or null handle is not shown. A title process was not measured.Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-11 at 06:00 UTC. A title process may differ. The cases are 1.2 to 4.2, lines 4 to 22 of the raw output in the first comment.mainbefore_Mtx_trylock(&handle)of a fresh plain mutex_Mtx_trylock(&handle)of a plain mutex the caller owns_Thrd_busy) (line 5)_Mtx_trylock(&handle)of a plain mutex held by another thread_Mtx_trylock(&handle)after_Mtx_destroy(stale handle)_Mtx_initand_Mtx_destroyof the same handle, and with zeroed storage)_Mtx_trylock(&handle)withhandlenull_Mtx_trylock(NULL)SIGSEGV(line 21)On
maince111157b8b3, Linux (WSL, Release), built for the targetsguest_libc_static_importsandguest_libc_threadswithninjareturning 0 for each commit: with only the test commitguest_libc_static_importsaborts (1 of the 4 mutex tests fails), and with the fix and with the documentation commit all four pass in 3 of 3 runs each.tools/check_conventions.pypasses on each of the three commits with no warning (the changed entry was 976 characters). The probe source and its raw output are in the first comment. On Windows 10 Pro 10.0.19045 (WinLibs GCC, Ninja, Release), on 2026-11-16 between 20:23 and 20:33 UTC, the build of the test commit4a3d0cab1f1calone finished withninjareturning 0 and 3 of the 9 mutex, condition variable, pad and forwarding tests failed (guest_libc_threads,guest_libc_static_imports,guest_libc_mutex_init_with_name), and the build of82402f2dc3b2finished withninjareturning 0 and all 9 passed. The Linux runs above are from before the destroyed-handle commits. The three review follow-ups were built and run on Windows (WinLibs MinGW-W64, Ninja, Release; one machine, the logs are kept locally and are not attached) on 2026-12-02: the atomic loads (ae3502724c3, 10 lines added and 5 removed inThreads.cpp) have no red arm, because on x86 the missing atomics cannot be seen without a thread sanitizer;guest_libc_threads_tests,guest_libc_static_imports_testsandguest_libc_mutex_init_with_name_testswere built (ninja returning 0) and each returned 0 in one run, at about 03:11 UTC. For the read-only slot, the test commit0372622ede6alone ona575ba6a9ad5madeguest_libc_threads_testscrash with an unhandled exception 0xc0000005 (a write) at about 05:00 UTC, and with the fix commitac188a9baf0it returned 0 in 3 of 3 runs, and the other two tests returned 0, at about 05:01 UTC. For the write-watched page, the test commit77d67f778d8alone onac188a9baf0ended instd::invalid_argument_Mtx_trylock: null mutex handle, then terminate and abort, at about 06:31 UTC, and with the fix commit378dd39ab94, the head of this branch,guest_libc_threads_testsreturned 0 in 3 of 3 runs and the other two tests returned 0, at about 06:32 UTC. Against a freshmainfc294cb (fetched on 2026-12-02):tools/debt_fold.py --checkexits with 0;tools/check_conventions.py --base upstream/mainreports no findings;git merge-treeof the head with thatmainis clean. Not tested: Linux for the destroyed-handle commits and the follow-ups, macOS, the CI runner, a title process, any other firmware, the recursive and timed mutex types, a handle that points to freed memory, and what the console does with a null handle or leaves in a destroyed handle after the call.Overlap: counted on 2026-12-02 from the 2357 open pull requests (file lists from the GitHub API, the pull requests with 100 or more files read in full through the files API; the 1386 pull requests that change
core/libs/prx/libc/src/Threads.cpp,core/libs/tests/GuestLibcMutexInitWithName.cpp,core/libs/tests/GuestLibcStaticImports.cpp,core/libs/tests/GuestLibcThreads.cpp, a file underdocs/dev/debt/or the fragment path, or have mtx or mutex in the title or branch name, had their patches of the files underdocs/dev/debt/and of the files with libc, Threads or GuestLibc in the path searched for_Mtx_trylock,_Mtx_destroy,destroyedMutexMarkerand the fragment name, from 08:08 to 09:17 UTC,mainatfc294cbbb539at the start). No other open pull request changes the fragmentdocs/dev/debt/changes/fix-libc-mtx-trylock-null-and-destroyed-handle.md, and no patch of a debt file contains a searched name, so none changes the entry for_Mtx_trylock. Of the pull requests that share a file, boykopovar#27937 (feat(libs): general system-library fixes from PS4 title bring-up,Threads.cpp) and boykopovar#26252 and boykopovar#26224 (GuestLibcStaticImports.cpp) merge cleanly with this head, and boykopovar#19434 (feat(libSceLibcInternal): forward the firmware libc-internal export surface) declares_Mtx_destroy_nid_disambig1_nid_postfixinForwards.cppand merges cleanly; boykopovar#12315 and boykopovar#1835 changeThreads.cppand already conflict withmainalone in as many files, so not because of this change. The merges of this head with each of the 52 pull requests that change one of the files named or have a searched name were made withgit merge-treefrom 08:08 to 09:17 UTC: 36 are clean; the other 16 already conflict withmainalone, in at least as many files as with this head, so none of them conflicts because of this change. The count was repeated for the 147 pull requests that were opened or updated since 08:08 UTC (of the 2359 open pull requests, from 09:36 to 09:41 UTC; 99 of them were patch-scanned for the same names): the only one that shares a file is boykopovar#12849 (libc.md), which already conflicts withmainalone in 2 files; no new hit. Two commits have been merged tomainsince68d65e6b14a(themainthat was merged into this branch;mainatfc294cbbb539); neither changed one of the files named, and a merge of this head intomainatfc294cbbb539was checked at 09:42 UTC and is clean. This pull request does not depend on any of them (Depends on: none).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)Summary by CodeRabbit