wasmer/lib/emscripten/src/memory.rs

49 lines
1.4 KiB
Rust
Raw Normal View History

2018-11-24 15:55:21 +01:00
use super::process::abort_with_message;
2018-12-18 09:43:59 -08:00
use libc::{c_int, c_void, memcpy, size_t};
use wasmer_runtime_core::Instance;
2018-11-20 20:11:58 +01:00
/// emscripten: _emscripten_memcpy_big
2018-11-21 20:59:23 -08:00
pub extern "C" fn _emscripten_memcpy_big(
dest: u32,
src: u32,
len: u32,
instance: &mut Instance,
) -> u32 {
debug!(
"emscripten::_emscripten_memcpy_big {}, {}, {}",
dest, src, len
);
2018-11-20 20:11:58 +01:00
let dest_addr = instance.memory_offset_addr(0, dest as usize) as *mut c_void;
let src_addr = instance.memory_offset_addr(0, src as usize) as *mut c_void;
2018-11-21 20:59:23 -08:00
unsafe {
memcpy(dest_addr, src_addr, len as size_t);
}
2018-11-20 20:11:58 +01:00
dest
}
/// emscripten: getTotalMemory
2018-11-26 20:28:13 -08:00
pub extern "C" fn get_total_memory(_instance: &mut Instance) -> u32 {
2018-11-20 19:24:23 -08:00
debug!("emscripten::get_total_memory");
2018-11-26 16:06:27 -05:00
// instance.memories[0].current_pages()
16_777_216
2018-11-20 20:11:58 +01:00
}
/// emscripten: enlargeMemory
2018-11-21 21:07:01 -08:00
pub extern "C" fn enlarge_memory(_instance: &mut Instance) {
2018-11-20 19:24:23 -08:00
debug!("emscripten::enlarge_memory");
// instance.memories[0].grow(100);
2018-11-20 20:11:58 +01:00
}
2018-11-24 15:55:21 +01:00
/// emscripten: abortOnCannotGrowMemory
pub extern "C" fn abort_on_cannot_grow_memory() {
debug!("emscripten::abort_on_cannot_grow_memory");
abort_with_message("Cannot enlarge memory arrays!");
}
/// emscripten: ___map_file
pub extern "C" fn ___map_file() -> c_int {
debug!("emscripten::___map_file");
// NOTE: TODO: Em returns -1 here as well. May need to implement properly
-1
}