Skip to content

Commit

Permalink
Implement .populate() for map_anon()
Browse files Browse the repository at this point in the history
Resolves RazrFalcon#70.
  • Loading branch information
jsgf committed Feb 22, 2023
1 parent e281d1f commit 580bf01
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 580bf01

Please sign in to comment.