The VMMemory must be convertable into a JsValue

This commit is contained in:
Johnathan Sharratt
2023-03-01 17:30:00 +11:00
committed by Christoph Herzog
parent 52bf78eb37
commit e2276c1e7e
6 changed files with 20 additions and 13 deletions

View File

@@ -109,6 +109,12 @@ impl VMMemory {
} }
} }
impl From<VMMemory> for JsValue {
fn from(value: VMMemory) -> Self {
JsValue::from(value.memory)
}
}
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct VMGlobal { pub struct VMGlobal {
pub(crate) global: Global, pub(crate) global: Global,

View File

@@ -104,8 +104,7 @@ pub fn spawn_exec_module(
let tasks_outer = tasks.clone(); let tasks_outer = tasks.clone();
let task = { let task = {
let mut store = store; move |mut store, module, memory| {
move |module, memory| {
// Create the WasiFunctionEnv // Create the WasiFunctionEnv
let mut wasi_env = env; let mut wasi_env = env;
wasi_env.runtime = runtime; wasi_env.runtime = runtime;
@@ -189,7 +188,7 @@ pub fn spawn_exec_module(
}; };
tasks_outer tasks_outer
.task_wasm(Box::new(task), module, memory_spawn) .task_wasm(Box::new(task), store, module, memory_spawn)
.map_err(|err| { .map_err(|err| {
error!("wasi[{}]::failed to launch module - {}", pid, err); error!("wasi[{}]::failed to launch module - {}", pid, err);
VirtualBusError::UnknownError VirtualBusError::UnknownError

View File

@@ -6,7 +6,7 @@ use std::{pin::Pin, time::Duration};
use ::tokio::runtime::Handle; use ::tokio::runtime::Handle;
use futures::Future; use futures::Future;
use wasmer::{MemoryType, Module}; use wasmer::{MemoryType, Module, Store};
#[cfg(feature = "js")] #[cfg(feature = "js")]
use wasmer::VMMemory; 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 /// It is ok for this task to block execution and any async futures within its scope
fn task_wasm( fn task_wasm(
&self, &self,
task: Box<dyn FnOnce(Module, Option<VMMemory>) + Send + 'static>, task: Box<dyn FnOnce(Store, Module, Option<VMMemory>) + Send + 'static>,
store: Store,
module: Module, module: Module,
spawn_type: SpawnType, spawn_type: SpawnType,
) -> Result<(), WasiThreadError>; ) -> Result<(), WasiThreadError>;

View File

@@ -4,7 +4,7 @@ use futures::Future;
use tokio::runtime::Handle; use tokio::runtime::Handle;
use wasmer::{ use wasmer::{
vm::{VMMemory, VMSharedMemory}, vm::{VMMemory, VMSharedMemory},
Module, Module, Store,
}; };
use crate::os::task::thread::WasiThreadError; use crate::os::task::thread::WasiThreadError;
@@ -125,14 +125,15 @@ impl VirtualTaskManager for TokioTaskManager {
/// See [`VirtualTaskManager::enter`]. /// See [`VirtualTaskManager::enter`].
fn task_wasm( fn task_wasm(
&self, &self,
task: Box<dyn FnOnce(Module, Option<VMMemory>) + Send + 'static>, task: Box<dyn FnOnce(Store, Module, Option<VMMemory>) + Send + 'static>,
store: Store,
module: Module, module: Module,
spawn_type: SpawnType, spawn_type: SpawnType,
) -> Result<(), WasiThreadError> { ) -> Result<(), WasiThreadError> {
let memory = self.build_memory(spawn_type)?; let memory = self.build_memory(spawn_type)?;
self.0.spawn_blocking(move || { self.0.spawn_blocking(move || {
// Invoke the callback // Invoke the callback
task(module, memory); task(store, module, memory);
}); });
Ok(()) Ok(())
} }

View File

@@ -191,11 +191,11 @@ pub fn proc_fork<M: MemorySize>(
let tasks = tasks.clone(); let tasks = tasks.clone();
let tasks_outer = tasks.clone(); let tasks_outer = tasks.clone();
let mut store = fork_store; let store = fork_store;
let module = fork_module; let module = fork_module;
let spawn_type = SpawnType::NewThread(fork_memory); let spawn_type = SpawnType::NewThread(fork_memory);
let task = move |module, memory| { let task = move |mut store, module, memory| {
// Create the WasiFunctionEnv // Create the WasiFunctionEnv
let pid = child_env.pid(); let pid = child_env.pid();
let tid = child_env.tid(); let tid = child_env.tid();
@@ -286,7 +286,7 @@ pub fn proc_fork<M: MemorySize>(
}; };
tasks_outer tasks_outer
.task_wasm(Box::new(task), module, spawn_type) .task_wasm(Box::new(task), store, module, spawn_type)
.map_err(|err| { .map_err(|err| {
warn!( warn!(
"wasi[{}:{}]::failed to fork as the process could not be spawned - {}", "wasi[{}:{}]::failed to fork as the process could not be spawned - {}",

View File

@@ -299,14 +299,14 @@ pub fn thread_spawn<M: MemorySize>(
let thread_module = env.inner().instance.module().clone(); let thread_module = env.inner().instance.module().clone();
let tasks2 = tasks.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) // FIXME: should not use unwrap() here! (initializiation refactor)
let mut store = Some(store); let mut store = Some(store);
execute_module(&mut store, thread_module, &mut thread_memory); execute_module(&mut store, thread_module, &mut thread_memory);
}; };
wasi_try!(tasks 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::<Errno>::into(err) })); .map_err(|err| { Into::<Errno>::into(err) }));
} }
_ => { _ => {