2019-02-07 23:12:27 +00:00
|
|
|
use libc::{abort, c_char, c_int, exit, EAGAIN};
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "windows"))]
|
2019-03-15 21:10:17 +00:00
|
|
|
type PidT = libc::pid_t;
|
2019-02-07 23:12:27 +00:00
|
|
|
#[cfg(target_os = "windows")]
|
2019-03-15 21:10:17 +00:00
|
|
|
type PidT = c_int;
|
2018-11-20 19:11:58 +00:00
|
|
|
|
|
|
|
use std::ffi::CStr;
|
2019-01-23 07:27:13 +00:00
|
|
|
use wasmer_runtime_core::vm::Ctx;
|
2018-11-20 19:11:58 +00:00
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn abort_with_message(ctx: &mut Ctx, 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);
|
2019-01-31 22:48:29 +00:00
|
|
|
_abort(ctx);
|
2018-11-20 19:11:58 +00:00
|
|
|
}
|
|
|
|
|
2019-02-02 23:28:50 +00:00
|
|
|
pub fn _abort(_ctx: &mut Ctx) {
|
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
|
|
|
}
|
|
|
|
|
2019-03-15 21:10:17 +00:00
|
|
|
pub fn _fork(_ctx: &mut Ctx) -> PidT {
|
2018-12-02 00:14:16 +00:00
|
|
|
debug!("emscripten::_fork");
|
|
|
|
// unsafe {
|
|
|
|
// fork()
|
|
|
|
// }
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-02 23:28:50 +00:00
|
|
|
pub fn _endgrent(_ctx: &mut Ctx) {
|
2019-01-25 05:58:54 +00:00
|
|
|
debug!("emscripten::_endgrent");
|
|
|
|
}
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn _execve(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 {
|
2019-01-25 05:58:54 +00:00
|
|
|
debug!("emscripten::_execve");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-01-31 22:48:29 +00:00
|
|
|
#[allow(unreachable_code)]
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn _exit(_ctx: &mut Ctx, status: c_int) {
|
2019-02-01 01:44:57 +00:00
|
|
|
// -> !
|
2018-12-18 05:54:00 +00:00
|
|
|
debug!("emscripten::_exit {}", status);
|
2018-12-15 06:46:11 +00:00
|
|
|
unsafe { exit(status) }
|
2018-12-02 00:14:16 +00:00
|
|
|
}
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn em_abort(ctx: &mut Ctx, message: u32) {
|
2018-12-18 05:54:00 +00:00
|
|
|
debug!("emscripten::em_abort {}", message);
|
2019-01-24 21:04:12 +00:00
|
|
|
let message_addr = emscripten_memory_pointer!(ctx.memory(0), message) as *mut c_char;
|
2018-11-20 19:11:58 +00:00
|
|
|
unsafe {
|
|
|
|
let message = CStr::from_ptr(message_addr)
|
|
|
|
.to_str()
|
|
|
|
.unwrap_or("Unexpected abort");
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
abort_with_message(ctx, message);
|
2018-11-20 19:11:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn _kill(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
2019-01-25 05:58:54 +00:00
|
|
|
debug!("emscripten::_kill");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-05 23:25:51 +00:00
|
|
|
pub fn _sched_yield(_ctx: &mut Ctx) -> i32 {
|
|
|
|
debug!("emscripten::_sched_yield");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn _llvm_stacksave(_ctx: &mut Ctx) -> i32 {
|
|
|
|
debug!("emscripten::_llvm_stacksave");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn _llvm_stackrestore(_ctx: &mut Ctx, _one: i32) {
|
2019-01-25 05:58:54 +00:00
|
|
|
debug!("emscripten::_llvm_stackrestore");
|
|
|
|
}
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn _raise(_ctx: &mut Ctx, _one: i32) -> i32 {
|
2019-01-25 05:58:54 +00:00
|
|
|
debug!("emscripten::_raise");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn _sem_init(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 {
|
2019-01-25 05:58:54 +00:00
|
|
|
debug!("emscripten::_sem_init");
|
2019-04-30 18:47:03 +00:00
|
|
|
0
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn _sem_destroy(_ctx: &mut Ctx, _one: i32) -> i32 {
|
|
|
|
debug!("emscripten::_sem_destroy");
|
|
|
|
0
|
2019-01-25 05:58:54 +00:00
|
|
|
}
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn _sem_post(_ctx: &mut Ctx, _one: i32) -> i32 {
|
2019-01-25 05:58:54 +00:00
|
|
|
debug!("emscripten::_sem_post");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn _sem_wait(_ctx: &mut Ctx, _one: i32) -> i32 {
|
2019-01-25 05:58:54 +00:00
|
|
|
debug!("emscripten::_sem_post");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-05 23:25:51 +00:00
|
|
|
#[allow(clippy::cast_ptr_alignment)]
|
2019-03-12 21:00:33 +00:00
|
|
|
pub fn _getgrent(_ctx: &mut Ctx) -> c_int {
|
2019-02-06 05:48:05 +00:00
|
|
|
debug!("emscripten::_getgrent");
|
2019-02-05 23:25:51 +00:00
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-02 23:28:50 +00:00
|
|
|
pub fn _setgrent(_ctx: &mut Ctx) {
|
2019-01-25 05:58:54 +00:00
|
|
|
debug!("emscripten::_setgrent");
|
|
|
|
}
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn _setgroups(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
2019-01-25 05:58:54 +00:00
|
|
|
debug!("emscripten::_setgroups");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn _setitimer(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 {
|
2019-01-25 05:58:54 +00:00
|
|
|
debug!("emscripten::_setitimer");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn _usleep(_ctx: &mut Ctx, _one: i32) -> i32 {
|
2019-01-25 05:58:54 +00:00
|
|
|
debug!("emscripten::_usleep");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-03-20 23:46:42 +00:00
|
|
|
pub fn _nanosleep(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
|
|
|
debug!("emscripten::_nanosleep");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn _utimes(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
2019-01-25 05:58:54 +00:00
|
|
|
debug!("emscripten::_utimes");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn _waitpid(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 {
|
2019-01-25 05:58:54 +00:00
|
|
|
debug!("emscripten::_waitpid");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn abort_stack_overflow(ctx: &mut Ctx, _what: c_int) {
|
2018-11-24 14:55:21 +00:00
|
|
|
debug!("emscripten::abort_stack_overflow");
|
|
|
|
// TODO: Message incomplete. Need to finish em runtime data first
|
2019-02-01 01:44:57 +00:00
|
|
|
abort_with_message(
|
|
|
|
ctx,
|
2019-02-09 21:58:05 +00:00
|
|
|
"Stack overflow! Attempted to allocate some bytes on the stack",
|
2019-02-01 01:44:57 +00:00
|
|
|
);
|
2018-11-20 19:11:58 +00:00
|
|
|
}
|
2018-12-13 18:28:30 +00:00
|
|
|
|
2019-02-02 23:28:50 +00:00
|
|
|
pub fn _llvm_trap(ctx: &mut Ctx) {
|
2018-12-13 18:28:30 +00:00
|
|
|
debug!("emscripten::_llvm_trap");
|
2019-02-09 21:58:05 +00:00
|
|
|
abort_with_message(ctx, "abort!");
|
2018-12-13 18:28:30 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 20:42:13 +00:00
|
|
|
pub fn _llvm_eh_typeid_for(_ctx: &mut Ctx, _type_info_addr: u32) -> i32 {
|
|
|
|
debug!("emscripten::_llvm_eh_typeid_for");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn _system(_ctx: &mut Ctx, _one: i32) -> c_int {
|
2018-12-13 18:28:30 +00:00
|
|
|
debug!("emscripten::_system");
|
|
|
|
// TODO: May need to change this Em impl to a working version
|
|
|
|
eprintln!("Can't call external programs");
|
2019-04-30 04:45:38 +00:00
|
|
|
EAGAIN
|
2018-12-13 18:28:30 +00:00
|
|
|
}
|
|
|
|
|
2019-02-09 21:58:05 +00:00
|
|
|
pub fn _popen(_ctx: &mut Ctx, _one: i32, _two: i32) -> c_int {
|
2018-12-13 18:28:30 +00:00
|
|
|
debug!("emscripten::_popen");
|
|
|
|
// TODO: May need to change this Em impl to a working version
|
|
|
|
eprintln!("Missing function: popen");
|
2018-12-18 17:43:59 +00:00
|
|
|
unsafe {
|
|
|
|
abort();
|
|
|
|
}
|
2018-12-13 18:28:30 +00:00
|
|
|
}
|