feat(libSceNpCommon): implement the sce::np::StreamReader and StreamWriter helpers #13345
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13345"
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-30T13:10:31Z.
What
Implements the
sce::np::StreamReaderandsce::np::StreamWriterhelper methods (14 exports) fromlibSceNpCommon.sprxof firmware 13.60 (read from disassembly, not measured on a console).main: 4 had placeholderint (void)declarations:Read(with aStreamCtx),ReadAll,SkipDataandWriteData, each without a context unless stated.StreamCtxoverloads ofReadAll,ReadData,SkipAll,SkipData,WriteDataandWriteFilledData, plusReadData,SkipAllandWriteFilledDatawithout a context andWritewith one.Contract. Each helper calls the stream's own virtual
ReadorWrite, which is slot+0x10of its vtable:(self, handle, buffer, size, size_t* count). The context variants then pass every chunk to the context's slot+0x10:(ctx, data, count). The objects are declared inApi.hppasNpStreamReader,NpStreamWriterandNpStreamCtx, each just a vtable pointer. The handle is passed through. A negative stream or context result is returned as is; positive results count as success and become 0.Read/Write(with a context): one stream call, then the context sees the reported count.ReadData: reads until the buffer is full or the stream reports 0 bytes. It returns0x80559E10if the buffer wasn't filled, and writes the total through the count pointer when that isn't null, including after a failure.ReadAll: likeReadData, but a short stream succeeds and reports what it got. A full buffer is followed by a one-byte probe read: if the stream has more data, it returns0x80559E0Dand the count is not written. A stream that reports more bytes than it was asked for reaches the module's assertion, which callssceNpPanic, as here.SkipAll: reads 256-byte chunks into a local buffer until the stream reports 0. It adds each reported count to the counter, even when that read or its context call fails.SkipData(size): skips in chunks of at most 256 bytes using theReadDataloop. It adds what each chunk'sReadDatacompleted before any failing call, never the failing call's own count, and stops on a failure or a short chunk (0x80559E10). A size of 0 or less does nothing.WriteData: writes until everything has been accepted, then writes the total through the count pointer when that isn't null.WriteFilledData(fill, size): writes a 256-byte buffer of the fill byte untilsizebytes are accepted. A size of 0 or less does nothing.The debt file records the module behaviour kept as is:
ReadAllassertion;WriteDataandWriteFilledDatalooping for as long as the stream accepts 0 bytes;SkipAlladding the count of a failed read, whileSkipDataadds only the bytes completed before the failure (for a first read returning -1 with count 7,SkipAlladds 7 andSkipData0);Tested
The tests, the differential and the corruption check below ran on head
b0853d70abd. The mutation check ran on the same helper code before the latestmainmerge. Linux (CachyOS, GCC 16.2, Release):ctest --test-dir build -R 'np_common|public_headers' --output-on-failure, 70/70 passed.guest_np_common_runtimepassed 3 of 3 runs. The full suite (2,998 tests), run on this change before the latestmainmerge, also passed apart fromguest_freetype, which fails here because my local3rdparty/freetypecheckout is not at the pinned commit; this PR does not touch FreeType.Firmware differential: 20,426 cases, run from the module's code under unicorn and replayed through this implementation, with 0 mismatches.
+0x10follows a script of results and byte counts. The scripts include failures, positive results, short reads and writes, counts larger than requested, and a stream that ends early.0xCCmargin;ReadAllassertion.np_stream_helpers_make_cases.pyandnp_stream_helpers_replay.cppin this gist, together withemucall.py.emucall.pygained acallback()method that lets a guest vtable point at Python code. It needs a decrypted module, which is not attached.Guest test:
TestStreamHelpersinGuestNpCommonRuntime.cppuses a chunked reader, a collecting writer and a summing context to check:ReadDatafilling a buffer across short reads and reporting a stream that ends early;ReadAllwith a short stream, an exactly full buffer, and a stream longer than the buffer;SkipDataadding to the counter;SkipAllstopping at the end and at a failed read;WriteDatathrough short writes;WriteFilledDatain chunks, and with a negative size;Writemaking a single stream call.Mutation check: I changed 9 single lines, one at a time, and the differential catches all 9:
ReadAllprobe check dropped;ReadAlltreating an empty first read as more data (this one hangs, as the module would);SkipAllcounter updated after the error check;ReadDatastopping on<instead of!=;SkipDataloop bound changed from>= 1to> 1;SkipDatachunk not capped by the remaining size;WriteDatacontext call dropped;Readreturning positive results as they are.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)mainasNotImplementedstubs, so it drops them fromInventoryExports.cppafter this lands. Agreed with its author (comment): #13120 has removed the ten declarations and declaresDepends on: #13130, #13270, #13277, #13281, #13345.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-30T13:14:02Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The implementation review found no confirmed code defect, but the landing order for 10 exports shared with open PR #13120 is not yet agreed or recorded.
What I ran
Reviewed head
b0853d70abdca600c552e9d0437d14df7ceaeecdagainst baseee9a9a66cffb77ba42781b66d764e96d22843554; the merge preview against the current target was clean. Environment: Debian 12 x86-64, Python 3.11.2, Git 2.39.5. I did not build or compile.Results
Unedited local check output
Conventions:
Precheck summary:
The precheck's reported failures were missing workspace-local helpers (
pr_abi_audit.pyandpr_test_quality.py) in its isolated PR worktree; they are not findings against the submitted source.Findings
Blocking
NotImplementedstubs. The PR description proposes that #13345 land first, but the latest discussion on #13120 asks its author to confirm that order and has no reply yet. The repository asks contributors to agree on overlapping exports and record the order withDepends on; without coordination, landing #13120 after this change would reintroduce duplicate definitions. Please obtain and record the agreed landing order, and ensure the second PR removes the overlapping declarations before it lands.Non-blocking
Sources
Depends onrule.Not verified
I did not independently run the C++ tests, a build, the firmware differential, the mutation checks, or console behavior. Hosted CI was still queued.
To get this to a good state
Please record an agreed order for #13345 and #13120 and make sure the PR that lands second removes the shared exports. I will re-check the overlap and rerun the relevant checks on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T13:34:08Z.
Review: APPROVED
Re-checked — overlap resolved, looks good
The authors recorded the landing order and removed the shared exports from #13120; I found no remaining blocker in the reviewed head.
What I ran
Reviewed head
b0853d70abdca600c552e9d0437d14df7ceaeecdagainst PR baseee9a9a66cffb77ba42781b66d764e96d22843554; the stack check also previewed that head against currentmainda026c70655a132031d45e2008c24f993870d801and reported a clean merge. Environment: Debian 12 x86-64, Python 3.11.2, Git 2.39.5. No build or compilation was run.Results
main. #13120 now depends on #13345 and no longer declares the ten overlapping exports.passed_with_warnings. It reports sevenRuntime.cpphelper definitions without public declarations. This lexical warning is not a full ABI validation.Unedited local check output
Diff check produced no output and exited successfully.
Precheck summary:
The precheck could not find
tools/pr_abi_audit.pyortools/pr_test_quality.pyin its isolated checkout. I ran the ABI audit from the local workspace separately. Conventions output:Findings
Blocking
None identified.
Non-blocking
The C++ tests, differential run, corruption check, and mutation checks are author-reported rather than independently reproduced here.
Sources
Not verified
I did not build or run C++ tests locally. At final refresh, the exact-head Windows job was queued, the library-portability job was in progress, and the new conventions and labels jobs were queued. Linux and specialized jobs were skipped by the hosted workflow.