fix(libSceHmd2): check the mirroring option before the reprojection pipeline #25756

Closed
edubox wants to merge 1 commit from upstream-pr/25756 into main
edubox commented 2026-11-22 16:43:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-11-22T16:43:47Z.


What

sceHmd2ReprojectionSetMirroringOption threw on every option once a reprojection session existed, including the ones the firmware rejects before it ever reaches the pipeline. main already answers 0x8A72000B (REPROJECTION_NOT_INITIALIZED) without a session; this adds the option check the 13.40 wrapper performs next:

  • a null or unreadable 32-byte option answers 0x8A720008 (PARAMETER_NULL);
  • a mode other than 0 or 1, or any of the seven reserved words nonzero, answers 0x8A720009 (PARAMETER_INVALID);
  • a valid option then reaches the reprojection pipeline, which still throws because the host has no model for it.

Evidence is the 13.40 libSceHmd2.sprx: the wrapper compares mode and each reserved word against zero and returns those codes before handing the call on. Not measured on a console beyond the module body.

Hmd2::MirroringOption is the 32-byte layout include/Api.hpp already pins (mode at 0, seven reserved words). The read goes through GuestCopyIn_nid_no_patch with errno preserved, as the other argument-taking exports in this file do.

Tested

Linux x86-64 (CachyOS), GCC 16.2.1, Release, BUILD_TESTING=ON, on main e3f556c718:

  • guest_hmd2, guest_hmd2_gaze and guest_hmd2_gaze_args: 3/3 pass.
  • Negative control: with Export.cpp at main and the new assertions kept, guest_hmd2 aborts with sceHmd2ReprojectionSetMirroringOption not implemented; restoring the change makes it pass. The new cases cover a null pointer, an unmapped pointer, mode = 2, each of the seven reserved words set on its own, and both valid modes still throwing inside a session.
  • tools/check_conventions.py --base origin/main and tools/debt_fold.py --check are clean.
  • tools/pr_overlap.py --branch fix/hmd2-mirroring-option-checks: no shared exports; it lists one open pull request that also changes Export.cpp and cannot be compared because it conflicts with main (it copies other Hmd2 structures through the guest helpers, not this export).

