fix(libScePsml): fail MFSR init and shared-resource limits as a base console does #11140

Merged
akkadbakkad89 merged 2 commits from upstream-pr/11140 into main 2026-10-26 16:42:59 +00:00
akkadbakkad89 commented 2026-10-25 19:29:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-25T19:29:00Z.


What

Makes scePsmlMfsrInit and the MFSR1 shared-resources path answer as a base (non-Trinity) console does, verified against the real Sony libScePsml.sprx that ships inside PPSA20397's fakelib directory (Sony build path W:/Build/J03828141/.../libScePsml.prx — the name is misleading, it is the genuine firmware module).

  • scePsmlMfsrInit returns 0x8A810012 before touching the initialized flag when sceKernelIsTrinityMode() is 0 — the same gate scePsmlMfsr2Init already models — and throws NotImplemented if Trinity mode is ever reported, instead of fabricating the real init path.
  • GetSharedResourcesInitRequirement / CreateSharedResources return 0x8A81000D for disallowed resource types (the binary gates types 1 and 2 behind a console feature flag set during init).
  • CreateSharedResources returns 0x8A810015 while a shared-resources object already exists (the binary keeps a single-instance refcount).
  • GetMipmapBias's log2f(dimension / inputWidth) - 1.0f and GetDispatchMfsrPacketSizeInDwords's 0x600 are confirmed against the same binary.
  • Debt file updated: the 900/1000/1100/1300 dispatch-packet routines stay NotImplemented, and on this console they are unreachable by design — the firmware's shared writer behind the 0x158-byte template rotates eight ring slots and emits AGC packets; those routines are not understood, and until then the init gate keeps callers on the correct 0x8A810001 path.

Tested

Windows 11 / MinGW: guest_psml_tests rewritten for the console contract — scePsmlMfsrInit fails with 0x8A810012 (twice) and every MFSR1 call keeps returning 0x8A810001; the MFSR2 unsupported-console path is unchanged. Passes.

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
  • 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5007936532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11140). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-25T19:29:00Z. --- ### What Makes `scePsmlMfsrInit` and the MFSR1 shared-resources path answer as a base (non-Trinity) console does, verified against the real Sony `libScePsml.sprx` that ships inside PPSA20397's `fakelib` directory (Sony build path `W:/Build/J03828141/.../libScePsml.prx` — the name is misleading, it is the genuine firmware module). - `scePsmlMfsrInit` returns `0x8A810012` before touching the initialized flag when `sceKernelIsTrinityMode()` is 0 — the same gate `scePsmlMfsr2Init` already models — and throws `NotImplemented` if Trinity mode is ever reported, instead of fabricating the real init path. - `GetSharedResourcesInitRequirement` / `CreateSharedResources` return `0x8A81000D` for disallowed resource types (the binary gates types 1 and 2 behind a console feature flag set during init). - `CreateSharedResources` returns `0x8A810015` while a shared-resources object already exists (the binary keeps a single-instance refcount). - `GetMipmapBias`'s `log2f(dimension / inputWidth) - 1.0f` and `GetDispatchMfsrPacketSizeInDwords`'s `0x600` are confirmed against the same binary. - Debt file updated: the 900/1000/1100/1300 dispatch-packet routines stay `NotImplemented`, and on this console they are unreachable by design — the firmware's shared writer behind the 0x158-byte template rotates eight ring slots and emits AGC packets; those routines are not understood, and until then the init gate keeps callers on the correct `0x8A810001` path. ### Tested Windows 11 / MinGW: `guest_psml_tests` rewritten for the console contract — `scePsmlMfsrInit` fails with `0x8A810012` (twice) and every MFSR1 call keeps returning `0x8A810001`; the MFSR2 unsupported-console path is unchanged. Passes. ### Checklist - [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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [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
MarcZX10 commented 2026-10-25 19:41:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T19:41:20Z.

Review: CHANGES_REQUESTED


Reviewed exact head fe38bc485d79315e73d8307e6f340043504b4507. The base-console scePsmlMfsrInit gate correctly returns before changing g_mfsrInitialized, and the local conventions and diff checks pass. The PR reports the Windows guest_psml_tests run; the current upstream product build/test jobs are skipped by repository policy.

I found a race in the new single-instance guard in scePsmlMfsrCreateSharedResources: it checks g_mfsrObjects while holding g_mfsrMutex, releases the lock, then later calls CreateMfsrObject, which reacquires the mutex to insert. Two concurrent calls can both observe no existing shared-resources object and both create one, contrary to the single-instance behavior this change is modeling. Please make the check and insertion atomic (or otherwise establish serialization for this API) and add focused coverage for competing creates where the initialized state can be exercised.

The current test change only exercises the base-console path, where init never succeeds, so it cannot catch this race in the new post-init branch. I am requesting changes for that invariant gap.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644918009 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11140#pullrequestreview-5644918009). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T19:41:20Z. **Review:** CHANGES_REQUESTED --- Reviewed exact head `fe38bc485d79315e73d8307e6f340043504b4507`. The base-console `scePsmlMfsrInit` gate correctly returns before changing `g_mfsrInitialized`, and the local conventions and diff checks pass. The PR reports the Windows `guest_psml_tests` run; the current upstream product build/test jobs are skipped by repository policy. I found a race in the new single-instance guard in `scePsmlMfsrCreateSharedResources`: it checks `g_mfsrObjects` while holding `g_mfsrMutex`, releases the lock, then later calls `CreateMfsrObject`, which reacquires the mutex to insert. Two concurrent calls can both observe no existing shared-resources object and both create one, contrary to the single-instance behavior this change is modeling. Please make the check and insertion atomic (or otherwise establish serialization for this API) and add focused coverage for competing creates where the initialized state can be exercised. The current test change only exercises the base-console path, where init never succeeds, so it cannot catch this race in the new post-init branch. I am requesting changes for that invariant gap.
MarcZX10 commented 2026-10-25 20:25:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T20:25:42Z.

Review: APPROVED


Re-reviewed head 44f2c7f607e75eb5127fea325f73dec97b0949b8. The single-instance scan and map insertion now share one g_mfsrMutex critical section, closing the TOCTOU window from my earlier review. The added concurrent test covers the reachable uninitialized base-console result and preserves out-handles. I confirmed the PR head has no assignment that can set g_mfsrInitialized true: scePsmlMfsrInit returns unsupported on the modeled console and throws before changing state on Trinity, so the initialized busy branch cannot currently be exercised by a guest test. I therefore do not require an impossible post-init fixture. Local conventions, diff check, and syntax-only compiles of Export.cpp and GuestPsml.cpp pass. The Windows focused test is author-reported; product CI jobs are skipped by policy.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645067151 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11140#pullrequestreview-5645067151). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T20:25:42Z. **Review:** APPROVED --- Re-reviewed head `44f2c7f607e75eb5127fea325f73dec97b0949b8`. The single-instance scan and map insertion now share one `g_mfsrMutex` critical section, closing the TOCTOU window from my earlier review. The added concurrent test covers the reachable uninitialized base-console result and preserves out-handles. I confirmed the PR head has no assignment that can set `g_mfsrInitialized` true: `scePsmlMfsrInit` returns unsupported on the modeled console and throws before changing state on Trinity, so the initialized busy branch cannot currently be exercised by a guest test. I therefore do not require an impossible post-init fixture. Local conventions, diff check, and syntax-only compiles of `Export.cpp` and `GuestPsml.cpp` pass. The Windows focused test is author-reported; product CI jobs are skipped by policy.
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!11140
No description provided.