Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions demo/runtime/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ std = [

[profile.release]
panic = "abort"
lto = true

[workspace]
members = []
Binary file not shown.
Binary file modified demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm
100644 → 100755
Binary file not shown.
1 change: 1 addition & 0 deletions polkadot/runtime/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ std = [

[profile.release]
panic = "abort"
lto = true

[workspace]
members = []
Binary file not shown.
Binary file modified polkadot/runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.wasm
100644 → 100755
Binary file not shown.
29 changes: 21 additions & 8 deletions substrate/executor/src/wasm_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,23 @@ struct Heap {
}

impl Heap {
fn new() -> Self {
Heap {
end: 262144,
fn new(memory: &MemoryInstance) -> Result<Self> {
const HEAP_SIZE_IN_PAGES: u32 = 8;
const PAGE_SIZE_IN_BYTES: u32 = 65536;

let prev_page_count = memory.grow(HEAP_SIZE_IN_PAGES).map_err(
|_: ::parity_wasm::interpreter::Error<DummyUserError>| Error::from(ErrorKind::Runtime),
)?;
if prev_page_count == 0xFFFFFFFF {
// Wasm vm refuses to mount the specified amount of new pages. This
// could mean that wasm binary specifies memory limit and we are trying
// to allocate beyond that limit.
return Err(ErrorKind::Runtime.into());
}
let allocated_area_start = prev_page_count * PAGE_SIZE_IN_BYTES;
Ok(Heap {
end: allocated_area_start as u32,
})
}
fn allocate(&mut self, size: u32) -> u32 {
let r = self.end;
Expand All @@ -57,13 +70,13 @@ struct FunctionExecutor<'e, E: Externalities + 'e> {
}

impl<'e, E: Externalities> FunctionExecutor<'e, E> {
fn new(m: &Arc<MemoryInstance>, e: &'e mut E) -> Self {
FunctionExecutor {
heap: Heap::new(),
fn new(m: &Arc<MemoryInstance>, e: &'e mut E) -> Result<Self> {
Ok(FunctionExecutor {
heap: Heap::new(&*m)?,
memory: Arc::clone(m),
ext: e,
hash_lookup: HashMap::new(),
}
})
}
}

Expand Down Expand Up @@ -317,7 +330,7 @@ impl CodeExecutor for WasmExecutor {
let module = program.add_module_by_sigs("test", module, map!["env" => FunctionExecutor::<E>::SIGNATURES]).expect("runtime signatures always provided; qed");

let memory = module.memory(ItemIndex::Internal(0)).expect("all modules compiled with rustc include memory segments; qed");
let mut fec = FunctionExecutor::new(&memory, ext);
let mut fec = FunctionExecutor::new(&memory, ext)?;

let size = data.len() as u32;
let offset = fec.heap.allocate(size);
Expand Down
1 change: 1 addition & 0 deletions substrate/executor/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ substrate-runtime-io = { path = "../../runtime-io", version = "0.1", default_fea

[profile.release]
panic = "abort"
lto = true

[workspace]
members = []
Binary file not shown.
Binary file modified substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm
100644 → 100755
Binary file not shown.
1 change: 1 addition & 0 deletions substrate/test-runtime/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ crate-type = ["cdylib"]

[profile.release]
panic = "abort"
lto = true

[workspace]
members = []
Binary file not shown.
Binary file not shown.