Review comments.
This commit is contained in:
@@ -7,8 +7,8 @@ use libc::c_void;
|
|||||||
use memfd::{Memfd, MemfdOptions};
|
use memfd::{Memfd, MemfdOptions};
|
||||||
use rustix::fd::AsRawFd;
|
use rustix::fd::AsRawFd;
|
||||||
use rustix::fs::FileExt;
|
use rustix::fs::FileExt;
|
||||||
use std::convert::TryFrom;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::{convert::TryFrom, ops::Range};
|
||||||
use wasmtime_environ::{
|
use wasmtime_environ::{
|
||||||
DefinedMemoryIndex, MemoryInitialization, MemoryInitializer, MemoryPlan, Module, PrimaryMap,
|
DefinedMemoryIndex, MemoryInitialization, MemoryInitializer, MemoryPlan, Module, PrimaryMap,
|
||||||
};
|
};
|
||||||
@@ -428,8 +428,7 @@ impl MemFdSlot {
|
|||||||
// so given initial_size_bytes < self.initial_size we
|
// so given initial_size_bytes < self.initial_size we
|
||||||
// mprotect(NONE) the zone from the first to the second.
|
// mprotect(NONE) the zone from the first to the second.
|
||||||
self.set_protection(
|
self.set_protection(
|
||||||
initial_size_bytes,
|
initial_size_bytes..self.initial_size,
|
||||||
self.initial_size,
|
|
||||||
rustix::io::MprotectFlags::empty(),
|
rustix::io::MprotectFlags::empty(),
|
||||||
)
|
)
|
||||||
.map_err(|e| InstantiationError::Resource(e.into()))?;
|
.map_err(|e| InstantiationError::Resource(e.into()))?;
|
||||||
@@ -461,8 +460,7 @@ impl MemFdSlot {
|
|||||||
self.initial_size = initial_size_bytes;
|
self.initial_size = initial_size_bytes;
|
||||||
self.cur_size = initial_size_bytes;
|
self.cur_size = initial_size_bytes;
|
||||||
self.set_protection(
|
self.set_protection(
|
||||||
0,
|
0..initial_size_bytes,
|
||||||
initial_size_bytes,
|
|
||||||
rustix::io::MprotectFlags::READ | rustix::io::MprotectFlags::WRITE,
|
rustix::io::MprotectFlags::READ | rustix::io::MprotectFlags::WRITE,
|
||||||
)
|
)
|
||||||
.map_err(|e| InstantiationError::Resource(e.into()))?;
|
.map_err(|e| InstantiationError::Resource(e.into()))?;
|
||||||
@@ -486,25 +484,19 @@ impl MemFdSlot {
|
|||||||
|
|
||||||
// mprotect the initial heap region beyond the initial heap size back to PROT_NONE.
|
// mprotect the initial heap region beyond the initial heap size back to PROT_NONE.
|
||||||
self.set_protection(
|
self.set_protection(
|
||||||
self.initial_size,
|
self.initial_size..self.static_size,
|
||||||
self.static_size - self.initial_size,
|
|
||||||
rustix::io::MprotectFlags::empty(),
|
rustix::io::MprotectFlags::empty(),
|
||||||
)?;
|
)?;
|
||||||
self.dirty = false;
|
self.dirty = false;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_protection(
|
fn set_protection(&self, range: Range<usize>, flags: rustix::io::MprotectFlags) -> Result<()> {
|
||||||
&self,
|
assert!(range.end <= self.static_size);
|
||||||
start: usize,
|
let mprotect_start = self.base.checked_add(range.start).unwrap();
|
||||||
len: usize,
|
if range.len() > 0 {
|
||||||
flags: rustix::io::MprotectFlags,
|
|
||||||
) -> Result<()> {
|
|
||||||
assert!(start.checked_add(len).unwrap() <= self.static_size);
|
|
||||||
let mprotect_start = self.base.checked_add(start).unwrap();
|
|
||||||
if len > 0 {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
rustix::io::mprotect(mprotect_start as *mut _, len, flags)?;
|
rustix::io::mprotect(mprotect_start as *mut _, range.len(), flags)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user