feat(runtime): redirect run-time loads of served DLLs to AnyBox's libraries #69
No reviewers
Labels
No labels
accessibility
bug
ci
docs
documentation
duplicate
enhancement
fixes issue
good first issue
help wanted
invalid
library request
libs
needs rebase
question
relinker
stale
tools
unblocks title
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Dark3581--AnyBox!69
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/69/head"
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?
@Dark3581 on GitHub · 2026-11-23 04:36 UTC · original
Dark3581:feat/loader-redirect→main· +372 −3 · 10 files · 1 commits · merged 2026-11-23 04:39 UTCWhat
The relinker only rewrites import tables, so a DLL a title loads by name at run time bypasses it. GDK modules do exactly that for the game runtime:
xgameruntime.dll. Instead, a helper callsLoadLibraryExW(L"xgameruntime.dll", NULL, flags)with flags0x800(LOAD_LIBRARY_SEARCH_SYSTEM32) or0xA00(adding the application directory). It then callsGetProcAddressforQueryApiImpl,InitializeApiImpl,InitializeApiImplEx,InitializeApiImplEx2,XErrorReportandUninitializeApiImpl, and returns0x89240101if the load fails. (Measured withobjdumpon one module's helper; the call sites are in the comments below.)C:\Windows\System32\xgameruntime.dllexists and exports exactly those six functions plusDllCanUnloadNow. So these modules would silently get the desktop runtime, not AnyBox's, and the title's runtime objects would be split between two implementations.runtime/src/LoaderRedirect.cpp:ab_runtimepoints the import slots forLoadLibraryExW/ExA/W/AandGetModuleHandleW/A/ExW/ExAin title-side modules at its own functions. Title-side means not AnyBox'sab_*libraries and not modules under the Windows directory; slots are matched by the addresseskernel32andkernelbaseexport.LdrRegisterDllNotification).LibraryMapData.inc(the relinker's own table, generated from each library'sImports.txt) loads AnyBox's library besideab_runtime.dll, whatever search flags the caller passed. Other names, data-file loads and address lookups pass through unchanged.[anybox] loader: LoadLibraryExW(xgameruntime.dll) from title.exe+0x7c9f loads ab_xgameruntime.dll.ARCHITECTURE and the game testing guide describe it, and the debt fragment lists what it does not cover: delay-loaded imports,
GetProcAddress-reached loaders, directLdrLoadDll, and loads from inside Windows modules.This is the first half of supporting GDK titles' runtime calls. The second half,
QueryApiImpland the related entry points inab_xgameruntime, follows in its own PR.Tested
Windows 10, MinGW (GCC) and MSVC 2022. This PC has the desktop
xgameruntime.dllin System32.New
e2e_dynamic_load: the relinked fake title calls:LoadLibraryExW(L"xgameruntime.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32)and getsab_xgameruntime.dll(checked by module path);GetModuleHandleW(L"XGameRuntime.dll"),GetModuleHandleExAandLoadLibraryA("xgameruntime"), which return the same module;GetProcAddressfor a runtime export, which resolves;LoadLibraryW(L"kernel32.dll"), which is unchanged.The log has one
loader:line per call style.MinGW
ctest: 74 of 74. With MSVC,e2e_dynamic_load, stub, crash, async and task queue e2e pass, and every target builds exceptab_gameinput, which needsgameinput.lib, which this machine doesn't have.python tools/check_conventions.pyanddebt_fold.py --check: ok.Checklist
main; no other open PR implements the same functionspython tools/check_conventions.pypasses (no comments in code, one declaration per export, Conventional Commit subjects)AbxNotImplemented/AbxUnsupported); silent stubs are listed under Silent stubs through a debt fragmentdocs/dev/debt/changes/<branch>.mdLdrRegisterDllNotification@Dark3581 on GitHub · 2026-11-23 04:36 UTC · original
Call sites behind the measurement (one bundled HTTP client module, image base 0x180000000):
mov r8d,0x800ormov r8d,0xa00,xor edx,edx,call [LoadLibraryExW]; returns0x89240101when the module is null.lea rdx,<name>; call [GetProcAddress]for QueryApiImpl, InitializeApiImpl, InitializeApiImplEx, InitializeApiImplEx2, XErrorReport, UninitializeApiImpl.