From 674836d0aefaf35d517bdd005dad3880c490ad43 Mon Sep 17 00:00:00 2001 From: timvisee Date: Fri, 15 Sep 2023 12:29:51 +0200 Subject: [PATCH 1/3] Flush does not require mut, because the kernel uses a global mutex --- src/mmap_view_sync.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mmap_view_sync.rs b/src/mmap_view_sync.rs index 26cc9a5..15820c0 100644 --- a/src/mmap_view_sync.rs +++ b/src/mmap_view_sync.rs @@ -104,7 +104,7 @@ impl MmapViewSync { /// map view are guaranteed to be durably stored. The file's metadata (including last /// modification timestamp) may not be updated. pub fn flush(&self) -> Result<()> { - self.inner_mut().flush_range(self.offset, self.len) + self.inner().flush_range(self.offset, self.len) } /// Returns the length of the memory map view. From 89bd9d942e648cbb4da9ab170105032863437e19 Mon Sep 17 00:00:00 2001 From: timvisee Date: Fri, 15 Sep 2023 12:30:16 +0200 Subject: [PATCH 2/3] Use mut ref self for internal mutability, remove clippy error bypass --- src/mmap_view_sync.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/mmap_view_sync.rs b/src/mmap_view_sync.rs index 15820c0..e7dd7c5 100644 --- a/src/mmap_view_sync.rs +++ b/src/mmap_view_sync.rs @@ -85,6 +85,9 @@ impl MmapViewSync { /// Get a reference to the inner mmap. /// + /// ## Unsafety + /// + /// The caller must ensure that the file is not concurrently modified. /// The caller must ensure that memory outside the `offset`/`len` range is not accessed. fn inner(&self) -> &MmapMut { unsafe { &*self.inner.get() } @@ -92,9 +95,11 @@ impl MmapViewSync { /// Get a mutable reference to the inner mmap. /// + /// ## Unsafety + /// + /// The caller must ensure that the file is not concurrently modified. /// The caller must ensure that memory outside the `offset`/`len` range is not accessed. - #[allow(clippy::mut_from_ref)] - fn inner_mut(&self) -> &mut MmapMut { + fn inner_mut(&mut self) -> &mut MmapMut { unsafe { &mut *self.inner.get() } } @@ -127,7 +132,8 @@ impl MmapViewSync { /// /// The caller must ensure that the file is not concurrently accessed. pub unsafe fn as_mut_slice(&mut self) -> &mut [u8] { - &mut self.inner_mut()[self.offset..self.offset + self.len] + let (offset, len) = (self.offset, self.len); + &mut self.inner_mut()[offset..offset + len] } /// Clones the view of the memory map. From 7344bc09d29bb0751d3145d848bd0ea73fda704f Mon Sep 17 00:00:00 2001 From: timvisee Date: Fri, 15 Sep 2023 12:31:41 +0200 Subject: [PATCH 3/3] Only implement Sync for MmapViewSync in tests, not needed elsewhere --- src/mmap_view_sync.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mmap_view_sync.rs b/src/mmap_view_sync.rs index e7dd7c5..b73bbd4 100644 --- a/src/mmap_view_sync.rs +++ b/src/mmap_view_sync.rs @@ -171,6 +171,7 @@ impl fmt::Debug for MmapViewSync { } } +#[cfg(test)] unsafe impl Sync for MmapViewSync {} unsafe impl Send for MmapViewSync {}