wasm_interp: tests for memory allocation instructions

This commit is contained in:
Brian Carroll 2022-11-25 16:51:36 +00:00
parent 06f3726e35
commit 2bd67a3292
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0
3 changed files with 59 additions and 7 deletions

View file

@ -790,6 +790,16 @@ impl<'a> MemorySection<'a> {
};
Ok(min_pages * MemorySection::PAGE_SIZE)
}
pub fn max_bytes(&self) -> Result<Option<u32>, ParseError> {
let mut cursor = 0;
let memory_limits = Limits::parse((), &self.bytes, &mut cursor)?;
let bytes = match memory_limits {
Limits::Min(_) => None,
Limits::MinMax(_, pages) => Some(pages * MemorySection::PAGE_SIZE),
};
Ok(bytes)
}
}
section_impl!(MemorySection, SectionId::Memory);