Add fn for splitting borrow of memory & data in Ctx, use in WASI

This commit is contained in:
Mark McCaskey
2019-12-16 16:48:52 -05:00
parent 598fbfa44a
commit bb344c1ab1
2 changed files with 55 additions and 69 deletions

View File

@ -401,6 +401,21 @@ impl Ctx {
}
}
/// Splits the borrow, getting both Memory and a mutable reference to
/// the data type provided.
///
/// This method is required to access both at the same time.
/// This is useful if the data stores information about locations in Wasm
/// memory that a hostcall needs to access.
///
/// # Safety
///
/// This function must be called with the same type, `T`, that the `data`
/// was set to.
pub unsafe fn memory_and_data_mut<T>(&mut self, mem_index: u32) -> (&Memory, &mut T) {
(self.memory(mem_index), &mut *(self.data as *mut T))
}
/// Gives access to the emscripten symbol map, used for debugging
pub unsafe fn borrow_symbol_map(&self) -> &Option<HashMap<u32, String>> {
&(*self.module).info.em_symbol_map