mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-10 22:58:18 +00:00
Implemented shared memory for Wasmer in preparation for multithreading
Fixed linter Fixed clippy Cleaned up some merge leftover
This commit is contained in:
committed by
ptitSeb
parent
0928629051
commit
a5f641b4b0
@@ -73,7 +73,6 @@ pub use crate::js::value::Value as Val;
|
||||
|
||||
pub mod vm {
|
||||
//! The `vm` module re-exports wasmer-vm types.
|
||||
|
||||
pub use crate::js::export::VMMemory;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
//! The import module contains the implementation data structures and helper functions used to
|
||||
//! manipulate and access a wasm module's imports including memories, tables, globals, and
|
||||
//! functions.
|
||||
use crate::{Exports, Extern, Module};
|
||||
use crate::{AsStoreMut, Exports, Extern, Memory, Module};
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use wasmer_compiler::LinkError;
|
||||
use wasmer_types::ImportError;
|
||||
use wasmer_vm::VMSharedMemory;
|
||||
|
||||
/// All of the import data used when instantiating.
|
||||
///
|
||||
@@ -111,6 +112,36 @@ impl Imports {
|
||||
.insert((ns.to_string(), name.to_string()), val.into());
|
||||
}
|
||||
|
||||
/// Imports (any) shared memory into the imports.
|
||||
/// (if the module does not import memory then this function is ignored)
|
||||
pub fn import_shared_memory(
|
||||
&mut self,
|
||||
module: &Module,
|
||||
store: &mut impl AsStoreMut,
|
||||
) -> Option<VMSharedMemory> {
|
||||
// Determine if shared memory needs to be created and imported
|
||||
let shared_memory = module
|
||||
.imports()
|
||||
.memories()
|
||||
.next()
|
||||
.map(|a| *a.ty())
|
||||
.map(|ty| {
|
||||
let style = store.as_store_ref().tunables().memory_style(&ty);
|
||||
VMSharedMemory::new(&ty, &style).unwrap()
|
||||
});
|
||||
|
||||
if let Some(memory) = shared_memory {
|
||||
self.define(
|
||||
"env",
|
||||
"memory",
|
||||
Memory::new_from_existing(store, memory.clone().into()),
|
||||
);
|
||||
Some(memory)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the contents of a namespace as an `Exports`.
|
||||
///
|
||||
/// Returns `None` if the namespace doesn't exist.
|
||||
|
||||
@@ -57,8 +57,8 @@ pub mod vm {
|
||||
//! The `vm` module re-exports wasmer-vm types.
|
||||
|
||||
pub use wasmer_vm::{
|
||||
MemoryError, MemoryStyle, TableStyle, VMExtern, VMMemory, VMMemoryDefinition, VMTable,
|
||||
VMTableDefinition,
|
||||
MemoryError, MemoryStyle, TableStyle, VMExtern, VMMemory, VMMemoryDefinition,
|
||||
VMOwnedMemory, VMSharedMemory, VMTable, VMTableDefinition,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user