Commit Graph

10 Commits

Author SHA1 Message Date
21ea2bb1d0 runtime: RT-136 review follow-up: check the test's setup, say what the returned table is valid for
process_cmdline_test now checks the return values of _putenv_s/_wputenv_s and says
when _wenviron already exists at startup, so the first-call check cannot pass
silently without exercising the lazy wide-table creation. process.cpp notes that
the returned table is the CRT's own and valid until the next _putenv, as with the
msvcrt.dll original.
2026-11-23 00:10:18 +08:00
2e6b237729 runtime: __getmainargs/__wgetmainargs read the host environment at call time (RT-136)
set_command_line kept _environ/_wenviron pointers. The host CRT has no wide
environment until a wide environment function first runs, and _putenv/_wputenv
reallocate both tables, so a wide-character startup calling __wgetmainargs got
a null or dangling environment. The shims now read the tables when asked and
make the CRT create a missing one first.

process_cmdline_test covers both functions: the first wide call, and variables
set before and after set_command_line.
2026-11-23 00:03:20 +08:00
6684d836ff Runtime: serve the game's command line and ExitProcess under every import 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>
2026-11-22 14:05:53 +00:00
fa4d54f22d process shim: keep the game's command line wide so a non-ASCII argument can't crash --run (RT-84)
main.cpp turned each game argument into std::filesystem::path::string(),
which throws std::system_error under MSVC when the ANSI code page has no
mapping for a character. Nothing caught it, so gta6rt --run ended in
0xc0000409 before the game started.

set_command_line now takes wide strings: __wargv and GetCommandLineW hold
the arguments exactly, and the narrow argv and GetCommandLineA are their
CP_ACP text from WideCharToMultiByte, which replaces a character the code
page lacks instead of failing, as the CRT does.

process_cmdline_test passes wide arguments and checks a Latin-1 one and a
Greek, Cyrillic and CJK one that no single-byte code page holds, so the
crash is covered on every system locale, not only 1253.
2026-11-22 13:28:05 +03:00
c8a341bc3f Merge pull request #1039 from sanuk369 2026-11-22 01:08:31 -05:00
232dd31ceb process: the command line parses back to __wargv (backslash rules, ANSI code page)
quote() escaped quotes but ignored CommandLineToArgvW's backslash rules,
so GetCommandLineA/W and __argv disagreed for an argument ending in a
backslash ("C:\My Games\" next" parsed back as 2 arguments, not 3) or
holding a backslash before a quote. A backslash run before a quote, or
before the closing quote, is now doubled.

widen() decoded the arguments as UTF-8, but main.cpp passes
std::filesystem::path::string(), which is ANSI code page text, so cafe
with an accent reached __wargv as caf\uFFFD. It widens from CP_ACP now;
under a UTF-8 activeCodePage that is the same thing.

New process_cmdline_test (ctest process_cmdline) checks that
GetCommandLineW parses back to __wargv.
2026-11-22 11:36:11 +05:30
8b51490ea7 process: park game threads that end the run until the host exits
Under Wine before 11.2, gta6rt --run sometimes exited 0 although the game
ended with 1 (run_tiny_game_exit_code in CI's Wine 9.0 job: 13 of 64 runs).
end_run signalled the host and called ExitThread; the host's ExitProcess
could then send SIGQUIT to that thread while it was exiting, Wine counted
the thread out twice and the process ended with _exit(0). Upstream fixed
it by blocking SIGQUIT during thread exit (4a9bc42a, wine-11.2).

end_run now parks every caller while a run is in progress (the first one
after recording the code and signalling), so no game thread is mid-exit
when the host calls ExitProcess. This also fixes two threads calling exit
at once: the second one called ExitProcess itself, sometimes before the
first had stored its code, and ended the process with 0 on any OS.

CI requires run_tiny_game_exit_code again.
2026-11-21 22:40:56 -07:00
1b3ddd4cf3 runtime: shim the Debug UCRT (ucrtbased.dll) for the game's argv and exit
A Debug build of the stand-in game links ucrtbased.dll rather than
ucrtbase.dll. The process shim only covered api-ms-win-crt-runtime and
ucrtbase, so __p___argc/__p___argv went to the host CRT. The game then got
gta6rt's own arguments (argc=6) and run_tiny_game failed in the Debug
configuration, which is the Visual Studio generator's default.
2026-11-22 01:10:57 +01:00
4abd54571b runtime: rename shims/process.h to process_shim.h (it hid the CRT's <process.h> from <thread>)
With runtime/shims on the include path, <thread>'s #include <process.h> found #316's header, so
_beginthreadex was undeclared in d3d12_com.cpp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 18:47:53 -05:00
0ca9bb8bc0 Runtime: gta6rt --run, and a stand-in game executable run through the loader
gta6rt --run <exe> [-- args] maps and binds the executable, initialises its
modules and calls its entry point on a game thread. shims/process.cpp answers
the process-level imports through the game's own import table: argv/argc and
GetCommandLine are the game's (UCRT api-set/ucrtbase and msvcrt forms), and
exit/_exit/quick_exit/ExitProcess/abort end the run with that exit code
instead of the host. gta6rt then exits with the game's code directly, so the
game's atexit handlers don't run during host shutdown.

tiny_game.exe (CTest run_tiny_game, run_tiny_game_exit_code) does what a title
does in its first second: arguments, a static initializer, a 4 MiB allocation,
a file round trip, a thread, and xgameruntime.dll imports, which the shim
registry answers instead of the link-time stub. thread_local and a C++
exception are opt-in (LEONIDA_RUN_TLS / LEONIDA_RUN_EH) until #93 and #176.
2026-11-21 23:50:31 +01:00