Skip to content

feat(exit-watchdog): the image list and stack capture on Windows (#4589) - #4890

Merged
vpacher merged 2 commits into
masterfrom
fix/4589-windows-dll-name
Nov 16, 2026
Merged

vpacher merged 2 commits into
masterfrom
fix/4589-windows-dll-name

Conversation

@vpacher

@vpacher vpacher commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Refs #4589

Part 3 of the plan in the claim: the image list and the stack capture on Windows, in-process. Part 4 (the helper names the DLL) follows in its own PR, so this one says Refs, not Fixes.

Problem

On Windows the watchdog line names no library: platform/mod.rs used the unsupported image list and stack capture there. So the host tests (the_host_lists_its_images_in_load_order, another_threads_stack_is_captured, a_blocked_process_names_the_library) took their "not supported" branch.

Change

rust/obs-exit-watchdog/src/platform/:

  • windows_images.rs (all Windows targets): images() lists the modules through Toolhelp (CreateToolhelp32Snapshot(TH32CS_SNAPMODULE), Module32FirstW/Module32NextW). It uses the loader's load order, with the executable first, so the obs-exit-watchdog: Record which module brought in which libraries #4549 owner rule works unchanged. A snapshot that fails with ERROR_BAD_LENGTH (a module loads at the same time) is retried.

  • windows_stack.rs (x86_64): current_thread() opens the armed thread (OpenThread with suspend and context rights). capture_stack() does this:

    1. suspends the thread and reads its registers (GetThreadContext, which also waits for the suspension);
    2. unwinds frame by frame with RtlLookupFunctionEntry/RtlVirtualUnwind. A frame without unwind data is a leaf, whose return address is at the stack pointer.

    It uses no allocation and no dbghelp, and it stops when the stack pointer does not move up.

  • mod.rs: the Windows x64 arm uses both. The other Windows arm (arm64) gets the image list, but its stack capture (an arm64 CONTEXT and its unwind) is not built yet and still gives no frames.

With this, the line names the DLL when the in-process thread fires. That covers a hang in exit() before ExitProcess, and a missing helper. A hang inside ExitProcess (a DLL's detach) is the helper's case, which is part 4.

docs/features.md: the "names the plugin" entry says what Windows x64 names now and what follows.

Tests

All Windows runs were on a Windows 11 VM (x64, MSVC), with soldr cargo test -p obs-gpu-status --test obs-tests-gpu exit_watchdog.

  • RED 428c046eb: two Windows tests in exit_watchdog::images::windows:

    • windows_lists_images_and_captures_stacks: the image list is not empty, and on x64 another thread's stack gives frames.
    • a_library_loaded_later_comes_last: winmm.dll loaded now is listed after every image loaded before it.

    Result: 25 passed; 2 failed.

  • GREEN 27ed17571: 27 passed; 0 failed. The three host tests above now run their real branch on Windows. In a_blocked_process_names_the_library, a blocked child's line names the test executable and the module the table gives it.

  • Repeats: 20 runs of the exit_watchdog tests on the GREEN build, 0 failures, longest 1.56 s.

  • Host: malloc taken by address on Windows is the import stub in the test executable, so the host test looks it up in ucrtbase.dll.

  • Lint: clippy -D warnings --all-targets for obs-exit-watchdog and obs-gpu-status is clean on x86_64-pc-windows-msvc, aarch64-pc-windows-msvc and the macOS host; rustfmt is clean. arm64 Windows is compile-checked only.

Tiers: Tier 1 only. This is new Rust host code with no C original, so Tiers 2–4 do not apply.

Test cost: the new tests run in well under a second. windows_lists_images_and_captures_stacks starts one thread, which stays blocked until the test process ends, as in another_threads_stack_is_captured. The whole exit_watchdog group takes about 1.6 s.

🤖 Generated with Claude Code

vpacher and others added 2 commits November 16, 2026 12:33
…ows (#4589)

On Windows the watchdog line names no library: the platform boundary
uses the `unsupported` image list and stack capture there, so the host
tests take their "not supported" branch. Two Windows tests:

- windows_lists_images_and_captures_stacks: the image list is not empty
  and, on x64, another thread's stack gives frames;
- a_library_loaded_later_comes_last: a DLL loaded now is listed after
  every image loaded before it (the load order the #4549 owner rule
  needs).

`malloc` taken by address on Windows is the import stub in the test
executable, so the host test looks it up in ucrtbase.dll.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The watchdog line now names the DLL on Windows when the in-process
thread fires (no helper, or a hang in exit() before ExitProcess):

- images(): Toolhelp (`CreateToolhelp32Snapshot`, `Module32FirstW`/
  `Module32NextW`) lists the modules in the loader's load order, the
  executable first, so the #4549 owner rule works unchanged. A snapshot
  that fails with ERROR_BAD_LENGTH (a module loads meanwhile) is retried.
- capture_stack() on x64: the armed thread is opened at arm time,
  suspended, its registers read with GetThreadContext, and its stack
  unwound with RtlLookupFunctionEntry/RtlVirtualUnwind (a frame without
  unwind data is a leaf: the return address is at the stack pointer).
  No allocation, no dbghelp.

arm64 Windows gets the image list; its stack capture (an arm64 CONTEXT
and its unwind) is not built yet and still gives no frames.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vpacher
vpacher requested a review from zackees as a code owner November 16, 2026 11:35
@vpacher
vpacher enabled auto-merge November 16, 2026 11:36
@vpacher
vpacher added this pull request to the merge queue Nov 16, 2026
Merged via the queue into master with commit 01c5c1e Nov 16, 2026
41 checks passed
@vpacher
vpacher deleted the fix/4589-windows-dll-name branch November 16, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant