Skip to content

BUILD-2127: Honor legacy CRT wildcard flags and match ordering - #6463

Open
Hiiva wants to merge 2 commits into
ItsNotRexed:mainfrom
Hiiva:fix/legacy-argv-wildcards
Open

Hiiva wants to merge 2 commits into
ItsNotRexed:mainfrom
Hiiva:fix/legacy-argv-wildcards

Conversation

@Hiiva

@Hiiva Hiiva commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Problem

The legacy msvcrt.dll!__getmainargs and __wgetmainargs shims ignored doWildCard, leaving patterns literal even when callers requested expansion. Microsoft documents the fourth argument as the expansion switch: __getmainargs / __wgetmainargs.

An original MSVC fixture with both functions in its actual msvcrt.dll import table reproduces the problem in native versus mapped execution. The native oracle also establishes that legacy expansion sorts each pattern's matches case-insensitively after conversion to the requested character width. That differs from the enumeration order retained by UCRT startup.

Changes

  • Honor the legacy expansion flag using the guest-owned argument configuration added by BUILD-1961: Honor mapped executable argument startup modes #6117.
  • Enable sorting only for legacy calls, within each original pattern's result range. Literal arguments and separate wildcard groups retain their positions.
  • Preserve zero-flag behavior, unmatched patterns, environment lookup, independent narrow/wide storage, and the existing UCRT startup path.
  • Add an import-library-only fixture, native/mapped comparisons, and registered-shim program-token controls. No replacement CRT DLL is built.

Coordination: BUILD-2127, original claim, carried to current coordinator #6414.

Depends on: #6117

This is a stacked follow-up on exact #6117 head a906994c9f0b9672b6647e571fa0a573fe171dae. Its published branch is unchanged. The follow-up delta is seven files above that commit.

Validation

Windows 11 x64, MSVC 19.44.35228, Windows SDK 10.0.26100.0, RelWithDebInfo, ACP 1252. CPU only; no GPU, driver exercise, or game inputs.

The same final fixture and runner were used before and after the fix:

  • Parent production: 16 of 20 mapped cases differ from their native controls. Zero-flag and unmatched-pattern controls agree. All child processes complete normally.
  • Fixed production: all 20 native/mapped pairs agree in their complete argument tables, including argv[0]. Output is never reordered by the test.
  • Four additional native program-token controls pass. Both registered-shim program-token failures on parent production pass after the fix.
  • Coverage includes both widths and flag values, quoted patterns, unmatched patterns, relative path prefixes, ACP-dependent patterns/results, both reconfiguration orders, mixed-case and punctuation ordering, and two wildcard groups separated by a literal.
  • process_cmdline, run_argv_modes, run_startup_cmdline, and the new run_legacy_argv CTests pass. Python syntax, the three text-line-ending checks, and git diff --check pass.
  • The fixture, seeded input bytes, and synthetic package are preserved.

Build the focused targets and run:

cmake -S runtime -B runtime/build -G "Visual Studio 17 2022" -A x64 -DCMAKE_SYSTEM_VERSION=10.0.26100.0 -DLEONIDA_SDL3_FETCH=OFF
cmake --build runtime/build --config RelWithDebInfo --target gta6rt process_cmdline_test tiny_legacy_argv tiny_startup_cmdline tiny_argv_default_a tiny_argv_default_w tiny_argv_expand_a tiny_argv_expand_w tiny_argv_noargs_a tiny_argv_noargs_w --parallel 4
ctest --test-dir runtime/build -C RelWithDebInfo -R "^(process_cmdline|run_argv_modes|run_startup_cmdline|run_legacy_argv)$" --output-on-failure

Integration and scope

Exact current-main snapshot f6c6d11eee62b614eafc2a8ae75ffbf3e0f4f9fd accepts #6117 and this follow-up through clean three-way application, with no manual resolutions. This is a source-only integration check; the executed results above are on the exact parent stack. The main snapshot's newer CMake stack/queue settings and unrelated runtime changes are retained. A final fetch at main 4beffda88aa4fc0c266623b311272078e0ad4079 found no subsequent changes to any of the seven affected paths.

This does not add console-path wildcard routing, change the loader's program-token policy, or alter host CRT argument globals. Native expectations are obtained from the active code page; only ACP 1252 was exercised here.

AI-assisted: yes. Independent read-only peer review and root review of the source, fixture, native oracle, and final sorting delta found no actionable issue. Root also verified all 28 frozen source, binary, and evidence hashes.

@thehollowedone

Copy link
Copy Markdown

Independent Windows check of 2aea6a78, stacked on #6117 at a906994c. Windows 11 x64 build 26300, MSVC 19.38.33145, Windows SDK 10.0.26100, ANSI code page 1252, RelWithDebInfo.

All four stock CTests passed. run_legacy_argv matched all 20 native and mapped argument tables and passed the four native program-token controls. run_argv_modes matched all 26 UCRT native and mapped pairs. process_cmdline and run_startup_cmdline also passed. The built guest imported both legacy argument functions from msvcrt.dll. Synthetic inputs only. AI-assisted.

@wasonidas

Copy link
Copy Markdown

Independent integration check for 2aea6a78c8fbfae01ed2e4cc822e57b9bc3de04e, stacked on #6117 at a906994c9f0b9672b6647e571fa0a573fe171dae.

Both commits applied cleanly to main 1cc6e3c121969761d9dad8fdec99f19928213973 (tested tree 332014a2cd51b135204fe7de1ff9ff9e9965117f). I built again from that integrated tree. On both the exact PR head and the integration build, process_cmdline, run_argv_modes, run_startup_cmdline, and run_legacy_argv passed. That covers 20 legacy and 26 UCRT native/mapped pairs per build, plus four native program-token controls. No actionable findings in the follow-up delta.

Windows 11 build 26300, MSVC 19.44.35230, Windows SDK 10.0.26100.0, x64 RelWithDebInfo, ACP 1252. Synthetic CPU fixtures only. Other code pages were untested.

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.

3 participants