feat(libSceJxr): implement the PKFactory and PKCodecFactory constructors #15232
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15232"
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 simnJS on 2026-11-02T21:26:13Z.
What
Implements seven libSceJxr factory exports on the pinned jxrlib:
PKCreateFactory,PKCreateFactory_CreateStream,PKCreateFactory_Release,PKCreateCodecFactory,PKCreateCodecFactory_Release,PKCodecFactory_CreateCodec(an unknown IID returnsWMP_errUnsupportedFormat) andPKCodecFactory_CreateFormatConverter. The function slots hold guest-ABI pointers.PKCreateFactory_CreateStreamallocatessizeof(PKStream), 24 bytes, asjxrgluelib/JXRGlue.cdoes:PKStream(JXRGlue.h) is a separate structure from the 88-byteWMPStreamthatCreateWS_FileandCreateWS_Memorycreate.CreateStreamFromFilename,PKCodecFactory_CreateDecoderFromFileand thePKFormatConverter_*andPKImageDecode_*functions reached through the slots stayNotImplemented_nid_no_patch; the debt file records it.Tested
Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release:
guest_jxr_factorypasses (creation and release, slots called, unknown IID -106, allocation failure -101, null pointers). Only this test was run, not the full suite. Not run on Linux or on a title.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 BunnyFl on 2026-11-04T00:08:27Z.
Review: CHANGES_REQUESTED
@simnJS thanks for this. The stream and format converter layouts match the console module, but the codec factory doesn't, and a guest calling its
Releasewould read past the allocation.PKCodecFactoryis 40 bytes on the console, withReleaseat+0x20. In firmware 13.42system/common/lib/libSceJxr.sprx(sha25673c51baf72937450751e8437e2744fcbe23a58844625f28375f7c423fbe50362),PKCreateCodecFactory(we4rPX+-zNg,0x378d0) is, read from disassembly and not run:Nothing is stored at
+0x18(378f4–3791babove). The allocator gets(1, size), presumably jxrlib'scalloc, so that slot is presumably zero. I named the four slot targets by matching their addresses against the module's export table (G+lqj7diiFM,nSR7deGcfPw,-sUOc+vW9iw,xTVG4ZQMwVk).In this PR
Jxr::CodecFactoryis 32 bytes (Factory.hpp,static_assert(sizeof(CodecFactory) == 32)), andreleasesits at+0x18. A title or SDK module built against Sony's header callspCodecFactory->Release(&pCodecFactory)through+0x20. Here that reads the 8 bytes right after the 32-bytecallocblock and calls them. On the console it'sPKCreateCodecFactory_Release.Suggested fix: add an 8-byte field at
+0x18beforereleaseand make the struct 40 bytes, withstatic_assert(offsetof(CodecFactory, release) == 0x20). Then have the test check that+0x18stays zero. I don't know what Sony's fourth slot is, and the constructor above doesn't set it. Avoid*the code leaves null would match what I read.What matches (same module, same reading):
PKCreateFactory(0x37650) allocates0x20and storesPKCreateFactory_CreateStream(0x375e0) at+0, an unexported function at+8,CreateWS_Memory(0x34f80) at+0x10andPKCreateFactory_Release(0x37620) at+0x18. That is yourFactory. The+8target is presumablyCreateWS_File; I didn't read it, and your throwingCreateStreamFromFilenamethere is fine.PKCreateFactory_CreateStream(0x375e0) allocates0x18, which matches your 24-bytePlainStream. It returns-101(0xffffffffffffff9b) when the allocation fails, as all four constructors do.PKCodecFactory_CreateFormatConverter(0x37800) allocates0x60and fills the slots in your order:Initialize,InitializeConvert,GetPixelFormat,GetSourcePixelFormat,GetSize,GetResolution,Copy,Convert(0x4b740), and thenRelease(0x4b750) at+0x40.What I ran: this head merged onto
main(merged19ea27c68), Windows 11, WinLibs GCC, Release.guest_jxr_factoryandpublic_headerspass (2 of 2). The test readsreleasethrough the PR's own struct (tests/JxrFactory.cpp:121and:150), which can't show the console's offset.Small note: my #15626 gives
PKFormatConverter_Convert_nid_postfixits jxrlib signature. YourSlot<decltype(value->convert)>(&PKFormatConverter_Convert_nid_postfix)is areinterpret_cast(Export.cpp,Slot), and I expect it to build against either signature. Whichever of us lands second should rebuild to confirm.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-04T00:18:52Z.
Review: COMMENTED
Reviewed — comments
The seven factory exports follow jxrlib's
JXRGlue.cexactly, and the test passes and fails when allocation-failure handling is broken; the open question is the console layout ofPKCodecFactorythat BunnyFl raised, which I could not verify.What I ran
Head
0d783107d35b4240a248eff9db145726f4b272d0merged intomain1c8c0efc8c41314402e6966da5bef6ea3d639d10(merged tree0156b3beef9b31462b656c7cbb8731b60793d37d), Debian 13 VM, GCC 14.2.0, Release, Ninja.Results
git diff --checkcheck_conventions.pylibsOKunwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_groupalso fails onmain(known)guest_jxr*(10 tests incl.guest_jxr_factory)guest_jxr_factory0.01 sgit status --porcelainemptyNegative control
With only
Export.cppandinclude/Api.hpptaken frommain, the test doesn't compile.maindeclares these exports as parameterlessintplaceholders:excerpt
That only shows the signatures changed, so I also ran a behavioural mutation. In the merged
Export.cpp, I changedAllocateZeroedto returnWmpErrSuccesseven whencallocfails.guest_jxr_factorythen failed (SEGFAULT on the allocation-failure path).After restoring the merged files and rebuilding, the test passes again and the worktree is clean.
Findings
Blocking
None of my own. BunnyFl's change request (
PKCodecFactoryis 40 bytes on the console, withReleaseat+0x20) has no reply yet; see Non-blocking for what I could add.Non-blocking
PKCodecFactorylayout finding: more evidence, still open.core/libs/prx/libSceJxr/Factory.hpp:29-34and:51match the pinned jxrlib (3rdparty/jxrlibatf7521879862b9085318e814c6157490dd9dbbdb4) exactly. In itsJXRGlue.h(lines 351-361),tagPKCodecFactoryhas four function pointers:CreateCodec,CreateDecoderFromFile,CreateFormatConverter,Release. That is 32 bytes.PKFactory,PKStream(24 bytes) andPKFormatConverter(96 bytes,pDecoderat 72) also match the header.+0x18, and the reference cannot show it.releasethrough the PR's own struct (tests/JxrFactory.cpp:121,:150), so it cannot tell the two layouts apart.docs/dev/debt/libSceJxr.md:17linksJXRGlue.c#L334-L480. At that commit,PKCreateFactory_CreateStreamstarts at line 333 andPKCreateCodecFactoryends at line 482. Suggest#L333-L482.core/libs/prx/libSceJxr/Export.cpp:151-156callPKImageEncode_Create_WMP_nid_postfix/PKImageDecode_Create_WMP_nid_postfixthrough a cast toint64_t(*)(void**). Both are still parameterlessintplaceholders that throw, so IIDs 101 and 201 currently end inNotImplemented.if(BUILD_TESTING)blocks.core/libs/prx/libSceJxr/CMakeLists.txt:73-84opens a secondif(BUILD_TESTING)block right after the existing one. The registration could go inside the existing block. Cosmetic.Not verified
guest_jxrandpublic_headerstests in the background; all 75 passed. That run overlapped the negative-control edits, so I don't count it. I rely on the script's full run of the merged tree, which reported no new failures.To get this to a good state
Jxr::CodecFactory40 bytes withreleaseat0x20and assert it withoffsetof. Have the test check that the+0x18slot is zero. Update the debt entry to say which layout follows the console and which follows jxrlib.JXRGlue.clink in the debt entry.Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-06T18:34:31Z.
Review: APPROVED
@simnJS re-checked at
bfc31e1c4e, and my change request is resolved (cc @oneandonlydean, thanks for pushing the fix in25f5019918).The codec factory now matches what
PKCreateCodecFactoryallocates in firmware 13.42.Jxr::CodecFactoryhas an emptyvoid* reservedat+0x18, andreleasesits at+0x20in a 40-byte struct.core/libs/prx/libSceJxr/Factory.hpp:79asserts both (sizeof == 40,offsetof(release) == 0x20). The test now reads the raw slots, so it no longer depends on the PR's own struct:tests/JxrFactory.cpp:122requires slot 3 to be null and slot 4 to beRelease. That is the layout from my disassembly at0d783107d3.I didn't check the other change,
initializeConverttaking the GUID by value, againstJXRGlue.hmyself.What I ran
Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0, Release, this head merged onto current
main(merge22edf6e602):guest_jxr_factoryandpublic_headers: 2 of 2 pass.43cadd451b):PKCreateCodecFactoryalso writesReleaseinto the reserved slot.guest_jxr_factorythen aborts (0xc0000409), 0 of 1 pass. So the new check catches a factory that fills+0x18.tools/check_conventions.py --base upstream/main --headon this head: all checks pass.tools/pr_overlap.py --branch: the confirmed line conflicts arelibSceJxr/CMakeLists.txtL121 (#15148, #15479, #15689), the debt entry list at L38-39 ofdocs/dev/debt/libSceJxr.md, andinclude/Api.hppL68-74 with my #15626. That last one is thePKFormatConverter_Convertsignature I mentioned at0d783107d3; whichever of us lands second rebuilds. Its "same exports" rows (Allocate,Align,Callocand so on) are the test's local heap callbacks, not exports.Still open from XairRrR's earlier review, non-blocking. At
bfc31e1c4e, the debt entry'sJXRGlue.clink still reads#L334-L480(docs/dev/debt/libSceJxr.md:39).AI-assisted: yes (Claude Code)