Repository navigation
feat(exit-watchdog): the image list and stack capture on Windows (#4589) - #4890
Merged
Merged
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, notFixes.Problem
On Windows the watchdog line names no library:
platform/mod.rsused theunsupportedimage 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 withERROR_BAD_LENGTH(a module loads at the same time) is retried.windows_stack.rs(x86_64):current_thread()opens the armed thread (OpenThreadwith suspend and context rights).capture_stack()does this:GetThreadContext, which also waits for the suspension);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 arm64CONTEXTand 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()beforeExitProcess, and a missing helper. A hang insideExitProcess(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 inexit_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.dllloaded 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. Ina_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_watchdogtests on the GREEN build, 0 failures, longest 1.56 s.Host:
malloctaken by address on Windows is the import stub in the test executable, so the host test looks it up inucrtbase.dll.Lint:
clippy -D warnings --all-targetsforobs-exit-watchdogandobs-gpu-statusis clean onx86_64-pc-windows-msvc,aarch64-pc-windows-msvcand the macOS host;rustfmtis 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_stacksstarts one thread, which stays blocked until the test process ends, as inanother_threads_stack_is_captured. The wholeexit_watchdoggroup takes about 1.6 s.🤖 Generated with Claude Code