Add well placed unwind(allowed) attribute

This commit is contained in:
Lachlan Sneff
2019-04-11 12:07:54 -07:00
parent 81fcecd705
commit c898439817
7 changed files with 20 additions and 5 deletions

2
Cargo.lock generated
View File

@ -2274,6 +2274,7 @@ dependencies = [
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
"nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-runtime-core 0.2.1", "wasmer-runtime-core 0.2.1",
"wasmparser 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)", "wasmparser 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -2372,6 +2373,7 @@ dependencies = [
"nix 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"page_size 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "page_size 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
"serde-bench 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "serde-bench 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_bytes 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_bytes 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -75,10 +75,12 @@ extern "C" {
fn module_delete(module: *mut LLVMModule); fn module_delete(module: *mut LLVMModule);
fn get_func_symbol(module: *mut LLVMModule, name: *const c_char) -> *const vm::Func; fn get_func_symbol(module: *mut LLVMModule, name: *const c_char) -> *const vm::Func;
fn throw_trap(ty: i32) -> !; fn throw_trap(ty: i32);
/// This should be the same as spliting up the fat pointer into two arguments, /// This should be the same as spliting up the fat pointer into two arguments,
/// but this is cleaner, I think? /// but this is cleaner, I think?
#[cfg_attr(nightly, unwind(allowed))]
#[allow(improper_ctypes)]
fn throw_any(data: *mut dyn Any) -> !; fn throw_any(data: *mut dyn Any) -> !;
#[allow(improper_ctypes)] #[allow(improper_ctypes)]
@ -438,7 +440,7 @@ impl ProtectedCaller for LLVMProtectedCaller {
impl UserTrapper for Placeholder { impl UserTrapper for Placeholder {
unsafe fn do_early_trap(&self, data: Box<dyn Any>) -> ! { unsafe fn do_early_trap(&self, data: Box<dyn Any>) -> ! {
throw_any(Box::leak(data)) throw_any(Box::leak(data));
} }
} }

View File

@ -45,6 +45,7 @@ field-offset = "0.1.1"
[build-dependencies] [build-dependencies]
blake2b_simd = "0.4.1" blake2b_simd = "0.4.1"
rustc_version = "0.2.3"
[features] [features]
debug = [] debug = []

View File

@ -23,4 +23,9 @@ fn main() {
f_out f_out
.write_all(hash_string.as_bytes()) .write_all(hash_string.as_bytes())
.expect("Could not write to file for wasmer hash value"); .expect("Could not write to file for wasmer hash value");
// Enable "nightly" cfg if the current compiler is nightly.
if rustc_version::version_meta().unwrap().channel == rustc_version::Channel::Nightly {
println!("cargo:rustc-cfg=nightly");
}
} }

View File

@ -1,3 +1,5 @@
#![cfg_attr(nightly, feature(unwind_attributes))]
#[cfg(test)] #[cfg(test)]
#[macro_use] #[macro_use]
extern crate field_offset; extern crate field_offset;

View File

@ -339,11 +339,14 @@ macro_rules! impl_traits {
fn to_raw(&self) -> NonNull<vm::Func> { fn to_raw(&self) -> NonNull<vm::Func> {
assert_eq!(mem::size_of::<Self>(), 0, "you cannot use a closure that captures state for `Func`."); assert_eq!(mem::size_of::<Self>(), 0, "you cannot use a closure that captures state for `Func`.");
/// This is required for the llvm backend to be able to unwind through this function.
#[cfg_attr(nightly, unwind(allowed))]
extern fn wrap<$( $x: WasmExternType, )* Rets: WasmTypeList, Trap: TrapEarly<Rets>, FN: Fn( &mut Ctx $( ,$x )* ) -> Trap>( ctx: &mut Ctx $( ,$x: $x )* ) -> Rets::CStruct { extern fn wrap<$( $x: WasmExternType, )* Rets: WasmTypeList, Trap: TrapEarly<Rets>, FN: Fn( &mut Ctx $( ,$x )* ) -> Trap>( ctx: &mut Ctx $( ,$x: $x )* ) -> Rets::CStruct {
let f: FN = unsafe { mem::transmute_copy(&()) }; let f: FN = unsafe { mem::transmute_copy(&()) };
let err = match panic::catch_unwind(panic::AssertUnwindSafe(|| { let err = match panic::catch_unwind(panic::AssertUnwindSafe(|| {
f( ctx $( ,$x )* ).report() let res = f( ctx $( ,$x )* ).report();
res
})) { })) {
Ok(Ok(returns)) => return returns.into_c_struct(), Ok(Ok(returns)) => return returns.into_c_struct(),
Ok(Err(err)) => err, Ok(Err(err)) => err,

View File

@ -59,9 +59,9 @@ fn main() -> Result<(), error::Error> {
}, },
})?; })?;
let foo: Func<(), i32> = instance.func("dbz")?; let foo = instance.dyn_func("dbz")?;
let result = foo.call(); let result = foo.call(&[]);
println!("result: {:?}", result); println!("result: {:?}", result);