mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-21 18:40:51 +00:00
Implementation Notes: - To avoid setjmp, longjmp, and the mess that those create, we instead set the interrupting context of the signal handler to return into the `throw_trap` routine. To my surprise, this actually works. The stack ends up getting unwound normally and the memory-oob error is caught by the trampoline.
39 lines
771 B
Rust
39 lines
771 B
Rust
use wasmer_runtime::{compile, error, imports, Func, Value};
|
|
|
|
use wabt::wat2wasm;
|
|
|
|
static WAT: &'static str = r#"
|
|
(module
|
|
(memory 1)
|
|
(type (;0;) (func (param i32) (result i32)))
|
|
(func (;0;) (type 0) (param i32) (result i32)
|
|
i32.const 0x20000
|
|
i32.load
|
|
)
|
|
(export "select_trap_l" (func 0))
|
|
)
|
|
"#;
|
|
|
|
fn get_wasm() -> Vec<u8> {
|
|
wat2wasm(WAT).unwrap()
|
|
}
|
|
|
|
fn main() -> Result<(), error::Error> {
|
|
let wasm = get_wasm();
|
|
|
|
let module = compile(&wasm)?;
|
|
|
|
let imports = imports! {};
|
|
|
|
println!("instantiating");
|
|
let instance = module.instantiate(&imports)?;
|
|
|
|
let foo = instance.dyn_func("select_trap_l")?;
|
|
|
|
let result = foo.call(&[Value::I32(0)]);
|
|
|
|
println!("result: {:?}", result);
|
|
|
|
Ok(())
|
|
}
|