fix(libSceVideoOut): copy guest pointer parameters through GuestPtr #19827

Merged
Ethan-Hainline merged 4 commits from upstream-pr/19827 into main 2026-11-25 15:25:55 +00:00
Ethan-Hainline commented 2026-11-14 00:48:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ethan-Hainline on 2026-11-14T00:48:43Z.


What

The libSceVideoOut conversion on top of #19266.

python3 tools/guest_pointer_audit.py libSceVideoOut reports 25 findings on main and 0 here:

  • the input structs (VideoOutBufferAttribute*, VideoOutBufferAttribute2*, VideoOutBuffers*, void* const*, KernelEvent*) are copied once before use;
  • the output structs (VideoOutFlipStatus*, VideoOutVblankStatus*, VideoOutOutputStatus*, VideoOutResolutionStatus*, the label address, the event data) are built locally and copied once;
  • the option helpers copy in, update and copy out only the 8-byte option field;
  • the separate AgcDriverCheckGuestMemory calls for those parameters are gone, so the check and the access are one operation. The display-buffer checks remain.

Error behavior is preserved for nulls; an unreadable non-null pointer now takes the same path as a null one (return VIDEO_OUT_ERROR_INVALID_ADDRESS, or throw ...: VIDEO_OUT_ERROR_INVALID_ADDRESS) instead of faulting. sceVideoOutSysInitMode, sceVideoOutModeSetAny_, sceVideoOutColorSettingsSetGamma and the color-space defaults are in the throw group.

This clears the audit's direct-access findings. Pointers passed into helpers are outside the audit's view and are unchanged.

Tested

Windows 11 Pro, Ryzen 5 7530U, AMD Radeon Vega 8, MinGW-w64 GCC 16.2, Release, BUILD_TESTING=ON. Rebased onto main 9504fbb964; the head is 8edaf548df (including the maintainer-added debt entry).

  • python tools/guest_pointer_audit.py libSceVideoOut: 21 findings on main, 0 here with the cast-aware audit.
  • Main added sceVideoOutSysModeIsHdr, which read the guest mode byte directly; it and the sceVideoOutSysIsModeS3d/sceVideoOutSysModeIs* queries now copy their mode fields and answer an unreadable mode with 0 (system-default with 1), covered by the fault test. The audit is 0 under both the current matcher and the cast-plus-offset matcher proposed in #21686.
  • ctest -R '^(guest_ptr|guest_video_out_pointer_faults|guest_video_out_resolution_status|guest_video_out_event_id|video_out_flip_(labels|controls|unopened|ps4|resolution|present|dcc))$' --output-on-failure with ANYPS5_REQUIRE_VULKAN=1: 11/11 passed on this diff before the final rebases; each rebase was clean apart from sceVideoOutInitializeOutputOptions, sceVideoOutGetEventData, sceVideoOutColorSettingsSetGamma and the color-space defaults, where main's newer errno-preserving GuestCopyIn/GuestCopyOut is kept as-is instead of being converted to GuestPtr.
  • The new guest_video_out_pointer_faults calls the converted exports with unmapped pointers (1) and checks the return or throw: the attribute builders, option add/remove, event id/count/data, sceVideoOutSysInitMode, sceVideoOutSysModeIsHdr, sceVideoOutInitializeOutputOptions, gamma and the color-space defaults.
  • python tools/tests/test_guest_pointer_audit.py: 21/21 passed.
  • python tools/check_conventions.py --base main --head HEAD passes.

