Skip to content

runtime: rewrite bound delay QueryApiImpl and always log it - #2349

Open
SimSalabimse wants to merge 7 commits into
R0Y00:mainfrom
SimSalabimse:cursor/runtime-queryapi-delay-bind-381f
Open

SimSalabimse wants to merge 7 commits into
R0Y00:mainfrom
SimSalabimse:cursor/runtime-queryapi-delay-bind-381f

Conversation

@SimSalabimse

Copy link
Copy Markdown
Contributor

Change

Account-picker TRACE_API on tip-of-main still shows zero QueryApiImpl / provider … proxied after the scoped package GPA patch (#2166). Y reaches GameInput (0x20); #2201 never gets a chance. Do not treat this as FakeUser slot-7 evidence.

Delay-imported xgameruntime.dll!QueryApiImpl binds through the CRT delay helper (its own unhooked GetProcAddress), so the title keeps calling the real export while the proxy only remembered it. This change:

  • rewrites a delay QueryApiImpl IAT slot only when it already equals the remembered real export (delay_query_slot_is_bound); unbound thunks stay untouched
  • periodically rescans so a bind after the load-driven pass is still caught
  • always logs GetProcAddress("QueryApiImpl") past the generic 40-line GPA cap
  • logs the first QueryApiImpl remembered via {gpa|iat|export} and a one-shot QueryApiImpl status when xgameruntime is loaded

Synthetic PE control + Windows startup_runtime_proxy_scope cover the bound rewrite; unbound delay and a pre-attach cached pointer are negative controls (the cache still calls the real export — claimable follow-up).

Refs #870.

AI-assisted.

Verification

g++ -std=c++17 -Wall -Wextra -Werror -Isrc -o /tmp/gpa_patch_check tests/startup_runtime_gpa_patch_check.cpp
/tmp/gpa_patch_check
# -> startup_runtime_gpa_patch: ok
/tmp/gpa_patch_check --mutate name-only
# -> FAIL: name-only accepts QueryApiImpl from other.dll (exit 1)
python3 -B tests/docs_links_check.py

On Windows after configure:

ctest --preset dev --no-tests=error -R '^startup_runtime_gpa_patch(_name_only_control)?$'
ctest --preset dev --no-tests=error -R '^startup_runtime_proxy_scope$'

Evidence and follow-up

Source-built / synthetic only; no game files. docs/startup-runtime.md X2W_RUNTIME_PROXY row updated.

User re-test: rebuild from this branch with $env:X2W_TRACE_API='1', press Y. Look for QueryApiImpl remembered via, always-on GPA for that name, bound delay QueryApiImpl import(s) rewritten, and any provider … proxied.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

Account-picker TRACE_API still shows zero providers after the scoped package
GPA patch. Delay-imported QueryApiImpl binds through the CRT helper (unhooked
GetProcAddress), so the title keeps calling the real export. Rewrite that slot
only after it equals the remembered export; leave unbound thunks alone. Always
log GetProcAddress("QueryApiImpl") past the generic 40-line GPA cap, and record
how the real export was first remembered.

Synthetic PE control covers bound vs unbound delay slots; the Windows scope
fixture delay-loads QueryApiImpl with unbound and pre-attach-cache negatives.

Refs R0Y00#870.

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head 95f0f67562aaff1610d639b55dd0a603928ec4f5 (comment only).

Scope read: runtime_gpa_patch.h (new delay_query_slot_is_bound), runtime_proxy.cpp (delay-slot rewrite, always-log QueryApiImpl GPA, periodic quiet rescan), CMakeLists.txt (helper now delay-loads the fake xgameruntime), the gpa-patch check and the proxy-scope host/helper.

Commands executed locally (Linux):

  • git diff --stat origin/main...HEAD -> 8 files, +212/-53
  • git diff --check origin/main...HEAD -> clean
  • python3 tests/docs_links_check.py -> self-test passed, 19 files / 453 links ok
  • python3 tests/bidi_controls_check.py -> 1630 files, no bidi controls
  • g++ -std=c++17 -Isrc tests/startup_runtime_gpa_patch_check.cpp + run -> startup_runtime_gpa_patch: ok; --mutate name-only -> FAIL: name-only accepts QueryApiImpl from other.dll (control fails as intended)
  • Mutation: dropped && slot_value == real_query from delay_query_slot_is_bound -> synthetic delay QueryApiImpl still unbound: MISMATCH, startup_runtime_gpa_patch: FAIL (2). The new test kills it. Reverted with git checkout -- ..
  • CI at this head: Windows build+test pass, Linux Python checks pass, gfx1013 fixtures pass. No separate Windows VM run from me; the new Windows-loader test (startup_runtime_proxy_scope) is covered by the passing CI Windows job.

Findings

  • P1: none.
  • P2: none.
  • nit (runtime_proxy.cpp, delay branch of patch_module): remember_real_query_from_export() runs on every delay hit on every quiet scan (every ~250 ms per module). It is cheap once real_query is set, but an early if (load_real_query()) skip would avoid a repeated GetModuleHandleW + GetProcAddress.
  • nit: the periodic scan relies on slot == real export to detect the bind. A package helper that caches the export elsewhere before the first scan is covered by the negative control (pre-attach cached pointer), so behavior is as documented; worth keeping that control.
  • nit: the quiet pass logs only when a slot was rewritten, which is a good choice. The first-call status line (log_query_status_once) is a useful diagnostic.

Semantics check: unbound delay thunks are never touched (value != real export). Only an exact match to the remembered real export is rewritten, with VirtualProtect around the 8-byte aligned store. The delay-GetProcAddress path stays unhooked, as before. Clean-room and title are neutral. PR is mergeable.

AI-assisted; commands listed were executed locally.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The independent Windows run passed the three GPA and loader-scope tests on 95f0f675. The background delay-slot rewrite still needs to preserve a value changed by the delay loader after the eligibility check. It reads the real export, calls VirtualProtect, and then writes the proxy for any value other than the proxy. If the slot was restored to its delay thunk in that interval, the fallback can overwrite the restored state.

Please make the replacement conditional on the slot still holding the exact real export at the write, and count only successful replacements. A source-built check can exercise both transitions deterministically: a real export that remains installed is replaced, and a slot changed back to the thunk before the replacement stays untouched. Keep the existing unbound, same-name decoy and pre-attach pointer controls.

@KelboLive

Copy link
Copy Markdown
Contributor

APPROVED. Rewrites bound delay QueryApiImpl with logging.

cursoragent and others added 2 commits November 26, 2026 12:13
Keep main's registry-import and save-path behavior, and keep the bound
delay QueryApiImpl rewrite on top of it.

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>

# Conflicts:
#	src/startup_stubs/runtime_proxy.cpp
#	tests/startup_runtime_proxy_scope/host.cpp
…lds the export

The write compare-exchanges the slot with the remembered export and counts
the replacement only when that exchange stores the proxy. The source-built
check covers a slot that stays the export and a slot restored to its thunk
before the store. Quiet scans reuse an export that was already remembered.

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
@SimSalabimse

Copy link
Copy Markdown
Contributor Author

Addressed the review in f8b51edb (after merging current main in 6adfba14). The delay-slot store now compare-exchanges against the remembered real export, so a slot that still holds that export is replaced and counted, while a slot restored to its delay thunk before the exchange is left untouched and not counted. startup_runtime_gpa_patch covers both transitions, and a mutant helper that stores the proxy for any other value fails both checks. The unbound-thunk, same-name decoy and pre-attach pointer controls remain in startup_runtime_proxy_scope. Quiet scans reuse an already-remembered export and still log only when a store succeeds.

Verification (Windows 11 25H2 26200, MSVC 19.42, dev preset):
ctest --preset dev --no-tests=error -R '^(startup_runtime_gpa_patch(_name_only_control)?|startup_runtime_proxy_scope)$' returned 3/3 passed, exit 0. On Linux, the python-linux check list returned 208/208 passed.

AI-Assisted

@SimSalabimse
SimSalabimse requested a review from R0Y00 November 26, 2026 12:33

@pigalot pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independently reviewed f8b51edb integrated over main e582a9a4 (tree 3784ee7e). The merge is clean (CMakeLists.txt and docs/startup-runtime.md auto-merged) and git diff --cached --check origin/main is clean.

Earlier finding (R0Y00, changes requested on 95f0f675): the code is addressed, the end-to-end evidence is not. replace_bound_delay_query now stores the proxy with InterlockedCompareExchange64 against the remembered real export, and patch_module counts only a successful exchange. Because the store compares at the moment it writes, a thunk the delay loader puts back after the eligibility read stays as it is. startup_runtime_gpa_patch covers both transitions with a fake exchange. Restoring the old unconditional store fails it at slot restored to the thunk stays the thunk: MISMATCH and restored thunk not counted: MISMATCH.

What I ran.

. .\tools\dev.ps1; cmake --preset <preset>
cmake --build --preset <preset> --target startup_runtime_gpa_patch startup_runtime_proxy_scope startup_stub_gameinput startup_stub_consumer startup_runtime_local startup_console_mode startup_console_mode_decoy
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_runtime_(local|local_control|gpa_patch|gpa_patch_name_only_control|proxy_scope)|startup_console_mode(_control|_provider_control)?)$'
ctest --test-dir out/build/<preset> --no-tests=error -j 1 --repeat until-fail:10 -R '^startup_runtime_proxy_scope$'
  • Results: 8/8 pass in dev and in release /O2, with no skips.
  • Repeats: startup_runtime_proxy_scope passes 10 of 10 repeats in each preset.
  • Other stand-ins: startup_stub_gameinput and startup_stub_consumer, which also compile runtime_proxy.cpp, build in both presets.

