Skip to content

Runtime: gta6rt --run, and a stand-in game executable run through the loader - #316

Merged
ItsNotRexed merged 4 commits into
ItsNotRexed:mainfrom
IAmNotSiob:loader-run
Nov 21, 2026
Merged

ItsNotRexed merged 4 commits into
ItsNotRexed:mainfrom
IAmNotSiob:loader-run

Conversation

@IAmNotSiob

@IAmNotSiob IAmNotSiob commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

The gta6rt --run item claimed in #156, toward the README's "PE loader and import shims ⚠️ Skeleton. Untested against the real executable".

What and why

The loader could map an image (--dry-run) and run DLL initialisers (--init), but nothing had ever run an executable. The first thing RT-5 does on day one is run one, so this rehearses it with a stand-in.

  • gta6rt --run <exe> [--game-dir DIR] [-- args]: map, bind, initialise() (TLS callbacks, DllMain), then call the EXE's entry point on a game thread with an 8 MiB stack. It prints the binding report, then game exited with code N, then any unimplemented imports that were called, and exits with the game's code.
  • shims/process.cpp: the process-level imports an EXE's CRT startup makes through its own import table:
    • argv/argc and GetCommandLineA/W: the game's (<exe name> args), not gta6rt's. That's __p___argc/__p___argv/__p___wargv, _configure_*_argv, __p__acmdln/__p__wcmdln on the UCRT api set and ucrtbase.dll, and __getmainargs/__wgetmainargs on msvcrt.dll.
    • exit, _exit, _Exit, quick_exit, ExitProcess and abort from the game end the run, not the host. The code is recorded and the run signalled, and gta6rt then ends the process with that code itself. If it let the host return normally, the shared CRT would run the game's atexit handlers during host shutdown, and on MinGW one of those overwrote the exit status.
    • Calls made inside host DLLs (not through the game's IAT) aren't seen. The Xbox executable's CRT imports are expected to go through its IAT like MSVC's, but that's unverified.
  • tiny_game.exe (CTest run_tiny_game, plus run_tiny_game_exit_code with WILL_FAIL): does what a title does in its first second. It checks its arguments and command line, a static initializer, a 4 MiB allocation, a file round trip, a second thread, and imports from xgameruntime.dll. It links against a stub that would fail those calls; under --run the shim registry (Runtime: offline xgameruntime shim, part 1 (XGameRuntime, XSystem, XTaskQueue, XAsync) #257) answers them. Then it calls exit(). No game data.

Tested

MinGW-w64 GCC 13 build of gta6rt and the stand-in, run under Wine 9.0:

tiny_game.exe  ... shim=7 host=112 module=0 unimplemented=0
running tiny_game.exe
tiny_game: PASS argv is the game's command line ("hello" "42"), not gta6rt's
tiny_game: PASS GetCommandLineA is the game's command line
tiny_game: PASS a static initializer ran before main
tiny_game: PASS a 4 MiB heap allocation works
tiny_game: PASS a file round trip through the CRT works
tiny_game: PASS a second thread ran and joined
tiny_game: PASS XGameRuntimeInitialize is answered by the gta6rt shim (S_OK)
tiny_game: PASS XSystemGetDeviceType is answered by the gta6rt shim (Series X)
tiny_game: OK
game exited with code 0

-- wrong args → the game exits 1 → gta6rt exits 1. The MSVC build (UCRT import names) is CI's first run.

Two opt-in checks

  • C++ exception (LEONIDA_RUN_EH=1): with Runtime: register each mapped image's x64 unwind table (.pdata) #176 on main, a MinGW build catches its exception (libgcc's SEH unwinder only needs the registered .pdata). An MSVC build still crashes on throw: _CxxThrowException resolves the throw info relative to the image it gets from RtlPcToFileHeader, which only knows modules the Windows loader mapped. This is the likely cause, seen as a CI crash with the check on. Fixing it means making the mapped image known to that lookup, so it's a separate item, and the check stays opt-in.
  • thread_local (LEONIDA_RUN_TLS=1): needs static TLS (Runtime: install static TLS for mapped images #93). MinGW's emulated TLS passes, which says nothing about MSVC's _tls_index path.

Rebased on main (with #176).

… 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 ItsNotRexed#93 and ItsNotRexed#176.
@NWX10

NWX10 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Tested ff45269 with a native MSVC build (the PR was tested with MinGW + Wine): RTX 3060 Ti machine, Windows 11, MSVC 14.44: pass.

  • RelWithDebInfo build with Ninja: clean. ctest: 17/17, including run_tiny_game (gta6rt --run tiny_game.exe -- hello 42) and run_tiny_game_exit_code (the wrong args run, WILL_FAIL).

AI-assisted (Claude Code).

@kotorvr

kotorvr commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Tested d1b75ca on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass

  • Clean RelWithDebInfo Ninja build of runtime/ (Vulkan SDK 1.4.363.0), then ctest --test-dir runtime/build --output-on-failure: 17/17 passed.
  • GPU tests with LEONIDA_VK_VALIDATION=1 and VK_LAYER_KHRONOS_validation: d3d12_com_test, d3d12_descriptor_test, d3d12_vulkan_device_test, vk_command_replay_test all exit 0, with 0 validation messages.

run_tiny_game and run_tiny_game_exit_code pass with an MSVC build.

No game files used. AI-assisted run (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit 537176f into ItsNotRexed:main Nov 21, 2026
7 checks passed
ItsNotRexed added a commit that referenced this pull request Nov 21, 2026
…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>
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