More PR feedback changes.
* More use of `anyhow`. * Change `make_accessible` into `protect_linear_memory` to better demonstrate what it is used for; this will make the uffd implementation make a little more sense. * Remove `create_memory_map` in favor of just creating the `Mmap` instances in the pooling allocator. This also removes the need for `MAP_NORESERVE` in the uffd implementation. * Moar comments. * Remove `BasePointerIterator` in favor of `impl Iterator`. * The uffd implementation now only monitors linear memory pages and will only receive faults on pages that could potentially be accessible and never on a statically known guard page. * Stop allocating memory or table pools if the maximum limit of the memory or table is 0.
This commit is contained in:
@@ -67,10 +67,10 @@ pub(crate) struct Instance {
|
||||
/// Hosts can store arbitrary per-instance information here.
|
||||
host_state: Box<dyn Any>,
|
||||
|
||||
/// Stores guard page faults in memory relating to the instance.
|
||||
/// This is used for the pooling allocator with uffd enabled on Linux.
|
||||
/// Stores linear memory guard page faults for the pooling allocator with uffd enabled.
|
||||
/// These pages need to be reset after the signal handler generates the out-of-bounds trap.
|
||||
#[cfg(all(feature = "uffd", target_os = "linux"))]
|
||||
guard_page_faults: RefCell<Vec<(*mut u8, usize, unsafe fn(*mut u8, usize) -> bool)>>,
|
||||
guard_page_faults: RefCell<Vec<(*mut u8, usize, fn(*mut u8, usize) -> anyhow::Result<()>)>>,
|
||||
|
||||
/// Additional context used by compiled wasm code. This field is last, and
|
||||
/// represents a dynamically-sized array that extends beyond the nominal
|
||||
@@ -821,7 +821,7 @@ impl Instance {
|
||||
&self,
|
||||
page_addr: *mut u8,
|
||||
size: usize,
|
||||
reset: unsafe fn(*mut u8, usize) -> bool,
|
||||
reset: fn(*mut u8, usize) -> anyhow::Result<()>,
|
||||
) {
|
||||
self.guard_page_faults
|
||||
.borrow_mut()
|
||||
@@ -837,11 +837,7 @@ impl Instance {
|
||||
pub(crate) fn reset_guard_pages(&self) -> anyhow::Result<()> {
|
||||
let mut faults = self.guard_page_faults.borrow_mut();
|
||||
for (addr, len, reset) in faults.drain(..) {
|
||||
unsafe {
|
||||
if !reset(addr, len) {
|
||||
anyhow::bail!("failed to reset previously faulted memory guard page");
|
||||
}
|
||||
}
|
||||
reset(addr, len)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user