2019-02-06 18:57:11 -08:00
|
|
|
#[cfg(unix)]
|
|
|
|
mod unix;
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
mod windows;
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
pub use self::unix::*;
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
pub use self::windows::*;
|
2019-02-07 15:24:22 -08:00
|
|
|
|
|
|
|
use crate::{allocate_on_stack, EmscriptenData};
|
|
|
|
use std::os::raw::c_int;
|
|
|
|
use wasmer_runtime_core::vm::Ctx;
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn _getaddrinfo(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32, _four: i32) -> i32 {
|
2019-02-07 15:24:22 -08:00
|
|
|
debug!("emscripten::_getaddrinfo");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn call_malloc(ctx: &mut Ctx, size: u32) -> u32 {
|
2019-02-07 15:24:22 -08:00
|
|
|
get_emscripten_data(ctx).malloc.call(size).unwrap()
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn call_memalign(ctx: &mut Ctx, alignment: u32, size: u32) -> u32 {
|
2019-02-07 15:24:22 -08:00
|
|
|
if let Some(memalign) = &get_emscripten_data(ctx).memalign {
|
|
|
|
memalign.call(alignment, size).unwrap()
|
|
|
|
} else {
|
|
|
|
panic!("Memalign is set to None");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn call_memset(ctx: &mut Ctx, pointer: u32, value: u32, size: u32) -> u32 {
|
2019-02-07 15:24:22 -08:00
|
|
|
get_emscripten_data(ctx)
|
|
|
|
.memset
|
|
|
|
.call(pointer, value, size)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn get_emscripten_data(ctx: &mut Ctx) -> &mut EmscriptenData {
|
|
|
|
unsafe { &mut *(ctx.data as *mut EmscriptenData) }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn _getpagesize(_ctx: &mut Ctx) -> u32 {
|
|
|
|
debug!("emscripten::_getpagesize");
|
|
|
|
16384
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(clippy::cast_ptr_alignment)]
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn ___build_environment(ctx: &mut Ctx, environ: c_int) {
|
2019-02-07 15:24:22 -08:00
|
|
|
debug!("emscripten::___build_environment {}", environ);
|
|
|
|
const MAX_ENV_VALUES: u32 = 64;
|
|
|
|
const TOTAL_ENV_SIZE: u32 = 1024;
|
|
|
|
let environment = emscripten_memory_pointer!(ctx.memory(0), environ) as *mut c_int;
|
|
|
|
unsafe {
|
|
|
|
let (pool_offset, _pool_slice): (u32, &mut [u8]) =
|
2019-02-09 13:58:05 -08:00
|
|
|
allocate_on_stack(ctx, TOTAL_ENV_SIZE as u32);
|
2019-02-07 15:24:22 -08:00
|
|
|
let (env_offset, _env_slice): (u32, &mut [u8]) =
|
2019-02-09 13:58:05 -08:00
|
|
|
allocate_on_stack(ctx, (MAX_ENV_VALUES * 4) as u32);
|
2019-02-07 15:24:22 -08:00
|
|
|
let env_ptr = emscripten_memory_pointer!(ctx.memory(0), env_offset) as *mut c_int;
|
|
|
|
let mut _pool_ptr = emscripten_memory_pointer!(ctx.memory(0), pool_offset) as *mut c_int;
|
|
|
|
*env_ptr = pool_offset as i32;
|
|
|
|
*environment = env_offset as i32;
|
|
|
|
|
|
|
|
// *env_ptr = 0;
|
|
|
|
};
|
|
|
|
// unsafe {
|
|
|
|
// *env_ptr = 0;
|
|
|
|
// };
|
|
|
|
}
|
|
|
|
|
2019-03-12 22:00:33 +01:00
|
|
|
pub fn ___assert_fail(_ctx: &mut Ctx, _a: c_int, _b: c_int, _c: c_int, _d: c_int) {
|
|
|
|
debug!("emscripten::___assert_fail {} {} {} {}", _a, _b, _c, _d);
|
2019-02-07 15:24:22 -08:00
|
|
|
// TODO: Implement like emscripten expects regarding memory/page size
|
|
|
|
// TODO raise an error
|
|
|
|
}
|
2019-03-21 08:55:23 -07:00
|
|
|
|
|
|
|
#[cfg(feature = "vfs")]
|
|
|
|
#[allow(clippy::cast_ptr_alignment)]
|
|
|
|
pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int {
|
|
|
|
debug!("emscripten::_getgrnam {}", name_ptr);
|
|
|
|
#[cfg(not(feature = "debug"))]
|
|
|
|
let _ = name_ptr;
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
struct GuestGroup {
|
|
|
|
gr_name: u32,
|
|
|
|
gr_passwd: u32,
|
|
|
|
gr_gid: u32,
|
|
|
|
gr_mem: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let group_struct_offset = call_malloc(ctx, std::mem::size_of::<GuestGroup>() as _);
|
|
|
|
let group_struct_ptr =
|
|
|
|
emscripten_memory_pointer!(ctx.memory(0), group_struct_offset) as *mut GuestGroup;
|
|
|
|
(*group_struct_ptr).gr_name = 0;
|
|
|
|
(*group_struct_ptr).gr_passwd = 0;
|
|
|
|
(*group_struct_ptr).gr_gid = 0;
|
|
|
|
(*group_struct_ptr).gr_mem = 0;
|
|
|
|
group_struct_offset as c_int
|
|
|
|
}
|
|
|
|
}
|