fix(libSceAgc): make the AGC patch functions validate like their emitters #16194

Merged
MarcZX10 merged 13 commits from upstream-pr/16194 into main 2026-11-08 23:16:30 +00:00
MarcZX10 commented 2026-11-05 20:36:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-05T20:36:38Z.


What

Makes the libSceAgc PATCH functions apply the same checks as the command emitters they patch. Each packet fix is followed by its regression test commit.

  • sceAgcWaitRegMemPatchAddress (commits 91d1563b5f, c65ee83001, e343e023db, ff8ea1a23d): applies WriteWait's alignment check (4 bytes for a 32-bit wait, 8 for a 64-bit one; null accepted) and the 48-bit address check. Before, a misaligned address split the wait's low word from the wrapper's, and an address above 2^48 was silently truncated.
  • sceAgcWaitRegMemPatchCompareFunction (ae406e0ca5, d69587fc52): rejects values above 6 as WriteWait does, instead of masking with 7.
  • sceAgcWriteDataPatchSetAddressOrOffset (56118fd82f, e6b5b508be): checks 4-byte alignment for graphics packets only, as WriteData does; the async (compute) variant is unchanged.
  • sceAgcQueueEndOfPipeActionPatchData (2a79c6078d, 272c4f251b): a GDS release (data select 5) rejects nonzero data and keeps the offset and size words the emitter encoded (55282e8d46, 7970b144fb): an interrupt-only release rejects data and a set address, as the emitter does.

Existing tests pinned the old behaviour (the wait-address test used a misaligned address above 2^48, and the comparison loop covered 0 to 255); those assertions were updated in the fix commits. Unsure points: the GDS zero-data patch is written as "keep the encoded words" rather than writing zero, which is what the emitter produces for zero data; I believe this is equivalent but have not confirmed it on hardware. The interrupt-only address check depends on the patch order, since the address patch itself does not check the interrupt select. Open PR 13940 compiles the same Patch sources and is not changed by this PR.

Tested

Run: python3 tools/check_conventions.py --base upstream/main (passed) and git diff --check upstream/main (clean).

Not yet run: the build and ctest of agc_command_tests and agc_write_data_patch_tests (build queued under the build lock, not yet run). The negative controls (each fix removed to show its test fails) have not run. Results will be added to this PR once they finish.

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:5178334121 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16194). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-05T20:36:38Z. --- ### What Makes the libSceAgc PATCH functions apply the same checks as the command emitters they patch. Each packet fix is followed by its regression test commit. - `sceAgcWaitRegMemPatchAddress` (commits 91d1563b5f, c65ee83001, e343e023db, ff8ea1a23d): applies WriteWait's alignment check (4 bytes for a 32-bit wait, 8 for a 64-bit one; null accepted) and the 48-bit address check. Before, a misaligned address split the wait's low word from the wrapper's, and an address above 2^48 was silently truncated. - `sceAgcWaitRegMemPatchCompareFunction` (ae406e0ca5, d69587fc52): rejects values above 6 as WriteWait does, instead of masking with 7. - `sceAgcWriteDataPatchSetAddressOrOffset` (56118fd82f, e6b5b508be): checks 4-byte alignment for graphics packets only, as WriteData does; the async (compute) variant is unchanged. - `sceAgcQueueEndOfPipeActionPatchData` (2a79c6078d, 272c4f251b): a GDS release (data select 5) rejects nonzero data and keeps the offset and size words the emitter encoded (55282e8d46, 7970b144fb): an interrupt-only release rejects data and a set address, as the emitter does. Existing tests pinned the old behaviour (the wait-address test used a misaligned address above 2^48, and the comparison loop covered 0 to 255); those assertions were updated in the fix commits. Unsure points: the GDS zero-data patch is written as "keep the encoded words" rather than writing zero, which is what the emitter produces for zero data; I believe this is equivalent but have not confirmed it on hardware. The interrupt-only address check depends on the patch order, since the address patch itself does not check the interrupt select. Open PR 13940 compiles the same Patch sources and is not changed by this PR. ### Tested Run: `python3 tools/check_conventions.py --base upstream/main` (passed) and `git diff --check upstream/main` (clean). Not yet run: the build and ctest of `agc_command_tests` and `agc_write_data_patch_tests` (build queued under the build lock, not yet run). The negative controls (each fix removed to show its test fails) have not run. Results will be added to this PR once they finish. ### 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
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!16194
No description provided.