feat(libSceJxr): detach bitstream writers #16278

Closed
MarrasFederico wants to merge 3 commits from upstream-pr/16278 into main
MarrasFederico commented 2026-11-06 02:49:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-11-06T02:49:49Z.


What

Flush full packets then write remaining bytes through the stream currently stored in the bit state, observing callback mutations. Propagate negative errors while preserving attachment, and return the full final result after clearing the stream on nonnegative completion. Preserve source pointer-difference conversion to size_t; undefined pointer/arithmetic and unaligned-bit paths throw.

detachISWrite not measured on a PS5: guest ABI/layout are inferred from pinned strcodec.c. Flushes full packets via writeIS, then writes the remaining byte count through the current stream, observing callback field changes. Negative results propagate without clearing the stream; a nonnegative final write clears it and returns the full result. Unaligned bit positions, null pointers and overflowing address arithmetic throw; negative pointer differences convert to size_t as in the source. Profiling is disabled. Closes when: console function and ABI are disassembled or measured on a PS5

Other open work changes nearby shared headers, tests and debt entries. These changes concern different exports; shared insertions must be reconciled in merge order.

python3 tools/pr_overlap.py --branch feat/jxr-detachiswrite --repo boykopovar/AnyPS5 --base main --jobs 2 examined 1885 open PRs. It returned 2 because some older heads cannot merge with its base; this is not a clean tool exit. I manually compared all 18 reported shared-file heads with their own merge bases, including original placeholder locations and newly added export declarations/definitions: none implements or changes this export. Pre-implementation function-name searches and a review of the broader implementation PRs found no existing implementation of this export.

Tested

Ubuntu 26.04.1 LTS x86-64, GCC 15.2.0, Release, BUILD_TESTING=ON, base c36ab99c74cde292a75c75c6ab2dc989a047bb7d. No PS5 hardware or title was tested; Windows and macOS were not tested.

  • Built guest_jxr_stream_tests serially with nice -n 19 cmake --build build --parallel 2 --target guest_jxr_stream_tests.
  • ctest --test-dir build -R '^guest_jxr_stream$' --output-on-failure passes.
  • Negative control: replaced the implemented body with its throwing placeholder while retaining the corrected declaration, rebuilt the target and observed the new checks fail. Restored the body, rebuilt and reran the test successfully.
  • python3 tools/check_conventions.py --base upstream/main, git diff --check and the public-header declaration/umbrella audit pass.

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