Finding: startup_runtime_proxy_scope does not exercise the new delay-slot rewrite, and its unbound-thunk control does not hold. Each mutant below was applied alone to src/startup_stubs/runtime_proxy.cpp, startup_runtime_proxy_scope (with the carrier) rebuilt in dev, the test rerun, and the file restored from its raw bytes. git diff --quiet was clean afterwards.

Mutant startup_runtime_proxy_scope
delay branch returns before the rewrite (no delay slot is ever rewritten, the same delay-slot handling as main) passes
real_bits = *slot (any non-proxy delay slot counts as bound, so the unbound thunk is rewritten) passes
  1. The rewrite path never runs. With the rewrite removed, the helper log shows only its GetProcAddress import being patched: x2w-runtime proxy: 1 import(s) patched in package module startup_runtime_proxy_helper.dll. Yet bound delay slot rewritten to proxy still passes. The CRT delay helper resolves QueryApiImpl through the helper's own GetProcAddress import, which the scan has already hooked. So the bind itself stores the proxy, and the slot never holds the real export for the new code to replace. That is also why delay bind wrote real export or proxy accepts either value.
  2. The negative control reads too late. With the unbound thunk rewritten, the log shows 2 import(s) patched in package module startup_runtime_proxy_helper.dll. The thunk is replaced in the same scan that hooks the helper's GetProcAddress. wait_for_helper_hook waits for that scan, so before_bind already reads the proxy. delay_query_slot_is_bound(proxy, real, proxy) is then false and the slot never changes after that, so both delay slot unbound before first use and unbound delay slot not rewritten pass.

