mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-16 17:18:57 +00:00
WIP checkpoint. Code that builds.
Use Option<VMTrampoline> which should be ffi-compatible. Put the register_signature and lookup_signature functions back on the Engine.
This commit is contained in:
28
lib/api/src/externals/function.rs
vendored
28
lib/api/src/externals/function.rs
vendored
@@ -10,18 +10,9 @@ use std::cell::RefCell;
|
||||
use std::cmp::max;
|
||||
use std::fmt;
|
||||
use wasmer_vm::{
|
||||
raise_user_trap,
|
||||
resume_panic,
|
||||
wasmer_call_trampoline,
|
||||
Export,
|
||||
ExportFunction,
|
||||
VMCallerCheckedAnyfunc,
|
||||
VMContext,
|
||||
VMDynamicFunctionContext,
|
||||
VMFunctionBody,
|
||||
VMFunctionKind,
|
||||
VMSharedSignatureIndex,
|
||||
VMTrampoline,
|
||||
raise_user_trap, resume_panic, wasmer_call_trampoline, Export, ExportFunction,
|
||||
VMCallerCheckedAnyfunc, VMContext, VMDynamicFunctionContext, VMFunctionBody, VMFunctionKind,
|
||||
VMSharedSignatureIndex, VMTrampoline,
|
||||
};
|
||||
|
||||
/// A function defined in the Wasm module
|
||||
@@ -104,7 +95,7 @@ impl Function {
|
||||
kind: VMFunctionKind::Dynamic,
|
||||
vmctx,
|
||||
signature: ty.clone(),
|
||||
trampoline: std::ptr::null_mut(),
|
||||
trampoline: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -154,7 +145,7 @@ impl Function {
|
||||
kind: VMFunctionKind::Dynamic,
|
||||
vmctx,
|
||||
signature: ty.clone(),
|
||||
trampoline: std::ptr::null(),
|
||||
trampoline: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -196,7 +187,7 @@ impl Function {
|
||||
vmctx,
|
||||
signature,
|
||||
kind: VMFunctionKind::Static,
|
||||
trampoline: std::ptr::null(),
|
||||
trampoline: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -250,7 +241,7 @@ impl Function {
|
||||
kind: VMFunctionKind::Static,
|
||||
vmctx,
|
||||
signature,
|
||||
trampoline: std::ptr::null(),
|
||||
trampoline: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -314,7 +305,7 @@ impl Function {
|
||||
if let Err(error) = unsafe {
|
||||
wasmer_call_trampoline(
|
||||
self.exported.vmctx,
|
||||
*func.trampoline,
|
||||
func.trampoline,
|
||||
self.exported.address,
|
||||
values_vec.as_mut_ptr() as *mut u8,
|
||||
)
|
||||
@@ -364,9 +355,10 @@ impl Function {
|
||||
}
|
||||
|
||||
pub(crate) fn from_export(store: &Store, wasmer_export: ExportFunction) -> Self {
|
||||
let trampoline = wasmer_export.trampoline.unwrap();
|
||||
Self {
|
||||
store: store.clone(),
|
||||
definition: FunctionDefinition::Wasm(WasmFunctionDefinition { trampoline: wasmer_export.trampoline }),
|
||||
definition: FunctionDefinition::Wasm(WasmFunctionDefinition { trampoline }),
|
||||
exported: wasmer_export,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ where
|
||||
vmctx: other.vmctx,
|
||||
signature,
|
||||
kind: other.arg_kind,
|
||||
trampoline: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,6 +89,7 @@ where
|
||||
vmctx: other.vmctx,
|
||||
signature,
|
||||
kind: other.arg_kind,
|
||||
trampoline: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ impl ValFuncRef for Val {
|
||||
// are converted to use the trampolines with static signatures).
|
||||
kind: wasmer_vm::VMFunctionKind::Static,
|
||||
vmctx: item.vmctx,
|
||||
trampoline: None,
|
||||
};
|
||||
let f = Function::from_export(store, export);
|
||||
Val::FuncRef(f)
|
||||
|
||||
@@ -338,7 +338,8 @@ impl NativeArtifact {
|
||||
metadata,
|
||||
library: None,
|
||||
finished_functions: finished_functions.into_boxed_slice(),
|
||||
finished_function_call_trampolines: finished_function_call_trampolines.into_boxed_slice(),
|
||||
finished_function_call_trampolines: finished_function_call_trampolines
|
||||
.into_boxed_slice(),
|
||||
finished_dynamic_function_trampolines: finished_dynamic_function_trampolines
|
||||
.into_boxed_slice(),
|
||||
signatures: signatures.into_boxed_slice(),
|
||||
@@ -390,11 +391,14 @@ impl NativeArtifact {
|
||||
}
|
||||
|
||||
// Retrieve function call trampolines
|
||||
let mut finished_function_call_trampolines: PrimaryMap<SignatureIndex, VMTrampoline> = PrimaryMap::with_capacity(metadata.compile_info.module.signatures.len());
|
||||
let mut finished_function_call_trampolines: PrimaryMap<SignatureIndex, VMTrampoline> =
|
||||
PrimaryMap::with_capacity(metadata.compile_info.module.signatures.len());
|
||||
for sig_index in metadata.compile_info.module.signatures.keys() {
|
||||
let function_name = metadata.symbol_to_name(Symbol::FunctionCallTrampoline(sig_index));
|
||||
unsafe {
|
||||
let trampoline: LibrarySymbol<VMTrampoline> = lib.get(function_name.as_bytes()).map_err(to_compile_error)?;
|
||||
let trampoline: LibrarySymbol<VMTrampoline> = lib
|
||||
.get(function_name.as_bytes())
|
||||
.map_err(to_compile_error)?;
|
||||
let raw = *trampoline.into_raw();
|
||||
finished_function_call_trampolines.push(raw);
|
||||
}
|
||||
@@ -454,7 +458,8 @@ impl NativeArtifact {
|
||||
metadata,
|
||||
library: Some(lib),
|
||||
finished_functions: finished_functions.into_boxed_slice(),
|
||||
finished_function_call_trampolines: finished_function_call_trampolines.into_boxed_slice(),
|
||||
finished_function_call_trampolines: finished_function_call_trampolines
|
||||
.into_boxed_slice(),
|
||||
finished_dynamic_function_trampolines: finished_dynamic_function_trampolines
|
||||
.into_boxed_slice(),
|
||||
signatures: signatures.into_boxed_slice(),
|
||||
|
||||
@@ -123,7 +123,6 @@ impl Engine for NativeEngine {
|
||||
&self.target
|
||||
}
|
||||
|
||||
/*
|
||||
/// Register a signature
|
||||
fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex {
|
||||
let compiler = self.inner();
|
||||
@@ -136,6 +135,7 @@ impl Engine for NativeEngine {
|
||||
compiler.signatures().lookup(sig)
|
||||
}
|
||||
|
||||
/*
|
||||
/// Retrieves a trampoline given a signature
|
||||
fn function_call_trampoline(&self, sig: VMSharedSignatureIndex) -> Option<VMTrampoline> {
|
||||
self.inner().trampoline(sig)
|
||||
|
||||
@@ -19,13 +19,13 @@ pub trait Engine {
|
||||
/// Gets the target
|
||||
fn target(&self) -> &Target;
|
||||
|
||||
/*
|
||||
/// Register a signature
|
||||
fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex;
|
||||
|
||||
/// Lookup a signature
|
||||
fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option<FunctionType>;
|
||||
|
||||
/*
|
||||
/// Retrieves a trampoline given a signature
|
||||
fn function_call_trampoline(&self, sig: VMSharedSignatureIndex) -> Option<VMTrampoline>;
|
||||
*/
|
||||
|
||||
@@ -35,8 +35,8 @@ pub struct ExportFunction {
|
||||
pub signature: FunctionType,
|
||||
/// The function kind (it defines how it's the signature that provided `address` have)
|
||||
pub kind: VMFunctionKind,
|
||||
/// Address of the function call trampoline owned by the same VMContext that owns the VMFunctionBody. May be nullptr when FunctionType == Dynamic or vmctx == nullptr.
|
||||
pub trampoline: VMTrampoline,
|
||||
/// Address of the function call trampoline owned by the same VMContext that owns the VMFunctionBody. May be None when FunctionType == Dynamic or vmctx == nullptr.
|
||||
pub trampoline: Option<VMTrampoline>,
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
|
||||
@@ -301,7 +301,7 @@ impl Instance {
|
||||
let import = self.imported_function(*index);
|
||||
(import.body, import.vmctx)
|
||||
};
|
||||
let trampoline = self.function_call_trampolines[*sig_index];
|
||||
let trampoline = Some(self.function_call_trampolines[*sig_index]);
|
||||
let signature = self.module.signatures[*sig_index].clone();
|
||||
ExportFunction {
|
||||
address,
|
||||
|
||||
Reference in New Issue
Block a user