Skip to content

Trap Stackoverflow Test #152

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions src/TrapException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -68,7 +68,7 @@ unsafe internal TrapFrame(IntPtr frame)
/// <summary>
/// Gets the frame's byte offset from the start of the function.
/// </summary>
public int FunctionOffset { get; private set; }
public nuint FunctionOffset { get; private set; }

/// <summary>
/// Gets the frame's function name.
Expand All @@ -78,7 +78,7 @@ unsafe internal TrapFrame(IntPtr frame)
/// <summary>
/// Gets the frame's module offset from the start of the module.
/// </summary>
public int ModuleOffset { get; private set; }
public nuint ModuleOffset { get; private set; }

/// <summary>
/// Gets the frame's module name.
Expand Down
19 changes: 19 additions & 0 deletions tests/Modules/Trap.wat
Original file line number Diff line number Diff line change
@@ -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)
)
Expand All @@ -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)
)
)
16 changes: 16 additions & 0 deletions tests/TrapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TrapException>();
}

public void Dispose()
{
Store.Dispose();
Expand Down