2018-12-15 00:46:11 -06:00
|
|
|
use libc::{abort, c_char, c_int, exit, pid_t};
|
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;
|
|
|
|
|
2018-11-24 15:55:21 +01:00
|
|
|
pub 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-12-01 16:14:16 -08:00
|
|
|
pub extern "C" fn _fork(_instance: &mut Instance) -> pid_t {
|
|
|
|
debug!("emscripten::_fork");
|
|
|
|
// unsafe {
|
|
|
|
// fork()
|
|
|
|
// }
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub extern "C" fn _exit(status: c_int, _instance: &mut Instance) -> ! {
|
|
|
|
debug!("emscripten::_exit");
|
2018-12-15 00:46:11 -06:00
|
|
|
unsafe { exit(status) }
|
2018-12-01 16:14:16 -08:00
|
|
|
}
|
|
|
|
|
2018-11-20 20:11:58 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-24 15:55:21 +01: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 20:11:58 +01:00
|
|
|
}
|