Skip to content

Commit

Permalink
Add memory offset addr impl
Browse files Browse the repository at this point in the history
  • Loading branch information
appcypher committed Jan 17, 2019
1 parent 82cb5dd commit ba6828c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/runtime/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,24 @@ impl Namespace for Instance {

// TODO Remove this later, only needed for compilation till emscripten is updated
impl Instance {
pub fn memory_offset_addr(&self, _index: usize, _offset: usize) -> *const usize {
unimplemented!("TODO replace this emscripten stub")
pub fn memory_offset_addr(&self, index: usize, offset: usize) -> *const u8 {
// Get vm context.
let vmctx = &self.vmctx;

// Check if the index specified refers to an imported memory.
if index < self.module.0.imported_memories.len() {
// Get imported memory at specified index.
let memory = unsafe { vmctx.imported_memories.add(index) };

// Get the actual address of the specified offset.
return unsafe { (*(*memory).memory).base.add(offset) }
}

// Index points to a locally-defined memory
// Get local memory at specified index.
let memory = unsafe { vmctx.memories.add(index) };

// Get the actual address of the specified offset.
unsafe { (*memory).base.add(offset) }
}
}

0 comments on commit ba6828c

Please sign in to comment.