Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Missing WaiterError export + Add notify/wait to fd_mmap memory #3833

Merged
merged 4 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/sys-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ wasmer = { path = "../api", version = "=3.2.1", default-features = false, featur
wasmer-vm = { path = "../vm", version = "=3.2.1" }
wasmer-types = { path = "../types", version = "=3.2.1" }
region = { version = "3.0" }
tracing = "0.1.37"

[target.'cfg(unix)'.dependencies]
libc = { version = "^0.2", default-features = false }
Expand Down
20 changes: 19 additions & 1 deletion lib/sys-utils/src/memory/fd_memory/memories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use std::{

use wasmer::{Bytes, MemoryError, MemoryType, Pages};
use wasmer_types::MemoryStyle;
use wasmer_vm::{LinearMemory, MaybeInstanceOwned, Trap, VMMemoryDefinition};
use wasmer_vm::{
LinearMemory, MaybeInstanceOwned, ThreadConditions, Trap, VMMemoryDefinition, WaiterError,
};

use super::fd_mmap::FdMmap;

Expand Down Expand Up @@ -297,6 +299,7 @@ impl VMOwnedMemory {
VMSharedMemory {
mmap: Arc::new(RwLock::new(self.mmap)),
config: self.config,
conditions: ThreadConditions::new(),
}
}

Expand Down Expand Up @@ -341,6 +344,7 @@ impl LinearMemory for VMOwnedMemory {

/// Owned memory can not be cloned (this will always return None)
fn try_clone(&self) -> Option<Box<dyn LinearMemory + 'static>> {
tracing::warn!("trying to clone owned memory");
None
}

Expand All @@ -358,6 +362,7 @@ pub struct VMSharedMemory {
mmap: Arc<RwLock<WasmMmap>>,
// Configuration of this memory
config: VMMemoryConfig,
conditions: ThreadConditions,
}

unsafe impl Send for VMSharedMemory {}
Expand Down Expand Up @@ -393,6 +398,7 @@ impl VMSharedMemory {
Ok(Self {
mmap: Arc::new(RwLock::new(guard.duplicate()?)),
config: self.config.clone(),
conditions: ThreadConditions::new(),
})
}
}
Expand Down Expand Up @@ -443,6 +449,18 @@ impl LinearMemory for VMSharedMemory {
let forked = Self::duplicate(self)?;
Ok(Box::new(forked))
}

fn do_wait(
&mut self,
dst: wasmer_vm::NotifyLocation,
timeout: Option<std::time::Duration>,
) -> Result<u32, WaiterError> {
self.conditions.do_wait(dst, timeout)
}

fn do_notify(&mut self, dst: wasmer_vm::NotifyLocation, count: u32) -> u32 {
self.conditions.do_notify(dst, count)
}
}

impl From<VMOwnedMemory> for VMMemory {
Expand Down
3 changes: 3 additions & 0 deletions lib/vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ pub use crate::probestack::PROBESTACK;
pub use crate::sig_registry::SignatureRegistry;
pub use crate::store::{InternalStoreHandle, MaybeInstanceOwned, StoreHandle, StoreObjects};
pub use crate::table::{TableElement, VMTable};
#[doc(hidden)]
pub use crate::threadconditions::ThreadConditions;
pub use crate::threadconditions::WaiterError;
pub use crate::trap::*;
pub use crate::vmcontext::{
VMCallerCheckedAnyfunc, VMContext, VMDynamicFunctionContext, VMFunctionContext,
Expand Down
4 changes: 3 additions & 1 deletion lib/vm/src/threadconditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ use std::thread::{current, park, park_timeout, Thread};
use std::time::Duration;
use thiserror::Error;

/// Wait/Notify error type
/// Error that can occur during wait/notify calls.
#[derive(Debug, Error)]
// Non-exhaustive to allow for future variants without breaking changes!
#[non_exhaustive]
pub enum WaiterError {
/// Wait/Notify is not implemented for this memory
Unimplemented,
Expand Down