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

@@ -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