From b391817c0fbfc8f05ca8f80f912c1d3a8099bf2f Mon Sep 17 00:00:00 2001 From: Peter Huene Date: Mon, 6 Jul 2020 14:17:42 -0700 Subject: [PATCH] Add a test case for unwind with saved FPRs on Windows. This commit adds a simple test case that reproduces the problem in --- tests/all/cli_tests.rs | 11 ++++++++ tests/wasm/exit_with_saved_fprs.wat | 40 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/wasm/exit_with_saved_fprs.wat diff --git a/tests/all/cli_tests.rs b/tests/all/cli_tests.rs index 41a0e155adc3..5c825cd59040 100644 --- a/tests/all/cli_tests.rs +++ b/tests/all/cli_tests.rs @@ -350,3 +350,14 @@ fn greeter_preload_callable_command() -> Result<()> { assert_eq!(stdout, "Hello _start\nHello callable greet\nHello done\n"); Ok(()) } + +// Ensure successful WASI exit call with FPR saving frames on stack for Windows x64 +// See https://github.com/bytecodealliance/wasmtime/issues/1967 +#[test] +fn exit_with_saved_fprs() -> Result<()> { + let wasm = build_wasm("tests/wasm/exit_with_saved_fprs.wat")?; + let output = run_wasmtime_for_output(&[wasm.path().to_str().unwrap(), "--disable-cache"])?; + assert_eq!(output.status.code().unwrap(), 0); + assert!(output.stdout.is_empty()); + Ok(()) +} diff --git a/tests/wasm/exit_with_saved_fprs.wat b/tests/wasm/exit_with_saved_fprs.wat new file mode 100644 index 000000000000..6149c6bdf2a9 --- /dev/null +++ b/tests/wasm/exit_with_saved_fprs.wat @@ -0,0 +1,40 @@ +;;; This is a test case for https://github.com/bytecodealliance/wasmtime/issues/1967 +(module + (type (func (param i32))) + + (import "wasi_snapshot_preview1" "proc_exit" (func (type 0))) + + (func $exit (param i32) + local.get 0 + call 0 + unreachable + ) + + (func $do_something (param f64 f64 f64 f64 f64 f64 f64 f64) + i32.const 0 + call $exit + unreachable + ) + + (func $has_saved_fprs (export "_start") + (local f64 f64 f64 f64 f64 f64 f64 f64) + (local.set 0 (f64.const 1)) + (local.set 1 (f64.const 2)) + (local.set 2 (f64.const 3)) + (local.set 3 (f64.const 4)) + (local.set 4 (f64.const 5)) + (local.set 5 (f64.const 6)) + (local.set 6 (f64.const 7)) + (local.set 7 (f64.const 8)) + local.get 0 + local.get 1 + local.get 2 + local.get 3 + local.get 4 + local.get 5 + local.get 6 + local.get 7 + call $do_something + unreachable + ) +)