feat: add a knob for reset stack (#4813)

* feat: add a knob for reset stack

* Touch up documentation of `async_stack_zeroing`

Co-authored-by: Alex Crichton <alex@alexcrichton.com>
This commit is contained in:
Xuran
2022-09-02 00:09:46 +08:00
committed by GitHub
parent c54d8384ee
commit bca4dae8b0
4 changed files with 92 additions and 8 deletions

View File

@@ -109,6 +109,7 @@ pub struct Config {
pub(crate) memory_init_cow: bool,
pub(crate) memory_guaranteed_dense_image_size: u64,
pub(crate) force_memory_init_memfd: bool,
pub(crate) async_stack_zeroing: bool,
}
/// User-provided configuration for the compiler.
@@ -196,6 +197,7 @@ impl Config {
memory_init_cow: true,
memory_guaranteed_dense_image_size: 16 << 20,
force_memory_init_memfd: false,
async_stack_zeroing: false,
};
#[cfg(compiler)]
{
@@ -341,6 +343,35 @@ impl Config {
self
}
/// Configures whether or not stacks used for async futures are reset to
/// zero after usage.
///
/// When the [`async_support`](Config::async_support) method is enabled for
/// Wasmtime and the [`call_async`] variant
/// of calling WebAssembly is used then Wasmtime will create a separate
/// runtime execution stack for each future produced by [`call_async`].
/// When using the pooling instance allocator
/// ([`InstanceAllocationStrategy::Pooling`]) this allocation will happen
/// from a pool of stacks and additionally deallocation will simply release
/// the stack back to the pool. During the deallocation process Wasmtime
/// won't by default reset the contents of the stack back to zero.
///
/// When this option is enabled it can be seen as a defense-in-depth
/// mechanism to reset a stack back to zero. This is not required for
/// correctness and can be a costly operation in highly concurrent
/// environments due to modifications of the virtual address space requiring
/// process-wide synchronization.
///
/// This option defaults to `false`.
///
/// [`call_async`]: crate::TypedFunc::call_async
#[cfg(feature = "async")]
#[cfg_attr(nightlydoc, doc(cfg(feature = "async")))]
pub fn async_stack_zeroing(&mut self, enable: bool) -> &mut Self {
self.async_stack_zeroing = enable;
self
}
/// Configures whether DWARF debug information will be emitted during
/// compilation.
///
@@ -1432,6 +1463,7 @@ impl Config {
instance_limits,
stack_size,
&self.tunables,
self.async_stack_zeroing,
)?)),
}
}