Not tested: a Windows full-suite run and a real title; the PR jobs will run the suite.

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: #19266
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (no GPU path changed; guest tests only)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5305271247 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19827). Originally posted by [Ethan-Hainline](https://github.com/Ethan-Hainline) on 2026-11-14T00:48:43Z. --- ### What The `libSceVideoOut` conversion on top of #19266. `python3 tools/guest_pointer_audit.py libSceVideoOut` reports **25 findings on `main` and 0 here**: - the input structs (`VideoOutBufferAttribute*`, `VideoOutBufferAttribute2*`, `VideoOutBuffers*`, `void* const*`, `KernelEvent*`) are copied once before use; - the output structs (`VideoOutFlipStatus*`, `VideoOutVblankStatus*`, `VideoOutOutputStatus*`, `VideoOutResolutionStatus*`, the label address, the event data) are built locally and copied once; - the option helpers copy in, update and copy out only the 8-byte `option` field; - the separate `AgcDriverCheckGuestMemory` calls for those parameters are gone, so the check and the access are one operation. The display-buffer checks remain. Error behavior is preserved for nulls; an unreadable non-null pointer now takes the same path as a null one (return `VIDEO_OUT_ERROR_INVALID_ADDRESS`, or throw `...: VIDEO_OUT_ERROR_INVALID_ADDRESS`) instead of faulting. `sceVideoOutSysInitMode`, `sceVideoOutModeSetAny_`, `sceVideoOutColorSettingsSetGamma` and the color-space defaults are in the throw group. This clears the audit's direct-access findings. Pointers passed into helpers are outside the audit's view and are unchanged. ### Tested Windows 11 Pro, Ryzen 5 7530U, AMD Radeon Vega 8, MinGW-w64 GCC 16.2, Release, `BUILD_TESTING=ON`. Rebased onto `main` `9504fbb964`; the head is `8edaf548df` (including the maintainer-added debt entry). - `python tools/guest_pointer_audit.py libSceVideoOut`: **21** findings on `main`, **0** here with the cast-aware audit. - Main added `sceVideoOutSysModeIsHdr`, which read the guest mode byte directly; it and the `sceVideoOutSysIsModeS3d`/`sceVideoOutSysModeIs*` queries now copy their mode fields and answer an unreadable mode with `0` (system-default with `1`), covered by the fault test. The audit is 0 under both the current matcher and the cast-plus-offset matcher proposed in #21686. - `ctest -R '^(guest_ptr|guest_video_out_pointer_faults|guest_video_out_resolution_status|guest_video_out_event_id|video_out_flip_(labels|controls|unopened|ps4|resolution|present|dcc))$' --output-on-failure` with `ANYPS5_REQUIRE_VULKAN=1`: **11/11 passed** on this diff before the final rebases; each rebase was clean apart from `sceVideoOutInitializeOutputOptions`, `sceVideoOutGetEventData`, `sceVideoOutColorSettingsSetGamma` and the color-space defaults, where main's newer errno-preserving `GuestCopyIn`/`GuestCopyOut` is kept as-is instead of being converted to `GuestPtr`. - The new `guest_video_out_pointer_faults` calls the converted exports with unmapped pointers (`1`) and checks the return or throw: the attribute builders, option add/remove, event id/count/data, `sceVideoOutSysInitMode`, `sceVideoOutSysModeIsHdr`, `sceVideoOutInitializeOutputOptions`, gamma and the color-space defaults. - `python tools/tests/test_guest_pointer_audit.py`: **21/21 passed**. - `python tools/check_conventions.py --base main --head HEAD` passes. Not tested: a Windows full-suite run and a real title; the PR jobs will run the suite. ### 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](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: #19266 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a (no GPU path changed; guest tests only) - [x] AI-assisted: yes
MarcZX10 commented 2026-11-23 04:35:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T04:35:48Z.

Review: COMMENTED


Reviewed — comments

The guest-copy conversions are largely consistent with the stated host-safety goal, but two changed pointer paths do not yet meet that goal.

What I ran

Reviewed head 319e7bde82513b20d2a6929377c07d270db26075 against the prepared diff. No commands or tests were run; repo_read.py was used to inspect changed files and targeted repository context.

Results

Check Result Note
Diff and description passed Seven changed files inspected
Guest-copy behavior passed Core copy helpers and converted paths read
Automated tests not run Author-reported runs not independently verified

Findings

Blocking

None verified.

Non-blocking

  • InventoryExports.cpp:21 forms mode + 0x20 before validating/copying the pointer. For a non-null but invalid address near the top of the address space, this pointer arithmetic can overflow before GuestBytes::CopyIn can safely reject the address. Consider validating the base range or using an overflow-safe address calculation before adding the offset.
  • Output.cpp:169-396 has sceVideoOutModeSetAny_ write the size first, then fill the remaining range in separate 256-byte guest copies. If a later chunk is unreadable, the function returns by throwing after partially modifying guest memory; this does not match the description’s claim that output parameters are built locally and copied once. Consider validating/writing the complete output through one guest-copy operation, or documenting and testing the partial-write behavior.

Not verified

No test/build commands were run. The Windows full suite and real-title behavior were not verified. The author-reported test results in description.md were not independently run. All seven changed files listed in manifest.json were read; none were excluded by the manifest.

To get this to a good state

Nothing is required. Optional: make the mode offset calculation overflow-safe and clarify or make atomic the variable-length mode output copy.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6016621735 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19827#pullrequestreview-6016621735). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T04:35:48Z. **Review:** COMMENTED --- # Reviewed — comments The guest-copy conversions are largely consistent with the stated host-safety goal, but two changed pointer paths do not yet meet that goal. ## What I ran Reviewed head `319e7bde82513b20d2a6929377c07d270db26075` against the prepared diff. No commands or tests were run; `repo_read.py` was used to inspect changed files and targeted repository context. ## Results | Check | Result | Note | | --- | --- | --- | | Diff and description | passed | Seven changed files inspected | | Guest-copy behavior | passed | Core copy helpers and converted paths read | | Automated tests | not run | Author-reported runs not independently verified | ## Findings ### Blocking None verified. ### Non-blocking - `InventoryExports.cpp:21` forms `mode + 0x20` before validating/copying the pointer. For a non-null but invalid address near the top of the address space, this pointer arithmetic can overflow before `GuestBytes::CopyIn` can safely reject the address. Consider validating the base range or using an overflow-safe address calculation before adding the offset. - `Output.cpp:169-396` has `sceVideoOutModeSetAny_` write the size first, then fill the remaining range in separate 256-byte guest copies. If a later chunk is unreadable, the function returns by throwing after partially modifying guest memory; this does not match the description’s claim that output parameters are built locally and copied once. Consider validating/writing the complete output through one guest-copy operation, or documenting and testing the partial-write behavior. ## Not verified No test/build commands were run. The Windows full suite and real-title behavior were not verified. The author-reported test results in `description.md` were not independently run. All seven changed files listed in `manifest.json` were read; none were excluded by the manifest. ## To get this to a good state Nothing is required. Optional: make the mode offset calculation overflow-safe and clarify or make atomic the variable-length mode output copy.
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!19827
No description provided.