fix(libSceAmpr): copy remaining command buffer and cnd name guest pointers via GuestCopyIn/Out #20633

Open
PrivacyOnion wants to merge 1 commit from upstream-pr/20633 into main
PrivacyOnion commented 2026-11-15 11:23:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T11:23:07Z.


What

Copy the remaining guest Apr::CommandBufferObject* and _Cnd_init_with_name_nid_postfix const char* name parameters in core/libs/prx/libSceAmpr/Export.cpp via GuestCopyIn / GuestCopyOut / CopyGuestString_nid_no_patch (preserving caller errno via ErrnoGuard and returning SCE_KERNEL_ERROR_EFAULT or setting errno = 14 / 63 with return 4 on fault), and add invalid-pointer tests in core/libs/tests/GuestAmpr.cpp:

  • sceAmprAprCommandBufferConstructor
  • sceAmprAprCommandBufferMapEnd
  • sceAmprAprCommandBufferReadFileGather
  • sceAmprAprCommandBufferResetGatherScatterState
  • sceAmprCommandBufferConstructNop
  • sceAmprCommandBufferNop
  • sceAmprCommandBufferNopWithData
  • sceAmprCommandBufferReset
  • sceAmprAmmCommandBufferUnmap
  • sceAmprAmmCommandBufferRemapIntoPrt
  • sceAmprAmmCommandBufferUnmapToPrt
  • _Cnd_init_with_name_nid_postfix

Tested

  • python tools/guest_pointer_audit.py libSceAmpr -> 0 direct guest pointer accesses in 0 exported functions
  • g++.exe -std=gnu++20 -fsyntax-only -D_fflush_nolock=fflush on core/libs/prx/libSceAmpr/Export.cpp and core/libs/tests/GuestAmpr.cpp -> exit 0
  • python tools/check_conventions.py --base upstream/main --head fix/ampr-guest-copy-remaining -> All conventions checks passed.

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: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5322185039 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20633). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-15T11:23:07Z. --- ### What Copy the remaining guest `Apr::CommandBufferObject*` and `_Cnd_init_with_name_nid_postfix` `const char* name` parameters in `core/libs/prx/libSceAmpr/Export.cpp` via `GuestCopyIn` / `GuestCopyOut` / `CopyGuestString_nid_no_patch` (preserving caller `errno` via `ErrnoGuard` and returning `SCE_KERNEL_ERROR_EFAULT` or setting `errno = 14` / `63` with return `4` on fault), and add invalid-pointer tests in `core/libs/tests/GuestAmpr.cpp`: - `sceAmprAprCommandBufferConstructor` - `sceAmprAprCommandBufferMapEnd` - `sceAmprAprCommandBufferReadFileGather` - `sceAmprAprCommandBufferResetGatherScatterState` - `sceAmprCommandBufferConstructNop` - `sceAmprCommandBufferNop` - `sceAmprCommandBufferNopWithData` - `sceAmprCommandBufferReset` - `sceAmprAmmCommandBufferUnmap` - `sceAmprAmmCommandBufferRemapIntoPrt` - `sceAmprAmmCommandBufferUnmapToPrt` - `_Cnd_init_with_name_nid_postfix` ### Tested - `python tools/guest_pointer_audit.py libSceAmpr` -> `0 direct guest pointer accesses in 0 exported functions` - `g++.exe -std=gnu++20 -fsyntax-only -D_fflush_nolock=fflush` on `core/libs/prx/libSceAmpr/Export.cpp` and `core/libs/tests/GuestAmpr.cpp` -> exit 0 - `python tools/check_conventions.py --base upstream/main --head fix/ampr-guest-copy-remaining` -> `All conventions checks passed.` ### 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: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-23 06:11:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T06:11:17Z.

Review: DISMISSED


Reviewed — changes requested

Changes are required before merge: synchronize the command-buffer metadata when sceAmprCommandBufferConstructNop expands its backing buffer.

What I ran

Reviewed head a3470677b6f42a61ba90735a44b01f42509e9fb8. No commands or tests were run; I inspected the prepared diff and targeted source through repo_read.py.

Results

