mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-29 16:41:33 +00:00
wip enchanced vfs
This commit is contained in:
27
lib/emscripten/src/env/mod.rs
vendored
27
lib/emscripten/src/env/mod.rs
vendored
@ -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
|
||||
}
|
||||
}
|
||||
|
32
lib/emscripten/src/env/unix/mod.rs
vendored
32
lib/emscripten/src/env/unix/mod.rs
vendored
@ -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
|
||||
}
|
||||
|
1
lib/emscripten/src/env/windows/mod.rs
vendored
1
lib/emscripten/src/env/windows/mod.rs
vendored
@ -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);
|
||||
|
Reference in New Issue
Block a user