mirror of
https://github.com/extism/extism.git
synced 2026-01-08 21:38:13 -05:00
feat: Use quickcheck to test allocations, fix one bug that was uncovered. (#662)
- Adds quickcheck tests for alloc/free/load/store from the kernel, I wasn't able to include these in the new wasm-bindgen tests because `getrandom` isn't available on wasm32-unknown-unknown - Fixes a bug in the calculation of how much memory is needed to allocate the next block in the kernel. This bug is triggered when allocating at the end of a page, the size of the MemoryBlock value wasn't being taken in consideration when determining whether or not to call memory.grow
This commit is contained in:
@@ -270,12 +270,13 @@ impl MemoryRoot {
|
||||
|
||||
// Get the number of bytes available
|
||||
let mem_left = self_length - self_position - core::mem::size_of::<MemoryRoot>() as u64;
|
||||
let length_with_block = length + core::mem::size_of::<MemoryBlock>() as u64;
|
||||
|
||||
// When the allocation is larger than the number of bytes available
|
||||
// we will need to try to grow the memory
|
||||
if length >= mem_left {
|
||||
if length_with_block >= mem_left {
|
||||
// Calculate the number of pages needed to cover the remaining bytes
|
||||
let npages = num_pages(length - mem_left);
|
||||
let npages = num_pages(length_with_block - mem_left);
|
||||
let x = core::arch::wasm32::memory_grow(0, npages);
|
||||
if x == usize::MAX {
|
||||
return None;
|
||||
|
||||
Reference in New Issue
Block a user