2018-12-18 09:43:36 -08:00
|
|
|
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 {
|
2018-12-01 16:14:16 -08:00
|
|
|
debug!("emscripten::_fork");
|
|
|
|
// unsafe {
|
|
|
|
// fork()
|
|
|
|
// }
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-01-24 23:58:54 -06:00
|
|
|
pub extern "C" fn _endgrent(_ctx: &mut Ctx) {
|
|
|
|
debug!("emscripten::_endgrent");
|
|
|
|
}
|
|
|
|
|
|
|
|
pub extern "C" fn _execve(one: i32, two: i32, three: i32, ctx: &mut Ctx) -> i32 {
|
|
|
|
debug!("emscripten::_execve");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-01-24 13:04:12 -08:00
|
|
|
pub extern "C" fn _exit(status: c_int, _ctx: &mut Ctx) -> ! {
|
2018-12-17 23:54:00 -06:00
|
|
|
debug!("emscripten::_exit {}", status);
|
2018-12-15 00:46:11 -06:00
|
|
|
unsafe { exit(status) }
|
2018-12-01 16:14:16 -08:00
|
|
|
}
|
|
|
|
|
2019-01-24 13:04:12 -08:00
|
|
|
pub extern "C" fn em_abort(message: u32, ctx: &mut Ctx) {
|
2018-12-17 23:54:00 -06:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-24 23:58:54 -06:00
|
|
|
pub extern "C" fn _kill(one: i32, two: i32, ctx: &mut Ctx) -> i32 {
|
|
|
|
debug!("emscripten::_kill");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub extern "C" fn _llvm_stackrestore(one: i32, ctx: &mut Ctx) {
|
|
|
|
debug!("emscripten::_llvm_stackrestore");
|
|
|
|
}
|
|
|
|
|
|
|
|
pub extern "C" fn _raise(one: i32, ctx: &mut Ctx) -> i32 {
|
|
|
|
debug!("emscripten::_raise");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub extern "C" fn _sem_init(one: i32, two: i32, three: i32, ctx: &mut Ctx) -> i32 {
|
|
|
|
debug!("emscripten::_sem_init");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub extern "C" fn _sem_post(one: i32, ctx: &mut Ctx) -> i32 {
|
|
|
|
debug!("emscripten::_sem_post");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub extern "C" fn _sem_wait(one: i32, ctx: &mut Ctx) -> i32 {
|
|
|
|
debug!("emscripten::_sem_post");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub extern "C" fn _setgrent(ctx: &mut Ctx) {
|
|
|
|
debug!("emscripten::_setgrent");
|
|
|
|
}
|
|
|
|
|
|
|
|
pub extern "C" fn _setgroups(one: i32, two: i32, ctx: &mut Ctx) -> i32 {
|
|
|
|
debug!("emscripten::_setgroups");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub extern "C" fn _setitimer(one: i32, two: i32, three: i32, ctx: &mut Ctx) -> i32 {
|
|
|
|
debug!("emscripten::_setitimer");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub extern "C" fn _usleep(one: i32, ctx: &mut Ctx) -> i32 {
|
|
|
|
debug!("emscripten::_usleep");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub extern "C" fn _utimes(one: i32, two: i32, ctx: &mut Ctx) -> i32 {
|
|
|
|
debug!("emscripten::_utimes");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub extern "C" fn _waitpid(one: i32, two: i32, three: i32, ctx: &mut Ctx) -> i32 {
|
|
|
|
debug!("emscripten::_waitpid");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-01-24 15:44:08 -08:00
|
|
|
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
|
|
|
}
|
2018-12-13 19:28:30 +01:00
|
|
|
|
2019-01-24 15:44:08 -08:00
|
|
|
pub extern "C" fn _llvm_trap(_ctx: &mut Ctx) {
|
2018-12-13 19:28:30 +01:00
|
|
|
debug!("emscripten::_llvm_trap");
|
|
|
|
abort_with_message("abort!");
|
|
|
|
}
|
|
|
|
|
2019-01-26 17:02:51 -06:00
|
|
|
pub extern "C" fn _system(one: i32, _ctx: &mut Ctx) -> c_int {
|
2018-12-13 19:28:30 +01:00
|
|
|
debug!("emscripten::_system");
|
|
|
|
// TODO: May need to change this Em impl to a working version
|
|
|
|
eprintln!("Can't call external programs");
|
|
|
|
return EAGAIN;
|
|
|
|
}
|
|
|
|
|
2019-01-26 17:02:51 -06:00
|
|
|
pub extern "C" fn _popen(one: i32, two: i32, _ctx: &mut Ctx) -> c_int {
|
2018-12-13 19:28:30 +01:00
|
|
|
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();
|
|
|
|
}
|
2018-12-13 19:28:30 +01:00
|
|
|
}
|