mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-12 13:28:49 +00:00
The VMMemory must be convertable into a JsValue
This commit is contained in:
committed by
Christoph Herzog
parent
52bf78eb37
commit
e2276c1e7e
@@ -109,6 +109,12 @@ impl VMMemory {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<VMMemory> for JsValue {
|
||||
fn from(value: VMMemory) -> Self {
|
||||
JsValue::from(value.memory)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct VMGlobal {
|
||||
pub(crate) global: Global,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<dyn FnOnce(Module, Option<VMMemory>) + Send + 'static>,
|
||||
task: Box<dyn FnOnce(Store, Module, Option<VMMemory>) + Send + 'static>,
|
||||
store: Store,
|
||||
module: Module,
|
||||
spawn_type: SpawnType,
|
||||
) -> Result<(), WasiThreadError>;
|
||||
|
||||
@@ -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<dyn FnOnce(Module, Option<VMMemory>) + Send + 'static>,
|
||||
task: Box<dyn FnOnce(Store, Module, Option<VMMemory>) + 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(())
|
||||
}
|
||||
|
||||
@@ -191,11 +191,11 @@ pub fn proc_fork<M: MemorySize>(
|
||||
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<M: MemorySize>(
|
||||
};
|
||||
|
||||
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 - {}",
|
||||
|
||||
@@ -299,14 +299,14 @@ pub fn thread_spawn<M: MemorySize>(
|
||||
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::<Errno>::into(err) }));
|
||||
}
|
||||
_ => {
|
||||
|
||||
Reference in New Issue
Block a user