Skip to content

gta6rt: keep an init failure's message under Wine; run_startup_cmdline passes on Wine - #8188

Open
XmYx wants to merge 2 commits into
ItsNotRexed:mainfrom
XmYx:wine-startup-cmdline-native
Open

XmYx wants to merge 2 commits into
ItsNotRexed:mainfrom
XmYx:wine-startup-cmdline-native

Conversation

@XmYx

@XmYx XmYx commented Nov 23, 2026

Copy link
Copy Markdown

Claim: #7913 (run_startup_cmdline under Wine)

run_startup_cmdline fails under Wine. Fixing the reason it fails first turned up a loader bug behind it, so this PR has two commits.

1. gta6rt: an init failure's message survives the rethrow (runtime/src/main.cpp, +8/−5)

--init/--run kept the init failure in a std::exception_ptr and later called std::rethrow_exception. Under Wine the outer handler then printed error: Unknown exception instead of <module>: DllMain returned FALSE. Wine's ucrtbase frees the stored exception before the rethrow (seen with WINEDEBUG=trace+seh). So when a package DLL's DllMain failed under Wine, the user lost the one line that names it.

The first catch now copies e.what() into a std::string, and the rethrow site throws a fresh std::runtime_error with it. That catch only ever handled std::exception, so nothing else changes. On Windows, stdout, stderr and the exit code stay byte-for-byte the same; the binding report still prints before it. The --init command-line area that #3881 edits is untouched.

2. tiny_startup_cmdline: relax only the native reference under Wine (runtime/test/fixtures/tiny_startup_cmdline.cpp, +25/−2)

The test's native reference run asserts that, at DLL attach, the UCRT hasn't configured argc/argv/wargv yet. That's true of Microsoft's UCRT, but Wine's built-in ucrtbase configures all three when it loads. So the test failed at the native step ("Native startup command line (args) returned 1") before testing the loader.

  • When it relaxes: only when it's both the native run (the PEB's image base is this image, not gta6rt.exe) and Wine (ntdll!wine_get_version, as tiny_game_abort_test: skip the native abort comparison under Wine #7904 does).
  • What it relaxes: the attach-time clause accepts a configured argc that matches. The "no wide argv at main" clause is skipped.
  • What stays strict: the command-line comparisons, the narrow argv checks and every check on the gta6rt --run path. The loader still has to provide the console-like state. Windows is unchanged.

Tested

Linux, Wine 10.0, clang-cl 21 + xwin cross build of main dde82f2. The ctest results:

main commit 2 only both
run_startup_cmdline fails at the native args step args + no_args pass; fail_init fails: "error: Unknown exception" passes (args, no_args, fail_init)
  • Unchanged, still passing: loader, pe_loader, startup_trace, dll_thread_calls, gta6rt_rejects_dry-run_init and gta6rt_rejects_init_run.
  • Negative control: with only main.cpp reverted, fail_init fails again with "Unknown exception".
  • The relaxed native reference still catches mistakes: a deliberately wrong command line or argc fails in both the native and the gta6rt run.
  • Clean: scripts/check_no_game_data.py. No game files are involved.
  • Not run on native Windows, where both new branches are inactive.

AI-assisted (Claude Code, Sonnet subagent, reviewed and re-run).

🤖 Generated with Claude Code

XmYx and others added 2 commits November 23, 2026 19:08
…ch; relax only the native reference

Under Wine the builtin ucrtbase has already configured argc and both argv
widths when the process image's TLS callback and the DLL's DllMain run, so
the native reference run could not show the console-like "argv not configured
at attach" state and failed before gta6rt was tested. Detect Wine in the
fixture (ntdll wine_get_version) and relax that one clause for the directly
run image only; the command lines are still compared, the attach-time argc
must equal main's, and the gta6rt --run steps keep every assertion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…it as "Unknown exception")

--init/--run held the failed attach in a std::exception_ptr and rethrew it after
the binding report. Under Wine the stored exception is freed before the rethrow,
so the user saw "error: Unknown exception" instead of "<dll>: DllMain returned
FALSE". Copy what() in the first catch and throw a fresh runtime_error with it;
the outer catch prints the same "error: <message>" and returns 1 as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thehollowedone

Copy link
Copy Markdown

Independent native Windows check of 3fd27e56 with MSVC 19.44.35230 x64, Release. The stock run_startup_cmdline CTest passed with quoted arguments, no arguments, and the synthetic initialization refusal.

For the refusal, the loader exited 1 and printed error: tiny_startup_cmdline_dll.dll: DllMain returned FALSE. It also printed the import binding report and never entered the synthetic guest.

Native Windows coverage with synthetic inputs. AI-assisted.

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.

2 participants