Fix MemFd's allocated memory for dynamic memories (#3763)

This fixes a bug in the memfd-related management of a linear memory
where for dynamic memories memfd wasn't informed of the extra room that
the dynamic memory could grow into, only the actual size of linear
memory, which ended up tripping an assert once the memory was grown. The
fix here is pretty simple which is to factor in this extra space when
passing the allocation size to the creation of the `MemFdSlot`.
This commit is contained in:
Alex Crichton
2022-02-03 11:56:16 -06:00
committed by GitHub
parent 31d4d2cbe0
commit 4ba3404ca3
3 changed files with 61 additions and 1 deletions

View File

@@ -159,7 +159,11 @@ impl MmapMemory {
let memfd = match memfd_image {
Some(image) => {
let base = unsafe { mmap.as_mut_ptr().add(pre_guard_bytes) };
let mut memfd_slot = MemFdSlot::create(base.cast(), minimum, alloc_bytes);
let mut memfd_slot = MemFdSlot::create(
base.cast(),
minimum,
alloc_bytes + extra_to_reserve_on_growth,
);
memfd_slot.instantiate(minimum, Some(image))?;
// On drop, we will unmap our mmap'd range that this
// memfd_slot was mapped on top of, so there is no