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 authored and GitHub committed 2020-02-14 01:42:27 +01:00
1 parent 78b5a06200
commit d3fa8c91af
6 files changed
+81 -4

No files matched your search

@@ -21,10 +21,10 @@ use crate::util;
use crate::imports::Imports;
use sc_executor_common::error::{Error, Result};
use sp_wasm_interface::{Pointer, WordSize};
use sp_wasm_interface::{Pointer, WordSize, Value};
use std::slice;
use std::marker;
use wasmtime::{Instance, Module, Memory, Table};
use wasmtime::{Instance, Module, Memory, Table, Val};
/// Wrap the given WebAssembly Instance of a wasm module with Substrate-runtime.
///
@@ -127,6 +127,24 @@ impl InstanceWrapper {
Ok(heap_base as u32)
}
/// Get the value from a global with the given `name`.
pub fn get_global_val(&self, name: &str) -> Result<Option<Value>> {
let global = match self.instance.get_export(name) {
Some(global) => global,
None => return Ok(None),
};
let global = global.global().ok_or_else(|| format!("`{}` is not a global", name))?;
match global.get() {
Val::I32(val) => Ok(Some(Value::I32(val))),
Val::I64(val) => Ok(Some(Value::I64(val))),
Val::F32(val) => Ok(Some(Value::F32(val))),
Val::F64(val) => Ok(Some(Value::F64(val))),
_ => Err("Unknow value type".into()),
}
}
}
/// Extract linear memory instance from the given instance.