wasmer/lib/emscripten/src/process.rs

70 lines
1.8 KiB
Rust
Raw Normal View History

use libc::{abort, c_char, c_int, exit, pid_t, EAGAIN};
2018-11-20 20:11:58 +01:00
use std::ffi::CStr;
2019-01-23 01:27:13 -06:00
use wasmer_runtime_core::vm::Ctx;
2018-11-20 20:11:58 +01:00
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
}
2019-01-24 13:04:12 -08:00
pub extern "C" fn _fork(_ctx: &mut Ctx) -> pid_t {
debug!("emscripten::_fork");
// unsafe {
// fork()
// }
-1
}
2019-01-24 13:04:12 -08:00
pub extern "C" fn _exit(status: c_int, _ctx: &mut Ctx) -> ! {
debug!("emscripten::_exit {}", status);
2018-12-15 00:46:11 -06:00
unsafe { exit(status) }
}
2019-01-24 13:04:12 -08:00
pub extern "C" fn em_abort(message: u32, ctx: &mut Ctx) {
debug!("emscripten::em_abort {}", message);
2019-01-24 13:04:12 -08:00
let message_addr = emscripten_memory_pointer!(ctx.memory(0), message) as *mut c_char;
2018-11-20 20:11:58 +01:00
unsafe {
let message = CStr::from_ptr(message_addr)
.to_str()
.unwrap_or("Unexpected abort");
abort_with_message(message);
}
}
pub extern "C" fn abort_stack_overflow(_what: c_int, _ctx: &mut Ctx) {
2018-11-24 15:55:21 +01:00
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
}
pub extern "C" fn _llvm_trap(_ctx: &mut Ctx) {
debug!("emscripten::_llvm_trap");
abort_with_message("abort!");
}
pub extern "C" fn _system(_ctx: &mut Ctx) -> c_int {
debug!("emscripten::_system");
// TODO: May need to change this Em impl to a working version
eprintln!("Can't call external programs");
return EAGAIN;
}
pub extern "C" fn _popen(_ctx: &mut Ctx) -> c_int {
debug!("emscripten::_popen");
// TODO: May need to change this Em impl to a working version
eprintln!("Missing function: popen");
2018-12-18 09:43:59 -08:00
unsafe {
abort();
}
}