summaryrefslogtreecommitdiffstats
path: root/vendor/memmap2/src
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/memmap2/src')
-rw-r--r--vendor/memmap2/src/lib.rs59
-rw-r--r--vendor/memmap2/src/stub.rs2
-rw-r--r--vendor/memmap2/src/unix.rs12
-rw-r--r--vendor/memmap2/src/windows.rs2
4 files changed, 65 insertions, 10 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();
diff --git a/vendor/memmap2/src/stub.rs b/vendor/memmap2/src/stub.rs
index e756da4f6..3c6af0e77 100644
--- a/vendor/memmap2/src/stub.rs
+++ b/vendor/memmap2/src/stub.rs
@@ -36,7 +36,7 @@ impl MmapInner {
MmapInner::new()
}
- pub fn map_anon(_: usize, _: bool) -> io::Result<MmapInner> {
+ pub fn map_anon(_: usize, _: bool, _: bool) -> io::Result<MmapInner> {
MmapInner::new()
}
diff --git a/vendor/memmap2/src/unix.rs b/vendor/memmap2/src/unix.rs
index 158d78c1f..221d3ba84 100644
--- a/vendor/memmap2/src/unix.rs
+++ b/vendor/memmap2/src/unix.rs
@@ -162,12 +162,13 @@ impl MmapInner {
}
/// Open an anonymous memory map.
- pub fn map_anon(len: usize, stack: bool) -> io::Result<MmapInner> {
+ pub fn map_anon(len: usize, stack: bool, populate: bool) -> io::Result<MmapInner> {
let stack = if stack { MAP_STACK } else { 0 };
+ let populate = if populate { MAP_POPULATE } else { 0 };
MmapInner::new(
len,
libc::PROT_READ | libc::PROT_WRITE,
- libc::MAP_PRIVATE | libc::MAP_ANON | stack,
+ libc::MAP_PRIVATE | libc::MAP_ANON | stack | populate,
-1,
0,
)
@@ -240,9 +241,12 @@ impl MmapInner {
self.len
}
- pub fn advise(&self, advice: Advice) -> io::Result<()> {
+ pub fn advise(&self, advice: Advice, offset: usize, len: usize) -> io::Result<()> {
+ let alignment = (self.ptr as usize + offset) % page_size();
+ let offset = offset as isize - alignment as isize;
+ let len = len + alignment;
unsafe {
- if libc::madvise(self.ptr, self.len, advice as i32) != 0 {
+ if libc::madvise(self.ptr.offset(offset), len, advice as i32) != 0 {
Err(io::Error::last_os_error())
} else {
Ok(())
diff --git a/vendor/memmap2/src/windows.rs b/vendor/memmap2/src/windows.rs
index d580995e6..c1b1a4d9f 100644
--- a/vendor/memmap2/src/windows.rs
+++ b/vendor/memmap2/src/windows.rs
@@ -340,7 +340,7 @@ impl MmapInner {
Ok(inner)
}
- pub fn map_anon(len: usize, _stack: bool) -> io::Result<MmapInner> {
+ pub fn map_anon(len: usize, _stack: bool, _populate: bool) -> io::Result<MmapInner> {
// Ensure a non-zero length for the underlying mapping
let mapped_len = len.max(1);
unsafe {