Skip to content

Commit

Permalink
linux can do MLOCK_ONFAULT, other unixes have to fall back to bare mlock
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Hickey committed Feb 17, 2022
1 parent c110a1a commit 561f325
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crates/runtime/src/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,14 +434,21 @@ impl Mmap {
range.start % region::page::size() == 0,
"changing of protections isn't page-aligned",
);
#[cfg(unix)]
#[cfg(target_os = "linux")]
unsafe {
rustix::io::mlock_with(
self.as_ptr().add(range.start) as *mut _,
range.end - range.start,
rustix::io::MlockFlags::ONFAULT,
)?;
}
#[cfg(all(unix, not(target_os = "linux")))]
unsafe {
rustix::io::mlock(
self.as_ptr().add(range.start) as *mut _,
range.end - range.start,
)?;
}
Ok(())
}
}
Expand Down

0 comments on commit 561f325

Please sign in to comment.