fix(libkernel): record AmmModifyMtypeProtect and AmmRemapIntoPrt commands #4266
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4266"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by ducloc080202 on 2026-10-12T03:34:09Z.
What
Fixes #4214. Trails in the Sky 2nd Chapter (PPSA35169) stops at process start on two missing
libkernelexports:sceKernelWriteModifyMtypeProtectCommand(hrEIwWDKm-w) andsceKernelWriteRemapIntoPrtCommand(RPAHEYSOt1s). Both are recorder-side functions that serialize anAmmModifyMtypeProtect/AmmRemapIntoPrtcommand into the caller's buffer; the execution side already handles both opcodes.Signatures are taken from ampr_emu's libkernel hook targets, which forward to the real kernel (same source this project's AMM work already cites): the
ModifyMtypeProtectwriter takes(dst, va, size, type, prot, protMask, outSize), theRemapIntoPrtwriter takes(dst, va, remapVa, size, prot, opcode, outSize), and a nulldstonly measures while a nulloutSizeonly records. Anopcodeof 0 is recorded as 1011, matching the existingsceAmprAmmCommandBufferRemapIntoPrt. Range, protection and mask checks mirror thelibSceAmprsiblings, and the recorded bytes are identical to theirs so the submitted buffer executes on the existing paths. Uncertainty is documented in TechnicalDebt.Tested
Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7, Release full build with BUILD_TESTING=ON. New
TestKernelWriteCommandsinGuestAmpr.cpp: measure mode, record mode (header + byte equality with thelibSceAmprsibling recorders),outSize-null recording, opcode 0/42 recording (1011/42), submit-and-execute round trip throughsceAmprAmmSubmitCommandBuffer3(protection change observed viasceKernelQueryMemoryProtection, remapped page readable in the PRT range), invalid arguments rejected withEINVALleavingdst/outSizeuntouched, and null/null calls. Without the fix the test binary fails to link withundefined referenceto both functions (the title's exact symptom); with the fixguest_ampr_markerspasses.python tools/nid_names.py --nid hrEIwWDKm-w --nid RPAHEYSOt1sreports both NIDs as already-implemented.python tools/check_conventions.py --base origin/mainandgit diff --checkpass.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T03:38:58Z.
Potential ABI conflict with the open #4244: both define
sceKernelWriteModifyMtypeProtectCommandandsceKernelWriteRemapIntoPrtCommand, but #4244 takes anApr::CommandBufferObject*and appends to its bound buffer, while this PR takes a rawdstplusoutSizeand supports a measure call. Those prototypes cannot both represent the same NIDs safely. #4258 was confirmed byte-identical to #4244 and closed as its duplicate, leaving #4244 as the competing implementation. The signature evidence here (ampr_emu hook targets) differs from #4244’s sibling-recorder inference; #4214 establishes the imports but not the call ABI. This needs reconciliation against a title call/register capture or another trusted source before both copies proceed.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T03:43:35Z.
Review: COMMENTED
Following up on the ABI mismatch noted earlier: has either implementation been checked against a captured guest call site or a trusted SDK header? The recorder-buffer prototype and the raw output-buffer prototype cannot both bind the same NIDs safely. A register/call-site trace or source signature would resolve which contract the exports need.
Imported from boykopovar/AnyPS5. Originally posted by ducloc080202 on 2026-10-12T03:43:58Z.
Thanks for catching the conflict — you're right that the two PRs can't both represent these NIDs. My duplicate check (
gh search prsfor both names) came back empty before #4244 was up, so I missed it; sorry for the extra reconciliation work.On the ABI question, the two proposals agree on the recorded bytes (same structs, same opcodes, same 0-to-1011 default — my test even byte-compares the
Write*output against thelibSceAmprsibling recorders), so execution behavior is identical either way. The dispute is only the call ABI: rawdst+outSizewith a measure mode (this PR) vsApr::CommandBufferObject*append ( #4244).The evidence for raw
dst+outSize:libkernelon real hardware with exactly these 7-arg signatures (include/ampr_libkernel_hook_targets.h:sceKernelWriteModifyMtypeProtectCommand(void*, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t*)andsceKernelWriteRemapIntoPrtCommand(uint32_t*, uint64_t, uint64_t, uint64_t, int, int, uint64_t*), both forwarded to the real kernel).AmmCommandBuffercalls the real kernel writer withdst == nullptrto measure (src/ampr_emu_command_buffer_amm.cpp, e.g.Emu::ammWriteModifyMtypeProtectCommand(nullptr, va, size, ..., out)insidecb_append_amm_kernel_record), and depends on getting the size back. Under aCommandBufferObject*ABI, a null buffer returnsEINVAL— which is exactly what #4244's own new test asserts (sceKernelWriteModifyMtypeProtectCommand(nullptr, ...) == invalidArgument). So if #4244's ABI were the real one, ampr_emu's measure path would fail on every append on console, but ampr_emu works there.Measuresiblings for these two exist anywhere, while everylibSceAmprCommandBuffer*recorder has aMeasure*partner. TheWrite*Commandname plus the built-in null-dstmeasure explains that absence; aCommandBuffer*theory leaves it unexplained.So I believe the
CommandBufferObject*form is a sibling-recorder inference that happens to produce the right bytes but the wrong call ABI, and a real title calling these NIDs would pass a raw cursor +outSize, which #4244's form would misread (itsbufferparam would receive the title'sdstpointer, and there is nooutSizeat all).Happy to carry over anything useful from #4244 if maintainers agree this ABI is the right one — e.g. its separate
Recorder.cppfile layout vs my in-Apr.cppplacement — or to yield if someone has a title register capture showing otherwise.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T03:44:47Z.
Progress report (
d146ec1→2cf929d)📈 System libraries: 86.55% (+0.01%, +2 implemented functions)
✅ 2 implemented
sceKernelWriteModifyMtypeProtectCommandsceKernelWriteRemapIntoPrtCommandImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T03:52:12Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)sceKernelWriteModifyMtypeProtectCommandsceKernelWriteRemapIntoPrtCommand