Files
wasmer/lib/emscripten/src/io/unix.rs

74 lines
1.8 KiB
Rust
Raw Normal View History

2019-03-20 16:46:42 -07:00
use libc::{chroot as _chroot, printf as _printf};
2018-11-13 19:19:23 -08:00
use wasmer_runtime_core::vm::Ctx;
2018-11-13 19:19:23 -08:00
2018-11-20 20:11:58 +01:00
/// putchar
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 22:00:33 +01:00
pub fn putchar(_ctx: &mut Ctx, chr: i32) {
2019-01-30 20:03:54 -06:00
unsafe { libc::putchar(chr) };
}
2018-11-20 20:11:58 +01:00
/// printf
pub fn printf(ctx: &mut Ctx, memory_offset: i32, extra: i32) -> i32 {
debug!("emscripten::printf {}, {}", memory_offset, extra);
unsafe {
let addr = emscripten_memory_pointer!(ctx.memory(0), memory_offset) as _;
_printf(addr, extra)
}
2018-11-13 19:19:23 -08:00
}
2019-03-20 16:46:42 -07:00
/// chroot
pub fn chroot(ctx: &mut Ctx, name_ptr: i32) -> i32 {
let name = emscripten_memory_pointer!(ctx.memory(0), name_ptr) as *const i8;
unsafe { _chroot(name) }
}
/// getprotobyname
pub fn getprotobyname(ctx: &mut Ctx, name_ptr: i32) -> i32 {
debug!("emscripten::getprotobyname");
// TODO: actually do this logic to return correctly
let _name = emscripten_memory_pointer!(ctx.memory(0), name_ptr) as *const i8;
//unsafe { _getprotobyname(name) as i32 }
0
}
/// getprotobynumber
pub fn getprotobynumber(_ctx: &mut Ctx, _one: i32) -> i32 {
debug!("emscripten::getprotobynumber");
0
}
/// getpwuid
pub fn getpwuid(_ctx: &mut Ctx, _uid: i32) -> i32 {
debug!("emscripten::getpwuid");
// TODO: actually do this logic to return correctly
0
}
/// longjmp
pub fn longjmp(_ctx: &mut Ctx, _one: i32, _two: i32) {
debug!("emscripten::longjump");
}
/// sigdelset
pub fn sigdelset(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::sigdelset");
0
}
/// sigfillset
pub fn sigfillset(_ctx: &mut Ctx, _one: i32) -> i32 {
debug!("emscripten::sigfillset");
0
}
/// tzset
pub fn tzset(_ctx: &mut Ctx) {
debug!("emscripten::tzset");
}
/// strptime
pub fn strptime(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 {
debug!("emscripten::strptime");
0
}