feat(libSceLibcInternal): implement _Mtxinit, _Mtxlock, _Mtxunlock and _Mtxdst #13724

Merged
MaxLikesCode merged 2 commits from upstream-pr/13724 into main 2026-11-01 00:51:10 +00:00
MaxLikesCode commented 2026-10-31 02:45:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MaxLikesCode on 2026-10-31T02:45:23Z.


What

Implements the four libSceLibcInternal mutex helpers that were NotImplemented stubs under their NIDs: _Mtxinit (z7STeF6abuU), _Mtxlock (pE4Ot3CffW0), _Mtxunlock (cMwgSSmpE5o) and _Mtxdst (LaPaA6mYA38). Each name hashes to its NID, and ps5sdk's libSceLibcInternal stubs list all four.

  • int _Mtxinit(PthreadMutex* mutex, const char* name) creates a recursive mutex named SceLibcI_<name>, or SceLibcI when name is null, cut to 32 bytes. It returns 0 on success. It returns 1 when the attribute or the mutex cannot be created, or when the attribute cannot be destroyed afterwards.
  • _Mtxlock, _Mtxunlock and _Mtxdst return 1 when the pthread lock, unlock or destroy fails, and 0 otherwise.

shadPS4 and fpPS4 agree on the signatures, the name, the recursive type and every return value:

Lock, unlock and destroy go through libkernel's POSIX mutex calls, as in shadPS4. Both references set up a zeroed mutex on its first lock and return 0 when one is destroyed; the POSIX calls do the same. A null mutex pointer throws in libkernel, as it does for every other mutex call: shadPS4 dereferences it, fpPS4 returns EINVAL. AnyPS5's scePthreadMutexInit does not store names yet, so the SceLibcI_ name is passed on and then dropped.

