Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add many emscripten functions for PHP #285

Merged
merged 10 commits into from
Mar 25, 2019
121 changes: 121 additions & 0 deletions lib/emscripten/src/emscripten_target.rs
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -171,6 +188,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,
Expand All @@ -183,6 +204,37 @@ 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_dii(_ctx: &mut Ctx, _index: i32) {
debug!("emscripten::nullFunc_dii");
Expand Down Expand Up @@ -287,6 +339,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 {
Expand Down Expand Up @@ -573,3 +686,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");
}
}
13 changes: 13 additions & 0 deletions lib/emscripten/src/exec.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::varargs::VarArgs;
use libc::execvp as libc_execvp;
use std::cell::Cell;
use std::ffi::CString;
Expand Down Expand Up @@ -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
}
44 changes: 44 additions & 0 deletions lib/emscripten/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,47 @@ 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!()
}

/// getpwuid
pub fn getpwuid(_ctx: &mut Ctx, _uid: i32) -> i32 {
debug!("emscripten::getpwuid");
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!()
}
9 changes: 8 additions & 1 deletion lib/emscripten/src/io/unix.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use libc::printf as _printf;
use libc::{chroot as _chroot, printf as _printf};

use wasmer_runtime_core::vm::Ctx;

Expand All @@ -15,3 +15,10 @@ 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) }
}
6 changes: 6 additions & 0 deletions lib/emscripten/src/io/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ 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!()
}
Loading