wasmer/src/apis/emscripten/process.rs

44 lines
1007 B
Rust
Raw Normal View History

2018-11-20 20:11:58 +01:00
use libc::{
// c_int,
// c_void,
c_char,
// size_t,
// ssize_t,
abort,
};
use std::ffi::CStr;
use crate::webassembly::{Instance};
extern "C" fn abort_with_message(message: &str) {
2018-11-20 19:24:23 -08:00
debug!("emscripten::abort_with_message");
2018-11-20 20:11:58 +01:00
println!("{}", message);
_abort();
}
/// emscripten: _abort
pub extern "C" fn _abort() {
2018-11-20 19:24:23 -08:00
debug!("emscripten::_abort");
2018-11-20 20:11:58 +01:00
unsafe { abort(); }
}
/// emscripten: abort
pub extern "C" fn em_abort(message: u32, instance: &mut Instance) {
2018-11-20 19:24:23 -08:00
debug!("emscripten::em_abort");
2018-11-20 20:11:58 +01:00
let message_addr = instance.memory_offset_addr(0, message as usize) as *mut c_char;
unsafe {
let message = CStr::from_ptr(message_addr)
.to_str()
.unwrap_or("Unexpected abort");
abort_with_message(message);
}
}
/// emscripten: abortOnCannotGrowMemory
pub extern "C" fn abort_on_cannot_grow_memory() {
2018-11-20 19:24:23 -08:00
debug!("emscripten::abort_on_cannot_grow_memory");
2018-11-20 20:11:58 +01:00
abort_with_message("Cannot enlarge memory arrays!");
}