The device-free check stays sound. But the one test that runs the real loader, which the body and docs/startup-runtime.md give as coverage for the rewrite, passes for this PR, for main's handling and for the unsafe rewrite R0Y00 asked to rule out.

Suggested direction (unconfirmed):

  • Make the slot bind to the real export first. Load the helper and call call_delay_query before the proxy carrier attaches. The bind then goes through the unhooked GetProcAddress. Check that the slot equals xgr_query, then load the carrier and wait for the slot to become the proxy.
  • Make the unbound control state its expectation. After the helper's scan has run, require the slot to still point inside the helper image (between the module base and SizeOfImage), not just to equal an earlier read of itself. A second helper that is never called would give a clean unbound slot for this.

Other mutants (same procedure; startup_runtime_gpa_patch for the header):

Mutant Result
proxy stored without the compare-exchange (the pre-fix store) killed: slot restored to the thunk stays the thunk: MISMATCH
every exchange attempt counted killed: restored thunk not counted: MISMATCH
bound test ignores the real export killed: unbound thunk refused: MISMATCH
export not remembered on a delay hit survives; in this fixture real_query is already remembered through the hooked GetProcAddress
QueryApiImpl lookups capped with the generic 40-line log survives; no test reads the always-on log line

Non-blocking, a hypothesis I did not reproduce. In a module built with /guard:cf, the delay IAT can be protected. The MSVC delay-load helper then keeps that section read-only and unprotects it under its own lock only while it writes a slot. The background pass calls VirtualProtect on the slot's page, compare-exchanges, then restores the protection it saw, without that lock. Suppose another thread's first call to a different delay import in the same module takes the helper through its unprotect/write/reprotect at the same time. This pass could then restore read-only between the helper's unprotect and its write, and the helper's write would fault. In the other order, it could leave the section writable. Nothing in this repository builds with /guard:cf, so the fixtures cannot show it. Leaving delay slots alone in an image whose load config sets IMAGE_GUARD_PROTECT_DELAYLOAD_IAT would avoid the question.

