Repository navigation
Conversation
…port name The UCRT's _get_narrow_winmain_command_line and _get_wide_winmain_command_line were not shimmed, so a /MD WinMain executable got gta6rt's own command line as lpCmdLine. GetCommandLineA/W and ExitProcess were shimmed under kernel32.dll only, and the loader matches DLL names exactly. Imported from kernelbase.dll, or from the API sets the umbrella libraries bind them to (api-ms-win-core-processenvironment-l1-1-0, api-ms-win-core-processthreads-l1-1-0), they went to the host. The package's vcomp140.dll imports ExitProcess from the latter. process_cmdline_test checks every name and the WinMain line. docs/runtime_imports.md: the dry-run table regenerated at this commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g it Without the shim, find() returns null and the WinMain check called it, ending the test with an access violation instead of a failure. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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. |
Claimed in the coordination issue as: #1548 (comment) (second new RT item)
Depends on: #1786. This is stacked on it because both regenerate the same rows of the
docs/runtime_imports.mdtable; only the last commit is this PR's.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,vcruntime140.dllandmsvcp140.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. Against Runtime: the game's command line and ExitProcess under every import name (WinMain line, kernelbase, API sets) #1786,XCurl.dll,msvcp140.dll,vcruntime140.dllandvcruntime140_1.dlleach move one import, this one, from host to shim.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.ctest: 102/103 pass. The exception isd3d12_draw, whose bundle-blend check fails on this machine onmaintoo: the same binary passed earlier today and fails every run since (finding). It's unrelated to this change.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