mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 06:15:33 +00:00
Merge branch 'master' into feature/vfs
This commit is contained in:
commit
60685d1d0a
@ -1,6 +1,8 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use crate::env::get_emscripten_data;
|
||||
#[cfg(target_os = "linux")]
|
||||
use libc::getdtablesize;
|
||||
use wasmer_runtime_core::vm::Ctx;
|
||||
|
||||
pub fn setTempRet0(_ctx: &mut Ctx, _a: i32) {
|
||||
@ -10,9 +12,24 @@ pub fn getTempRet0(_ctx: &mut Ctx) -> i32 {
|
||||
debug!("emscripten::getTempRet0");
|
||||
0
|
||||
}
|
||||
pub fn nullFunc_d(_ctx: &mut Ctx, _a: i32) {
|
||||
debug!("emscripten::nullFunc_d");
|
||||
}
|
||||
pub fn nullFunc_ji(_ctx: &mut Ctx, _a: i32) {
|
||||
debug!("emscripten::nullFunc_ji");
|
||||
}
|
||||
pub fn nullFunc_viidii(_ctx: &mut Ctx, _a: i32) {
|
||||
debug!("emscripten::nullFunc_viidii");
|
||||
}
|
||||
pub fn nullFunc_iiiiiii(_ctx: &mut Ctx, _a: i32) {
|
||||
debug!("emscripten::nullFunc_iiiiiii");
|
||||
}
|
||||
pub fn nullFunc_iiiiiiii(_ctx: &mut Ctx, _a: i32) {
|
||||
debug!("emscripten::nullFunc_iiiiiiii");
|
||||
}
|
||||
pub fn nullFunc_iiiiiiiiii(_ctx: &mut Ctx, _a: i32) {
|
||||
debug!("emscripten::nullFunc_iiiiiiiiii");
|
||||
}
|
||||
pub fn invoke_i(ctx: &mut Ctx, index: i32) -> i32 {
|
||||
debug!("emscripten::invoke_i");
|
||||
if let Some(dyn_call_i) = &get_emscripten_data(ctx).dyn_call_i {
|
||||
@ -119,6 +136,14 @@ pub fn _pthread_cond_destroy(_ctx: &mut Ctx, _a: i32) -> i32 {
|
||||
debug!("emscripten::_pthread_cond_destroy");
|
||||
0
|
||||
}
|
||||
pub fn _pthread_create(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32, _d: i32) -> i32 {
|
||||
debug!("emscripten::_pthread_create");
|
||||
0
|
||||
}
|
||||
pub fn _pthread_join(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
|
||||
debug!("emscripten::_pthread_join");
|
||||
0
|
||||
}
|
||||
pub fn _pthread_cond_init(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
|
||||
debug!("emscripten::_pthread_cond_init");
|
||||
0
|
||||
@ -171,6 +196,10 @@ pub fn _pthread_rwlock_unlock(_ctx: &mut Ctx, _a: i32) -> i32 {
|
||||
debug!("emscripten::_pthread_rwlock_unlock");
|
||||
0
|
||||
}
|
||||
pub fn _pthread_setcancelstate(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
|
||||
debug!("emscripten::_pthread_setcancelstate");
|
||||
0
|
||||
}
|
||||
pub fn ___gxx_personality_v0(
|
||||
_ctx: &mut Ctx,
|
||||
_a: i32,
|
||||
@ -183,7 +212,41 @@ pub fn ___gxx_personality_v0(
|
||||
debug!("emscripten::___gxx_personality_v0");
|
||||
0
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn _getdtablesize(_ctx: &mut Ctx) -> i32 {
|
||||
debug!("emscripten::getdtablesize");
|
||||
unsafe { getdtablesize() }
|
||||
}
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub fn _getdtablesize(_ctx: &mut Ctx) -> i32 {
|
||||
debug!("emscripten::getdtablesize");
|
||||
-1
|
||||
}
|
||||
pub fn _gethostbyaddr(_ctx: &mut Ctx, _addr: i32, _addrlen: i32, _atype: i32) -> i32 {
|
||||
debug!("emscripten::gethostbyaddr");
|
||||
0
|
||||
}
|
||||
pub fn _gethostbyname_r(
|
||||
_ctx: &mut Ctx,
|
||||
_name: i32,
|
||||
_ret: i32,
|
||||
_buf: i32,
|
||||
_buflen: i32,
|
||||
_out: i32,
|
||||
_err: i32,
|
||||
) -> i32 {
|
||||
debug!("emscripten::gethostbyname_r");
|
||||
0
|
||||
}
|
||||
// NOTE: php.js has proper impl; libc has proper impl for linux
|
||||
pub fn _getloadavg(_ctx: &mut Ctx, _loadavg: i32, _nelem: i32) -> i32 {
|
||||
debug!("emscripten::getloadavg");
|
||||
0
|
||||
}
|
||||
// round 2
|
||||
pub fn nullFunc_di(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_di");
|
||||
}
|
||||
pub fn nullFunc_dii(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_dii");
|
||||
}
|
||||
@ -193,21 +256,72 @@ pub fn nullFunc_diiii(_ctx: &mut Ctx, _index: i32) {
|
||||
pub fn nullFunc_iiji(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_iiji");
|
||||
}
|
||||
pub fn nullFunc_iiid(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_iiid");
|
||||
}
|
||||
pub fn nullFunc_iij(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_iij");
|
||||
}
|
||||
pub fn nullFunc_iiiiiiiii(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_iiiiiiiii");
|
||||
}
|
||||
pub fn nullFunc_iiiiiiiiiii(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_iiiiiiiiiii");
|
||||
}
|
||||
pub fn nullFunc_iiiiijii(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_iiiiijii");
|
||||
}
|
||||
pub fn nullFunc_iiiijii(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_iiiijii");
|
||||
}
|
||||
pub fn nullFunc_iiiij(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_iiiij");
|
||||
}
|
||||
pub fn nullFunc_iiij(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_iiij");
|
||||
}
|
||||
pub fn nullFunc_iijii(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_iijii");
|
||||
}
|
||||
pub fn nullFunc_iijj(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_iijj");
|
||||
}
|
||||
pub fn nullFunc_iiiiji(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_iiiiji");
|
||||
}
|
||||
pub fn nullFunc_ij(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_ij");
|
||||
}
|
||||
pub fn nullFunc_j(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_j");
|
||||
}
|
||||
pub fn nullFunc_jij(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_jij");
|
||||
}
|
||||
pub fn nullFunc_jj(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_jj");
|
||||
}
|
||||
pub fn nullFunc_jjj(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_jjj");
|
||||
}
|
||||
pub fn nullFunc_jii(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_jii");
|
||||
}
|
||||
pub fn nullFunc_jiij(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_jiij");
|
||||
}
|
||||
pub fn nullFunc_vd(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_vd");
|
||||
}
|
||||
pub fn nullFunc_vid(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_vid");
|
||||
}
|
||||
pub fn nullFunc_viiiiiii(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_viiiiiii");
|
||||
}
|
||||
pub fn nullFunc_viiiij(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_viiiij");
|
||||
}
|
||||
pub fn nullFunc_viiiiiiii(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_viiiiiiii");
|
||||
}
|
||||
@ -226,9 +340,15 @@ pub fn nullFunc_viiijiiiiii(_ctx: &mut Ctx, _index: i32) {
|
||||
pub fn nullFunc_viij(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_viij");
|
||||
}
|
||||
pub fn nullFunc_viijii(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_viijii");
|
||||
}
|
||||
pub fn nullFunc_viiji(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_viiji");
|
||||
}
|
||||
pub fn nullFunc_vijii(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_vijii");
|
||||
}
|
||||
pub fn nullFunc_viijiii(_ctx: &mut Ctx, _index: i32) {
|
||||
debug!("emscripten::nullFunc_viijiii");
|
||||
}
|
||||
@ -287,6 +407,67 @@ pub fn invoke_iiiiii(
|
||||
panic!("dyn_call_iiiiii is set to None");
|
||||
}
|
||||
}
|
||||
pub fn invoke_iiiiiii(
|
||||
ctx: &mut Ctx,
|
||||
index: i32,
|
||||
a1: i32,
|
||||
a2: i32,
|
||||
a3: i32,
|
||||
a4: i32,
|
||||
a5: i32,
|
||||
a6: i32,
|
||||
) -> i32 {
|
||||
debug!("emscripten::invoke_iiiiiii");
|
||||
if let Some(dyn_call_iiiiiii) = &get_emscripten_data(ctx).dyn_call_iiiiiii {
|
||||
dyn_call_iiiiiii
|
||||
.call(index, a1, a2, a3, a4, a5, a6)
|
||||
.unwrap()
|
||||
} else {
|
||||
panic!("dyn_call_iiiiiii is set to None");
|
||||
}
|
||||
}
|
||||
pub fn invoke_iiiiiiii(
|
||||
ctx: &mut Ctx,
|
||||
index: i32,
|
||||
a1: i32,
|
||||
a2: i32,
|
||||
a3: i32,
|
||||
a4: i32,
|
||||
a5: i32,
|
||||
a6: i32,
|
||||
a7: i32,
|
||||
) -> i32 {
|
||||
debug!("emscripten::invoke_iiiiiiii");
|
||||
if let Some(dyn_call_iiiiiiii) = &get_emscripten_data(ctx).dyn_call_iiiiiiii {
|
||||
dyn_call_iiiiiiii
|
||||
.call(index, a1, a2, a3, a4, a5, a6, a7)
|
||||
.unwrap()
|
||||
} else {
|
||||
panic!("dyn_call_iiiiiiii is set to None");
|
||||
}
|
||||
}
|
||||
pub fn invoke_iiiiiiiiii(
|
||||
ctx: &mut Ctx,
|
||||
index: i32,
|
||||
a1: i32,
|
||||
a2: i32,
|
||||
a3: i32,
|
||||
a4: i32,
|
||||
a5: i32,
|
||||
a6: i32,
|
||||
a7: i32,
|
||||
a8: i32,
|
||||
a9: i32,
|
||||
) -> i32 {
|
||||
debug!("emscripten::invoke_iiiiiiiiii");
|
||||
if let Some(dyn_call_iiiiiiiiii) = &get_emscripten_data(ctx).dyn_call_iiiiiiiiii {
|
||||
dyn_call_iiiiiiiiii
|
||||
.call(index, a1, a2, a3, a4, a5, a6, a7, a8, a9)
|
||||
.unwrap()
|
||||
} else {
|
||||
panic!("dyn_call_iiiiiiiiii is set to None");
|
||||
}
|
||||
}
|
||||
pub fn invoke_vd(ctx: &mut Ctx, index: i32, a1: f64) {
|
||||
debug!("emscripten::invoke_vd");
|
||||
if let Some(dyn_call_vd) = &get_emscripten_data(ctx).dyn_call_vd {
|
||||
@ -573,3 +754,11 @@ pub fn invoke_vijj(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i32
|
||||
panic!("dyn_call_vijj is set to None");
|
||||
}
|
||||
}
|
||||
pub fn invoke_viidii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: f64, a4: i32, a5: i32) {
|
||||
debug!("emscripten::invoke_viidii");
|
||||
if let Some(dyn_call_viidii) = &get_emscripten_data(ctx).dyn_call_viidii {
|
||||
dyn_call_viidii.call(index, a1, a2, a3, a4, a5).unwrap();
|
||||
} else {
|
||||
panic!("dyn_call_viidii is set to None");
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::varargs::VarArgs;
|
||||
use libc::execvp as libc_execvp;
|
||||
use std::cell::Cell;
|
||||
use std::ffi::CString;
|
||||
@ -38,3 +39,15 @@ pub fn execvp(ctx: &mut Ctx, command_name_offset: u32, argv_offset: u32) -> i32
|
||||
let args_pointer = argv.as_ptr();
|
||||
unsafe { libc_execvp(command_pointer, args_pointer) }
|
||||
}
|
||||
|
||||
/// execl
|
||||
pub fn execl(_ctx: &mut Ctx, _path_ptr: i32, _arg0_ptr: i32, _varargs: VarArgs) -> i32 {
|
||||
debug!("emscripten::execl");
|
||||
-1
|
||||
}
|
||||
|
||||
/// execle
|
||||
pub fn execle(_ctx: &mut Ctx, _path_ptr: i32, _arg0_ptr: i32, _varargs: VarArgs) -> i32 {
|
||||
debug!("emscripten::execle");
|
||||
-1
|
||||
}
|
||||
|
@ -9,3 +9,41 @@ pub use self::unix::*;
|
||||
|
||||
#[cfg(windows)]
|
||||
pub use self::windows::*;
|
||||
|
||||
use wasmer_runtime_core::vm::Ctx;
|
||||
|
||||
/// getprotobyname
|
||||
pub fn getprotobyname(_ctx: &mut Ctx, _name_ptr: i32) -> i32 {
|
||||
debug!("emscripten::getprotobyname");
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// getprotobynumber
|
||||
pub fn getprotobynumber(_ctx: &mut Ctx, _one: i32) -> i32 {
|
||||
debug!("emscripten::getprotobynumber");
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// sigdelset
|
||||
pub fn sigdelset(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::sigdelset");
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// sigfillset
|
||||
pub fn sigfillset(_ctx: &mut Ctx, _one: i32) -> i32 {
|
||||
debug!("emscripten::sigfillset");
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// tzset
|
||||
pub fn tzset(_ctx: &mut Ctx) {
|
||||
debug!("emscripten::tzset");
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// strptime
|
||||
pub fn strptime(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 {
|
||||
debug!("emscripten::strptime");
|
||||
unimplemented!()
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use libc::printf as _printf;
|
||||
use libc::{chroot as _chroot, printf as _printf};
|
||||
|
||||
use wasmer_runtime_core::vm::Ctx;
|
||||
|
||||
@ -15,3 +15,16 @@ pub fn printf(ctx: &mut Ctx, memory_offset: i32, extra: i32) -> i32 {
|
||||
_printf(addr, extra)
|
||||
}
|
||||
}
|
||||
|
||||
/// chroot
|
||||
pub fn chroot(ctx: &mut Ctx, name_ptr: i32) -> i32 {
|
||||
debug!("emscripten::chroot");
|
||||
let name = emscripten_memory_pointer!(ctx.memory(0), name_ptr) as *const i8;
|
||||
unsafe { _chroot(name) }
|
||||
}
|
||||
|
||||
/// getpwuid
|
||||
pub fn getpwuid(_ctx: &mut Ctx, _uid: i32) -> i32 {
|
||||
debug!("emscripten::getpwuid");
|
||||
0
|
||||
}
|
||||
|
@ -32,3 +32,15 @@ pub fn printf(_ctx: &mut Ctx, memory_offset: i32, extra: i32) -> i32 {
|
||||
// }
|
||||
-1
|
||||
}
|
||||
|
||||
/// chroot
|
||||
pub fn chroot(ctx: &mut Ctx, name_ptr: i32) -> i32 {
|
||||
debug!("emscripten::chroot");
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// getpwuid
|
||||
pub fn getpwuid(_ctx: &mut Ctx, uid: i32) -> i32 {
|
||||
debug!("emscripten::getpwuid");
|
||||
unimplemented!()
|
||||
}
|
||||
|
@ -100,6 +100,10 @@ pub struct EmscriptenData<'a> {
|
||||
pub dyn_call_diiii: Option<Func<'a, (i32, i32, i32, i32, i32), f64>>,
|
||||
pub dyn_call_iiiii: Option<Func<'a, (i32, i32, i32, i32, i32), i32>>,
|
||||
pub dyn_call_iiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32), i32>>,
|
||||
pub dyn_call_iiiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32), i32>>,
|
||||
pub dyn_call_iiiiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32), i32>>,
|
||||
pub dyn_call_iiiiiiiiii:
|
||||
Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32, i32, i32, i32), i32>>,
|
||||
pub dyn_call_vd: Option<Func<'a, (i32, f64)>>,
|
||||
pub dyn_call_viiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32)>>,
|
||||
pub dyn_call_viiiiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32)>>,
|
||||
@ -123,6 +127,7 @@ pub struct EmscriptenData<'a> {
|
||||
pub dyn_call_viji: Option<Func<'a, (i32, i32, i32, i32, i32)>>,
|
||||
pub dyn_call_vijiii: Option<Func<'a, (i32, i32, i32, i32, i32, i32, i32)>>,
|
||||
pub dyn_call_vijj: Option<Func<'a, (i32, i32, i32, i32, i32, i32)>>,
|
||||
pub dyn_call_viidii: Option<Func<'a, (i32, i32, i32, f64, i32, i32)>>,
|
||||
|
||||
#[cfg(all(feature = "vfs", not(target_os = "windows")))]
|
||||
pub vfs: Option<EmscriptenVfs>,
|
||||
@ -155,6 +160,9 @@ impl<'a> EmscriptenData<'a> {
|
||||
let dyn_call_diiii = instance.func("dynCall_diiii").ok();
|
||||
let dyn_call_iiiii = instance.func("dynCall_iiiii").ok();
|
||||
let dyn_call_iiiiii = instance.func("dynCall_iiiiii").ok();
|
||||
let dyn_call_iiiiiii = instance.func("dynCall_iiiiiii").ok();
|
||||
let dyn_call_iiiiiiii = instance.func("dynCall_iiiiiiii").ok();
|
||||
let dyn_call_iiiiiiiiii = instance.func("dynCall_iiiiiiiiii").ok();
|
||||
let dyn_call_vd = instance.func("dynCall_vd").ok();
|
||||
let dyn_call_viiiii = instance.func("dynCall_viiiii").ok();
|
||||
let dyn_call_viiiiii = instance.func("dynCall_viiiiii").ok();
|
||||
@ -177,6 +185,7 @@ impl<'a> EmscriptenData<'a> {
|
||||
let dyn_call_viji = instance.func("dynCall_viji").ok();
|
||||
let dyn_call_vijiii = instance.func("dynCall_vijiii").ok();
|
||||
let dyn_call_vijj = instance.func("dynCall_vijj").ok();
|
||||
let dyn_call_viidii = instance.func("dynCall_viidii").ok();
|
||||
|
||||
EmscriptenData {
|
||||
malloc,
|
||||
@ -200,6 +209,9 @@ impl<'a> EmscriptenData<'a> {
|
||||
dyn_call_diiii,
|
||||
dyn_call_iiiii,
|
||||
dyn_call_iiiiii,
|
||||
dyn_call_iiiiiii,
|
||||
dyn_call_iiiiiiii,
|
||||
dyn_call_iiiiiiiiii,
|
||||
dyn_call_vd,
|
||||
dyn_call_viiiii,
|
||||
dyn_call_viiiiii,
|
||||
@ -222,6 +234,7 @@ impl<'a> EmscriptenData<'a> {
|
||||
dyn_call_viji,
|
||||
dyn_call_vijiii,
|
||||
dyn_call_vijj,
|
||||
dyn_call_viidii,
|
||||
#[cfg(all(feature = "vfs", not(target_os = "windows")))]
|
||||
vfs: None,
|
||||
}
|
||||
@ -445,9 +458,20 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
||||
"___lock" => func!(crate::lock::___lock),
|
||||
"___unlock" => func!(crate::lock::___unlock),
|
||||
"___wait" => func!(crate::lock::___wait),
|
||||
"_flock" => func!(crate::lock::_flock),
|
||||
"_chroot" => func!(crate::io::chroot),
|
||||
"_getprotobyname" => func!(crate::io::getprotobyname),
|
||||
"_getprotobynumber" => func!(crate::io::getprotobynumber),
|
||||
"_getpwuid" => func!(crate::io::getpwuid),
|
||||
"_sigdelset" => func!(crate::io::sigdelset),
|
||||
"_sigfillset" => func!(crate::io::sigfillset),
|
||||
"_tzset" => func!(crate::io::tzset),
|
||||
"_strptime" => func!(crate::io::strptime),
|
||||
|
||||
// exec
|
||||
"_execvp" => func!(crate::exec::execvp),
|
||||
"_execl" => func!(crate::exec::execl),
|
||||
"_execle" => func!(crate::exec::execle),
|
||||
|
||||
// exit
|
||||
"__exit" => func!(crate::exit::exit),
|
||||
@ -488,13 +512,17 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
||||
"___syscall4" => func!(crate::syscalls::___syscall4),
|
||||
"___syscall5" => func!(crate::syscalls::___syscall5),
|
||||
"___syscall6" => func!(crate::syscalls::___syscall6),
|
||||
"___syscall9" => func!(crate::syscalls::___syscall9),
|
||||
"___syscall10" => func!(crate::syscalls::___syscall10),
|
||||
"___syscall12" => func!(crate::syscalls::___syscall12),
|
||||
"___syscall15" => func!(crate::syscalls::___syscall15),
|
||||
"___syscall20" => func!(crate::syscalls::___syscall20),
|
||||
"___syscall33" => func!(crate::syscalls::___syscall33),
|
||||
"___syscall34" => func!(crate::syscalls::___syscall34),
|
||||
"___syscall39" => func!(crate::syscalls::___syscall39),
|
||||
"___syscall38" => func!(crate::syscalls::___syscall38),
|
||||
"___syscall40" => func!(crate::syscalls::___syscall40),
|
||||
"___syscall41" => func!(crate::syscalls::___syscall41),
|
||||
"___syscall42" => func!(crate::syscalls::___syscall42),
|
||||
"___syscall54" => func!(crate::syscalls::___syscall54),
|
||||
"___syscall57" => func!(crate::syscalls::___syscall57),
|
||||
@ -503,17 +531,22 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
||||
"___syscall64" => func!(crate::syscalls::___syscall64),
|
||||
"___syscall66" => func!(crate::syscalls::___syscall66),
|
||||
"___syscall75" => func!(crate::syscalls::___syscall75),
|
||||
"___syscall77" => func!(crate::syscalls::___syscall77),
|
||||
"___syscall83" => func!(crate::syscalls::___syscall83),
|
||||
"___syscall85" => func!(crate::syscalls::___syscall85),
|
||||
"___syscall91" => func!(crate::syscalls::___syscall191),
|
||||
"___syscall94" => func!(crate::syscalls::___syscall194),
|
||||
"___syscall97" => func!(crate::syscalls::___syscall97),
|
||||
"___syscall102" => func!(crate::syscalls::___syscall102),
|
||||
"___syscall110" => func!(crate::syscalls::___syscall110),
|
||||
"___syscall114" => func!(crate::syscalls::___syscall114),
|
||||
"___syscall118" => func!(crate::syscalls::___syscall118),
|
||||
"___syscall122" => func!(crate::syscalls::___syscall122),
|
||||
"___syscall140" => func!(crate::syscalls::___syscall140),
|
||||
"___syscall142" => func!(crate::syscalls::___syscall142),
|
||||
"___syscall145" => func!(crate::syscalls::___syscall145),
|
||||
"___syscall146" => func!(crate::syscalls::___syscall146),
|
||||
"___syscall148" => func!(crate::syscalls::___syscall148),
|
||||
"___syscall168" => func!(crate::syscalls::___syscall168),
|
||||
"___syscall180" => func!(crate::syscalls::___syscall180),
|
||||
"___syscall181" => func!(crate::syscalls::___syscall181),
|
||||
@ -524,16 +557,22 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
||||
"___syscall195" => func!(crate::syscalls::___syscall195),
|
||||
"___syscall196" => func!(crate::syscalls::___syscall196),
|
||||
"___syscall197" => func!(crate::syscalls::___syscall197),
|
||||
"___syscall198" => func!(crate::syscalls::___syscall198),
|
||||
"___syscall199" => func!(crate::syscalls::___syscall199),
|
||||
"___syscall200" => func!(crate::syscalls::___syscall200),
|
||||
"___syscall201" => func!(crate::syscalls::___syscall201),
|
||||
"___syscall202" => func!(crate::syscalls::___syscall202),
|
||||
"___syscall205" => func!(crate::syscalls::___syscall205),
|
||||
"___syscall207" => func!(crate::syscalls::___syscall207),
|
||||
"___syscall212" => func!(crate::syscalls::___syscall212),
|
||||
"___syscall219" => func!(crate::syscalls::___syscall219),
|
||||
"___syscall220" => func!(crate::syscalls::___syscall220),
|
||||
"___syscall221" => func!(crate::syscalls::___syscall221),
|
||||
"___syscall268" => func!(crate::syscalls::___syscall268),
|
||||
"___syscall272" => func!(crate::syscalls::___syscall272),
|
||||
"___syscall295" => func!(crate::syscalls::___syscall295),
|
||||
"___syscall300" => func!(crate::syscalls::___syscall300),
|
||||
"___syscall324" => func!(crate::syscalls::___syscall324),
|
||||
"___syscall330" => func!(crate::syscalls::___syscall330),
|
||||
"___syscall334" => func!(crate::syscalls::___syscall334),
|
||||
"___syscall340" => func!(crate::syscalls::___syscall340),
|
||||
@ -562,6 +601,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
||||
"_setgroups" => func!(crate::process::_setgroups),
|
||||
"_setitimer" => func!(crate::process::_setitimer),
|
||||
"_usleep" => func!(crate::process::_usleep),
|
||||
"_nanosleep" => func!(crate::process::_nanosleep),
|
||||
"_utimes" => func!(crate::process::_utimes),
|
||||
"_waitpid" => func!(crate::process::_waitpid),
|
||||
|
||||
@ -609,11 +649,14 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
||||
"_llvm_log2_f64" => func!(crate::math::_llvm_log2_f64),
|
||||
"_llvm_log10_f32" => func!(crate::math::_llvm_log10_f32),
|
||||
"_llvm_log2_f32" => func!(crate::math::_llvm_log2_f64),
|
||||
"_llvm_sin_f64" => func!(crate::math::_llvm_sin_f64),
|
||||
"_llvm_cos_f64" => func!(crate::math::_llvm_cos_f64),
|
||||
"_emscripten_random" => func!(crate::math::_emscripten_random),
|
||||
|
||||
// Jump
|
||||
"__setjmp" => func!(crate::jmp::__setjmp),
|
||||
"__longjmp" => func!(crate::jmp::__longjmp),
|
||||
"_longjmp" => func!(crate::jmp::__longjmp),
|
||||
|
||||
// Linking
|
||||
"_dlclose" => func!(crate::linking::_dlclose),
|
||||
@ -625,6 +668,11 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
||||
"setTempRet0" => func!(crate::emscripten_target::setTempRet0),
|
||||
"getTempRet0" => func!(crate::emscripten_target::getTempRet0),
|
||||
"nullFunc_ji" => func!(crate::emscripten_target::nullFunc_ji),
|
||||
"nullFunc_d" => func!(crate::emscripten_target::nullFunc_d),
|
||||
"nullFunc_viidii" => func!(crate::emscripten_target::nullFunc_viidii),
|
||||
"nullFunc_iiiiiii" => func!(crate::emscripten_target::nullFunc_iiiiiii),
|
||||
"nullFunc_iiiiiiii" => func!(crate::emscripten_target::nullFunc_iiiiiiii),
|
||||
"nullFunc_iiiiiiiiii" => func!(crate::emscripten_target::nullFunc_iiiiiiiiii),
|
||||
"invoke_i" => func!(crate::emscripten_target::invoke_i),
|
||||
"invoke_ii" => func!(crate::emscripten_target::invoke_ii),
|
||||
"invoke_iii" => func!(crate::emscripten_target::invoke_iii),
|
||||
@ -642,6 +690,8 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
||||
"___cxa_free_exception" => func!(crate::emscripten_target::___cxa_free_exception),
|
||||
"___resumeException" => func!(crate::emscripten_target::___resumeException),
|
||||
"_dladdr" => func!(crate::emscripten_target::_dladdr),
|
||||
"_pthread_create" => func!(crate::emscripten_target::_pthread_create),
|
||||
"_pthread_join" => func!(crate::emscripten_target::_pthread_join),
|
||||
"_pthread_cond_destroy" => func!(crate::emscripten_target::_pthread_cond_destroy),
|
||||
"_pthread_cond_init" => func!(crate::emscripten_target::_pthread_cond_init),
|
||||
"_pthread_cond_signal" => func!(crate::emscripten_target::_pthread_cond_signal),
|
||||
@ -656,15 +706,36 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
||||
"_pthread_mutexattr_settype" => func!(crate::emscripten_target::_pthread_mutexattr_settype),
|
||||
"_pthread_rwlock_rdlock" => func!(crate::emscripten_target::_pthread_rwlock_rdlock),
|
||||
"_pthread_rwlock_unlock" => func!(crate::emscripten_target::_pthread_rwlock_unlock),
|
||||
"_pthread_setcancelstate" => func!(crate::emscripten_target::_pthread_setcancelstate),
|
||||
"___gxx_personality_v0" => func!(crate::emscripten_target::___gxx_personality_v0),
|
||||
"_getdtablesize" => func!(crate::emscripten_target::_getdtablesize),
|
||||
"_gethostbyaddr" => func!(crate::emscripten_target::_gethostbyaddr),
|
||||
"_gethostbyname_r" => func!(crate::emscripten_target::_gethostbyname_r),
|
||||
"_getloadavg" => func!(crate::emscripten_target::_getloadavg),
|
||||
// round 2
|
||||
"nullFunc_di" => func!(crate::emscripten_target::nullFunc_di),
|
||||
"nullFunc_dii" => func!(crate::emscripten_target::nullFunc_dii),
|
||||
"nullFunc_diiii" => func!(crate::emscripten_target::nullFunc_diiii),
|
||||
"nullFunc_iiid" => func!(crate::emscripten_target::nullFunc_iiid),
|
||||
"nullFunc_iiji" => func!(crate::emscripten_target::nullFunc_iiji),
|
||||
"nullFunc_iijj" => func!(crate::emscripten_target::nullFunc_iijj),
|
||||
"nullFunc_iij" => func!(crate::emscripten_target::nullFunc_iij),
|
||||
"nullFunc_ij" => func!(crate::emscripten_target::nullFunc_ij),
|
||||
"nullFunc_j" => func!(crate::emscripten_target::nullFunc_j),
|
||||
"nullFunc_jij" => func!(crate::emscripten_target::nullFunc_jij),
|
||||
"nullFunc_jj" => func!(crate::emscripten_target::nullFunc_jj),
|
||||
"nullFunc_jjj" => func!(crate::emscripten_target::nullFunc_jjj),
|
||||
"nullFunc_jii" => func!(crate::emscripten_target::nullFunc_jii),
|
||||
"nullFunc_jiij" => func!(crate::emscripten_target::nullFunc_jiij),
|
||||
"nullFunc_vd" => func!(crate::emscripten_target::nullFunc_vd),
|
||||
"nullFunc_iiiiiiiii" => func!(crate::emscripten_target::nullFunc_iiiiiiiii),
|
||||
"nullFunc_iiiiiiiiiii" => func!(crate::emscripten_target::nullFunc_iiiiiiiiiii),
|
||||
"nullFunc_iiiiijii" => func!(crate::emscripten_target::nullFunc_iiiiijii),
|
||||
"nullFunc_iiiij" => func!(crate::emscripten_target::nullFunc_iiiij),
|
||||
"nullFunc_iiij" => func!(crate::emscripten_target::nullFunc_iiij),
|
||||
"nullFunc_iiiiji" => func!(crate::emscripten_target::nullFunc_iiiiji),
|
||||
"nullFunc_iijii" => func!(crate::emscripten_target::nullFunc_iijii),
|
||||
"nullFunc_iiiijii" => func!(crate::emscripten_target::nullFunc_iiiijii),
|
||||
"nullFunc_viiiiiii" => func!(crate::emscripten_target::nullFunc_viiiiiii),
|
||||
"nullFunc_viiiiiiii" => func!(crate::emscripten_target::nullFunc_viiiiiiii),
|
||||
"nullFunc_viiiiiiiii" => func!(crate::emscripten_target::nullFunc_viiiiiiiii),
|
||||
@ -673,9 +744,13 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
||||
"nullFunc_viiijiiiiii" => func!(crate::emscripten_target::nullFunc_viiijiiiiii),
|
||||
"nullFunc_viij" => func!(crate::emscripten_target::nullFunc_viij),
|
||||
"nullFunc_viiji" => func!(crate::emscripten_target::nullFunc_viiji),
|
||||
"nullFunc_vijii" => func!(crate::emscripten_target::nullFunc_vijii),
|
||||
"nullFunc_viijii" => func!(crate::emscripten_target::nullFunc_viijii),
|
||||
"nullFunc_viiiij" => func!(crate::emscripten_target::nullFunc_viiiij),
|
||||
"nullFunc_viijiii" => func!(crate::emscripten_target::nullFunc_viijiii),
|
||||
"nullFunc_viijj" => func!(crate::emscripten_target::nullFunc_viijj),
|
||||
"nullFunc_vij" => func!(crate::emscripten_target::nullFunc_vij),
|
||||
"nullFunc_vid" => func!(crate::emscripten_target::nullFunc_vid),
|
||||
"nullFunc_viji" => func!(crate::emscripten_target::nullFunc_viji),
|
||||
"nullFunc_vijiii" => func!(crate::emscripten_target::nullFunc_vijiii),
|
||||
"nullFunc_vijj" => func!(crate::emscripten_target::nullFunc_vijj),
|
||||
@ -683,6 +758,9 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
||||
"invoke_diiii" => func!(crate::emscripten_target::invoke_diiii),
|
||||
"invoke_iiiii" => func!(crate::emscripten_target::invoke_iiiii),
|
||||
"invoke_iiiiii" => func!(crate::emscripten_target::invoke_iiiiii),
|
||||
"invoke_iiiiiii" => func!(crate::emscripten_target::invoke_iiiiiii),
|
||||
"invoke_iiiiiiii" => func!(crate::emscripten_target::invoke_iiiiiiii),
|
||||
"invoke_iiiiiiiiii" => func!(crate::emscripten_target::invoke_iiiiiiiiii),
|
||||
"invoke_vd" => func!(crate::emscripten_target::invoke_vd),
|
||||
"invoke_viiiii" => func!(crate::emscripten_target::invoke_viiiii),
|
||||
"invoke_viiiiii" => func!(crate::emscripten_target::invoke_viiiiii),
|
||||
@ -705,6 +783,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
||||
"invoke_viji" => func!(crate::emscripten_target::invoke_viji),
|
||||
"invoke_vijiii" => func!(crate::emscripten_target::invoke_vijiii),
|
||||
"invoke_vijj" => func!(crate::emscripten_target::invoke_vijj),
|
||||
"invoke_viidii" => func!(crate::emscripten_target::invoke_viidii),
|
||||
},
|
||||
"global" => {
|
||||
"NaN" => Global::new(Value::F64(f64::NAN)),
|
||||
@ -712,6 +791,8 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
||||
},
|
||||
"global.Math" => {
|
||||
"pow" => func!(crate::math::pow),
|
||||
"exp" => func!(crate::math::exp),
|
||||
"log" => func!(crate::math::log),
|
||||
},
|
||||
"asm2wasm" => {
|
||||
"f64-rem" => func!(crate::math::f64_rem),
|
||||
|
@ -15,3 +15,8 @@ pub fn ___unlock(_ctx: &mut Ctx, _what: c_int) {
|
||||
pub fn ___wait(_ctx: &mut Ctx, _which: u32, _varargs: u32, _three: u32, _four: u32) {
|
||||
debug!("emscripten::___wait");
|
||||
}
|
||||
|
||||
pub fn _flock(_ctx: &mut Ctx, _fd: u32, _op: u32) -> u32 {
|
||||
debug!("emscripten::_flock");
|
||||
0
|
||||
}
|
||||
|
@ -12,6 +12,18 @@ pub fn _llvm_log2_f64(_ctx: &mut Ctx, value: f64) -> f64 {
|
||||
value.log2()
|
||||
}
|
||||
|
||||
/// emscripten: _llvm_sin_f64
|
||||
pub fn _llvm_sin_f64(_ctx: &mut Ctx, value: f64) -> f64 {
|
||||
debug!("emscripten::_llvm_sin_f64");
|
||||
value.sin()
|
||||
}
|
||||
|
||||
/// emscripten: _llvm_cos_f64
|
||||
pub fn _llvm_cos_f64(_ctx: &mut Ctx, value: f64) -> f64 {
|
||||
debug!("emscripten::_llvm_cos_f64");
|
||||
value.cos()
|
||||
}
|
||||
|
||||
pub fn _llvm_log10_f32(_ctx: &mut Ctx, _value: f64) -> f64 {
|
||||
debug!("emscripten::_llvm_log10_f32");
|
||||
-1.0
|
||||
@ -37,3 +49,13 @@ pub fn f64_rem(_ctx: &mut Ctx, x: f64, y: f64) -> f64 {
|
||||
pub fn pow(_ctx: &mut Ctx, x: f64, y: f64) -> f64 {
|
||||
x.powf(y)
|
||||
}
|
||||
|
||||
// emscripten: global.Math exp
|
||||
pub fn exp(_ctx: &mut Ctx, value: f64) -> f64 {
|
||||
value.exp()
|
||||
}
|
||||
|
||||
// emscripten: global.Math log
|
||||
pub fn log(_ctx: &mut Ctx, value: f64) -> f64 {
|
||||
value.ln()
|
||||
}
|
||||
|
@ -121,6 +121,11 @@ pub fn _usleep(_ctx: &mut Ctx, _one: i32) -> i32 {
|
||||
-1
|
||||
}
|
||||
|
||||
pub fn _nanosleep(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::_nanosleep");
|
||||
-1
|
||||
}
|
||||
|
||||
pub fn _utimes(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::_utimes");
|
||||
-1
|
||||
|
@ -24,6 +24,9 @@ use libc::{c_int, c_void, chdir, exit, getpid, lseek, rmdir};
|
||||
use wasmer_runtime_core::vm::Ctx;
|
||||
|
||||
use super::env;
|
||||
#[allow(unused_imports)]
|
||||
use std::io::Error;
|
||||
use std::mem;
|
||||
use std::slice;
|
||||
|
||||
/// exit
|
||||
@ -164,10 +167,28 @@ pub fn ___syscall140(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
|
||||
// -> c_int
|
||||
debug!("emscripten::___syscall140 (lseek) {}", _which);
|
||||
let fd: i32 = varargs.get(ctx);
|
||||
let offset: i32 = varargs.get(ctx);
|
||||
let _ = varargs.get::<i32>(ctx); // ignore high offset
|
||||
let offset_low: i32 = varargs.get(ctx);
|
||||
let result_ptr_value = varargs.get::<i32>(ctx);
|
||||
let whence: i32 = varargs.get(ctx);
|
||||
debug!("=> fd: {}, offset: {}, whence = {}", fd, offset, whence);
|
||||
unsafe { lseek(fd, offset as _, whence) as _ }
|
||||
let offset = offset_low as libc::off_t;
|
||||
let ret = unsafe { lseek(fd, offset, whence) as i32 };
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let result_ptr = emscripten_memory_pointer!(ctx.memory(0), result_ptr_value) as *mut i32;
|
||||
assert_eq!(4, mem::align_of_val(&result_ptr));
|
||||
unsafe {
|
||||
*result_ptr = ret;
|
||||
}
|
||||
debug!(
|
||||
"=> fd: {}, offset: {}, result_ptr: {}, whence: {} = {}\nlast os error: {}",
|
||||
fd,
|
||||
offset,
|
||||
result_ptr_value,
|
||||
whence,
|
||||
0,
|
||||
Error::last_os_error(),
|
||||
);
|
||||
0
|
||||
}
|
||||
|
||||
/// readv
|
||||
@ -217,21 +238,57 @@ pub fn ___syscall191(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
-1
|
||||
}
|
||||
|
||||
pub fn ___syscall194(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::___syscall194 - stub");
|
||||
-1
|
||||
}
|
||||
|
||||
pub fn ___syscall196(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::___syscall194 - stub");
|
||||
-1
|
||||
}
|
||||
|
||||
pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::___syscall199 - stub");
|
||||
-1
|
||||
}
|
||||
|
||||
// stat64
|
||||
pub fn ___syscall195(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall195 (stat64) {}", _which);
|
||||
let pathname: u32 = varargs.get(ctx);
|
||||
let buf: u32 = varargs.get(ctx);
|
||||
|
||||
let pathname_addr = emscripten_memory_pointer!(ctx.memory(0), pathname) as *const i8;
|
||||
|
||||
unsafe {
|
||||
let mut _stat: libc::stat = std::mem::zeroed();
|
||||
let ret = libc::stat(pathname_addr, &mut _stat);
|
||||
debug!(
|
||||
"=> pathname: {}, buf: {}, path: {} = {}\nlast os error: {}",
|
||||
pathname,
|
||||
buf,
|
||||
std::ffi::CStr::from_ptr(pathname_addr).to_str().unwrap(),
|
||||
ret,
|
||||
Error::last_os_error()
|
||||
);
|
||||
if ret != 0 {
|
||||
return ret;
|
||||
}
|
||||
crate::utils::copy_stat_into_wasm(ctx, buf, &_stat);
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
// fstat64
|
||||
pub fn ___syscall197(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall197 (fstat64) {}", _which);
|
||||
let fd: c_int = varargs.get(ctx);
|
||||
let buf: u32 = varargs.get(ctx);
|
||||
|
||||
unsafe {
|
||||
let mut stat = std::mem::zeroed();
|
||||
let ret = libc::fstat(fd, &mut stat);
|
||||
debug!("ret: {}", ret);
|
||||
if ret != 0 {
|
||||
return ret;
|
||||
}
|
||||
crate::utils::copy_stat_into_wasm(ctx, buf, &stat);
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
pub fn ___syscall220(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::___syscall220");
|
||||
-1
|
||||
@ -243,8 +300,14 @@ pub fn ___syscall221(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in
|
||||
// fcntl64
|
||||
let _fd: i32 = varargs.get(ctx);
|
||||
let cmd: u32 = varargs.get(ctx);
|
||||
// (FAPPEND - 0x08
|
||||
// |FASYNC - 0x40
|
||||
// |FFSYNC - 0x80
|
||||
// |FNONBLOCK - 0x04
|
||||
debug!("=> fd: {}, cmd: {}", _fd, cmd);
|
||||
match cmd {
|
||||
2 => 0,
|
||||
13 | 14 => 0, // pretend file locking worked
|
||||
_ => -1,
|
||||
}
|
||||
}
|
||||
|
@ -28,10 +28,106 @@ use wasmer_runtime_core::vm::Ctx;
|
||||
#[link(name = "c")]
|
||||
extern "C" {
|
||||
pub fn wait4(pid: pid_t, status: *mut c_int, options: c_int, rusage: *mut rusage) -> pid_t;
|
||||
pub fn madvise(addr: *mut libc::c_void, len: libc::size_t, advice: c_int) -> c_int;
|
||||
pub fn fdatasync(fd: c_int) -> c_int;
|
||||
pub fn lstat64(path: *const libc::c_char, buf: *mut libc::c_void) -> c_int;
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
use libc::wait4;
|
||||
use libc::{fallocate, fdatasync, ftruncate64, lstat64, madvise, wait4};
|
||||
|
||||
/// link
|
||||
pub fn ___syscall9(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall9 (link) {}", _which);
|
||||
|
||||
let oldname: c_int = varargs.get(ctx);
|
||||
let newname: c_int = varargs.get(ctx);
|
||||
let oldname_ptr = emscripten_memory_pointer!(ctx.memory(0), oldname) as *const i8;
|
||||
let newname_ptr = emscripten_memory_pointer!(ctx.memory(0), newname) as *const i8;
|
||||
let result = unsafe { libc::link(oldname_ptr, newname_ptr) };
|
||||
debug!(
|
||||
"=> oldname: {}, newname: {}, result: {}",
|
||||
unsafe { std::ffi::CStr::from_ptr(oldname_ptr).to_str().unwrap() },
|
||||
unsafe { std::ffi::CStr::from_ptr(newname_ptr).to_str().unwrap() },
|
||||
result,
|
||||
);
|
||||
result
|
||||
}
|
||||
|
||||
/// access
|
||||
pub fn ___syscall33(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall33 (access) {}", _which);
|
||||
let path_ptr: c_int = varargs.get(ctx);
|
||||
let amode: c_int = varargs.get(ctx);
|
||||
let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const i8;
|
||||
let result = unsafe { libc::access(path, amode) };
|
||||
debug!(
|
||||
"=> path: {}, result: {}",
|
||||
unsafe { std::ffi::CStr::from_ptr(path).to_str().unwrap() },
|
||||
result
|
||||
);
|
||||
result
|
||||
}
|
||||
|
||||
/// nice
|
||||
pub fn ___syscall34(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall34 (nice) {}", _which);
|
||||
let inc_r: c_int = varargs.get(ctx);
|
||||
unsafe { libc::nice(inc_r) }
|
||||
}
|
||||
|
||||
/// getrusage
|
||||
pub fn ___syscall77(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall77 (getrusage) {}", _which);
|
||||
|
||||
let resource: c_int = varargs.get(ctx);
|
||||
let rusage_ptr: c_int = varargs.get(ctx);
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let rusage = emscripten_memory_pointer!(ctx.memory(0), rusage_ptr) as *mut rusage;
|
||||
assert_eq!(8, std::mem::align_of_val(&rusage));
|
||||
unsafe { libc::getrusage(resource, rusage) }
|
||||
}
|
||||
|
||||
/// dup
|
||||
pub fn ___syscall41(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall41 (dup) {}", _which);
|
||||
let fd: c_int = varargs.get(ctx);
|
||||
unsafe { libc::dup(fd) }
|
||||
}
|
||||
|
||||
/// setpgid
|
||||
pub fn ___syscall57(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall57 (setpgid) {}", _which);
|
||||
let pid: i32 = varargs.get(ctx);
|
||||
let pgid: i32 = varargs.get(ctx);
|
||||
unsafe { setpgid(pid, pgid) }
|
||||
}
|
||||
|
||||
/// symlink
|
||||
pub fn ___syscall83(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall83 (symlink) {}", _which);
|
||||
|
||||
let path1_ptr: c_int = varargs.get(ctx);
|
||||
let path2_ptr: c_int = varargs.get(ctx);
|
||||
let path1 = emscripten_memory_pointer!(ctx.memory(0), path1_ptr) as *mut i8;
|
||||
let path2 = emscripten_memory_pointer!(ctx.memory(0), path2_ptr) as *mut i8;
|
||||
let result = unsafe { libc::symlink(path1, path2) };
|
||||
debug!(
|
||||
"=> path1: {}, path2: {}, result: {}",
|
||||
unsafe { std::ffi::CStr::from_ptr(path1).to_str().unwrap() },
|
||||
unsafe { std::ffi::CStr::from_ptr(path2).to_str().unwrap() },
|
||||
result,
|
||||
);
|
||||
result
|
||||
}
|
||||
|
||||
/// fchmod
|
||||
pub fn ___syscall94(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall118 (fchmod) {}", _which);
|
||||
let fd: c_int = varargs.get(ctx);
|
||||
let mode: libc::mode_t = varargs.get(ctx);
|
||||
unsafe { libc::fchmod(fd, mode) }
|
||||
}
|
||||
|
||||
/// wait4
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
@ -51,12 +147,11 @@ pub fn ___syscall114(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> pid_
|
||||
res
|
||||
}
|
||||
|
||||
/// setpgid
|
||||
pub fn ___syscall57(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall57 (setpgid) {}", _which);
|
||||
let pid: i32 = varargs.get(ctx);
|
||||
let pgid: i32 = varargs.get(ctx);
|
||||
unsafe { setpgid(pid, pgid) }
|
||||
/// fsync
|
||||
pub fn ___syscall118(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall118 (fsync) {}", _which);
|
||||
let fd: c_int = varargs.get(ctx);
|
||||
unsafe { libc::fsync(fd) }
|
||||
}
|
||||
|
||||
/// uname
|
||||
@ -74,6 +169,72 @@ pub fn ___syscall122(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in
|
||||
uname_result
|
||||
}
|
||||
|
||||
|
||||
/// fdatasync
|
||||
pub fn ___syscall148(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall148 (fdatasync) {}", _which);
|
||||
|
||||
let fd: i32 = varargs.get(ctx);
|
||||
|
||||
unsafe { fdatasync(fd) }
|
||||
}
|
||||
|
||||
/// ftruncate64
|
||||
pub fn ___syscall194(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall194 (ftruncate64) {}", _which);
|
||||
let _fd: c_int = varargs.get(ctx);
|
||||
let _length: i64 = varargs.get(ctx);
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
unsafe {
|
||||
ftruncate64(_fd, _length)
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// lstat64
|
||||
pub fn ___syscall196(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
|
||||
debug!("emscripten::___syscall196 (lstat64) {}", _which);
|
||||
let path_ptr: c_int = varargs.get(ctx);
|
||||
let buf_ptr: c_int = varargs.get(ctx);
|
||||
let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const libc::c_char;
|
||||
let buf = emscripten_memory_pointer!(ctx.memory(0), buf_ptr) as *mut libc::c_void;
|
||||
let result = unsafe { lstat64(path, buf as _) };
|
||||
debug!(
|
||||
"=> path: {}, buf: {} = fd: {}\npath: {}\nlast os error: {}",
|
||||
path_ptr,
|
||||
buf_ptr,
|
||||
result,
|
||||
unsafe { std::ffi::CStr::from_ptr(path).to_str().unwrap() },
|
||||
Error::last_os_error(),
|
||||
);
|
||||
result
|
||||
}
|
||||
|
||||
/// lchown
|
||||
pub fn ___syscall198(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall198 (lchown) {}", _which);
|
||||
let path: c_int = varargs.get(ctx);
|
||||
let uid: libc::uid_t = varargs.get(ctx);
|
||||
let gid: libc::gid_t = varargs.get(ctx);
|
||||
let path_ptr = emscripten_memory_pointer!(ctx.memory(0), path) as *const i8;
|
||||
let result = unsafe { libc::lchown(path_ptr, uid, gid) };
|
||||
debug!(
|
||||
"=> path: {}, uid: {}, gid: {}, result: {}",
|
||||
unsafe { std::ffi::CStr::from_ptr(path_ptr).to_str().unwrap() },
|
||||
uid,
|
||||
gid,
|
||||
result,
|
||||
);
|
||||
result
|
||||
}
|
||||
|
||||
/// getgid
|
||||
pub fn ___syscall200(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::___syscall200 (getgid)");
|
||||
unsafe { libc::getgid() as i32 }
|
||||
}
|
||||
|
||||
/// getgid
|
||||
pub fn ___syscall201(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::___syscall201 (getgid)");
|
||||
@ -94,6 +255,32 @@ pub fn ___syscall202(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
}
|
||||
}
|
||||
|
||||
/// fchown
|
||||
pub fn ___syscall207(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall207 (fchown) {}", _which);
|
||||
let fd: c_int = varargs.get(ctx);
|
||||
let owner: libc::uid_t = varargs.get(ctx);
|
||||
let group: libc::gid_t = varargs.get(ctx);
|
||||
unsafe { libc::fchown(fd, owner, group) }
|
||||
}
|
||||
|
||||
/// getgroups
|
||||
pub fn ___syscall205(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall205 (getgroups) {}", _which);
|
||||
let ngroups_max: c_int = varargs.get(ctx);
|
||||
let groups: c_int = varargs.get(ctx);
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let gid_ptr = emscripten_memory_pointer!(ctx.memory(0), groups) as *mut libc::gid_t;
|
||||
assert_eq!(4, std::mem::align_of_val(&gid_ptr));
|
||||
let result = unsafe { libc::getgroups(ngroups_max, gid_ptr) };
|
||||
debug!(
|
||||
"=> ngroups_max: {}, gid_ptr: {:?}, result: {}",
|
||||
ngroups_max, gid_ptr, result,
|
||||
);
|
||||
result
|
||||
}
|
||||
|
||||
/// chown
|
||||
pub fn ___syscall212(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall212 (chown) {}", _which);
|
||||
@ -106,3 +293,33 @@ pub fn ___syscall212(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in
|
||||
|
||||
unsafe { libc::chown(pathname_addr, owner, group) }
|
||||
}
|
||||
|
||||
/// madvise
|
||||
pub fn ___syscall219(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall212 (chown) {}", _which);
|
||||
|
||||
let addr_ptr: c_int = varargs.get(ctx);
|
||||
let len: usize = varargs.get(ctx);
|
||||
let advice: c_int = varargs.get(ctx);
|
||||
|
||||
let addr = emscripten_memory_pointer!(ctx.memory(0), addr_ptr) as *mut libc::c_void;
|
||||
|
||||
unsafe { madvise(addr, len, advice) }
|
||||
}
|
||||
|
||||
/// fallocate
|
||||
pub fn ___syscall324(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall324 (fallocate) {}", _which);
|
||||
let _fd: c_int = varargs.get(ctx);
|
||||
let _mode: c_int = varargs.get(ctx);
|
||||
let _offset: libc::off_t = varargs.get(ctx);
|
||||
let _len: libc::off_t = varargs.get(ctx);
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
unsafe {
|
||||
fallocate(_fd, _mode, _offset, _len)
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,18 @@ pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
}
|
||||
}
|
||||
|
||||
/// link
|
||||
pub fn ___syscall9(_ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall9 (link) {}", _which);
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// ftruncate64
|
||||
pub fn ___syscall194(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::___syscall194 - stub");
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
// chown
|
||||
pub fn ___syscall212(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall212 (chown) {}", which);
|
||||
@ -66,6 +78,18 @@ pub fn ___syscall212(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_i
|
||||
-1
|
||||
}
|
||||
|
||||
/// access
|
||||
pub fn ___syscall33(_ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall33 (access) {}", _which);
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// nice
|
||||
pub fn ___syscall34(_ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall34 (nice) {}", _which);
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
// mkdir
|
||||
pub fn ___syscall39(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall39 (mkdir) {}", which);
|
||||
@ -76,6 +100,36 @@ pub fn ___syscall39(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int
|
||||
unsafe { mkdir(pathname_addr) }
|
||||
}
|
||||
|
||||
/// 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!()
|
||||
}
|
||||
|
||||
/// lchown
|
||||
pub fn ___syscall198(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall198 (lchown) {}", _which);
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// getgid
|
||||
pub fn ___syscall200(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::___syscall200 (getgid)");
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
// getgid
|
||||
pub fn ___syscall201(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::___syscall201 (getgid)");
|
||||
@ -89,6 +143,18 @@ pub fn ___syscall202(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
-1
|
||||
}
|
||||
|
||||
/// 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!()
|
||||
}
|
||||
|
||||
/// dup3
|
||||
pub fn ___syscall330(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> pid_t {
|
||||
debug!("emscripten::___syscall330 (dup3)");
|
||||
@ -103,6 +169,12 @@ pub fn ___syscall54(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_in
|
||||
-1
|
||||
}
|
||||
|
||||
/// fchmod
|
||||
pub fn ___syscall94(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall118 (fchmod) {}", _which);
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
// socketcall
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
pub fn ___syscall102(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
|
||||
@ -112,6 +184,12 @@ pub fn ___syscall102(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_i
|
||||
-1
|
||||
}
|
||||
|
||||
/// fsync
|
||||
pub fn ___syscall118(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall118 (fsync) {}", _which);
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
// pread
|
||||
pub fn ___syscall180(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall180 (pread) {}", which);
|
||||
@ -144,6 +222,12 @@ pub fn ___syscall142(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_i
|
||||
-1
|
||||
}
|
||||
|
||||
/// fdatasync
|
||||
pub fn ___syscall148(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall148 (fdatasync) {}", _which);
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
// setpgid
|
||||
pub fn ___syscall57(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall57 (setpgid) {}", which);
|
||||
@ -160,3 +244,21 @@ pub fn ___syscall122(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_i
|
||||
let _ = which;
|
||||
-1
|
||||
}
|
||||
|
||||
/// lstat64
|
||||
pub fn ___syscall196(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::___syscall196 (lstat64) - stub");
|
||||
-1
|
||||
}
|
||||
|
||||
/// fchown
|
||||
pub fn ___syscall207(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall207 (fchown) {}", _which);
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// fallocate
|
||||
pub fn ___syscall324(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall324 (fallocate) {}", _which);
|
||||
unimplemented!()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user