fix(libSceAgc): copy packet info guest pointers safely #22137

Merged
domx4q merged 1 commit from upstream-pr/22137 into main 2026-11-17 06:57:09 +00:00
domx4q commented 2026-11-17 06:19:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by domx4q on 2026-11-17T06:19:30Z.


What

sceAgcGetPacketSize, sceAgcGetDataPacketPayloadAddress_0090 (and its sceAgcGetDataPacketPayloadAddress alias), sceAgcGetDataPacketPayloadRange and sceAgcDcbGetSystemSoftwareVersion read the PM4 header, and the version dword, straight from the guest packet pointer, so an unmapped packet crashed the process. They now copy those words in with GuestCopyIn_nid_no_patch and compute on the host copy. An unreadable packet throws through Agc::Command::Require ("source pointer is not readable"), the way #20051 made these exports handle an unwritable output pointer. A type 1 payload address query still does not read the packet. For readable packets the results are byte-for-byte the same.

No debt fragment: the existing libSceAgc.md entries describe only the null or unwritable output pointer, not how an unreadable packet is handled.

Overlap

  • python3 tools/pr_overlap.py --names sceAgcDcbGetSystemSoftwareVersion sceAgcGetDataPacketPayloadAddress_0090 sceAgcGetDataPacketPayloadRange sceAgcGetPacketSize sceAgcGetDataPacketPayloadAddress: every function is main: core/libs/prx/libSceAgc (implemented), open: none.
  • python3 tools/pr_overlap.py --branch fix/agc-packet-info-guest-pointers: "No overlap with open pull requests."

Tested

Arch Linux, GCC 16.2.1, Release, -DBUILD_TESTING=ON.

  • ctest --test-dir build -R 'agc_commands$|agc_packet_info|agc_payload_range|agcvsh_packet_writer': 4/4 passed (libSceAgcVsh compiles the same PacketInfo.cpp). ctest -R '^public_headers$' passed.
  • New cases in core/libs/prx/libSceAgc/tests/PacketInfo.cpp pass the unmapped address 0x10 (the address the library's existing tests use for unwritable outputs) as the packet to each of the four exports, and for both types of sceAgcGetDataPacketPayloadRange.
  • Mutation check: I restored each of the four function bodies to main one at a time. Each time agc_packet_info_tests died with fatal SIGSEGV ... at address 0x10 (rc 139), and it passes with the fix.
  • python3 tools/guest_pointer_audit.py libSceAgc no longer lists anything in PacketInfo.cpp. python3 tools/check_conventions.py --base origin/main passes. python3 tools/debt_fold.py --check fails only on docs/dev/debt/changes/docs-nkwebkit-drop-readded-count-lines.md, which is already on main and is not touched here.
  • GPU run, same machine and GPU, with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest -R '^(agc_commands|agc_packet_info_tests|agc_payload_range_tests|agcvsh_packet_writer)$' -V, once on main (e4caa07950) and once on this branch. Both runs passed 4/4 with 0 VUID- lines and no was not found but was requested by env var VK_INSTANCE_LAYERS. These CPU-only packet tests never create a Vulkan instance, so neither log has an Insert instance layer line. To show the layer setup works, vulkaninfo --summary with the same environment logs Insert instance layer "VK_LAYER_KHRONOS_validation" (/usr/lib/libVkLayer_khronos_validation.so), layer 1.4.363.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: NVIDIA GeForce RTX 4090, driver 620.70.06, Vulkan 1.4.357, validation layer 1.4.363.1, Arch Linux
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5351919877 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22137). Originally posted by [domx4q](https://github.com/domx4q) on 2026-11-17T06:19:30Z. --- ### What `sceAgcGetPacketSize`, `sceAgcGetDataPacketPayloadAddress_0090` (and its `sceAgcGetDataPacketPayloadAddress` alias), `sceAgcGetDataPacketPayloadRange` and `sceAgcDcbGetSystemSoftwareVersion` read the PM4 header, and the version dword, straight from the guest packet pointer, so an unmapped packet crashed the process. They now copy those words in with `GuestCopyIn_nid_no_patch` and compute on the host copy. An unreadable packet throws through `Agc::Command::Require` ("source pointer is not readable"), the way #20051 made these exports handle an unwritable output pointer. A type 1 payload address query still does not read the packet. For readable packets the results are byte-for-byte the same. No debt fragment: the existing `libSceAgc.md` entries describe only the null or unwritable output pointer, not how an unreadable packet is handled. ### Overlap - `python3 tools/pr_overlap.py --names sceAgcDcbGetSystemSoftwareVersion sceAgcGetDataPacketPayloadAddress_0090 sceAgcGetDataPacketPayloadRange sceAgcGetPacketSize sceAgcGetDataPacketPayloadAddress`: every function is `main: core/libs/prx/libSceAgc (implemented)`, `open: none`. - `python3 tools/pr_overlap.py --branch fix/agc-packet-info-guest-pointers`: "No overlap with open pull requests." ### Tested Arch Linux, GCC 16.2.1, Release, `-DBUILD_TESTING=ON`. - `ctest --test-dir build -R 'agc_commands$|agc_packet_info|agc_payload_range|agcvsh_packet_writer'`: 4/4 passed (`libSceAgcVsh` compiles the same `PacketInfo.cpp`). `ctest -R '^public_headers$'` passed. - New cases in `core/libs/prx/libSceAgc/tests/PacketInfo.cpp` pass the unmapped address `0x10` (the address the library's existing tests use for unwritable outputs) as the packet to each of the four exports, and for both types of `sceAgcGetDataPacketPayloadRange`. - Mutation check: I restored each of the four function bodies to `main` one at a time. Each time `agc_packet_info_tests` died with `fatal SIGSEGV ... at address 0x10` (rc 139), and it passes with the fix. - `python3 tools/guest_pointer_audit.py libSceAgc` no longer lists anything in `PacketInfo.cpp`. `python3 tools/check_conventions.py --base origin/main` passes. `python3 tools/debt_fold.py --check` fails only on `docs/dev/debt/changes/docs-nkwebkit-drop-readded-count-lines.md`, which is already on `main` and is not touched here. - GPU run, same machine and GPU, with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest -R '^(agc_commands|agc_packet_info_tests|agc_payload_range_tests|agcvsh_packet_writer)$' -V`, once on `main` (e4caa07950) and once on this branch. Both runs passed 4/4 with 0 `VUID-` lines and no `was not found but was requested by env var VK_INSTANCE_LAYERS`. These CPU-only packet tests never create a Vulkan instance, so neither log has an `Insert instance layer` line. To show the layer setup works, `vulkaninfo --summary` with the same environment logs `Insert instance layer "VK_LAYER_KHRONOS_validation" (/usr/lib/libVkLayer_khronos_validation.so)`, layer 1.4.363. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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: NVIDIA GeForce RTX 4090, driver 620.70.06, Vulkan 1.4.357, validation layer 1.4.363.1, Arch Linux - [x] AI-assisted: yes (Claude Code)
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!22137
No description provided.