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

Open
opened 2026-11-26 20:21:26 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1464
Author: @piyonchu
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: pr/fs-crt-stat-remove


📝 Commits (1)

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

📊 Changes

2 files changed (+235 additions, -0 deletions)

View changed files

📝 runtime/shims/file_system.cpp (+144 -0)
📝 runtime/test/file_system_test.cpp (+91 -0)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1464 **Author:** [@piyonchu](https://github.com/piyonchu) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/fs-crt-stat-remove` --- ### 📝 Commits (1) - [`fc6fb0b`](https://github.com/ubiquitarianism/leonida/commit/fc6fb0bd030d3cc4c1cd9f22529e84bee9eb8b41) file_system: shim CRT _stat* and remove/_unlink for console paths (RT-FS-CRT-STAT-REMOVE) ### 📊 Changes **2 files changed** (+235 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/file_system.cpp` (+144 -0) 📝 `runtime/test/file_system_test.cpp` (+91 -0) </details> ### 📄 Description 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).* --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1494
No description provided.