No known title imports these. shadPS4 added them as callees of its own stdio code (shadPS4#4019).

Tested

Windows 11 Pro 10.0.26200, MinGW-W64 GCC 15.2.0 (winlibs r7), Release build of this branch on main 014c19ab19. It was then rebased onto 0cc02f7cde; the 4 new commits don't touch these files.

  • New guest_libc_internal_mtx passes 3 of 3 runs. It covers recursion, ownership checks from another thread, unlocking a released mutex, destroying twice, locking after destroy, a null name, a long name, and a zeroed mutex. On main it does not build, because the four functions only exist there as unnamed stubs.
  • Full build with -k 0 and the libs target: no errors, and no warnings from the new files. The patched libSceLibcInternal.prx exports z7STeF6abuU, pE4Ot3CffW0, cMwgSSmpE5o and LaPaA6mYA38.
  • Full ctest: 3162 of 3163 pass. The first run used the Windows Store Python, where import ctypes is denied, so its 135 Python tool and relinker tests were rerun with Anaconda's Python, the one the usual build uses. The one failure is guest_wide_formatting, which also fails on main on this machine (#10981, fix in #10987).
  • python3 tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py --branch feat/libcinternal-mtx found no overlapping lines or exports. It could not compare #5021, #11750 and #11751 automatically; checked by hand, they share only files and touch other lines.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5093766759 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13724). Originally posted by [MaxLikesCode](https://github.com/MaxLikesCode) on 2026-10-31T02:45:23Z. --- ### What Implements the four libSceLibcInternal mutex helpers that were `NotImplemented` stubs under their NIDs: `_Mtxinit` (`z7STeF6abuU`), `_Mtxlock` (`pE4Ot3CffW0`), `_Mtxunlock` (`cMwgSSmpE5o`) and `_Mtxdst` (`LaPaA6mYA38`). Each name hashes to its NID, and [ps5sdk's libSceLibcInternal stubs](https://github.com/ps5-payload-dev/sdk/blob/a7685ce8e97ce1f8a4f38253a41d54241c9124f1/sce_stubs/libSceLibcInternal.c#L1002-L1016) list all four. - `int _Mtxinit(PthreadMutex* mutex, const char* name)` creates a recursive mutex named `SceLibcI_<name>`, or `SceLibcI` when `name` is null, cut to 32 bytes. It returns 0 on success. It returns 1 when the attribute or the mutex cannot be created, or when the attribute cannot be destroyed afterwards. - `_Mtxlock`, `_Mtxunlock` and `_Mtxdst` return 1 when the pthread lock, unlock or destroy fails, and 0 otherwise. shadPS4 and fpPS4 agree on the signatures, the name, the recursive type and every return value: - shadPS4: [`libc_internal_threads.cpp` L10-L62](https://github.com/shadps4-emu/shadPS4/blob/860d73b7e99559106a3ffa3d3d69f0f9237e115e/src/core/libraries/libc_internal/libc_internal_threads.cpp#L10-L62) - fpPS4: [`ps4_mtx_internal.pas` L47-L99](https://github.com/red-prig/fpPS4/blob/04cefd43e6fddd1ab033e7980cd356d14c964905/src/libcinternal/ps4_mtx_internal.pas#L47-L99), registered in [`ps4_libscelibcinternal.pas` L445-L448](https://github.com/red-prig/fpPS4/blob/04cefd43e6fddd1ab033e7980cd356d14c964905/src/libcinternal/ps4_libscelibcinternal.pas#L445-L448) Lock, unlock and destroy go through libkernel's POSIX mutex calls, as in shadPS4. Both references set up a zeroed mutex on its first lock and return 0 when one is destroyed; the POSIX calls do the same. A null mutex pointer throws in libkernel, as it does for every other mutex call: shadPS4 dereferences it, fpPS4 returns `EINVAL`. AnyPS5's `scePthreadMutexInit` does not store names yet, so the `SceLibcI_` name is passed on and then dropped. No known title imports these. shadPS4 added them as callees of its own stdio code (shadPS4#4019). ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 Pro 10.0.26200, MinGW-W64 GCC 15.2.0 (winlibs r7), Release build of this branch on `main` 014c19ab19. It was then rebased onto 0cc02f7cde; the 4 new commits don't touch these files. - New `guest_libc_internal_mtx` passes 3 of 3 runs. It covers recursion, ownership checks from another thread, unlocking a released mutex, destroying twice, locking after destroy, a null name, a long name, and a zeroed mutex. On `main` it does not build, because the four functions only exist there as unnamed stubs. - Full build with `-k 0` and the `libs` target: no errors, and no warnings from the new files. The patched `libSceLibcInternal.prx` exports `z7STeF6abuU`, `pE4Ot3CffW0`, `cMwgSSmpE5o` and `LaPaA6mYA38`. - Full `ctest`: 3162 of 3163 pass. The first run used the Windows Store Python, where `import ctypes` is denied, so its 135 Python tool and relinker tests were rerun with Anaconda's Python, the one the usual build uses. The one failure is `guest_wide_formatting`, which also fails on `main` on this machine (#10981, fix in #10987). - `python3 tools/check_conventions.py --base origin/main` passes. `tools/pr_overlap.py --branch feat/libcinternal-mtx` found no overlapping lines or exports. It could not compare #5021, #11750 and #11751 automatically; checked by hand, they share only files and touch other lines. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-31 03:05:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T03:05:24Z.

Review: COMMENTED


Re-checked — exact-head test evidence needed

Source review of head 0e8a80443ad09690e144f3ae252475f026c74234 found no blocking defect, but the new guest_libc_internal_mtx test was not executed by the hosted Windows job.

The Windows log says no guest core/libs test sources changed; Linux and specialized test jobs were skipped. The PR description reports three passes and a broader CTest run, but does not identify the tested head SHA. The no-build review also confirmed the test is registered in the changed CMake file; its test-quality warning was a heuristic false positive. No local build or test was run.

Please provide the exact tested SHA and output for guest_libc_internal_mtx (or arrange for CI to select and run it). I will recheck the same evidence on the updated head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5720759520 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13724#pullrequestreview-5720759520). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T03:05:24Z. **Review:** COMMENTED --- # Re-checked — exact-head test evidence needed Source review of head `0e8a80443ad09690e144f3ae252475f026c74234` found no blocking defect, but the new `guest_libc_internal_mtx` test was not executed by the hosted Windows job. The Windows log says no guest core/libs test sources changed; Linux and specialized test jobs were skipped. The PR description reports three passes and a broader CTest run, but does not identify the tested head SHA. The no-build review also confirmed the test is registered in the changed CMake file; its test-quality warning was a heuristic false positive. No local build or test was run. Please provide the exact tested SHA and output for `guest_libc_internal_mtx` (or arrange for CI to select and run it). I will recheck the same evidence on the updated head.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!13724
No description provided.