Verdict: changes requested on f8b51edb, for the loader fixture above. The compare-exchange itself looks right to me.

Environment: Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10. No GPU is involved.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on f8b51edb.

This reply was AI-assisted.

cursoragent and others added 2 commits November 27, 2026 22:37
Keep main's behavior where the files overlap, and keep the bound delay
QueryApiImpl compare-exchange on top of it.
Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
The loader test called the delay import after GetProcAddress was already
hooked, so the bind stored the proxy and the slot rewrite never ran. The
helper now binds through the unhooked lookup first, and the test waits for
that real export to become the proxy. A second helper is never called; after
the scan its thunk must still lie inside its own image.

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
@SimSalabimse

Copy link
Copy Markdown
Contributor Author

The loader test was calling the delay import after GetProcAddress was already hooked, so the bind wrote the proxy and the rewrite never got a real export to replace. The helper now calls it before the proxy attaches. The test checks the slot is the real export, then waits for that slot to become the proxy. A second helper is never called, and after the scan its thunk has to still sit inside its own image.

I built the source-built check, then ran it again with the exchange removed. bound delay slot rewritten to proxy was MISMATCH and the check failed (8). The loader test waits for that same change, so dropping the rewrite leaves the real export in the slot and the wait fails.

g++ -std=c++17 -Wall -Wextra -Werror -Isrc -o /tmp/gpa_patch_check tests/startup_runtime_gpa_patch_check.cpp
/tmp/gpa_patch_check
/tmp/gpa_patch_check --mutate name-only
./out/pe-env/bin/python -B tools/run_checks_parallel.py --from-dir tests/checks/python-linux

The check printed startup_runtime_gpa_patch: ok, the name-only control exited 1, and the Python run was 245 passed.

Windows test PC: the three tests passed twice, ctest exit 0.

AI-Assisted

@pigalot pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retested eafec814 integrated over main 2e12dd8e (tree 987cb1c4). The merge is clean (CMakeLists.txt and docs/startup-runtime.md auto-merged) and git diff --cached --check origin/main is clean.

My earlier finding on f8b51edb (the loader fixture did not exercise the rewrite): addressed. The helper now binds its delay slot before the proxy attaches, and the test checks that the slot is the real export first. A second, never-called helper must keep its thunk inside its own image. My two earlier survivors are now killed:

