loader: a run-time LoadLibrary takes the LEONIDA_COMPAT_DIR module too (RT-COMPAT-DIR-RUNTIME-LOADS) #1565
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!1565
Loading…
Reference in a new issue
No description provided.
Delete branch "rt-compat-dir-runtime-loads"
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?
Pull request successfully merged and closed
Claimed in the coordination issue as: RT-COMPAT-DIR-RUNTIME-LOADS (#1562, since #14 is at the 2,500-comment cap)
What and why
LEONIDA_COMPAT_DIRonly applied to static imports (runtime/README.md: "a run-timeLoadLibraryof the same name does not yet"). A mapped image'sLoadLibraryof a module the folder holds got the shim's pseudo-handle instead of the drop-in DLL, andGetProcAddresson the compat DLL's real handle looked the name up in the shim of the same module name first. One console module could then be served half by the drop-in and half by the shim, which the static step exists to prevent.Now
shims::BundledModuleOpsgainscompat_module/owns_compat_handle, answered byrt::Loaderfrom the samecompat_handle()its static step (resolve_compat) uses, so both get oneHMODULEper module. Inshims/library_loader.cpp:LoadLibrary*checks the compat folder before the shim registry and the bundled package DLLs;GetModuleHandle*answers a compat module's handle once loaded and NULL before (never the shim's pseudo-handle);GetProcAddresson a compat handle gives only that DLL's exports;FreeLibraryon it returns TRUE and keeps it loaded (it is the Loader's reference, static imports may be bound through it; compat modules already stay for the process lifetime).A compat file Windows refuses fails that
LoadLibrarywith Windows' error (logged) instead of throwing into the title.runtime/README.mdis updated.Tested
loader_testnow linksshims/library_loader.cppand gainstest_compat_runtime_loads, eight cases with a synthetic drop-in DLL and the test shim module: without the folder the shim still answers; with it,GetModuleHandleis NULL before the load,LoadLibraryWreturns the compat DLL,GetModuleHandle(with and without.dll) returns it after,GetProcAddressgivesAnswer(42) and not the shim'sF, a static import in the same Loader binds to the same export,FreeLibrarykeeps it loaded, and a file Windows refuses (error 193) fails the load without the shim or a throw.loader: 103 ok, 0 FAIL.ctest: 376/377; the one failure isws2_offlineunder-j 4(loopback bind failures; it failed the same way here on a run without this change), which passes 3/3 run alone.GPUs tested: n/a (CPU only). Built with MSVC (VS 2022 Build Tools 17.14) + Ninja via
scripts\build_runtime.ps1, Windows 11 Pro 10.0.26200.AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)Thanks for the probes. All points are addressed in 2cca47b:
LoadLibraryExflags reach the compat branch;DONT_RESOLVE_DLL_REFERENCESon a compat module fails withERROR_NOT_SUPPORTEDbefore loading or returning a loaded handle, as the bundled branch does (A and W tested).compat_handlefinds it by its full path (GetModuleHandleExW, reference kept), andowns_compat_handleby its folder (read outsidemutex_, sinceGetModuleFileNameWcan take the loader lock).GetModuleHandle/LoadLibraryreturn it, andGetProcAddressno longer fills in a missing export from the shim.main); the compat lookup runs before the ASCII/wide split, so non-ASCII basenames reach it; the folder's file names are listed once perLoader, so lookups no longer touch the disk.test_compat_runtime_edgesadds six cases, including a compat DLL importing a second one that lacks the shim's export; all six fail on582e14d. Full build and CTest pass here (377/377, RTX 4050).Written with AI assistance (Claude Code, Claude Opus 5.5) and reviewed with GPT-6 Sol High; every change above was checked against the code and the tests were run locally.
Re-checked at
2cca47b5cmerged cleanly onto currentmain(02f71ccfe, Windows 10 x64, MSVC 14.44 RelWithDebInfo, Ninja).All should-fix items and nits from the previous review are addressed cleanly:
LoadLibraryExA/Wflags reach the compat path and refuseDONT_RESOLVE_DLL_REFERENCESwithERROR_NOT_SUPPORTEDbefore loading or returning a cached handle.GetModuleHandleExWincompat_handleand folder lookup outsidemutex_inowns_compat_handle, soGetModuleHandle/LoadLibraryreturn them andGetProcAddressdoes not fall back to a shim.std::filesystem::equivalent, non-ASCII basenames are checked before the ASCII/wide split, andcompat_files_is snapshotted once perLoader.Local verification:
python -I scripts/check_no_game_data.pyon all 8 changed files: exit 0.loader_testcleanly (zero new warnings).ctest -R '^loader$': 114 checks, 0 failed (21.39 s), covering all newtest_compat_runtime_loadsandtest_compat_runtime_edgescases.(Minor non-blocking nit for a future cleanup: when
LEONIDA_COMPAT_DIRis set,owns_compat_module_handleinget_proc_addressruns before savingGetLastError().)Looks ready to merge.