2019-02-07 15:12:27 -08:00
|
|
|
use libc::{abort, c_char, c_int, exit, EAGAIN};
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "windows"))]
|
2019-03-15 14:10:17 -07:00
|
|
|
type PidT = libc::pid_t;
|
2019-02-07 15:12:27 -08:00
|
|
|
#[cfg(target_os = "windows")]
|
2019-03-15 14:10:17 -07:00
|
|
|
type PidT = c_int;
|
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
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn abort_with_message(ctx: &mut Ctx, 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);
|
2019-01-31 14:48:29 -08:00
|
|
|
_abort(ctx);
|
2018-11-20 20:11:58 +01:00
|
|
|
}
|
|
|
|
|
2019-02-02 15:28:50 -08:00
|
|
|
pub fn _abort(_ctx: &mut Ctx) {
|
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-03-15 14:10:17 -07:00
|
|
|
pub fn _fork(_ctx: &mut Ctx) -> PidT {
|
2018-12-01 16:14:16 -08:00
|
|
|
debug!("emscripten::_fork");
|
|
|
|
// unsafe {
|
|
|
|
// fork()
|
|
|
|
// }
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-02 15:28:50 -08:00
|
|
|
pub fn _endgrent(_ctx: &mut Ctx) {
|
2019-01-24 23:58:54 -06:00
|
|
|
debug!("emscripten::_endgrent");
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn _execve(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 {
|
2019-01-24 23:58:54 -06:00
|
|
|
debug!("emscripten::_execve");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-01-31 14:48:29 -08:00
|
|
|
#[allow(unreachable_code)]
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn _exit(_ctx: &mut Ctx, status: c_int) {
|
2019-01-31 17:44:57 -08:00
|
|
|
// -> !
|
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-02-09 13:58:05 -08:00
|
|
|
pub fn em_abort(ctx: &mut Ctx, message: u32) {
|
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");
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
abort_with_message(ctx, message);
|
2018-11-20 20:11:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn _kill(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
2019-01-24 23:58:54 -06:00
|
|
|
debug!("emscripten::_kill");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-05 17:25:51 -06: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 13:58:05 -08:00
|
|
|
pub fn _llvm_stackrestore(_ctx: &mut Ctx, _one: i32) {
|
2019-01-24 23:58:54 -06:00
|
|
|
debug!("emscripten::_llvm_stackrestore");
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn _raise(_ctx: &mut Ctx, _one: i32) -> i32 {
|
2019-01-24 23:58:54 -06:00
|
|
|
debug!("emscripten::_raise");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn _sem_init(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 {
|
2019-05-03 17:34:57 -07:00
|
|
|
debug!("emscripten::_sem_init: {}, {}, {}", _one, _two, _three);
|
2019-04-30 11:47:03 -07:00
|
|
|
0
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn _sem_destroy(_ctx: &mut Ctx, _one: i32) -> i32 {
|
|
|
|
debug!("emscripten::_sem_destroy");
|
|
|
|
0
|
2019-01-24 23:58:54 -06:00
|
|
|
}
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn _sem_post(_ctx: &mut Ctx, _one: i32) -> i32 {
|
2019-01-24 23:58:54 -06:00
|
|
|
debug!("emscripten::_sem_post");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn _sem_wait(_ctx: &mut Ctx, _one: i32) -> i32 {
|
2019-01-24 23:58:54 -06:00
|
|
|
debug!("emscripten::_sem_post");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-05 17:25:51 -06:00
|
|
|
#[allow(clippy::cast_ptr_alignment)]
|
2019-03-12 22:00:33 +01:00
|
|
|
pub fn _getgrent(_ctx: &mut Ctx) -> c_int {
|
2019-02-05 23:48:05 -06:00
|
|
|
debug!("emscripten::_getgrent");
|
2019-02-05 17:25:51 -06:00
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-02 15:28:50 -08:00
|
|
|
pub fn _setgrent(_ctx: &mut Ctx) {
|
2019-01-24 23:58:54 -06:00
|
|
|
debug!("emscripten::_setgrent");
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn _setgroups(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
2019-01-24 23:58:54 -06:00
|
|
|
debug!("emscripten::_setgroups");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn _setitimer(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 {
|
2019-01-24 23:58:54 -06:00
|
|
|
debug!("emscripten::_setitimer");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn _usleep(_ctx: &mut Ctx, _one: i32) -> i32 {
|
2019-01-24 23:58:54 -06:00
|
|
|
debug!("emscripten::_usleep");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-03-20 16:46:42 -07:00
|
|
|
pub fn _nanosleep(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
|
|
|
debug!("emscripten::_nanosleep");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-05-28 09:39:49 +02:00
|
|
|
pub fn _utime(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
|
|
|
debug!("emscripten::_utime");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn _utimes(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
2019-01-24 23:58:54 -06:00
|
|
|
debug!("emscripten::_utimes");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-05-28 09:39:49 +02:00
|
|
|
pub fn _wait(_ctx: &mut Ctx, _one: i32) -> i32 {
|
|
|
|
debug!("emscripten::_wait");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn _wait3(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 {
|
|
|
|
debug!("emscripten::_wait3");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn _wait4(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32, _d: i32) -> i32 {
|
|
|
|
debug!("emscripten::_wait4");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn _waitid(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32, _d: i32) -> i32 {
|
|
|
|
debug!("emscripten::_waitid");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn _waitpid(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 {
|
2019-01-24 23:58:54 -06:00
|
|
|
debug!("emscripten::_waitpid");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn abort_stack_overflow(ctx: &mut Ctx, _what: c_int) {
|
2018-11-24 15:55:21 +01:00
|
|
|
debug!("emscripten::abort_stack_overflow");
|
|
|
|
// TODO: Message incomplete. Need to finish em runtime data first
|
2019-01-31 17:44:57 -08:00
|
|
|
abort_with_message(
|
|
|
|
ctx,
|
2019-02-09 13:58:05 -08:00
|
|
|
"Stack overflow! Attempted to allocate some bytes on the stack",
|
2019-01-31 17:44:57 -08:00
|
|
|
);
|
2018-11-20 20:11:58 +01:00
|
|
|
}
|
2018-12-13 19:28:30 +01:00
|
|
|
|
2019-02-02 15:28:50 -08:00
|
|
|
pub fn _llvm_trap(ctx: &mut Ctx) {
|
2018-12-13 19:28:30 +01:00
|
|
|
debug!("emscripten::_llvm_trap");
|
2019-02-09 13:58:05 -08:00
|
|
|
abort_with_message(ctx, "abort!");
|
2018-12-13 19:28:30 +01:00
|
|
|
}
|
|
|
|
|
2019-03-29 13:42:13 -07: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 13:58:05 -08:00
|
|
|
pub fn _system(_ctx: &mut Ctx, _one: i32) -> 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");
|
2019-04-29 23:45:38 -05:00
|
|
|
EAGAIN
|
2018-12-13 19:28:30 +01:00
|
|
|
}
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn _popen(_ctx: &mut Ctx, _one: i32, _two: i32) -> 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
|
|
|
}
|