Skip to content

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

Closed
edubox wants to merge 1 commit into
boykopovar:mainfrom
edubox:fix/hmd2-mirroring-option-checks
Closed

edubox wants to merge 1 commit into
boykopovar:mainfrom
edubox:fix/hmd2-mirroring-option-checks

Conversation

@edubox

@edubox edubox commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

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

…ipeline

sceHmd2ReprojectionSetMirroringOption threw on every option it was given
once a reprojection session existed. The 13.40 module reads the 32-byte
option first: a null or unreadable pointer answers 0x8A720008, a mode
other than 0 or 1 or any nonzero reserved word answers 0x8A720009, and
only then does it reach the pipeline, which still throws here because it
has no host model.

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@edubox, the checks themselves look right and the tests cover each branch. What I cannot see yet is an effect for a game:

  • A valid option still throws NotImplemented, so no title gets past sceHmd2ReprojectionSetMirroringOption today.
  • The codes 0x8A720008 and 0x8A720009 come from 13.40 disassembly only, and the PR says console execution is not measured. fix(libSceHmd2): report unavailable predicted display time #25677 had a console measurement for the same module.

Please add either a console run of this export for a null pointer, mode 2 and a nonzero reserved word, or a PPSA title that imports it with a run showing which code it reaches. With either I will re-review.

@edubox

edubox commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, both points are fair. On the effect for a game: the valid-option throw is deliberate in this PR — it only puts the guard in the documented order, and the reprojection pipeline behind it is not implemented, so answering success would invent state. The alternative (keep throwing everything, including the null-pointer and reserved-word cases) is what the branch replaces.

On the evidence, I do not have a console measurement for this export, and I would rather say so than claim one:

  • Of the 57 dumped registries I have, only one imports sceHmd2ReprojectionSetMirroringOption (+seEJVlljr0): The 7th Guest (PPSA17019), with a resolved call site at 0x48B37D0. Gran Turismo 7 (PPSA01317), the title behind the #7658 measurement, does not import it, so that run cannot reach this path.
  • The two codes come from 13.40 disassembly, like fix(libSceHmd2): report unavailable predicted display time #25677's. What the GT7 session does measure is the same family: GetStatus(NULL) returns 0x8a720008 there, i.e. the argument check returns the same code this PR uses for a null pointer, and every gated export tests the session before its arguments. That is consistent with, not a substitute for, a measurement of this export.

So the choices are: leave it open until someone with console access runs the 7th Guest call site (I can try the dump here, but I cannot promise that call is reached without a headset), or accept firmware evidence for the ordering and keep the two codes marked unmeasured in the debt entry, as they are now. Tell me which you prefer and I will follow it — I will not claim a console run I have not done.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 19525 core/libs/prx/libSceHmd2/Export.cpp
PR 26370 core/libs/prx/libSceHmd2/Export.cpp

@oneandonlydean

Copy link
Copy Markdown
Collaborator

I am closing this for now. The checks look right and the tests cover each branch, but a valid option still throws NotImplemented so no title gets past sceHmd2ReprojectionSetMirroringOption today, and the codes 0x8A720008 and 0x8A720009 come from 13.40 disassembly only, with no console measurement. There has been no push since 22 Nov. If you can name a title or measure it on the console, please reopen and we will look again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants