Adds a test to ensure that we clear the heap between calls into runtime (#4903)

* Adds a test to ensure that we clear the heap between calls into runtime

The tests shows that we currently not clearing the heap in wasmtime.
For now we don't run the test for wasmtime.

* Fix compilation
This commit is contained in:
Bastian Köcher
2020-02-14 01:42:27 +01:00
committed by GitHub
parent 78b5a06200
commit d3fa8c91af
6 changed files with 81 additions and 4 deletions
@@ -275,6 +275,20 @@ sp_core::wasm_export_functions! {
data.to_vec()
}
// Check that the heap at `heap_base + offset` don't contains the test message.
// After the check succeeds the test message is written into the heap.
//
// It is expected that the given pointer is not allocated.
fn check_and_set_in_heap(heap_base: u32, offset: u32) {
let test_message = b"Hello invalid heap memory";
let ptr = unsafe { (heap_base + offset) as *mut u8 };
let message_slice = unsafe { sp_std::slice::from_raw_parts_mut(ptr, test_message.len()) };
assert_ne!(test_message, message_slice);
message_slice.copy_from_slice(test_message);
}
}
#[cfg(not(feature = "std"))]