From 1376c5a617be5c25655d0d7cb63e3beaa5a6e026 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:20:39 +0200 Subject: Merging upstream version 1.70.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/memmap2/src/lib.rs | 59 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 4 deletions(-) (limited to 'vendor/memmap2/src/lib.rs') diff --git a/vendor/memmap2/src/lib.rs b/vendor/memmap2/src/lib.rs index 58df7589b..2d730ae90 100644 --- a/vendor/memmap2/src/lib.rs +++ b/vendor/memmap2/src/lib.rs @@ -482,7 +482,7 @@ impl MmapOptions { )); } - MmapInner::map_anon(len, self.stack).map(|inner| MmapMut { inner }) + MmapInner::map_anon(len, self.stack, self.populate).map(|inner| MmapMut { inner }) } /// Creates a raw memory map. @@ -627,7 +627,19 @@ impl Mmap { /// See [madvise()](https://man7.org/linux/man-pages/man2/madvise.2.html) map page. #[cfg(unix)] pub fn advise(&self, advice: Advice) -> Result<()> { - self.inner.advise(advice) + self.inner.advise(advice, 0, self.inner.len()) + } + + /// Advise OS how this range of memory map will be accessed. + /// + /// The offset and length must be in the bounds of the memory map. + /// + /// Only supported on Unix. + /// + /// See [madvise()](https://man7.org/linux/man-pages/man2/madvise.2.html) map page. + #[cfg(unix)] + pub fn advise_range(&self, advice: Advice, offset: usize, len: usize) -> Result<()> { + self.inner.advise(advice, offset, len) } /// Lock the whole memory map into RAM. Only supported on Unix. @@ -806,7 +818,19 @@ impl MmapRaw { /// See [madvise()](https://man7.org/linux/man-pages/man2/madvise.2.html) map page. #[cfg(unix)] pub fn advise(&self, advice: Advice) -> Result<()> { - self.inner.advise(advice) + self.inner.advise(advice, 0, self.inner.len()) + } + + /// Advise OS how this range of memory map will be accessed. + /// + /// The offset and length must be in the bounds of the memory map. + /// + /// Only supported on Unix. + /// + /// See [madvise()](https://man7.org/linux/man-pages/man2/madvise.2.html) map page. + #[cfg(unix)] + pub fn advise_range(&self, advice: Advice, offset: usize, len: usize) -> Result<()> { + self.inner.advise(advice, offset, len) } /// Lock the whole memory map into RAM. Only supported on Unix. @@ -835,6 +859,18 @@ impl fmt::Debug for MmapRaw { } } +impl From for MmapRaw { + fn from(value: Mmap) -> Self { + Self { inner: value.inner } + } +} + +impl From for MmapRaw { + fn from(value: MmapMut) -> Self { + Self { inner: value.inner } + } +} + /// A handle to a mutable memory mapped buffer. /// /// A file-backed `MmapMut` buffer may be used to read from or write to a file. An anonymous @@ -1050,7 +1086,19 @@ impl MmapMut { /// See [madvise()](https://man7.org/linux/man-pages/man2/madvise.2.html) map page. #[cfg(unix)] pub fn advise(&self, advice: Advice) -> Result<()> { - self.inner.advise(advice) + self.inner.advise(advice, 0, self.inner.len()) + } + + /// Advise OS how this range of memory map will be accessed. + /// + /// The offset and length must be in the bounds of the memory map. + /// + /// Only supported on Unix. + /// + /// See [madvise()](https://man7.org/linux/man-pages/man2/madvise.2.html) map page. + #[cfg(unix)] + pub fn advise_range(&self, advice: Advice, offset: usize, len: usize) -> Result<()> { + self.inner.advise(advice, offset, len) } /// Lock the whole memory map into RAM. Only supported on Unix. @@ -1633,6 +1681,9 @@ mod test { // check that the mmap is empty assert_eq!(&zeros[..], &mmap[..]); + mmap.advise_range(Advice::Sequential, 0, mmap.len()) + .expect("mmap advising should be supported on unix"); + // write values into the mmap (&mut mmap[..]).write_all(&incr[..]).unwrap(); -- cgit v1.2.3