Repository navigation
RR plugin: stay off when another Ray Reconstruction plugin is already active - #43
Merged
Merged
Conversation
… active When another Ray Reconstruction plugin already holds the game's RR calls, or a second copy of WrongGPU-RR.asi is loaded, WrongGPU's RR plugin patches nothing, leaves Model M alone and writes one line to wronggpu-rr.log saying why. A plugin that loads later is found at the game's first call; WrongGPU's handlers then pass every call on unchanged. rr_other_plugin=take in wronggpu-rr.ini lets a player choose WrongGPU's RR on purpose. Every read of memory the plugin does not own is guarded; a read that fails counts as another plugin (the safe side). Two copies of the plugin write one log: each line is one append call under a process-wide lock, so lines never tear. The guard is read-only and generic (src/rr_guard.h/.cpp, HOOK-MODE.md "Another Ray Reconstruction plugin"). Tests: test_rr_guard (safe reads, jump forms, classification, one decision under 32 threads) and test_rr_guard_dll with a stand-in other plugin in every mode, for interface 2.7, 2.8 and 2.14, release and probe builds, plus a 200-run two-copy log stress. CI runs test_rr_guard. Fixes #22 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Review of the RR plugin guard, done in this commit: - Only a positive finding switches WrongGPU RR off: an address that ends in another named module (directly or through decoded hook jumps), or in a second copy of WrongGPU RR. Unreadable memory, code outside every module that does not jump on, the exe's own code and a jump chain longer than the hop limit are now inconclusive: counted, logged once with a "hook: coexistence check ...: inconclusive" line, and RR stays active. Execute-only pages count as readable for the code read (the copy is still guarded by the structured-exception handler). - The module holding the host's API table counts as the host too. When a separate loader called InitializeASI and the load check took the real host's own patches for another plugin, OptiPluginInit runs the load check again with that module as the host (nothing was patched before). New test mode hostsplit: a separate DLL calls InitializeASI. - The two-copies log test now makes every copy log at once: four more copies run InitializeASI / OptiPluginInit from threads while 16 game threads make the first call; no line may be torn. - The exit summary at DLL_PROCESS_DETACH only tries the log's process-wide lock (no wait under the loader lock); the comment says so. - A second copy of WrongGPU RR writes no exit summary. - The hook build's probe log starts a new empty file also when the old one could not be moved aside. - The hop limit and the docs agree: at most 4 hook jumps are followed, a fifth is too many (tested both ways). - g_take, the host modules and the pass-through targets are atomics. - The off modes check that the RR runtime is not loaded (and the clean mode that it is). - HOOK-MODE.md: what counts as a finding, the inconclusive cases, the known fail-open cases, the new log line and test modes. - Removed the Model M guard tools (tests/guard_inject.cpp, tests/guard_scene.cpp, tools/guard_modelm.py) and every reference. - The file-proxy build's log change (proxy_dll.cpp) is taken out of this pull request; it is not needed by the guard. Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
phantoslayer21
marked this pull request as ready for review
November 13, 2026 20:28
phantoslayer21
marked this pull request as draft
November 13, 2026 21:05
… is inconclusive
WrongGPU RR now switches itself off only on evidence that is positive by contract: a second
copy of WrongGPU RR, or the host's plugin API refusing our registration (NGX provider slot
taken, game-interface routes refused). A named module on the RR call path (a game's wrapper
DLL, an overlay, a host helper, a forwarded export's implementation DLL, or another RR plugin)
is inconclusive: RR stays active as in 0.6.0 and one line names the module and the place
("another module hooks the game's RR calls: <module> (...)").
- rr_other_plugin = off (default) | take | yield. take goes in front of a module found at load
or under our host routes and never switches RR off; yield keeps RR off whenever a named
module is on the path. The policy is one table, rr_guard::decide.
- The host guess (caller of InitializeASI, module of the API table) only shapes the wording;
the load-check re-run is removed, so no misleading "stays off" line can remain.
- The late check reports only exports that changed since the load check.
- Another module's PE headers: e_lfanew, data directories and every RVA the walk follows are
checked against SizeOfImage before an address is formed (PeView); jump targets are integer
arithmetic.
- Docs: the guard-page race and the log lock's best effort after a timeout are described
instead of claimed away.
- Tests: test_rr_guard covers the decide table for six layouts without a second RR provider,
the own-copy cases and the PE bounds; test_rr_guard_dll adds wrapper, wrapper --yield,
overlay, forward, helper, heaptable, helpertable, route-other --yield and route-refused, and
the existing modes now expect "stays active" plus the one line.
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
phantoslayer21
marked this pull request as ready for review
November 13, 2026 21:42
phantoslayer21
marked this pull request as draft
November 14, 2026 00:07
…GX registration claims no other plugin Third review. The load scan reads another module's headers only within the image's real extent (min of SizeOfImage and the mapping, measured first), reads names byte by byte inside it, reads import descriptors only within the directory's declared size, holds a module reference around module APIs, and stops after 200000 entries or 100 ms (inconclusive, RR stays active). The NGX refusal line says only that the host refused (its API gives one false for every refusal). take / yield wording in HOOK-MODE.md. Fixes #22 Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
phantoslayer21
marked this pull request as ready for review
November 14, 2026 01:04
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
This was referenced Nov 14, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Policy (decided 2026-11-14). WrongGPU RR stays off only when another Ray Reconstruction plugin is positively
identified: a second copy of WrongGPU RR, or the host's plugin API refusing our registration. A foreign hook that cannot
be identified as an RR plugin keeps WrongGPU RR on, because a false positive would take RR away from players whose game
merely has a wrapper, overlay or helper on that path.
Known limitation. A different RR plugin that hooks the call path from its own module is not identified as such. With
the default setting both can run side by side; the log names the module (see below). A player who sees that can set
rr_other_plugin = yieldto keep WrongGPU RR off.WrongGPU's RR plugin now notices when something else sits on the game's Ray Reconstruction call path, and says so in
one line of
wronggpu-rr.log. It switches itself off only on evidence that is positive by contract; it neverswitches RR off for a player on a guess. Model M is not affected.
When WrongGPU RR switches itself off
contract export): the second copy starts nothing and writes no exit summary.
routes (that route stays off). The API gives the same
falsefor an occupied slot and for a structure it does notaccept, so the log says only that the host refused; it does not claim another plugin.
Nothing else.
A named module on the call path is inconclusive. It may be another RR plugin, but it may as well be a game's own
wrapper DLL, an overlay, a security shim, a host helper in a third image or a forwarded export's implementation DLL.
WrongGPU RR stays active, as in 0.6.0, and one line names the module and the place:
another module hooks the game's RR calls: <module> (<where>); it is not known to be a Ray Reconstruction plugin: WrongGPU RR stays active (...). A bug report shows it, and the launcher's Last run can say "another module hooks thegame's RR calls:
<module>" from that line's beginning. What the scan cannot explain at all (unreadable memory, codeoutside every module that does not jump on, the exe's own code, more than 4 hook jumps) gets one "inconclusive"
diagnostic line and changes nothing either.
rr_other_plugininwronggpu-rr.ini(all three documented inHOOK-MODE.md):off(the default): as above.take: as before. With a module named at load (or under our host routes) WrongGPU RR goes in front of it andcontinues the game's other calls through it.
takenever switches RR off because of a named module (a copy ofWrongGPU RR still stops it, a host refusal still keeps that route off); a module that hooks after ours is only named.
yield: WrongGPU RR stays off whenever any named module outside the recognised images is on the path. Found at load:nothing patched, the RR core and runtime are not loaded. Found later: WrongGPU's handlers pass every call on
unchanged.
yieldcannot establish who owns that module: a game's own wrapper DLL, an overlay or a host helper in athird image switch it off as well.
The host is taken to be the module that called
InitializeASIand the module holding the host's API table. Withthe default setting this guess is now used only for the log's wording (the host's own patches are not named), so a
wrong host identification can no longer switch RR off. The load-check re-run of the first round is removed. It could
leave a misleading "stays off" line in the log, and it did not help when the host table is on the heap or in a helper
image.
Also in this pull request (the guard runs in every player's game at load):
SizeOfImageand what isreally mapped there, measured with
VirtualQuerybefore any header is read.e_lfanew, every data directory, everyRVA the walk follows and every byte of an import name are checked against it before an address is formed; import
descriptors are read only within the directory's declared size (
PeView,import_slots,thunksinsrc/rr_guard.{h,cpp}). Module APIs run under a held module reference. The load scan has a budget (200000 entries,100 ms) that fails open: over it, nothing is decided, one line, RR stays active. Jump targets are computed as
integers.
HOOK-MODE.mdnow says what that leaves. The log's process-wide lock is described as best effort after a timeout(
log_append.h,HOOK-MODE.md"The log with two copies").Beyond the feature: the hook plugin's log writing (unchanged from round 1). Two copies of the plugin in one process
write the same
wronggpu-rr.log. In the hook plugin (src/hook_dll.cpp,src/log_append.h), every line is now oneappend call, and the size check and rotation happen under a process-wide lock. The exit summary only tries the lock,
with no wait. The probe log starts a new empty file even when the old one cannot be moved aside. The file-replacement
proxy's part is not in this pull request.
Two decisions taken in this round (beyond the written design)
takenever switches WrongGPU RR off. In round 1,takewith a module that hooked after ours meant "cannot beapplied, stays off", which would have made
takestricter than the default. Now a late module is only named, as withoff.next to items 3, 4 and the rest of 6. Module references and the time budget are done here (third review).
not reported again as "took the RR calls after WrongGPU".
Fixes #22
Review findings, first review (head 58a283c)
(
src/rr_guard.cppVerdict::add,readable()), and this round goes further: a named module is no longer a findingeither (see second review 1).
InitializeASI: superseded. The table's module still counts as the hostfor the wording (
src/hook_dll.cppOptiPluginInit), but the host guess no longer decides anything with the defaultsetting, and the load-check re-run is removed (
src/hook_dll.cpp). Tests:hostsplit,heaptableandhelpertableall stay active.tests/test_rr_guard_dll.cppowncopy: fivecopies log at once;
build.pyrepeats it 200 times).src/hook_dll.cppexit_summary: 0 ms try).src/hook_dll.cpp, early return;checked in
owncopy).src/hook_dll.cpp,CREATE_ALWAYS).src/rr_guard.cpp; tested).g_takebecameg_mode, also atomic.tests/test_rr_guard_dll.cpp). This round checks it forwrapper --yield(not loaded) and for every stays-active mode (loaded).HOOK-MODE.md, "What the guard does not see"); more in the follow-up below.Review findings, second review (head 44db7ed)
src/rr_guard.{h,cpp}(Verdict::kForeign,decide,line_foreign,Mode) andsrc/hook_dll.cpp(guard_apply, the load, host-route and late checks). Anamed module is inconclusive: one line, RR stays active. Only a copy of WrongGPU RR or the host's API refusing us
switches off;
yieldgives the player the old behaviour. New tests:test_rr_guard(the wholedecidetable for agame-owned wrapper DLL, a host helper in a third image, an overlay-style wrapper, a forwarded export, the heap-table
and helper-table host layouts) and
test_rr_guard_dllmodeswrapper,overlay,forward,helper,heaptable,helpertable(stay active, RR answered by WrongGPU, NGX provider ours, runtime loaded),wrapper --yield(off),route-other --yield(passing) androute-refused(off by the host's answer). The existingfirst,inline,relay,execonly,hostsplit,late,late-replace,route-otherandroute-inlinemodes now expect "staysactive" plus the one line.
src/hook_dll.cpp: thehost guess is used for the wording only; the re-run is removed). Tests:
heaptable,helpertable,hostsplit.HOOK-MODE.md,src/rr_guard.hand the test comments (the race is described, not claimed away). Re-querying cachedregions and a test for it are split out to the follow-up.
module unnamed, never switch RR off. Split out to the follow-up (region-crossing reads, a second jump inside the
interface, the 1,024-module cap, ordinal imports, bound
FirstThunk, enumeration failure as inconclusive).e_lfanew, data directories and RVAs are now checked againstSizeOfImagebefore any pointerarithmetic (
src/rr_guard.{h,cpp}PeView;src/hook_dll.cppguard_thunks,guard_import_slots, the delay-loadwalk;
process_env), and jump targets are integer arithmetic. Tests:test_rr_guard(the real exe; synthetic headerswith a negative, too-small, absurd and out-of-image
e_lfanew; directories past or wrappingSizeOfImage; too fewdirectories; PE32; no signature). Module references and an overall time budget are split out to the follow-up.
src/log_append.h,HOOK-MODE.md). The "misleading off line left in the log" case is gone with the re-run. The other points are splitout to the follow-up: a lock-timeout test, marker creation failure, the host's loader-lock context, what the stress
loop proves, CI cost, a stricter parser warning.
Follow-up issue (items 3, 4, the old patch walk of 5, and 6): drafted for the maintainer to file.
Review findings, third review (head 7ef3a34)
src/rr_guard.{h,cpp}andsrc/hook_dll.cpp.PeView::str, each byte checked against the image's extent; a name without its NULinside the image is skipped, never read past (was
Reader::strwith up to 96 bytes from the first checked byte).import_slotsreads only the descriptors the import directory's declared size holds (the walk movedfrom
hook_dll.cpptorr_guard.cppso the unit test can drive it).mapped_extent(VirtualQueryover the committed regions of the module's allocation) is measuredbefore any header is read;
e_lfanewis checked against it before the NT headers are read; the extent ismin(SizeOfImage, mapping), so a forged largerSizeOfImagedoes not widen it.ModuleRef(GetModuleHandleExWfrom address,FreeLibraryat the end of the scope) aroundGetProcAddress/GetModuleFileNameW(process_env) and around each module's import walk and the export scan;a module unloaded meanwhile counts as nothing found.
Budget(200000 entries, 100 ms, the time looked at every 64 entries) counts every module, descriptor andname-table entry of the load scan. Over it, the scan decides nothing, logs
hook: coexistence check at load: stopped after <n> entries (<t> ms), over its budget ...; inconclusive, WrongGPU RR stays active, and RR staysactive in every mode (fails open; the process marker still stops a second copy).
test_rr_guard): an import name at the image's last byte with no NUL inside the image and readable bytesafter it (skipped, not read); names ending at the last byte; an import directory smaller than its descriptors (only
the declared ones) and smaller than one descriptor (none); another DLL's name; a
SizeOfImagelarger than themapping; NT headers past the mapping;
mapped_extent; the budget by entries (the walk stops, stays over) and bytime; the budget line's exact words.
HOOK-MODE.md("Another module's PE headers", "The load scan's budget") now claims only this: the extent boundswhere the walk reads, it does not make the memory stable.
line_ngx_refused(wasline_ngx_other):the host refused WrongGPU's NGX RR provider registration; the NGX route stays off (the game-interface route is decided on its own). The host API has no distinct signal for an occupied slot, so none isclaimed. Tests:
test_rr_guard(exact words, no "plugin is active", no "another provider");test_rr_guard_dllnew mode
provider-refused(the host refuses with no provider installed: the line, no other plugin claimed, no provideranywhere, the game-interface route stays ours), and
providernow expects the same line.takeandyield: done inHOOK-MODE.mdand here.takenever switches off because ofa named module (own copy and host refusal still apply);
yieldreacts to any named module outside the recognisedimages and cannot establish who owns it.
line_inconclusivebeside an own-copyfinding, the loader-lock statement, marker creation failure, the forward test's real loader forwarding.
hook_dll.cppis the existing integration's (its entry point and API); the newguard names and depends on no third-party product.
Tested (CPU only; counts from the saved run outputs)
python clean/rr_f/proxy/tools/build.py --out <dir>(all CPU tests; the probe and hook tests use the software D3D12adapter, WARP), on 334c93c: 201 test programs, 1801388 checks, 0 failures; 141
test_rr_guard_dllmode runs (32release and 15 probe modes for each of 2.7, 2.8 and 2.14, including the new
provider-refused), 0 failures; owncopystress (five copies logging at once) 200/200, 0 torn lines;
test_rr_guard595 checks, 0 failures (577 before);Python 33 tests OK (1 skipped).
tools/ci/run_proxy_core_tests.pyon that build: plugin CPU tests 6 run, 0 failed.build.py --no-testsstill builds and runs everytest_rr_guard_dllmode for 2.7, 2.8 and2.14 (release and probe) and the 200-run stress;
run_proxy_core_tests.pyrunstest_rr_guard.coexistence check at load: 0.10-0.13 ms),far below the budget.
file of this pull request (a first try named the new mode
ngx-refusedand wrote a test table on one line; bothmatched leak patterns and were changed before the push).
Not tested