Repository navigation
Conversation
Windows' RtlPcToFileHeader returns NULL for an image it didn't map. The loader redirected only the host copies of the MSVC runtime, so a mapped image that imports it itself, such as a static-CRT _CxxThrowException or a crash or stack-walk helper, got NULL. A static-CRT C++ throw then records image base 0, and its catch never matches. Serve RtlPcToFileHeader under kernel32, kernelbase, ntdll and api-ms-win-core-rtlsupport-l1-1-0/-l1-2-0. The package's XCurl.dll, vcruntime140.dll and msvcp140.dll import it from the l1-1-0 set. Look the Windows function up on first use when no host copy has been redirected yet. pe_loader_test checks every name and the answers. tiny_game_static, the stand-in game linked with the static CRT, runs its C++ exception check under gta6rt. docs/runtime_imports.md: the dry-run table at this commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Flyander
left a comment
There was a problem hiding this comment.
Re-reviewed current head. The shim preserves the documented RtlPcToFileHeader contract: it uses Windows for loader-mapped images, adds the base for custom-mapped images, and returns NULL after the custom loader releases them. The alias table covers the package imports identified in the report, and the static-CRT exception test exercises the failure mode from #1786. The GitHub checks are still pending; the reported Windows/Vulkan test run is meaningful coverage. I found no blocker in this diff.
|
Tests pass but it cannot merge as-is. Built clean (VS 18/MSVC 19.51, Ninja): Conflicts: The AI-assisted review, no game files, no GPU. |
Both sides added code at the same places, so both are kept: tiny_game_static next to main's tiny_game_fixed and run_tiny_game_dir (runtime/CMakeLists.txt), test_pc_to_file_header next to test_inherited_reservation (runtime/test/pe_loader_test.cpp), and the RtlPcToFileHeader shim table next to cleanup_tls_clones (runtime/src/pe_loader.cpp). docs/runtime_imports.md takes main's table here; a later commit regenerates it from the dry-run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Regenerated from gta6rt --dry-run on the 16 package DLLs (1.0.2.1) with this branch's build. Four rows change because of this PR: XCurl, msvcp140, vcruntime140 and vcruntime140_1 each move RtlPcToFileHeader (from api-ms-win-core-rtlsupport-l1-1-0) from host to shim. The other changed rows were already stale on main, which serves shims the table never counted (the WinHTTP offline functions, more file-system calls and UCRT runtime exports). The comment above the shim table now names vcruntime140_1.dll too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@tupacfan04 @Flyander thanks for the reviews. I merged
Tested on the merged branch: Windows 11, AMD Radeon RX 5700 (driver 32.0.21045.29003, Adrenalin 26.11.2, Vulkan 1.4.315), MSVC 14.44, Vulkan SDK 1.4.363.1, CMake 4.4.5 and Ninja 1.13.2, RelWithDebInfo.
The comment above the shim table now names AI-assisted (Claude Code). |
|
Independent native Windows check of Built Focused exception tests only, using synthetic fixtures. AI-assisted. |
The only conflict is docs/runtime_imports.md: main's table (with its new --init column) and paragraphs are kept, plus this branch's RtlPcToFileHeader paragraph. The table's counts are regenerated from the dry-run in the next commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…561b65a) Regenerated with this branch's gta6rt --dry-run and --init on the 16 package DLLs (1.0.2.1), in main's new table format with the --init column. Every --init exits 0. Four rows move RtlPcToFileHeader from host to shim (this PR); the other changed rows count shims main already serves that its table did not. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Updated: Thanks @Roberto0953 for the rebase branch and @thehollowedone for the check. Your conflict notes matched what I found.
AI-assisted (Claude Code). |
|
Tested 62f15fd on Intel UHD 770, driver 32.0.101.7088, MSVC 19.44: gta6rt, tiny_game_static and pe_loader_test build, and ctest passes pe_loader (#15, "pe_loader_test: OK (88 checks)", including "PASS kernel32.dll!RtlPcToFileHeader is served by the loader", "PASS an address in the mapped image gives the image's base" and "PASS after the Loader is gone the address is no image's") and run_tiny_game_static_eh (#100, "tiny_game: PASS a C++ exception is thrown and caught inside the image" and "game exited with code 0"). Neither test opens a Vulkan device. pe_loader_bounds and the full ctest suite were not run, and I did not run main's pe_loader.cpp, so this does not show the new checks failing without the change. AI-assisted. |
|
Tested 62f15fd merged onto main 561b65a on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:
AI-assisted (Claude Code). |
runtime/CMakeLists.txt keeps this branch's run_tiny_game_static_eh next to main's gta6rt_stack and run_tiny_game_stack. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged the latest AI-assisted (Claude Code). |
LaugeM
left a comment
There was a problem hiding this comment.
This should go in first of the module identity PRs (#2075 carries it as a merge, so #2075 shrinks once it lands).
On upstream/main 5d74c27 the code still merges cleanly. git merge-tree reports one conflict, in docs/runtime_imports.md, the per-DLL table. runtime/CMakeLists.txt and runtime/src/pe_loader.cpp auto-merge, b7a3fed's /GA TLS change included.
- Main still binds a mapped image's own
RtlPcToFileHeaderimport to Windows. The only redirect isredirect_pc_to_file_headerfor host CRT copies (runtime/src/pe_loader.cpparound 849-890 on main), andpc_to_file_headercallsg_host_pc_to_file_header.load()with no null check, so the fallback to ntdll's export inhost_pc_to_file_header()is needed as well as the table. - The five names in the new
SHIM_TABLE(pc_to_file_header, ...)don't interact with #5731's "shim-owned modules skip the host" change.kernel32,kernelbaseandntdllare inowns_dll's host list, andapi-ms-*is excluded by prefix (runtime/shims/registry.cpp:487-496). So unshimmed imports from those DLLs still bind to the host whichever order the two land in. - The table conflict has come back on every main merge so far, because most of its changed rows count shims main already serves, not this PR. One way to stop that: keep only the new paragraph, and have whoever next regenerates the table pick up the four
RtlPcToFileHeadermoves.
AI-assisted review (Opus 5.5). Read the diff against main; not built (merge-tree against upstream/main only).
Claimed in the coordination issue as: #1548 (comment) (second new RT item)
Updated 23 Nov: #1786 has merged, and
main(3faac55) is merged into this branch with the conflicts resolved as the reviews asked, so the diff againstmainis only this PR.What and why
_CxxThrowExceptionputs the throwing image's base in the exception record, taken fromRtlPcToFileHeader(pThrowInfo), and the frame handler adds the ThrowInfo's RVAs to it. Windows'RtlPcToFileHeaderonly knows images the Windows loader mapped, so for ours it returns NULL. The loader already redirects that import in the host copies of the MSVC runtime (redirect_pc_to_file_header), which covers a/MDexecutable throwing through the hostvcruntime140.A mapped image that imports
RtlPcToFileHeaderitself still bound it to Windows. That covers a static-CRT (/MT) executable, whose_CxxThrowExceptionis linked into the image, and any crash or stack-walk helper that calls it directly. Such an executable's first C++ throw recorded image base 0 and was never caught. The package's ownXCurl.dll,msvcp140.dll,vcruntime140.dllandvcruntime140_1.dllimport it fromapi-ms-win-core-rtlsupport-l1-1-0.dll, the setOneCore_apiset.lib/mincore.libbind it to, so the executable may well do the same.The change (
runtime/src/pe_loader.cpp):pc_to_file_headerforRtlPcToFileHeaderunderkernel32.dll,kernelbase.dll,ntdll.dllandapi-ms-win-core-rtlsupport-l1-1-0/-l1-2-0.owns_dllalready treats all of these as host DLLs, soGetModuleHandlefor them is unchanged.pc_to_file_headercalledg_host_pc_to_file_headerwithout a null check, and that pointer is only set once a host copy has been redirected. It now falls back to ntdll's export on first use.docs/runtime_imports.md: a paragraph, and the dry-run table, regenerated on the merged branch.XCurl.dll,msvcp140.dll,vcruntime140.dllandvcruntime140_1.dlleach move one import, this one, from host to shim. The table's other changed rows were already stale onmain, which serves shims it never counted (the WinHTTP offline functions, more file-system calls and UCRT runtime exports).Tested
Windows 11, AMD Radeon RX 5700 (Adrenalin 26.11.2), MSVC 14.44, Ninja RelWithDebInfo, Vulkan SDK 1.4.363.1:
pe_loader_test's newtest_pc_to_file_headerruns before any host CRT is redirected. It checks:tiny_dll, while ours returns its base;Loaderis gone, that address gets NULL.tiny_game_static(the stand-in game linked with the static CRT) andrun_tiny_game_static_eh, which run its C++ exception check undergta6rt --run.main'spe_loader.cpp,pe_loaderfails its 5 new name checks andrun_tiny_game_static_ehfails, because the game can't catch its own exception. With this branch, both pass, and so doesrun_tiny_game_eh.cteston the merged branch (main3faac55), without the three window tests: 176 run, 167 pass, 9 skip, 0 fail. The skips need a variable or a feature this machine doesn't have (package, movie, corpus, validation layer, first-light folder, RGB9E5 render targets). Before the merge it was 102/103; the one failure,d3d12_draw, came from AMD's warm pipeline cache (finding), and that test passes here now.gta6rt --dry-runon the 16 package DLLs of my own 1.0.2.1 copy: every import binds, 0 unimplemented, with the counts in the table.AI-assisted (Claude Code).
Checklist
docs/design.md, with how it was confirmed. (N/A: no translator change.)🤖 Generated with Claude Code