Skip to content

Commit 7c75e9e

Browse files
feat(crashpad): Support optional usage of stack pointer for captured stack frame (#1427)
* Support optional usage of stack pointer for captured stack frame --------- Co-authored-by: Mischan Toosarani-Hausberger <[email protected]>
1 parent 9895a5c commit 7c75e9e

File tree

6 files changed

+40
-3
lines changed

6 files changed

+40
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- 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))
88

9+
**Features**:
10+
11+
- 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))
12+
913
**Fixes**:
1014

1115
- Add logs flush on crash. This is not available for macOS with the `crashpad` backend. ([#1404](https://github.com/getsentry/sentry-native/pull/1404))

include/sentry.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,22 @@ SENTRY_API void sentry_options_set_system_crash_reporter_enabled(
15731573
SENTRY_API void sentry_options_set_crashpad_wait_for_upload(
15741574
sentry_options_t *opts, int wait_for_upload);
15751575

1576+
/**
1577+
* Limits stack capture to stack pointer for the Crashpad backend.
1578+
* When enabled, Crashpad will use the current stack pointer as the upper bound
1579+
* of the stack capture range, once validated to be within TEB
1580+
* StackLimit/StackBase values. This reduces the capture range compared to
1581+
* using the full TEB-derived stack region.
1582+
*
1583+
* This is useful when running under Wine/Proton where the TEB values may
1584+
* be incorrect, leading to excessively large stack captures. This is
1585+
* disabled by default.
1586+
*
1587+
* This setting only has an effect when using the `crashpad` backend on Windows.
1588+
*/
1589+
SENTRY_API void sentry_options_set_crashpad_limit_stack_capture_to_sp(
1590+
sentry_options_t *opts, int enabled);
1591+
15761592
/**
15771593
* Sets the maximum time (in milliseconds) to wait for the asynchronous
15781594
* tasks to end on shutdown before attempting a forced termination.

src/backends/sentry_backend_crashpad.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,14 +597,22 @@ crashpad_backend_startup(
597597
}
598598
#endif
599599

600+
crashpad::CrashpadInfo *crashpad_info
601+
= crashpad::CrashpadInfo::GetCrashpadInfo();
602+
600603
if (!options->system_crash_reporter_enabled) {
601604
// Disable the system crash reporter. Especially on macOS, it takes
602605
// substantial time *after* crashpad has done its job.
603-
crashpad::CrashpadInfo *crashpad_info
604-
= crashpad::CrashpadInfo::GetCrashpadInfo();
605606
crashpad_info->set_system_crash_reporter_forwarding(
606607
crashpad::TriState::kDisabled);
607608
}
609+
610+
if (options->crashpad_limit_stack_capture_to_sp) {
611+
// Enable stack capture limit to work around Wine/Proton TEB issues
612+
crashpad_info->set_limit_stack_capture_to_sp(
613+
crashpad::TriState::kEnabled);
614+
}
615+
608616
return 0;
609617
}
610618

src/sentry_options.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ sentry_options_new(void)
5252
opts->crashpad_wait_for_upload = false;
5353
opts->enable_logging_when_crashed = true;
5454
opts->propagate_traceparent = false;
55+
opts->crashpad_limit_stack_capture_to_sp = false;
5556
opts->symbolize_stacktraces =
5657
// AIX doesn't have reliable debug IDs for server-side symbolication,
5758
// and the diversity of Android makes it infeasible to have access to debug
@@ -488,6 +489,13 @@ sentry_options_set_crashpad_wait_for_upload(
488489
opts->crashpad_wait_for_upload = !!wait_for_upload;
489490
}
490491

492+
void
493+
sentry_options_set_crashpad_limit_stack_capture_to_sp(
494+
sentry_options_t *opts, int enabled)
495+
{
496+
opts->crashpad_limit_stack_capture_to_sp = !!enabled;
497+
}
498+
491499
void
492500
sentry_options_set_shutdown_timeout(
493501
sentry_options_t *opts, uint64_t shutdown_timeout)

src/sentry_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct sentry_options_s {
4444
bool crashpad_wait_for_upload;
4545
bool enable_logging_when_crashed;
4646
bool propagate_traceparent;
47+
bool crashpad_limit_stack_capture_to_sp;
4748

4849
sentry_attachment_t *attachments;
4950
sentry_run_t *run;

0 commit comments

Comments
 (0)