fix(libSceAmpr): record Nop as n dwords with a one-dword header #10936
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10936"
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 AdnanKhan-ak47 on 2026-10-25T11:06:32Z.
What
sceAmprCommandBufferNop(n)now records n dwords andsceAmprCommandBufferNopWithData(n)(n + 1) dwords, as on the console, instead of 8 + 4n bytes.docs/dev/debt/libSceAmpr.mdrecorded the consequence: a title padding to an exact offset or to the end of its buffer withNop(remaining / 4)gotSCE_KERNEL_ERROR_EBUSYor a shifted offset.The record is one dword of header followed by the payload. The header word is the console's, as observed by BunnyFl from firmware 13.42's
libSceAmpr.sprxin this thread:0x5452000F | payloadDwords << 8 | (type & 0xF) << 12, soNop(1)writes0x5452000F,Nop(16)0x54520F0F,NopWithData(n)0x5452000F | n << 8andConstructNopcarries the low four bits oftype(Apr::NopHeader,IsNopHeader,NopDwords,NopHeaderBytesinAprCommandBuffer.hpp). The executor recognises the record by(word & 0xFFFF00FF) == 0x5452000Fbefore the 8-byte header guard; the low byte alone would collide withReadFileGatherScatter = 15, and no 8-byte header carries0x5452in its upper half. A 4-byteNop(1)at the end of a buffer is valid, a record past the buffer end isAPR: malformed command, fewer than 4 remaining bytesAPR: truncated command buffer, and the old 8-byte{Nop, bytes}record isAPR: unknown opcode 0. A nullbaseis reported (EPERM) before the count or payload range, as on the console.Nop(n)writes only the header and leaves the other n - 1 dwords as they were.ConstructNopwrites its payload after the 4-byte header. The measure functions return 4n for both, keepingMeasureCommandSizeNopWithData's argument as the total dword count the existing tests use.ConstructNopwrites the word before the payload and zeroes the payload's padding, as in BunnyFl's dump ofConstructNop(buffer, 7, {1,2,3,4,5}, 5, &0xCAFEF00D)(0f 73 52 54 | 0d f0 fe ca | 01 02 03 04 | 05 00 00 00). One console behaviour is deliberately not reproduced and is recorded indocs/dev/debt/libSceAmpr.md:NopWithDatawith data andConstructNopwrite four zero bytes right after the payload even where they fall past the end of the record and of the buffer; AnyPS5 stops at the record.GuestAmpr.cpp:RequireAppendedchecks the dword header for Nop;TestNopspins the header word forNop(1..16),NopWithData(0)andNopWithData(3), thatNop(n)leaves the n - 1 dwords after the header untouched, and that a buffer withoutbasereturnsEPERMfor out-of-range counts;TestConstructedpins0x5452730F, the word at +4, the payload at +8 and zeroed padding at +13..15 for type 7 with a word and 5 payload bytes over pre-filled memory, with the byte past the record untouched, and0x5452510Ffor type0x15with one payload dword;TestNopPaddingpinsNop(1) = 4,Nop(16) = 64, fills a 64-byte buffer to exactly its end withNop(remaining / 4)after a marker and a write, checks that one dword more isEBUSYbefore and after, submits it, and submits a buffer where a 4-byte Nop misaligns the following 8-byte-header command;TestMalformedCommandSizescovers the Nop count 0, count overflow and 3-byte-tail failures and keeps the header-record cases onPopMarker.Tested
Arch Linux x86-64, GCC 16.2.1, head
0d14468ccc:ctest -R 'guest_ampr|guest_amm|guest_apr'9/9 pass (guest_ampr_markers,guest_ampr_threads,guest_ampr_cpp_error,guest_amm_placement, 5 ×guest_apr_read_*). Withada5ad0990'sExport.cpprestored,guest_ampr_testsfails at the padding check (GuestAmpr.cpp:540); with the head before that restored, at the Nop header check (GuestAmpr.cpp:68); withmain'sExport.cppandApr.cpprestored it aborts at the same check.tools/check_conventions.py --base origin/mainandtools/pr_overlap.pyclean. Not run against a title; the header word, sizes, ranges and error order match BunnyFl's emulator run of firmware 13.42 in this thread.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T11:22:27Z.
Review: APPROVED
Reviewed exact head
0924ce7. The one-dword NOP header carries its total dword count; append, construct, measure, execute, and malformed-record checks are internally consistent. Boundary coverage includes exact-buffer padding and odd alignment before another command. Local diff and conventions checks passed. Hosted policy checks pass and the author reports nine focused runtime tests pass on Linux; I did not rerun the AMPR suite locally. The debt entry now distinguishes NOP from the remaining emulator command format.Imported from boykopovar/AnyPS5. Originally posted by thepoppfish on 2026-10-25T11:25:46Z.
Review: COMMENTED
Additional recorder-only native Windows validation of exact head
0924ce7c38d0e3e3b88c215a6e238bdc3f907ec4, adding a platform not in the author's Linux test report. This is comment-only because the APR executor and complete GuestAmpr test were not run in this harness.Windows 11 build 26200, MSYS2 UCRT64 GCC 16.2.0-6, CMake 4.3.1, Ninja 1.13.2, Release
-O3 -DNDEBUGwith LTO:libSceAmpr/Export.cppand actual public headers with an external recorder probe. No replacement recorder functions, kernel adapters or behavior stubs. LTO discards unrelated exports; the first non-LTO standalone link needed those unrelated library dependencies and was a setup failure, not a PR defect.b91a6a60c5abe08be4a315cf2e1f42c11f414564builds but exits 1 at the recorder contract assertion, as expected. This is a runtime negative control, not a link failure.16ff208dc32cf3927ba1bae492eee363a5ae7ae8and whitespace pass. A tree-only merge with that main is clean (tree5277cd98643c17ec000b22887ba8dfb93c5cd8a9); it was not built/tested as a merged tree.This checks AnyPS5's internal record format and producer bounds. It does not independently validate PS5 wire encoding or console behavior, execute APR commands, run the full submitted GuestAmpr fixture, build shared libraries/full runtime, exercise a title/GPU, or certify hosted CI. The author checkout remains clean and unchanged. AI-assisted: yes, OpenAI Codex.
Native probe replay
Save the two files below outside the checkout. With GCC 16.2/CMake/Ninja on PATH and the checkout at the reviewed head:
For the negative control, save
git show b91a6a60c5abe08be4a315cf2e1f42c11f414564:core/libs/prx/libSceAmpr/Export.cppasBaselineExport.cppoutside the checkout. Configure a separate build with the same arguments plus-DAMPR_SOURCE=<harness>/BaselineExport.cpp; its probe should exit 1 withnative Ampr recorder contract failed.CMakeLists.txtWriterProbe.cpp