Skip to content

Runtime: expose the mapped title's full path through CRT program-path imports - #2861

Open
s0las16 wants to merge 5 commits into
ItsNotRexed:mainfrom
s0las16:devin/1795375000-crt-pgmptr
Open

s0las16 wants to merge 5 commits into
ItsNotRexed:mainfrom
s0las16:devin/1795375000-crt-pgmptr

Conversation

@s0las16

@s0las16 s0las16 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

claiming: runtime/shims/process.cpp:233-265 on upstream/main registered argv and command-line shims but none of _get_pgmptr, _get_wpgmptr, __p__pgmptr, or __p__wpgmptr. The loader's host fallback (runtime/src/pe_loader.cpp:1026-1033) therefore bound CRT program-path queries to gta6rt's own CRT state instead of the mapped title. Add stable title-path getters, accessors and data bindings. Coordination issue: #2716; no comment posted. No matching claim/fix found in the preceding read-only overlap investigation.

Claimed in the coordination issue as: new item (claim above; no comment posted to #2716). The item ID can be added by the coordinator.

What and why

Provide _get_pgmptr, _get_wpgmptr, __p__pgmptr, __p__wpgmptr, _pgmptr and _wpgmptr under the same UCRT DLL names used by the argv shims and under msvcrt.dll. The import binder writes untyped registry addresses into the IAT, so it can serve the data exports too: their entries point at the shared pointer slots, not function thunks.

Upstream/main does not yet contain #2075's mapped-image filename identity, so main captures the absolute image path before initialization can change the working directory, and passes it alongside the existing filename-based command line. argv and GetCommandLine behavior stays unchanged. Store narrow (ANSI code page) and wide path strings in an immortal deque so even previously returned strings survive another setup call and process teardown. Before setup, queries return an empty string; the getter forms reject a null output pointer with EINVAL and set errno. Accessors/data bindings share the same pointer slots.

Add a synthetic dynamic-CRT (/MD, /MDd in Debug) tiny_pgmptr fixture, located in fixtures/game rather than beside gta6rt. The CMake subprocess checker passes its expected full path as a game argument and requires both the fixture PASS marker and game exit code zero. The fixture compares narrow/wide getters and pointer accessors against the expected path, normalizing the test argument through Win32 for native/Wine path spelling. Extend process_cmdline_test with all registered DLL aliases, empty initial state, invalid output pointers, getter/accessor/data consistency, and retained-string lifetime checks. No game files are used.

Overlap: #2075 supplies Win32 mapped-module identity rather than CRT program-path getters; #2750 routes dynamic host lookups through already registered shims rather than providing these exports; RT-107 concerns filesystem/overlay operations. This change does not depend on those PRs. #2661 will need to retain the added image-path argument when its command-line setup move is combined with this change.

Tested

Not compiled locally: Linux without MSVC, with cmake/ctest unavailable. Configure and targeted process_cmdline/run_tiny_pgmptr attempts reported cmake: command not found and ctest: command not found. Relies on the Windows runtime.yml workflow; compilation and runtime execution remain unverified locally. No workflow dispatched as part of this change. CPU-only, no GPU or driver involved. AI-assisted (Devin).

git diff --check completed without output before review; after final edits, git diff --cached --check also completed without output. Manually reviewed the final changes, Windows signatures, includes, heap-storage lifetime, data-export indirection and fixture linkage.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md (n/a: no translator change).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@tupacfan04

Copy link
Copy Markdown
Contributor

Code read of 27f16813 (I didn't build it). The shims look right:

  • _pgmptr/_wpgmptr map to the addresses of g_program/g_wprogram, which is what a data import's IAT slot must hold.
  • __p__pgmptr and the _get_* forms return the same storage, with EINVAL for null.
  • The immortal deque keeps every earlier path valid across later set_command_line calls, because push_back doesn't move existing elements.

Merge note: this changes set_command_line's call at its old place in main.cpp, after loader.initialise(). #2661 moves that call before initialise(), so TLS callbacks and DllMain see the command line. Whichever lands second needs to carry image_path to the new position. Otherwise the program path would again be empty during DLL initialisation, which is exactly when CRT startup code tends to read _pgmptr.

AI-assisted review (Claude Code).

@2-CD

2-CD commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Windows + GPU check: RTX 5080 (NVIDIA 621.01) and AMD Radeon Graphics (Ryzen 9 9950X3D iGPU, driver 32.0.13018.6), Windows 11, MSVC RelWithDebInfo/Ninja, CMake 4.4.5, glslang 16.6.0, spirv-tools v2026.4, llvm-mc via scripts/build_llvm_mc.ps1. Tested head 27f1681.

  • Clean build, 0 errors.
  • The two new tests process_cmdline and run_tiny_pgmptr: pass 5/5 (--repeat until-fail:5) on both GPUs.
  • Full ctest -C RelWithDebInfo -j 6 --output-on-failure: 118/118 on the RTX 5080 and 118/118 on the iGPU (the four window-showing present/swapchain tests excluded from the loops).
  • The PR's unstable CI state did not reproduce locally; both runs green.

Synthetic fixtures only, no game files. AI-assisted (opencode); runs on my machine.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 27f1681 merged onto main 77444fa on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:

  • Full ctest: 131/131.
  • process_cmdline: passes 20 of 20 runs, and passes under LEONIDA_VK_VALIDATION=1 with 0 validation messages.
  • One new MSVC warning: C4996 at runtime/test/fixtures/tiny_pgmptr.cpp:28 ('__p__pgmptr': ... Consider using _get_pgmptr instead). The fixture calls __p__pgmptr() on purpose, to compare it with _get_pgmptr, so a #pragma warning(suppress: 4996) on that line would keep the build quiet.

AI-assisted (Claude Code).

@FaKL-Code

Copy link
Copy Markdown
Contributor

Tested 27f1681 (merged onto main 77444fa) on NVIDIA GeForce RTX 4060 Ti, driver 610.88 (32.0.16.1088), Windows 11 26200, MSVC 14.51.36231 (VS 2026), Vulkan SDK 1.4.363.0: pass

  • Clean merge; RelWithDebInfo build.
  • ctest -j 4 (all but loader): 121/121 pass. That is main's 120 plus the new run_tiny_pgmptr, which passes through gta6rt, with the same 8 skips as main. process_cmdline passes too.
  • loader run on its own: pass.
  • With LEONIDA_VK_VALIDATION=1, every d3d12_* and dxgi_* test plus command_list and xbox_present (48 tests): no validation errors, the same as main.
  • One new warning, a nit:
    • runtime/test/fixtures/tiny_pgmptr.cpp(28,10): warning C4996: '__p__pgmptr': ... Consider using _get_pgmptr instead.
    • The call is deliberate, since __p__pgmptr is one of the imports under test. _CRT_SECURE_NO_WARNINGS in tiny_pgmptr's target_compile_definitions would keep the build log clean.

AI-assisted (Claude).

s0las16 and others added 2 commits November 22, 2026 20:17
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
seblessa added a commit to seblessa/Leonida that referenced this pull request Nov 22, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
seblessa added a commit to seblessa/Leonida that referenced this pull request Nov 22, 2026
Conflicts with upstream's API-set ExitProcess/GetCommandLine entries, the tiny_game_fixed fixture and the program-path set_command_line (ItsNotRexed#2861/ItsNotRexed#2661): kept both sides; the RT-119 CreateThread/_beginthread entries sit beside the EXIT_PROCESS/COMMAND_LINE macros, and main.cpp sets the stack reserve and the command line before initialise().

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

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head merged with main f847748, MSVC 14.51):

  • RTX 4080 SUPER: process_cmdline and run_tiny_pgmptr pass.
  • Intel UHD 770 (VK_LOADER_DRIVERS_DISABLE=*nv*): both pass.
  • Negative control: with process.cpp, process_shim.h and main.cpp reverted to main, process_cmdline_test no longer compiles (set_command_line does not take 3 arguments), and run_tiny_pgmptr fails on both GPUs.

Only these two tests were built and run, not the full ctest. No concerns.

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Windows + GPU check: AMD Radeon RX 9070 (RDNA4), Windows 11, MSVC Release, Vulkan SDK 1.4.363. Tested head 40a2157 merged onto main f847748 (clean merge), full build, full ctest -C Release -j 4: 100% tests passed out of 133 | new failures vs main: none. The main baseline on the same machine passes 132/132.

AI-assisted (Claude Code); runs on my machine.

@tupacfan04

Copy link
Copy Markdown
Contributor

Approved by static review (no MSVC here): merge clean, Python compileall and the ctest/CI/docs tests pass.

The path handling is right: the full path is captured before init (runtime/src/main.cpp:97), the wide path is exact, the narrow one uses CP_ACP like the UCRT (runtime/shims/process.cpp:73-77), the strings are NUL-terminated and held in an immortal deque (:208-212), and the data exports point at &g_program/&g_wprogram (:266-269). The fixture only prints PASS (tiny_pgmptr.cpp:24-30), so no repo writes.

Two non-blocking notes:

  • There is no end-to-end test that a mapped title's _pgmptr data import binds through the IAT; process_cmdline_test.cpp:33 queries the registry directly.
  • The pre-existing narrow() writes n bytes into a size-n-1 string (process.cpp:75-76).

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

@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested 40a2157 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) — 26 of 26 passed. AI-assisted.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@Kam471 Kam471 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.

