From b26573b52f1ace32f27232276eb0aadd1d0b0640 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Wed, 22 Feb 2023 09:55:01 -0800 Subject: [PATCH] Implement `.populate()` for `map_anon()`. Closes #70 --- src/lib.rs | 2 +- src/stub.rs | 2 +- src/unix.rs | 5 +++-- src/windows.rs | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0d64d2b6..2d730ae9 100644 --- a/src/lib.rs +++ b/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. diff --git a/src/stub.rs b/src/stub.rs index e756da4f..3c6af0e7 100644 --- a/src/stub.rs +++ b/src/stub.rs @@ -36,7 +36,7 @@ impl MmapInner { MmapInner::new() } - pub fn map_anon(_: usize, _: bool) -> io::Result { + pub fn map_anon(_: usize, _: bool, _: bool) -> io::Result { MmapInner::new() } diff --git a/src/unix.rs b/src/unix.rs index f691e680..221d3ba8 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -162,12 +162,13 @@ impl MmapInner { } /// Open an anonymous memory map. - pub fn map_anon(len: usize, stack: bool) -> io::Result { + pub fn map_anon(len: usize, stack: bool, populate: bool) -> io::Result { 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, ) diff --git a/src/windows.rs b/src/windows.rs index d580995e..c1b1a4d9 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -340,7 +340,7 @@ impl MmapInner { Ok(inner) } - pub fn map_anon(len: usize, _stack: bool) -> io::Result { + pub fn map_anon(len: usize, _stack: bool, _populate: bool) -> io::Result { // Ensure a non-zero length for the underlying mapping let mapped_len = len.max(1); unsafe {