mirror of
https://github.com/extism/extism.git
synced 2026-01-09 13:57:55 -05:00
fix(kernel): update outdated implementation of MemoryBlock::next_ptr (#509)
`MemoryBlock::next_ptr` used to calculate the offset to the data of the next block, but it should be returning the start of the `MemoryBlock` structure in memory. Also updates the tests for this case. This was discovered when trying to update the kernel in the go-sdk: https://github.com/extism/go-sdk/pull/32 --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: zshipko <zshipko@users.noreply.github.com>
This commit is contained in:
@@ -283,7 +283,7 @@ impl MemoryRoot {
|
||||
|
||||
// Bump the position by the size of the actual data + the size of the MemoryBlock structure
|
||||
self.position.fetch_add(
|
||||
length + core::mem::size_of::<MemoryBlock>() as u64 - 1,
|
||||
length + core::mem::size_of::<MemoryBlock>() as u64,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
|
||||
@@ -316,9 +316,7 @@ impl MemoryBlock {
|
||||
/// is calculated based on metadata provided by the current block
|
||||
#[inline]
|
||||
pub unsafe fn next_ptr(&mut self) -> *mut MemoryBlock {
|
||||
self.data
|
||||
.as_mut_ptr()
|
||||
.add(self.size + core::mem::size_of::<MemoryBlock>()) as *mut MemoryBlock
|
||||
self.data.as_mut_ptr().add(self.size) as *mut MemoryBlock
|
||||
}
|
||||
|
||||
/// Mark a block as free
|
||||
|
||||
Reference in New Issue
Block a user