From 84994203a165e4e869ccdd4b7917b26ce88488bc Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 26 Sep 2022 17:48:26 -0500 Subject: [PATCH] Increase the `sigaltstack` stack size (#4964) This commit updates the `MIN_STACK_SIZE` constant for Unix platforms when allocating a sigaltstack from 16k to 64k. The signal handler captures a wasm `Backtrace` which involves memory allocations and it was recently discovered that, at least in debug mode, jemalloc can take up to 16k of stack space for an allocation. To allow running the sigaltstack size is increased here. --- crates/runtime/src/traphandlers/unix.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/runtime/src/traphandlers/unix.rs b/crates/runtime/src/traphandlers/unix.rs index ef40b8c2c3..445646e6a5 100644 --- a/crates/runtime/src/traphandlers/unix.rs +++ b/crates/runtime/src/traphandlers/unix.rs @@ -286,7 +286,14 @@ pub fn lazy_per_thread_init() { /// The size of the sigaltstack (not including the guard, which will be /// added). Make this large enough to run our signal handlers. - const MIN_STACK_SIZE: usize = 16 * 4096; + /// + /// The main current requirement of the signal handler in terms of stack + /// space is that `malloc`/`realloc` are called to create a `Backtrace` of + /// wasm frames. + /// + /// Historically this was 16k. Turns out jemalloc requires more than 16k of + /// stack space in debug mode, so this was bumped to 64k. + const MIN_STACK_SIZE: usize = 64 * 4096; struct Stack { mmap_ptr: *mut libc::c_void,