2019-05-29 14:20:52 -07:00
|
|
|
use crate::utils::{copy_cstr_into_wasm, get_cstr_path};
|
2019-02-07 16:56:44 -08:00
|
|
|
use crate::varargs::VarArgs;
|
|
|
|
use libc::mkdir;
|
2019-02-22 10:42:38 -08:00
|
|
|
use libc::open;
|
|
|
|
use rand::Rng;
|
|
|
|
use std::env;
|
|
|
|
use std::ffi::CString;
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Write;
|
2019-02-07 16:56:44 -08:00
|
|
|
use std::os::raw::c_int;
|
|
|
|
use wasmer_runtime_core::vm::Ctx;
|
|
|
|
|
2019-03-15 14:10:17 -07:00
|
|
|
#[allow(non_camel_case_types)]
|
2019-02-07 16:56:44 -08:00
|
|
|
type pid_t = c_int;
|
|
|
|
|
2019-02-22 10:42:38 -08:00
|
|
|
/// open
|
|
|
|
pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
|
|
|
|
debug!("emscripten::___syscall5 (open) {}", which);
|
2019-03-15 14:10:17 -07:00
|
|
|
#[cfg(not(feature = "debug"))]
|
|
|
|
let _ = which;
|
2019-05-18 12:38:22 -07:00
|
|
|
let pathname_addr = varargs.get_str(ctx);
|
2019-05-29 14:20:52 -07:00
|
|
|
let real_path_owned = get_cstr_path(ctx, pathname_addr);
|
|
|
|
let real_path = if let Some(ref rp) = real_path_owned {
|
|
|
|
rp.as_c_str().as_ptr()
|
|
|
|
} else {
|
|
|
|
pathname_addr
|
|
|
|
};
|
2019-02-22 10:42:38 -08:00
|
|
|
let flags: i32 = varargs.get(ctx);
|
|
|
|
let mode: u32 = varargs.get(ctx);
|
2019-05-29 14:20:52 -07:00
|
|
|
let path_str = unsafe { std::ffi::CStr::from_ptr(real_path).to_str().unwrap() };
|
2019-02-22 10:42:38 -08:00
|
|
|
match path_str {
|
|
|
|
"/dev/urandom" => {
|
|
|
|
// create a fake urandom file for windows, super hacky
|
|
|
|
// put it in the temp directory so we can just forget about it
|
|
|
|
let mut tmp_dir = env::temp_dir();
|
|
|
|
tmp_dir.push("urandom");
|
|
|
|
let tmp_dir_str = tmp_dir.to_str().unwrap();
|
|
|
|
let tmp_dir_c_str = CString::new(tmp_dir_str).unwrap();
|
|
|
|
let ptr = tmp_dir_c_str.as_ptr() as *const i8;
|
|
|
|
let mut urandom_file = File::create(tmp_dir).unwrap();
|
|
|
|
// create some random bytes and put them into the file
|
|
|
|
let random_bytes = rand::thread_rng().gen::<[u8; 32]>();
|
2019-03-15 14:10:17 -07:00
|
|
|
let _ = urandom_file.write_all(&random_bytes).unwrap();
|
2019-02-22 10:42:38 -08:00
|
|
|
// put the file path string into wasm memory
|
|
|
|
let urandom_file_offset = unsafe { copy_cstr_into_wasm(ctx, ptr) };
|
|
|
|
let raw_pointer_to_urandom_file =
|
|
|
|
emscripten_memory_pointer!(ctx.memory(0), urandom_file_offset) as *const i8;
|
|
|
|
let fd = unsafe { open(raw_pointer_to_urandom_file, flags, mode) };
|
|
|
|
debug!(
|
2019-03-11 10:25:45 -07:00
|
|
|
"=> pathname: {}, flags: {}, mode: {} = fd: {}",
|
2019-05-18 12:38:22 -07:00
|
|
|
path_str, flags, mode, fd
|
2019-02-22 10:42:38 -08:00
|
|
|
);
|
|
|
|
fd
|
|
|
|
}
|
|
|
|
_ => {
|
2019-05-29 14:20:52 -07:00
|
|
|
let fd = unsafe { open(real_path, flags, mode) };
|
2019-02-22 10:42:38 -08:00
|
|
|
debug!(
|
|
|
|
"=> pathname: {}, flags: {}, mode: {} = fd: {}\npath: {}",
|
2019-05-18 12:38:22 -07:00
|
|
|
path_str, flags, mode, fd, path_str
|
2019-02-22 10:42:38 -08:00
|
|
|
);
|
|
|
|
fd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 10:45:02 -07:00
|
|
|
/// link
|
2019-03-26 19:00:09 -07:00
|
|
|
pub fn ___syscall9(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> c_int {
|
2019-03-25 10:45:02 -07:00
|
|
|
debug!("emscripten::___syscall9 (link) {}", _which);
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2019-03-25 16:13:41 -07:00
|
|
|
/// ftruncate64
|
|
|
|
pub fn ___syscall194(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
|
|
|
debug!("emscripten::___syscall194 - stub");
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2019-02-07 16:56:44 -08:00
|
|
|
// chown
|
2019-03-15 14:10:17 -07:00
|
|
|
pub fn ___syscall212(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
|
2019-02-07 16:56:44 -08:00
|
|
|
debug!("emscripten::___syscall212 (chown) {}", which);
|
2019-03-15 14:10:17 -07:00
|
|
|
#[cfg(not(feature = "debug"))]
|
|
|
|
let _ = which;
|
2019-02-07 16:56:44 -08:00
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-03-25 10:45:02 -07:00
|
|
|
/// access
|
2019-03-26 19:00:09 -07:00
|
|
|
pub fn ___syscall33(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> c_int {
|
2019-03-25 10:45:02 -07:00
|
|
|
debug!("emscripten::___syscall33 (access) {}", _which);
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// nice
|
2019-03-26 19:00:09 -07:00
|
|
|
pub fn ___syscall34(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> c_int {
|
2019-03-25 10:45:02 -07:00
|
|
|
debug!("emscripten::___syscall34 (nice) {}", _which);
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2019-02-07 16:56:44 -08:00
|
|
|
// mkdir
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn ___syscall39(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
|
2019-02-07 16:56:44 -08:00
|
|
|
debug!("emscripten::___syscall39 (mkdir) {}", which);
|
2019-03-15 14:10:17 -07:00
|
|
|
#[cfg(not(feature = "debug"))]
|
|
|
|
let _ = which;
|
2019-05-18 12:38:22 -07:00
|
|
|
let pathname_addr = varargs.get_str(ctx);
|
2019-05-29 14:20:52 -07:00
|
|
|
let real_path_owned = get_cstr_path(ctx, pathname_addr);
|
|
|
|
let real_path = if let Some(ref rp) = real_path_owned {
|
|
|
|
rp.as_c_str().as_ptr()
|
|
|
|
} else {
|
|
|
|
pathname_addr
|
|
|
|
};
|
|
|
|
unsafe { mkdir(real_path) }
|
2019-02-07 16:56:44 -08:00
|
|
|
}
|
|
|
|
|
2019-03-25 10:45:02 -07:00
|
|
|
/// dup
|
|
|
|
pub fn ___syscall41(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
|
|
|
debug!("emscripten::___syscall41 (dup) {}", _which);
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getrusage
|
|
|
|
pub fn ___syscall77(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
|
|
|
debug!("emscripten::___syscall77 (getrusage) {}", _which);
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// symlink
|
|
|
|
pub fn ___syscall83(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
|
|
|
debug!("emscripten::___syscall83 (symlink) {}", _which);
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2019-07-01 16:50:55 -07:00
|
|
|
/// readlink
|
|
|
|
pub fn ___syscall85(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
|
|
|
debug!("emscripten::___syscall85 (readlink) {}", _which);
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-03-25 10:45:02 -07:00
|
|
|
/// lchown
|
|
|
|
pub fn ___syscall198(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
|
|
|
debug!("emscripten::___syscall198 (lchown) {}", _which);
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2019-07-07 19:35:09 -07:00
|
|
|
/// getgid32
|
2019-03-25 10:45:02 -07:00
|
|
|
pub fn ___syscall200(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
2019-07-07 19:35:09 -07:00
|
|
|
debug!("emscripten::___syscall200 (getgid32)");
|
2019-07-07 19:51:11 -07:00
|
|
|
unimplemented!();
|
2019-03-25 10:45:02 -07:00
|
|
|
}
|
|
|
|
|
2019-07-07 19:35:09 -07:00
|
|
|
// geteuid32
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn ___syscall201(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
2019-07-07 19:35:09 -07:00
|
|
|
debug!("emscripten::___syscall201 (geteuid32)");
|
2019-07-07 19:51:11 -07:00
|
|
|
unimplemented!();
|
2019-02-07 16:56:44 -08:00
|
|
|
}
|
|
|
|
|
2019-07-07 19:35:09 -07:00
|
|
|
// getegid32
|
2019-02-09 13:58:05 -08:00
|
|
|
pub fn ___syscall202(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
2019-02-07 16:56:44 -08:00
|
|
|
// gid_t
|
2019-07-07 19:35:09 -07:00
|
|
|
debug!("emscripten::___syscall202 (getegid32)");
|
2019-07-07 19:51:11 -07:00
|
|
|
unimplemented!();
|
2019-02-07 16:56:44 -08:00
|
|
|
}
|
|
|
|
|
2019-03-25 10:45:02 -07:00
|
|
|
/// getgroups
|
|
|
|
pub fn ___syscall205(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
|
|
|
debug!("emscripten::___syscall205 (getgroups) {}", _which);
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// madvise
|
|
|
|
pub fn ___syscall219(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
|
|
|
debug!("emscripten::___syscall212 (chown) {}", _which);
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2019-02-07 16:56:44 -08:00
|
|
|
/// dup3
|
2019-03-15 14:10:17 -07:00
|
|
|
pub fn ___syscall330(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> pid_t {
|
2019-02-07 16:56:44 -08:00
|
|
|
debug!("emscripten::___syscall330 (dup3)");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ioctl
|
2019-03-15 14:10:17 -07:00
|
|
|
pub fn ___syscall54(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
|
2019-02-07 16:56:44 -08:00
|
|
|
debug!("emscripten::___syscall54 (ioctl) {}", which);
|
2019-03-15 14:10:17 -07:00
|
|
|
#[cfg(not(feature = "debug"))]
|
|
|
|
let _ = which;
|
2019-02-07 16:56:44 -08:00
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-03-25 11:12:34 -07:00
|
|
|
/// fchmod
|
|
|
|
pub fn ___syscall94(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
|
|
|
debug!("emscripten::___syscall118 (fchmod) {}", _which);
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2019-02-07 16:56:44 -08:00
|
|
|
// socketcall
|
|
|
|
#[allow(clippy::cast_ptr_alignment)]
|
2019-03-15 14:10:17 -07:00
|
|
|
pub fn ___syscall102(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
|
2019-02-07 16:56:44 -08:00
|
|
|
debug!("emscripten::___syscall102 (socketcall) {}", which);
|
2019-03-15 14:10:17 -07:00
|
|
|
#[cfg(not(feature = "debug"))]
|
|
|
|
let _ = which;
|
2019-02-07 16:56:44 -08:00
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-03-25 11:12:34 -07:00
|
|
|
/// fsync
|
|
|
|
pub fn ___syscall118(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
|
|
|
debug!("emscripten::___syscall118 (fsync) {}", _which);
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2019-02-07 16:56:44 -08:00
|
|
|
// pread
|
2019-03-15 14:10:17 -07:00
|
|
|
pub fn ___syscall180(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
|
2019-02-07 16:56:44 -08:00
|
|
|
debug!("emscripten::___syscall180 (pread) {}", which);
|
2019-03-15 14:10:17 -07:00
|
|
|
#[cfg(not(feature = "debug"))]
|
|
|
|
let _ = which;
|
2019-02-07 16:56:44 -08:00
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
// pwrite
|
2019-03-15 14:10:17 -07:00
|
|
|
pub fn ___syscall181(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
|
2019-02-07 16:56:44 -08:00
|
|
|
debug!("emscripten::___syscall181 (pwrite) {}", which);
|
2019-03-15 14:10:17 -07:00
|
|
|
#[cfg(not(feature = "debug"))]
|
|
|
|
let _ = which;
|
2019-02-07 16:56:44 -08:00
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
/// wait4
|
|
|
|
#[allow(clippy::cast_ptr_alignment)]
|
2019-03-15 14:10:17 -07:00
|
|
|
pub fn ___syscall114(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> pid_t {
|
2019-02-07 16:56:44 -08:00
|
|
|
debug!("emscripten::___syscall114 (wait4)");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
// select
|
|
|
|
#[allow(clippy::cast_ptr_alignment)]
|
2019-03-15 14:10:17 -07:00
|
|
|
pub fn ___syscall142(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
|
2019-02-07 16:56:44 -08:00
|
|
|
debug!("emscripten::___syscall142 (newselect) {}", which);
|
2019-03-15 14:10:17 -07:00
|
|
|
#[cfg(not(feature = "debug"))]
|
|
|
|
let _ = which;
|
2019-02-07 16:56:44 -08:00
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-03-25 13:09:23 -07:00
|
|
|
/// fdatasync
|
|
|
|
pub fn ___syscall148(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
|
|
|
debug!("emscripten::___syscall148 (fdatasync) {}", _which);
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
2019-02-07 16:56:44 -08:00
|
|
|
// setpgid
|
2019-03-15 14:10:17 -07:00
|
|
|
pub fn ___syscall57(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
|
2019-02-07 16:56:44 -08:00
|
|
|
debug!("emscripten::___syscall57 (setpgid) {}", which);
|
2019-03-15 14:10:17 -07:00
|
|
|
#[cfg(not(feature = "debug"))]
|
|
|
|
let _ = which;
|
2019-02-07 16:56:44 -08:00
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
|
|
|
/// uname
|
|
|
|
// NOTE: Wondering if we should return custom utsname, like Emscripten.
|
2019-03-15 14:10:17 -07:00
|
|
|
pub fn ___syscall122(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
|
2019-02-07 16:56:44 -08:00
|
|
|
debug!("emscripten::___syscall122 (uname) {}", which);
|
2019-03-15 14:10:17 -07:00
|
|
|
#[cfg(not(feature = "debug"))]
|
|
|
|
let _ = which;
|
2019-02-07 16:56:44 -08:00
|
|
|
-1
|
|
|
|
}
|
2019-03-25 11:12:34 -07:00
|
|
|
|
2019-07-01 16:36:30 -07:00
|
|
|
/// poll
|
|
|
|
pub fn ___syscall168(_ctx: &mut Ctx, _which: i32, _varargs: VarArgs) -> i32 {
|
|
|
|
debug!("emscripten::___syscall168(poll) - stub");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-03-25 16:13:41 -07:00
|
|
|
/// lstat64
|
|
|
|
pub fn ___syscall196(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
|
|
|
debug!("emscripten::___syscall196 (lstat64) - stub");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-06-13 20:46:05 +02:00
|
|
|
// getuid
|
|
|
|
pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
|
|
|
debug!("emscripten::___syscall199 (getuid)");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-05-24 18:00:07 -07:00
|
|
|
// getdents
|
|
|
|
pub fn ___syscall220(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
|
|
|
debug!("emscripten::___syscall220");
|
|
|
|
-1
|
|
|
|
}
|
|
|
|
|
2019-03-25 11:12:34 -07:00
|
|
|
/// fchown
|
|
|
|
pub fn ___syscall207(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
|
|
|
debug!("emscripten::___syscall207 (fchown) {}", _which);
|
|
|
|
unimplemented!()
|
|
|
|
}
|
2019-03-25 13:09:23 -07:00
|
|
|
|
|
|
|
/// fallocate
|
|
|
|
pub fn ___syscall324(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
|
|
|
debug!("emscripten::___syscall324 (fallocate) {}", _which);
|
|
|
|
unimplemented!()
|
|
|
|
}
|