Skip to content

Runtime: the game's command line and ExitProcess under every import name (WinMain line, kernelbase, API sets) - #1786

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
dracbat:rt-process-import-paths
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
dracbat:rt-process-import-paths

Conversation

@dracbat

@dracbat dracbat commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #1548 (comment) (new RT item)

What and why

gta6rt --run gives a mapped executable its own command line and turns its ExitProcess into the end of the run (runtime/shims/process.cpp). Two import paths still reached the host:

  • WinMain's lpCmdLine. The CRT's WinMain startup gets it from the UCRT's _get_narrow_winmain_command_line / _get_wide_winmain_command_line, and those weren't in the UCRT shim set. A /MD WinMain/wWinMain executable bound them to the host UCRT and got gta6rt's own command line (--run <exe> --game-dir … --) instead of the game's arguments.
  • API-set names. GetCommandLineA/W and ExitProcess were shimmed under kernel32.dll only, and the loader matches DLL names exactly. The API-set umbrella libraries (OneCore_apiset.lib, mincore.lib in SDK 10.0.26100) bind them to api-ms-win-core-processenvironment-l1-1-0.dll and api-ms-win-core-processthreads-l1-1-0.dll. The retail package's own DLLs import nearly everything that way; vcomp140.dll takes ExitProcess from that processthreads set. An executable built the same way would read gta6rt's command line, and its ExitProcess would end the host before the exit code and the unimplemented-import summary are printed.

The change:

  • _get_narrow_winmain_command_line and _get_wide_winmain_command_line join the UCRT set (api-ms-win-crt-runtime-l1-1-0, ucrtbase, ucrtbased). They return the game's command line after the program name and the blanks that follow it, using the UCRT's own scan: the name ends at the first character up to ' ' outside quotes. The compare is unsigned, so a non-ASCII byte of the narrow line stays part of the name.
  • GetCommandLineA/W and ExitProcess are also served under kernelbase.dll and those two API sets, as library_loader.cpp already does for its functions.
  • docs/runtime_imports.md: a paragraph on the above, and the gta6rt --dry-run table regenerated. Against main's own build at 89b047cd, only vcomp140.dll changes: from 6 shim / 72 host to 7 / 71, its ExitProcess. The libHttpClient.GDK.dll, XCurl.dll, msvcp140.dll and vcomp140.dll rows were already behind main; its build gives 10/188, 8/132, 9/178 and 6/72 for them.

Tested

Windows 11, AMD Radeon RX 5700 (Adrenalin 26.11.2), MSVC 14.44, Ninja RelWithDebInfo, Vulkan SDK 1.4.363.1:

  • Full runtime ctest: 102/102 pass. 5 were skipped: the package-gated bink_decode, bink_audio, fsr_dispatch and bvh_builder (run without LEONIDA_GAME_DIR), and d3d12_rgb9e5_rtv (no RGB9E5 colour attachment on this GPU). The pass includes process_cmdline, loader and every run_tiny_game*.
  • process_cmdline_test now checks two things. Every kernelbase and API-set name hands out the kernel32 shim. The WinMain line is right from both api-ms-win-crt-runtime-l1-1-0 and ucrtbase for four cases: plain arguments, a quoted program name with a space, no arguments, and a non-ASCII program name.
  • Negative control: with main's process.cpp, the new checks fail (12 failures, exit 1). With this branch they pass.
  • gta6rt --dry-run on all 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

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. Only import names and counts, as docs/runtime_imports.md already records.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A: no translator change.)

🤖 Generated with Claude Code

dracbat and others added 2 commits November 22, 2026 14:05
…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>

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed the import table and command-line tests. The new kernelbase/API-set names map to the existing process shims, and the WinMain line tests cover quoted names, no arguments, and non-ASCII executable names. No automated checks are visible for this head; I found no blocking issue in the diff.

@mesterember104-cpu

mesterember104-cpu commented Nov 22, 2026 •

Copy link
Copy Markdown

Tested 7f67a9a on Intel(R) UHD Graphics (Tiger Lake (Xe-LP) iGPU 0x9a78, subgroup 8..32, no mesh), driver 32.0.101.7088, Windows 11, MSVC 14.44: pass

Full runtime ctest (RelWithDebInfo): 85/89 pass. process_cmdline also run separately: exit 0 — the new checks pass (kernelbase and the API-set names hand out the kernel32 shim for GetCommandLineA/W and ExitProcess; the WinMain line is right from api-ms-win-crt-runtime-l1-1-0 and ucrtbase for all four cases, code page 1250, non-ASCII program name included). loader, run_tiny_game* and tiny_game_exit_code pass in the full run. The 4 failures are pre-existing on main and touch nothing this PR changes: d3d12_draw (bundle blend pixel (0, 0): got 255,0,0,255, expected red 64 — the #1660 fence clash), d3d12_descriptor (Intel minimum-LOD views read one mip too detailed — #1725/D3D-219), d3d12_vulkan_device (placed SRGB-cast clear row 0 byte 1: ours bb, host bc — D3D-221, #1752), d3d12_copy_xfmt (ExecuteCommandLists failed: invalid copy or resolve — D3D-220). Not run: bink_decode, bink_audio (no game package), d3d12_rgb9e5_rtv (RGB9E5 render targets unavailable on this adapter, same as the author's AMD), d3d12_queue_wait (standalone Vulkan device creation failed on this driver — environment, needs a look), gameinput disabled (no SDL3 installed).

AI-assisted (GLM, operated by the account owner).

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.

4 participants