Skip to content

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

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
ahmadmuj:fix/anyps5-jxr-memory-stream
Nov 5, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
ahmadmuj:fix/anyps5-jxr-memory-stream

Conversation

@ahmadmuj

@ahmadmuj ahmadmuj commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

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

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks. I compared these with jxrlib at the pinned commit (image/sys/strcodec.c lines 246-447) and they match, including the read clamp and the unchecked SetPosWS_Memory. The tests cover the edges well.

One thing: this is ported code, so the project rule on ported code applies: code copied or ported from a permissively licensed project keeps that project's licence notice. Please add jxrlib's notice from the top of strcodec.c (lines 1-27, from the //*@@@+++@@@@ line to the closing //*@@@---@@@@ line) to the top of core/libs/prx/libSceJxr/Export.cpp. One notice there also covers the PKFree, readIS and writeIS ports already in that file.

Reviewed at 03f2eb9.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 14425 docs/dev/debt/libSceJxr.md L15

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Progress report (03cfa4c → 1a28810)

📈 System libraries: 26.73% (+0.02%, +8 implemented functions)

✅ 8 implemented
Library Name
libSceJxr CreateWS_Memory_nid_postfix
libSceJxr EOSWS_Memory_nid_postfix
libSceJxr GetPosWS_Memory_nid_postfix
libSceJxr ReadWS_Memory_nid_postfix
libSceJxr SetPosWS_Memory_nid_postfix
libSceJxr WMPAlloc_nid_postfix
libSceJxr WMPFree_nid_postfix
libSceJxr WriteWS_Memory_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceJxr 5/136 (3.68%) 13/136 (9.56%) +5.88%

@CnRJay CnRJay left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ AMD GPU test: passed

PR head 03f2eb9 merged onto main 4639eff · tested 2026-11-05 09:42 UTC · 14 min

GPU AMD Radeon RX 6300 (RADV NAVI24), driver Mesa 25.2.8-0ubuntu0.24.04.4, Vulkan 1.4.318
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-42-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 1,167 passed · 5 failed (0 new, 4 also fail on main, 1 unstable on main) · 9 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 1,181 of 3,962 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (570 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_pipeline_journal 120.0 s, ⚠️ public_headers 73.5 s, ⚠️ agc_driver_lazy_resolved_abi 59.5 s, ⚠️ agc_driver_image_sample_unnormalized 49.2 s, ⚠️ agc_driver_indexed_copy 33.5 s
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)
agc_driver_pipeline_journal: failed in 9 of the last 10 main runs
Failing on main too (4, not counted against this PR)
agc_driver_image_table
agc_driver_native_depth_bda_clear
agc_driver_native_multisample_depth
agc_driver_submit_progress
Validation IDs already present on main (4 IDs in 487 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (487 tests): agc_driver_address_draw_space_reuse, agc_driver_address_passes, agc_driver_alias_copy_label, agc_driver_alpha_to_coverage, agc_driver_array_layer_target, agc_driver_bc_block_copy, agc_driver_bda_anchor_reads, agc_driver_bda_span_reads, and 479 more
VUID-vkCmdCopyImage-srcImage-01548 (4 tests): agc_driver_depth_clear_hle, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth
VUID-vkCmdCopyImage-srcImage-01551 (4 tests): agc_driver_depth_clear_hle, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (2 tests): agc_driver_prepared_exports, agc_driver_srgb8_color_target
Skipped (9)
agc_driver_copied_writer_label_order: skipped, the device reports a minStorageBufferOffsetAlignment of 4, so the dispatch binds its record at +0x1004 in place and nothing is written back; the test needs an alignment above 4
agc_driver_float16_unused_nan_payloads: skipped, the device has no native f16 conversions with RTE rounding and kept f16 denormals
agc_driver_gcn_display_present: skipped, no display: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
agc_driver_linear_target_direct_write_completion: skipped, the device does not keep host imports write-watched, so no completion stamp over the target is tracked
agc_driver_ngg_vertex_wave_reduction: skipped, s3 describes a 32-lane wave only on 32-lane subgroups, and the device has 64 lanes
agc_driver_recorded_draw_staging: skipped, the device does not keep host imports write-watched, so the target is never resident
agc_driver_scattered_runs: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_driver_sparse_dma_buf_import: skipped, host imports are unavailable: /dev/udmabuf is not accessible
Reproduce
git fetch origin 03f2eb905b61663f3ddc1ca9e7001eb7b3cae9b5 4639eff7f4c23325a916875a0e37f1e312fa18f4
git checkout 4639eff7f4c23325a916875a0e37f1e312fa18f4 && git merge --no-ff 03f2eb905b61663f3ddc1ca9e7001eb7b3cae9b5
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 12 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 16 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 5, 2026
The WMPAlloc, WMPFree and memory stream ports, like PKFree, readIS and writeIS, follow jxrlib's strcodec.c; the notice is lines 1-27 of that file at f7521879862b9085318e814c6157490dd9dbbdb4.
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Hi @ahmadmuj, thanks for the WMPAlloc, WMPFree and memory stream work. We merged main into your branch (the only conflict was the export count in the technical debt file, now 123) and added jxrlib's licence notice, lines 1-27 of image/sys/strcodec.c, to the top of core/libs/prx/libSceJxr/Export.cpp, as asked on 1 Nov. Nothing else changed.

@oneandonlydean
oneandonlydean merged commit 2beed81 into boykopovar:main Nov 5, 2026
12 checks passed
@ahmadmuj

ahmadmuj commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

On the remaining null-buffer question: jxrlib accepts null during construction, then passes it to memcpy when a copy occurs. Our positive-length copy throws std::invalid_argument instead. We have no title capture showing a null buffer; console behavior remains unverified.

guest_jxr_stream is registered in the JXR CMake file. All nine local JXR tests pass on our merge with main 4180951e. I compared its JXR code and tests with merged head 1a288102; they match apart from trailing licence whitespace. No further branch update is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs needs rebase Conflicts with main, rebase needed prx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants