A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Handle core dumps during instantiation (#15174)
Alex Crichton0ad712ca16a0
diff --git a/src/commands/run.rs b/src/commands/run.rsindex 92183001b2..200a46b0c2 100644--- a/src/commands/run.rs+++ b/src/commands/run.rs@@ -723,16 +723,16 @@ impl RunCommand {let instance = linker.instantiate_async(&mut *store, &module).await- .with_context(|| {- format!("failed to instantiate {:?}", self.module_and_args[0])- })?;+ .with_context(|| format!("failed to instantiate {:?}", self.module_and_args[0]))+ .map_err(|e| self.handle_core_dump(&mut *store, e))?;// If `_initialize` is present, meaning a reactor, then invoke// the function.if let Some(func) = instance.get_func(&mut *store, "_initialize") {func.typed::<(), ()>(&store)?.call_async(&mut *store, ())- .await?;+ .await+ .map_err(|e| self.handle_core_dump(&mut *store, e))?;}// Look for the specific function provided or otherwise look fordiff --git a/tests/all/cli_tests.rs b/tests/all/cli_tests.rsindex 799f3e927b..efc545e5c2 100644--- a/tests/all/cli_tests.rs+++ b/tests/all/cli_tests.rs@@ -104,6 +104,23 @@ fn run_coredump_smoketest() -> Result<()> {Ok(())}+#[test]+fn run_coredump_during_instantiation() -> Result<()> {+ let coredump_file = NamedTempFile::new()?;+ let coredump_arg = format!("-Dcoredump={}", coredump_file.path().display());+ let err = run_wasmtime(&[+ "run",+ &coredump_arg,+ "tests/all/cli_tests/coredump_start_trap.wat",+ ])+ .unwrap_err();+ assert!(err.to_string().contains(&format!(+ "core dumped at {}",+ coredump_file.path().display()+ )));+ Ok(())+}+// Running simple wat#[test]fn run_wasmtime_simple_wat() -> Result<()> {diff --git a/tests/all/cli_tests/coredump_start_trap.wat b/tests/all/cli_tests/coredump_start_trap.watnew file mode 100644index 0000000000..d2b343dd95--- /dev/null+++ b/tests/all/cli_tests/coredump_start_trap.wat@@ -0,0 +1,6 @@+(module+ (func $start+ unreachable+ )+ (start $start)+)