Mutant f8b51edb eafec814
delay slot never rewritten (main's handling) passed killed: bound delay slot rewritten to proxy: MISMATCH
any non-proxy delay slot counted as bound (unbound thunk rewritten) passed killed: unbound delay thunk stays inside its image: MISMATCH
proxy stored without the compare-exchange killed killed
every exchange attempt counted killed killed
bound test ignores the real export killed killed

What I ran. I built startup_runtime_gpa_patch, startup_runtime_proxy_scope, startup_stub_gameinput, startup_stub_consumer, startup_runtime_local, startup_console_mode and startup_console_mode_decoy in dev and release, then ran:

ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_runtime_(local|local_control|gpa_patch|gpa_patch_name_only_control|proxy_scope)|startup_console_mode(_control|_provider_control)?)$'
ctest --test-dir out/build/<preset> --no-tests=error -j 1 --repeat until-fail:10 -R '^startup_runtime_proxy_scope$'

8 of 8 pass in Debug and Release /O2, with no skips. startup_runtime_proxy_scope passes 10 of 10 repeats in each preset.

New finding: the loader test no longer loads anything after the proxy attaches, so the late-load path that main tests is now uncovered. On main, host.cpp loads the carrier first and then the helper ("late-load package helper"). It then waits for the helper's GetProcAddress import to be hooked by the worker. At this head both helpers, the decoy and the fake xgameruntime.dll all load before the carrier, so the initial scan finds everything. This came from my suggested direction, and I didn't flag the cost at the time.

The mutant: the worker runs only its first patch_package_modules and never rescans.

  • On main 2e12dd8e (if (rescan_package_modules.exchange(...)) patch_package_modules(); changed to run once): startup_runtime_proxy_scope fails at helper sees proxied xgameruntime QueryApiImpl: MISMATCH.
  • At eafec814 (if (tick == 0) patch_package_modules(true);): the test passes. Two narrower mutants also pass: dll_loaded ignoring the load notification, and the new periodic quiet pass removed.

AGENTS.md asks not to weaken existing tests. The load-notification path is also the one docs/startup-runtime.md and the CMakeLists.txt comment still describe ("Notification only enqueues; rewrite runs after link").

Suggested direction (unconfirmed): load startup_runtime_proxy_helper_unbound.dll after the carrier, instead of before it. Keep the bound helper where it is. The unbound helper then needs the worker's load-driven scan to get its GetProcAddress hooked, which a resolve_query wait like wait_for_helper_hook would check. Its delay thunk is still never called, so the in-image check stays the negative control. The scan-once mutant should then fail again.

The periodic quiet pass is new in this PR. With the bind moved before attach, no test now needs it. A slot bound after the load-driven scan through an unhooked lookup would need it, but I don't see a cheap way to build that through the real loader. I'm not asking for it.

Verdict: changes requested on eafec814, for the lost late-load coverage only. The compare-exchange and the new bound and unbound controls look right to me. R0Y00's changes-requested review on 95f0f675 also still stands. This supersedes my changes-requested review on f8b51edb.

Environment: AMD Ryzen 7 9800X3D, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10. No GPU is involved.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on eafec814.

