Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Execute wasm calls in shared library
Run `cargo run --release -- purge-chain --dev && cargo run --release -- --dev`.

Besides this nothing works (no tests, no import, etc.).
  • Loading branch information
cmichi committed Feb 22, 2019
commit 56f72cd634b5930745b9de85ae6f73c100ca1875
22 changes: 10 additions & 12 deletions core/executor/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use log::trace;
use wasmi::Error;
use wasmi::MemoryRef;
use wasmi::memory_units::Bytes;
use crate::wasm_executor::{memory_set, memory_get, memory_get_into};

// The pointers need to be aligned to 8 bytes.
const ALIGNMENT: u32 = 8;
Expand All @@ -40,7 +41,6 @@ pub const REQUESTED_SIZE_TOO_LARGE: &str = "Requested size to allocate is too la
pub struct FreeingBumpHeapAllocator {
bumper: u32,
heads: [u32; N],
heap: MemoryRef,
max_heap_size: u32,
ptr_offset: u32,
total_size: u32,
Expand All @@ -63,12 +63,7 @@ impl FreeingBumpHeapAllocator {
/// * `heap` - A `MemoryRef` to the available `MemoryInstance` which is
/// used as the heap.
///
pub fn new(mem: MemoryRef) -> Self {
let current_size: Bytes = mem.current_size().into();
let current_size = current_size.0 as u32;
let used_size = mem.used_size().0 as u32;
let heap_size = current_size - used_size;

pub fn new(used_size: u32, heap_size: u32) -> Self {
let mut ptr_offset = used_size;
let padding = ptr_offset % ALIGNMENT;
if padding != 0 {
Expand All @@ -78,7 +73,6 @@ impl FreeingBumpHeapAllocator {
FreeingBumpHeapAllocator {
bumper: 0,
heads: [0; N],
heap: mem,
max_heap_size: heap_size,
ptr_offset: ptr_offset,
total_size: 0,
Expand Down Expand Up @@ -179,22 +173,26 @@ impl FreeingBumpHeapAllocator {

fn get_heap_4bytes(&mut self, ptr: u32) -> Result<[u8; 4], Error> {
let mut arr = [0u8; 4];
self.heap.get_into(self.ptr_offset + ptr, &mut arr)?;
memory_get_into(self.ptr_offset + ptr, &mut arr)
.map_err(|e| wasmi::Error::Memory(e.to_string()))?;
Ok(arr)
}

fn get_heap_byte(&mut self, ptr: u32) -> Result<u8, Error> {
let mut arr = [0u8; 1];
self.heap.get_into(self.ptr_offset + ptr, &mut arr)?;
memory_get_into(self.ptr_offset + ptr, &mut arr)
.map_err(|e| wasmi::Error::Memory(e.to_string()))?;
Ok(arr[0])
}

fn set_heap(&mut self, ptr: u32, value: u8) -> Result<(), Error> {
self.heap.set(self.ptr_offset + ptr, &[value])
memory_set(self.ptr_offset + ptr, &[value])
.map_err(|e| wasmi::Error::Memory(e.to_string()))
}

fn set_heap_4bytes(&mut self, ptr: u32, value: [u8; 4]) -> Result<(), Error> {
self.heap.set(self.ptr_offset + ptr, &value)
memory_set(self.ptr_offset + ptr, &value)
.map_err(|e| wasmi::Error::Memory(e.to_string()))
}

}
Expand Down
3 changes: 3 additions & 0 deletions core/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#![warn(missing_docs)]
#![recursion_limit="128"]

#[macro_use]
extern crate lazy_static;

#[macro_use]
mod wasm_utils;
mod wasm_executor;
Expand Down
Loading