feat(libkernel): record APR memory protection and remap commands #4244

Closed
MarcZX10 wants to merge 1 commit from upstream-pr/4244 into main
MarcZX10 commented 2026-10-12 02:10:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T02:10:51Z.


What

Carries Dextroid17's single commit from #4214, preserving the original commit author. Adds the missing libkernel recorders for sceKernelWriteModifyMtypeProtectCommand and sceKernelWriteRemapIntoPrtCommand. They validate the guest range/protection arguments and append the existing APR command structures and opcodes that libkernel already executes. The remap recorder retains the established default opcode value when the caller supplies zero.

The regression cases are added to GuestAmpr.cpp. Open #4207 also edits this test file for separate libSceAmpr functions; the current PR heads merge cleanly, and this PR has no dependency on it. The other absent exports mentioned in #4214 are outside this change.

Tested

Linux x86-64, GCC 12.2, Release/Ninja:

  • Built guest_ampr_tests and its dependencies successfully.
  • Ran /tmp/AnyPS5-4214-build/tests/guest_ampr_tests: passed (exit 0), including the new recorder checks.
  • ctest -R '^guest_ampr$' found no registered tests in this build configuration; the built test executable was run directly.
  • tools/check_conventions.py --base upstream/main --head HEAD: passed.
  • git diff --check upstream/main...HEAD: passed.

Checklist

  • Based on current main; no other open PR implements these two exports
  • 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 in TechnicalDebt (n/a)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (n/a)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (carried commit from Dextroid17)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4824109409 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4244). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T02:10:51Z. --- ### What Carries Dextroid17's single commit from #4214, preserving the original commit author. Adds the missing libkernel recorders for `sceKernelWriteModifyMtypeProtectCommand` and `sceKernelWriteRemapIntoPrtCommand`. They validate the guest range/protection arguments and append the existing APR command structures and opcodes that libkernel already executes. The remap recorder retains the established default opcode value when the caller supplies zero. The regression cases are added to `GuestAmpr.cpp`. Open #4207 also edits this test file for separate libSceAmpr functions; the current PR heads merge cleanly, and this PR has no dependency on it. The other absent exports mentioned in #4214 are outside this change. ### Tested Linux x86-64, GCC 12.2, Release/Ninja: - Built `guest_ampr_tests` and its dependencies successfully. - Ran `/tmp/AnyPS5-4214-build/tests/guest_ampr_tests`: passed (exit 0), including the new recorder checks. - `ctest -R '^guest_ampr$'` found no registered tests in this build configuration; the built test executable was run directly. - `tools/check_conventions.py --base upstream/main --head HEAD`: passed. - `git diff --check upstream/main...HEAD`: passed. ### Checklist - [x] Based on current `main`; no other open PR implements these two exports - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) (n/a) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (n/a) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (carried commit from Dextroid17)
github-actions[bot] commented 2026-10-12 02:11:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T02:11:16Z.


Progress report (ceb342b → 7a3e7b1)

📈 System libraries: 86.48% (+0.01%, +2 implemented functions)

✅ 2 implemented
Library Name
libkernel sceKernelWriteModifyMtypeProtectCommand
libkernel sceKernelWriteRemapIntoPrtCommand
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6116513495 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4244#issuecomment-6116513495). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T02:11:16Z. --- <!-- progress-report --> ### Progress report (ceb342b → 7a3e7b1) 📈 **System libraries**: 86.48% (+0.01%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libkernel | `sceKernelWriteModifyMtypeProtectCommand` | | libkernel | `sceKernelWriteRemapIntoPrtCommand` | </details>
Dextroid17 commented 2026-10-12 03:25:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T03:25:00Z.