Built and ran at 56c5afe4b on Windows 11 (MSVC, RelWithDebInfo):

  • ctest -R 'pgmptr|process_cmdline' -> 2/2 passed: process_cmdline and run_tiny_pgmptr.
  • Direct process_cmdline_test -> exit 0 (GetCommandLineW parses back to __wargv, non-ASCII arguments intact).
  • git diff --check clean.

The shim now sets _pgmptr/_wpgmptr from the loaded image's own program path instead of the host loader's, so a mapped title's argv[0]/CRT program path names the title and not gta6rt.exe; the new run_tiny_pgmptr fixture checks it through gta6rt --run. No blocking issue.

seblessa added a commit to seblessa/Leonida that referenced this pull request Nov 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
seblessa added a commit to seblessa/Leonida that referenced this pull request Nov 23, 2026
Conflicts with ItsNotRexed#2861 (CRT program-path imports) in runtime/src/main.cpp and runtime/shims/process.cpp: kept both. main.cpp keeps main's mod hooks and ItsNotRexed#2861's set_command_line(..., image_path), then calls ItsNotRexed#1895's set_thread_stack; process.cpp takes the union of the includes and puts set_thread_stack before ItsNotRexed#2861's set_command_line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
seblessa added a commit to seblessa/Leonida that referenced this pull request Nov 23, 2026
…est_docs_cli_flags

