You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: more defensive auto thread stack guarantee (#1196)
* fix: provide less aggressive auto thread stack guarantee
* verbose-log is off
* update changelog
* ensure no unused `success` variable
* update inline docs to reflect that sentry_init() is no longer a requirement
* clarify error logs when SetThreadStackGuarantee failed
* redo dynamic loading of thread-stack-guarantee functions from DllMain since all come directly from kernel32 which guaranteed to be loaded.
* remove superflous 0
Co-authored-by: JoshuaMoelans <[email protected]>
* clarify 32KiB as a lower bound
* replace copy-pasted GetCurrentThreadStackLimits error message
* adding unit-test
* fix syntax error in calling convention of unit-test utilities
* separate cmake patterns in editorconfig
* clion ignores editorconfig for cmake -> fix inconsistent space-based indentation
* further whitespace fixes
* parameterize stack-overflow integration tests
expose handler stack size as first step where applicable.
---------
Co-authored-by: JoshuaMoelans <[email protected]>
@@ -178,11 +178,23 @@ if(SENTRY_BACKEND_CRASHPAD AND ANDROID)
178
178
endif()
179
179
180
180
set(SENTRY_SDK_NAME ""CACHESTRING"The SDK name to report when sending events.")
181
+
set(SENTRY_HANDLER_STACK_SIZE 64 CACHESTRING"The stack size (in KiB) that should be reserved for the crash handler.")
182
+
if (WIN32)
183
+
set(SENTRY_THREAD_STACK_GUARANTEE_FACTOR 10 CACHESTRING"The factor by which a threads stack should be larger than the stack guarantee for its handler.")
184
+
option(SENTRY_THREAD_STACK_GUARANTEE_AUTO_INIT "Automatically sets the thread stack guarantee for each thread via `DllMain` or for the `sentry_init()` when building statically"ON)
185
+
option(SENTRY_THREAD_STACK_GUARANTEE_VERBOSE_LOG "Enables logging of successfully set thread stack guarantees"OFF)
The following options can be set when running the cmake generator, for example
188
188
using `cmake -D BUILD_SHARED_LIBS=OFF ..`.
189
189
190
-
-`SENTRY_BUILD_SHARED_LIBS` (Default: ON):
190
+
-`SENTRY_BUILD_SHARED_LIBS` (Default: `ON`):
191
191
By default, `sentry` is built as a shared library. Setting this option to
192
192
`OFF` will build `sentry` as a static library instead.
193
193
If sentry is used as a subdirectory of another project, the value `BUILD_SHARED_LIBS` will be inherited by default.
194
194
195
195
When using `sentry` as a static library, make sure to `#define SENTRY_BUILD_STATIC 1` before including the sentry header.
196
196
197
-
-`SENTRY_PIC` (Default: ON):
197
+
-`SENTRY_PIC` (Default: `ON`):
198
198
By default, `sentry` is built as a position-independent library.
199
199
200
-
-`SENTRY_EXPORT_SYMBOLS` (Default: ON):
201
-
By default, `sentry` exposes all symbols in the dynamic symbol table. You might want to disable it if the program intends to `dlopen` third-party shared libraries and avoid symbol collisions.
202
-
203
-
-`SENTRY_BUILD_RUNTIMESTATIC` (Default: OFF):
200
+
-`SENTRY_BUILD_RUNTIMESTATIC` (Default: `OFF`):
204
201
Enables linking with the static MSVC runtime. Has no effect if the compiler is not MSVC.
205
202
206
-
-`SENTRY_LINK_PTHREAD` (Default: ON):
203
+
-`SENTRY_LINK_PTHREAD` (Default: `ON`):
207
204
Links platform threads library like `pthread` on UNIX targets.
208
205
209
-
-`SENTRY_BUILD_FORCE32` (Default: OFF):
206
+
-`SENTRY_BUILD_FORCE32` (Default: `OFF`):
210
207
Forces cross-compilation from 64-bit host to 32-bit target. Only affects Linux.
211
208
212
209
-`CMAKE_SYSTEM_VERSION` (Default: depending on Windows SDK version):
@@ -246,32 +243,58 @@ using `cmake -D BUILD_SHARED_LIBS=OFF ..`.
246
243
-**none**: This builds `sentry-native` without a backend, so it does not handle
247
244
crashes. It is primarily used for tests.
248
245
249
-
-`SENTRY_INTEGRATION_QT` (Default: OFF):
246
+
-`SENTRY_INTEGRATION_QT` (Default: `OFF`):
250
247
Builds the Qt integration, which turns Qt log messages into breadcrumbs.
251
248
252
-
-`SENTRY_BREAKPAD_SYSTEM` (Default: OFF):
249
+
-`SENTRY_BREAKPAD_SYSTEM` (Default: `OFF`):
253
250
This instructs the build system to use system-installed breakpad libraries instead of the in-tree version.
254
251
255
-
-`SENTRY_TRANSPORT_COMPRESSION` (Default: OFF):
252
+
-`SENTRY_TRANSPORT_COMPRESSION` (Default: `OFF`):
256
253
Adds Gzip transport compression. Requires `zlib`.
257
254
258
255
-`SENTRY_FOLDER` (Default: not defined):
259
-
Sets the sentry-native projects folder name for generators that support project hierarchy (like Microsoft Visual Studio).
260
-
To use this feature, you need to enable hierarchy via [`USE_FOLDERS` property](https://cmake.org/cmake/help/latest/prop_gbl/USE_FOLDERS.html)
256
+
Sets the sentry-native projects folder name for generators that support project hierarchy (like Microsoft Visual
257
+
Studio). To use this feature, you need to enable hierarchy via [`USE_FOLDERS` property](https://cmake.org/cmake/help/latest/prop_gbl/USE_FOLDERS.html)
261
258
262
-
-`CRASHPAD_ENABLE_STACKTRACE` (Default: OFF):
263
-
This enables client-side stackwalking when using the crashpad backend. Stack unwinding will happen on the client's machine
264
-
and the result will be submitted to Sentry attached to the generated minidump.
265
-
Note that this feature is still experimental.
259
+
-`CRASHPAD_ENABLE_STACKTRACE` (Default: `OFF`):
260
+
This enables client-side stackwalking when using the crashpad backend. Stack unwinding will happen on the client's
261
+
machine and the result will be submitted to Sentry attached to the generated minidump.**Note that this feature is
262
+
still experimental**.
266
263
267
-
-`SENTRY_SDK_NAME` (Default: sentry.native or sentry.native.android):
264
+
-`SENTRY_SDK_NAME` (Default: `sentry.native` or `sentry.native.android`):
268
265
Sets the SDK name that should be included in the reported events. If you're overriding this, also define
269
266
the same value using `target_compile_definitions()` on your own targets that include `sentry.h`.
270
267
268
+
-`SENTRY_HANDLER_STACK_SIZE` (Default: `64`):
269
+
This specifies the size in KiB of the stack reserved for the crash handler (including hooks like `on_crash` and
270
+
`before_send`) on Windows, Linux and the `inproc` backend in macOS. Reserving the stack is necessary in case of a
271
+
stack-overflow, where the handler could otherwise no longer execute. This parameter allows users to specify their
272
+
target stack size in KiB, because some applications might require a different value from our default. This value can
273
+
be as small as 16KiB (on `crashpad` and `breakpad`) for handlers to work, but we recommend 32KiB as the lower bound
274
+
on 64-bit systems. **The value should be a multiple of the page size**.
275
+
276
+
-`SENTRY_THREAD_STACK_GUARANTEE_FACTOR` (Default: `10`, only for Windows):
277
+
Defines the factor by which the thread's stack reserve must be bigger than the specified guarantee for the handler.
278
+
_Example_: if the `SENTRY_HANDLER_STACK_SIZE` is defined as 64KiB then the thread's stack reserve must at least have
279
+
a size of 640KiB.
280
+
-`SENTRY_THREAD_STACK_GUARANTEE_AUTO_INIT` (Default: `ON`, only for Windows):
281
+
Ensures that all threads created after the SDK's initialization will be configured to use the
282
+
`SENTRY_HANDLER_STACK_SIZE` as its handler stack guarantee.
283
+
284
+
_Note_: assigning this to all threads only works when building the SDK as a shared library. If you build it as a
285
+
static library and this option is enabled, only the `sentry_init()` thread will have a stack guarantee for the handler
286
+
(other threads must be manually initialized via `sentry_set_thread_stack_guarantee()`).
287
+
288
+
-`SENTRY_THREAD_STACK_GUARANTEE_VERBOSE_LOG` (Default: `OFF`, only for Windows):
289
+
Adds info level logs for every successfully set thread stack guarantee. This is `OFF` by default, because depending
290
+
on the number of threads used (by all dependencies) this could flood the logs. But it will be helpful to anyone
291
+
tuning the thread stack guarantee parameters. Warnings and errors in the process of setting thread stack guarantees
292
+
will always be logged.
293
+
271
294
### Support Matrix
272
295
273
296
| Feature | Windows | macOS | Linux | Android | iOS |
0 commit comments