diff --git a/lib/api/src/js/export.rs b/lib/api/src/js/export.rs index 1cf18286a..6a40c86c8 100644 --- a/lib/api/src/js/export.rs +++ b/lib/api/src/js/export.rs @@ -54,7 +54,7 @@ impl VMMemory { } /// Copies this memory to a new memory - pub fn fork(&self) -> Result { + pub fn duplicate(&self) -> Result { let new_memory = crate::Memory::new_internal(self.ty.clone())?; #[cfg(feature = "tracing")] diff --git a/lib/api/src/js/externals/memory.rs b/lib/api/src/js/externals/memory.rs index 5678e5c3e..969fb9588 100644 --- a/lib/api/src/js/externals/memory.rs +++ b/lib/api/src/js/externals/memory.rs @@ -265,9 +265,9 @@ impl Memory { } /// Copies this memory to a new memory - pub fn fork(&mut self, store: &impl AsStoreRef) -> Result { + pub fn duplicate(&mut self, store: &impl AsStoreRef) -> Result { let mem = self.handle.get(store.as_store_ref().objects()); - mem.fork() + mem.duplicate() } } diff --git a/lib/api/src/sys/tunables.rs b/lib/api/src/sys/tunables.rs index e8866abe7..aa69f2903 100644 --- a/lib/api/src/sys/tunables.rs +++ b/lib/api/src/sys/tunables.rs @@ -117,10 +117,12 @@ mod tests { .unwrap() } } + fn try_clone(&self) -> Option> { None } - fn fork(&mut self) -> Result, MemoryError> { + + fn duplicate(&mut self) -> Result, MemoryError> { let mem = self.mem.clone(); Ok(Box::new(Self { memory_definition: Some(UnsafeCell::new(VMMemoryDefinition { diff --git a/lib/vm/src/memory.rs b/lib/vm/src/memory.rs index 1ca89c001..d3d288a0c 100644 --- a/lib/vm/src/memory.rs +++ b/lib/vm/src/memory.rs @@ -119,11 +119,11 @@ impl WasmMmap { /// Copies the memory /// (in this case it performs a copy-on-write to save memory) - pub fn fork(&mut self) -> Result { + pub fn duplicate(&mut self) -> Result { let mem_length = self.size.bytes().0; let mut alloc = self .alloc - .fork(Some(mem_length)) + .duplicate(Some(mem_length)) .map_err(MemoryError::Generic)?; let base_ptr = alloc.as_mut_ptr(); Ok(Self { @@ -289,9 +289,9 @@ impl VMOwnedMemory { } /// Copies this memory to a new memory - pub fn fork(&mut self) -> Result { + pub fn duplicate(&mut self) -> Result { Ok(Self { - mmap: self.mmap.fork()?, + mmap: self.mmap.duplicate()?, config: self.config.clone(), }) } @@ -333,8 +333,8 @@ impl LinearMemory for VMOwnedMemory { } /// Copies this memory to a new memory - fn fork(&mut self) -> Result, MemoryError> { - let forked = Self::fork(self)?; + fn duplicate(&mut self) -> Result, MemoryError> { + let forked = Self::duplicate(self)?; Ok(Box::new(forked)) } } @@ -376,10 +376,10 @@ impl VMSharedMemory { } /// Copies this memory to a new memory - pub fn fork(&mut self) -> Result { + pub fn duplicate(&mut self) -> Result { let mut guard = self.mmap.write().unwrap(); Ok(Self { - mmap: Arc::new(RwLock::new(guard.fork()?)), + mmap: Arc::new(RwLock::new(guard.duplicate()?)), config: self.config.clone(), }) } @@ -427,8 +427,8 @@ impl LinearMemory for VMSharedMemory { } /// Copies this memory to a new memory - fn fork(&mut self) -> Result, MemoryError> { - let forked = Self::fork(self)?; + fn duplicate(&mut self) -> Result, MemoryError> { + let forked = Self::duplicate(self)?; Ok(Box::new(forked)) } } @@ -495,8 +495,8 @@ impl LinearMemory for VMMemory { } /// Copies this memory to a new memory - fn fork(&mut self) -> Result, MemoryError> { - self.0.fork() + fn duplicate(&mut self) -> Result, MemoryError> { + self.0.duplicate() } } @@ -558,8 +558,8 @@ impl VMMemory { } /// Copies this memory to a new memory - pub fn fork(&mut self) -> Result, MemoryError> { - LinearMemory::fork(self) + pub fn duplicate(&mut self) -> Result, MemoryError> { + LinearMemory::duplicate(self) } } @@ -615,5 +615,5 @@ where } /// Copies this memory to a new memory - fn fork(&mut self) -> Result, MemoryError>; + fn duplicate(&mut self) -> Result, MemoryError>; } diff --git a/lib/vm/src/mmap.rs b/lib/vm/src/mmap.rs index ebd844c0d..3c0c5763b 100644 --- a/lib/vm/src/mmap.rs +++ b/lib/vm/src/mmap.rs @@ -317,7 +317,7 @@ impl Mmap { /// Copies the memory to a new swap file (using copy-on-write if available) #[cfg(not(target_os = "windows"))] - pub fn fork(&mut self, hint_used: Option) -> Result { + pub fn duplicate(&mut self, hint_used: Option) -> Result { // Empty memory is an edge case use std::os::unix::prelude::FromRawFd; @@ -395,7 +395,7 @@ impl Mmap { /// Copies the memory to a new swap file (using copy-on-write if available) #[cfg(target_os = "windows")] - pub fn fork(&mut self, hint_used: Option) -> Result { + pub fn duplicate(&mut self, hint_used: Option) -> Result { // Create a new memory which we will copy to let new_mmap = Self::with_at_least(self.len)?;