From 3d7e8f8cfa049e72c86c3c999417899384e379d5 Mon Sep 17 00:00:00 2001 From: mujacica Date: Wed, 22 Oct 2025 17:48:00 +0200 Subject: [PATCH 1/7] feat(crashpad): Support optional usage of stack pointer for captured stack frame --- include/sentry.h | 14 ++++++++++++++ src/backends/sentry_backend_crashpad.cpp | 11 +++++++++-- src/sentry_options.c | 8 ++++++++ src/sentry_options.h | 1 + 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/include/sentry.h b/include/sentry.h index 0548fa667..316a7d6b8 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -1573,6 +1573,20 @@ SENTRY_API void sentry_options_set_system_crash_reporter_enabled( SENTRY_API void sentry_options_set_crashpad_wait_for_upload( sentry_options_t *opts, int wait_for_upload); +/** + * Enables stack capture adjustment for the Crashpad backend. + * When enabled, Crashpad will adjust the stack capture range based on the + * current stack pointer instead of using TEB StackLimit/StackBase values. + * + * This is useful when running under Wine/Proton where the TEB values may + * be incorrect, leading to excessively large stack captures. This is + * disabled by default. + * + * This setting only has an effect when using the `crashpad` backend on Windows. + */ +SENTRY_API void sentry_options_set_crashpad_adjust_stack_capture( + sentry_options_t *opts, int enabled); + /** * Sets the maximum time (in milliseconds) to wait for the asynchronous * tasks to end on shutdown before attempting a forced termination. diff --git a/src/backends/sentry_backend_crashpad.cpp b/src/backends/sentry_backend_crashpad.cpp index b8d0069ef..447b6a9b0 100644 --- a/src/backends/sentry_backend_crashpad.cpp +++ b/src/backends/sentry_backend_crashpad.cpp @@ -597,14 +597,21 @@ crashpad_backend_startup( } #endif + crashpad::CrashpadInfo *crashpad_info + = crashpad::CrashpadInfo::GetCrashpadInfo(); + if (!options->system_crash_reporter_enabled) { // Disable the system crash reporter. Especially on macOS, it takes // substantial time *after* crashpad has done its job. - crashpad::CrashpadInfo *crashpad_info - = crashpad::CrashpadInfo::GetCrashpadInfo(); crashpad_info->set_system_crash_reporter_forwarding( crashpad::TriState::kDisabled); } + + if (options->crashpad_adjust_stack_capture) { + // Enable stack capture adjustment to work around Wine/Proton TEB issues + crashpad_info->set_adjust_stack_capture(crashpad::TriState::kEnabled); + } + return 0; } diff --git a/src/sentry_options.c b/src/sentry_options.c index fccfb0bb3..6b4724486 100644 --- a/src/sentry_options.c +++ b/src/sentry_options.c @@ -52,6 +52,7 @@ sentry_options_new(void) opts->crashpad_wait_for_upload = false; opts->enable_logging_when_crashed = true; opts->propagate_traceparent = false; + opts->crashpad_adjust_stack_capture = false; opts->symbolize_stacktraces = // AIX doesn't have reliable debug IDs for server-side symbolication, // and the diversity of Android makes it infeasible to have access to debug @@ -488,6 +489,13 @@ sentry_options_set_crashpad_wait_for_upload( opts->crashpad_wait_for_upload = !!wait_for_upload; } +void +sentry_options_set_crashpad_adjust_stack_capture( + sentry_options_t *opts, int enabled) +{ + opts->crashpad_adjust_stack_capture = !!enabled; +} + void sentry_options_set_shutdown_timeout( sentry_options_t *opts, uint64_t shutdown_timeout) diff --git a/src/sentry_options.h b/src/sentry_options.h index fe00778d3..929786d39 100644 --- a/src/sentry_options.h +++ b/src/sentry_options.h @@ -44,6 +44,7 @@ struct sentry_options_s { bool crashpad_wait_for_upload; bool enable_logging_when_crashed; bool propagate_traceparent; + bool crashpad_adjust_stack_capture; sentry_attachment_t *attachments; sentry_run_t *run; From a9cbfc2a2b4a8da70ee20406a7e2399bb4aec4ab Mon Sep 17 00:00:00 2001 From: mujacica Date: Wed, 22 Oct 2025 17:57:54 +0200 Subject: [PATCH 2/7] Fix changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e2779c31..65fdeec6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - If you use a narrow string path interface (for instance, `sentry_options_set_database_path()`) on _Windows_ rather than one of the wide string variants (`sentry_options_set_database_pathw()`), then the expected encoding is now UTF-8. ([#1413](https://github.com/getsentry/sentry-native/pull/1413)) +**Features**: + +- Support optional usage of stack pointer for captured stack frame ([#1427](https://github.com/getsentry/sentry-native/pull/1427)) + **Fixes**: - Add logs flush on crash. This is not available for macOS with the `crashpad` backend. ([#1404](https://github.com/getsentry/sentry-native/pull/1404)) From d5365205264bd2915ba8eadef798edd6730a002b Mon Sep 17 00:00:00 2001 From: mujacica Date: Fri, 24 Oct 2025 15:30:32 +0200 Subject: [PATCH 3/7] Update crashpad version --- external/crashpad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/crashpad b/external/crashpad index b160f39e9..94636a4a2 160000 --- a/external/crashpad +++ b/external/crashpad @@ -1 +1 @@ -Subproject commit b160f39e9cea7b365d963d9e4774e0fa22c03725 +Subproject commit 94636a4a2e9530ff3a356377965126633bd908eb From c75fd24f3c0d7b863c3713f2f5c3e75baf911c24 Mon Sep 17 00:00:00 2001 From: Amir Mujacic Date: Tue, 28 Oct 2025 08:49:12 +0100 Subject: [PATCH 4/7] Update CHANGELOG.md Co-authored-by: Mischan Toosarani-Hausberger --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65fdeec6c..3cc39ff63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ **Features**: -- Support optional usage of stack pointer for captured stack frame ([#1427](https://github.com/getsentry/sentry-native/pull/1427)) +- Add an option to use the stack pointer as an upper limit for the stack capture range in `crashpad` on Windows. This is useful for targets like Proton/Wine, where one can't rely on the TEB-derived upper bound being correctly maintained by the system, leading to overly large stack captures per thread. ([#1427](https://github.com/getsentry/sentry-native/pull/1427), [crashpad#137](https://github.com/getsentry/crashpad/pull/137)) **Fixes**: From ce44f65a5ae2637eb07486ca66bdd83e6955c11e Mon Sep 17 00:00:00 2001 From: mujacica Date: Tue, 28 Oct 2025 09:06:41 +0100 Subject: [PATCH 5/7] Fix PR comments --- external/crashpad | 2 +- include/sentry.h | 10 ++++++---- src/backends/sentry_backend_crashpad.cpp | 6 +++--- src/sentry_options.c | 6 +++--- src/sentry_options.h | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/external/crashpad b/external/crashpad index 94636a4a2..69e96cf2d 160000 --- a/external/crashpad +++ b/external/crashpad @@ -1 +1 @@ -Subproject commit 94636a4a2e9530ff3a356377965126633bd908eb +Subproject commit 69e96cf2d9e5523afb29cd9b19aa4b91d38b4263 diff --git a/include/sentry.h b/include/sentry.h index 316a7d6b8..4e65ca767 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -1574,9 +1574,11 @@ SENTRY_API void sentry_options_set_crashpad_wait_for_upload( sentry_options_t *opts, int wait_for_upload); /** - * Enables stack capture adjustment for the Crashpad backend. - * When enabled, Crashpad will adjust the stack capture range based on the - * current stack pointer instead of using TEB StackLimit/StackBase values. + * Limits stack capture to stack pointer for the Crashpad backend. + * When enabled, Crashpad will use the current stack pointer as the upper bound + * of the stack capture range, once validated to be within TEB + * StackLimit/StackBase values. This reduces the capture range compared to + * using the full TEB-derived stack region. * * This is useful when running under Wine/Proton where the TEB values may * be incorrect, leading to excessively large stack captures. This is @@ -1584,7 +1586,7 @@ SENTRY_API void sentry_options_set_crashpad_wait_for_upload( * * This setting only has an effect when using the `crashpad` backend on Windows. */ -SENTRY_API void sentry_options_set_crashpad_adjust_stack_capture( +SENTRY_API void sentry_options_set_crashpad_limit_stack_capture_to_sp( sentry_options_t *opts, int enabled); /** diff --git a/src/backends/sentry_backend_crashpad.cpp b/src/backends/sentry_backend_crashpad.cpp index 447b6a9b0..63530d8b3 100644 --- a/src/backends/sentry_backend_crashpad.cpp +++ b/src/backends/sentry_backend_crashpad.cpp @@ -607,9 +607,9 @@ crashpad_backend_startup( crashpad::TriState::kDisabled); } - if (options->crashpad_adjust_stack_capture) { - // Enable stack capture adjustment to work around Wine/Proton TEB issues - crashpad_info->set_adjust_stack_capture(crashpad::TriState::kEnabled); + if (options->crashpad_limit_stack_capture_to_sp) { + // Enable stack capture limit to work around Wine/Proton TEB issues + crashpad_info->set_limit_stack_capture_to_sp(crashpad::TriState::kEnabled); } return 0; diff --git a/src/sentry_options.c b/src/sentry_options.c index 6b4724486..5cc69c4df 100644 --- a/src/sentry_options.c +++ b/src/sentry_options.c @@ -52,7 +52,7 @@ sentry_options_new(void) opts->crashpad_wait_for_upload = false; opts->enable_logging_when_crashed = true; opts->propagate_traceparent = false; - opts->crashpad_adjust_stack_capture = false; + opts->crashpad_limit_stack_capture_to_sp = false; opts->symbolize_stacktraces = // AIX doesn't have reliable debug IDs for server-side symbolication, // and the diversity of Android makes it infeasible to have access to debug @@ -490,10 +490,10 @@ sentry_options_set_crashpad_wait_for_upload( } void -sentry_options_set_crashpad_adjust_stack_capture( +sentry_options_set_crashpad_limit_stack_capture_to_sp( sentry_options_t *opts, int enabled) { - opts->crashpad_adjust_stack_capture = !!enabled; + opts->crashpad_limit_stack_capture_to_sp = !!enabled; } void diff --git a/src/sentry_options.h b/src/sentry_options.h index 929786d39..bbcc8c93e 100644 --- a/src/sentry_options.h +++ b/src/sentry_options.h @@ -44,7 +44,7 @@ struct sentry_options_s { bool crashpad_wait_for_upload; bool enable_logging_when_crashed; bool propagate_traceparent; - bool crashpad_adjust_stack_capture; + bool crashpad_limit_stack_capture_to_sp; sentry_attachment_t *attachments; sentry_run_t *run; From 82834bdefe50f07b66a016ff4703ddec849b95a5 Mon Sep 17 00:00:00 2001 From: mujacica Date: Tue, 28 Oct 2025 09:11:25 +0100 Subject: [PATCH 6/7] Fix build errors --- external/crashpad | 2 +- src/backends/sentry_backend_crashpad.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/external/crashpad b/external/crashpad index 69e96cf2d..683054d8f 160000 --- a/external/crashpad +++ b/external/crashpad @@ -1 +1 @@ -Subproject commit 69e96cf2d9e5523afb29cd9b19aa4b91d38b4263 +Subproject commit 683054d8fde443da6d57fc0ffc26eb166b4e80b7 diff --git a/src/backends/sentry_backend_crashpad.cpp b/src/backends/sentry_backend_crashpad.cpp index 63530d8b3..181e3d6c4 100644 --- a/src/backends/sentry_backend_crashpad.cpp +++ b/src/backends/sentry_backend_crashpad.cpp @@ -609,7 +609,8 @@ crashpad_backend_startup( if (options->crashpad_limit_stack_capture_to_sp) { // Enable stack capture limit to work around Wine/Proton TEB issues - crashpad_info->set_limit_stack_capture_to_sp(crashpad::TriState::kEnabled); + crashpad_info->set_limit_stack_capture_to_sp( + crashpad::TriState::kEnabled); } return 0; From 26ad6d80bcfb1401ab9bf5d26741549571163112 Mon Sep 17 00:00:00 2001 From: mujacica Date: Tue, 28 Oct 2025 13:42:10 +0100 Subject: [PATCH 7/7] Point to getsentry head again --- external/crashpad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/crashpad b/external/crashpad index 683054d8f..d8990d2f6 160000 --- a/external/crashpad +++ b/external/crashpad @@ -1 +1 @@ -Subproject commit 683054d8fde443da6d57fc0ffc26eb166b4e80b7 +Subproject commit d8990d2f686b8827a21532748c6c42add21c21ea