feat(libSceJxr): implement WMPAlloc, WMPFree and the memory stream #14631

Merged
ahmadmuj merged 3 commits from upstream-pr/14631 into main 2026-11-05 15:09:02 +00:00
ahmadmuj commented 2026-11-01 16:38:36 +00:00 (Migrated from github.com)

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_Memory and GetPosWS_Memory.

They follow the pinned jxrlib strcodec.c line by line:

  • WMPAlloc is guest calloc(1, cb), -101 on failure; WMPFree frees a non-null *ppv and clears it.
  • CreateWS_Memory allocates the 88-byte WMPStream (the existing Jxr::Stream) and stores buffer, size, position 0 and the six callbacks. Close is jxrlib's CloseWS_Memory, which isn't in the export inventory, so it's a private _nid_no_patch helper.
  • Read returns 0 without copying when the position is past the end, -103 when cbCur + cb wraps, 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.
  • Where jxrlib would dereference null (ppv, stream, poffPos, a buffer when at least one byte is copied) it throws std::invalid_argument, like readIS does. The well-defined null cases (past-end read, zero-byte copy, null pv in 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 in JxrStream.cpp: allocation (zeroed, -101 on SIZE_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).
  • Red check: the new test against main's libSceJxr.prx aborts with WMPAlloc_nid_postfix not implemented.
  • Differential against host jxrlib built from the submodule (local only, not committed): 20,000 random sequences of 40 operations on buffers of 0-16 bytes, sizes up to 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 to SIZE_MAX.
  • public_headers passes; python3 tools/check_conventions.py --base origin/main passes.

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 prs finds no other PR on these names.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5109364339 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14631). Originally posted by [ahmadmuj](https://github.com/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_Memory` and `GetPosWS_Memory`. They follow the pinned jxrlib [strcodec.c](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/strcodec.c#L246-L447) line by line: - `WMPAlloc` is guest `calloc(1, cb)`, -101 on failure; `WMPFree` frees a non-null `*ppv` and clears it. - `CreateWS_Memory` allocates the 88-byte `WMPStream` (the existing `Jxr::Stream`) and stores buffer, size, position 0 and the six callbacks. `Close` is jxrlib's `CloseWS_Memory`, which isn't in the export inventory, so it's a private `_nid_no_patch` helper. - Read returns 0 without copying when the position is past the end, -103 when `cbCur + cb` wraps, 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. - Where jxrlib would dereference null (`ppv`, stream, `poffPos`, a buffer when at least one byte is copied) it throws `std::invalid_argument`, like readIS does. The well-defined null cases (past-end read, zero-byte copy, null `pv` in 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 <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Ubuntu 24.04 on WSL2, GCC 13.3, Release build. - `ctest -R guest_jxr`: 9/9 pass. New cases in `JxrStream.cpp`: allocation (zeroed, -101 on `SIZE_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). - Red check: the new test against main's `libSceJxr.prx` aborts with `WMPAlloc_nid_postfix not implemented`. - Differential against host jxrlib built from the submodule (local only, not committed): 20,000 random sequences of 40 operations on buffers of 0-16 bytes, sizes up to `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 to `SIZE_MAX`. - `public_headers` passes; `python3 tools/check_conventions.py --base origin/main` passes. 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 prs` finds no other PR on these names. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
CnRJay commented 2026-11-01 19:49:56 +00:00 (Migrated from github.com)

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: none is allowed. The technical points below are unaffected.

Unblocks is none and the body names no title that calls WMPAlloc/CreateWS_Memory on main. The comparison is against jxrlib's strcodec.c source, which shows the contract, not that a title reaches these eight exports. Please add the title ID and the log line (unresolved import or NotImplemented hit with the queue position) that ties this to a running title; otherwise it is the export-only pattern.

One code question: ReadWS_Memory returns success without copying when the position is past the end, and SetPosWS_Memory accepts any position with no bound, as jxrlib does. With state[MemoryPosition] guest-controlled through SetPos, buffer + position on the write path is only guarded by the MemorySize < position + size check, which holds. Is the null buffer with nonzero MemorySize throw (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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729923821 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14631#pullrequestreview-5729923821). Originally posted by [CnRJay](https://github.com/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: none` is allowed. The technical points below are unaffected. Unblocks is none and the body names no title that calls `WMPAlloc`/`CreateWS_Memory` on main. The comparison is against jxrlib's `strcodec.c` source, which shows the contract, not that a title reaches these eight exports. Please add the title ID and the log line (unresolved import or `NotImplemented` hit with the queue position) that ties this to a running title; otherwise it is the export-only pattern. One code question: `ReadWS_Memory` returns success without copying when the position is past the end, and `SetPosWS_Memory` accepts any position with no bound, as jxrlib does. With `state[MemoryPosition]` guest-controlled through `SetPos`, `buffer + position` on the write path is only guarded by the `MemorySize < position + size` check, which holds. Is the null `buffer` with nonzero `MemorySize` throw (`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.
MarcZX10 commented 2026-11-02 07:20:47 +00:00 (Migrated from github.com)

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 NotImplemented stubs for WMPAlloc, WMPFree and the memory-stream callbacks in libSceJxr with 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 and guest_jxr_stream. I read the production change in full. I did not read the test bodies in JxrStream.cpp.

What I ran

  • Head 03f2eb905b61663f3ddc1ca9e7001eb7b3cae9b5; base f2d874c1fdccf781c0fa5d86619bb5dd8894b958. 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.
  • Read the Export.cpp and Api.hpp diffs in full. The memory stream keeps buffer, size and position in state. Reads and writes check for overflow and clamp to the buffer size, and an end check reports end of stream. CloseWS_Memory frees the stream through WMPFree.
  • Test source: read the test names only, through the CTest output.
  • Hosted, Windows CTest: 2594 of 2594 passed. guest_jxr_lookup_reference, guest_jxr_lookup, its patched and padding variants (Test #2274 to #2280), guest_jxr (Test #2281) and guest_jxr_stream (Test #2282) all passed.
  • Read-only checks from the trusted main checkout: diff check, conventions and PR template, and the stack check all passed (no declared dependencies, no errors). ABI audit passed: 137 symbols.
  • The test-quality helper flagged JxrStream.cpp as possibly unregistered. Not investigated further.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed conventions check from the main checkout
Mergeability and dependencies passed stack check: no declared dependencies, no errors
ABI audit (main-checkout tool) passed 137 symbols
JXR lookup cases and guest_jxr_stream (hosted, Windows) passed Test #2274 to #2282
Memory-stream logic (read) passed by reading overflow checks and clamping are present; no blocking defect found
Signatures against the PS5 headers not verified the return types were changed from int to std::int64_t in this PR; not compared with PS5
Test bodies in JxrStream.cpp not verified names only
Relinkers (hosted) skipped not run for this change
Negative controls not run no local build
Read-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

  • The exported return types moved from int to std::int64_t (and EOSWS_Memory to std::int32_t). These are this PR's choices. They were not compared with the PS5 signatures in this pass.

Sources

Not verified

  • The bodies of the tests in JxrStream.cpp.
  • The signatures against the PS5 headers.
  • The Linux build and runtime tests (not run).

To get this to a good state

  • Nothing blocking. Check the signatures against the PS5 headers if they are available.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5733185748 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14631#pullrequestreview-5733185748). Originally posted by [MarcZX10](https://github.com/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 `NotImplemented` stubs for `WMPAlloc`, `WMPFree` and the memory-stream callbacks in `libSceJxr` with 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 and `guest_jxr_stream`. I read the production change in full. I did not read the test bodies in `JxrStream.cpp`. ## What I ran - Head `03f2eb905b61663f3ddc1ca9e7001eb7b3cae9b5`; base `f2d874c1fdccf781c0fa5d86619bb5dd8894b958`. 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. - Read the `Export.cpp` and `Api.hpp` diffs in full. The memory stream keeps buffer, size and position in `state`. Reads and writes check for overflow and clamp to the buffer size, and an `end` check reports end of stream. `CloseWS_Memory` frees the stream through `WMPFree`. - Test source: read the test names only, through the CTest output. - Hosted, Windows CTest: 2594 of 2594 passed. `guest_jxr_lookup_reference`, `guest_jxr_lookup`, its patched and padding variants (Test #2274 to #2280), `guest_jxr` (Test #2281) and `guest_jxr_stream` (Test #2282) all passed. - Read-only checks from the trusted main checkout: diff check, conventions and PR template, and the stack check all passed (no declared dependencies, no errors). ABI audit passed: 137 symbols. - The test-quality helper flagged `JxrStream.cpp` as possibly unregistered. Not investigated further. - No MarcZX10 review at this head. ## Results | Check | Result | Note | | --- | --- | --- | | Diff check | passed | | | Conventions and PR template | passed | conventions check from the main checkout | | Mergeability and dependencies | passed | stack check: no declared dependencies, no errors | | ABI audit (main-checkout tool) | passed | 137 symbols | | JXR lookup cases and `guest_jxr_stream` (hosted, Windows) | passed | Test #2274 to #2282 | | Memory-stream logic (read) | passed by reading | overflow checks and clamping are present; no blocking defect found | | Signatures against the PS5 headers | not verified | the return types were changed from `int` to `std::int64_t` in this PR; not compared with PS5 | | Test bodies in `JxrStream.cpp` | not verified | names only | | Relinkers (hosted) | skipped | not run for this change | | Negative controls | not run | no local build | <details><summary>Read-only check output</summary> 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. </details> ## 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** - The exported return types moved from `int` to `std::int64_t` (and `EOSWS_Memory` to `std::int32_t`). These are this PR's choices. They were not compared with the PS5 signatures in this pass. ## Sources - Implementation: https://github.com/boykopovar/AnyPS5/blob/03f2eb905b61663f3ddc1ca9e7001eb7b3cae9b5/core/libs/prx/libSceJxr/Export.cpp - Header: https://github.com/boykopovar/AnyPS5/blob/03f2eb905b61663f3ddc1ca9e7001eb7b3cae9b5/core/libs/prx/libSceJxr/include/Api.hpp - Test: https://github.com/boykopovar/AnyPS5/blob/03f2eb905b61663f3ddc1ca9e7001eb7b3cae9b5/core/libs/tests/JxrStream.cpp - Windows job log: check-run `windows` on 03f2eb905b61663f3ddc1ca9e7001eb7b3cae9b5 ## Not verified - The bodies of the tests in `JxrStream.cpp`. - The signatures against the PS5 headers. - The Linux build and runtime tests (not run). ## To get this to a good state - Nothing blocking. Check the signatures against the PS5 headers if they are available.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!14631
No description provided.