feat(runtime-core) Replace missing host function by always_trap.

This commit is contained in:
Ivan Enderlin 2020-01-09 15:12:09 +01:00
parent 6018aa32e1
commit c81e49a091
2 changed files with 18 additions and 12 deletions

View File

@ -8,6 +8,7 @@ use crate::{
sig_registry::SigRegistry,
structures::{BoxedMap, Map, SliceMap, TypedIndex},
table::Table,
typed_func::{always_trap, Func},
types::{
ImportedFuncIndex, ImportedGlobalIndex, ImportedMemoryIndex, ImportedTableIndex,
Initializer, LocalFuncIndex, LocalGlobalIndex, LocalMemoryIndex, LocalOrImport,
@ -15,11 +16,7 @@ use crate::{
},
vm,
};
use std::{
fmt::Debug,
ptr::{self, NonNull},
slice,
};
use std::{fmt::Debug, ptr::NonNull, slice};
/// Size of the array for internal instance usage
pub const INTERNALS_SIZE: usize = 256;
@ -652,9 +649,18 @@ fn import_functions(
}
None => {
if imports.allow_missing_functions {
let always_trap = Func::new(always_trap);
functions.push(vm::ImportedFunc {
func: ptr::null(),
func_ctx: unsafe { NonNull::new_unchecked(ptr::null_mut()) }, // TODO: Non-sense…
func: always_trap.get_vm_func().as_ptr(),
func_ctx: NonNull::new(Box::into_raw(Box::new(vm::FuncCtx {
// ^^^^^^^^ `vm::FuncCtx` is purposely leaked.
// It is dropped by the specific `Drop`
// implementation of `ImportBacking`.
vmctx: NonNull::new(vmctx).expect("`vmctx` must not be null."),
func_env: None,
})))
.unwrap(),
});
} else {
link_errors.push(LinkError::ImportNotFound {

View File

@ -258,11 +258,6 @@ where
_phantom: PhantomData,
}
}
/// Get the underlying func pointer.
pub fn get_vm_func(&self) -> NonNull<vm::Func> {
self.func
}
}
impl<'a, Args, Rets> Func<'a, Args, Rets, Host>
@ -303,6 +298,11 @@ where
pub fn returns(&self) -> &'static [Type] {
Rets::types()
}
/// Get the underlying func pointer.
pub fn get_vm_func(&self) -> NonNull<vm::Func> {
self.func
}
}
impl WasmTypeList for Infallible {