Skip to content

Commit

Permalink
Implement .populate() for map_anon().
Browse files Browse the repository at this point in the history
Closes #70
  • Loading branch information
jsgf authored Feb 22, 2023
1 parent e281d1f commit b26573b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 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
2 changes: 1 addition & 1 deletion src/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

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 b26573b

Please sign in to comment.