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
Contributor

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

5 participants