wasmer/lib/emscripten/src/process.rs

158 lines
3.6 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
pub fn abort_with_message(message: &str, ctx: &mut Ctx) {
2018-11-20 19:24:23 -08:00
debug!("emscripten::abort_with_message");
2018-11-20 20:11:58 +01:00
println!("{}", message);
_abort(ctx);
2018-11-20 20:11:58 +01: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
}
pub fn _fork(_ctx: &mut Ctx) -> pid_t {
debug!("emscripten::_fork");
// unsafe {
// fork()
// }
-1
}
pub fn _endgrent(_ctx: &mut Ctx) {
2019-01-24 23:58:54 -06:00
debug!("emscripten::_endgrent");
}
pub fn _execve(_one: i32, _two: i32, _three: i32, _ctx: &mut Ctx) -> i32 {
2019-01-24 23:58:54 -06:00
debug!("emscripten::_execve");
-1
}
#[allow(unreachable_code)]
pub fn _exit(status: c_int, _ctx: &mut Ctx) {
// -> !
debug!("emscripten::_exit {}", status);
2018-12-15 00:46:11 -06:00
unsafe { exit(status) }
}
pub 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, ctx);
2018-11-20 20:11:58 +01:00
}
}
pub fn _kill(_one: i32, _two: i32, _ctx: &mut Ctx) -> i32 {
2019-01-24 23:58:54 -06:00
debug!("emscripten::_kill");
-1
}
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
}
pub fn _llvm_stackrestore(_one: i32, _ctx: &mut Ctx) {
2019-01-24 23:58:54 -06:00
debug!("emscripten::_llvm_stackrestore");
}
pub fn _raise(_one: i32, _ctx: &mut Ctx) -> i32 {
2019-01-24 23:58:54 -06:00
debug!("emscripten::_raise");
-1
}
pub fn _sem_init(_one: i32, _two: i32, _three: i32, _ctx: &mut Ctx) -> i32 {
2019-01-24 23:58:54 -06:00
debug!("emscripten::_sem_init");
-1
}
pub fn _sem_post(_one: i32, _ctx: &mut Ctx) -> i32 {
2019-01-24 23:58:54 -06:00
debug!("emscripten::_sem_post");
-1
}
pub fn _sem_wait(_one: i32, _ctx: &mut Ctx) -> i32 {
2019-01-24 23:58:54 -06:00
debug!("emscripten::_sem_post");
-1
}
#[allow(clippy::cast_ptr_alignment)]
pub fn _getgrent(ctx: &mut Ctx) -> c_int {
2019-02-05 23:48:05 -06:00
debug!("emscripten::_getgrent");
-1
}
pub fn _setgrent(_ctx: &mut Ctx) {
2019-01-24 23:58:54 -06:00
debug!("emscripten::_setgrent");
}
pub fn _setgroups(_one: i32, _two: i32, _ctx: &mut Ctx) -> i32 {
2019-01-24 23:58:54 -06:00
debug!("emscripten::_setgroups");
-1
}
pub fn _setitimer(_one: i32, _two: i32, _three: i32, _ctx: &mut Ctx) -> i32 {
2019-01-24 23:58:54 -06:00
debug!("emscripten::_setitimer");
-1
}
pub fn _usleep(_one: i32, _ctx: &mut Ctx) -> i32 {
2019-01-24 23:58:54 -06:00
debug!("emscripten::_usleep");
-1
}
pub fn _utimes(_one: i32, _two: i32, _ctx: &mut Ctx) -> i32 {
2019-01-24 23:58:54 -06:00
debug!("emscripten::_utimes");
-1
}
pub fn _waitpid(_one: i32, _two: i32, _three: i32, _ctx: &mut Ctx) -> i32 {
2019-01-24 23:58:54 -06:00
debug!("emscripten::_waitpid");
-1
}
pub 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",
ctx,
);
2018-11-20 20:11:58 +01:00
}
pub fn _llvm_trap(ctx: &mut Ctx) {
debug!("emscripten::_llvm_trap");
abort_with_message("abort!", ctx);
}
pub fn _system(_one: i32, _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 fn _popen(_one: i32, _two: i32, _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();
}
}