feat(libSceJxr): implement PKAlloc #14425

Merged
AlexWhitehouse merged 1 commit from upstream-pr/14425 into main 2026-11-05 08:46:45 +00:00
AlexWhitehouse commented 2026-11-01 12:26:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexWhitehouse on 2026-11-01T12:26:24Z.


What

Implements PKAlloc (NID IXOD4hTCNU0) in libSceJxr, ported from jxrlib JXRGlue.c at the commit the debt file and 3rdparty/jxrlib pin.

  • It allocates cb zeroed bytes with the guest calloc(1, cb), the same application heap PKFree already frees to.
  • It stores the pointer through ppv, NULL on failure included, and returns WMP_errSuccess (0) or WMP_errOutOfMemory (-101), with ERR a signed 64-bit value as in the pinned headers.
  • A zero cb follows the guest calloc(1, 0).
  • A null ppv, which upstream dereferences, throws.

src/Allocation.cpp starts with the Microsoft copyright and licence notice from JXRGlue.c, lines 1-27. Upstream stores that file in Windows-1252, so the notice is converted to UTF-8 (iconv -f WINDOWS-1252): the copyright sign and the two bullet characters change encoding and the text is unchanged. The repository accepts UTF-8 text only.

The debt file gets a Functional entry, and the additional-export count goes from 132 to 131.