This reply was AI-assisted.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Thanks for the compare-exchange and the bound and unbound helpers. I reviewed head eafec814 against current main (1f07b2c1). R0Y00's request is met in code. A g++ 17 -Wall -Wextra -Werror build of startup_runtime_gpa_patch_check.cpp prints startup_runtime_gpa_patch: ok, and five header mutants all fail it. A plain store instead of the CAS gives slot restored to the thunk stays the thunk: MISMATCH, counting every attempt gives restored thunk not counted: MISMATCH, and the other three (the bound test ignoring the real export, address_in_image without its upper bound, the pre-check dropped) fail too. R0Y00 will still need to re-review, because that changes request stands. Two things block the merge:

  1. Please restore the late-load coverage, as pigalot asked on this head. On main, host.cpp loads the carrier first and the helper after it (check("late-load package helper", ...)). At eafec814 both helpers load before the carrier. No load_beside( call follows the carrier, and grep -c late-load on host.cpp → 0. The worker's first scan therefore sees every module, and the dll_loaded rescan never runs. pigalot's scan-once mutant (if (tick == 0) ...) and their notification-ignored mutant both pass at this head. pigalot's suggestion would fix this: load startup_runtime_proxy_helper_unbound.dll after the carrier and wait for its GetProcAddress hook with wait_for_helper_hook. The CMake comment "Notification only enqueues; rewrite runs after link" would then be true again.
  2. Please merge current main. git merge-tree --write-tree 1f07b2c1 eafec814 exits 1 with CONFLICT (content): Merge conflict in docs/startup-runtime.md. Only one table row conflicts. Keep runtime: count XMA context and XApu command activity in the audio stand-ins #2107's X2W_AUDIO_ACTIVITY=1 row from main, with your updated X2W_RUNTIME_PROXY=1 row below it. Main's proxy row is byte-identical to the base row (cmp prints nothing), so there is nothing else to reconcile. Please merge rather than rebase.

Also worth fixing:

  • The new 250 ms quiet pass (else if (tick % 10 == 0) patch_package_modules(false);) has no test: pigalot's mutant that removes it passes. It also never stops. On the regular-import path, patch_module calls VirtualProtect(slot, 8, PAGE_READWRITE, &old) before if (*slot != ...hooked_get_proc_address). Every regular GetProcAddress and QueryApiImpl slot in the EXE and package helpers therefore gets a protect/restore pair four times a second. On main that happened only on module loads (grep -c 'tick % 10' → 0). The new delay path already compares first. Moving the comparison before VirtualProtect, limiting the quiet pass to delay QueryApiImpl slots, or dropping the pass would fix this.
  • CI ran neither new test. The Windows job ran ctest --preset pr (100% tests passed out of 69), and grep -c for startup_runtime_proxy_scope and startup_runtime_gpa_patch on its log gives 0 and 0. Please post a Windows startup_runtime_proxy_scope run on the fixed head.

Environment: Linux. I reviewed the git objects statically, ran git merge-tree, built the device-free check with g++ (plus the five mutants) and read the CI job logs. I did no Windows or loader run, so the loader mutant results above are pigalot's.

This comment was AI-assisted.

cursoragent and others added 2 commits November 28, 2026 10:32
Keep the audio-activity row from main and the updated runtime-proxy row
from this branch.

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>

# Conflicts:
#	docs/startup-runtime.md
The bound helper still binds QueryApiImpl to the real export before the
carrier loads. The second helper loads after that scan, so its
GetProcAddress hook needs the load-driven rescan and its thunk stays
inside its image. Regular import slots are compared before VirtualProtect
so a quiet pass does not change protection on a slot that is already patched.

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>

@pigalot pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retested 3ceef4a4 integrated over main ec71c290 (tree bb3f0da7). The merge is clean and git diff --cached --check origin/main is clean. The author's merge of main (9d2d0700) resolves the one conflicting table row in docs/startup-runtime.md by keeping main's X2W_AUDIO_ACTIVITY=1 row and the PR's X2W_RUNTIME_PROXY=1 row.

My earlier finding on eafec814 (late-load coverage lost): addressed. host.cpp now loads startup_runtime_proxy_helper_unbound.dll after the carrier and waits for its GetProcAddress hook (late-load helper sees proxied xgameruntime QueryApiImpl). The bound helper still binds before the carrier loads, and the unbound thunk must still lie inside its own image after the scan. The scan-once mutant that passed at eafec814 now fails.

What I ran. I built startup_runtime_gpa_patch, startup_runtime_proxy_scope, startup_stub_gameinput, startup_stub_consumer, startup_runtime_local, startup_console_mode and startup_console_mode_decoy in dev and release, then ran:

ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_runtime_(local|local_control|gpa_patch|gpa_patch_name_only_control|proxy_scope)|startup_console_mode(_control|_provider_control)?)$'
ctest --test-dir out/build/<preset> --no-tests=error -j 1 --repeat until-fail:10 -R '^startup_runtime_proxy_scope$'

8 of 8 pass in Debug and Release /O2, with no skips. startup_runtime_proxy_scope passes 10 of 10 repeats in each preset.

