feat(libSceLibcInternal): implement std mutex object lifecycle and locking #19602
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19602"
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 fogydes on 2026-11-13T15:42:27Z.
What
Implement all six unversioned std::_Mutex constructor/destructor/lock/unlock exports using the existing guest heap and mutex primitives. Each constructor allocates one eight-byte mutex slot, publishes it into the one-pointer object, and initializes it with the SDK's C++ name. Destruction destroys the mutex, reloads the object's slot, and deletes nonnull storage without clearing the object. Lock/unlock forward the stored slot and ignore primitive status as the SDK does.
Destruction explicitly catches escaping exceptions and invokes guest std::terminate. SDK 10.00's destructor has that termination landing pad; compiler-only noexcept was insufficient with the current guest personality, which continued through a GCC no-call-site region. The focused test registers a guest terminate handler and fails if an exception propagates. The general personality gap is recorded in libc debt; no global exception implementation is changed.
Clean-room evidence: readable libc.prx, SDK 10.00, C1/C2 at 0xb8080, D1/D2 at 0xb80b0 and termination 0xb80d5, lock0xb80e0, unlock0xb80f0; allocation 0xb808e, publication 0xb809d, initialization 0xb80a0; destroy 0xb80bc, slot reload 0xb80c1, delete 0xb80c9. target/include/yvals.h:1918-1933 supplies the one-pointer class declaration. No reference binaries/extracts are attached/linked and no console measurement is claimed.
Unreadable object/slot and unwritable constructor destinations throw as documented host-safety policy; failed destination publication frees the allocation. Forged handles, concurrent slot mutation and firmware fault behavior retain native/unverified preconditions.
Based on main
4c0998e1a81. Remaining gaps and removed stub-inventory entries usedocs/dev/debt/changes/libSceLibcInternal-mutex-objects.md; canonical debt files are unchanged. No new third-party code is added.Tested
Windows 11 / WinLibs GCC 15.2 Release at
b0ffc06914eb4abee710a9806b561b788d821b4a: rebuilt affected runtime libraries and test targets; 5/5 CTests passed (guest_mutex_object,guest_mutex_object_termination,guest_libc_internal_mtx,guest_freebsd_clocks,guest_appcontent). The termination test requires the guest terminate-handler marker. The object tests cover layout, recursive ownership, blocked waiters, application allocation/deallocation and invalid memory. Current conventions, debt-fragment validation, whitespace and merge-tree checks passed.The earlier shared AppContent CI failure was independently reproduced using CI-main source; main now includes its upstream #20058 revert. The former clock abort did not reproduce in five consecutive local runs. The mutex implementation and test blobs are unchanged by these main merges. New hosted checks are pending.
Original export measurement at main
228330220ba: 424 → 430 implemented, 706 → 700 TODO, 1,130 total; all six NIDs were already present as throwing exports. These are historical counts, not a current-main recount. Original SDK-backed runtime validation and manual overlap inspection found no competing mutex implementation or behavioral dependency; automated overlap had stale heads and did not establish globally clean mergeability. No console, title, GPU or performance claim.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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T10:08:58Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: handle mutex initialization failure before leaving the object constructed.
What I ran
Reviewed head
3ae4623c7da44462feab38c7c4fd62f2de3ee0ea. Read the prepared description, commits, diff and manifest, then usedrepo_read.pyto inspect the changed implementation and the allocator and mutex primitives it calls. No build or tests were run in this review.Results
Findings
Blocking
core/libs/prx/libSceLibcInternal/MutexObject.cpp:38: construction ignores_Mtxinit_nid_postfix's status. The existing primitive returns nonzero when attribute setup or mutex initialization fails. In that case the constructor returns successfully with published storage that may not hold an initialized mutex, so later lock, unlock, or destruction operates on invalid state. Check the result and clean up the storage/object consistently before reporting construction failure.Non-blocking
None.
Not verified
No build, CTest, CI, console execution, or firmware behavior was verified. Read all files listed as
reviewedin the manifest, including the changed source, tests, headers, CMake configuration, export inventory edits, and debt note.files.jsonwas not available in the prepared review resources, so excluded files are not verified.To get this to a good state
Handle
_Mtxinit_nid_postfixfailure and add coverage for that failure path; then rerun the focused mutex object tests on the updated head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T14:48:43Z.
Review: COMMENTED
Reviewed — comments
Nothing blocks this based on the code inspected; the points below should be verified before relying on the new wrappers.
What I ran
Reviewed head
ceaac7409184ac3082fb73c2b239fc460561538d. No commands or tests were run. The author reports Windows 11 / WinLibs GCC 15.2 CTest results in the PR description; those were not independently run here.Results
Findings
Blocking
None verified.
Non-blocking
MutexObject.cpp:38ignores_Mtxinit_nid_postfix’s status, then leaves the object pointing at the allocated slot. The existing primitive returns failure when mutex attribute setup or initialization fails. Consider handling that result and releasing the slot so the object is not left with an uninitialized mutex.MutexObject.cpp:62-87do not showAPS5_EXPORTregistrations. Existing inventory-based exports use that macro to publish guest-visible NIDs. Verify that these wrappers are exported through another mechanism; the checked source did not establish this.Not verified
No tests were run. No physical-console or firmware validation was performed. The following changed files were listed in
manifest.jsonbut not read at the head:core/libs/prx/libSceLibcInternal/CMakeLists.txt,core/libs/prx/libSceLibcInternal/InventoryExports.cpp,core/libs/prx/libSceLibcInternal/InventoryExports6.cpp,core/libs/prx/libSceLibcInternal/include/InventoryExports.hpp,core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp,core/libs/prx/libSceLibcInternal/include/MutexObject.hpp, andcore/libs/prx/libSceLibcInternal/libSceLibcInternal.hpp. I also did not inspect the full export-generation and packaging path, so symbol publication is not verified. The author’s reported test results and clean-room SDK observations were not independently checked.Files read:
review/description.md,review/commits.md,review/manifest.json,review/diff.patch,core/libs/prx/libSceLibcInternal/MutexObject.cpp,core/libs/prx/libSceLibcInternal/Mutex.cpp,core/libs/prx/libSceLibcInternal/include/Api.hpp,core/libs/prx/libSceLibcInternal/Export.cpp(lines 1–50),core/libs/prx/libc/src/StdioExtras.cpp,core/libs/prx/libc/src/General.cpp,core/libs/prx/libc/include/General.hpp,core/libs/prx/libc/include/general/ExportMacros.hpp,core/libs/prx/libkernel/Pthread/include/Mutex.hpp,core/libs/prx/libkernel/Pthread/src/Mutex.cpp,core/libs/SceTypes.hpp,core/libs/tests/GuestMutexObject.cpp, anddocs/dev/debt/changes/libSceLibcInternal-mutex-objects.md. No files were excluded by rule according to the supplied manifest.To get this to a good state
Nothing is required. Optional points: handle mutex initialization failure, and confirm that all six wrapper symbols are published in the guest export table.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T12:46:39Z.
Review: COMMENTED
Reviewed — comments
The code inspected implements the described mutex wrappers; I did not run the reported checks or verify every changed file, so a formal decision is not justified.
What I ran
971b982b84a34f7d1b930d035be4f7643258fd04using the pinnedrepo_read.pyreader.Results
Findings
Blocking
None verified in the inspected code.
Non-blocking
None.
Not verified
I read
description.md,commits.md,manifest.json, anddiff.patch; repository files read:core/libs/prx/libSceLibcInternal/MutexObject.cpp,core/libs/prx/libSceLibcInternal/CMakeLists.txt,core/libs/prx/libSceLibcInternal/InventoryExports6.cpp,core/libs/prx/libSceLibcInternal/include/MutexObject.hpp,core/libs/prx/libSceLibcInternal/libSceLibcInternal.hpp,core/libs/prx/libSceLibcInternal/Mutex.cpp,core/libs/prx/libc/src/StdioExtras.cpp,core/libs/prx/libkernel/Pthread/include/Mutex.hpp, andcore/libs/tests/GuestMutexObject.cpp. The remaining changed files listed inmanifest.jsonwere not read in full; behavior on console and the author-reported test runs were not verified.To get this to a good state
Nothing is required. Optional: complete the review of the remaining changed files and run the reported checks on this head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T11:10:24Z.
Review: COMMENTED
Reviewed — no blocking findings
No blocking defect was verified in the implementation paths inspected, but the review is incomplete because several changed files were not read in full.
What I ran
Reviewed head
a43d24d800033677263eb6e89cb2f1e0d59acaf3. I used the prepared diff and repository reader; I ran no build or tests. The author reports Windows 11 / WinLibs GCC 15.2 tests in the PR description; I did not run them.Results
Findings
Blocking
None verified in the code inspected.
Non-blocking
None.
Not verified
I read the review description, commits, manifest, and diff; the changed mutex implementation and header, its test, the relevant CMake section, mutex primitive implementation, and relevant portions of the export files and API declarations. I did not read the full text of
InventoryExports.cpp,include/InventoryExports.hpp,include/InventoryExports6.hpp,libSceLibcInternal.hpp, ordocs/dev/debt/changes/libSceLibcInternal-mutex-objects.md. The export source/header changes were visible in the prepared diff, but their full file contents were not reviewed. I did not independently verify SDK binary claims, run tests, or check console behavior.To get this to a good state
Nothing is required. Optional: complete review of the unread changed files before making a formal approval decision.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T12:51:16Z.
Review: COMMENTED
Reviewed — comments
The review covered all ten changed files at head
42cebf894180a166017a5f2e9d17d5697ea63870; no verified blocking defect was found, but one lifecycle edge case needs clarification or coverage before I can recommend approval.What I ran
Results
Findings
Blocking
None.
Non-blocking
Destroy_nid_no_patchreads the stored pointer and checks its memory before entering thetryblock inDestroyStorage_nid_no_patch(core/libs/prx/libSceLibcInternal/MutexObject.cpp:52). If either guest read throws, the destructor propagates the exception instead of calling gueststd::terminate. The tested termination case only throws during the later release callback, after entering thetryblock. Consider covering unreadable object/storage errors under the destructor's termination policy, or clarify that termination is guaranteed only for errors during destroy and release.Not verified
To get this to a good state
Nothing is required. Optional: align destructor termination handling with the stated policy for exceptions from its initial guest reads, and add a focused test if that behavior is intended.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T02:58:31Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the available evidence supports the implementation, though tests were not run in this review.
What I ran
Reviewed head
07fa83644830000912d977e59d35373287e7e36busing the prepared diff andrepo_read.pyreader. No commands or tests were run; the reader interface provides source access only.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Tests, builds, and runtime behavior were not independently verified. Reviewed all changed files listed in the manifest, including the new implementation, test, and debt note; no changed files were excluded by the manifest. The report's SDK binary analysis and console behavior were not independently confirmed.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T03:03:33Z.
Review: COMMENTED
Architecture findings (2)
Advisory architecture findings (2)
01a39512-79bb-481e-8a71-9e5653efeb72Reviewing files that changed from the base of the PR and between
5ed18b5d5aand07fa836448.core/libs/prx/libSceLibcInternal/CMakeLists.txtcore/libs/prx/libSceLibcInternal/InventoryExports.cppcore/libs/prx/libSceLibcInternal/InventoryExports6.cppcore/libs/prx/libSceLibcInternal/MutexObject.cppcore/libs/prx/libSceLibcInternal/include/InventoryExports.hppcore/libs/prx/libSceLibcInternal/include/InventoryExports6.hppcore/libs/prx/libSceLibcInternal/include/MutexObject.hppcore/libs/prx/libSceLibcInternal/libSceLibcInternal.hppcore/libs/tests/GuestMutexObject.cppdocs/dev/debt/changes/libSceLibcInternal-mutex-objects.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.