Skip to content

Commit

Permalink
Try to fix uffd failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Jun 10, 2021
1 parent b7ca4c9 commit 88128ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
24 changes: 16 additions & 8 deletions crates/runtime/src/instance/allocator/pooling/uffd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ struct FaultLocator {
instances_start: usize,
instance_size: usize,
max_instances: usize,
unguarded_memories_start: usize,
memories_start: usize,
memories_end: usize,
memory_size: usize,
Expand All @@ -167,14 +168,16 @@ impl FaultLocator {
let instances_start = instances.mapping.as_ptr() as usize;
let memories_start =
instances.memories.mapping.as_ptr() as usize + instances.memories.initial_memory_offset;
let memories_end = memories_start + instances.memories.mapping.len();
let memories_end =
instances.memories.mapping.as_ptr() as usize + instances.memories.mapping.len();

// Should always have instances
debug_assert!(instances_start != 0);

Self {
instances_start,
instance_size: instances.instance_size,
unguarded_memories_start: instances.memories.mapping.as_ptr() as usize,
max_instances: instances.max_instances,
memories_start,
memories_end,
Expand Down Expand Up @@ -345,7 +348,7 @@ fn fault_handler_thread(uffd: Uffd, locator: FaultLocator) -> Result<()> {

let (start, end) = (start as usize, end as usize);

if start == locator.memories_start && end == locator.memories_end {
if start == locator.unguarded_memories_start && end == locator.memories_end {
break;
} else {
panic!("unexpected memory region unmapped");
Expand Down Expand Up @@ -438,7 +441,9 @@ mod test {
PoolingAllocationStrategy, VMSharedSignatureIndex,
};
use std::sync::Arc;
use wasmtime_environ::{entity::PrimaryMap, wasm::Memory, MemoryPlan, MemoryStyle, Module};
use wasmtime_environ::{
entity::PrimaryMap, wasm::Memory, MemoryPlan, MemoryStyle, Module, Tunables,
};

#[cfg(target_pointer_width = "64")]
#[test]
Expand All @@ -456,13 +461,16 @@ mod test {
table_elements: 0,
memory_pages: 2,
};
let instance_limits = InstanceLimits {
count: 3,
memory_reservation_size: (WASM_PAGE_SIZE * 10) as u64,
let instance_limits = InstanceLimits { count: 3 };
let tunables = Tunables {
static_memory_bound: 10,
static_memory_offset_guard_size: 0,
guard_before_linear_memory: false,
..Tunables::default()
};

let instances =
InstancePool::new(&module_limits, &instance_limits).expect("should allocate");
let instances = InstancePool::new(&module_limits, &instance_limits, &tunables)
.expect("should allocate");

let locator = FaultLocator::new(&instances);

Expand Down
6 changes: 6 additions & 0 deletions tests/all/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ unsafe fn assert_faults(ptr: *mut u8) {
use std::io::Error;
#[cfg(unix)]
{
// I think things get real weird with uffd since there's a helper thread
// that's not cloned with `fork` below. Just skip this test for uffd
// since it's covered by tests elsewhere.
if cfg!(target_os = "linux") && cfg!(feature = "uffd") {
return;
}
// There's probably a faster way to do this here, but, uh, when in rome?
match libc::fork() {
0 => {
Expand Down

0 comments on commit 88128ed

Please sign in to comment.