Skip to content

runtime: initialize guest command line in --init mode - #3881

Open
Desamodeth wants to merge 1 commit into
ItsNotRexed:mainfrom
Desamodeth:fix/init-guest-command-line
Open

Desamodeth wants to merge 1 commit into
ItsNotRexed:mainfrom
Desamodeth:fix/init-guest-command-line

Conversation

@Desamodeth

Copy link
Copy Markdown
Contributor

The first-boot --init pass can report successful DLL initialization for the same image and arguments that fail at process attach under --run. Only --run initialized the guest process command line. Set it before the shared callback dispatch so both passes expose the image name and the arguments following --.

On main at 4c52ce27, I built the existing tiny_startup_cmdline fixture unchanged and passed -- fail-init to all three loader modes. Its DLL checks the command line in DllMain and rejects this argument.

Mode Main With this change
--dry-run 0, map only 0, map only
--init 0, reported two modules initialized 1, reported the DLL's rejection
--run 1, reported the DLL's rejection 1, reported the DLL's rejection

Extended the existing CTest to exercise both callback modes with no extra arguments, a quoted argument, and a rejected attach. The fixture now also rejects a missing startup argument snapshot. The extended test failed against the original loader and passed after the fix. Built the Windows x64 MSVC Release CPU configuration and ran 24 related CTests, all passed. Synthetic fixtures only.

Rebased onto aa2988cc (identical runtime source tree) and repeated the build and all 24 checks.

Coordination item 7086600162 in #3796. Follow-up to #2661. Open PR #3790 moves the --run callback dispatch to the entry thread and touches the same block. When integrating both, keep the command-line setup for both modes before their respective callbacks.

AI-assisted (Codex Astra 6.2 High).

AI-assisted-by: Codex Astra 6.2 High

@kacper-serewis kacper-serewis 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.

Windows x64 validation at 7fb25cd passed the startup test and 12 additional CLI cases. Both modes exposed the guest arguments before DLL attach, including the failure marker. A marker confined to the host overlay path had no effect. The separate command-line test verified spaces, embedded quotes and trailing backslashes.

@justr4mzi

Copy link
Copy Markdown
Contributor

Tested 7fb25cda on Windows 11 25H2 (build 26200.9974), MSVC 19.44.35230.0 (VS 2022 Build Tools 17.14.45, CMake + Ninja RelWithDebInfo):

  • Build (cmake --build runtime/build --target gta6rt gta6rt_tls_host tiny_startup_cmdline tiny_startup_cmdline_dll tiny_game tiny_game_fixed tiny_game_exit_code_test -j 6): exit 0.
  • ctest --test-dir runtime/build --output-on-failure -R "run_startup_cmdline|gta6rt_rejects_|run_tiny_game": 12/12 passed (#39 run_startup_cmdline 0.33 s, plus run_tiny_game* and gta6rt_rejects_*, 0.86 s total).
  • Direct check & negative control:
    • PR gta6rt.exe --init tiny_startup_cmdline.exe -- hello "two words": 2 module(s) initialised, exit 0.
    • PR gta6rt.exe --init tiny_startup_cmdline.exe -- fail-init: exit 1 (DllMain returned FALSE).
    • Baseline main (f847748c) gta6rt.exe --init on the updated fixture -- hello "two words": exit 1 (DllMain returned FALSE), confirming DllMain failed to capture the command line before set_command_line() ran in --init.
  • gta6rt.exe usage check: prints --init <image> ... [-- game arguments...].
  • python -I tests/test_docs_cli_flags.py (3/3) and python -I tests/test_docs_repo_paths.py (2/2): passed.

AI-assisted (Gemini, Antigravity).

@Ingenioeren

Copy link
Copy Markdown

Synthetic startup integration check of 7fb25cda with #3790 e9e6b578. I applied this PR’s non-main.cpp changes over the #3790 head and reconciled the overlap by setting the command line for init || run before either path starts callbacks. --init retains its inline initialization; --run still attaches and enters on the guest thread.

On Windows 11, clang-cl/lld 23.1.5, Debug, CPU-only build, all 12 focused CTests passed. These include quoted/no-args/failed-attach cases for both actions, rollback, native/mapped TLS (both reached 0x6A), argument rejection, and the synthetic guest’s exit code. A --dry-run trace contained map events and exit only, with no attach or guest entry.

The broader 13-test run also selected run_tiny_game_eh. It exits 0xE06D7363 in this Clang Debug build both with the reconciliation and with #3790’s original runtime source, so this run does not show an exception-handling regression from the overlap. Synthetic inputs only. AI-assisted.

@lahlousaad4

Copy link
Copy Markdown
Contributor

Independent Windows x64 validation at 7fb25cda (MSVC 19.44). Built gta6rt and the startup fixtures. CTest passed run_startup_cmdline and startup_trace (2/2).

The command-line test covered --init and --run with arguments, without arguments, and with a synthetic DLL whose process attach returns FALSE. A separate --init --trace <file> --trace-d3d12 -- fail-init run recorded the attach failure and exited 1 before any D3D12 trace event. All runs used synthetic guests.

@Vonsek

Vonsek commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 7fb25cd on Windows 11 (MSVC RelWithDebInfo): full runtime build, then ctest for the shim/loader tests (loader, pe_loader, loader_tls, dll_thread_calls, unimplemented_policy, startup_trace, xmem, process_cmdline, file_system, winhttp_offline, xgameruntime, run_tiny_*, allocator_proxy) — 27 of 27 passed. AI-assisted.

@tupacfan04

Copy link
Copy Markdown
Contributor

PASS. runtime/src/main.cpp:109 sets the guest command line inside if (init || run), before loader.initialise() and therefore before TLS callbacks/DllMain; --run is unchanged. There is no double free: the storage is static std::string/std::vector (runtime/shims/process.cpp:165-178), never freed manually, and the setter runs once. --init output is unchanged (only module(s) initialised after success), CTest exercises both actions including the failing attach (runtime/test/check_startup_cmdline.cmake:8-26), and the fixture's !g_captured check (fixtures/tiny_startup_cmdline.cpp:60) detects a missing line. Merge clean.

compileall clean; the full pytest run's 10 failures are identical on clean main (Windows rmtree lock, CRLF anchors, shader semantics).

Approve. AI-assisted review, no game files, no GPU.

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.

7 participants