wasmer/lib/emscripten/src/process.rs

203 lines
4.6 KiB
Rust
Raw Normal View History

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;
#[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
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);
_abort(ctx);
2018-11-20 19:11:58 +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 {
debug!("emscripten::_fork");
// unsafe {
// fork()
// }
-1
}
pub fn _endgrent(_ctx: &mut Ctx) {
2019-01-25 05:58:54 +00:00
debug!("emscripten::_endgrent");
}
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
}
#[allow(unreachable_code)]
pub fn _exit(_ctx: &mut Ctx, status: c_int) {
// -> !
debug!("emscripten::_exit {}", status);
2018-12-15 06:46:11 +00:00
unsafe { exit(status) }
}
pub fn em_abort(ctx: &mut Ctx, message: u32) {
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");
abort_with_message(ctx, message);
2018-11-20 19:11:58 +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
}
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(_ctx: &mut Ctx, _one: i32) {
2019-01-25 05:58:54 +00:00
debug!("emscripten::_llvm_stackrestore");
}
pub fn _raise(_ctx: &mut Ctx, _one: i32) -> i32 {
2019-01-25 05:58:54 +00:00
debug!("emscripten::_raise");
-1
}
pub fn _sem_init(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 {
2019-05-04 00:34:57 +00:00
debug!("emscripten::_sem_init: {}, {}, {}", _one, _two, _three);
0
}
pub fn _sem_destroy(_ctx: &mut Ctx, _one: i32) -> i32 {
debug!("emscripten::_sem_destroy");
0
2019-01-25 05:58:54 +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
}
pub fn _sem_wait(_ctx: &mut Ctx, _one: i32) -> i32 {
2019-01-25 05:58:54 +00:00
debug!("emscripten::_sem_post");
-1
}
#[allow(clippy::cast_ptr_alignment)]
fix(emscripten) Various warning fixes and cleanups (#266) * fix(emscripten) Remove unused imports. This patch removes unused imports reported by `rustc` as warnings. * fix(emscripten) Allow unreachable patterns in `_clock_gettime`. The compiler thinks `CLOCK_MONOTONIC_COARSE` is unreachable, which is not always the case. Add an attribute to allow unreachable patterns to remove the warning. * fix(emscripten) Rename unused variables. This patch renames various unused variables by appending an underscore to them. * fix(emscripten) Declare `table` as immutable. The `table` variable in `EmscriptenGlobals::new` was declared as mutable, but it's never mutated. * fix(emscripten) Remove an unnecessary `unsafe` block. * fix(emscripten) Remove duplicate definition of `SO_NOSIGPIPE`. The `SO_NOSIGPIPE` constant is defined in `syscalls/mod.rs` and `syscalls/unix.rs`. It's never used in the first case. We can safely remove it in this file, and keep it in `unix.rs`. * fix(emscripten) `read_string_from_wasm` is used only on Windows. Mark `read_string_from_wasm` as possible deadcode, since it's used only on Windows. * fix(emscripten) Remove `DYNAMICTOP_PTR_DIFF`, `stacktop`, `stack_max`, `dynamic_base` and `dynamic_ptr`. Four functions and one constant are used together but never used inside or outside this file. They are deadcode. * fix(emscripten) Remove `infinity` and `nan` fields of `EmscriptenGlobalsData`. Those fields are never used. * fix(emscripten) Allow non snake case in `emscripten_target.rs`. Many functions in this file don't follow the snake case style for Rust function names. The reason is that we want the names to match the emscripten symbol names; even if a mapping is done in `lib.rs`, it's easier to get the same names. * fix(emscripten) Rename `STATIC_TOP` to `static_top`. This variable is not a constant.
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");
-1
}
pub fn _setgrent(_ctx: &mut Ctx) {
2019-01-25 05:58:54 +00:00
debug!("emscripten::_setgrent");
}
pub fn _setgroups(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
2019-01-25 05:58:54 +00:00
debug!("emscripten::_setgroups");
-1
}
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
}
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
}
pub fn _utime(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::_utime");
-1
}
pub fn _utimes(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
2019-01-25 05:58:54 +00:00
debug!("emscripten::_utimes");
-1
}
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
}
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
}
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
abort_with_message(
ctx,
"Stack overflow! Attempted to allocate some bytes on the stack",
);
2018-11-20 19:11:58 +00:00
}
pub fn _llvm_trap(ctx: &mut Ctx) {
debug!("emscripten::_llvm_trap");
abort_with_message(ctx, "abort!");
}
pub fn _llvm_eh_typeid_for(_ctx: &mut Ctx, _type_info_addr: u32) -> i32 {
debug!("emscripten::_llvm_eh_typeid_for");
-1
}
pub fn _system(_ctx: &mut Ctx, _one: i32) -> c_int {
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
}
pub fn _popen(_ctx: &mut Ctx, _one: i32, _two: i32) -> c_int {
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();
}
}