Move linear memory faulted guard page tracking into Memory.

This commit moves the tracking for faulted guard pages in a linear memory into
`Memory`.
This commit is contained in:
Peter Huene
2021-03-08 09:23:17 -08:00
parent 7a93132ffa
commit 5fa0f8d469
5 changed files with 76 additions and 57 deletions

View File

@@ -602,8 +602,6 @@ unsafe impl InstanceAllocator for OnDemandInstanceAllocator {
)),
dropped_data: RefCell::new(EntitySet::with_capacity(req.module.passive_data.len())),
host_state,
#[cfg(all(feature = "uffd", target_os = "linux"))]
guard_page_faults: RefCell::new(Vec::new()),
vmctx: VMContext {},
};
let layout = instance.alloc_layout();

View File

@@ -367,8 +367,6 @@ impl InstancePool {
dropped_elements: RefCell::new(EntitySet::new()),
dropped_data: RefCell::new(EntitySet::new()),
host_state: Box::new(()),
#[cfg(all(feature = "uffd", target_os = "linux"))]
guard_page_faults: RefCell::new(Vec::new()),
vmctx: VMContext {},
},
);
@@ -431,9 +429,15 @@ impl InstancePool {
let memory = mem::take(memory);
debug_assert!(memory.is_static());
// Reset any faulted guard pages as the physical memory may be reused for another instance in the future
#[cfg(all(feature = "uffd", target_os = "linux"))]
memory
.reset_guard_pages()
.expect("failed to reset guard pages");
let size = (memory.size() * WASM_PAGE_SIZE) as usize;
drop(memory);
decommit_memory_pages(base, size).unwrap();
decommit_memory_pages(base, size).expect("failed to decommit linear memory pages");
}
instance.memories.clear();
@@ -450,7 +454,7 @@ impl InstancePool {
);
drop(table);
decommit_table_pages(base, size).unwrap();
decommit_table_pages(base, size).expect("failed to decommit table pages");
}
instance.tables.clear();
@@ -469,12 +473,6 @@ impl InstancePool {
) -> Result<(), InstantiationError> {
let module = instance.module.as_ref();
// Reset all guard pages before reusing the instance
#[cfg(all(feature = "uffd", target_os = "linux"))]
instance
.reset_guard_pages()
.map_err(|e| InstantiationError::Resource(e.to_string()))?;
debug_assert!(instance.memories.is_empty());
for plan in

View File

@@ -313,8 +313,12 @@ unsafe fn handle_page_fault(
None => {
log::trace!("out of bounds memory access at {:p}", addr);
// Record the guard page fault with the instance so it can be reset later.
instance.record_guard_page_fault(page_addr, len, reset_guard_page);
// Record the guard page fault so the page protection level can be reset later
instance.memories[memory_index].record_guard_page_fault(
page_addr,
len,
reset_guard_page,
);
wake_guard_page_access(&uffd, page_addr, len)?;
}
}