Makes the specified `range` within this `Mmap` to be read/execute. # Unsafety This method is unsafe as it's generally not valid to simply make memory executable, so it's up to the caller to ensure that everything is in order and this doesn't overlap with other memory that should only be read or only read/write. # Panics Panics of `range` is out-of-bounds or not page-aligned.
(
&self,
range: Range<usize>,
enable_branch_protection: bool,
)
| 300 | /// |
| 301 | /// Panics of `range` is out-of-bounds or not page-aligned. |
| 302 | pub unsafe fn make_executable( |
| 303 | &self, |
| 304 | range: Range<usize>, |
| 305 | enable_branch_protection: bool, |
| 306 | ) -> Result<()> { |
| 307 | assert!(range.start <= self.len()); |
| 308 | assert!(range.end <= self.len()); |
| 309 | assert!(range.start <= range.end); |
| 310 | assert!( |
| 311 | range.start % crate::runtime::vm::host_page_size() == 0, |
| 312 | "changing of protections isn't page-aligned", |
| 313 | ); |
| 314 | |
| 315 | if range.start == range.end { |
| 316 | // A zero-sized mprotect (or equivalent) is allowed on some |
| 317 | // platforms but not others (notably Windows). Treat it as a no-op |
| 318 | // everywhere. |
| 319 | return Ok(()); |
| 320 | } |
| 321 | |
| 322 | unsafe { |
| 323 | self.sys |
| 324 | .make_executable(range, enable_branch_protection) |
| 325 | .context("failed to make memory executable") |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | /// Makes the specified `range` within this `Mmap` to be readonly. |
| 330 | pub unsafe fn make_readonly(&self, range: Range<usize>) -> Result<()> { |