diff --git a/src/TrapException.cs b/src/TrapException.cs index ac910e7..55b526f 100644 --- a/src/TrapException.cs +++ b/src/TrapException.cs @@ -47,9 +47,9 @@ public class TrapFrame { unsafe internal TrapFrame(IntPtr frame) { - FunctionOffset = (int)Native.wasm_frame_func_offset(frame); + FunctionOffset = (nuint)Native.wasm_frame_func_offset(frame); FunctionName = null; - ModuleOffset = (int)Native.wasm_frame_module_offset(frame); + ModuleOffset = (nuint)Native.wasm_frame_module_offset(frame); ModuleName = null; var bytes = Native.wasmtime_frame_func_name(frame); @@ -68,7 +68,7 @@ unsafe internal TrapFrame(IntPtr frame) /// /// Gets the frame's byte offset from the start of the function. /// - public int FunctionOffset { get; private set; } + public nuint FunctionOffset { get; private set; } /// /// Gets the frame's function name. @@ -78,7 +78,7 @@ unsafe internal TrapFrame(IntPtr frame) /// /// Gets the frame's module offset from the start of the module. /// - public int ModuleOffset { get; private set; } + public nuint ModuleOffset { get; private set; } /// /// Gets the frame's module name. diff --git a/tests/Modules/Trap.wat b/tests/Modules/Trap.wat index f3015bc..a9fd2af 100644 --- a/tests/Modules/Trap.wat +++ b/tests/Modules/Trap.wat @@ -1,5 +1,9 @@ (module (export "run" (func $run)) + (export "run_div_zero" (func $run_div_zero)) + (export "run_div_zero_with_result" (func $run_div_zero_with_result)) + (export "run_stack_overflow" (func $run_stack_overflow)) + (func $run (call $first) ) @@ -12,4 +16,19 @@ (func $third unreachable ) + + (func $run_div_zero_with_result (result i32) + (i32.const 1) + (i32.const 0) + (i32.div_s) + ) + + (func $run_div_zero + (call $run_div_zero_with_result) + (drop) + ) + + (func $run_stack_overflow + (call $run_stack_overflow) + ) ) diff --git a/tests/TrapTests.cs b/tests/TrapTests.cs index 5785ef6..a95a192 100644 --- a/tests/TrapTests.cs +++ b/tests/TrapTests.cs @@ -46,6 +46,22 @@ public void ItIncludesAStackTrace() .WithMessage("wasm trap: wasm `unreachable` instruction executed*"); } + [Fact] + public void ItCatchesAStackOverflow() + { + Action action = () => + { + var instance = Linker.Instantiate(Store, Fixture.Module); + var run = instance.GetAction("run_stack_overflow"); + run.Should().NotBeNull(); + run(); + }; + + action + .Should() + .Throw(); + } + public void Dispose() { Store.Dispose();