Rename vm::Export to vm::VMExport

This commit is contained in:
Mark McCaskey
2020-11-30 11:38:14 -08:00
parent 8669e92ed4
commit 9e0cfcebbb
9 changed files with 66 additions and 64 deletions

View File

@@ -14,8 +14,9 @@ use std::cmp::max;
use std::fmt; use std::fmt;
use wasmer_engine::{EngineExport, EngineExportFunction}; use wasmer_engine::{EngineExport, EngineExportFunction};
use wasmer_vm::{ use wasmer_vm::{
raise_user_trap, resume_panic, wasmer_call_trampoline, ExportFunction, VMCallerCheckedAnyfunc, raise_user_trap, resume_panic, wasmer_call_trampoline, VMCallerCheckedAnyfunc,
VMDynamicFunctionContext, VMFunctionBody, VMFunctionEnvironment, VMFunctionKind, VMTrampoline, VMDynamicFunctionContext, VMExportFunction, VMFunctionBody, VMFunctionEnvironment,
VMFunctionKind, VMTrampoline,
}; };
/// A function defined in the Wasm module /// A function defined in the Wasm module
@@ -97,7 +98,7 @@ impl Function {
definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: false }), definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: false }),
exported: EngineExportFunction { exported: EngineExportFunction {
function_ptr: None, function_ptr: None,
function: ExportFunction { function: VMExportFunction {
address, address,
kind: VMFunctionKind::Dynamic, kind: VMFunctionKind::Dynamic,
vmctx, vmctx,
@@ -159,7 +160,7 @@ impl Function {
definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: true }), definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: true }),
exported: EngineExportFunction { exported: EngineExportFunction {
function_ptr, function_ptr,
function: ExportFunction { function: VMExportFunction {
address, address,
kind: VMFunctionKind::Dynamic, kind: VMFunctionKind::Dynamic,
vmctx, vmctx,
@@ -209,7 +210,7 @@ impl Function {
// TODO: figure out what's going on in this function: it takes an `Env` // TODO: figure out what's going on in this function: it takes an `Env`
// param but also marks itself as not having an env // param but also marks itself as not having an env
function_ptr: None, function_ptr: None,
function: ExportFunction { function: VMExportFunction {
address, address,
vmctx, vmctx,
signature, signature,
@@ -275,7 +276,7 @@ impl Function {
definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: true }), definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: true }),
exported: EngineExportFunction { exported: EngineExportFunction {
function_ptr, function_ptr,
function: ExportFunction { function: VMExportFunction {
address, address,
kind: VMFunctionKind::Static, kind: VMFunctionKind::Static,
vmctx, vmctx,
@@ -324,7 +325,7 @@ impl Function {
definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: true }), definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: true }),
exported: EngineExportFunction { exported: EngineExportFunction {
function_ptr, function_ptr,
function: ExportFunction { function: VMExportFunction {
address, address,
kind: VMFunctionKind::Static, kind: VMFunctionKind::Static,
vmctx, vmctx,

View File

@@ -8,7 +8,7 @@ use crate::RuntimeError;
use std::fmt; use std::fmt;
use std::sync::Arc; use std::sync::Arc;
use wasmer_engine::EngineExport; use wasmer_engine::EngineExport;
use wasmer_vm::{ExportGlobal, Global as RuntimeGlobal}; use wasmer_vm::{Global as RuntimeGlobal, VMExportGlobal};
/// A WebAssembly `global` instance. /// A WebAssembly `global` instance.
/// ///
@@ -181,7 +181,7 @@ impl Global {
Ok(()) Ok(())
} }
pub(crate) fn from_export(store: &Store, wasmer_export: ExportGlobal) -> Self { pub(crate) fn from_export(store: &Store, wasmer_export: VMExportGlobal) -> Self {
Self { Self {
store: store.clone(), store: store.clone(),
global: wasmer_export.from, global: wasmer_export.from,
@@ -217,7 +217,7 @@ impl fmt::Debug for Global {
impl<'a> Exportable<'a> for Global { impl<'a> Exportable<'a> for Global {
fn to_export(&self) -> EngineExport { fn to_export(&self) -> EngineExport {
ExportGlobal { VMExportGlobal {
from: self.global.clone(), from: self.global.clone(),
} }
.into() .into()

View File

@@ -7,7 +7,7 @@ use std::slice;
use std::sync::Arc; use std::sync::Arc;
use wasmer_engine::EngineExport; use wasmer_engine::EngineExport;
use wasmer_types::{Pages, ValueType}; use wasmer_types::{Pages, ValueType};
use wasmer_vm::{ExportMemory, Memory as RuntimeMemory, MemoryError}; use wasmer_vm::{Memory as RuntimeMemory, MemoryError, VMExportMemory};
/// A WebAssembly `memory` instance. /// A WebAssembly `memory` instance.
/// ///
@@ -221,7 +221,7 @@ impl Memory {
unsafe { MemoryView::new(base as _, length as u32) } unsafe { MemoryView::new(base as _, length as u32) }
} }
pub(crate) fn from_export(store: &Store, wasmer_export: ExportMemory) -> Self { pub(crate) fn from_export(store: &Store, wasmer_export: VMExportMemory) -> Self {
Self { Self {
store: store.clone(), store: store.clone(),
memory: wasmer_export.from, memory: wasmer_export.from,
@@ -247,7 +247,7 @@ impl Memory {
impl<'a> Exportable<'a> for Memory { impl<'a> Exportable<'a> for Memory {
fn to_export(&self) -> EngineExport { fn to_export(&self) -> EngineExport {
ExportMemory { VMExportMemory {
from: self.memory.clone(), from: self.memory.clone(),
} }
.into() .into()

View File

@@ -6,7 +6,7 @@ use crate::RuntimeError;
use crate::TableType; use crate::TableType;
use std::sync::Arc; use std::sync::Arc;
use wasmer_engine::EngineExport; use wasmer_engine::EngineExport;
use wasmer_vm::{ExportTable, Table as RuntimeTable, VMCallerCheckedAnyfunc}; use wasmer_vm::{Table as RuntimeTable, VMCallerCheckedAnyfunc, VMExportTable};
/// A WebAssembly `table` instance. /// A WebAssembly `table` instance.
/// ///
@@ -140,7 +140,7 @@ impl Table {
Ok(()) Ok(())
} }
pub(crate) fn from_export(store: &Store, wasmer_export: ExportTable) -> Self { pub(crate) fn from_export(store: &Store, wasmer_export: VMExportTable) -> Self {
Self { Self {
store: store.clone(), store: store.clone(),
table: wasmer_export.from, table: wasmer_export.from,
@@ -155,7 +155,7 @@ impl Table {
impl<'a> Exportable<'a> for Table { impl<'a> Exportable<'a> for Table {
fn to_export(&self) -> EngineExport { fn to_export(&self) -> EngineExport {
ExportTable { VMExportTable {
from: self.table.clone(), from: self.table.clone(),
} }
.into() .into()

View File

@@ -89,7 +89,7 @@ pub use wasmer_types::{
}; };
// TODO: should those be moved into wasmer::vm as well? // TODO: should those be moved into wasmer::vm as well?
pub use wasmer_vm::{raise_user_trap, Export, MemoryError}; pub use wasmer_vm::{raise_user_trap, MemoryError, VMExport};
pub mod vm { pub mod vm {
//! We use the vm module for re-exporting wasmer-vm types //! We use the vm module for re-exporting wasmer-vm types

View File

@@ -18,7 +18,8 @@ use std::panic::{catch_unwind, AssertUnwindSafe};
use wasmer_engine::EngineExportFunction; use wasmer_engine::EngineExportFunction;
use wasmer_types::NativeWasmType; use wasmer_types::NativeWasmType;
use wasmer_vm::{ use wasmer_vm::{
ExportFunction, VMDynamicFunctionContext, VMFunctionBody, VMFunctionEnvironment, VMFunctionKind, VMDynamicFunctionContext, VMExportFunction, VMFunctionBody, VMFunctionEnvironment,
VMFunctionKind,
}; };
/// A WebAssembly function that can be called natively /// A WebAssembly function that can be called natively
@@ -59,7 +60,7 @@ where
} }
/* /*
impl<Args, Rets> From<&NativeFunc<Args, Rets>> for ExportFunction impl<Args, Rets> From<&NativeFunc<Args, Rets>> for VMExportFunction
where where
Args: WasmTypeList, Args: WasmTypeList,
Rets: WasmTypeList, Rets: WasmTypeList,
@@ -86,7 +87,7 @@ where
Self { Self {
// TODO: // TODO:
function_ptr: None, function_ptr: None,
function: ExportFunction { function: VMExportFunction {
address: other.address, address: other.address,
vmctx: other.vmctx, vmctx: other.vmctx,
signature, signature,
@@ -110,7 +111,7 @@ where
exported: EngineExportFunction { exported: EngineExportFunction {
// TODO: // TODO:
function_ptr: None, function_ptr: None,
function: ExportFunction { function: VMExportFunction {
address: other.address, address: other.address,
vmctx: other.vmctx, vmctx: other.vmctx,
signature, signature,

View File

@@ -77,7 +77,7 @@ impl ValFuncRef for Val {
// TODO: // TODO:
// figure out if we ever need a value here: need testing with complicated import patterns // figure out if we ever need a value here: need testing with complicated import patterns
function_ptr: None, function_ptr: None,
function: wasmer_vm::ExportFunction { function: wasmer_vm::VMExportFunction {
address: item.func_ptr, address: item.func_ptr,
signature, signature,
// All functions in tables are already Static (as dynamic functions // All functions in tables are already Static (as dynamic functions

View File

@@ -10,23 +10,23 @@ use wasmer_types::{FunctionType, MemoryType, TableType};
/// The value of an export passed from one instance to another. /// The value of an export passed from one instance to another.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Export { pub enum VMExport {
/// A function export value. /// A function export value.
Function(ExportFunction), Function(VMExportFunction),
/// A table export value. /// A table export value.
Table(ExportTable), Table(VMExportTable),
/// A memory export value. /// A memory export value.
Memory(ExportMemory), Memory(VMExportMemory),
/// A global export value. /// A global export value.
Global(ExportGlobal), Global(VMExportGlobal),
} }
/// A function export value. /// A function export value.
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub struct ExportFunction { pub struct VMExportFunction {
/// The address of the native-code function. /// The address of the native-code function.
pub address: *const VMFunctionBody, pub address: *const VMFunctionBody,
/// Pointer to the containing `VMContext`. /// Pointer to the containing `VMContext`.
@@ -43,20 +43,20 @@ pub struct ExportFunction {
/// # Safety /// # Safety
/// There is no non-threadsafe logic directly in this type. Calling the function /// There is no non-threadsafe logic directly in this type. Calling the function
/// may not be threadsafe. /// may not be threadsafe.
unsafe impl Send for ExportFunction {} unsafe impl Send for VMExportFunction {}
/// # Safety /// # Safety
/// The members of an ExportFunction are immutable after construction. /// The members of an VMExportFunction are immutable after construction.
unsafe impl Sync for ExportFunction {} unsafe impl Sync for VMExportFunction {}
impl From<ExportFunction> for Export { impl From<VMExportFunction> for VMExport {
fn from(func: ExportFunction) -> Self { fn from(func: VMExportFunction) -> Self {
Self::Function(func) Self::Function(func)
} }
} }
/// A table export value. /// A table export value.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ExportTable { pub struct VMExportTable {
/// Pointer to the containing `Table`. /// Pointer to the containing `Table`.
pub from: Arc<dyn Table>, pub from: Arc<dyn Table>,
} }
@@ -65,14 +65,14 @@ pub struct ExportTable {
/// This is correct because there is no non-threadsafe logic directly in this type; /// This is correct because there is no non-threadsafe logic directly in this type;
/// correct use of the raw table from multiple threads via `definition` requires `unsafe` /// correct use of the raw table from multiple threads via `definition` requires `unsafe`
/// and is the responsibilty of the user of this type. /// and is the responsibilty of the user of this type.
unsafe impl Send for ExportTable {} unsafe impl Send for VMExportTable {}
/// # Safety /// # Safety
/// This is correct because the values directly in `definition` should be considered immutable /// This is correct because the values directly in `definition` should be considered immutable
/// and the type is both `Send` and `Clone` (thus marking it `Sync` adds no new behavior, it /// and the type is both `Send` and `Clone` (thus marking it `Sync` adds no new behavior, it
/// only makes this type easier to use) /// only makes this type easier to use)
unsafe impl Sync for ExportTable {} unsafe impl Sync for VMExportTable {}
impl ExportTable { impl VMExportTable {
/// Get the table type for this exported table /// Get the table type for this exported table
pub fn ty(&self) -> &TableType { pub fn ty(&self) -> &TableType {
self.from.ty() self.from.ty()
@@ -83,21 +83,21 @@ impl ExportTable {
self.from.style() self.from.style()
} }
/// Returns whether or not the two `ExportTable`s refer to the same Memory. /// Returns whether or not the two `VMExportTable`s refer to the same Memory.
pub fn same(&self, other: &Self) -> bool { pub fn same(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.from, &other.from) Arc::ptr_eq(&self.from, &other.from)
} }
} }
impl From<ExportTable> for Export { impl From<VMExportTable> for VMExport {
fn from(table: ExportTable) -> Self { fn from(table: VMExportTable) -> Self {
Self::Table(table) Self::Table(table)
} }
} }
/// A memory export value. /// A memory export value.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ExportMemory { pub struct VMExportMemory {
/// Pointer to the containing `Memory`. /// Pointer to the containing `Memory`.
pub from: Arc<dyn Memory>, pub from: Arc<dyn Memory>,
} }
@@ -106,14 +106,14 @@ pub struct ExportMemory {
/// This is correct because there is no non-threadsafe logic directly in this type; /// This is correct because there is no non-threadsafe logic directly in this type;
/// correct use of the raw memory from multiple threads via `definition` requires `unsafe` /// correct use of the raw memory from multiple threads via `definition` requires `unsafe`
/// and is the responsibilty of the user of this type. /// and is the responsibilty of the user of this type.
unsafe impl Send for ExportMemory {} unsafe impl Send for VMExportMemory {}
/// # Safety /// # Safety
/// This is correct because the values directly in `definition` should be considered immutable /// This is correct because the values directly in `definition` should be considered immutable
/// and the type is both `Send` and `Clone` (thus marking it `Sync` adds no new behavior, it /// and the type is both `Send` and `Clone` (thus marking it `Sync` adds no new behavior, it
/// only makes this type easier to use) /// only makes this type easier to use)
unsafe impl Sync for ExportMemory {} unsafe impl Sync for VMExportMemory {}
impl ExportMemory { impl VMExportMemory {
/// Get the type for this exported memory /// Get the type for this exported memory
pub fn ty(&self) -> &MemoryType { pub fn ty(&self) -> &MemoryType {
self.from.ty() self.from.ty()
@@ -124,21 +124,21 @@ impl ExportMemory {
self.from.style() self.from.style()
} }
/// Returns whether or not the two `ExportMemory`s refer to the same Memory. /// Returns whether or not the two `VMExportMemory`s refer to the same Memory.
pub fn same(&self, other: &Self) -> bool { pub fn same(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.from, &other.from) Arc::ptr_eq(&self.from, &other.from)
} }
} }
impl From<ExportMemory> for Export { impl From<VMExportMemory> for VMExport {
fn from(memory: ExportMemory) -> Self { fn from(memory: VMExportMemory) -> Self {
Self::Memory(memory) Self::Memory(memory)
} }
} }
/// A global export value. /// A global export value.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ExportGlobal { pub struct VMExportGlobal {
/// The global declaration, used for compatibility checking. /// The global declaration, used for compatibility checking.
pub from: Arc<Global>, pub from: Arc<Global>,
} }
@@ -147,22 +147,22 @@ pub struct ExportGlobal {
/// This is correct because there is no non-threadsafe logic directly in this type; /// This is correct because there is no non-threadsafe logic directly in this type;
/// correct use of the raw global from multiple threads via `definition` requires `unsafe` /// correct use of the raw global from multiple threads via `definition` requires `unsafe`
/// and is the responsibilty of the user of this type. /// and is the responsibilty of the user of this type.
unsafe impl Send for ExportGlobal {} unsafe impl Send for VMExportGlobal {}
/// # Safety /// # Safety
/// This is correct because the values directly in `definition` should be considered immutable /// This is correct because the values directly in `definition` should be considered immutable
/// from the perspective of users of this type and the type is both `Send` and `Clone` (thus /// from the perspective of users of this type and the type is both `Send` and `Clone` (thus
/// marking it `Sync` adds no new behavior, it only makes this type easier to use) /// marking it `Sync` adds no new behavior, it only makes this type easier to use)
unsafe impl Sync for ExportGlobal {} unsafe impl Sync for VMExportGlobal {}
impl ExportGlobal { impl VMExportGlobal {
/// Returns whether or not the two `ExportGlobal`s refer to the same Global. /// Returns whether or not the two `VMExportGlobal`s refer to the same Global.
pub fn same(&self, other: &Self) -> bool { pub fn same(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.from, &other.from) Arc::ptr_eq(&self.from, &other.from)
} }
} }
impl From<ExportGlobal> for Export { impl From<VMExportGlobal> for VMExport {
fn from(global: ExportGlobal) -> Self { fn from(global: VMExportGlobal) -> Self {
Self::Global(global) Self::Global(global)
} }
} }

View File

@@ -4,7 +4,7 @@
//! An `Instance` contains all the runtime state used by execution of a //! An `Instance` contains all the runtime state used by execution of a
//! wasm module (except its callstack and register state). An //! wasm module (except its callstack and register state). An
//! `InstanceHandle` is a reference-counting handle for an `Instance`. //! `InstanceHandle` is a reference-counting handle for an `Instance`.
use crate::export::Export; use crate::export::VMExport;
use crate::global::Global; use crate::global::Global;
use crate::imports::Imports; use crate::imports::Imports;
use crate::memory::{Memory, MemoryError}; use crate::memory::{Memory, MemoryError};
@@ -16,8 +16,8 @@ use crate::vmcontext::{
VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport,
VMTrampoline, VMTrampoline,
}; };
use crate::{ExportFunction, ExportGlobal, ExportMemory, ExportTable};
use crate::{FunctionBodyPtr, ModuleInfo, VMOffsets}; use crate::{FunctionBodyPtr, ModuleInfo, VMOffsets};
use crate::{VMExportFunction, VMExportGlobal, VMExportMemory, VMExportTable};
use memoffset::offset_of; use memoffset::offset_of;
use more_asserts::assert_lt; use more_asserts::assert_lt;
use std::alloc::{self, Layout}; use std::alloc::{self, Layout};
@@ -308,7 +308,7 @@ impl Instance {
} }
/// Lookup an export with the given name. /// Lookup an export with the given name.
pub fn lookup(&self, field: &str) -> Option<Export> { pub fn lookup(&self, field: &str) -> Option<VMExport> {
let export = self.module.exports.get(field)?; let export = self.module.exports.get(field)?;
Some(self.lookup_by_declaration(&export)) Some(self.lookup_by_declaration(&export))
@@ -316,7 +316,7 @@ impl Instance {
/// Lookup an export with the given export declaration. /// Lookup an export with the given export declaration.
// TODO: maybe EngineExport // TODO: maybe EngineExport
pub fn lookup_by_declaration(&self, export: &ExportIndex) -> Export { pub fn lookup_by_declaration(&self, export: &ExportIndex) -> VMExport {
match export { match export {
ExportIndex::Function(index) => { ExportIndex::Function(index) => {
let sig_index = &self.module.functions[*index]; let sig_index = &self.module.functions[*index];
@@ -339,7 +339,7 @@ impl Instance {
/*EngineExportFunction { /*EngineExportFunction {
function_ptr, function_ptr,
function: */ function: */
ExportFunction { VMExportFunction {
address, address,
// Any function received is already static at this point as: // Any function received is already static at this point as:
// 1. All locally defined functions in the Wasm have a static signature. // 1. All locally defined functions in the Wasm have a static signature.
@@ -360,7 +360,7 @@ impl Instance {
let import = self.imported_table(*index); let import = self.imported_table(*index);
import.from.clone() import.from.clone()
}; };
ExportTable { from }.into() VMExportTable { from }.into()
} }
ExportIndex::Memory(index) => { ExportIndex::Memory(index) => {
let from = if let Some(def_index) = self.module.local_memory_index(*index) { let from = if let Some(def_index) = self.module.local_memory_index(*index) {
@@ -369,7 +369,7 @@ impl Instance {
let import = self.imported_memory(*index); let import = self.imported_memory(*index);
import.from.clone() import.from.clone()
}; };
ExportMemory { from }.into() VMExportMemory { from }.into()
} }
ExportIndex::Global(index) => { ExportIndex::Global(index) => {
let from = { let from = {
@@ -380,7 +380,7 @@ impl Instance {
import.from.clone() import.from.clone()
} }
}; };
ExportGlobal { from }.into() VMExportGlobal { from }.into()
} }
} }
} }
@@ -1072,12 +1072,12 @@ impl InstanceHandle {
} }
/// Lookup an export with the given name. /// Lookup an export with the given name.
pub fn lookup(&self, field: &str) -> Option<Export> { pub fn lookup(&self, field: &str) -> Option<VMExport> {
self.instance().lookup(field) self.instance().lookup(field)
} }
/// Lookup an export with the given export declaration. /// Lookup an export with the given export declaration.
pub fn lookup_by_declaration(&self, export: &ExportIndex) -> Export { pub fn lookup_by_declaration(&self, export: &ExportIndex) -> VMExport {
self.instance().lookup_by_declaration(export) self.instance().lookup_by_declaration(export)
} }