wasmer/src/apis/emscripten/process.rs

36 lines
952 B
Rust
Raw Normal View History

2018-11-24 14:55:21 +00:00
use libc::{abort, c_char};
2018-11-20 19:11:58 +00:00
2018-11-22 04:59:23 +00:00
use crate::webassembly::Instance;
2018-11-20 19:11:58 +00:00
use std::ffi::CStr;
2018-11-24 14:55:21 +00:00
pub extern "C" fn abort_with_message(message: &str) {
2018-11-21 03:24:23 +00:00
debug!("emscripten::abort_with_message");
2018-11-20 19:11:58 +00:00
println!("{}", message);
_abort();
}
pub extern "C" fn _abort() {
2018-11-21 03:24:23 +00:00
debug!("emscripten::_abort");
2018-11-22 04:59:23 +00:00
unsafe {
abort();
}
2018-11-20 19:11:58 +00:00
}
pub extern "C" fn em_abort(message: u32, instance: &mut Instance) {
2018-11-21 03:24:23 +00:00
debug!("emscripten::em_abort");
2018-11-20 19:11:58 +00: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);
}
}
2018-11-24 14:55:21 +00:00
pub extern "C" fn abort_stack_overflow() {
debug!("emscripten::abort_stack_overflow");
// TODO: Message incomplete. Need to finish em runtime data first
abort_with_message("Stack overflow! Attempted to allocate some bytes on the stack");
2018-11-20 19:11:58 +00:00
}