2018-11-24 14:55:21 +00:00
|
|
|
use super::process::abort_with_message;
|
2018-12-18 17:43:59 +00:00
|
|
|
use libc::{c_int, c_void, memcpy, size_t};
|
2019-01-23 07:27:13 +00:00
|
|
|
use wasmer_runtime_core::vm::Ctx;
|
2018-11-20 19:11:58 +00:00
|
|
|
|
|
|
|
/// emscripten: _emscripten_memcpy_big
|
2019-01-24 21:04:12 +00:00
|
|
|
pub extern "C" fn _emscripten_memcpy_big(dest: u32, src: u32, len: u32, ctx: &mut Ctx) -> u32 {
|
2018-12-18 05:54:00 +00:00
|
|
|
debug!(
|
|
|
|
"emscripten::_emscripten_memcpy_big {}, {}, {}",
|
|
|
|
dest, src, len
|
|
|
|
);
|
2019-01-24 21:04:12 +00:00
|
|
|
let dest_addr = emscripten_memory_pointer!(ctx.memory(0), dest) as *mut c_void;
|
|
|
|
let src_addr = emscripten_memory_pointer!(ctx.memory(0), src) 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
|
2019-01-24 21:04:12 +00:00
|
|
|
pub extern "C" fn get_total_memory(_ctx: &mut Ctx) -> 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()
|
2019-01-23 07:27:13 +00:00
|
|
|
// TODO: Fix implementation
|
2018-12-08 06:19:55 +00:00
|
|
|
16_777_216
|
2018-11-20 19:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// emscripten: enlargeMemory
|
2019-01-24 21:04:12 +00:00
|
|
|
pub extern "C" fn enlarge_memory(_ctx: &mut Ctx) -> u32 {
|
2018-11-21 03:24:23 +00:00
|
|
|
debug!("emscripten::enlarge_memory");
|
|
|
|
// instance.memories[0].grow(100);
|
2019-01-23 07:27:13 +00:00
|
|
|
// TODO: Fix implementation
|
2019-01-23 18:54:03 +00:00
|
|
|
0
|
2018-11-20 19:11:58 +00:00
|
|
|
}
|
2018-11-24 14:55:21 +00:00
|
|
|
|
|
|
|
/// emscripten: abortOnCannotGrowMemory
|
2019-01-24 23:44:08 +00:00
|
|
|
pub extern "C" fn abort_on_cannot_grow_memory(_ctx: &mut Ctx) -> u32 {
|
2018-11-24 14:55:21 +00:00
|
|
|
debug!("emscripten::abort_on_cannot_grow_memory");
|
|
|
|
abort_with_message("Cannot enlarge memory arrays!");
|
2019-01-23 18:54:03 +00:00
|
|
|
0
|
2018-11-24 14:55:21 +00:00
|
|
|
}
|
2018-12-13 18:28:30 +00:00
|
|
|
|
|
|
|
/// emscripten: ___map_file
|
2019-01-26 23:02:51 +00:00
|
|
|
pub extern "C" fn ___map_file(one: u32, two: u32, _ctx: &mut Ctx) -> c_int {
|
2018-12-13 18:28:30 +00:00
|
|
|
debug!("emscripten::___map_file");
|
|
|
|
// NOTE: TODO: Em returns -1 here as well. May need to implement properly
|
|
|
|
-1
|
|
|
|
}
|