mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-18 06:19:12 +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::cmp::max;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use wasmer_vm::{
|
use wasmer_vm::{
|
||||||
raise_user_trap,
|
raise_user_trap, resume_panic, wasmer_call_trampoline, Export, ExportFunction,
|
||||||
resume_panic,
|
VMCallerCheckedAnyfunc, VMContext, VMDynamicFunctionContext, VMFunctionBody, VMFunctionKind,
|
||||||
wasmer_call_trampoline,
|
VMSharedSignatureIndex, VMTrampoline,
|
||||||
Export,
|
|
||||||
ExportFunction,
|
|
||||||
VMCallerCheckedAnyfunc,
|
|
||||||
VMContext,
|
|
||||||
VMDynamicFunctionContext,
|
|
||||||
VMFunctionBody,
|
|
||||||
VMFunctionKind,
|
|
||||||
VMSharedSignatureIndex,
|
|
||||||
VMTrampoline,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A function defined in the Wasm module
|
/// A function defined in the Wasm module
|
||||||
@@ -104,7 +95,7 @@ impl Function {
|
|||||||
kind: VMFunctionKind::Dynamic,
|
kind: VMFunctionKind::Dynamic,
|
||||||
vmctx,
|
vmctx,
|
||||||
signature: ty.clone(),
|
signature: ty.clone(),
|
||||||
trampoline: std::ptr::null_mut(),
|
trampoline: None,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,7 +145,7 @@ impl Function {
|
|||||||
kind: VMFunctionKind::Dynamic,
|
kind: VMFunctionKind::Dynamic,
|
||||||
vmctx,
|
vmctx,
|
||||||
signature: ty.clone(),
|
signature: ty.clone(),
|
||||||
trampoline: std::ptr::null(),
|
trampoline: None,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -196,7 +187,7 @@ impl Function {
|
|||||||
vmctx,
|
vmctx,
|
||||||
signature,
|
signature,
|
||||||
kind: VMFunctionKind::Static,
|
kind: VMFunctionKind::Static,
|
||||||
trampoline: std::ptr::null(),
|
trampoline: None,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,7 +241,7 @@ impl Function {
|
|||||||
kind: VMFunctionKind::Static,
|
kind: VMFunctionKind::Static,
|
||||||
vmctx,
|
vmctx,
|
||||||
signature,
|
signature,
|
||||||
trampoline: std::ptr::null(),
|
trampoline: None,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -314,7 +305,7 @@ impl Function {
|
|||||||
if let Err(error) = unsafe {
|
if let Err(error) = unsafe {
|
||||||
wasmer_call_trampoline(
|
wasmer_call_trampoline(
|
||||||
self.exported.vmctx,
|
self.exported.vmctx,
|
||||||
*func.trampoline,
|
func.trampoline,
|
||||||
self.exported.address,
|
self.exported.address,
|
||||||
values_vec.as_mut_ptr() as *mut u8,
|
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 {
|
pub(crate) fn from_export(store: &Store, wasmer_export: ExportFunction) -> Self {
|
||||||
|
let trampoline = wasmer_export.trampoline.unwrap();
|
||||||
Self {
|
Self {
|
||||||
store: store.clone(),
|
store: store.clone(),
|
||||||
definition: FunctionDefinition::Wasm(WasmFunctionDefinition { trampoline: wasmer_export.trampoline }),
|
definition: FunctionDefinition::Wasm(WasmFunctionDefinition { trampoline }),
|
||||||
exported: wasmer_export,
|
exported: wasmer_export,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ where
|
|||||||
vmctx: other.vmctx,
|
vmctx: other.vmctx,
|
||||||
signature,
|
signature,
|
||||||
kind: other.arg_kind,
|
kind: other.arg_kind,
|
||||||
|
trampoline: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,6 +89,7 @@ where
|
|||||||
vmctx: other.vmctx,
|
vmctx: other.vmctx,
|
||||||
signature,
|
signature,
|
||||||
kind: other.arg_kind,
|
kind: other.arg_kind,
|
||||||
|
trampoline: None,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ impl ValFuncRef for Val {
|
|||||||
// are converted to use the trampolines with static signatures).
|
// are converted to use the trampolines with static signatures).
|
||||||
kind: wasmer_vm::VMFunctionKind::Static,
|
kind: wasmer_vm::VMFunctionKind::Static,
|
||||||
vmctx: item.vmctx,
|
vmctx: item.vmctx,
|
||||||
|
trampoline: None,
|
||||||
};
|
};
|
||||||
let f = Function::from_export(store, export);
|
let f = Function::from_export(store, export);
|
||||||
Val::FuncRef(f)
|
Val::FuncRef(f)
|
||||||
|
|||||||
@@ -338,7 +338,8 @@ impl NativeArtifact {
|
|||||||
metadata,
|
metadata,
|
||||||
library: None,
|
library: None,
|
||||||
finished_functions: finished_functions.into_boxed_slice(),
|
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
|
finished_dynamic_function_trampolines: finished_dynamic_function_trampolines
|
||||||
.into_boxed_slice(),
|
.into_boxed_slice(),
|
||||||
signatures: signatures.into_boxed_slice(),
|
signatures: signatures.into_boxed_slice(),
|
||||||
@@ -390,11 +391,14 @@ impl NativeArtifact {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve function call trampolines
|
// 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() {
|
for sig_index in metadata.compile_info.module.signatures.keys() {
|
||||||
let function_name = metadata.symbol_to_name(Symbol::FunctionCallTrampoline(sig_index));
|
let function_name = metadata.symbol_to_name(Symbol::FunctionCallTrampoline(sig_index));
|
||||||
unsafe {
|
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();
|
let raw = *trampoline.into_raw();
|
||||||
finished_function_call_trampolines.push(raw);
|
finished_function_call_trampolines.push(raw);
|
||||||
}
|
}
|
||||||
@@ -454,7 +458,8 @@ impl NativeArtifact {
|
|||||||
metadata,
|
metadata,
|
||||||
library: Some(lib),
|
library: Some(lib),
|
||||||
finished_functions: finished_functions.into_boxed_slice(),
|
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
|
finished_dynamic_function_trampolines: finished_dynamic_function_trampolines
|
||||||
.into_boxed_slice(),
|
.into_boxed_slice(),
|
||||||
signatures: signatures.into_boxed_slice(),
|
signatures: signatures.into_boxed_slice(),
|
||||||
|
|||||||
@@ -123,7 +123,6 @@ impl Engine for NativeEngine {
|
|||||||
&self.target
|
&self.target
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
/// Register a signature
|
/// Register a signature
|
||||||
fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex {
|
fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex {
|
||||||
let compiler = self.inner();
|
let compiler = self.inner();
|
||||||
@@ -136,6 +135,7 @@ impl Engine for NativeEngine {
|
|||||||
compiler.signatures().lookup(sig)
|
compiler.signatures().lookup(sig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
/// Retrieves a trampoline given a signature
|
/// Retrieves a trampoline given a signature
|
||||||
fn function_call_trampoline(&self, sig: VMSharedSignatureIndex) -> Option<VMTrampoline> {
|
fn function_call_trampoline(&self, sig: VMSharedSignatureIndex) -> Option<VMTrampoline> {
|
||||||
self.inner().trampoline(sig)
|
self.inner().trampoline(sig)
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ pub trait Engine {
|
|||||||
/// Gets the target
|
/// Gets the target
|
||||||
fn target(&self) -> &Target;
|
fn target(&self) -> &Target;
|
||||||
|
|
||||||
/*
|
|
||||||
/// Register a signature
|
/// Register a signature
|
||||||
fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex;
|
fn register_signature(&self, func_type: &FunctionType) -> VMSharedSignatureIndex;
|
||||||
|
|
||||||
/// Lookup a signature
|
/// Lookup a signature
|
||||||
fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option<FunctionType>;
|
fn lookup_signature(&self, sig: VMSharedSignatureIndex) -> Option<FunctionType>;
|
||||||
|
|
||||||
|
/*
|
||||||
/// Retrieves a trampoline given a signature
|
/// Retrieves a trampoline given a signature
|
||||||
fn function_call_trampoline(&self, sig: VMSharedSignatureIndex) -> Option<VMTrampoline>;
|
fn function_call_trampoline(&self, sig: VMSharedSignatureIndex) -> Option<VMTrampoline>;
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ pub struct ExportFunction {
|
|||||||
pub signature: FunctionType,
|
pub signature: FunctionType,
|
||||||
/// The function kind (it defines how it's the signature that provided `address` have)
|
/// The function kind (it defines how it's the signature that provided `address` have)
|
||||||
pub kind: VMFunctionKind,
|
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.
|
/// 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: VMTrampoline,
|
pub trampoline: Option<VMTrampoline>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
|
|||||||
@@ -301,7 +301,7 @@ impl Instance {
|
|||||||
let import = self.imported_function(*index);
|
let import = self.imported_function(*index);
|
||||||
(import.body, import.vmctx)
|
(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();
|
let signature = self.module.signatures[*sig_index].clone();
|
||||||
ExportFunction {
|
ExportFunction {
|
||||||
address,
|
address,
|
||||||
|
|||||||
Reference in New Issue
Block a user