Skip to content

file_system: shim CRT _stat* and remove/_unlink for console paths (RT-FS-CRT-STAT-REMOVE) - #1464

Open
piyonchu wants to merge 1 commit into
ProjectLeonida:mainfrom
piyonchu:pr/fs-crt-stat-remove
Open

piyonchu wants to merge 1 commit into
ProjectLeonida:mainfrom
piyonchu:pr/fs-crt-stat-remove

Conversation

@piyonchu

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-FS-CRT-STAT-REMOVE

Summary

  • Measures from game_scarlett_master.exe show direct imports and call sites for api-ms-win-crt-filesystem-l1-1-0.dll!_wstat64 and api-ms-win-crt-filesystem-l1-1-0.dll!remove. Because the host UCRT calls Win32 file APIs through its own import table rather than the guest's IAT, console paths (GAME:, G:, T:), overlay copies, and deletion markers were bypassed by CRT stat/remove calls.
  • Implement shims in runtime/shims/file_system.cpp for remove, _wremove, _unlink, _wunlink, _wstat64, _stat64, _wstat64i32, _stat64i32, _wstat32, _stat32, _wstat32i64, and _stat32i64 registered under api-ms-win-crt-filesystem-l1-1-0.dll and ucrtbase.dll.
  • Console-path stat queries resolve overlay vs. package visibility and delete markers via view() / missing_error() and delegate disk resolution to host UCRT _wstat* (preserving long \\?\ paths and UCRT mode/size/time fields); CRT deletes delegate console paths to delete_file_w() and map Win32 failures (ERROR_FILE_NOT_FOUND/ERROR_PATH_NOT_FOUND/ERROR_INVALID_NAME -> ENOENT, ERROR_ACCESS_DENIED -> EACCES, etc.) to errno and _doserrno.
  • Extend runtime/test/file_system_test.cpp with check_crt_stat_remove covering GAME:, G:, T:, overlay shadowing, delete-marker preservation of package files, EACCES on read-only package files and directories, ENOENT on escaped .. paths, and host passthrough.

Verification

  • Built with MSVC (RelWithDebInfo, Windows 11, CPU-only build without Vulkan headers) and ran ctest -C RelWithDebInfo -R "^(file_system|xgameruntime)$" --output-on-failure: 2/2 passed (file_system, xgameruntime).
  • Verified gta6rt.exe --dry-run against a local game_scarlett_master.exe confirms both api-ms-win-crt-filesystem-l1-1-0.dll!_wstat64 and api-ms-win-crt-filesystem-l1-1-0.dll!remove now bind to shim.
  • python -I tests/test_build_runtime_fallback.py and python -I tests/test_text_write_line_endings.py (run below before commit).
  • git diff --check: clean.

AI-assisted; synthetic tests + --dry-run import check on Windows 11 (CPU-only build; no game files included).

@Gefik23

Gefik23 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Tested 8b65897 on NVIDIA GeForce RTX 4060, driver 617.42, AMD Ryzen 5 7500F, Windows 11 Pro build 26200, native Windows: pass.

Built at this head with scripts\build_runtime.ps1 (MSVC 19.44, VS 2022 Build Tools, Ninja, RelWithDebInfo, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0).

  • ctest -R file_system -V: passed.
  • Full ctest -C RelWithDebInfo: 350/350 passed (game-data tests skipped, LEONIDA_GAME_DIR unset).

AI-assisted (Claude Code ran the build and tests). No game files.

@whoalin1

Copy link
Copy Markdown
Contributor

Independent verification (CPU-only change, no GPU needed): built file_system_test + unimplemented_policy_test on native Windows (MSVC 2022, Ninja, RelWithDebInfo) and ran ctest -R file_system — 1/1 pass including the new check_crt_stat_remove (console-path stat, overlay shadowing, delete markers, errno mapping, host passthrough). Diff review agrees with the PR's claims: console paths route through the existing parse_console/view/missing_error/delete_file_w helpers and Win32 errors map correctly. AI-assisted verification.

