runtime: trampoline xgameruntime!QueryApiImpl for pre-attach GPA caches #3880
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!3880
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3878"
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?
@Ammmae0x on GitHub · 2026-12-02 17:37 UTC · original
Ammmae0x:runtime/queryapiimpl-trampoline→main· +888 −20 · 7 files · 1 commits · draftRefs #2350, #870, #2349
A
QueryApiImplpointer cached viaGetProcAddressbefore the proxy attaches keeps pointing at the export, so IAT/GPA rewrites never reach it and FakeUser /X2W_TRACE_APInever see providers on that path. This change trampolinesxgameruntime.dll!QueryApiImplat the export itself once the real export is known.What landed (single commit, 7 files, +888/-20):
src/startup_stubs/runtime_gpa_patch.h— pure x64 prologue length decoder and relocator (no Windows calls), so the source-built check tests it directly: whole-instruction boundaries for a 12-byte absolute patch (mov rax, imm64; jmp rax) and a 14-byte indirect patch (jmp [rip+0]+ slot), RIP-relativedisp32and relative-branch fixups, and refusal (zero bytes written) for a prologue that is too short, contains RET/UD2/VEX/unknown opcodes, or has a relative branch / RIP-relative access targeting the stolen bytes themselves. A resume stub more than 2 GiB away is refused when the adjusted displacement no longer fits.src/startup_stubs/runtime_proxy.cpp— oncereal_queryis learned (viaexport,gpaoriat), the export is trampolined once, idempotently (trampoline_state+ wait-for-settle inremember_real_query). The resume stub (relocated prologue + jump back toreal + stolen, allocated near the export so RIP-relative fixups fit,VirtualAlloc+FlushInstructionCache) is allocated and published asforward_querybefore the export entry is patched, soproxy_query(and the XAsync helpers, now also onforward_query) never recurse into their own trampoline.real_querykeeps the original export address, so bound delay-IAT comparisons and logging still work. The install is refused (logged, export left unpatched) when the export's module is notxgameruntime.dll— a forwarded export and the decoy's same-named export both fail that guard — or when the prologue cannot be relocated safely. Protection is restored and the instruction cache flushed. No-op in the source-built fixture (X2W_RUNTIME_PROXY_FIXTURE).tests/startup_runtime_proxy_scope/— the fakexgameruntimenow answers one test provider/IID pair with a fake object (query_object/object_callsexports).host.cppverifies the cached pointer keeps its original numerical address and calling it after attach goes throughproxy_query(returns a wrapper, not the real object; a method through the wrapper reaches the real object; the real export runs once), plus thatdecoy.dll!QueryApiImplstays unpatched (answers its own0xA11C0001, never enters the proxy). No new test targets.tests/startup_runtime_gpa_patch_check.cpp— unit tests for instruction lengths, 12/14-byte plans and relocation (including a load-bearing unfixed-copy control), plus refusal cases;--mutate name-onlyis unchanged, and--mutate prologue-reloc(unregistered manual control) also printsFAIL:with exit 1.docs/startup-runtime.md— one sentence on theX2W_RUNTIME_PROXY=1row describing the export trampoline and its limits.Linux verification (this host has no mingw/MSVC, so no Windows compile check):
Note:
form_coverage_check.pyneedsiced_x86in the venv (out/pe-env,pip install iced-x86); the systempython3lacks it and fails withModuleNotFoundErrorbefore any check runs. That is environmental, not this change.Caveats: the Windows-only code (
runtime_proxy.cpptrampoline install,startup_runtime_proxy_scope) could not be compiled or run on this Linux host. The fixture's fake export prologue is covered only by the decoder's instruction set (register saves, stack adjustment, RIP-relative LEA / indirect call, relative calls/jumps); a realxgameruntime.dllprologue outside that set is refused safely and logged, which the Windows run will show.WIN-VERIFYis the arbiter.WIN-VERIFY: pending | sha=23848272803f463784eab7065124aecd44d509d1 | targets=startup_runtime_proxy_scope startup_runtime_gpa_patch | ctest=^(startup_runtime_proxy_scope|startup_runtime_gpa_patch(_name_only_control)?)$ | release=true
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.