Option for host managed memory (#1400)
* Option for host managed memory * Rename Allocator to MemoryCreator * Create LinearMemory and MemoryCreator traits in api * Leave only one as_ptr function in LinearMemory trait * Memory creator test * Update comments/docs for LinearMemory and MemoryCreator traits * Add guard page to the custom memory example * Remove mut from LinearMemory trait as_ptr * Host_memory_grow test
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use crate::externals::MemoryCreator;
|
||||
use crate::trampoline::MemoryCreatorProxy;
|
||||
use anyhow::Result;
|
||||
use std::cell::RefCell;
|
||||
use std::fmt;
|
||||
@@ -9,6 +11,7 @@ use wasmtime_environ::settings::{self, Configurable};
|
||||
use wasmtime_environ::CacheConfig;
|
||||
use wasmtime_jit::{native, CompilationStrategy, Compiler};
|
||||
use wasmtime_profiling::{JitDumpAgent, NullProfilerAgent, ProfilingAgent, VTuneAgent};
|
||||
use wasmtime_runtime::RuntimeMemoryCreator;
|
||||
|
||||
// Runtime Environment
|
||||
|
||||
@@ -27,6 +30,7 @@ pub struct Config {
|
||||
pub(crate) strategy: CompilationStrategy,
|
||||
pub(crate) cache_config: CacheConfig,
|
||||
pub(crate) profiler: Arc<dyn ProfilingAgent>,
|
||||
pub(crate) memory_creator: Option<MemoryCreatorProxy>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
@@ -66,6 +70,7 @@ impl Config {
|
||||
strategy: CompilationStrategy::Auto,
|
||||
cache_config: CacheConfig::new_cache_disabled(),
|
||||
profiler: Arc::new(NullProfilerAgent),
|
||||
memory_creator: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,6 +331,12 @@ impl Config {
|
||||
self.cache_config = wasmtime_environ::CacheConfig::from_file(None)?;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
/// Sets a custom memory creator
|
||||
pub fn with_host_memory(&mut self, mem_creator: Arc<dyn MemoryCreator>) -> &mut Self {
|
||||
self.memory_creator = Some(MemoryCreatorProxy { mem_creator });
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
@@ -506,6 +517,11 @@ impl Store {
|
||||
&self.inner.engine
|
||||
}
|
||||
|
||||
/// Returns an optional reference to a ['RuntimeMemoryCreator']
|
||||
pub(crate) fn memory_creator(&self) -> Option<&dyn RuntimeMemoryCreator> {
|
||||
self.engine().config.memory_creator.as_ref().map(|x| x as _)
|
||||
}
|
||||
|
||||
pub(crate) fn compiler(&self) -> std::cell::Ref<'_, Compiler> {
|
||||
self.inner.compiler.borrow()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user