Not run: Windows, a console, and a title that opens a reprojection session.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5441091832 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25756). Originally posted by [edubox](https://github.com/edubox) on 2026-11-22T16:43:47Z. --- ### What `sceHmd2ReprojectionSetMirroringOption` threw on every option once a reprojection session existed, including the ones the firmware rejects before it ever reaches the pipeline. `main` already answers `0x8A72000B` (`REPROJECTION_NOT_INITIALIZED`) without a session; this adds the option check the 13.40 wrapper performs next: - a null or unreadable 32-byte option answers `0x8A720008` (`PARAMETER_NULL`); - a `mode` other than 0 or 1, or any of the seven `reserved` words nonzero, answers `0x8A720009` (`PARAMETER_INVALID`); - a valid option then reaches the reprojection pipeline, which still throws because the host has no model for it. Evidence is the 13.40 `libSceHmd2.sprx`: the wrapper compares `mode` and each reserved word against zero and returns those codes before handing the call on. Not measured on a console beyond the module body. `Hmd2::MirroringOption` is the 32-byte layout `include/Api.hpp` already pins (mode at 0, seven reserved words). The read goes through `GuestCopyIn_nid_no_patch` with `errno` preserved, as the other argument-taking exports in this file do. ### Tested Linux x86-64 (CachyOS), GCC 16.2.1, Release, `BUILD_TESTING=ON`, on `main` `e3f556c718`: - `guest_hmd2`, `guest_hmd2_gaze` and `guest_hmd2_gaze_args`: 3/3 pass. - Negative control: with `Export.cpp` at `main` and the new assertions kept, `guest_hmd2` aborts with `sceHmd2ReprojectionSetMirroringOption not implemented`; restoring the change makes it pass. The new cases cover a null pointer, an unmapped pointer, `mode = 2`, each of the seven reserved words set on its own, and both valid modes still throwing inside a session. - `tools/check_conventions.py --base origin/main` and `tools/debt_fold.py --check` are clean. - `tools/pr_overlap.py --branch fix/hmd2-mirroring-option-checks`: no shared exports; it lists one open pull request that also changes `Export.cpp` and cannot be compared because it conflicts with `main` (it copies other Hmd2 structures through the guest helpers, not this export). Not run: Windows, a console, and a title that opens a reprojection session. ### 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
PrivacyOnion commented 2026-11-22 16:52:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-22T16:52:01Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 58d31dce47:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_hmd2_tests built cleanly.
  • CTest (guest_hmd2):
    1/1 Test #4025: guest_hmd2 .......................   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceHmd2/Export.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4025: guest_hmd2 .......................Subprocess aborted***Exception:   0.43 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified sceHmd2ReprojectionSetMirroringOption checks option == nullptr and GuestCopyIn_nid_no_patch failures, returning Hmd2::ParameterNull (0x8A720008).
    • Verified range validation on local.mode (mode > 1) and all 7 reserved words (reserved != 0) returning Hmd2::ParameterInvalid (0x8A720009).
    • Verified preservation and restoration of errno around GuestCopyIn_nid_no_patch.
    • Verified session state gating under reprojectionMutex returning Hmd2::ReprojectionNotInitialized (0x8A72000B) before option validation.
    • Verified unhandled valid option path terminates with NotImplemented_nid_no_patch(func) and documentation fragment in docs/dev/debt/changes/fix-hmd2-mirroring-option-checks.md conforms to AGENTS.md rules.
    • Verified guest_hmd2 test additions in GuestHmd2.cpp exhaustively test null, bad pointers, mode > 1, all reserved word indices, and valid modes (0, 1) throwing NotImplemented.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6013359996 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25756#pullrequestreview-6013359996). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-22T16:52:01Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `58d31dce47`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_hmd2_tests` built cleanly. - **CTest** (`guest_hmd2`): ``` 1/1 Test #4025: guest_hmd2 ....................... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceHmd2/Export.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #4025: guest_hmd2 .......................Subprocess aborted***Exception: 0.43 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified sceHmd2ReprojectionSetMirroringOption checks option == nullptr and GuestCopyIn_nid_no_patch failures, returning Hmd2::ParameterNull (0x8A720008). - Verified range validation on local.mode (mode > 1) and all 7 reserved words (reserved != 0) returning Hmd2::ParameterInvalid (0x8A720009). - Verified preservation and restoration of errno around GuestCopyIn_nid_no_patch. - Verified session state gating under reprojectionMutex returning Hmd2::ReprojectionNotInitialized (0x8A72000B) before option validation. - Verified unhandled valid option path terminates with NotImplemented_nid_no_patch(__func__) and documentation fragment in docs/dev/debt/changes/fix-hmd2-mirroring-option-checks.md conforms to AGENTS.md rules. - Verified guest_hmd2 test additions in GuestHmd2.cpp exhaustively test null, bad pointers, mode > 1, all reserved word indices, and valid modes (0, 1) throwing NotImplemented. Looks Good To Me
MarcZX10 commented 2026-11-22 17:03:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T17:03:56Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation matches the stated validation order and preserves the existing unimplemented path for valid options.

What I ran

Reviewed head 58d31dce47104dac44387911aa9430f71bab78bc against base main. No commands or tests were run; repo_read.py was unavailable as a runnable command in this interface. Read the prepared description, commits, manifest, diff, and all changed lines in core/libs/prx/libSceHmd2/Export.cpp, core/libs/tests/GuestHmd2.cpp, and docs/dev/debt/changes/fix-hmd2-mirroring-option-checks.md. Also read the option layout and the adjacent copy-in path.

Results

Check Result Note
Changed lines passed All changed lines read
Tests not run Reported test results are author supplied
Repository checks not run Not independently verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports three passing tests, a passing negative control, and clean convention and debt checks; these were not run independently. Windows, console behavior, and the titled reprojection-session scenario were not verified. No changed file was excluded; all three changed files marked included in the manifest were read in full or across their changed lines. The full text of Export.cpp and GuestHmd2.cpp beyond the targeted ranges was not read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6013413530 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25756#pullrequestreview-6013413530). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T17:03:56Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation matches the stated validation order and preserves the existing unimplemented path for valid options. ## What I ran Reviewed head `58d31dce47104dac44387911aa9430f71bab78bc` against base `main`. No commands or tests were run; `repo_read.py` was unavailable as a runnable command in this interface. Read the prepared description, commits, manifest, diff, and all changed lines in `core/libs/prx/libSceHmd2/Export.cpp`, `core/libs/tests/GuestHmd2.cpp`, and `docs/dev/debt/changes/fix-hmd2-mirroring-option-checks.md`. Also read the option layout and the adjacent copy-in path. ## Results | Check | Result | Note | |---|---|---| | Changed lines | passed | All changed lines read | | Tests | not run | Reported test results are author supplied | | Repository checks | not run | Not independently verified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The author reports three passing tests, a passing negative control, and clean convention and debt checks; these were not run independently. Windows, console behavior, and the titled reprojection-session scenario were not verified. No changed file was excluded; all three changed files marked included in the manifest were read in full or across their changed lines. The full text of `Export.cpp` and `GuestHmd2.cpp` beyond the targeted ranges was not read. ## To get this to a good state Nothing is required.

Pull request closed

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!25756
No description provided.