From 526fd2e05fcfbb91d2b0728b81e59eca252c5063 Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Sun, 26 Jul 2026 15:17:38 +0300 Subject: [PATCH 1/4] fix: apply default thread stack guarantee in static builds and the native backend Cache kernel32 functions before backend startup in static builds - previously sentry__set_default_thread_stack_guarantee() called from backend startup (crashpad/breakpad/inproc) silently no-oped because GetCurrentThreadStackLimits was not loaded yet. Also apply the default thread stack guarantee in the native backend startup, matching the other backends, so its in-process exception filter can run after a stack overflow. --- src/backends/sentry_backend_native.c | 5 +++++ src/sentry_core.c | 15 ++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/backends/sentry_backend_native.c b/src/backends/sentry_backend_native.c index 7bef920da..1a685843d 100644 --- a/src/backends/sentry_backend_native.c +++ b/src/backends/sentry_backend_native.c @@ -191,6 +191,11 @@ native_backend_startup( "development."); SENTRY_DEBUG("starting native backend"); +#if defined(SENTRY_PLATFORM_WINDOWS) && !defined(SENTRY_BUILD_SHARED) \ + && defined(SENTRY_THREAD_STACK_GUARANTEE_AUTO_INIT) + sentry__set_default_thread_stack_guarantee(); +#endif + #if defined(SENTRY_PLATFORM_WINDOWS) // Create process-wide mutex for IPC synchronization (Windows) // Use portable mutex to protect Windows mutex creation diff --git a/src/sentry_core.c b/src/sentry_core.c index ce47a38d4..5307cdc89 100644 --- a/src/sentry_core.c +++ b/src/sentry_core.c @@ -209,6 +209,14 @@ sentry_init(sentry_options_t *options) uint64_t last_crash = 0; +#if defined(SENTRY_PLATFORM_WINDOWS) \ + && (!defined(SENTRY_BUILD_SHARED) || defined(SENTRY_PLATFORM_XBOX)) + // This must run before backend startup so that dependents on its cached + // functions (e.g. the default thread stack guarantee set during backend + // startup) actually work. + sentry__init_cached_kernel32_functions(); +#endif + // and then we will start the backend, since it requires a valid run sentry_backend_t *backend = options->backend; if (backend && backend->startup_func) { @@ -253,13 +261,6 @@ sentry_init(sentry_options_t *options) backend->user_consent_changed_func(backend); } -#if defined(SENTRY_PLATFORM_WINDOWS) \ - && (!defined(SENTRY_BUILD_SHARED) || defined(SENTRY_PLATFORM_XBOX)) - // This function must be positioned so that any dependents on its cached - // functions are invoked after it. - sentry__init_cached_kernel32_functions(); -#endif - // after initializing the transport, we will submit all the unsent envelopes // and handle remaining sessions. SENTRY_DEBUG("processing and pruning old runs"); From a79302669c5759073ae6e6cbd05abde5338f2457 Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Mon, 27 Jul 2026 09:17:23 +0300 Subject: [PATCH 2/4] docs: add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99301f7bf..93bc6870d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ - Native: don't dump the crash daemon's log to `stderr` on shutdown unless debug logging is enabled, so terminal applications stay quiet when `debug` is off. ([#1910](https://github.com/getsentry/sentry-native/pull/1910)) - Native/Windows: capture heap corruption crashes reported as `STATUS_HEAP_CORRUPTION` (`0xC0000374`). ([#1909](https://github.com/getsentry/sentry-native/pull/1909)) - Native/Linux: add support for `sentry_options_set_handler_strategy(SENTRY_HANDLER_STRATEGY_CHAIN_AT_START)`. ([#1912](https://github.com/getsentry/sentry-native/pull/1912)) +- Windows: apply the default thread stack guarantee in static builds - kernel32 functions are now cached before backend startup, so `sentry__set_default_thread_stack_guarantee()` no longer silently no-ops. ([#1918](https://github.com/getsentry/sentry-native/pull/1918)) +- Native/Windows: set the default thread stack guarantee during backend startup, matching the other backends, so crash handling can run after a stack overflow. ([#1918](https://github.com/getsentry/sentry-native/pull/1918)) ## 0.15.4 From 9184e2228a9bb2afe20aec56a45ccd6c8636b5eb Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Mon, 27 Jul 2026 09:33:45 +0300 Subject: [PATCH 3/4] keep original comment for the relocated kernel32 caching call --- src/sentry_core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/sentry_core.c b/src/sentry_core.c index 5307cdc89..f0d151788 100644 --- a/src/sentry_core.c +++ b/src/sentry_core.c @@ -211,9 +211,8 @@ sentry_init(sentry_options_t *options) #if defined(SENTRY_PLATFORM_WINDOWS) \ && (!defined(SENTRY_BUILD_SHARED) || defined(SENTRY_PLATFORM_XBOX)) - // This must run before backend startup so that dependents on its cached - // functions (e.g. the default thread stack guarantee set during backend - // startup) actually work. + // This function must be positioned so that any dependents on its cached + // functions are invoked after it. sentry__init_cached_kernel32_functions(); #endif From bb7f4143381cdc7ac5da4673f9f42c5cf1109405 Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Mon, 27 Jul 2026 09:40:02 +0300 Subject: [PATCH 4/4] condense changelog to a single entry --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93bc6870d..a0239fca5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,8 +21,7 @@ - Native: don't dump the crash daemon's log to `stderr` on shutdown unless debug logging is enabled, so terminal applications stay quiet when `debug` is off. ([#1910](https://github.com/getsentry/sentry-native/pull/1910)) - Native/Windows: capture heap corruption crashes reported as `STATUS_HEAP_CORRUPTION` (`0xC0000374`). ([#1909](https://github.com/getsentry/sentry-native/pull/1909)) - Native/Linux: add support for `sentry_options_set_handler_strategy(SENTRY_HANDLER_STRATEGY_CHAIN_AT_START)`. ([#1912](https://github.com/getsentry/sentry-native/pull/1912)) -- Windows: apply the default thread stack guarantee in static builds - kernel32 functions are now cached before backend startup, so `sentry__set_default_thread_stack_guarantee()` no longer silently no-ops. ([#1918](https://github.com/getsentry/sentry-native/pull/1918)) -- Native/Windows: set the default thread stack guarantee during backend startup, matching the other backends, so crash handling can run after a stack overflow. ([#1918](https://github.com/getsentry/sentry-native/pull/1918)) +- Windows: the default thread stack guarantee is now actually applied in static builds and is also set by the native backend, so crash handling can run after a stack overflow. ([#1918](https://github.com/getsentry/sentry-native/pull/1918)) ## 0.15.4