wip enchanced vfs

This commit is contained in:
Mackenzie Clark
2019-03-21 08:55:23 -07:00
parent edacb0a8a7
commit 9ed593d7b6
19 changed files with 1805 additions and 148 deletions

View File

@ -75,3 +75,30 @@ pub fn ___assert_fail(_ctx: &mut Ctx, _a: c_int, _b: c_int, _c: c_int, _d: c_int
// TODO: Implement like emscripten expects regarding memory/page size
// TODO raise an error
}
#[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
}
}

View File

@ -1,14 +1,11 @@
/// NOTE: These syscalls only support wasm_32 for now because they take u32 offset
use libc::{
c_int, getenv, getgrnam as libc_getgrnam, getpwnam as libc_getpwnam, putenv, setenv, sysconf,
unsetenv,
};
use libc::{c_int, getenv, getpwnam as libc_getpwnam, putenv, setenv, sysconf, unsetenv};
use std::ffi::CStr;
use std::mem;
use std::os::raw::c_char;
use crate::env::call_malloc;
use crate::utils::{copy_cstr_into_wasm, copy_terminated_array_of_cstrs};
use crate::utils::copy_cstr_into_wasm;
use wasmer_runtime_core::vm::Ctx;
// #[no_mangle]
@ -103,6 +100,7 @@ pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int {
}
}
#[cfg(not(feature = "vfs"))]
#[allow(clippy::cast_ptr_alignment)]
pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int {
debug!("emscripten::_getgrnam {}", name_ptr);
@ -121,7 +119,7 @@ pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int {
};
unsafe {
let group = &*libc_getgrnam(name.as_ptr());
let group = &*libc::getgrnam(name.as_ptr());
let group_struct_offset = call_malloc(ctx, mem::size_of::<GuestGroup>() as _);
let group_struct_ptr =
@ -140,3 +138,25 @@ pub fn _sysconf(_ctx: &mut Ctx, name: c_int) -> i32 {
// TODO: Implement like emscripten expects regarding memory/page size
unsafe { sysconf(name) as i32 } // TODO review i64
}
pub fn _initgroups(_ctx: &mut Ctx, user_offset: u32, gid: u32) -> c_int {
0
}
#[cfg(not(feature = "vfs"))]
unsafe fn copy_terminated_array_of_cstrs(_ctx: &mut Ctx, cstrs: *mut *mut c_char) -> u32 {
let _total_num = {
let mut ptr = cstrs;
let mut counter = 0;
while !(*ptr).is_null() {
counter += 1;
ptr = ptr.add(1);
}
counter
};
debug!(
"emscripten::copy_terminated_array_of_cstrs::total_num: {}",
_total_num
);
0
}

View File

@ -97,6 +97,7 @@ pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int {
}
}
#[cfg(not(feature = "vfs"))]
#[allow(clippy::cast_ptr_alignment)]
pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int {
debug!("emscripten::_getgrnam {}", name_ptr);