Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -Wasync-stack-size, automatically configure it too #9302

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,25 @@ gc = ["wasmtime-cli-flags/gc"]

# CLI subcommands for the `wasmtime` executable. See `wasmtime $cmd --help`
# for more information on each subcommand.
serve = ["wasi-http", "component-model", "dep:http-body-util", "dep:http"]
serve = [
"wasi-http",
"component-model",
"dep:http-body-util",
"dep:http",
"wasmtime-cli-flags/async",
]
explore = ["dep:wasmtime-explorer", "dep:tempfile"]
wast = ["dep:wasmtime-wast"]
config = ["cache"]
compile = ["cranelift"]
run = ["dep:wasmtime-wasi", "wasmtime/runtime", "dep:listenfd", "dep:wasi-common", "dep:tokio"]
run = [
"dep:wasmtime-wasi",
"wasmtime/runtime",
"dep:listenfd",
"dep:wasi-common",
"dep:tokio",
"wasmtime-cli-flags/async",
]

[[test]]
name = "host_segfault"
Expand Down
21 changes: 21 additions & 0 deletions crates/cli-flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ wasmtime_option_group! {
/// Maximum stack size, in bytes, that wasm is allowed to consume before a
/// stack overflow is reported.
pub max_wasm_stack: Option<usize>,
/// Stack size, in bytes, that will be allocated for async stacks.
///
/// Note that this must be larger than `max-wasm-stack` and the
/// difference between the two is how much stack the host has to execute
/// on.
pub async_stack_size: Option<usize>,
/// Allow unknown exports when running commands.
pub unknown_exports_allow: Option<bool>,
/// Allow the main module to import unknown functions, using an
Expand Down Expand Up @@ -658,8 +664,23 @@ impl CommonOptions {
anyhow::bail!("memory protection keys require the pooling allocator");
}

match_feature! {
["async" : self.wasm.async_stack_size]
size => config.async_stack_size(size),
_ => err,
}

if let Some(max) = self.wasm.max_wasm_stack {
config.max_wasm_stack(max);

// If `-Wasync-stack-size` isn't passed then automatically adjust it
// to the wasm stack size provided here too. That prevents the need
// to pass both when one can generally be inferred from the other.
#[cfg(feature = "async")]
if self.wasm.async_stack_size.is_none() {
const DEFAULT_HOST_STACK: usize = 512 << 10;
config.async_stack_size(max + DEFAULT_HOST_STACK);
}
}

if let Some(enable) = self.wasm.relaxed_simd_deterministic {
Expand Down
15 changes: 15 additions & 0 deletions tests/all/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,21 @@ fn mpk_without_pooling() -> Result<()> {
Ok(())
}

// Very basic use case: compile binary wasm file and run specific function with arguments.
#[test]
fn increase_stack_size() -> Result<()> {
run_wasmtime(&[
"run",
"--invoke",
"simple",
&format!("-Wmax-wasm-stack={}", 5 << 20),
"-Ccache=n",
"tests/all/cli_tests/simple.wat",
"4",
])?;
Ok(())
}

mod test_programs {
use super::{get_wasmtime_command, run_wasmtime};
use anyhow::{bail, Context, Result};
Expand Down