mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-28 08:01:33 +00:00
Fix trap handling bug on Windows and add test
This commit is contained in:
21
lib/runtime-core-tests/tests/exception_handling.rs
Normal file
21
lib/runtime-core-tests/tests/exception_handling.rs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
use wasmer_runtime_core::{compile_with, imports};
|
||||||
|
use wasmer_runtime_core_tests::{get_compiler, wat2wasm};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn exception_handling_works() {
|
||||||
|
const MODULE: &str = r#"
|
||||||
|
(module
|
||||||
|
(func (export "throw_trap")
|
||||||
|
unreachable
|
||||||
|
))
|
||||||
|
"#;
|
||||||
|
|
||||||
|
let wasm_binary = wat2wasm(MODULE.as_bytes()).expect("WAST not valid or malformed");
|
||||||
|
let module = compile_with(&wasm_binary, &get_compiler()).unwrap();
|
||||||
|
|
||||||
|
let imports = imports! {};
|
||||||
|
for _ in 0..2 {
|
||||||
|
let instance = module.instantiate(&imports).unwrap();
|
||||||
|
assert!(instance.call("throw_trap", &[]).is_err());
|
||||||
|
}
|
||||||
|
}
|
@ -59,6 +59,7 @@ uint8_t callProtected(trampoline_t trampoline,
|
|||||||
// install exception handler
|
// install exception handler
|
||||||
if (exceptionHandlerInstalled == FALSE) {
|
if (exceptionHandlerInstalled == FALSE) {
|
||||||
exceptionHandlerInstalled = TRUE;
|
exceptionHandlerInstalled = TRUE;
|
||||||
|
alreadyHandlingException = FALSE;
|
||||||
handle = AddVectoredExceptionHandler(CALL_FIRST, exceptionHandler);
|
handle = AddVectoredExceptionHandler(CALL_FIRST, exceptionHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,4 +87,4 @@ uint8_t callProtected(trampoline_t trampoline,
|
|||||||
|
|
||||||
removeExceptionHandler();
|
removeExceptionHandler();
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user