Mutants. Each was applied alone to src/startup_stubs/runtime_proxy.cpp (the last one to runtime_gpa_patch.h), the two tests rebuilt in dev and run with --repeat until-fail:5, and the file restored from its raw bytes. git diff --quiet was clean afterwards.

Killed:

Mutant First mismatch
worker scans once and never rescans late-load helper sees proxied xgameruntime QueryApiImpl: MISMATCH
load notification ignored and the quiet pass removed late-load helper sees proxied xgameruntime QueryApiImpl: MISMATCH
delay slot never rewritten (main's handling) bound delay slot rewritten to proxy: MISMATCH
any non-proxy delay slot counted as bound unbound delay thunk stays inside its image: MISMATCH
new compare-first check inverted for GetProcAddress slots host GetProcAddress(xgameruntime) is proxied: MISMATCH
proxy stored without the compare-exchange slot restored to the thunk stays the thunk: MISMATCH, restored thunk not counted: MISMATCH

Surviving:

Mutant Why
load notification ignored (quiet pass kept) the 250 ms quiet pass hooks the late helper inside the test's 2 s wait
quiet pass removed (notification kept) the load-driven scan does the same work
new compare-first check inverted for regular QueryApiImpl slots no loader fixture has a regular xgameruntime.dll!QueryApiImpl import; main has the same gap for that branch

Equivalent:

Mutant Why
new compare-first check removed for GetProcAddress slots the store below is already guarded by the same comparison; only the VirtualProtect pair differs, which no test observes

The first two survivors are the two rescan paths covering for each other: either one alone gets the late helper hooked, and removing both fails. I'm not asking for a test that tells them apart.

Other notes, none blocking.

  • The compare before VirtualProtect on regular slots means a quiet pass no longer changes page protection on slots that are already patched. I read it; no test observes it (see the equivalent mutant).
  • The /guard:cf protected delay IAT hypothesis from my review on f8b51edb is unchanged. I still have not reproduced it and nothing in this repository builds that way.
  • CI's ctest --preset pr does not run startup_runtime_proxy_scope or startup_runtime_gpa_patch, so the results above are from my local runs.

Verdict: approved on 3ceef4a4. This supersedes my changes-requested review on eafec814. R0Y00's changes-requested review on 95f0f675 still stands on the PR; the compare-exchange it asked for is in the code and covered by startup_runtime_gpa_patch. I am not merging this.

Environment: AMD Ryzen 7 9800X3D, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10. No GPU is involved.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on 3ceef4a4.

This reply was AI-assisted.

@SimSalabimse

Copy link
Copy Markdown
Contributor Author

The second helper loads after the carrier again, with the late-load package helper check, and the test waits for that helper's GetProcAddress hook. The first helper still binds the delay slot to the real export before the proxy attaches. Current main is merged, with the audio-activity switch row kept above the runtime-proxy row. Regular import slots are compared before VirtualProtect, so the quiet pass leaves an already patched slot's protection unchanged.

g++ -std=c++17 -Wall -Wextra -Werror -Isrc tests/startup_runtime_gpa_patch_check.cpp is ok. --mutate name-only exits 1 with FAIL: name-only accepts QueryApiImpl from other.dll. The five header mutants (plain store, count every attempt, bound test ignoring the real export, image check without the upper bound, pre-check dropped) each fail that binary. The Linux Python suite reported all 254 checks passed.

Windows test PC, head 3ceef4a (upstream main 3926a28 merged):

ctest --preset dev --no-tests=error -j 1 -R "^(startup_runtime_gpa_patch(_name_only_control)?|startup_runtime_proxy_scope)$" -E "startup_audio_output|startup_audio_pacing|startup_audio_provider"

passed 3/3 twice, exit 0. startup_runtime_gpa_patch_name_only_control printed FAIL: name-only accepts QueryApiImpl from other.dll and ctest still passed it, as expected.

ctest --preset dev --no-tests=error -j 1 -R startup_runtime_ -E "startup_audio_output|startup_audio_pacing|startup_audio_provider"

passed 6/6 once, exit 0.

AI-Assisted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants