Skip to content

Menu: use an exclusive RAII temp manifest for the activation context - #2283

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-2272-menu-temp-manifest
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-2272-menu-temp-manifest

Conversation

@Decodere

Copy link
Copy Markdown
Contributor

What is in it

Fixes #2272 by hardening and cleaning up the temporary Common Controls 6 activation-context manifest created in crates/xcl/src/main.rs:

  1. Exclusive unique RAII temp manifest (TempManifest): Replaces std::fs::write to the fixed path %TEMP%\xcl-menu.manifest with TempManifest::create_in, which generates unique xcl-menu-<pid>-<seq>.manifest paths and creates them exclusively via OpenOptions::new().write(true).create_new(true).share_mode(0).custom_flags(FILE_FLAG_OPEN_REPARSE_POINT). Colliding files, hard links, symlinks, directories, or junctions (AlreadyExists, or PermissionDenied when symlink_metadata().is_ok()) are skipped without truncating or overwriting existing targets, write/flush errors close the file handle before removing the partial file, and the handle is flushed and closed before calling CreateActCtxW with lossless UTF-16 encoding (OsStrExt::encode_wide).
  2. Immediate manifest cleanup: activate_manifest_in drops TempManifest immediately after CreateActCtxW returns (on both success and failure), so no temporary manifest file stays in %TEMP% while the menu is open or after teardown.
  3. Activation-context and COM lifecycle cleanup: activate_manifest_in calls ReleaseActCtx(h) if ActivateActCtx fails (fixing the handle leak), and Ui records com_init = CoInitializeEx(...) >= 0 so Ui::drop only calls CoUninitialize() when CoInitializeEx actually succeeded (avoiding an unbalanced CoUninitialize() after RPC_E_CHANGED_MODE).

Tested

  • Pre-fix reproduction (cargo test --release -p xcl --bin xcl -- --test-threads=1 --nocapture): confirmed unmodified Ui::enter() overwrote a pre-existing xcl-menu.manifest sentinel (FAILED, 0 passed; 1 failed).
  • Post-fix cargo test --release -p xcl --bin xcl -- --nocapture: 2 passed, 0 failed, 0 ignored:
    • temp_manifest_skips_collisions_and_removes_on_drop: pre-populates xcl-menu.manifest, a hard link to victim.txt at candidate 0, and a directory at candidate 1; verifies TempManifest skips both collisions without touching xcl-menu.manifest or victim.txt, writes exact MENU_MANIFEST to candidate 2, deletes it on Drop, and returns Err for a non-existent directory.
    • live_actctx_activates_after_manifest_removal_and_ui_guards_com: verifies live CreateActCtxW -> drop TempManifest (confirming file deleted before activation) -> ActivateActCtx + GetCurrentActCtx succeeds, Ui::enter_in on a fresh STA thread initializes COM and leaves zero extra temp files while active and after drop, and Ui::enter_in on an already-MTA thread observes RPC_E_CHANGED_MODE (com_init == false) and drops cleanly.
  • Full release workspace (cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture on NVIDIA GeForce RTX 4060): 23 test binaries, 1252 passed, 0 failed, 46 ignored (27 pre-existing hardware/debug-layer SKIPPED: 20 no wave64 on 32-lane GPU, 3 wave32 per-lane refused, 2 missing D3D12 debug layer, 1 driver cache toggle, 1 no heap windows; 0 skipped in main.rs).

Regression run

Paired 60 s scripts/smoke.ps1 runs on the same RTX 4060 host against origin/main (1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6) and PR head (0ec32afd07a6ce5de24259703cb2e10f983aa372):

Baseline (origin/main):

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1585 (PresentX 1585)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 14409 MB

PR head:

xcl-smoke v1
commit: 0ec32afd07a6ce5de24259703cb2e10f983aa372
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1594 (PresentX 1594)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14450 MB

Not tested

  • Interactive double-click Explorer launch of the TaskDialog menu UI (activation context creation, activation after file deletion, and STA/MTA COM pairing are exercised directly by the live Windows unit tests).
  • Symlink creation without elevation (hard link and directory collisions are exercised in the unprivileged unit test, and FILE_FLAG_OPEN_REPARSE_POINT prevents reparse-point traversal).
  • AMD/Intel GPUs and D3D12 debug-layer tests (d3d12SDKLayers.dll is not installed on this host).

AI use

Implemented and verified with Google Antigravity (Gemini 4 Neon).

Fixes #2272

Replace the fixed `%TEMP%\xcl-menu.manifest` `std::fs::write` in `Ui::enter()`
with an exclusively created `TempManifest` (`create_new(true)`, `share_mode(0)`,
`FILE_FLAG_OPEN_REPARSE_POINT`) named `xcl-menu-<pid>-<seq>.manifest` that
skips colliding files/links/directories, closes the file before `CreateActCtxW`,
deletes any partial file on write failure, and removes the manifest immediately
after `CreateActCtxW` finishes.

Also release the activation context handle if `ActivateActCtx` fails and only
call `CoUninitialize()` when `CoInitializeEx` succeeded (`hr >= 0`).

Fixes xcl-dev#2272
Assisted-by: Google Antigravity (Gemini 4 Neon)
@jennydeth

Copy link
Copy Markdown

NVIDIA run.

Setup: RTX 3060 12 GB (32-lane waves, driver 32.0.16.2101), Ryzen 5 5600X, 32 GB RAM, Windows 11 build 26300, Rust 1.100.0, DXC 1.9.2609.5, debug build. Head 0ec32af.

Result: cargo test --workspace -- --test-threads=4: 1252 passed, 0 failed, 46 ignored. SKIPPED: 18 GPU tests for no wave64 (expected on this card) and the usual per-lane / heap-window / driver-cache skips.

Not tested: opening xcl.exe from Explorer and using the menu by hand.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

@throny throny added the off-goal Does not bear on the current goal (world loading); waits until it is reached label Nov 25, 2026
@S1m0ne1997

Copy link
Copy Markdown

Test report for 0ec32afd07a6ce5de24259703cb2e10f983aa372 (this PR's head), for #1607.

Tested

  • NVIDIA GeForce RTX 4090 24 GB (driver 621.40), AMD Ryzen 9 9950X3D, 47 GB RAM, Windows 11 Home 10.0.26300, rustc 1.100.0 (0ef1bc386 2026-11-09) x86_64-pc-windows-msvc, debug.
  • cargo build --workspace, then cargo test --workspace -- --test-threads=4 at the head: 1252 passed, 0 failed, 46 ignored.
  • SKIPPED (17): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu (no wave64), coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu (no wave64), cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu (no wave64), the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu (no wave64), a_per_lane_2d_or_3d_group_runs_on_the_gpu (no wave64), const_and_null_mask_operands_agree_with_hlsl_on_the_gpu (const_mask, wave64: no wave64), f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's)); f16 arithmetic, wave64: no wave64), f32_programs_on_the_gpu (f32 arithmetic, wave64: no wave64; f32 compares, wave64: no wave64), f64_programs_on_the_gpu (f64, wave64: no wave64), integer_programs_on_the_gpu (integer arithmetic, wave64: no wave64; integer carries, wave64: no wave64), mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu (mask_ff0_flbit, wave64: no wave64), gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows), pso_measurement_compiles_an_exact_synthetic_record (cannot disable the driver cache (Windows Developer Mode is required): L'applicazione ha richiesto un'operazione che dipende da un componente SDK mancante o non corrispondente. (0x887A002D)), test_title_draws_with_a_root_signature_under_the_debug_layer (no d3d12SDKLayers.dll), uploads_start_from_each_subresources_state (no D3D12 debug layer (L'applicazione ha richiesto un'operazione che dipende da un componente SDK mancante o non corrispondente. (0x887A002D))).

Regression run (retail title, scripts/smoke.ps1 -Seconds 60, release; main built from the commit in its block, this PR from its head with no changes to crates/, both run with the scripts/smoke.ps1 of main, which hashes the name of the game folder)

main:

xcl-smoke v1
commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324
gpu: NVIDIA GeForce RTX 4090
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1599 (PresentX 1599)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16384 MB

this PR:

xcl-smoke v1
commit: 0ec32afd07a6ce5de24259703cb2e10f983aa372
gpu: NVIDIA GeForce RTX 4090
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1632 (PresentX 1632)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17600 MB

Not tested

  • AMD, other NVIDIA cards and drivers, Linux. I did not review the diff; this report is the build, the suite and the regression run only.

AI use: Claude Code with Claude Opus 5.5 ran the build, the suite and the regression run and wrote this report at my request.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

off-goal Does not bear on the current goal (world loading); waits until it is reached

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Menu: the activation-context manifest is written to a fixed name in %TEMP%, follows links, and is never removed

5 participants