Tested

  • Ubuntu 26.04 x86-64, GCC 15.2, full build.
  • tests/GuestJxr.cpp (ctest guest_jxr) now covers PKAlloc through the existing replacement-heap hooks:
    • one calloc(1, size) call per allocation, for sizes 1, 257, 4097 and 0;
    • zeroed memory, and the pointer stored through ppv;
    • the return code following the result;
    • a forced allocation failure storing NULL and returning -101;
    • freeing each allocation through PKFree;
    • a null ppv throwing.
  • On main the test fails with PKAlloc_nid_postfix not implemented.
  • Mutation check: swapping the two return codes makes the test fail at GuestJxr.cpp:94. The restored code passes.
  • ctest --test-dir build-full -R jxr: 9/9 passed. -R 'jxr|public_headers': 74/74 passed.
  • python3 tools/check_conventions.py --base origin/main: all conventions checks passed.
  • python3 tools/pr_overlap.py --branch feat/libscejxr-pkalloc: no overlap with open pull requests.
  • Not run on Windows, macOS or a console.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5107310778 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14425). Originally posted by [AlexWhitehouse](https://github.com/AlexWhitehouse) on 2026-11-01T12:26:24Z. --- ### What Implements `PKAlloc` (NID `IXOD4hTCNU0`) in libSceJxr, ported from jxrlib [`JXRGlue.c`](https://github.com/4creators/jxrlib/blob/f7521879862b9085318e814c6157490dd9dbbdb4/jxrgluelib/JXRGlue.c#L46-L50) at the commit the debt file and `3rdparty/jxrlib` pin. - It allocates `cb` zeroed bytes with the guest `calloc(1, cb)`, the same application heap `PKFree` already frees to. - It stores the pointer through `ppv`, NULL on failure included, and returns `WMP_errSuccess` (0) or `WMP_errOutOfMemory` (-101), with `ERR` a signed 64-bit value as in the pinned headers. - A zero `cb` follows the guest `calloc(1, 0)`. - A null `ppv`, which upstream dereferences, throws. `src/Allocation.cpp` starts with the Microsoft copyright and licence notice from `JXRGlue.c`, lines 1-27. Upstream stores that file in Windows-1252, so the notice is converted to UTF-8 (`iconv -f WINDOWS-1252`): the copyright sign and the two bullet characters change encoding and the text is unchanged. The repository accepts UTF-8 text only. The debt file gets a Functional entry, and the additional-export count goes from 132 to 131. ### 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 26.04 x86-64, GCC 15.2, full build. - `tests/GuestJxr.cpp` (ctest `guest_jxr`) now covers `PKAlloc` through the existing replacement-heap hooks: - one `calloc(1, size)` call per allocation, for sizes 1, 257, 4097 and 0; - zeroed memory, and the pointer stored through `ppv`; - the return code following the result; - a forced allocation failure storing NULL and returning -101; - freeing each allocation through `PKFree`; - a null `ppv` throwing. - On `main` the test fails with `PKAlloc_nid_postfix not implemented`. - Mutation check: swapping the two return codes makes the test fail at `GuestJxr.cpp:94`. The restored code passes. - `ctest --test-dir build-full -R jxr`: 9/9 passed. `-R 'jxr|public_headers'`: 74/74 passed. - `python3 tools/check_conventions.py --base origin/main`: all conventions checks passed. - `python3 tools/pr_overlap.py --branch feat/libscejxr-pkalloc`: no overlap with open pull requests. - Not run on Windows, macOS or a console. ### 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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-01 12:43:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T12:43:17Z.

Review: COMMENTED


Reviewed — no blocking findings

The PKAlloc port matches jxrlib's calloc(1, cb) behaviour and its out-of-memory return code at the pinned commit, and the test pins the allocation, zeroing, failure and null cases; the only issue is three trailing spaces in the copied licence header, which is non-blocking. I found no blocking issue at 9719c64df6.

What I ran

Exact head 9719c64df6c37282b47e64f6a2c991646891511b; PR base ba627802e2210187d417deb64c8f2fed8e33011f (current main), unchanged at completion. No build and no test run. Commands:

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14425
python3 tools/pr_abi_audit.py --base ba627802e2210187d417deb64c8f2fed8e33011f --head 9719c64df6c37282b47e64f6a2c991646891511b --json
python3 tools/pr_test_quality.py --root <git archive of 9719c64df6: core/libs/tests, core/libs/prx/libSceJxr, core/libs/CMakeLists.txt> --json core/libs/tests/GuestJxr.cpp

The precheck's ABI and test-quality helpers were missing from the isolated head tree, so both were run by hand from /marc/AnyPS5/tools. I also compared the port with jxrlib at f7521879862b9085318e814c6157490dd9dbbdb4: jxrgluelib/JXRGlue.c L46-L50, image/sys/windowsmediaphoto.h L226 (WMP_errOutOfMemory -101) and L243 (typedef long ERR).

Results

Check Result
Diff check (precheck) Failed: trailing whitespace on three // lines of the copied licence header in core/libs/prx/libSceJxr/src/Allocation.cpp (lines 5, 8 and 14); non-blocking, see below
Conventions and PR template (precheck) Passed
Live dependency and mergeability (precheck) Passed
ABI audit (by hand) Passed, 0 findings
Test-quality heuristic (by hand) One possible-unregistered-cpp-test finding; false positive, because the test is registered as guest_jxr_tests in core/libs/prx/libSceJxr/CMakeLists.txt L49
Port versus jxrlib Same allocation (calloc(1, cb)), zero-size behaviour and return codes
Build and tests Not run (no-build review)

Findings

Blocking: none.

Non-blocking:

  1. The three // lines in the licence header carry a trailing space, which git diff --check reports. Stripping those spaces makes the diff check pass; nothing else in the file is affected.

What I read: PKAlloc in Allocation.cpp, the new test in core/libs/tests/GuestJxr.cpp (the allocation hook is wrapped so each call is counted, zeroed memory is checked, and failure and null-ppv cases are covered), and the debt entry, whose count goes from 132 to 131 and matches the 135 to 134 declarations in Export.cpp.

Not verified

  • Nothing was compiled or run. The author reports ctest guest_jxr 9/9 on Ubuntu and a mutation check; I did not reproduce them.
  • Windows, macOS and console behaviour were not checked.
  • Hosted checks are queued at this head.

To get this to a good state

Optional: strip the trailing spaces on the three licence lines so git diff --check is clean. No other change is needed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5728102965 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14425#pullrequestreview-5728102965). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-01T12:43:17Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The `PKAlloc` port matches jxrlib's `calloc(1, cb)` behaviour and its out-of-memory return code at the pinned commit, and the test pins the allocation, zeroing, failure and null cases; the only issue is three trailing spaces in the copied licence header, which is non-blocking. I found no blocking issue at `9719c64df6`. ## What I ran Exact head `9719c64df6c37282b47e64f6a2c991646891511b`; PR base `ba627802e2210187d417deb64c8f2fed8e33011f` (current `main`), unchanged at completion. No build and no test run. Commands: ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14425 python3 tools/pr_abi_audit.py --base ba627802e2210187d417deb64c8f2fed8e33011f --head 9719c64df6c37282b47e64f6a2c991646891511b --json python3 tools/pr_test_quality.py --root <git archive of 9719c64df6: core/libs/tests, core/libs/prx/libSceJxr, core/libs/CMakeLists.txt> --json core/libs/tests/GuestJxr.cpp ``` The precheck's ABI and test-quality helpers were missing from the isolated head tree, so both were run by hand from `/marc/AnyPS5/tools`. I also compared the port with jxrlib at `f7521879862b9085318e814c6157490dd9dbbdb4`: `jxrgluelib/JXRGlue.c` L46-L50, `image/sys/windowsmediaphoto.h` L226 (`WMP_errOutOfMemory -101`) and L243 (`typedef long ERR`). ## Results | Check | Result | |---|---| | Diff check (precheck) | Failed: trailing whitespace on three `// ` lines of the copied licence header in `core/libs/prx/libSceJxr/src/Allocation.cpp` (lines 5, 8 and 14); non-blocking, see below | | Conventions and PR template (precheck) | Passed | | Live dependency and mergeability (precheck) | Passed | | ABI audit (by hand) | Passed, 0 findings | | Test-quality heuristic (by hand) | One `possible-unregistered-cpp-test` finding; false positive, because the test is registered as `guest_jxr_tests` in `core/libs/prx/libSceJxr/CMakeLists.txt` L49 | | Port versus jxrlib | Same allocation (`calloc(1, cb)`), zero-size behaviour and return codes | | Build and tests | Not run (no-build review) | ## Findings **Blocking:** none. **Non-blocking:** 1. The three `// ` lines in the licence header carry a trailing space, which `git diff --check` reports. Stripping those spaces makes the diff check pass; nothing else in the file is affected. What I read: `PKAlloc` in `Allocation.cpp`, the new test in `core/libs/tests/GuestJxr.cpp` (the allocation hook is wrapped so each call is counted, zeroed memory is checked, and failure and null-`ppv` cases are covered), and the debt entry, whose count goes from 132 to 131 and matches the 135 to 134 declarations in `Export.cpp`. ## Not verified - Nothing was compiled or run. The author reports `ctest guest_jxr` 9/9 on Ubuntu and a mutation check; I did not reproduce them. - Windows, macOS and console behaviour were not checked. - Hosted checks are queued at this head. ## To get this to a good state Optional: strip the trailing spaces on the three licence lines so `git diff --check` is clean. No other change is needed.
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!14425
No description provided.