Loader: forwarders honour LEONIDA_COMPAT_DIR; CLZERO scan keeps VirtualSize 0 sections (RT-LOADER-FORWARDER-COMPAT-CLZERO-SCAN) #2528
Closed
leonida/mandy
Tyrannys wants to merge 0 commits from
claude/loader-forwarder-compat into main
pull from: claude/loader-forwarder-compat
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2528
Loading…
Reference in a new issue
No description provided.
Delete branch "claude/loader-forwarder-compat"
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 closed
This pull request cannot be reopened because the branch was deleted.
Claimed in the coordination issue as: RT-LOADER-FORWARDER-COMPAT-CLZERO-SCAN (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231125400). Found by @kevincommits, item 5 of https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7230685285. Thanks!
What and why
Two loader bugs in
runtime/src/pe_loader.cpp:LEONIDA_COMPAT_DIR.resolve()asksresolve_compat()first, so a drop-in DLL the player put inLEONIDA_COMPAT_DIRowns all of its imports: a module is never served half by a shim and half by the drop-in, which would not share state.resolve_forwarder()never asked it. So an export forwarded into such a module still went to the shim, a bundled copy or System32.Fix:
resolve_forwarder()asksresolve_compat()before the shim lookup, with the same key and file name rule it already uses (".dll"added when the forwarder string leaves it out). A symbol the drop-in lacks stays unbound, as it does for a direct import. The ordinal is now parsed before the lookups, becauseresolve_compat()needs it.VirtualSize == 0.protect_sections()sized the scan of an executable section asmin(VirtualSize, SizeOfRawData), which is 0 for such a section, so its CLZERO loops were never patched on a CPU without CLZERO.map_image()takes a virtual size of 0 as the raw size and copies those bytes.Fix: both now use
section_file_bytes()(inpe_loader.h), so the scan covers exactly the bytesmap_image()copied.Item 4 of the later finding (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7230881417:
clzero_patch::patch()leavesVirtualProtectunchecked after patching) is not here: open #2036 already fixes it, so it is left to that PR.Tested
loader_test, intest_compat_modules(CPU only, synthetic images):testshim.F, which the test shim table has) is left unimplemented and does not reach the shim. WithoutLEONIDA_COMPAT_DIRthe same forwarder binds to the shim.mainthe second case fails ("F was not left unimplemented"); with the fix all 102 checks pass. The first case also passes onmainhere, because Windows finds the already loaded compat DLL by name through the System32 search, so the second case is the one that shows the bug.section_file_bytes():static_asserts inloader_test.cpp, including a virtual size of 0. The CLZERO path itself only runs on a CPU without CLZERO; the test machine has it (Zen 5), so that path is covered by the helper it now shares withmap_image()./W4), Release; no new warnings.GPUs tested: n/a (CPU test).
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).protect_sections, not to the CLZERO scan; #2036 owns theclzero_patch.hfix.🤖 Generated with Claude Code
Reviewed at head
472c9638con Windows 11 (MSVC 202219.44).Verification
loader_test,pe_loader_test, andgta6rt.ctest -R "^(loader|pe_loader)$": 2/2 passed.Findings (Request changes)
LEONIDA_COMPAT_DIRexport miss in a forwarder can still fall through toSystem32(pe_loader.cpp:2017-2024,2113-2129):Direct imports handle an owned compat miss by immediately returning
shims::make_unimplemented_thunk(dll, sym)(pe_loader.cpp:2096-2099). Inresolve_forwarder(), an owned compat miss returnsnullptr, which stops fallback insideresolve_forwarder(), but the caller inresolve()(pe_loader.cpp:2113-2119) treatsnullptrthe same as any lookup miss and falls through toLoadLibraryExA(dll.c_str(), nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32)(pe_loader.cpp:2122). If a System32 DLL shares the forwarding DLL's name and exportssym, it will silently supply a host implementation despite the compat DLL owning the forwarded module. Returning a distinct owned-miss status (e.g., via an out flag or enum) soresolve()goes directly tomake_unimplemented_thunkkeeps forwarded and direct compat ownership consistent..dllexplicit suffixes get.dllappended for compat lookup (pe_loader.cpp:2005,2019-2020):Because
shim_keyappends".dll"whenever the module name does not end with".dll", a forwarder naming a non-.dllextension (e.g.,winspool.drv) probeswinspool.drv.dllinLEONIDA_COMPAT_DIR, whereas the bundled lookup (pe_loader.cpp:2035) triesmodulebeforemodule + ".dll". Preserving an existing extension (or checkingmodulebeforemodule + ".dll"as bundled lookup does) would avoid surprising misses.The
CLZEROscan raw-byte calculation (pe_loader.cpp:2217-2221) cleanly matches the mapper (1737-1743) and clamps to the mapped image boundary.AI-assisted review + local MSVC verification.
@timbot103 thank you, both findings were right. They are fixed in e2f9c316e:
resolve_forwarder()now reports, through a newcompat_missout flag, that aLEONIDA_COMPAT_DIRmodule owns the forwarded name but lacks the export.resolve()then binds a failure thunk (make_unimplemented_thunk(dll, sym)), as it does for a direct import of the compat DLL, instead of going on to the forwarding module's System32 namesake. The flag is passed through forwarder chains.winspool.drv), then with.dll. It is no longer alwaysname + ".dll".New
loader_testcases, both failing at the previous head (472c9638c) and passing now (104 checks, 0 failed):version.dllwhoseGetFileVersionInfoSizeAforwards to a compat DLL that lacks the target. The import is unimplemented; before, it bound to System32's export.testcompat.drv.Answerwithtestcompat.drvin the compat folder. It binds to that file's export, which returns 42.AI-assisted (Claude Code).
Reviewed
e2f9c316eand verified the loader test suites on Windows 11.Code audit:
runtime/src/pe_loader.h,runtime/src/pe_loader.cpp:section_file_bytes()cleanly unifiesmap_image()andprotect_sections()so executable sections withVirtualSize == 0useSizeOfRawDataduring the CLZERO scan.resolve_forwarder()checksLEONIDA_COMPAT_DIRbefore shims and bundled modules (preserving an explicit extension like.drvbefore appending.dll), and propagatescompat_missso a compat drop-in missing a forwarded export binds a failure thunk instead of falling through to System32.Verification (Windows 11, MSVC 19.44, Ninja Release):
loader_testandpe_loader_test.ctest -R '^(loader|pe_loader)$': 2/2 passed (loader,pe_loader).python -I scripts/check_no_game_data.py: passed.AI-assisted (Antigravity, Gemini).
Hi @Tyrannys, thanks for this pull request. It currently conflicts with
main(conflicting file(s):runtime/src/pe_loader.h), so it carries theneeds rebaselabel. CONTRIBUTING.md asks authors to rebase their branch onmain; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.AI-assisted (Claude Code, Claude Opus 5.5).
Verified by OreoFR
c1ecf04ed+ PR heade2f9c316e(tested ate2f9c316e, head is now0cceb06ee)AI-assisted (Claude Code, Claude Opus 5.5).
Native Windows 11 + MSVC
19.44Verification (0cceb06ee8+origin/mainadfb3821a2)Verdict: PASS (0 blockers, 0
/W4warnings)Environment & Merge Check
10.0.26200), MSVC19.44.35228(x64,/W4 /permissive- /utf-8 /O2 /EHsc)0cceb06ee8ontoorigin/main(adfb3821a2,git merge-tree --write-treerc=0), and clean combined merge alongside#1600(runtime/src/pe_loader.cpp,runtime/test/loader_test.cpp).Red -> Green Results
origin/mainruntime/src/pe_loader.cpp+ PR#2528runtime/src/pe_loader.h&runtime/test/loader_test.cpp):1, failing all 3 forwarder-compat isolation checks:FAIL a forwarder into a compat DLL that lacks the symbol is unimplemented, not shimmed: F was not left unimplementedFAIL a compat DLL's missing forwarded export is not taken from a System32 namesake: the import was boundFAIL a forwarder to a compat module with its own extension finds that file: the forwarded import was not bound as HostPR #2528 + origin/main):loader_test.exe(withgta6rt_tls_host.dll, linked/OPT:NOREF /BASE:0x10000000000): PASS (120 checks, 0 failed,10.55 s,0/W4warnings).test_pe_loader_bounds.exe: PASS (test_pe_loader_bounds: ALL 60 CHECKS PASSED,0.94 s).Diff Audit Notes
resolve_forwardernow matchesresolve_import'sLEONIDA_COMPAT_DIRlookup order andcompat_missshort-circuit (so an owned compat DLL missing a forwarded export gets an unimplemented thunk instead of falling through to a shim orSystem32namesake), andprotect_sectionsusessection_file_bytes(VirtualSize == 0 -> SizeOfRawData) consistently withmap_image.rt::section_file_bytes(0, 0x200) == 0x200is covered viastatic_assert; an end-to-end syntheticVirtualSize == 0executable section CLZERO scan case could be added later if desired.AI-assisted.
Re-verified by OreoFR at head
0cceb06eeon main91bab934d: READY — red 3 fail → green 120 OK; ctest/link:loaderandpe_loaderpass,gta6rt.exelinks with imports equal to main (24 DLLs, 655 functions, no WS2_32); head unchanged since the earlier verification https://github.com/ProjectLeonida/mandy/pull/2528#issuecomment-7246471800 (that one was CONFLICT; this head now merges cleanly). Windows 11, RTX 4070 Laptop 8 GB, NVIDIA 621.40. AI-assisted (Claude Code, Claude Opus 5.5).runtime/test/loader_test.cpp, its foursection_file_bytesstatic_asserts left out because that helper is new in the PR's header):loader120 checks, 3 failed, the three forwarder/compat cases (forwarder into a compat DLL missing the symbol, System32 namesake, compat module with its own extension).git merge --no-ff):ctest -R "^(loader|pe_loader)$"2/2 pass.loadertest's "PE images are being scanned" timing guard tripped once on main and once on the merge (antivirus timing), both passed on rerun.Ready to merge per the maintainers' plan.
Independent check on Windows (not the author), at
0cceb06ee.runtimeand builtloader_test(MSVC 14.52.37025, Windows SDK 10.0.26100).LEONIDA_COMPAT_DIR, non-ASCII module name, dependency-loaded compat DLL exports).Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711.
AI-assisted: yes (opencode).
Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (
d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools,d3d12/, or general docs), please feel free to reopen it.