[PR #1363] [CLOSED] runtime: trace successful file opens (RT-TRACE-SUCCESSFUL-OPENS) #1393

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1363
Author: @Moriz82
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: split/rt-trace-successful-opens


📝 Commits (1)

  • 75731cf runtime: trace successful file opens (RT-TRACE-SUCCESSFUL-OPENS)

📊 Changes

5 files changed (+91 additions, -21 deletions)

View changed files

📝 docs/boot.md (+3 -1)
📝 runtime/CMakeLists.txt (+1 -0)
📝 runtime/README.md (+1 -0)
📝 runtime/shims/file_system.cpp (+23 -17)
📝 runtime/test/file_system_test.cpp (+63 -3)

📄 Description

Claimed in the coordination issue as: RT-TRACE-SUCCESSFUL-OPENS (claim).

Part of the split of #984 into small pull requests.

Depends on: none
Overlaps: #984 (integration source; there the success events were written without restoring the last error, here it is restored and tested). #41 (caller of a call through a null pointer), #638 (LEONIDA_SKIP_INT3 on title threads) and #994 (unhandled-exception log) add other startup-trace events. None records a successful open.

What and why

gta6rt --trace FILE writes a file_open_failed event for a guest file open that fails. A run that stops making progress without a failed open leaves nothing in the trace about the files it had reached.

With the trace on, a guest CreateFileW or CreateFile2 that succeeds now writes a file_open event with the path the title passed, the requested access mask and the caller. CreateFileA goes through CreateFileW and is recorded as that.

  • The first 600 successful opens are recorded. Their budget is separate from the 256 failures, so neither kind of event can use up the other's.
  • OPEN_ALWAYS and CREATE_ALWAYS report ERROR_ALREADY_EXISTS through the last error of a successful open. Writing the event changes the last error, so it is read before the event and put back after it.
  • With the trace off the new function returns at its first line: no event, no change of the last error.

No new switch or environment variable: the events are written only when --trace is on. docs/boot.md and the event table in runtime/README.md name the new event and both budgets.

Tested

Cross-built on CachyOS Linux 7.3.5 with clang-cl 23.1.5 and the xwin SDK. Ran the Windows tests one at a time under Wine 11.22 (distribution package, a prefix of its own) on a Ryzen 5 5600X with 16 GB RAM.

cmake --build runtime/build/boot --target file_system_test gta6rt dstorage_test xgameruntime_test xgameruntime_user_test xgameruntime_gamesave_test xgameruntime_store_test xgameruntime_offline_test -j6
export WINEDEBUG=-all WINEDLLOVERRIDES="winedbg.exe=d;mscoree=d;mshtml=d"
timeout 240 wine file_system_test.exe
timeout 240 wine file_system_test.exe --trace-opens
timeout 240 wine dstorage_test.exe
timeout 240 wine xgameruntime_test.exe
timeout 240 wine xgameruntime_user_test.exe
LEONIDA_GAMERTAG=Tester42 timeout 240 wine xgameruntime_user_test.exe --expect-gamertag Tester42
LEONIDA_GAMERTAG=GGGG...(70 characters) timeout 240 wine xgameruntime_user_test.exe --expect-gamertag Player
timeout 240 wine xgameruntime_gamesave_test.exe
timeout 240 wine xgameruntime_store_test.exe
timeout 240 wine xgameruntime_offline_test.exe
LEONIDA_HDR=1 timeout 240 wine xgameruntime_offline_test.exe
python3 -I scripts/check_no_game_data.py
python3 -I tests/test_docs_env_vars.py
python3 -I tests/test_ctest_registration.py
git diff --check

file_system_test --trace-opens is the new form (CTest name file_system_open_trace); it has a process of its own because the budgets are per process. Over temporary folders it opens a file before the trace is opened, then with the trace on opens one existing file through CreateFile2 with OPEN_ALWAYS, the same file 601 times through CreateFileW, and one missing file, and reads the trace back.

Form Base implementation with this test This change
file_system_test --trace-opens Exit 1, 3 of 9 checks failed: no CreateFile2 success event, no CreateFileW success events, not 600 events with path, access and caller. Exit 0, 9 of 9 checks in 4 runs: 1 CreateFile2 event, 599 CreateFileW events, 600 in all with GAME:\existing.txt, the access mask and a caller; all 601 further opens still succeed; 1 file_open_failed event; the file opened before the trace is not in it; OPEN_ALWAYS leaves ERROR_ALREADY_EXISTS.
file_system_test (trace off) Exit 1, 8 of 494 checks failed, with the base implementation and with both files as on 6293c1c4f. Exit 1, the same 8 of 494 checks failed in 4 runs.

"Base implementation" is this branch with runtime/shims/file_system.cpp as it is on 6293c1c4f.

The 8 checks that fail in the plain form with and without the change are Wine differences: a host ReadFile into uncommitted pages, six MAXIMUM_ALLOWED opens and their overlay writes, and one long-listing wildcard (*.?.). None of them is in code this change touches.

Mutation: with the SetLastError after the event removed, --trace-opens failed 1 of 9 checks, "OPEN_ALWAYS preserves its success last-error". The restore is needed under Wine and the test sees it.

The other test programs that compile file_system.cpp do not open the startup trace, so the new function returns at its first line there:

Other test Result
xgameruntime_test (158 checks), xgameruntime_user_test (42 checks, plain and both LEONIDA_GAMERTAG forms), xgameruntime_gamesave_test (56), xgameruntime_store_test (27), xgameruntime_offline_test (69, plain and LEONIDA_HDR=1) Passed (exit 0).
dstorage_test Stopped by the 240 s timeout, on the base and with this change, after the same 6 failed checks in its read and status cases (one of them: "a destination the process cannot write", E_PENDING instead of the expected error). Its sources are the base's except file_system.cpp.
python3 -I scripts/check_no_game_data.py, tests/test_docs_env_vars.py (4 tests), tests/test_ctest_registration.py (4 tests), git diff --check Passed.
Python loop over the non-semantic test files (compileall, 520 files of tests/, the content guard) One failing file, tests/test_imhex_patterns.py, as on the base. None added.

Not run: native Windows (the 8 plain-form failures and the dstorage_test stop are unverified there), Proton, CTest itself (the executables were started directly), the CREATE_ALWAYS case of the last error (only OPEN_ALWAYS is tested), CreateFileA, the translator's semantic suite (no Python or translator file changed) and a boot of the title.

GPUs tested: none. The fixture uses files and the startup trace only.
AI-assisted: yes (Claude Code).

Checklist

  • One commit based on upstream main 6293c1c4f.
  • One topic: one startup-trace event, its documentation and its test form.
  • No new switch. With the trace off nothing is written and the plain test form gives the same result as the base.
  • Synthetic test over temporary files, no game data. Content guard and whitespace check passed.
  • No translator rule changed.

🤖 Generated with Claude Code


🔄 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/1363 **Author:** [@Moriz82](https://github.com/Moriz82) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `split/rt-trace-successful-opens` --- ### 📝 Commits (1) - [`75731cf`](https://github.com/ubiquitarianism/leonida/commit/75731cfccb53d6f4091ec4e034169de0ddf40381) runtime: trace successful file opens (RT-TRACE-SUCCESSFUL-OPENS) ### 📊 Changes **5 files changed** (+91 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `docs/boot.md` (+3 -1) 📝 `runtime/CMakeLists.txt` (+1 -0) 📝 `runtime/README.md` (+1 -0) 📝 `runtime/shims/file_system.cpp` (+23 -17) 📝 `runtime/test/file_system_test.cpp` (+63 -3) </details> ### 📄 Description Claimed in the coordination issue as: RT-TRACE-SUCCESSFUL-OPENS ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7146367781)). Part of the split of #984 into small pull requests. Depends on: none Overlaps: #984 (integration source; there the success events were written without restoring the last error, here it is restored and tested). #41 (caller of a call through a null pointer), #638 (`LEONIDA_SKIP_INT3` on title threads) and #994 (unhandled-exception log) add other startup-trace events. None records a successful open. ### What and why `gta6rt --trace FILE` writes a `file_open_failed` event for a guest file open that fails. A run that stops making progress without a failed open leaves nothing in the trace about the files it had reached. With the trace on, a guest `CreateFileW` or `CreateFile2` that succeeds now writes a `file_open` event with the path the title passed, the requested access mask and the caller. `CreateFileA` goes through `CreateFileW` and is recorded as that. - The first 600 successful opens are recorded. Their budget is separate from the 256 failures, so neither kind of event can use up the other's. - `OPEN_ALWAYS` and `CREATE_ALWAYS` report `ERROR_ALREADY_EXISTS` through the last error of a successful open. Writing the event changes the last error, so it is read before the event and put back after it. - With the trace off the new function returns at its first line: no event, no change of the last error. No new switch or environment variable: the events are written only when `--trace` is on. `docs/boot.md` and the event table in `runtime/README.md` name the new event and both budgets. ### Tested Cross-built on CachyOS Linux 7.3.5 with clang-cl 23.1.5 and the xwin SDK. Ran the Windows tests one at a time under Wine 11.22 (distribution package, a prefix of its own) on a Ryzen 5 5600X with 16 GB RAM. ```sh cmake --build runtime/build/boot --target file_system_test gta6rt dstorage_test xgameruntime_test xgameruntime_user_test xgameruntime_gamesave_test xgameruntime_store_test xgameruntime_offline_test -j6 export WINEDEBUG=-all WINEDLLOVERRIDES="winedbg.exe=d;mscoree=d;mshtml=d" timeout 240 wine file_system_test.exe timeout 240 wine file_system_test.exe --trace-opens timeout 240 wine dstorage_test.exe timeout 240 wine xgameruntime_test.exe timeout 240 wine xgameruntime_user_test.exe LEONIDA_GAMERTAG=Tester42 timeout 240 wine xgameruntime_user_test.exe --expect-gamertag Tester42 LEONIDA_GAMERTAG=GGGG...(70 characters) timeout 240 wine xgameruntime_user_test.exe --expect-gamertag Player timeout 240 wine xgameruntime_gamesave_test.exe timeout 240 wine xgameruntime_store_test.exe timeout 240 wine xgameruntime_offline_test.exe LEONIDA_HDR=1 timeout 240 wine xgameruntime_offline_test.exe python3 -I scripts/check_no_game_data.py python3 -I tests/test_docs_env_vars.py python3 -I tests/test_ctest_registration.py git diff --check ``` `file_system_test --trace-opens` is the new form (CTest name `file_system_open_trace`); it has a process of its own because the budgets are per process. Over temporary folders it opens a file before the trace is opened, then with the trace on opens one existing file through `CreateFile2` with `OPEN_ALWAYS`, the same file 601 times through `CreateFileW`, and one missing file, and reads the trace back. | Form | Base implementation with this test | This change | |---|---|---| | `file_system_test --trace-opens` | Exit 1, 3 of 9 checks failed: no `CreateFile2` success event, no `CreateFileW` success events, not 600 events with path, access and caller. | Exit 0, 9 of 9 checks in 4 runs: 1 `CreateFile2` event, 599 `CreateFileW` events, 600 in all with `GAME:\existing.txt`, the access mask and a caller; all 601 further opens still succeed; 1 `file_open_failed` event; the file opened before the trace is not in it; `OPEN_ALWAYS` leaves `ERROR_ALREADY_EXISTS`. | | `file_system_test` (trace off) | Exit 1, 8 of 494 checks failed, with the base implementation and with both files as on `6293c1c4f`. | Exit 1, the same 8 of 494 checks failed in 4 runs. | "Base implementation" is this branch with `runtime/shims/file_system.cpp` as it is on `6293c1c4f`. The 8 checks that fail in the plain form with and without the change are Wine differences: a host `ReadFile` into uncommitted pages, six `MAXIMUM_ALLOWED` opens and their overlay writes, and one long-listing wildcard (`*.?.`). None of them is in code this change touches. Mutation: with the `SetLastError` after the event removed, `--trace-opens` failed 1 of 9 checks, "OPEN_ALWAYS preserves its success last-error". The restore is needed under Wine and the test sees it. The other test programs that compile `file_system.cpp` do not open the startup trace, so the new function returns at its first line there: | Other test | Result | |---|---| | `xgameruntime_test` (158 checks), `xgameruntime_user_test` (42 checks, plain and both `LEONIDA_GAMERTAG` forms), `xgameruntime_gamesave_test` (56), `xgameruntime_store_test` (27), `xgameruntime_offline_test` (69, plain and `LEONIDA_HDR=1`) | Passed (exit 0). | | `dstorage_test` | Stopped by the 240 s timeout, on the base and with this change, after the same 6 failed checks in its read and status cases (one of them: "a destination the process cannot write", `E_PENDING` instead of the expected error). Its sources are the base's except `file_system.cpp`. | | `python3 -I scripts/check_no_game_data.py`, `tests/test_docs_env_vars.py` (4 tests), `tests/test_ctest_registration.py` (4 tests), `git diff --check` | Passed. | | Python loop over the non-semantic test files (`compileall`, 520 files of `tests/`, the content guard) | One failing file, `tests/test_imhex_patterns.py`, as on the base. None added. | Not run: native Windows (the 8 plain-form failures and the `dstorage_test` stop are unverified there), Proton, CTest itself (the executables were started directly), the `CREATE_ALWAYS` case of the last error (only `OPEN_ALWAYS` is tested), `CreateFileA`, the translator's semantic suite (no Python or translator file changed) and a boot of the title. GPUs tested: none. The fixture uses files and the startup trace only. AI-assisted: yes (Claude Code). ### Checklist - [x] One commit based on upstream main `6293c1c4f`. - [x] One topic: one startup-trace event, its documentation and its test form. - [x] No new switch. With the trace off nothing is written and the plain test form gives the same result as the base. - [x] Synthetic test over temporary files, no game data. Content guard and whitespace check passed. - [x] No translator rule changed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:21:06 +01:00
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#1393
No description provided.