mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 21:28:21 +00:00
Rename vm::Export to vm::VMExport
This commit is contained in:
15
lib/api/src/externals/function.rs
vendored
15
lib/api/src/externals/function.rs
vendored
@@ -14,8 +14,9 @@ use std::cmp::max;
|
||||
use std::fmt;
|
||||
use wasmer_engine::{EngineExport, EngineExportFunction};
|
||||
use wasmer_vm::{
|
||||
raise_user_trap, resume_panic, wasmer_call_trampoline, ExportFunction, VMCallerCheckedAnyfunc,
|
||||
VMDynamicFunctionContext, VMFunctionBody, VMFunctionEnvironment, VMFunctionKind, VMTrampoline,
|
||||
raise_user_trap, resume_panic, wasmer_call_trampoline, VMCallerCheckedAnyfunc,
|
||||
VMDynamicFunctionContext, VMExportFunction, VMFunctionBody, VMFunctionEnvironment,
|
||||
VMFunctionKind, VMTrampoline,
|
||||
};
|
||||
|
||||
/// A function defined in the Wasm module
|
||||
@@ -97,7 +98,7 @@ impl Function {
|
||||
definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: false }),
|
||||
exported: EngineExportFunction {
|
||||
function_ptr: None,
|
||||
function: ExportFunction {
|
||||
function: VMExportFunction {
|
||||
address,
|
||||
kind: VMFunctionKind::Dynamic,
|
||||
vmctx,
|
||||
@@ -159,7 +160,7 @@ impl Function {
|
||||
definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: true }),
|
||||
exported: EngineExportFunction {
|
||||
function_ptr,
|
||||
function: ExportFunction {
|
||||
function: VMExportFunction {
|
||||
address,
|
||||
kind: VMFunctionKind::Dynamic,
|
||||
vmctx,
|
||||
@@ -209,7 +210,7 @@ impl Function {
|
||||
// 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: ExportFunction {
|
||||
function: VMExportFunction {
|
||||
address,
|
||||
vmctx,
|
||||
signature,
|
||||
@@ -275,7 +276,7 @@ impl Function {
|
||||
definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: true }),
|
||||
exported: EngineExportFunction {
|
||||
function_ptr,
|
||||
function: ExportFunction {
|
||||
function: VMExportFunction {
|
||||
address,
|
||||
kind: VMFunctionKind::Static,
|
||||
vmctx,
|
||||
@@ -324,7 +325,7 @@ impl Function {
|
||||
definition: FunctionDefinition::Host(HostFunctionDefinition { has_env: true }),
|
||||
exported: EngineExportFunction {
|
||||
function_ptr,
|
||||
function: ExportFunction {
|
||||
function: VMExportFunction {
|
||||
address,
|
||||
kind: VMFunctionKind::Static,
|
||||
vmctx,
|
||||
|
||||
6
lib/api/src/externals/global.rs
vendored
6
lib/api/src/externals/global.rs
vendored
@@ -8,7 +8,7 @@ use crate::RuntimeError;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use wasmer_engine::EngineExport;
|
||||
use wasmer_vm::{ExportGlobal, Global as RuntimeGlobal};
|
||||
use wasmer_vm::{Global as RuntimeGlobal, VMExportGlobal};
|
||||
|
||||
/// A WebAssembly `global` instance.
|
||||
///
|
||||
@@ -181,7 +181,7 @@ impl Global {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn from_export(store: &Store, wasmer_export: ExportGlobal) -> Self {
|
||||
pub(crate) fn from_export(store: &Store, wasmer_export: VMExportGlobal) -> Self {
|
||||
Self {
|
||||
store: store.clone(),
|
||||
global: wasmer_export.from,
|
||||
@@ -217,7 +217,7 @@ impl fmt::Debug for Global {
|
||||
|
||||
impl<'a> Exportable<'a> for Global {
|
||||
fn to_export(&self) -> EngineExport {
|
||||
ExportGlobal {
|
||||
VMExportGlobal {
|
||||
from: self.global.clone(),
|
||||
}
|
||||
.into()
|
||||
|
||||
6
lib/api/src/externals/memory.rs
vendored
6
lib/api/src/externals/memory.rs
vendored
@@ -7,7 +7,7 @@ use std::slice;
|
||||
use std::sync::Arc;
|
||||
use wasmer_engine::EngineExport;
|
||||
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.
|
||||
///
|
||||
@@ -221,7 +221,7 @@ impl Memory {
|
||||
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 {
|
||||
store: store.clone(),
|
||||
memory: wasmer_export.from,
|
||||
@@ -247,7 +247,7 @@ impl Memory {
|
||||
|
||||
impl<'a> Exportable<'a> for Memory {
|
||||
fn to_export(&self) -> EngineExport {
|
||||
ExportMemory {
|
||||
VMExportMemory {
|
||||
from: self.memory.clone(),
|
||||
}
|
||||
.into()
|
||||
|
||||
6
lib/api/src/externals/table.rs
vendored
6
lib/api/src/externals/table.rs
vendored
@@ -6,7 +6,7 @@ use crate::RuntimeError;
|
||||
use crate::TableType;
|
||||
use std::sync::Arc;
|
||||
use wasmer_engine::EngineExport;
|
||||
use wasmer_vm::{ExportTable, Table as RuntimeTable, VMCallerCheckedAnyfunc};
|
||||
use wasmer_vm::{Table as RuntimeTable, VMCallerCheckedAnyfunc, VMExportTable};
|
||||
|
||||
/// A WebAssembly `table` instance.
|
||||
///
|
||||
@@ -140,7 +140,7 @@ impl Table {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn from_export(store: &Store, wasmer_export: ExportTable) -> Self {
|
||||
pub(crate) fn from_export(store: &Store, wasmer_export: VMExportTable) -> Self {
|
||||
Self {
|
||||
store: store.clone(),
|
||||
table: wasmer_export.from,
|
||||
@@ -155,7 +155,7 @@ impl Table {
|
||||
|
||||
impl<'a> Exportable<'a> for Table {
|
||||
fn to_export(&self) -> EngineExport {
|
||||
ExportTable {
|
||||
VMExportTable {
|
||||
from: self.table.clone(),
|
||||
}
|
||||
.into()
|
||||
|
||||
@@ -89,7 +89,7 @@ pub use wasmer_types::{
|
||||
};
|
||||
|
||||
// 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 {
|
||||
//! We use the vm module for re-exporting wasmer-vm types
|
||||
|
||||
|
||||
@@ -18,7 +18,8 @@ use std::panic::{catch_unwind, AssertUnwindSafe};
|
||||
use wasmer_engine::EngineExportFunction;
|
||||
use wasmer_types::NativeWasmType;
|
||||
use wasmer_vm::{
|
||||
ExportFunction, VMDynamicFunctionContext, VMFunctionBody, VMFunctionEnvironment, VMFunctionKind,
|
||||
VMDynamicFunctionContext, VMExportFunction, VMFunctionBody, VMFunctionEnvironment,
|
||||
VMFunctionKind,
|
||||
};
|
||||
|
||||
/// 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
|
||||
Args: WasmTypeList,
|
||||
Rets: WasmTypeList,
|
||||
@@ -86,7 +87,7 @@ where
|
||||
Self {
|
||||
// TODO:
|
||||
function_ptr: None,
|
||||
function: ExportFunction {
|
||||
function: VMExportFunction {
|
||||
address: other.address,
|
||||
vmctx: other.vmctx,
|
||||
signature,
|
||||
@@ -110,7 +111,7 @@ where
|
||||
exported: EngineExportFunction {
|
||||
// TODO:
|
||||
function_ptr: None,
|
||||
function: ExportFunction {
|
||||
function: VMExportFunction {
|
||||
address: other.address,
|
||||
vmctx: other.vmctx,
|
||||
signature,
|
||||
|
||||
@@ -77,7 +77,7 @@ impl ValFuncRef for Val {
|
||||
// TODO:
|
||||
// figure out if we ever need a value here: need testing with complicated import patterns
|
||||
function_ptr: None,
|
||||
function: wasmer_vm::ExportFunction {
|
||||
function: wasmer_vm::VMExportFunction {
|
||||
address: item.func_ptr,
|
||||
signature,
|
||||
// All functions in tables are already Static (as dynamic functions
|
||||
|
||||
@@ -10,23 +10,23 @@ use wasmer_types::{FunctionType, MemoryType, TableType};
|
||||
|
||||
/// The value of an export passed from one instance to another.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Export {
|
||||
pub enum VMExport {
|
||||
/// A function export value.
|
||||
Function(ExportFunction),
|
||||
Function(VMExportFunction),
|
||||
|
||||
/// A table export value.
|
||||
Table(ExportTable),
|
||||
Table(VMExportTable),
|
||||
|
||||
/// A memory export value.
|
||||
Memory(ExportMemory),
|
||||
Memory(VMExportMemory),
|
||||
|
||||
/// A global export value.
|
||||
Global(ExportGlobal),
|
||||
Global(VMExportGlobal),
|
||||
}
|
||||
|
||||
/// A function export value.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ExportFunction {
|
||||
pub struct VMExportFunction {
|
||||
/// The address of the native-code function.
|
||||
pub address: *const VMFunctionBody,
|
||||
/// Pointer to the containing `VMContext`.
|
||||
@@ -43,20 +43,20 @@ pub struct ExportFunction {
|
||||
/// # Safety
|
||||
/// There is no non-threadsafe logic directly in this type. Calling the function
|
||||
/// may not be threadsafe.
|
||||
unsafe impl Send for ExportFunction {}
|
||||
unsafe impl Send for VMExportFunction {}
|
||||
/// # Safety
|
||||
/// The members of an ExportFunction are immutable after construction.
|
||||
unsafe impl Sync for ExportFunction {}
|
||||
/// The members of an VMExportFunction are immutable after construction.
|
||||
unsafe impl Sync for VMExportFunction {}
|
||||
|
||||
impl From<ExportFunction> for Export {
|
||||
fn from(func: ExportFunction) -> Self {
|
||||
impl From<VMExportFunction> for VMExport {
|
||||
fn from(func: VMExportFunction) -> Self {
|
||||
Self::Function(func)
|
||||
}
|
||||
}
|
||||
|
||||
/// A table export value.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ExportTable {
|
||||
pub struct VMExportTable {
|
||||
/// Pointer to the containing `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;
|
||||
/// correct use of the raw table from multiple threads via `definition` requires `unsafe`
|
||||
/// and is the responsibilty of the user of this type.
|
||||
unsafe impl Send for ExportTable {}
|
||||
unsafe impl Send for VMExportTable {}
|
||||
/// # Safety
|
||||
/// 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
|
||||
/// 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
|
||||
pub fn ty(&self) -> &TableType {
|
||||
self.from.ty()
|
||||
@@ -83,21 +83,21 @@ impl ExportTable {
|
||||
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 {
|
||||
Arc::ptr_eq(&self.from, &other.from)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ExportTable> for Export {
|
||||
fn from(table: ExportTable) -> Self {
|
||||
impl From<VMExportTable> for VMExport {
|
||||
fn from(table: VMExportTable) -> Self {
|
||||
Self::Table(table)
|
||||
}
|
||||
}
|
||||
|
||||
/// A memory export value.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ExportMemory {
|
||||
pub struct VMExportMemory {
|
||||
/// Pointer to the containing `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;
|
||||
/// correct use of the raw memory from multiple threads via `definition` requires `unsafe`
|
||||
/// and is the responsibilty of the user of this type.
|
||||
unsafe impl Send for ExportMemory {}
|
||||
unsafe impl Send for VMExportMemory {}
|
||||
/// # Safety
|
||||
/// 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
|
||||
/// 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
|
||||
pub fn ty(&self) -> &MemoryType {
|
||||
self.from.ty()
|
||||
@@ -124,21 +124,21 @@ impl ExportMemory {
|
||||
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 {
|
||||
Arc::ptr_eq(&self.from, &other.from)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ExportMemory> for Export {
|
||||
fn from(memory: ExportMemory) -> Self {
|
||||
impl From<VMExportMemory> for VMExport {
|
||||
fn from(memory: VMExportMemory) -> Self {
|
||||
Self::Memory(memory)
|
||||
}
|
||||
}
|
||||
|
||||
/// A global export value.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ExportGlobal {
|
||||
pub struct VMExportGlobal {
|
||||
/// The global declaration, used for compatibility checking.
|
||||
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;
|
||||
/// correct use of the raw global from multiple threads via `definition` requires `unsafe`
|
||||
/// and is the responsibilty of the user of this type.
|
||||
unsafe impl Send for ExportGlobal {}
|
||||
unsafe impl Send for VMExportGlobal {}
|
||||
/// # Safety
|
||||
/// 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
|
||||
/// 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 {
|
||||
/// Returns whether or not the two `ExportGlobal`s refer to the same Global.
|
||||
impl VMExportGlobal {
|
||||
/// Returns whether or not the two `VMExportGlobal`s refer to the same Global.
|
||||
pub fn same(&self, other: &Self) -> bool {
|
||||
Arc::ptr_eq(&self.from, &other.from)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ExportGlobal> for Export {
|
||||
fn from(global: ExportGlobal) -> Self {
|
||||
impl From<VMExportGlobal> for VMExport {
|
||||
fn from(global: VMExportGlobal) -> Self {
|
||||
Self::Global(global)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! An `Instance` contains all the runtime state used by execution of a
|
||||
//! wasm module (except its callstack and register state). An
|
||||
//! `InstanceHandle` is a reference-counting handle for an `Instance`.
|
||||
use crate::export::Export;
|
||||
use crate::export::VMExport;
|
||||
use crate::global::Global;
|
||||
use crate::imports::Imports;
|
||||
use crate::memory::{Memory, MemoryError};
|
||||
@@ -16,8 +16,8 @@ use crate::vmcontext::{
|
||||
VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport,
|
||||
VMTrampoline,
|
||||
};
|
||||
use crate::{ExportFunction, ExportGlobal, ExportMemory, ExportTable};
|
||||
use crate::{FunctionBodyPtr, ModuleInfo, VMOffsets};
|
||||
use crate::{VMExportFunction, VMExportGlobal, VMExportMemory, VMExportTable};
|
||||
use memoffset::offset_of;
|
||||
use more_asserts::assert_lt;
|
||||
use std::alloc::{self, Layout};
|
||||
@@ -308,7 +308,7 @@ impl Instance {
|
||||
}
|
||||
|
||||
/// 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)?;
|
||||
|
||||
Some(self.lookup_by_declaration(&export))
|
||||
@@ -316,7 +316,7 @@ impl Instance {
|
||||
|
||||
/// Lookup an export with the given export declaration.
|
||||
// TODO: maybe EngineExport
|
||||
pub fn lookup_by_declaration(&self, export: &ExportIndex) -> Export {
|
||||
pub fn lookup_by_declaration(&self, export: &ExportIndex) -> VMExport {
|
||||
match export {
|
||||
ExportIndex::Function(index) => {
|
||||
let sig_index = &self.module.functions[*index];
|
||||
@@ -339,7 +339,7 @@ impl Instance {
|
||||
/*EngineExportFunction {
|
||||
function_ptr,
|
||||
function: */
|
||||
ExportFunction {
|
||||
VMExportFunction {
|
||||
address,
|
||||
// Any function received is already static at this point as:
|
||||
// 1. All locally defined functions in the Wasm have a static signature.
|
||||
@@ -360,7 +360,7 @@ impl Instance {
|
||||
let import = self.imported_table(*index);
|
||||
import.from.clone()
|
||||
};
|
||||
ExportTable { from }.into()
|
||||
VMExportTable { from }.into()
|
||||
}
|
||||
ExportIndex::Memory(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);
|
||||
import.from.clone()
|
||||
};
|
||||
ExportMemory { from }.into()
|
||||
VMExportMemory { from }.into()
|
||||
}
|
||||
ExportIndex::Global(index) => {
|
||||
let from = {
|
||||
@@ -380,7 +380,7 @@ impl Instance {
|
||||
import.from.clone()
|
||||
}
|
||||
};
|
||||
ExportGlobal { from }.into()
|
||||
VMExportGlobal { from }.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1072,12 +1072,12 @@ impl InstanceHandle {
|
||||
}
|
||||
|
||||
/// 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)
|
||||
}
|
||||
|
||||
/// 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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user