feat(libSceUlt): implement sceUltMutexDestroy and sceUltWaitingQueueResourcePoolDestroy #5422
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5422"
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 mariusyo07 on 2026-10-13T19:25:45Z.
What
Implements
sceUltMutexDestroyandsceUltWaitingQueueResourcePoolDestroyin libSceUlt.METAL GEAR SOLID: Peace Walker - Master Collection Version (PPSA18216) stops on
mainwhen relinkingmgspw.elf(#5268):sceUltMutexDestroyvalidates the mutex pointer, returnsULT_ERROR_BUSYif currently locked, and removes the mutex from the registered map.sceUltWaitingQueueResourcePoolDestroyvalidates the pool pointer, verifies that no registered mutexes, semaphores, or queue data pools are still referencing the waiting queue pool (returningULT_ERROR_BUSYif so), and erases the pool.UltMutexStateandUltSemaphoreStatenow track their associated_waitingPoolso that pool destruction safety is properly enforced.Tested
Export.cppandGuestUltThread.cppcompile cleanly.guest_ult_thread_underscoredcreateincore/libs/tests/GuestUltThread.cppexercisessceUltMutexDestroyandsceUltWaitingQueueResourcePoolDestroy(null handling, unknown pool, busy checks when resources are active, successful destruction, and subsequent state error on double destroy). The test fails to link onmainwithout the exports.python3 tools/check_conventions.py --base upstream/main: all checks passed.git diff --check: passes with no whitespace or style warnings.python3 tools/pr_overlap.py --branch feat/ult-mutex-pool-destroy: no overlap with open pull requests.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 repositoryImported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-13T19:25:51Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T19:26:22Z.
Progress report (
63fb0cd→ca9f4e4)📈 System libraries: 88.37% (+0.01%, +2 implemented functions)
✅ 2 implemented
sceUltMutexDestroysceUltWaitingQueueResourcePoolDestroyImported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T01:40:17Z.
Review: COMMENTED
sceUltWaitingQueueResourcePoolDestroyrefusing a pool still referenced by a mutex, semaphore or queue pool looks right.sceUltMutexDestroy's busy check has two problems:try_lockon a mutex the calling thread already owns is undefined forstd::mutex. A ULT program that destroys a mutex while it holds it (a bug, but exactly what theBUSYanswer is for) gets undefined behaviour instead ofULT_ERROR_BUSY. The same applies when the owner is another ULT scheduled on the same worker thread, which is the normal case for user-level threads.sceUltMutexLocklooks the state up undergMutex, releasesgMutex, then blocks instate->_mutex.lock(). A thread can be in that window, or blocked inlock()just after the owner unlocked.try_lockinDestroythen succeeds, the mutex is erased, and the waiter still acquires the orphanedstd::mutexafterwards. ItssceUltMutexUnlockreturnsULT_ERROR_STATEand leaves the mutex locked when the lastshared_ptrdestroys it, which is undefined behaviour too.Tracking ownership and waiters explicitly avoids both. For example, keep
owner(thread or ULT id) andwaiterscounters inUltMutexState, updated under its own lock inLock/Unlock, and haveDestroyreturnBUSYwhen either is set. Thestd::mutexcan then be a condition-variable-based lock, soDestroynever has to probe it.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:42:07Z.
Review: CHANGES_REQUESTED
Thanks, built and ran
guest_ult_thread_*on the PR merged onto main: green. Points to fix:sceUltWaitingQueueResourcePoolDestroy(Export.cpp:258) returnsULT_ERROR_BUSYwhile any idle mutex/semaphore/queue pool is bound to the pool. The PS5 reference we have (prosperhle_ult.cpp, from libSceUltor55417wcDkdisassembly, busy return at 0x473a) refuses only while a thread is currently waiting on a pool-backed object; bound but idle objects do not block destroy on hardware. A title that destroys the pool before its mutexes would get BUSY here and OK on a console. Please drop the bound-object check, or limit it to what can be observed as waiting (and note the rest under TechnicalDebt).sceUltMutexDestroy(Export.cpp:195):_mutexis astd::recursive_mutex, sotry_lockfrom the thread that holds it succeeds and Destroy returns OK instead of BUSY; a thread blocked insceUltMutexLockafter it releasedgMutexis also missed (see CnRJay's review). Track owner/waiter counts inUltMutexStateinstead of probing the lock. Note prosper only logs a destroy of a held mutex and returns OK, so check which result you want and say which reference it follows.sceUltMutexDestroyis not exercised (the test only destroys an unlocked mutex). Add a case with a held mutex and a waiter.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T13:16:50Z.
Review: APPROVED
Re-checked the new head: pool destroy refuses only with active waiters, the mutex tracks owner/lock count/waiters (no
try_lock), the test covers a held mutex plus a waiter, and TechnicalDebt notes the difference from prosper. Built and ranguest_ult_thread_*on the PR merged onto main (green; the test fails to link without the change); merging.Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-14T13:56:40Z.
Windows run: Windows 11, WinLibs GCC 15.2.0 r7, Release, this head (
ca9f4e47b) merged ontomainf3a826ba5.guest_ult*tests pass 5 of 5, and the fullctesthas 0 failures out of 1184.core/libs/prx/libSceUlt/Export.cpptaken back tomain,guest_ult_thread_testsno longer links (undefined reference to sceUltMutexDestroyandsceUltWaitingQueueResourcePoolDestroy), so its cases can't pass without the change.AI-assisted: yes (Claude Code Opus 5.5)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T14:01:47Z.
Re-checked the new head: pool destroy refuses only with active waiters, the mutex tracks owner/lock count/waiters (no
try_lock), the test covers a held mutex plus a waiter, and TechnicalDebt notes the difference from prosper. Built and ranguest_ult_thread_*on the PR merged onto main (green; the test fails to link without the change); merging.