feat(libkernel): add fallback search paths and loaded handle lookup i… #9415
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9415"
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 Delciob on 2026-10-21T21:10:28Z.
What
Enhance dlopen on Windows to reuse existing loaded module handles via GetModuleHandleW before attempting a new disk load. Add fallback search candidate paths for game_modules/ and libs/ subdirectories including .guest.prx suffix resolution.
Tested
Windows 10 x64, game module dynamic loading with secondary modules.
Checklist
Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T22:41:53Z.
Windows run of
5e55c4a463merged ontomaina6dcea9279(3fd670a490, clean), no platform is listed in the description. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,BUILD_TESTING=ON.Built
libkernel,libkernel_sys,libcand the loader and module test executables with no errors or warnings.ctest --repeat until-fail:2on these 15 tests:guest_dynamic_loader,guest_dynamic_loader_variant_names,guest_module_args,guest_module_dir,guest_module_directories,guest_module_fini,guest_module_identity,guest_module_info,guest_needed_modules,guest_needed_nested_modules,guest_deferred_module_parallel,guest_deferred_module_pinned,guest_deferred_module_reentrant,guest_deferred_module_reloadandguest_sysmodule: all pass on both repeats. The description names no test, so these are the dynamic loader and module tests. Not run: a title.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T22:43:19Z.
The hosted conventions check is failing while the PR description still has empty
WhatandTestedsections and the template instruction text inTested. Please replace those with a short behavior summary and the exact checks run (or “Not tested” where applicable); the description currently gives reviewers no validation scope.Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-21T23:44:34Z.
Review of
5e55c4a46againstmaina6dcea927(merges cleanly). The change is entirely inside the#ifdef _WIN32branch ofdlopen_nid_postfix(lines 176–220). On Linux,DynamicLoader.cppcompiled frommainand from this PR gives byte-identical objects (GCC 13.3.0). On Windows it compiles without warnings using libkernel's flags (MinGW GCC 15.2.0,-Wall). Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs MinGW-w64 GCC 15.2.0, Release relinker-onlyBUILD_TESTING=ON; Linux: WSL Ubuntu 24.04, GCC 13.3.0, same configuration.To check what the fallbacks do, I copied the added block verbatim into a small Windows program (
RelinkedModulePath_nid_no_patchreplaced by identity), together withmain's singleLoadLibraryExWcall, and ran it on Windows 11. Amod.prxDLL is first loaded fromt\a\.maint\nonexistent\kernel32.dll(missing)C:\WINDOWS\System32\KERNEL32.DLL,owned=falset\b\mod.prx(missing)t\a\mod.prx,owned=falset\c\mod.prx(present, not a PE file)t\a\mod.prx,owned=falset\d\other.prx(missing;t\d\libs\other.prxpresent)t\d\libs\other.prxt\e\none.prx(missing everywhere)GetLastError()3 when the message is writtenWhat this means for
sceKernelLoadStartModuleanddlopen:GetModuleHandleW(filename)matches any loaded module with the same base name, whatever directory it came from, including system DLLs. When the requested file is missing or fails to load (error 193), this PR returns a handle to a different module and reports success.owned=false, soInitializeDeferredModuleis skipped.sceKernelLoadStartModulethen returns a handle with*res = 0and never runsmodule_startor the initializers./.find_libraryreturns it unchanged as a "Hard coded pathname" (rtld.c in 11.4, around line 1630).load_objectreuses a loaded object only when the whole name matches (object_match_name) or the opened file has the same device and inode (around lines 2405 and 2454). Thegame_modules/andlibs/directories added here are not on that path. I found no other reference togame_modulesin the repository.parent/<name>.guest.prx(the fourth candidate) is already tried byRelinkedModulePath_nid_no_patch, which runs beforeLoadLibraryExW.Windows loader erroris no longer the originalLoadLibraryExWerror: thestd::filesystem::existscalls overwriteGetLastError()(126 becomes 3 above).The PR has no test and names no title. A title that needs this, with the path it passes, would show which of these lookups is actually required.
Not run: a full Windows build of the libraries or a title with this PR. The table above comes from the copied block, not from libkernel.
AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T05:04:56Z.
Review: CHANGES_REQUESTED
Requesting changes based on the still-unresolved findings already documented in the review thread. The Windows experiment in comment 6329077430 shows the fallback can return a different module by basename (including a system DLL) after the requested path fails or names a non-PE file, then mark it unowned so initialization is skipped; the fallback also changes the reported loader error. The same report found no title/path evidence for the added
game_modulesandlibssearches. Please address those concrete cases with a focused test before keeping these search paths.The PR is also 423 commits behind current
main524398151f1e(merge base0c6a5bd5938f) and the hosted conventions checks still fail; theWhatandTestedsections remain empty. Please rebase, complete the PR template and rerun the relevant checks after correcting the behavior. The independent Windows report says the broader module test set passed on an older base, but its copied-block probe is not a test of the library build.I manually compared the shared-file warnings: #5021 changes only Apple branches, #6879 only adds the Emscripten include, and #7201 changes Apple link-map handling. Those changes are distinct from this PR's Windows-only fallback block, so no dependency on those three is indicated by the current diffs.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-25T13:05:51Z.
Review: CHANGES_REQUESTED
Thanks for the PR. Findings, most of them from wachi35676's experiment above (verified against the diff):
DynamicLoader.cpp:186-190:GetModuleHandleW(filename)matches any loaded module with the same base name, from any directory, system DLLs included. When the requested file is missing or is not a PE file,dlopenreturns a different module and reports success. Match the whole resolved path, or the file identity, as FreeBSD'sload_objectdoes (object_match_name/ same device and inode).DynamicLoader.cpp:192-193,213: the reused handle isowned = false, soInitializeDeferredModuleis skipped andsceKernelLoadStartModulenever runsmodule_startor the initializers.DynamicLoader.cpp:197-204: nothing in the repo or in FreeBSD's rtld refers togame_modules/orlibs/; a path containing/is used as given. Name the title and the exact path it passes, or drop these candidates. The fourth candidate (<name>.guest.prx) is already tried byRelinkedModulePath_nid_no_patchbeforeLoadLibraryExW.DynamicLoader.cpp:207:std::filesystem::existsoverwritesGetLastError(), so the loggedWindows loader erroris no longer the originalLoadLibraryExWone (126 becomes 3). Save the error before the fallbacks and restore it.What/Testedneed the exact scenario and checks.main.Welcome to push a narrower version with a test that fails without it.
Pull request closed