wasmer/src/apis/emscripten/memory.rs

39 lines
1.1 KiB
Rust
Raw Normal View History

2018-11-22 04:59:23 +00:00
use libc::{c_void, memcpy, size_t};
use crate::webassembly::Instance;
2018-11-24 14:55:21 +00:00
use super::process::abort_with_message;
2018-11-20 19:11:58 +00:00
/// emscripten: _emscripten_memcpy_big
2018-11-22 04:59:23 +00:00
pub extern "C" fn _emscripten_memcpy_big(
dest: u32,
src: u32,
len: u32,
instance: &mut Instance,
) -> u32 {
2018-11-21 03:24:23 +00:00
debug!("emscripten::_emscripten_memcpy_big");
2018-11-20 19:11:58 +00: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-22 04:59:23 +00:00
unsafe {
memcpy(dest_addr, src_addr, len as size_t);
}
2018-11-20 19:11:58 +00:00
dest
}
/// emscripten: getTotalMemory
pub extern "C" fn get_total_memory(instance: &mut Instance) -> u32 {
2018-11-21 03:24:23 +00:00
debug!("emscripten::get_total_memory");
2018-11-26 21:06:27 +00:00
// instance.memories[0].current_pages()
16777216
2018-11-20 19:11:58 +00:00
}
/// emscripten: enlargeMemory
2018-11-22 05:07:01 +00:00
pub extern "C" fn enlarge_memory(_instance: &mut Instance) {
2018-11-21 03:24:23 +00:00
debug!("emscripten::enlarge_memory");
// instance.memories[0].grow(100);
2018-11-20 19:11:58 +00:00
}
2018-11-24 14:55:21 +00: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!");
}