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

Open
github-bot wants to merge 1 commit from github-bot/gh-1464 into main AGit
Owner

@⁠piyonchu on GitHub · 2026-11-25 00:45 UTC · original
piyonchu:pr/fs-crt-stat-remove → main · +235 −0 · 2 files · 1 commits · open

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

**@⁠piyonchu** on GitHub · 2026-11-25 00:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1464) `piyonchu:pr/fs-crt-stat-remove` → `main` · +235 −0 · 2 files · 1 commits · open 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).*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:52:23 +00:00
Author
Owner

@⁠Gefik23 on GitHub · 2026-11-25 07:04 UTC · original

Tested 8b658972a 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.

**@⁠Gefik23** on GitHub · 2026-11-25 07:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1464#issuecomment-7155455340) Tested 8b658972a 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.
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 07:24 UTC · original

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.

**@⁠whoalin1** on GitHub · 2026-11-25 07:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1464#issuecomment-7155819170) 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.
Author
Owner

@⁠piyonchu on GitHub · 2026-11-26 02:47 UTC · original

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)
**@⁠piyonchu** on GitHub · 2026-11-26 02:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1464#issuecomment-7181125855) 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)
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1464/head:github-bot/gh-1464'
git switch 'github-bot/gh-1464'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1464'
git switch 'github-bot/gh-1464'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1464'
git switch 'github-bot/gh-1464'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1464'
git switch 'main'
git merge --squash 'github-bot/gh-1464'
git switch 'main'
git merge --ff-only 'github-bot/gh-1464'
git switch 'main'
git merge 'github-bot/gh-1464'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.