2019-06-13 14:05:57 +02:00
|
|
|
use super::super::env::call_malloc;
|
2019-06-13 20:46:05 +02:00
|
|
|
use super::super::utils::copy_cstr_into_wasm;
|
|
|
|
use libc::{chroot as _chroot, getpwuid as _getpwuid, printf as _printf};
|
|
|
|
use std::mem;
|
2018-11-13 19:19:23 -08:00
|
|
|
|
2019-01-24 15:44:08 -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
|
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
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn printf(ctx: &mut Ctx, memory_offset: i32, extra: i32) -> i32 {
|
2018-12-17 23:54:00 -06:00
|
|
|
debug!("emscripten::printf {}, {}", memory_offset, extra);
|
2018-11-25 13:51:21 -05:00
|
|
|
unsafe {
|
2019-01-24 15:44:08 -08:00
|
|
|
let addr = emscripten_memory_pointer!(ctx.memory(0), memory_offset) as _;
|
2018-11-25 13:51:21 -05:00
|
|
|
_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 {
|
2019-03-25 10:45:02 -07:00
|
|
|
debug!("emscripten::chroot");
|
2019-03-20 16:46:42 -07:00
|
|
|
let name = emscripten_memory_pointer!(ctx.memory(0), name_ptr) as *const i8;
|
|
|
|
unsafe { _chroot(name) }
|
|
|
|
}
|
2019-03-25 11:58:44 -07:00
|
|
|
|
|
|
|
/// getpwuid
|
2019-06-13 14:05:57 +02:00
|
|
|
pub fn getpwuid(ctx: &mut Ctx, uid: i32) -> i32 {
|
|
|
|
debug!("emscripten::getpwuid {}", uid);
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
struct GuestPasswd {
|
|
|
|
pw_name: u32,
|
|
|
|
pw_passwd: u32,
|
|
|
|
pw_uid: u32,
|
|
|
|
pw_gid: u32,
|
|
|
|
pw_gecos: u32,
|
|
|
|
pw_dir: u32,
|
|
|
|
pw_shell: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let passwd = &*_getpwuid(uid as _);
|
|
|
|
let passwd_struct_offset = call_malloc(ctx, mem::size_of::<GuestPasswd>() as _);
|
|
|
|
|
|
|
|
let passwd_struct_ptr =
|
|
|
|
emscripten_memory_pointer!(ctx.memory(0), passwd_struct_offset) as *mut GuestPasswd;
|
|
|
|
(*passwd_struct_ptr).pw_name = copy_cstr_into_wasm(ctx, passwd.pw_name);
|
|
|
|
(*passwd_struct_ptr).pw_passwd = copy_cstr_into_wasm(ctx, passwd.pw_passwd);
|
|
|
|
(*passwd_struct_ptr).pw_gecos = copy_cstr_into_wasm(ctx, passwd.pw_gecos);
|
|
|
|
(*passwd_struct_ptr).pw_dir = copy_cstr_into_wasm(ctx, passwd.pw_dir);
|
|
|
|
(*passwd_struct_ptr).pw_shell = copy_cstr_into_wasm(ctx, passwd.pw_shell);
|
|
|
|
(*passwd_struct_ptr).pw_uid = passwd.pw_uid;
|
|
|
|
(*passwd_struct_ptr).pw_gid = passwd.pw_gid;
|
|
|
|
|
|
|
|
passwd_struct_offset as _
|
|
|
|
}
|
|
|
|
// unsafe { _getpwuid(uid as _) as _}
|
|
|
|
// 0
|
2019-03-25 11:58:44 -07:00
|
|
|
}
|