feat(libSceJxr): implement WMPAlloc, WMPFree and the memory stream #14631
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14631"
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 ahmadmuj on 2026-11-01T16:38:36Z.
What
Implements the jxrlib allocator pair and the memory stream in libSceJxr:
WMPAlloc,WMPFree,CreateWS_Memory,EOSWS_Memory,ReadWS_Memory,WriteWS_Memory,SetPosWS_MemoryandGetPosWS_Memory.They follow the pinned jxrlib strcodec.c line by line:
WMPAllocis guestcalloc(1, cb), -101 on failure;WMPFreefrees a non-null*ppvand clears it.CreateWS_Memoryallocates the 88-byteWMPStream(the existingJxr::Stream) and stores buffer, size, position 0 and the six callbacks.Closeis jxrlib'sCloseWS_Memory, which isn't in the export inventory, so it's a private_nid_no_patchhelper.cbCur + cbwraps, otherwise clamps and copies. Write returns -103 on wrap or past the end and leaves the position alone. SetPos has no bounds check, same as jxrlib.ppv, stream,poffPos, a buffer when at least one byte is copied) it throwsstd::invalid_argument, like readIS does. The well-defined null cases (past-end read, zero-byte copy, nullpvin create) return normally.This is the first way to create a stream for the merged readIS/writeIS. Debt entry added, and the "additional exports" count goes from 132 to 124.
Tested
Ubuntu 24.04 on WSL2, GCC 13.3, Release build.
ctest -R guest_jxr: 9/9 pass. New cases inJxrStream.cpp: allocation (zeroed, -101 onSIZE_MAX, free clears), create state and callbacks, read clamp / at-end / past-end / wrap, write overflow / wrap / zero-byte cases, EOS and positions, close through the stored callback, and readIS/writeIS driving a memory stream (full packet, clamped last packet, overflowing write returning -103 without advancing).libSceJxr.prxaborts withWMPAlloc_nid_postfix not implemented.SIZE_MAX, positions past the end. Return values, stream state,fMem, GetPos output and buffer bytes all match (2.46M checks, 0 mismatches). WMPAlloc/WMPFree also match for sizes 0 toSIZE_MAX.public_headerspasses;python3 tools/check_conventions.py --base origin/mainpasses.Not tested: console behaviour (no PS5 or dumps), Windows. No title is known to call these yet.
Overlap:
tools/pr_overlap.py --branch(1833 open PRs) flags only #14425 (PKAlloc), on the debt file's export-count line: both PRs lower the 132. No shared export or test case. Whichever lands second fixes that one number.gh search prsfinds no other PR on these names.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 CnRJay on 2026-11-01T19:49:56Z.
Review: COMMENTED
Correction (2026-11-01): the title-ID/log demand below is not a CONTRIBUTING requirement;
Unblocks: noneis allowed. The technical points below are unaffected.Unblocks is none and the body names no title that calls
WMPAlloc/CreateWS_Memoryon main. The comparison is against jxrlib'sstrcodec.csource, which shows the contract, not that a title reaches these eight exports. Please add the title ID and the log line (unresolved import orNotImplementedhit with the queue position) that ties this to a running title; otherwise it is the export-only pattern.One code question:
ReadWS_Memoryreturns success without copying when the position is past the end, andSetPosWS_Memoryaccepts any position with no bound, as jxrlib does. Withstate[MemoryPosition]guest-controlled throughSetPos,buffer + positionon the write path is only guarded by theMemorySize < position + sizecheck, which holds. Is the nullbufferwith nonzeroMemorySizethrow (APS5_INVALID_ARG_EX) what jxrlib does, or a crash there? The body says it throws where jxrlib would dereference null; a guest that relies on that crash cannot exist, so fine, but please say whether any title was seen passing a null buffer.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T07:20:47Z.
Review: COMMENTED
Reviewed — no blocking findings; the JXR memory stream is implemented, and its tests passed on Windows
This PR replaces the
NotImplementedstubs forWMPAlloc,WMPFreeand the memory-stream callbacks inlibSceJxrwith working code: a calloc-backed allocation, and a memory stream with bounded read, write, seek and end-of-stream logic. The Windows CTest run passed the JXR lookup cases andguest_jxr_stream. I read the production change in full. I did not read the test bodies inJxrStream.cpp.What I ran
03f2eb905b61663f3ddc1ca9e7001eb7b3cae9b5; basef2d874c1fdccf781c0fa5d86619bb5dd8894b958. 4 files, +224/-25:libSceJxr/Export.cpp(+84/-25),libSceJxr/include/Api.hpp(+16/-8),core/libs/tests/JxrStream.cpp(+145), and a debt line.Export.cppandApi.hppdiffs in full. The memory stream keeps buffer, size and position instate. Reads and writes check for overflow and clamp to the buffer size, and anendcheck reports end of stream.CloseWS_Memoryfrees the stream throughWMPFree.guest_jxr_lookup_reference,guest_jxr_lookup, its patched and padding variants (Test #2274 to #2280),guest_jxr(Test #2281) andguest_jxr_stream(Test #2282) all passed.JxrStream.cppas possibly unregistered. Not investigated further.Results
guest_jxr_stream(hosted, Windows)inttostd::int64_tin this PR; not compared with PS5JxrStream.cppRead-only check output
Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: passed (137 symbols). Stack check: passed, no errors. Hosted:
gh api repos/boykopovar/AnyPS5/commits/03f2eb905b61663f3ddc1ca9e7001eb7b3cae9b5/check-runs, and the Windows job log.Negative control
Not run here. A negative control needs a local build and run of the JXR tests, and code from this head is not run here.
Findings
Blocking
None from the code read.
Non-blocking
inttostd::int64_t(andEOSWS_Memorytostd::int32_t). These are this PR's choices. They were not compared with the PS5 signatures in this pass.Sources
github.com/boykopovar/AnyPS5@03f2eb905b/core/libs/prx/libSceJxr/Export.cppgithub.com/boykopovar/AnyPS5@03f2eb905b/core/libs/prx/libSceJxr/include/Api.hppgithub.com/boykopovar/AnyPS5@03f2eb905b/core/libs/tests/JxrStream.cppwindowson03f2eb905bNot verified
JxrStream.cpp.To get this to a good state