FORK.md: boot-prep is upstream main 3faac55 + ItsNotRexed#2861, ItsNotRexed#1895, fork/first-boot and
gdk-offline-classes (ItsNotRexed#3476, after its merge of main). ItsNotRexed#2218, ItsNotRexed#2784, ItsNotRexed#2594, ItsNotRexed#2839,
ItsNotRexed#2954, ItsNotRexed#2957, ItsNotRexed#2750, ItsNotRexed#2833 and our ItsNotRexed#3455 are upstream now; fork/first-boot and
gdk-runtime-calls are gone, so the fork-only files are carried as a patch when
boot-prep is rebuilt. gta6rt now seeds its VkPipelineCache from the
pipeline_cache.bin beside it when the header matches the device.

tests/test_docs_cli_flags.py failed on boot-prep only: FORK.md, merged from
fork/first-boot, quotes git commands, and the test wants every --flag in a
Markdown page to appear in a source file. git's flags join FOREIGN, next to gh's
and pip's (fork-only line).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@devnull34 devnull34 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified at head 2741cef on Windows 11 Pro 24H2, MSVC 19.44 (Visual Studio 2022) with AMD Radeon RX 7900 GRE:

  • Build: Built gta6rt, process_cmdline_test, and fixture iny_pgmptr with 0 errors/warnings.
  • Runtime CTest:
    • process_cmdline: 5/5 passed (--repeat until-fail:5). Direct execution confirms GetCommandLineW roundtrips to __wargv, non-ASCII arguments intact (code page 1252).

un_tiny_pgmptr: 5/5 passed (--repeat until-fail:5). Confirms gta6rt --run exposes the mapped guest executable's full directory/image path through _pgmptr/_wpgmptr and get* APIs rather than the host loader's path.

  • Clean Diff: git diff --check 56c5afe..HEAD clean, no trailing whitespace or merge artifacts.

No game files used.

AI-assisted verification.

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.

10 participants