fix(libkernel): provide default arguments block for DT_INIT on Linux #6149
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6149"
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 Nubi-Prey on 2026-10-14T23:33:36Z.
What
core/libs/prx/libkernel/Module/src/ModuleArgs.cppandModuleArgs.hpp(SetPendingModuleArgs_nid_no_patch,GetPendingModuleInitResult_nid_no_patch,SetModuleInitResultObserverForTest_nid_no_patch) and link it into bothlibkernelandguest_module_args_hostso the relinker test exercises the production implementation directly.sceKernelLoadStartModulecall is active viathread_local bool explicitLoadInProgress(with exception-safe reset arounddlopen_nid_postfixinModule.cpp), preserving explicit(args, nullptr)pairs whenexplicitLoadInProgressistrueand returning a 16-byte default block{size: 0x10, version: 0x200, context: nullptr}(args = 16) only whenexplicitLoadInProgressisfalse.docs/dev/debt/libkernel.md: what the console passes outsidesceKernelLoadStartModuleor toDT_NEEDEDdependencies pulled in duringsceKernelLoadStartModule, that{0x10, 0x200}is a guess from #5621 whilecontextis unknown (nullptrfaults if called during init), and thatexplicitLoadInProgressremainstrueacrossdlopen_nid_postfix.Tested
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON), rebased onmain(474030e584): builtrelinkerandguest_module_args_hostand ranctest --test-dir build-relinker -R "guest_module_args|guest_deferred_dependencies" --output-on-failure -V(2/2 passed:load_and_record,load_and_record_default,load_and_record_explicit_null, andguest_deferred_dependencies).SceKernelDefaultModuleArgs::versionto0x201inModuleArgs.hppfailsguest_module_argswithGuest module argument fixture: Default arguments corruption.kEmptyPendingArgswhenpendingModuleArgs.argp == nullptrinModuleArgs.cppfailsload_and_record_explicit_nullinguest_module_args.python3 tools/check_conventions.py --base upstream/mainpasses with 0 warnings and 0 errors.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 simonbbby on 2026-10-15T00:24:26Z.
Independent Linux check at exact head
950bc7c323a44bac2f83781e57d968cf016e932f(Ubuntu 24.04 / Ryzen 9 9950X / GCC 13.3 / Ninja Release).The relinker-only suite passes 165/165 (28.88 s), and the real production getter returns the proposed default block in a separate native probe. There is a gap in the new regression, though: it remains green with the runtime fix removed, and also with a null default pointer in its own provider.
Controls, rebuilt and run with
ctest -R '^guest_module_args$' -V:Module.cppfrom this head's parentkEmptyPending{sizeof(kDefaultArgs), nullptr}kEmptyPending{8, &kDefaultArgs}Missing default argument blockThe size mutation confirms the fixture ran and rebuilt. The two false greens have separate causes:
guest_module_args_host.prxsupplies its own__aps5_get_pending_module_args_nid_no_patch, so it never calls the changed production helper; andRecordArgschecks the payload only ifargp == &kDefaultArgs. A null pointer skips that check, while Python asserts the size and initializer result but not the pointer. The fixture's initializer only callsRecordArgs, so it does not dereference the null pointer as the reported Unity initializer does.This small test-only change catches the null pointer and also checks
context:It still needs a regression that calls the real runtime getter. I checked that independently without the full SDL build: compile the actual
core/libs/prx/libkernel/Module/src/Module.cppwith-std=c++20 -O2 -ffunction-sections -fdata-sections -Icore/libs, then link a small getter probe with-Wl,--gc-sectionsto discard unrelated unused runtime functions. The probe casts the getter result toPendingModuleArgs, requiresargs == 16and non-nullargp, then checks the payload's size0x10, version0x200and null context. The PR production object passes; its parent's production object exits 1 with a missing/null default block. This links the actual compiled helper, rather than a replacement getter.All temporary source edits were restored, the stock provider rebuilt, and
guest_module_argspasses again with a clean checkout. No title run, full-runtime load, or claim that this default block matches console behavior.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T00:31:45Z.
Review: COMMENTED
macOS run of the new
--load-defaultpath, which has its owndarwinbranch (RTLD_GLOBAL) that the Linux runs don't cover.Machine: Apple M2 Max, macOS 27.2, Xcode 27 toolchain, relinker-only Release.
Head:
950bc7c32, merged ontomain@ab9a47684(clean).The test only executes natively on macOS when the interpreter is x86_64 (
platform.machine() == 'x86_64'). Undercteston Apple silicon, both the arm64 build and the x86_64 build printnative execution skipped, because/usr/bin/python3starts as arm64. So I ran it by hand from the x86_64 build:GuestModuleArgsHost.cpprestored frommainargs=0000000000000000 argp=0000000000000000--load-defaultwithDEFAULT_MODEinstead ofRTLD_GLOBALdlopen(...): symbol not found in flat namespace '_RecordArgs'So the
darwinbranch works and theRTLD_GLOBALis required there. As @simonbbby showed on Linux, what the test checks is the fixture's own provider, not the production__aps5_get_pending_module_args_nid_no_patchinModule.cpp. That is the same on macOS:Module.cppis not part of the relinker-only build.Full relinker-only suite with the PR: arm64 163/163; x86_64 + Python 3.9.6 159/163, with the same 4 failures as
main.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by Nubi-Prey on 2026-10-15T01:01:28Z.
Thanks @jotitadev and @simonbbby for the thorough independent validation on macOS and Linux!
Carried the suggested mutation control in commit
20e36060f:GuestModuleArgsHost.cpp: fail with"Missing default argument block"ifargp == nullptrwhenargs == sizeof(DefaultModuleArgs), and checkcontext == nullptr.test_guest_module_args.py: assert that the recordedargpis not null.Verified locally with a negative mutation control (setting
nullptrfails CTest immediately with the expected error) and all 165 CTests and conventions pass on a clean checkout.Written with AI assistance (Gemini).
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-15T20:43:34Z.
Independent Linux title check of exact PR head
0cd9877c6d3224c6207ed58948bc102330350648: Double Dragon Gaiden: Rise of the Dragons (PPSA16018), 01.000.013 is not unblocked by the fallback alone.Compared main
ce991f1ec2eb71a1f30459b4442a0730a0a4861bplus the common #6476 build repair against that same source plus only this PR's two commits, preserving authorship. Fulllibsand relinker builds pass. The rebuiltguest_module_argsCTest passes (0.14 s). A separate ctypes call to the built production__aps5_get_pending_module_args_nid_no_patchconfirms a non-null 16-byte default block with size0x10, version0x200, null context; this check uses the runtime library, not the relinker test provider.Both native launches fail before the executable's main entry, in the converted bundled
Media/Plugins/NativePluginPS5Example.prx:+0x23a+0x3a9The first check accepts
{size=0x10, version=0x200}and saves the pointer at block+8. The second crash follows its use. Thus supplying a non-null header is insufficient for this plugin: it needs the context as well. I have not established the correct source or lifecycle for that context and have not added a replacement pointer, skipped initialization, or bypassed the call. This is additional title scope, not a rerun of the Cult of the Lamb result.Environment: Arch Linux 7.2.9-arch1-1, GCC 16.2.1, Ryzen 9 7950X. Both regular runs exit 139; debugger runs confirm the distinct sites above. Same converted executable and guest modules, with verified library paths. No game assets, raw title logs, binaries or screenshots attached. AI-assisted investigation.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T00:08:19Z.
I checked the independent Double Dragon result in the linked issue thread against this PR's stated fallback. On the exact earlier PR head, the {0x10, 0x200, nullptr} block gets past the plugin's header check, but NativePluginPS5Example.prx then dereferences the null context at +0x3a9 before the executable reaches main (https://github.com/boykopovar/AnyPS5/pull/6149#issuecomment-6201881775).\n\nThat does not disprove the narrower Cult of the Lamb fix, but it shows the default block does not make every needed-module DT_INIT safe. Could you clarify whether Cult of the Lamb was run past this initializer on the current head, and keep the PR's claim scoped to the reproduced case if that remains unverified?
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T02:17:48Z.
Two things before this can go further. The fallback also fires for an explicit
sceKernelLoadStartModulewith no arguments, since that path stores{0, nullptr}too, so those loads now get the guessed block as well; could you limit it to theDT_NEEDEDinitializers this PR is about? And on @MarcZX100's question: was Cult of the Lamb run past this initializer on the current head? @JJenkx's Double Dragon run shows the block gets past the header check and then hits the null context, so I'd like the claim scoped to what was reproduced.Imported from boykopovar/AnyPS5. Originally posted by socket1001 on 2026-10-17T21:12:07Z.
Suggestion for this PR, with measurements (AI-assisted - note at the end).
Cross-posting this from #5621 because it is about the fallback this PR installs, rather than a per-title finding.
The default block here is
{0x10, 0x200}withcontext = nullptr. On a title that actually consumes that block (PPSA16018, Double Dragon Gaiden: Rise of the Dragons), the field turns out not to be a data pointer - it gets called:args[8](the+8field,0x10/0x200format) into a module global;rc = g_context(id, &out); return rc ? 0 : out;- so the field is invoked asint (*)(int id, void **out);*outand calls[obj->vtable + 0x10], withrsipointing at the module's own static table (where the module has just registered its callback pointers);nullptr, this title faults inside plugin init at module offset+0x3a9- acall raxwithrax = 0, which is the null it was handed.What I measured locally. Setting that field to a getter of that shape, returning 0 and handing back a statically built object whose
[vtable+0x10]is a harmless stub, is enough for this title to get through: plugin init completes and the game runs - Vulkan device, swapchain 2224x1251 with 3 images, then its prologue, character select and mission select on input, into the first stage at 45-60 FPS. Same three commits cherry-picked ontomainas of13d07428a, 127 runtime libraries rebuilt, both this title and an unaffected one re-run as a control.To be clear: a real loader-side context object is presumably the right answer and this is not a proposal to merge - it is a throwaway probe to demonstrate the shape of the field, and it should not be committed as-is. Two things a proper version would have to do differently are reflected in the code below: no mutable static state (the module may call this from more than one thread), and a real decision about the block size.
The
idargument's meaning is not established - the plugin passes a value of its choosing and the getter above ignores it. Whether the returned object's other methods matter beyond this title is untested.One size caveat while picking a default: the block above is the 16-byte
{0x10, 0x200}shape, and this plugin also carries code for the{0x48, 0x103}shape, which reads the same field from a 0x48-byte block (offset0x40). It selects between the two from the version field, so a consistent 16-byte block does not reach the larger path here - but anything handed the 16-byte default while taking that path would read past the end of it. Not something I could trigger, just worth knowing.Disassembly, register state and the thread-level evidence behind the shape claim are in my comment on #5621; happy to test anything more specific you would like tried.
Note: written by an AI agent (Hermes, running on the reporter's own machine) while testing the emulator locally. The builds, runs and measurements are real and reproducible; the prose is the agent's. Not affiliated with the project.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T06:25:09Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The head conflicts with current
main. The fallback also replaces the arguments of explicitsceKernelLoadStartModulecalls, not onlyDT_NEEDEDinitializers. The new regression still passes when the production change is reverted.What I ran
0cd9877c6d3224c6207ed58948bc102330350648main:2960e9a6e7e1fc99c4ed180c71495b5eb83464c7Results
maincore/relinker/relinker/tests/test_guest_module_args.pyanddocs/dev/debt/libkernel.mdgit diff --checktools/check_conventions.py --base origin/mainrelinker,guest_module_args_host(PR head)libs(PR head)guest_module_args(PR head)guest_module_argswith productionModule.cpprevertedMerge conflict
On
main, the--loadbranch of the test now drives__aps5_guest_lifecycle_nid_no_patchitself, and the Linux setup copies the provider intolibs/libkernel.prx. The PR's--load-defaultbranch and itsload_and_record_defaultcalls were written against the earlier version of that code.Negative control
Negative control
I restored only
core/libs/prx/libkernel/Module/src/Module.cppfrom the PR's merge base92e50418f3, then rebuiltlibs,relinkerandguest_module_args_host.guest_module_argsstill passes. I used the merge base rather thanmainbecause the PR head does not merge withmain. This confirms, on the current head, what @simonbbby reported for950bc7c32. The later null-pointer check in the fixture catches a null pointer in the fixture's own provider. It does not make the test exercise the production getter.Findings
Blocking
Conflicts with
main. The PR conflicts incore/relinker/relinker/tests/test_guest_module_args.pyanddocs/dev/debt/libkernel.md. @oneandonlydean flagged this on 2026-10-25, and the head has not changed since.mainhas also changed the code this PR depends on. Linux explicit runtime directories now use deferred initialization, which reads the getter inInitializeLinuxGuestModule, and the debt doc has a Linux runtime module initialization entry. After the rebase, the claim that aDT_NEEDEDmodule runs its entry at process start before anysceKernelLoadStartModuleshould be checked again against the deferred path.The fallback rewrites explicit load arguments, not only
DT_NEEDEDinitializers.Module.cpp:276-281substitutes{0x10, &kDefaultModuleArgs}wheneverargp == nullptr. However,sceKernelLoadStartModulestores the caller's{args, argp}verbatim at line 294. @oneandonlydean raised theargs == 0case. One more input changes as well: an explicitsceKernelLoadStartModule(path, 8, nullptr, ...)reaches the module entry as(0x10, &kDefaultModuleArgs), so the caller'sargsvalue is replaced as well asargp. This is a value the title did not pass, and its console behaviour is unverified. The same happens for a guestdlopenon a thread without pending arguments, becausependingModuleArgsisthread_local.Suggested fix: record whether an explicit start is in flight, for example a separate thread-local flag set and cleared around
dlopen_nid_postfixinsceKernelLoadStartModule. The default block should apply only when no explicit start is in progress. Explicit loads would then always pass the caller's arguments unchanged. Update the debt entry to say exactly which loads receive the block.The regression does not cover the production change. The fixture provider
GuestModuleArgsHost.cpp:65-70contains its own copy of the fallback, so--load-defaultchecks the test's copy. The negative control above passes with the production fix reverted. Two options would fix this. A test could call the real__aps5_get_pending_module_args_nid_no_patchfromModule.cpp: @simonbbby and @JJenkx both did this outside CTest, with a probe and with ctypes. Or the fixture could forward to the production object instead of reimplementing it. Either test should also cover the explicit-load case from finding 2, checking that(8, nullptr)reaches the entry unchanged.Non-blocking
UnifyPS5Plugin.prxinitialization on this head. @MarcZX10 and @oneandonlydean asked this, and it is still unanswered. @JJenkx's PPSA16018 run and @socket1001's analysis show a plugin that callscontextas a function and crashes on the null value. I did not run a title, so I cannot add evidence either way. The description should say what was reproduced. The debt entry could also note that some plugins dereferencecontext, because a later reader would otherwise assume that a null context is safe.Not verified
92e50418f3.To get this to a good state
mainand resolve the test and debt-doc conflicts against the deferred lifecycle path.sceKernelLoadStartModule. Explicit loads should pass the caller's{args, argp}unchanged, including(0, nullptr)and(N, nullptr).Module.cppchange reverted.Unblocksand the debt entry to what was reproduced on the current head.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T08:25:37Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
This pull request does not merge cleanly into
main(4f41f4c375): heada407a5ef83conflicts incore/relinker/elfpatcher/tests/GuestModuleArgsHost.cppPlease rebase it onto current
main. I will review the change once it merges cleanly.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T11:23:42Z.
Review: COMMENTED
Reviewed — no blocking findings
The reviewed changes look consistent with the stated behavior, but I could not run the reported checks in this session, so a formal approval is not justified.
What I ran
Reviewed head
a407a5ef836405798b7e248b876acd66aa3f39e7. I read every changed line in all 8 changed files using the review reader; no checks were run in this session.Results
Negative control
Not run in this session. The description reports two negative controls that were verified and reverted.
Findings
Blocking
None.
Non-blocking
None.
Sources
Reviewed
core/libs/prx/libkernel/CMakeLists.txt,core/libs/prx/libkernel/Module/ModuleArgs.hpp,core/libs/prx/libkernel/Module/src/Module.cpp,core/libs/prx/libkernel/Module/src/ModuleArgs.cpp,core/relinker/CMakeLists.txt,core/relinker/elfpatcher/tests/GuestModuleArgsHost.cpp,core/relinker/relinker/tests/test_guest_module_args.py, anddocs/dev/debt/libkernel.mdat the pinned head. All were included in the review folder and their changed lines were read.Not verified
The author-reported test and convention command results were not independently confirmed. Commercial title and console behavior remain unverified.
To get this to a good state
Nothing is required. Optional: independently run the reported Linux tests and convention check before merge.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:45:55Z.
Review: COMMENTED
The exact branch passed guest_module_args in a Linux relinker-only build. A trial merge against main
13aa5703b3reports conflicts in Module.cpp and GuestModuleArgsHost.cpp, which block an integrated kernel-loader run.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.