wasmer/src/apis/emscripten/process.rs

45 lines
1016 B
Rust
Raw Normal View History

2018-11-20 20:11:58 +01:00
use libc::{
// size_t,
// ssize_t,
abort,
2018-11-21 20:59:23 -08:00
// c_int,
// c_void,
c_char,
2018-11-20 20:11:58 +01:00
};
2018-11-21 20:59:23 -08:00
use crate::webassembly::Instance;
2018-11-20 20:11:58 +01:00
use std::ffi::CStr;
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-21 20:59:23 -08:00
unsafe {
abort();
}
2018-11-20 20:11:58 +01:00
}
/// 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!");
}