diff --git a/lib/api/src/js/vm.rs b/lib/api/src/js/vm.rs index 08e43ffc2..349663b00 100644 --- a/lib/api/src/js/vm.rs +++ b/lib/api/src/js/vm.rs @@ -109,6 +109,12 @@ impl VMMemory { } } +impl From for JsValue { + fn from(value: VMMemory) -> Self { + JsValue::from(value.memory) + } +} + #[derive(Clone, Debug, PartialEq)] pub struct VMGlobal { pub(crate) global: Global, diff --git a/lib/wasi/src/bin_factory/exec.rs b/lib/wasi/src/bin_factory/exec.rs index 803047f1e..7163b9d26 100644 --- a/lib/wasi/src/bin_factory/exec.rs +++ b/lib/wasi/src/bin_factory/exec.rs @@ -104,8 +104,7 @@ pub fn spawn_exec_module( let tasks_outer = tasks.clone(); let task = { - let mut store = store; - move |module, memory| { + move |mut store, module, memory| { // Create the WasiFunctionEnv let mut wasi_env = env; wasi_env.runtime = runtime; @@ -189,7 +188,7 @@ pub fn spawn_exec_module( }; tasks_outer - .task_wasm(Box::new(task), module, memory_spawn) + .task_wasm(Box::new(task), store, module, memory_spawn) .map_err(|err| { error!("wasi[{}]::failed to launch module - {}", pid, err); VirtualBusError::UnknownError diff --git a/lib/wasi/src/runtime/task_manager/mod.rs b/lib/wasi/src/runtime/task_manager/mod.rs index 96b69b8e6..372a351fc 100644 --- a/lib/wasi/src/runtime/task_manager/mod.rs +++ b/lib/wasi/src/runtime/task_manager/mod.rs @@ -6,7 +6,7 @@ use std::{pin::Pin, time::Duration}; use ::tokio::runtime::Handle; use futures::Future; -use wasmer::{MemoryType, Module}; +use wasmer::{MemoryType, Module, Store}; #[cfg(feature = "js")] use wasmer::VMMemory; @@ -69,7 +69,8 @@ pub trait VirtualTaskManager: std::fmt::Debug + Send + Sync + 'static { /// It is ok for this task to block execution and any async futures within its scope fn task_wasm( &self, - task: Box) + Send + 'static>, + task: Box) + Send + 'static>, + store: Store, module: Module, spawn_type: SpawnType, ) -> Result<(), WasiThreadError>; diff --git a/lib/wasi/src/runtime/task_manager/tokio.rs b/lib/wasi/src/runtime/task_manager/tokio.rs index 5554da0ef..48a35887c 100644 --- a/lib/wasi/src/runtime/task_manager/tokio.rs +++ b/lib/wasi/src/runtime/task_manager/tokio.rs @@ -4,7 +4,7 @@ use futures::Future; use tokio::runtime::Handle; use wasmer::{ vm::{VMMemory, VMSharedMemory}, - Module, + Module, Store, }; use crate::os::task::thread::WasiThreadError; @@ -125,14 +125,15 @@ impl VirtualTaskManager for TokioTaskManager { /// See [`VirtualTaskManager::enter`]. fn task_wasm( &self, - task: Box) + Send + 'static>, + task: Box) + Send + 'static>, + store: Store, module: Module, spawn_type: SpawnType, ) -> Result<(), WasiThreadError> { let memory = self.build_memory(spawn_type)?; self.0.spawn_blocking(move || { // Invoke the callback - task(module, memory); + task(store, module, memory); }); Ok(()) } diff --git a/lib/wasi/src/syscalls/wasix/proc_fork.rs b/lib/wasi/src/syscalls/wasix/proc_fork.rs index 69100d46c..26622acd8 100644 --- a/lib/wasi/src/syscalls/wasix/proc_fork.rs +++ b/lib/wasi/src/syscalls/wasix/proc_fork.rs @@ -191,11 +191,11 @@ pub fn proc_fork( let tasks = tasks.clone(); let tasks_outer = tasks.clone(); - let mut store = fork_store; + let store = fork_store; let module = fork_module; let spawn_type = SpawnType::NewThread(fork_memory); - let task = move |module, memory| { + let task = move |mut store, module, memory| { // Create the WasiFunctionEnv let pid = child_env.pid(); let tid = child_env.tid(); @@ -286,7 +286,7 @@ pub fn proc_fork( }; tasks_outer - .task_wasm(Box::new(task), module, spawn_type) + .task_wasm(Box::new(task), store, module, spawn_type) .map_err(|err| { warn!( "wasi[{}:{}]::failed to fork as the process could not be spawned - {}", diff --git a/lib/wasi/src/syscalls/wasix/thread_spawn.rs b/lib/wasi/src/syscalls/wasix/thread_spawn.rs index a61cbd02b..fb650f9ea 100644 --- a/lib/wasi/src/syscalls/wasix/thread_spawn.rs +++ b/lib/wasi/src/syscalls/wasix/thread_spawn.rs @@ -299,14 +299,14 @@ pub fn thread_spawn( let thread_module = env.inner().instance.module().clone(); let tasks2 = tasks.clone(); - let task = move |thread_module, mut thread_memory| { + let task = move |store, thread_module, mut thread_memory| { // FIXME: should not use unwrap() here! (initializiation refactor) let mut store = Some(store); execute_module(&mut store, thread_module, &mut thread_memory); }; wasi_try!(tasks - .task_wasm(Box::new(task), thread_module, spawn_type) + .task_wasm(Box::new(task), store, thread_module, spawn_type) .map_err(|err| { Into::::into(err) })); } _ => {