runtime: trace successful file opens (RT-TRACE-SUCCESSFUL-OPENS) #1363

Closed
github-bot wants to merge 1 commit from gh-pr/1363/head into gh-pr/1363/base
Owner

@⁠Moriz82 on GitHub · 2026-11-24 22:33 UTC · original
split/rt-trace-successful-opens → main · +91 −21 · 5 files · 1 commits · closed without merging

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

**@⁠Moriz82** on GitHub · 2026-11-24 22:33 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1363) `split/rt-trace-successful-opens` → `main` · +91 −21 · 5 files · 1 commits · closed without merging Claimed in the coordination issue as: RT-TRACE-SUCCESSFUL-OPENS ([claim](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14)). 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)
The startup trace records a failed guest file open but not a successful
one, so a run that stops making progress does not show which files the
title had reached.

With --trace on, the first 600 successful CreateFileW and CreateFile2
calls are written as file_open events with the path the title passed,
the access mask and the caller. They have a budget of their own, apart
from the 256 failures. The last error a successful open leaves
(ERROR_ALREADY_EXISTS for OPEN_ALWAYS and CREATE_ALWAYS) is kept across
the event write. With the trace off nothing changes.

Cross-built gta6rt and file_system_test with clang-cl and ran the test
under Wine 11.22. file_system_test --trace-opens passed 9 of 9 checks;
with the base implementation 3 of the 9 failed (no file_open event).
Without the last-error restore the OPEN_ALWAYS check failed. The plain
file_system_test has the same 8 failures of 494 checks under Wine with
and without the change.

AI-assisted (Claude Code).

Co-authored-by: Plaaasma <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:48:48 +00:00
github-bot closed this pull request 2026-11-26 09:48:48 +00:00
Author
Owner

@⁠Moriz82 on GitHub · 2026-11-25 03:51 UTC · original

Rebased onto main at 5129be10. The success trace preserves the Win32 last error and keeps its own 600-event budget. file_system_open_trace passed under Wine. The broader file_system test had 8 failures out of 507 checks, including host ReadFile, MAXIMUM_ALLOWED opens and a wildcard listing. A matching baseline run is pending.

AI-assisted.

**@⁠Moriz82** on GitHub · 2026-11-25 03:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1363#issuecomment-7152305392) Rebased onto main at `5129be10`. The success trace preserves the Win32 last error and keeps its own 600-event budget. `file_system_open_trace` passed under Wine. The broader `file_system` test had 8 failures out of 507 checks, including host `ReadFile`, `MAXIMUM_ALLOWED` opens and a wildcard listing. A matching baseline run is pending. AI-assisted.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.