diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:39 +0000 |
commit | 1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch) | |
tree | 3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /vendor/memmap2/src/lib.rs | |
parent | Releasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip |
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/memmap2/src/lib.rs')
-rw-r--r-- | vendor/memmap2/src/lib.rs | 59 |
1 files changed, 55 insertions, 4 deletions
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<Mmap> for MmapRaw { + fn from(value: Mmap) -> Self { + Self { inner: value.inner } + } +} + +impl From<MmapMut> 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(); |