mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 13:18:20 +00:00
Rename EngineExport to Export
This commit is contained in:
@@ -7,7 +7,7 @@ use std::fmt;
|
||||
use std::iter::{ExactSizeIterator, FromIterator};
|
||||
use std::sync::Arc;
|
||||
use thiserror::Error;
|
||||
use wasmer_engine::EngineExport;
|
||||
use wasmer_engine::Export;
|
||||
|
||||
/// The `ExportError` can happen when trying to get a specific
|
||||
/// export [`Extern`] from the [`Instance`] exports.
|
||||
@@ -264,11 +264,11 @@ impl FromIterator<(String, Extern)> for Exports {
|
||||
}
|
||||
|
||||
impl LikeNamespace for Exports {
|
||||
fn get_namespace_export(&self, name: &str) -> Option<EngineExport> {
|
||||
fn get_namespace_export(&self, name: &str) -> Option<Export> {
|
||||
self.map.get(name).map(|is_export| is_export.to_export())
|
||||
}
|
||||
|
||||
fn get_namespace_exports(&self) -> Vec<(String, EngineExport)> {
|
||||
fn get_namespace_exports(&self) -> Vec<(String, Export)> {
|
||||
self.map
|
||||
.iter()
|
||||
.map(|(k, v)| (k.clone(), v.to_export()))
|
||||
@@ -284,7 +284,7 @@ pub trait Exportable<'a>: Sized {
|
||||
/// can be used while instantiating the [`Module`].
|
||||
///
|
||||
/// [`Module`]: crate::Module
|
||||
fn to_export(&self) -> EngineExport;
|
||||
fn to_export(&self) -> Export;
|
||||
|
||||
/// Implementation of how to get the export corresponding to the implementing type
|
||||
/// from an [`Instance`] by name.
|
||||
|
||||
70
lib/api/src/externals/function.rs
vendored
70
lib/api/src/externals/function.rs
vendored
@@ -12,7 +12,7 @@ pub use inner::{UnsafeMutableEnv, WithUnsafeMutableEnv};
|
||||
|
||||
use std::cmp::max;
|
||||
use std::fmt;
|
||||
use wasmer_engine::{EngineExport, EngineExportFunction};
|
||||
use wasmer_engine::{Export, ExportFunction};
|
||||
use wasmer_vm::{
|
||||
raise_user_trap, resume_panic, wasmer_call_trampoline, VMCallerCheckedAnyfunc,
|
||||
VMDynamicFunctionContext, VMExportFunction, VMFunctionBody, VMFunctionEnvironment,
|
||||
@@ -57,7 +57,7 @@ pub enum FunctionDefinition {
|
||||
pub struct Function {
|
||||
pub(crate) store: Store,
|
||||
pub(crate) definition: FunctionDefinition,
|
||||
pub(crate) exported: EngineExportFunction,
|
||||
pub(crate) exported: ExportFunction,
|
||||
}
|
||||
|
||||
impl Function {
|
||||
@@ -96,9 +96,9 @@ impl Function {
|
||||
Self {
|
||||
store: store.clone(),
|
||||
definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: false }),
|
||||
exported: EngineExportFunction {
|
||||
function_ptr: None,
|
||||
function: VMExportFunction {
|
||||
exported: ExportFunction {
|
||||
import_init_function_ptr: None,
|
||||
vm_function: VMExportFunction {
|
||||
address,
|
||||
kind: VMFunctionKind::Dynamic,
|
||||
vmctx,
|
||||
@@ -149,7 +149,7 @@ impl Function {
|
||||
host_env: Box::into_raw(Box::new(dynamic_ctx)) as *mut _,
|
||||
};
|
||||
// TODO: look into removing transmute by changing API type signatures
|
||||
let function_ptr = Some(unsafe {
|
||||
let import_init_function_ptr = Some(unsafe {
|
||||
std::mem::transmute::<fn(_, _) -> Result<(), _>, fn(_, _) -> Result<(), _>>(
|
||||
Env::init_with_instance,
|
||||
)
|
||||
@@ -158,9 +158,9 @@ impl Function {
|
||||
Self {
|
||||
store: store.clone(),
|
||||
definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: true }),
|
||||
exported: EngineExportFunction {
|
||||
function_ptr,
|
||||
function: VMExportFunction {
|
||||
exported: ExportFunction {
|
||||
import_init_function_ptr,
|
||||
vm_function: VMExportFunction {
|
||||
address,
|
||||
kind: VMFunctionKind::Dynamic,
|
||||
vmctx,
|
||||
@@ -206,11 +206,11 @@ impl Function {
|
||||
store: store.clone(),
|
||||
definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: false }),
|
||||
|
||||
exported: EngineExportFunction {
|
||||
exported: ExportFunction {
|
||||
// TODO: figure out what's going on in this function: it takes an `Env`
|
||||
// param but also marks itself as not having an env
|
||||
function_ptr: None,
|
||||
function: VMExportFunction {
|
||||
import_init_function_ptr: None,
|
||||
vm_function: VMExportFunction {
|
||||
address,
|
||||
vmctx,
|
||||
signature,
|
||||
@@ -264,7 +264,7 @@ impl Function {
|
||||
host_env: Box::into_raw(box_env) as *mut _,
|
||||
};
|
||||
// TODO: look into removing transmute by changing API type signatures
|
||||
let function_ptr = Some(unsafe {
|
||||
let import_init_function_ptr = Some(unsafe {
|
||||
std::mem::transmute::<fn(_, _) -> Result<(), _>, fn(_, _) -> Result<(), _>>(
|
||||
Env::init_with_instance,
|
||||
)
|
||||
@@ -274,9 +274,9 @@ impl Function {
|
||||
Self {
|
||||
store: store.clone(),
|
||||
definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: true }),
|
||||
exported: EngineExportFunction {
|
||||
function_ptr,
|
||||
function: VMExportFunction {
|
||||
exported: ExportFunction {
|
||||
import_init_function_ptr,
|
||||
vm_function: VMExportFunction {
|
||||
address,
|
||||
kind: VMFunctionKind::Static,
|
||||
vmctx,
|
||||
@@ -315,7 +315,7 @@ impl Function {
|
||||
};
|
||||
let signature = function.ty();
|
||||
// TODO: look into removing transmute by changing API type signatures
|
||||
let function_ptr = Some(std::mem::transmute::<
|
||||
let import_init_function_ptr = Some(std::mem::transmute::<
|
||||
fn(_, _) -> Result<(), _>,
|
||||
fn(_, _) -> Result<(), _>,
|
||||
>(Env::init_with_instance));
|
||||
@@ -323,9 +323,9 @@ impl Function {
|
||||
Self {
|
||||
store: store.clone(),
|
||||
definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: true }),
|
||||
exported: EngineExportFunction {
|
||||
function_ptr,
|
||||
function: VMExportFunction {
|
||||
exported: ExportFunction {
|
||||
import_init_function_ptr,
|
||||
vm_function: VMExportFunction {
|
||||
address,
|
||||
kind: VMFunctionKind::Static,
|
||||
vmctx,
|
||||
@@ -354,7 +354,7 @@ impl Function {
|
||||
/// assert_eq!(f.ty().results(), vec![Type::I32]);
|
||||
/// ```
|
||||
pub fn ty(&self) -> &FunctionType {
|
||||
&self.exported.function.signature
|
||||
&self.exported.vm_function.signature
|
||||
}
|
||||
|
||||
/// Returns the [`Store`] where the `Function` belongs.
|
||||
@@ -411,9 +411,9 @@ impl Function {
|
||||
// Call the trampoline.
|
||||
if let Err(error) = unsafe {
|
||||
wasmer_call_trampoline(
|
||||
self.exported.function.vmctx,
|
||||
self.exported.vm_function.vmctx,
|
||||
func.trampoline,
|
||||
self.exported.function.address,
|
||||
self.exported.vm_function.address,
|
||||
values_vec.as_mut_ptr() as *mut u8,
|
||||
)
|
||||
} {
|
||||
@@ -513,8 +513,8 @@ impl Function {
|
||||
Ok(results.into_boxed_slice())
|
||||
}
|
||||
|
||||
pub(crate) fn from_export(store: &Store, wasmer_export: EngineExportFunction) -> Self {
|
||||
if let Some(trampoline) = wasmer_export.function.call_trampoline {
|
||||
pub(crate) fn from_export(store: &Store, wasmer_export: ExportFunction) -> Self {
|
||||
if let Some(trampoline) = wasmer_export.vm_function.call_trampoline {
|
||||
Self {
|
||||
store: store.clone(),
|
||||
definition: FunctionDefinition::Wasm(WasmFunctionDefinition { trampoline }),
|
||||
@@ -524,7 +524,7 @@ impl Function {
|
||||
Self {
|
||||
store: store.clone(),
|
||||
definition: FunctionDefinition::Host(HostFunctionDefinition {
|
||||
has_env: !wasmer_export.function.vmctx.is_null(),
|
||||
has_env: !wasmer_export.vm_function.vmctx.is_null(),
|
||||
}),
|
||||
exported: wasmer_export,
|
||||
}
|
||||
@@ -535,11 +535,11 @@ impl Function {
|
||||
let vmsignature = self
|
||||
.store
|
||||
.engine()
|
||||
.register_signature(&self.exported.function.signature);
|
||||
.register_signature(&self.exported.vm_function.signature);
|
||||
VMCallerCheckedAnyfunc {
|
||||
func_ptr: self.exported.function.address,
|
||||
func_ptr: self.exported.vm_function.address,
|
||||
type_index: vmsignature,
|
||||
vmctx: self.exported.function.vmctx,
|
||||
vmctx: self.exported.vm_function.vmctx,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -625,7 +625,7 @@ impl Function {
|
||||
{
|
||||
// type check
|
||||
{
|
||||
let expected = self.exported.function.signature.params();
|
||||
let expected = self.exported.vm_function.signature.params();
|
||||
let given = Args::wasm_types();
|
||||
|
||||
if expected != given {
|
||||
@@ -638,7 +638,7 @@ impl Function {
|
||||
}
|
||||
|
||||
{
|
||||
let expected = self.exported.function.signature.results();
|
||||
let expected = self.exported.vm_function.signature.results();
|
||||
let given = Rets::wasm_types();
|
||||
|
||||
if expected != given {
|
||||
@@ -653,16 +653,16 @@ impl Function {
|
||||
|
||||
Ok(NativeFunc::new(
|
||||
self.store.clone(),
|
||||
self.exported.function.address,
|
||||
self.exported.function.vmctx,
|
||||
self.exported.function.kind,
|
||||
self.exported.vm_function.address,
|
||||
self.exported.vm_function.vmctx,
|
||||
self.exported.vm_function.kind,
|
||||
self.definition.clone(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Exportable<'a> for Function {
|
||||
fn to_export(&self) -> EngineExport {
|
||||
fn to_export(&self) -> Export {
|
||||
self.exported.clone().into()
|
||||
}
|
||||
|
||||
|
||||
12
lib/api/src/externals/global.rs
vendored
12
lib/api/src/externals/global.rs
vendored
@@ -7,7 +7,7 @@ use crate::Mutability;
|
||||
use crate::RuntimeError;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use wasmer_engine::EngineExport;
|
||||
use wasmer_engine::{Export, ExportGlobal};
|
||||
use wasmer_vm::{Global as RuntimeGlobal, VMExportGlobal};
|
||||
|
||||
/// A WebAssembly `global` instance.
|
||||
@@ -181,10 +181,10 @@ impl Global {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn from_export(store: &Store, wasmer_export: VMExportGlobal) -> Self {
|
||||
pub(crate) fn from_export(store: &Store, wasmer_export: ExportGlobal) -> Self {
|
||||
Self {
|
||||
store: store.clone(),
|
||||
global: wasmer_export.from,
|
||||
global: wasmer_export.vm_global.from,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,9 +216,11 @@ impl fmt::Debug for Global {
|
||||
}
|
||||
|
||||
impl<'a> Exportable<'a> for Global {
|
||||
fn to_export(&self) -> EngineExport {
|
||||
VMExportGlobal {
|
||||
fn to_export(&self) -> Export {
|
||||
ExportGlobal {
|
||||
vm_global: VMExportGlobal {
|
||||
from: self.global.clone(),
|
||||
},
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
12
lib/api/src/externals/memory.rs
vendored
12
lib/api/src/externals/memory.rs
vendored
@@ -5,7 +5,7 @@ use crate::{MemoryType, MemoryView};
|
||||
use std::convert::TryInto;
|
||||
use std::slice;
|
||||
use std::sync::Arc;
|
||||
use wasmer_engine::EngineExport;
|
||||
use wasmer_engine::{Export, ExportMemory};
|
||||
use wasmer_types::{Pages, ValueType};
|
||||
use wasmer_vm::{Memory as RuntimeMemory, MemoryError, VMExportMemory};
|
||||
|
||||
@@ -221,10 +221,10 @@ impl Memory {
|
||||
unsafe { MemoryView::new(base as _, length as u32) }
|
||||
}
|
||||
|
||||
pub(crate) fn from_export(store: &Store, wasmer_export: VMExportMemory) -> Self {
|
||||
pub(crate) fn from_export(store: &Store, wasmer_export: ExportMemory) -> Self {
|
||||
Self {
|
||||
store: store.clone(),
|
||||
memory: wasmer_export.from,
|
||||
memory: wasmer_export.vm_memory.from,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,9 +246,11 @@ impl Memory {
|
||||
}
|
||||
|
||||
impl<'a> Exportable<'a> for Memory {
|
||||
fn to_export(&self) -> EngineExport {
|
||||
VMExportMemory {
|
||||
fn to_export(&self) -> Export {
|
||||
ExportMemory {
|
||||
vm_memory: VMExportMemory {
|
||||
from: self.memory.clone(),
|
||||
},
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
14
lib/api/src/externals/mod.rs
vendored
14
lib/api/src/externals/mod.rs
vendored
@@ -17,7 +17,7 @@ use crate::exports::{ExportError, Exportable};
|
||||
use crate::store::{Store, StoreObject};
|
||||
use crate::ExternType;
|
||||
use std::fmt;
|
||||
use wasmer_engine::EngineExport;
|
||||
use wasmer_engine::Export;
|
||||
|
||||
/// An `Extern` is the runtime representation of an entity that
|
||||
/// can be imported or exported.
|
||||
@@ -47,18 +47,18 @@ impl Extern {
|
||||
}
|
||||
|
||||
/// Create an `Extern` from an `Export`.
|
||||
pub fn from_export(store: &Store, export: EngineExport) -> Self {
|
||||
pub fn from_export(store: &Store, export: Export) -> Self {
|
||||
match export {
|
||||
EngineExport::Function(f) => Self::Function(Function::from_export(store, f)),
|
||||
EngineExport::Memory(m) => Self::Memory(Memory::from_export(store, m)),
|
||||
EngineExport::Global(g) => Self::Global(Global::from_export(store, g)),
|
||||
EngineExport::Table(t) => Self::Table(Table::from_export(store, t)),
|
||||
Export::Function(f) => Self::Function(Function::from_export(store, f)),
|
||||
Export::Memory(m) => Self::Memory(Memory::from_export(store, m)),
|
||||
Export::Global(g) => Self::Global(Global::from_export(store, g)),
|
||||
Export::Table(t) => Self::Table(Table::from_export(store, t)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Exportable<'a> for Extern {
|
||||
fn to_export(&self) -> EngineExport {
|
||||
fn to_export(&self) -> Export {
|
||||
match self {
|
||||
Self::Function(f) => f.to_export(),
|
||||
Self::Global(g) => g.to_export(),
|
||||
|
||||
12
lib/api/src/externals/table.rs
vendored
12
lib/api/src/externals/table.rs
vendored
@@ -5,7 +5,7 @@ use crate::types::{Val, ValFuncRef};
|
||||
use crate::RuntimeError;
|
||||
use crate::TableType;
|
||||
use std::sync::Arc;
|
||||
use wasmer_engine::EngineExport;
|
||||
use wasmer_engine::{Export, ExportTable};
|
||||
use wasmer_vm::{Table as RuntimeTable, VMCallerCheckedAnyfunc, VMExportTable};
|
||||
|
||||
/// A WebAssembly `table` instance.
|
||||
@@ -140,10 +140,10 @@ impl Table {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn from_export(store: &Store, wasmer_export: VMExportTable) -> Self {
|
||||
pub(crate) fn from_export(store: &Store, wasmer_export: ExportTable) -> Self {
|
||||
Self {
|
||||
store: store.clone(),
|
||||
table: wasmer_export.from,
|
||||
table: wasmer_export.vm_table.from,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,9 +154,11 @@ impl Table {
|
||||
}
|
||||
|
||||
impl<'a> Exportable<'a> for Table {
|
||||
fn to_export(&self) -> EngineExport {
|
||||
VMExportTable {
|
||||
fn to_export(&self) -> Export {
|
||||
ExportTable {
|
||||
vm_table: VMExportTable {
|
||||
from: self.table.clone(),
|
||||
},
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
@@ -6,16 +6,16 @@ use std::collections::VecDeque;
|
||||
use std::collections::{hash_map::Entry, HashMap};
|
||||
use std::fmt;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use wasmer_engine::{EngineExport, NamedResolver};
|
||||
use wasmer_engine::{Export, NamedResolver};
|
||||
|
||||
/// The `LikeNamespace` trait represents objects that act as a namespace for imports.
|
||||
/// For example, an `Instance` or `Namespace` could be
|
||||
/// considered namespaces that could provide imports to an instance.
|
||||
pub trait LikeNamespace {
|
||||
/// Gets an export by name.
|
||||
fn get_namespace_export(&self, name: &str) -> Option<EngineExport>;
|
||||
fn get_namespace_export(&self, name: &str) -> Option<Export>;
|
||||
/// Gets all exports in the namespace.
|
||||
fn get_namespace_exports(&self) -> Vec<(String, EngineExport)>;
|
||||
fn get_namespace_exports(&self) -> Vec<(String, Export)>;
|
||||
}
|
||||
|
||||
/// All of the import data used when instantiating.
|
||||
@@ -58,7 +58,7 @@ impl ImportObject {
|
||||
/// let mut import_object = ImportObject::new();
|
||||
/// import_object.get_export("module", "name");
|
||||
/// ```
|
||||
pub fn get_export(&self, module: &str, name: &str) -> Option<EngineExport> {
|
||||
pub fn get_export(&self, module: &str, name: &str) -> Option<Export> {
|
||||
let guard = self.map.lock().unwrap();
|
||||
let map_ref = guard.borrow();
|
||||
if map_ref.contains_key(module) {
|
||||
@@ -101,7 +101,7 @@ impl ImportObject {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_objects(&self) -> VecDeque<((String, String), EngineExport)> {
|
||||
fn get_objects(&self) -> VecDeque<((String, String), Export)> {
|
||||
let mut out = VecDeque::new();
|
||||
let guard = self.map.lock().unwrap();
|
||||
let map = guard.borrow();
|
||||
@@ -115,18 +115,18 @@ impl ImportObject {
|
||||
}
|
||||
|
||||
impl NamedResolver for ImportObject {
|
||||
fn resolve_by_name(&self, module: &str, name: &str) -> Option<EngineExport> {
|
||||
fn resolve_by_name(&self, module: &str, name: &str) -> Option<Export> {
|
||||
self.get_export(module, name)
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterator for an `ImportObject`'s exports.
|
||||
pub struct ImportObjectIterator {
|
||||
elements: VecDeque<((String, String), EngineExport)>,
|
||||
elements: VecDeque<((String, String), Export)>,
|
||||
}
|
||||
|
||||
impl Iterator for ImportObjectIterator {
|
||||
type Item = ((String, String), EngineExport);
|
||||
type Item = ((String, String), Export);
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.elements.pop_front()
|
||||
}
|
||||
@@ -134,7 +134,7 @@ impl Iterator for ImportObjectIterator {
|
||||
|
||||
impl IntoIterator for ImportObject {
|
||||
type IntoIter = ImportObjectIterator;
|
||||
type Item = ((String, String), EngineExport);
|
||||
type Item = ((String, String), Export);
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
ImportObjectIterator {
|
||||
@@ -317,13 +317,11 @@ mod test {
|
||||
let resolver = imports1.chain_front(imports2);
|
||||
let happy_dog_entry = resolver.resolve_by_name("dog", "happy").unwrap();
|
||||
|
||||
assert!(
|
||||
if let EngineExport::Global(happy_dog_global) = happy_dog_entry {
|
||||
happy_dog_global.from.ty().ty == Type::I64
|
||||
assert!(if let Export::Global(happy_dog_global) = happy_dog_entry {
|
||||
happy_dog_global.vm_global.from.ty().ty == Type::I64
|
||||
} else {
|
||||
false
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// now test it in reverse
|
||||
let store = Store::default();
|
||||
@@ -345,13 +343,11 @@ mod test {
|
||||
let resolver = imports1.chain_back(imports2);
|
||||
let happy_dog_entry = resolver.resolve_by_name("dog", "happy").unwrap();
|
||||
|
||||
assert!(
|
||||
if let EngineExport::Global(happy_dog_global) = happy_dog_entry {
|
||||
happy_dog_global.from.ty().ty == Type::I32
|
||||
assert!(if let Export::Global(happy_dog_global) = happy_dog_entry {
|
||||
happy_dog_global.vm_global.from.ty().ty == Type::I32
|
||||
} else {
|
||||
false
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -367,13 +363,11 @@ mod test {
|
||||
|
||||
let happy_dog_entry = imports1.resolve_by_name("dog", "happy").unwrap();
|
||||
|
||||
assert!(
|
||||
if let EngineExport::Global(happy_dog_global) = happy_dog_entry {
|
||||
happy_dog_global.from.ty().ty == Type::I32
|
||||
assert!(if let Export::Global(happy_dog_global) = happy_dog_entry {
|
||||
happy_dog_global.vm_global.from.ty().ty == Type::I32
|
||||
} else {
|
||||
false
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -80,8 +80,8 @@ pub use wasmer_compiler::{
|
||||
};
|
||||
pub use wasmer_compiler::{CpuFeature, Features, Target};
|
||||
pub use wasmer_engine::{
|
||||
ChainableNamedResolver, DeserializeError, Engine, EngineExport, FrameInfo, LinkError,
|
||||
NamedResolver, NamedResolverChain, Resolver, RuntimeError, SerializeError,
|
||||
ChainableNamedResolver, DeserializeError, Engine, Export, FrameInfo, LinkError, NamedResolver,
|
||||
NamedResolverChain, Resolver, RuntimeError, SerializeError,
|
||||
};
|
||||
pub use wasmer_types::{
|
||||
Atomically, Bytes, GlobalInit, LocalFunctionIndex, MemoryView, Pages, ValueType,
|
||||
|
||||
@@ -15,7 +15,7 @@ use crate::externals::function::{
|
||||
};
|
||||
use crate::{FromToNativeWasmType, Function, FunctionType, RuntimeError, Store, WasmTypeList};
|
||||
use std::panic::{catch_unwind, AssertUnwindSafe};
|
||||
use wasmer_engine::EngineExportFunction;
|
||||
use wasmer_engine::ExportFunction;
|
||||
use wasmer_types::NativeWasmType;
|
||||
use wasmer_vm::{
|
||||
VMDynamicFunctionContext, VMExportFunction, VMFunctionBody, VMFunctionEnvironment,
|
||||
@@ -30,7 +30,7 @@ pub struct NativeFunc<Args = (), Rets = ()> {
|
||||
address: *const VMFunctionBody,
|
||||
vmctx: VMFunctionEnvironment,
|
||||
arg_kind: VMFunctionKind,
|
||||
// exported: EngineExportFunction,
|
||||
// exported: ExportFunction,
|
||||
_phantom: PhantomData<(Args, Rets)>,
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ where
|
||||
}
|
||||
}*/
|
||||
|
||||
impl<Args, Rets> From<&NativeFunc<Args, Rets>> for EngineExportFunction
|
||||
impl<Args, Rets> From<&NativeFunc<Args, Rets>> for ExportFunction
|
||||
where
|
||||
Args: WasmTypeList,
|
||||
Rets: WasmTypeList,
|
||||
@@ -86,8 +86,8 @@ where
|
||||
let signature = FunctionType::new(Args::wasm_types(), Rets::wasm_types());
|
||||
Self {
|
||||
// TODO:
|
||||
function_ptr: None,
|
||||
function: VMExportFunction {
|
||||
import_init_function_ptr: None,
|
||||
vm_function: VMExportFunction {
|
||||
address: other.address,
|
||||
vmctx: other.vmctx,
|
||||
signature,
|
||||
@@ -108,10 +108,10 @@ where
|
||||
Self {
|
||||
store: other.store,
|
||||
definition: other.definition,
|
||||
exported: EngineExportFunction {
|
||||
exported: ExportFunction {
|
||||
// TODO:
|
||||
function_ptr: None,
|
||||
function: VMExportFunction {
|
||||
import_init_function_ptr: None,
|
||||
vm_function: VMExportFunction {
|
||||
address: other.address,
|
||||
vmctx: other.vmctx,
|
||||
signature,
|
||||
|
||||
@@ -73,11 +73,11 @@ impl ValFuncRef for Val {
|
||||
.engine()
|
||||
.lookup_signature(item.type_index)
|
||||
.expect("Signature not found in store");
|
||||
let export = wasmer_engine::EngineExportFunction {
|
||||
let export = wasmer_engine::ExportFunction {
|
||||
// TODO:
|
||||
// figure out if we ever need a value here: need testing with complicated import patterns
|
||||
function_ptr: None,
|
||||
function: wasmer_vm::VMExportFunction {
|
||||
import_init_function_ptr: None,
|
||||
vm_function: wasmer_vm::VMExportFunction {
|
||||
address: item.func_ptr,
|
||||
signature,
|
||||
// All functions in tables are already Static (as dynamic functions
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
//! by index and not by module and name.
|
||||
|
||||
use std::iter::FromIterator;
|
||||
use wasmer::{EngineExport, Exportable, Extern, Resolver};
|
||||
use wasmer::{Export, Exportable, Extern, Resolver};
|
||||
|
||||
/// An `OrderedResolver` stores all the `externs` provided to an Instance
|
||||
/// in a Vec, so we can retrieve them later based on index.
|
||||
@@ -16,7 +16,7 @@ pub struct OrderedResolver {
|
||||
}
|
||||
|
||||
impl Resolver for OrderedResolver {
|
||||
fn resolve(&self, index: u32, _module: &str, _name: &str) -> Option<EngineExport> {
|
||||
fn resolve(&self, index: u32, _module: &str, _name: &str) -> Option<Export> {
|
||||
self.externs
|
||||
.get(index as usize)
|
||||
.map(|extern_| extern_.to_export())
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
pub use crate::new::{
|
||||
wasmer::Export as RuntimeExport,
|
||||
wasmer::{Exportable, Extern as Export},
|
||||
wasmer_vm::Export as RuntimeExport,
|
||||
};
|
||||
|
||||
@@ -87,7 +87,7 @@ impl From<&new::wasmer::Global> for Global {
|
||||
}
|
||||
|
||||
impl<'a> new::wasmer::Exportable<'a> for Global {
|
||||
fn to_export(&self) -> new::wasmer_vm::Export {
|
||||
fn to_export(&self) -> new::wasmer::Export {
|
||||
self.new_global.to_export()
|
||||
}
|
||||
|
||||
|
||||
@@ -30,11 +30,11 @@ impl Namespace {
|
||||
}
|
||||
|
||||
impl LikeNamespace for Namespace {
|
||||
fn get_namespace_export(&self, name: &str) -> Option<new::wasmer_vm::Export> {
|
||||
fn get_namespace_export(&self, name: &str) -> Option<new::wasmer::Export> {
|
||||
self.exports.new_exports.get_namespace_export(name)
|
||||
}
|
||||
|
||||
fn get_namespace_exports(&self) -> Vec<(String, new::wasmer_vm::Export)> {
|
||||
fn get_namespace_exports(&self) -> Vec<(String, new::wasmer::Export)> {
|
||||
self.exports.new_exports.get_namespace_exports()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,11 +222,11 @@ impl Instance {
|
||||
}
|
||||
|
||||
impl LikeNamespace for Instance {
|
||||
fn get_namespace_export(&self, name: &str) -> Option<new::wasmer_vm::Export> {
|
||||
fn get_namespace_export(&self, name: &str) -> Option<new::wasmer::Export> {
|
||||
self.exports.new_exports.get_namespace_export(name)
|
||||
}
|
||||
|
||||
fn get_namespace_exports(&self) -> Vec<(String, new::wasmer_vm::Export)> {
|
||||
fn get_namespace_exports(&self) -> Vec<(String, new::wasmer::Export)> {
|
||||
self.exports.new_exports.get_namespace_exports()
|
||||
}
|
||||
}
|
||||
@@ -256,11 +256,11 @@ impl Exports {
|
||||
}
|
||||
|
||||
impl LikeNamespace for Exports {
|
||||
fn get_namespace_export(&self, name: &str) -> Option<new::wasmer_vm::Export> {
|
||||
fn get_namespace_export(&self, name: &str) -> Option<new::wasmer::Export> {
|
||||
self.new_exports.get_namespace_export(name)
|
||||
}
|
||||
|
||||
fn get_namespace_exports(&self) -> Vec<(String, new::wasmer_vm::Export)> {
|
||||
fn get_namespace_exports(&self) -> Vec<(String, new::wasmer::Export)> {
|
||||
self.new_exports.get_namespace_exports()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ pub mod ptr {
|
||||
pub use crate::new::wasmer::{Array, Item, WasmPtr};
|
||||
}
|
||||
|
||||
pub use new::wasmer_types::MemoryType as MemoryDescriptor;
|
||||
pub use new::wasmer::{Atomically, MemoryView};
|
||||
pub use new::wasmer_types::MemoryType as MemoryDescriptor;
|
||||
pub use new::wasmer_vm::MemoryStyle as MemoryType;
|
||||
|
||||
/// A Wasm linear memory.
|
||||
@@ -108,7 +108,7 @@ impl From<&new::wasmer::Memory> for Memory {
|
||||
}
|
||||
|
||||
impl<'a> new::wasmer::Exportable<'a> for Memory {
|
||||
fn to_export(&self) -> new::wasmer_vm::Export {
|
||||
fn to_export(&self) -> new::wasmer::Export {
|
||||
self.new_memory.to_export()
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
types::{FuncSig, Value},
|
||||
vm,
|
||||
};
|
||||
use new::wasmer_vm::Export;
|
||||
use new::wasmer::Export;
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
collections::HashMap,
|
||||
@@ -98,18 +98,20 @@ impl Module {
|
||||
// `function` is a static host function
|
||||
// constructed with
|
||||
// `new::wasmer::Function::new_env`.
|
||||
if !function.address.is_null() {
|
||||
if !function.vm_function.address.is_null() {
|
||||
// Properly drop the empty `vm::Ctx`
|
||||
// created by the host function.
|
||||
unsafe {
|
||||
ptr::drop_in_place::<vm::Ctx>(function.vmctx.host_env as _);
|
||||
ptr::drop_in_place::<vm::Ctx>(
|
||||
function.vm_function.vmctx.host_env as _,
|
||||
);
|
||||
}
|
||||
|
||||
// Update the pointer to `VMContext`,
|
||||
// which is actually a `vm::Ctx`
|
||||
// pointer, to fallback on the
|
||||
// environment hack.
|
||||
function.vmctx.host_env = pre_instance.vmctx_ptr() as _;
|
||||
function.vm_function.vmctx.host_env = pre_instance.vmctx_ptr() as _;
|
||||
}
|
||||
// `function` is a dynamic host function
|
||||
// constructed with
|
||||
@@ -147,13 +149,15 @@ impl Module {
|
||||
new::wasmer_vm::VMDynamicFunctionContext<
|
||||
VMDynamicFunctionWithEnv<DynamicCtx>,
|
||||
>,
|
||||
> = unsafe { Box::from_raw(function.vmctx.host_env as *mut _) };
|
||||
> = unsafe {
|
||||
Box::from_raw(function.vm_function.vmctx.host_env as *mut _)
|
||||
};
|
||||
|
||||
// Replace the environment by ours.
|
||||
vmctx.ctx.env.borrow_mut().vmctx = pre_instance.vmctx();
|
||||
|
||||
// … without anyone noticing…
|
||||
function.vmctx.host_env = Box::into_raw(vmctx) as _;
|
||||
function.vm_function.vmctx.host_env = Box::into_raw(vmctx) as _;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ impl From<&new::wasmer::Table> for Table {
|
||||
}
|
||||
|
||||
impl<'a> new::wasmer::Exportable<'a> for Table {
|
||||
fn to_export(&self) -> new::wasmer_vm::Export {
|
||||
fn to_export(&self) -> new::wasmer::Export {
|
||||
self.new_table.to_export()
|
||||
}
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ where
|
||||
Args: WasmTypeList,
|
||||
Rets: WasmTypeList,
|
||||
{
|
||||
fn to_export(&self) -> new::wasmer_vm::Export {
|
||||
fn to_export(&self) -> new::wasmer::Export {
|
||||
self.new_function.to_export()
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ impl From<&new::wasmer::Function> for DynamicFunc {
|
||||
}
|
||||
|
||||
impl<'a> new::wasmer::Exportable<'a> for DynamicFunc {
|
||||
fn to_export(&self) -> new::wasmer_vm::Export {
|
||||
fn to_export(&self) -> new::wasmer::Export {
|
||||
self.new_function.to_export()
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ pub use crate::engine::{Engine, EngineId};
|
||||
pub use crate::error::{
|
||||
DeserializeError, ImportError, InstantiationError, LinkError, SerializeError,
|
||||
};
|
||||
pub use crate::export::{EngineExport, EngineExportFunction};
|
||||
pub use crate::export::{Export, ExportFunction, ExportGlobal, ExportMemory, ExportTable};
|
||||
pub use crate::resolver::{
|
||||
resolve_imports, ChainableNamedResolver, NamedResolver, NamedResolverChain, NullResolver,
|
||||
Resolver,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Define the `Resolver` trait, allowing custom resolution for external
|
||||
//! references.
|
||||
|
||||
use crate::{EngineExport, ImportError, LinkError};
|
||||
use crate::{Export, ImportError, LinkError};
|
||||
use more_asserts::assert_ge;
|
||||
use wasmer_types::entity::{BoxedSlice, EntityRef, PrimaryMap};
|
||||
use wasmer_types::{ExternType, FunctionIndex, ImportIndex, MemoryIndex, TableIndex};
|
||||
@@ -32,7 +32,7 @@ pub trait Resolver {
|
||||
/// (import "" "" (func (param i32) (result i32)))
|
||||
/// )
|
||||
/// ```
|
||||
fn resolve(&self, _index: u32, module: &str, field: &str) -> Option<EngineExport>;
|
||||
fn resolve(&self, _index: u32, module: &str, field: &str) -> Option<Export>;
|
||||
}
|
||||
|
||||
/// Import resolver connects imports with available exported values.
|
||||
@@ -45,26 +45,26 @@ pub trait NamedResolver {
|
||||
///
|
||||
/// It receives the `module` and `field` names and return the [`Export`] in
|
||||
/// case it's found.
|
||||
fn resolve_by_name(&self, module: &str, field: &str) -> Option<EngineExport>;
|
||||
fn resolve_by_name(&self, module: &str, field: &str) -> Option<Export>;
|
||||
}
|
||||
|
||||
// All NamedResolvers should extend `Resolver`.
|
||||
impl<T: NamedResolver> Resolver for T {
|
||||
/// By default this method will be calling [`NamedResolver::resolve_by_name`],
|
||||
/// dismissing the provided `index`.
|
||||
fn resolve(&self, _index: u32, module: &str, field: &str) -> Option<EngineExport> {
|
||||
fn resolve(&self, _index: u32, module: &str, field: &str) -> Option<Export> {
|
||||
self.resolve_by_name(module, field)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: NamedResolver> NamedResolver for &T {
|
||||
fn resolve_by_name(&self, module: &str, field: &str) -> Option<EngineExport> {
|
||||
fn resolve_by_name(&self, module: &str, field: &str) -> Option<Export> {
|
||||
(**self).resolve_by_name(module, field)
|
||||
}
|
||||
}
|
||||
|
||||
impl NamedResolver for Box<dyn NamedResolver> {
|
||||
fn resolve_by_name(&self, module: &str, field: &str) -> Option<EngineExport> {
|
||||
fn resolve_by_name(&self, module: &str, field: &str) -> Option<Export> {
|
||||
(**self).resolve_by_name(module, field)
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ impl NamedResolver for Box<dyn NamedResolver> {
|
||||
pub struct NullResolver {}
|
||||
|
||||
impl Resolver for NullResolver {
|
||||
fn resolve(&self, _idx: u32, _module: &str, _field: &str) -> Option<EngineExport> {
|
||||
fn resolve(&self, _idx: u32, _module: &str, _field: &str) -> Option<Export> {
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -101,13 +101,13 @@ fn get_extern_from_import(module: &ModuleInfo, import_index: &ImportIndex) -> Ex
|
||||
}
|
||||
|
||||
/// Get an `ExternType` given an export (and Engine signatures in case is a function).
|
||||
fn get_extern_from_export(_module: &ModuleInfo, export: &EngineExport) -> ExternType {
|
||||
fn get_extern_from_export(_module: &ModuleInfo, export: &Export) -> ExternType {
|
||||
match export {
|
||||
EngineExport::Function(ref f) => ExternType::Function(f.function.signature.clone()),
|
||||
EngineExport::Table(ref t) => ExternType::Table(*t.ty()),
|
||||
EngineExport::Memory(ref m) => ExternType::Memory(*m.ty()),
|
||||
EngineExport::Global(ref g) => {
|
||||
let global = g.from.ty();
|
||||
Export::Function(ref f) => ExternType::Function(f.vm_function.signature.clone()),
|
||||
Export::Table(ref t) => ExternType::Table(*t.vm_table.ty()),
|
||||
Export::Memory(ref m) => ExternType::Memory(*m.vm_memory.ty()),
|
||||
Export::Global(ref g) => {
|
||||
let global = g.vm_global.from.ty();
|
||||
ExternType::Global(*global)
|
||||
}
|
||||
}
|
||||
@@ -153,8 +153,8 @@ pub fn resolve_imports(
|
||||
));
|
||||
}
|
||||
match resolved {
|
||||
EngineExport::Function(ref f) => {
|
||||
let address = match f.function.kind {
|
||||
Export::Function(ref f) => {
|
||||
let address = match f.vm_function.kind {
|
||||
VMFunctionKind::Dynamic => {
|
||||
// If this is a dynamic imported function,
|
||||
// the address of the function is the address of the
|
||||
@@ -165,27 +165,27 @@ pub fn resolve_imports(
|
||||
// TODO: We should check that the f.vmctx actually matches
|
||||
// the shape of `VMDynamicFunctionImportContext`
|
||||
}
|
||||
VMFunctionKind::Static => f.function.address,
|
||||
VMFunctionKind::Static => f.vm_function.address,
|
||||
};
|
||||
function_imports.push(VMFunctionImport {
|
||||
body: address,
|
||||
environment: f.function.vmctx,
|
||||
environment: f.vm_function.vmctx,
|
||||
});
|
||||
|
||||
host_function_env_initializers.push(f.function_ptr);
|
||||
host_function_env_initializers.push(f.import_init_function_ptr);
|
||||
}
|
||||
EngineExport::Table(ref t) => {
|
||||
Export::Table(ref t) => {
|
||||
table_imports.push(VMTableImport {
|
||||
definition: t.from.vmtable(),
|
||||
from: t.from.clone(),
|
||||
definition: t.vm_table.from.vmtable(),
|
||||
from: t.vm_table.from.clone(),
|
||||
});
|
||||
}
|
||||
EngineExport::Memory(ref m) => {
|
||||
Export::Memory(ref m) => {
|
||||
match import_index {
|
||||
ImportIndex::Memory(index) => {
|
||||
// Sanity-check: Ensure that the imported memory has at least
|
||||
// guard-page protections the importing module expects it to have.
|
||||
let export_memory_style = m.style();
|
||||
let export_memory_style = m.vm_memory.style();
|
||||
let import_memory_style = &memory_styles[*index];
|
||||
if let (
|
||||
MemoryStyle::Static { bound, .. },
|
||||
@@ -210,15 +210,15 @@ pub fn resolve_imports(
|
||||
}
|
||||
|
||||
memory_imports.push(VMMemoryImport {
|
||||
definition: m.from.vmmemory(),
|
||||
from: m.from.clone(),
|
||||
definition: m.vm_memory.from.vmmemory(),
|
||||
from: m.vm_memory.from.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
EngineExport::Global(ref g) => {
|
||||
Export::Global(ref g) => {
|
||||
global_imports.push(VMGlobalImport {
|
||||
definition: g.from.vmglobal(),
|
||||
from: g.from.clone(),
|
||||
definition: g.vm_global.from.vmglobal(),
|
||||
from: g.vm_global.from.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -303,7 +303,7 @@ where
|
||||
A: NamedResolver,
|
||||
B: NamedResolver,
|
||||
{
|
||||
fn resolve_by_name(&self, module: &str, field: &str) -> Option<EngineExport> {
|
||||
fn resolve_by_name(&self, module: &str, field: &str) -> Option<Export> {
|
||||
self.a
|
||||
.resolve_by_name(module, field)
|
||||
.or_else(|| self.b.resolve_by_name(module, field))
|
||||
|
||||
Reference in New Issue
Block a user