Skip to content

fix(gui,overlay): give Windows debug builds a 2 MiB main-thread stack - #2126

Open
Levgenij wants to merge 1 commit into
AprilNEA:masterfrom
Levgenij:fix/windows-debug-main-stack
Open

Levgenij wants to merge 1 commit into
AprilNEA:masterfrom
Levgenij:fix/windows-debug-main-stack

Conversation

@Levgenij

Copy link
Copy Markdown
Contributor

Summary

Debug builds of openlogi-desktop and openlogi-overlay die with STATUS_STACK_OVERFLOW on Windows before they show anything. The frame that overflows is the initializer rust_i18n::i18n! generates, and only an unoptimized build has it. This gives those two binaries, in the debug profile only, the 2 MiB main-thread stack Rust already gives every other thread. Release binaries are untouched.

Split out of #1904 as asked there, with the frame named.

The frame

Under cdb on a 1 MiB stack, both binaries overflow at the same place:

00  __chkstk+0x37
01  openlogi_desktop::_RUST_I18N_BACKEND::closure$0+0xb   main.rs @ 41   (the i18n! macro)
02  FnOnce::call_once
…   LazyLock::force / Once::call_once_force
0b  openlogi_desktop::_rust_i18n_backend_translate
0c  openlogi_desktop::_rust_i18n_try_translate
0d  openlogi_desktop::app::menu::menus                     (the first t! on the main thread)
0e  openlogi_desktop::app::menu::install                   menu.rs @ 109
0f  openlogi_desktop::main::closure$2                      main.rs @ 129

The prologue of _RUST_I18N_BACKEND::closure$0 is

mov  eax, 1352C0h      ; 1 266 368 bytes
call __chkstk

in both the desktop and the overlay debug binaries. The rest of the stack at that point is about 26 KiB, so no other frame matters: this one asks for 1.21 MiB on a 1 MiB thread.

rust-i18n-macro 4.2.1 (generate_code) expands every catalog under openlogi-ui/locales into one HashMap literal each, inside the LazyLock closure. Unoptimized, every Cow pair of all 24 catalogs sits in the closure's frame until add_translations takes it. The release build inlines the closure and has no such frame: dumpbin of the release binaries shows neither the symbol nor a large __chkstk request.

The macro offers no way around this: its backend = argument only extends the generated backend, the literal is emitted regardless.

Why only these two binaries

  • openlogi-agent also expands i18n! but translates only from the tray's own win32 thread, which Rust gives 2 MiB. It never hit this.
  • Test harnesses run each test on a 2 MiB thread. cargo test -p openlogi-overlay the_shared_catalog_is_wired_up passes as is and overflows with RUST_MIN_STACK=1048576, which is the same frame; CI never saw the problem because CI never runs the binaries.
  • Release: left alone, see above.

Changes

  • crates/openlogi-desktop/build.rs, crates/openlogi-overlay/build.rs: reserve_debug_main_stack, which emits cargo:rustc-link-arg-bin=<binary>=/STACK:2097152 (--stack for GNU) when CARGO_CFG_TARGET_OS is windows and PROFILE is debug. It is a linker argument in the build script rather than rustflags in .cargo/config.toml because CI's RUSTFLAGS would override the latter.

2 MiB is the smallest round size that fits: the frame is 1.21 MiB plus a few KiB of callers. It is also what std reserves for a spawned thread, so it is not a new number in the project.

Testing

cargo build -p openlogi-desktop -p openlogi-overlay            # debug
cargo build -p openlogi-desktop -p openlogi-overlay --release
cargo clippy -p openlogi-desktop -p openlogi-overlay --all-targets -- -D warnings

On Windows 11, MSVC, stable 1.99:

  • dumpbin /headers on the debug binaries: 200000 size of stack reserve (2 MiB); on the release binaries: 100000 (1 MiB, unchanged).
  • The debug GUI opens and shows a device; the debug overlay opens the ring. Both died at startup before.

Not run on macOS or Linux; the function returns early there, so the build scripts are unchanged for those targets.

Debug builds of openlogi-desktop and openlogi-overlay died with
STATUS_STACK_OVERFLOW on Windows before showing anything. Under cdb both
overflow in the same frame: `_RUST_I18N_BACKEND::closure$0`, the
initializer `rust_i18n::i18n!` generates, whose prologue asks `__chkstk`
for 0x1352C0 bytes (1.21 MiB) on the 1 MiB stack Windows gives the main
thread. Unoptimized, the closure keeps every entry of all 24 catalogs on
the stack until the HashMap takes it; release inlines the closure and has
no such frame. The macro's `backend =` argument only extends the
generated backend, so the literal cannot be avoided from this side.

Each build script now passes the linker a 2 MiB stack reserve for its own
binary, in the debug profile on Windows only. 2 MiB is what std gives a
spawned thread, which is why the agent, translating from the tray's own
thread, and the test harnesses never hit this. The value lives in the
build scripts because CI's RUSTFLAGS would override `.cargo/config.toml`.
@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

Gives Windows debug builds of openlogi-desktop and openlogi-overlay a 2 MiB main-thread stack.

  • Windows debug desktop and overlay builds now get a 2 MiB main-thread stack.

Reviews (1) · Last reviewed commit: "fix(gui,overlay): give Windows debug bui..." · Reviewed by Greptile

@davidbudnick davidbudnick added this to the v1.0.0 milestone Oct 28, 2026
@davidbudnick davidbudnick added area: gui Graphical user interface platform: windows Windows-specific issue type: bug Something is broken or behaves incorrectly labels Oct 28, 2026
@Ariazonaa

Ariazonaa commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Tested on Windows 11 (MSVC), this commit merged onto bcaa7a20 without conflicts. The debug GUI dies with 0xC00000FD without it and opens with it, three starts each. I did not open the ring; dumpbin shows 1 MiB → 2 MiB for both binaries.

One thing to consider: the frame has grown with the catalogs, from 0x1352C0 (727 keys) to 0x1B0D30 (1024 keys, 1.69 MiB), about 72 bytes per entry in all 24 catalogs. That leaves room for roughly 170 more keys or four more languages. I added dummy keys to check: with 150 the overlay's catalog test passes, with 200 it overflows, and so does the debug GUI built with this PR. So a larger reserve (8 MiB?) would last longer.

With 200 extra keys the overlay and desktop tests overflow as well, since test threads get 2 MiB. I only measured that on Windows, but it means CI could hit this independently of this PR.

Edit: I missed that rust-i18n 4.2.4 fixes the cause. With it, the debug GUI starts on the default 1 MiB without this PR, so the larger reserve I suggested is not needed. I did not test the overlay's ring.

This branch has not been deployed

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

Labels

area: gui Graphical user interface platform: windows Windows-specific issue type: bug Something is broken or behaves incorrectly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants