wasmer/entities/memory/
location.rs

1use wasmer_types::MemoryError;
2
3use crate::error::AtomicsError;
4
5/// Location in a WebAssembly memory.
6#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
7pub struct MemoryLocation {
8    // NOTE: must be expanded to an enum that also supports 64bit memory in
9    // the future
10    // That's why this is private.
11    pub(crate) address: u32,
12}
13
14impl MemoryLocation {
15    /// Create a new memory location for a 32bit memory.
16    pub fn new_32(address: u32) -> Self {
17        Self { address }
18    }
19}
20
21impl From<u32> for MemoryLocation {
22    fn from(value: u32) -> Self {
23        Self::new_32(value)
24    }
25}
26
27/// See [`crate::SharedMemory`].
28pub(crate) trait SharedMemoryOps {
29    /// See [`crate::SharedMemory::disable_atomics`].
30    fn disable_atomics(&self) -> Result<(), MemoryError> {
31        Err(MemoryError::AtomicsNotSupported)
32    }
33
34    /// See [`crate::SharedMemory::wake_all_atomic_waiters`].
35    fn wake_all_atomic_waiters(&self) -> Result<(), MemoryError> {
36        Err(MemoryError::AtomicsNotSupported)
37    }
38
39    /// See [`crate::SharedMemory::notify`].
40    fn notify(&self, _dst: MemoryLocation, _count: u32) -> Result<u32, AtomicsError> {
41        Err(AtomicsError::Unimplemented)
42    }
43
44    /// See [`crate::SharedMemory::wait`].
45    fn wait(
46        &self,
47        _dst: MemoryLocation,
48        _timeout: Option<std::time::Duration>,
49    ) -> Result<u32, AtomicsError> {
50        Err(AtomicsError::Unimplemented)
51    }
52}