Skip to content

runtime: create startup traces exclusively without fopen x mode - #6991

Open
Zunraz wants to merge 1 commit into
ItsNotRexed:mainfrom
Zunraz:fix/startup-trace-exclusive-create
Open

Zunraz wants to merge 1 commit into
ItsNotRexed:mainfrom
Zunraz:fix/startup-trace-exclusive-create

Conversation

@Zunraz

@Zunraz Zunraz commented Nov 23, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue as: startup trace exclusive creation with the static UCRT.

What and why

With the static UCRT in the documented clang-cl/xwin build, gta6rt --dry-run <synthetic.exe> --trace fresh.jsonl terminates with 0xC0000409 before loading the image. _wfopen_s(..., L"wxb") invokes the invalid-parameter handler; a separate no-game CRT probe confirms EINVAL for wxb, wbx and wx, while wb opens.

Create the file using _wsopen_s with _O_CREAT | _O_EXCL | _O_WRONLY | _O_BINARY, then attach its FILE stream with _wfdopen. The documented exclusive-create flags preserve atomic refusal of existing paths. A failed stream conversion closes its descriptor and reports the saved error.

The new package-free startup_trace_creation CTest checks fresh Unicode output and its first JSON event, preservation of an existing trace, preservation of a copied synthetic input image, and clean refusal of directory/missing-parent destinations. Guest arguments are relative for compatibility with the existing Wine runner; Wine was not executed locally.

No prerequisite. Rebased onto main bd3f061ad at f298ec64e, retaining #6937's diagnostics. A trial merge with #6410 (d7222bfde) remains clean.

Tested

Native Windows x64, build 26300 / 26H2; binaries cross-built in Ubuntu/WSL with clang-cl 21.1.8 and xwin SDK 10.0.26100. CPU only; no GPU/driver paths exercised.

  • Red control: the new CLI checker against the unchanged trace opener fails on fresh creation with 0xC0000409.
  • On the final rebased head, both static (MultiThreaded) and dynamic (MultiThreadedDLL) CRT builds pass all five CLI scenarios and 26/26 existing startup_trace checks each.
  • The fixed static build also passes the synthetic GDK dynamic-load and GAME-directory subprocess checkers.
  • test_ctest_registration: 4 passed; test_ci_registration: 14 passed. Both startup trace tests appear in the configured CTest list. Python compileall, whitespace and no-game-data checks pass.
  • Broader checks have baseline failures, reproduced in a separate untouched bd3f061ad worktree: test_runtime_paths is 4 passed / 1 failed because tools/replace_retry.py is absent from the workflow filter; test_text_write_line_endings is 2 passed / 1 failed at unchanged tools/f64_omod_probe.py:268 and tools/leonida_tui.py:753.

AI-assisted: yes, Codex. The fix and regressions use synthetic inputs only. This is a diagnostic fix, not a successful-boot claim.

Checklist

  • No game data, keys or decryption, including in logs/reports quoted here.
  • Translator contract update: not applicable; no translator rule changes.

@Zunraz
Zunraz force-pushed the fix/startup-trace-exclusive-create branch from 3757d46 to f298ec6 Compare November 23, 2026 15:41
@thehollowedone

Copy link
Copy Markdown

Independent native Windows check of f298ec64 with MSVC 19.44 and Windows SDK 10.0.26100. The stock startup_trace_creation CTest passed with both the dynamic CRT (/MD) and the static CRT (/MT).

A new trace with a Unicode name started with the expected trace_open record. Trying to reuse that filename exited 2 and left its bytes unchanged. The synthetic input executable also stayed unchanged, and a directory or missing parent was rejected cleanly. This run covered trace creation.

AI-assisted.

@devnull34 devnull34 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Windows 11 (MSVC RelWithDebInfo):

  • Built gta6rt, tiny_game, and startup_trace_test cleanly.
  • startup_trace_test.exe passed all 26 checks (0 failures), verifying:
    • Exclusive creation without relying on fopen x mode (_wsopen_s with _O_CREAT | _O_EXCL and _wfdopen).
    • Pre-existing files and collision refusal report EEXIST cleanly and preserve file bytes.
  • CTest targets passed 100%:
    • 23: startup_trace: Passed (0.01s)
    • 24: startup_trace_creation: Passed (0.16s)
  • Whitespace clean (git diff HEAD~1..HEAD --check).

@pvfreis

pvfreis commented Nov 23, 2026

Copy link
Copy Markdown

Tested f298ec6 on Windows 11 26H2 (26300), MSVC 19.44.35229 (v143) + Ninja, RelWithDebInfo (dynamic UCRT): pass.

  • ctest -R ^startup_trace: 2/2 pass (startup_trace, startup_trace_creation), including the Unicode trace name, the refusal that keeps an existing trace and the input image unchanged, and the . / missing-parent refusals.
  • Negative control: with runtime/shims/startup_trace.h reverted to main (bd3f061ad, the _wfopen_s(..., L"wxb") version), startup_trace_creation still passes on this MSVC build. That matches the description (the abort is specific to the static UCRT in the clang-cl/xwin build), but it means the new test only guards against a regression in that build: the MSVC CI job would not catch a return to "wxb".

AI-assisted (Claude Code).

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.

4 participants