@piyonchu
piyonchu force-pushed the pr/fs-crt-stat-remove branch from 8b65897 to fc6fb0b Compare November 26, 2026 02:47
@piyonchu

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main (86dc3d86e, head commit fc6fb0bd0) and updated the T: test setup in runtime/test/file_system_test.cpp to write to own_t_folder(layer) (matching per-process scratch_dir()).

Verified locally after rebase:

  • python -I scripts/check_no_game_data.py runtime/shims/file_system.cpp runtime/test/file_system_test.cpp
  • cmake --build runtime/build --config RelWithDebInfo --target gta6rt file_system_test
  • ctest --test-dir runtime/build -C RelWithDebInfo -R "^file_system$" --output-on-failure (1/1 passed)

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 28, 2026
@MoonEyes

Copy link
Copy Markdown
Collaborator

Hi @piyonchu, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/shims/file_system.cpp), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

@OreoFR

OreoFR commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Verified by OreoFR

  • Base: main c1ecf04ed + PR head fc6fb0bd0
  • Test: not run (merge conflict with main)
  • Red on main: not run
  • Green with the PR: not run
  • Verdict: CONFLICT (runtime/shims/file_system.cpp conflicts with main)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

@piyonchu
piyonchu force-pushed the pr/fs-crt-stat-remove branch from fc6fb0b to 596c49f Compare November 29, 2026 01:21
@piyonchu

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main (16f505304, head commit 596c49f37), keeping both the upstream get_disk_free_space_* shims and the crt_* stat/remove shims cleanly separated in runtime/shims/file_system.cpp.

Verified locally after rebase:

  • git diff --check cont/main..HEAD
  • python -I scripts/check_no_game_data.py runtime/shims/file_system.cpp runtime/test/file_system_test.cpp
  • cmake --build runtime/build --config RelWithDebInfo --target gta6rt file_system_test
  • ctest --test-dir runtime/build -C RelWithDebInfo -R "^file_system$" --output-on-failure (1/1 passed)

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 29, 2026
@zmasi