Merge verification: updated against main 1be701e166ca3ea627b3282fb7886b3f71143091 with a normal merge. Main and this PR are preserved independently; the implemented function bodies are unchanged. Built guest_jxr_stream_tests with nice -n 19 cmake --build build --parallel 2 --target guest_jxr_stream_tests; ctest --test-dir build -R '^guest_jxr_stream$' --output-on-failure passes. Conventions and the public-header audit pass. No console or Windows run.
The additional-export inventory counts 81 remaining throwing placeholders.
The previously added empty-final-write review regression cases are retained, including the negative 64-bit final result after a successful 4096-byte flush.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5182089867 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16278). Originally posted by [MarrasFederico](https://github.com/MarrasFederico) on 2026-11-06T02:49:49Z. --- ### What Flush full packets then write remaining bytes through the stream currently stored in the bit state, observing callback mutations. Propagate negative errors while preserving attachment, and return the full final result after clearing the stream on nonnegative completion. Preserve source pointer-difference conversion to size_t; undefined pointer/arithmetic and unaligned-bit paths throw. [detachISWrite](https://github.com/MarrasFederico/AnyPS5/blob/e03f3b82e6c29d296f9977c544e1cca4a7248e82/core/libs/prx/libSceJxr/Export.cpp#L471) not measured on a PS5: guest ABI/layout are inferred from pinned [strcodec.c](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/strcodec.c#L1180-L1196). Flushes full packets via `writeIS`, then writes the remaining byte count through the current stream, observing callback field changes. Negative results propagate without clearing the stream; a nonnegative final write clears it and returns the full result. Unaligned bit positions, null pointers and overflowing address arithmetic throw; negative pointer differences convert to `size_t` as in the source. Profiling is disabled. Closes when: console function and ABI are disassembled or measured on a PS5 Other open work changes nearby shared headers, tests and debt entries. These changes concern different exports; shared insertions must be reconciled in merge order. `python3 tools/pr_overlap.py --branch feat/jxr-detachiswrite --repo boykopovar/AnyPS5 --base main --jobs 2` examined 1885 open PRs. It returned 2 because some older heads cannot merge with its base; this is not a clean tool exit. I manually compared all 18 reported shared-file heads with their own merge bases, including original placeholder locations and newly added export declarations/definitions: none implements or changes this export. Pre-implementation function-name searches and a review of the broader implementation PRs found no existing implementation of this export. ### Tested Ubuntu 26.04.1 LTS x86-64, GCC 15.2.0, Release, `BUILD_TESTING=ON`, base `c36ab99c74cde292a75c75c6ab2dc989a047bb7d`. No PS5 hardware or title was tested; Windows and macOS were not tested. - Built `guest_jxr_stream_tests` serially with `nice -n 19 cmake --build build --parallel 2 --target guest_jxr_stream_tests`. - `ctest --test-dir build -R '^guest_jxr_stream$' --output-on-failure` passes. - Negative control: replaced the implemented body with its throwing placeholder while retaining the corrected declaration, rebuilt the target and observed the new checks fail. Restored the body, rebuilt and reran the test successfully. - `python3 tools/check_conventions.py --base upstream/main`, `git diff --check` and the public-header declaration/umbrella audit pass. <!-- 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. --> ### 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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no --> Merge verification: updated against main `1be701e166ca3ea627b3282fb7886b3f71143091` with a normal merge. Main and this PR are preserved independently; the implemented function bodies are unchanged. Built `guest_jxr_stream_tests` with `nice -n 19 cmake --build build --parallel 2 --target guest_jxr_stream_tests`; `ctest --test-dir build -R '^guest_jxr_stream$' --output-on-failure` passes. Conventions and the public-header audit pass. No console or Windows run. The additional-export inventory counts 81 remaining throwing placeholders. The previously added empty-final-write review regression cases are retained, including the negative 64-bit final result after a successful 4096-byte flush.
ahmadmuj commented 2026-11-06 12:18:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-11-06T12:18:25Z.

Review: COMMENTED


Checked head e03f3b82e6c29d296f9977c544e1cca4a7248e82, PR base 9775ae22cee9de1e46c56c2013dd8cb864eb2bb8, and main source e3a14a86e4c9f0db6314a4a4e6527d1a60c44842.

On Ubuntu 24.04.2 / WSL2, GCC 13.3, Release:

  • guest_jxr_stream passes.
  • An isolated probe calls the actual module and pinned jxrlib f7521879862b9085318e814c6157490dd9dbbdb4 independently. All 30 cases / 1,770 assertions pass: empty, 1-byte, 4095-byte, 4096-byte and 4097-byte output, both ring halves, and final results 0, 0x123456789, -0x123456789. It checks exact callback bytes, sizes, relative addresses, return values and all BitIo fields. Native sizeof(ERR)==8 is asserted.
  • ctest -R '^guest_jxr_(stream|detach_write_probe)$' -V passes both tests without skips. Conventions passes.

Could you add the empty final callback cases to DetachWrites? In particular, test a negative final result after a successful 4096-byte flush: the final callback receives zero bytes, its error returns unchanged, and the stream stays attached. Pinned jxrlib requires this callback. A disposable change that skips it passes the existing stream test but fails the probe. Clearing attachment before handling its error also fails the probe. The restored head passes.

No production defect found in these cases. This is exact-head CPU evidence; the current merge conflict remains. Main's throwing body fails a control in the head build, not a separate main build. Console ABI, titles and GPU behavior are not tested; GPUs: n/a.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5799968245 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16278#pullrequestreview-5799968245). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-11-06T12:18:25Z. **Review:** COMMENTED --- Checked head `e03f3b82e6c29d296f9977c544e1cca4a7248e82`, PR base `9775ae22cee9de1e46c56c2013dd8cb864eb2bb8`, and main source `e3a14a86e4c9f0db6314a4a4e6527d1a60c44842`. On Ubuntu 24.04.2 / WSL2, GCC 13.3, Release: - `guest_jxr_stream` passes. - An isolated probe calls the actual module and pinned jxrlib `f7521879862b9085318e814c6157490dd9dbbdb4` independently. All 30 cases / 1,770 assertions pass: empty, 1-byte, 4095-byte, 4096-byte and 4097-byte output, both ring halves, and final results `0`, `0x123456789`, `-0x123456789`. It checks exact callback bytes, sizes, relative addresses, return values and all BitIo fields. Native `sizeof(ERR)==8` is asserted. - `ctest -R '^guest_jxr_(stream|detach_write_probe)$' -V` passes both tests without skips. Conventions passes. Could you add the empty final callback cases to `DetachWrites`? In particular, test a negative final result after a successful 4096-byte flush: the final callback receives zero bytes, its error returns unchanged, and the stream stays attached. [Pinned jxrlib requires this callback](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/image/sys/strcodec.c#L1180-L1196). A disposable change that skips it passes the existing stream test but fails the probe. Clearing attachment before handling its error also fails the probe. The restored head passes. No production defect found in these cases. This is exact-head CPU evidence; the current merge conflict remains. Main's throwing body fails a control in the head build, not a separate main build. Console ABI, titles and GPU behavior are not tested; GPUs: n/a.

Pull request closed

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!16278
No description provided.