feat(libSceNpCommon): implement sce::np::MemoryStreamReader and MemoryStreamWriter #13281
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13281"
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 hypermoist on 2026-10-30T11:41:38Z.
What
Implements
sce::np::MemoryStreamReaderandsce::np::MemoryStreamWriter(12 exports) fromlibSceNpCommon.sprxof firmware 13.60 (read from disassembly, not measured on a console).main: 6 had placeholderint (void)declarations: readerC1andD0; writerD0,D1,D2andWrite.C2,D1,D2andRead; writerC1andC2.Layout (declared in
Api.hppasNpMemoryStreamReader/NpMemoryStreamWriter, 32 bytes): vtable, buffer pointer, size, position. The reader vtable is{0, 0, D1, D0, Read}, the writer one{0, 0, D1, D0, Write}.(buffer, size): set the vtable, buffer and size, and position 0.operator delete(void*, size_t)with size0x20(libc's_ZdlPvm).Read(Handle*, void* out, size_t n, size_t* read): copiesmin(n, size - position)bytes when the position is below the size, otherwise 0, and advances the position. It always writes the count throughreadand returns 0.Write(Handle*, const void* data, size_t n, size_t* written):size - positionunsigned, or 0 when the size is 0. Ifnexceeds it, it returns0x80559E0Dand changes nothing; otherwise it copies;nand writesnthroughwrittenwhen that is not null.Handle*argument is ignored by both.The debt file records the asymmetries kept from the module:
Readdoes not check its count pointer, and a position past a non-zero size is not refused byWrite.Tested
Linux (CachyOS, GCC 16.2, Release):
ctest --test-dir build -R 'np_common|public_headers' --output-on-failure, 70/70 passed. The full suite passed apart fromguest_freetype, which fails the same way here because my local3rdparty/freetypecheckout is not at the pinned commit; this PR does not touch FreeType.Firmware differential: 13,400 cases, run from the module's code under unicorn and replayed through this implementation, with 0 mismatches.
Read: 5,000 cases over sizes 0–127, positions below, at and past the end, and counts up to 150. The position, the reported count and the destination with an 8-byte0xCCmargin are compared.Write: 6,000 cases, of which 1,946 are refused with0x80559E0D. They cover null buffers, size 0, positions past the end, and calls with and without a count pointer. The position, the reported count and the whole stream buffer are compared.np_memory_stream_make_cases.py(withnp_memory_stream_replay.cpp) in this gist, with theemucall.pyrunner. It needs a decrypted module, which is not attached.Guest test:
TestMemoryStreamsinGuestNpCommonRuntime.cppchecks:D0is not run in the test: libc's globaloperator newneeds the application heap's process parameters, which this test executable does not set up.Mutation check: I changed 6 single lines, one at a time. The test and the differential both catch 5:
mindropped fromRead;<=for the room check;Write;The survivor,
position <= sizeinRead, is equivalent: at the end it copies 0 bytes either way.Windows not built. Not run on a console.
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)NotImplementedstubs (readerC2,D1,D2,Read; writerC1,C2), so it drops them fromInventoryExports.cppafter this lands. #13120 already does the same for #13130's exports and declaresDepends on: #13130. Agreed with its author (comment): #13120 has removed these declarations and declaresDepends on: #13130, #13270, #13277, #13281.Assisted With AI: Yes. All tests were run locally on computer hardware (AMD Ryzen 5 5600G, 32 GB RAM, NVIDIA GeForce RTX 3060, CachyOS Linux 7.3, GCC 16.2), not on an actual console.
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T11:56:26Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The implementation has extensive author-reported tests, but its landing order with #13120 is still awaiting agreement despite six identical exports.
What I ran
Reviewed head
38bd414bee3ca9de3a1483ccd05e69f1e392f35eagainst PR base1c6b316cf762c7a8d34623907d62bc1cba2217b6; the current-main merge preview against51c31ea17e9f66cb36fe9655ec31c81610bfcfc9was clean. Environment: Debian 12 x86-64, Python 3.11.2, Git 2.39.5. I inspected the implementation and guest assertions but did not build or run C++ tests.Results
passed_with_warningsfor 319 symbols; seven lexical warnings identify internal helper definitions without public-header declarations. The audit does not prove binary ABI correctness.51c31ea17e9f66cb36fe9655ec31c81610bfcfc9.TestMemoryStreams; I inspected reader/writer bounds, return/count behavior, and the new assertions. I did not run these C++ tests.Unedited local output
Findings
Blocking
The PR says
Depends on: none, but it overlaps #13120 on six exact MemoryStream exports. The #13120 author has a current comment proposing that #13281 land first and that #13120 then drop those six stubs, and is explicitly awaiting agreement. The repository requires authors to agree on the order for overlapping exports and record the dependency/order on the checklist. Please confirm the proposed order with the #13120 author and record the agreed relationship; if #13120 lands first instead, update this PR against it and declare that dependency.Non-blocking
The reported differential and focused test coverage is detailed, but it has not been independently reproduced here. The D0 destructor is also explicitly untested in the guest test because the test executable lacks the application heap setup.
Sources
Not verified
I did not build or run the C++ tests, reproduce the firmware differential, test Windows or console behavior, or observe hosted Windows CI completion. The isolated precheck could not run its ABI and test-quality helper scripts because they are absent from that checkout; I ran the ABI audit from the workspace. Linux and specialized hosted jobs were skipped.
To get this to a good state
Please get agreement on which PR lands first for the six shared exports and record that order and any dependency in the checklist. I will rerun the diff, conventions, ABI, and dependency checks on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T12:22:53Z.
Review: CHANGES_REQUESTED
Re-checked — new head, changes still needed
At head
c3d3296c56cff04d5705460d7cc67282dc56aaee, the MemoryStream implementation is unchanged, but its proposed landing order remains unconfirmed and the branch now conflicts with currentmain.What I ran
Head:
c3d3296c56cff04d5705460d7cc67282dc56aaee; PR base SHA reported by GitHub:51c31ea17e9f66cb36fe9655ec31c81610bfcfc9. Currentmainat the check was42d009f5f37c8f388b01fbfe38d2e704c792c46f. I used Linux x86_64 / Python 3.11.2. No local build or C++ tests were run.Results
passed_with_warningsfor 319 symbols; the seven warnings are the same private helper definitions previously inspected, not the 12 MemoryStream exports.Runtime.cpp,include/Api.hpp,GuestNpCommonRuntime.cpp, anddocs/dev/debt/libSceNpCommon.md. The isolated merge preview confirms content conflicts, so this is no longer only a behind-main condition.Unedited merge-conflict summary
Negative control
No new negative control was run locally. The previous mutation results remain author-reported; the PR-specific files did not change between the previously reviewed head and this merge commit.
Findings
Blocking
mainonly through51c31ea, while currentmainis42d009f. A clean merge preview now reports content conflicts in the four files listed above, including the files changed by this PR. Please update the branch and resolve them against currentmainbefore approval.Non-blocking
The source and tests for the MemoryStream feature are unchanged in the new merge commit. The author reports rerunning the focused tests and firmware differential on this head; I did not independently reproduce them.
Sources
Not verified
I did not build or run the C++ tests, reproduce the firmware differential, run Windows tests, or test on a console. Linux and specialized hosted jobs were skipped. The ABI helper's warnings do not establish ABI correctness.
To get this to a good state
Please confirm the landing order with the #13120 author, record it in the checklist, and update this branch onto current
mainresolving the four conflicts. On the new head I will rerun conventions, ABI audit, diff check, and the dependency/mergeability check; the same focused test command and differential evidence should be reported for that head.