Check the types of values returned by Callable (#876)

If the values mismatch to the ones that were specified by the
signature of the callable, raise a trap!
This commit is contained in:
Sergei Pepyakin
2020-01-30 21:11:41 +01:00
committed by GitHub
parent eb183d7ab3
commit f2382db461
2 changed files with 58 additions and 1 deletions

View File

@@ -129,8 +129,15 @@ unsafe extern "C" fn stub_fn(
.downcast_ref::<TrampolineState>()
.expect("state");
state.func.call(&args, &mut returns)?;
let module = instance.module_ref();
let signature = &module.signatures[module.functions[FuncIndex::new(call_id as usize)]];
for (i, ret) in returns.iter_mut().enumerate() {
// TODO check signature.returns[i].value_type ?
if ret.ty().get_wasmtime_type() != Some(signature.returns[i].value_type) {
return Err(Trap::new(
"`Callable` attempted to return an incompatible value",
));
}
ret.write_value_to(values_vec.add(i));
}
Ok(())