Thanks for carrying this — it is my commit from #4214, and the title behind it is Trails in the Sky 2nd Chapter (PPSA35169, 01.003.000). Two details from my run of it that may be useful here:

  • The registered test name is guest_ampr_markers (core/libs/prx/libSceAmpr/CMakeLists.txt), not guest_ampr — the new TestKernelAmmRecorders() cases run under it, alongside guest_ampr_threads. An anchored ctest -R '^guest_ampr$' matches neither, which is what your run saw, and ctest -N | grep -i ampr lists them.
  • Full build + ctest of the branch pass here (Linux, CachyOS, GCC 16.2.1, Release), and with this change plus the two libSceAmpr exports of the same set the title clears the wall in #4214 and reaches its Vulkan device, swapchain, save data and 16 game threads (measured); the next stop is the unrelated NGS2 audio wall filed as #4246.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117178433 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4244#issuecomment-6117178433). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-12T03:25:00Z. --- Thanks for carrying this — it is my commit from #4214, and the title behind it is Trails in the Sky 2nd Chapter (PPSA35169, 01.003.000). Two details from my run of it that may be useful here: - The registered test name is `guest_ampr_markers` (`core/libs/prx/libSceAmpr/CMakeLists.txt`), not `guest_ampr` — the new `TestKernelAmmRecorders()` cases run under it, alongside `guest_ampr_threads`. An anchored `ctest -R '^guest_ampr$'` matches neither, which is what your run saw, and `ctest -N | grep -i ampr` lists them. - Full build + `ctest` of the branch pass here (Linux, CachyOS, GCC 16.2.1, Release), and with this change plus the two `libSceAmpr` exports of the same set the title clears the wall in #4214 and reaches its Vulkan device, swapchain, save data and 16 game threads ([measured](https://github.com/boykopovar/AnyPS5/issues/4214#issuecomment-6116547964)); the next stop is the unrelated NGS2 audio wall filed as #4246. Written with AI assistance.
overlordxrz-source commented 2026-10-12 05:20:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-12T05:20:37Z.


Since #4258 was closed as a duplicate of this PR, here is my note from there again, because it applies here too: on the console these two are the libkernel writers that libSceAmpr's AMM command buffer calls, not recorders into a CommandBufferObject. drakmor/ampr_emu hooks them as (void* dst, va, size, type, prot, protMask, uint64_t* outSize) and (uint32_t* dst, va, remapVa, size, prot, opcode, uint64_t* outSize). libSceAmpr calls each one twice: first with dst = nullptr to get the size, then to write (L327-L403). With the CommandBufferObject* form, the size call returns EINVAL, and the write call reads its base/size/offset out of the title's raw buffer bytes.

#4266 (ducloc080202) already uses the raw-destination form with outSize, so maintainers may want to compare the two before merging either.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6118251266 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4244#issuecomment-6118251266). Originally posted by [overlordxrz-source](https://github.com/overlordxrz-source) on 2026-10-12T05:20:37Z. --- Since #4258 was closed as a duplicate of this PR, here is my note from there again, because it applies here too: on the console these two are the libkernel *writers* that libSceAmpr's AMM command buffer calls, not recorders into a `CommandBufferObject`. [drakmor/ampr_emu](https://github.com/drakmor/ampr_emu/blob/cfa85df379f6eeeb165d7badf9b648e266fe77b7/include/ampr_libkernel_hook_targets.h#L112-L114) hooks them as `(void* dst, va, size, type, prot, protMask, uint64_t* outSize)` and `(uint32_t* dst, va, remapVa, size, prot, opcode, uint64_t* outSize)`. libSceAmpr calls each one twice: first with `dst = nullptr` to get the size, then to write ([L327-L403](https://github.com/drakmor/ampr_emu/blob/cfa85df379f6eeeb165d7badf9b648e266fe77b7/src/ampr_emu_command_buffer_amm.cpp#L327-L403)). With the `CommandBufferObject*` form, the size call returns `EINVAL`, and the write call reads its `base`/`size`/`offset` out of the title's raw buffer bytes. #4266 (ducloc080202) already uses the raw-destination form with `outSize`, so maintainers may want to compare the two before merging either. AI-assisted: yes
oneandonlydean commented 2026-10-12 07:36:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T07:36:42Z.


Closing in favour of #4266. These two take a raw destination and an outSize, like the other sceKernelWrite*Command writers (ampr_emu hook targets), and are called with a null destination to measure. With Apr::CommandBufferObject* that call returns EINVAL, and the write call would read base/size/offset out of the title's buffer.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6119852276 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4244#issuecomment-6119852276). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-12T07:36:42Z. --- Closing in favour of #4266. These two take a raw destination and an `outSize`, like the other `sceKernelWrite*Command` writers ([ampr_emu hook targets](https://github.com/drakmor/ampr_emu/blob/cfa85df379f6eeeb165d7badf9b648e266fe77b7/include/ampr_libkernel_hook_targets.h#L112-L114)), and are called with a null destination to measure. With `Apr::CommandBufferObject*` that call returns `EINVAL`, and the write call would read `base`/`size`/`offset` out of the title's buffer.

Pull request closed

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!4244
No description provided.