Check Result Note
Changed code review failed Found one buffer state synchronization defect
Tests not run Author-reported checks were not rerun

Findings

Blocking

  • core/libs/prx/libSceAmpr/Export.cpp:596: AppendNop can grow local.base and local.size through EnsureCommandCapacity, but the call here passes nullptr for payload and does not copy local back until line 610. If that append is the one that triggers expansion, the command bytes are written to the new allocation while the guest buffer still points to the freed/original allocation. A failed subsequent guest write also leaves the expanded allocation recorded against the buffer. Copy the updated metadata back immediately after the append/capacity operation, before writing trailing data, while preserving safe failure behavior.

Non-blocking

None.

Not verified

  • The changed files read were core/libs/prx/libSceAmpr/Export.cpp and core/libs/tests/GuestAmpr.cpp; both were included in the review bundle. No changed files were excluded according to the manifest.
  • No test suite, syntax check, convention check, or guest pointer audit was run. The checks listed in the PR description are author-reported.
  • Console behavior and the remainder of the 1,228-line export file and 2,030-line test file were not fully reviewed.

To get this to a good state

Fix the construct-NOP expansion path so the guest command buffer is synchronized with its new backing allocation, then rerun the relevant tests and checks on the updated head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6017253704 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20633#pullrequestreview-6017253704). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T06:11:17Z. **Review:** DISMISSED --- # Reviewed — changes requested Changes are required before merge: synchronize the command-buffer metadata when `sceAmprCommandBufferConstructNop` expands its backing buffer. ## What I ran Reviewed head `a3470677b6f42a61ba90735a44b01f42509e9fb8`. No commands or tests were run; I inspected the prepared diff and targeted source through `repo_read.py`. ## Results | Check | Result | Note | |---|---|---| | Changed code review | failed | Found one buffer state synchronization defect | | Tests | not run | Author-reported checks were not rerun | ## Findings ### Blocking - `core/libs/prx/libSceAmpr/Export.cpp:596`: `AppendNop` can grow `local.base` and `local.size` through `EnsureCommandCapacity`, but the call here passes `nullptr` for payload and does not copy `local` back until line 610. If that append is the one that triggers expansion, the command bytes are written to the new allocation while the guest buffer still points to the freed/original allocation. A failed subsequent guest write also leaves the expanded allocation recorded against the buffer. Copy the updated metadata back immediately after the append/capacity operation, before writing trailing data, while preserving safe failure behavior. ### Non-blocking None. ## Not verified - The changed files read were `core/libs/prx/libSceAmpr/Export.cpp` and `core/libs/tests/GuestAmpr.cpp`; both were included in the review bundle. No changed files were excluded according to the manifest. - No test suite, syntax check, convention check, or guest pointer audit was run. The checks listed in the PR description are author-reported. - Console behavior and the remainder of the 1,228-line export file and 2,030-line test file were not fully reviewed. ## To get this to a good state Fix the construct-NOP expansion path so the guest command buffer is synchronized with its new backing allocation, then rerun the relevant tests and checks on the updated head.
ligmaSec commented 2026-12-03 15:44:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T15:44:01Z.

Review: COMMENTED


This head conflicts where main added OriginalBufferBase to recover the caller's pointer after command storage expands. Please keep that lookup when threading the staged command-buffer copy through Append and the publish paths. Otherwise the rebased change could alter which storage the caller gets back.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6173138205 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20633#pullrequestreview-6173138205). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T15:44:01Z. **Review:** COMMENTED --- This head conflicts where main added `OriginalBufferBase` to recover the caller's pointer after command storage expands. Please keep that lookup when threading the staged command-buffer copy through `Append` and the publish paths. Otherwise the rebased change could alter which storage the caller gets back. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/20633:upstream-pr/20633'
git switch 'upstream-pr/20633'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/20633'
git switch 'upstream-pr/20633'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/20633'
git switch 'upstream-pr/20633'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/20633'
git switch 'main'
git merge --squash 'upstream-pr/20633'
git switch 'main'
git merge --ff-only 'upstream-pr/20633'
git switch 'main'
git merge 'upstream-pr/20633'
git push origin 'main'
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!20633
No description provided.