zmasi commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Windows 11 + NTFS Verification (596c49f37c merged with origin/main 02944d4ca1)

  • Environment: Windows 11 (10.0.26200) NTFS, MSVC 19.44.35228 (Release, /W4 /permissive- /utf-8), clean merge onto origin/main (0 conflicts).
  • Red -> Green:
    • Red (origin/main runtime/shims/file_system.cpp + PR runtime/test/file_system_test.cpp): file_system_test failed (rc=1, 545 check(s), 1 failure(s) — api-ms-win-crt-filesystem-l1-1-0.dll and ucrtbase.dll did not expose _wstat64, _stat64, _wstat64i32, _stat64i32, remove, _wremove, _unlink, _wunlink).
    • Green (origin/main + #1464): file_system_test passed 559 check(s), 0 failure(s) (rc=0, 22.24s), verifying:
      • _wstat64 / _stat64i32 / _stat64 across GAME:, G:, and T: scratch roots (regular files, directories, and overlay copy-up size shadowing).
      • remove / _wremove / _unlink / _wunlink scratch deletion (T:), package delete-marker creation leaving package files untouched (ENOENT on subsequent _wstat64), FILE_ATTRIBUTE_READONLY package file refusal (EACCES), directory _wunlink refusal (EACCES), GAME:/../outside.txt traversal refusal (ENOENT), and native host path passthrough.

AI-assisted.

@TheGeogeo

Copy link
Copy Markdown
Contributor

Ready for testing: merges cleanly with main 3535eb5c4. Not in main yet: git cherry finds 1 commit(s) not there, and 10 of the 143 lines it adds are already present. No duplicate found: its claim RT-FS-CRT-STAT-REMOVE appears in no other open pull request and in no main commit.

AI-assisted (Claude Code).

@enlight3d

Copy link
Copy Markdown
Contributor

RUN report for #1464 (RT-FS-CRT-STAT-REMOVE)

Heads: PR head 596c49f37 (base 16f505304); origin/main c22a0a732, merged locally with git merge --no-ff (clean, 2 files).

Kind: runtime C++ (runtime/shims/file_system.cpp, runtime/test/file_system_test.cpp).

Commands (VS 2022 vcvars64 shell, Ninja, RelWithDebInfo, -DLEONIDA_REQUIRE_VULKAN=ON, SDL3 via SDL3_DIR):

  • cmake -S runtime -B <build> -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON
  • cmake --build <build> -j 8 --target file_system_test (merged tree and plain main: --target gta6rt file_system_test)
  • ctest --test-dir <build> -R "^file_system$" --output-on-failure
  • python -I -B tests/<file> for test_build_runtime_fallback.py, test_text_write_line_endings.py, test_ctest_registration.py

Results:

  • RED (behavioural: runtime/shims/file_system.cpp reverted to the PR base, test file kept; it builds because the test resolves the shims by name): file_system fails with FAIL api-ms-win-crt-filesystem-l1-1-0 and ucrtbase serve CRT stat and remove/unlink (the shims are not registered, so the rest of check_crt_stat_remove is skipped).
  • GREEN at PR head: file_system passes (1/1). test_text_write_line_endings.py 3 OK, test_ctest_registration.py 7 OK.
  • GREEN merged into origin/main: file_system passes (1/1). test_build_runtime_fallback.py 11 OK, test_text_write_line_endings.py 3 OK, test_ctest_registration.py 11 OK.
  • Pre-existing, not caused by the PR: at the PR head test_build_runtime_fallback.py fails test_the_loader_gets_the_stack_reserve_cmake_gives_it (1 of 11). It fails the same way on the PR's own base 16f505304 and passes on current main and in the merge, so the branch is just behind main.
  • gta6rt imports (dumpbin /imports, DLL!symbol, merged vs plain main c22a0a732): 714 on main, 726 merged; 12 new, none removed:
    • api-ms-win-crt-filesystem-l1-1-0.dll! _stat32, _stat32i64, _stat64, _stat64i32, _wremove, _wstat32, _wstat32i64, _wstat64, _wstat64i32, remove
    • api-ms-win-crt-runtime-l1-1-0.dll! _set_doserrno, _set_errno
      All are UCRT apiset imports of the host CRT; no new DLL.
  • Not checked: the xgameruntime CTest named in the description, and the --dry-run binding check against the game executable (needs the game; not run here).

Machine: Windows 11 Pro x64, RTX 3090 24 GB (has VK_EXT_mesh_shader), NVIDIA 621.40, MSVC 14.44 (VS 2022 Build Tools), CMake/Ninja from VS, Vulkan SDK 1.4.363.1, SDL3 3.4.20 static, Python 3.13.12.

@fiestorra

Copy link
Copy Markdown
Contributor

Independent verification on this machine (Windows 11, MSVC 19.44.35226), with a negative control that bites.

1. It applies and builds. merge-tree clean onto main d367675c7; runtime/shims/file_system.cpp plus its test.

2. With the branch: ctest -R 'file_system' -> 100% tests passed, 0 tests failed out of 1.

3. The control - revert only the shim, keep the test:

git checkout origin/main -- runtime/shims/file_system.cpp
cmake --build … --target file_system_test
ctest -R 'file_system' --output-on-failure
0% tests passed, 1 tests failed out of 1
FAIL api-ms-win-crt-filesystem-l1-1-0 and ucrtbase serve CRT stat and remove/unlink

The assertion names the change: the CRT's stat and remove/unlink, resolved through api-ms-win-crt-filesystem-l1-1-0 and ucrtbase, must be served by the shim rather than the host's runtime - so a title that stats a GAME: path gets the emulated file, not a host ENOENT.

The note that now applies to four pull requests: #977, #1234, #1464 and #2375 all modify runtime/shims/file_system.cpp, each with a control that bites, each on a different entry point (GetDriveTypeW/A, CRT stat/remove, the file-system API, MoveFile*). Four branches, one shim: three rebases whichever lands first, and none supersedes another.

What I did not test: the rest of the CRT file surface, and whether the shim's stat fills st_size/st_mode the way a title expects.

Why I am commenting: I verify open pull requests that replay onto current main, build the binaries their tests name, run them, then revert only the source change. 31 controls so far: 24 bite.

Written with an AI assistant.

@piyonchu
piyonchu force-pushed the pr/fs-crt-stat-remove branch from 596c49f to 2244e3d Compare November 30, 2026 19:06
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.

9 participants