Move Webassembly objects to Store and remove Context

Co-authored-by: ptitSeb <sebastien.chev@gmail.com>
Co-authored-by: Manos Pitsidianakis <manos@wasmer.io>
This commit is contained in:
Syrus Akbary
2022-07-08 15:33:29 -07:00
committed by Manos Pitsidianakis
parent b5ae6399ce
commit a419ccdf52
214 changed files with 5800 additions and 5759 deletions

View File

@@ -1,9 +1,9 @@
use crate::emscripten_target;
use crate::EmEnv;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
///emscripten: _llvm_bswap_i64
pub fn _llvm_bswap_i64(ctx: ContextMut<'_, EmEnv>, _low: i32, high: i32) -> i32 {
pub fn _llvm_bswap_i64(ctx: FunctionEnvMut<EmEnv>, _low: i32, high: i32) -> i32 {
debug!("emscripten::_llvm_bswap_i64");
emscripten_target::setTempRet0(ctx, _low.swap_bytes());
high.swap_bytes()

View File

@@ -4,33 +4,33 @@ use crate::env::{get_emscripten_data, get_emscripten_funcs};
use crate::EmEnv;
#[cfg(target_os = "linux")]
use libc::getdtablesize;
use wasmer::{AsContextMut, ContextMut};
use wasmer::FunctionEnvMut;
pub fn asm_const_i(_ctx: ContextMut<'_, EmEnv>, _val: i32) -> i32 {
pub fn asm_const_i(_ctx: FunctionEnvMut<EmEnv>, _val: i32) -> i32 {
debug!("emscripten::asm_const_i: {}", _val);
0
}
pub fn exit_with_live_runtime(_ctx: ContextMut<'_, EmEnv>) {
pub fn exit_with_live_runtime(_ctx: FunctionEnvMut<EmEnv>) {
debug!("emscripten::exit_with_live_runtime");
}
pub fn setTempRet0(ctx: ContextMut<'_, EmEnv>, val: i32) {
pub fn setTempRet0(ctx: FunctionEnvMut<EmEnv>, val: i32) {
trace!("emscripten::setTempRet0: {}", val);
get_emscripten_data(&ctx).as_mut().unwrap().temp_ret_0 = val;
}
pub fn getTempRet0(ctx: ContextMut<'_, EmEnv>) -> i32 {
pub fn getTempRet0(ctx: FunctionEnvMut<EmEnv>) -> i32 {
trace!("emscripten::getTempRet0");
get_emscripten_data(&ctx).as_ref().unwrap().temp_ret_0
}
pub fn _alarm(_ctx: ContextMut<'_, EmEnv>, _seconds: u32) -> i32 {
pub fn _alarm(_ctx: FunctionEnvMut<EmEnv>, _seconds: u32) -> i32 {
debug!("emscripten::_alarm({})", _seconds);
0
}
pub fn _atexit(_ctx: ContextMut<'_, EmEnv>, _func: i32) -> i32 {
pub fn _atexit(_ctx: FunctionEnvMut<EmEnv>, _func: i32) -> i32 {
debug!("emscripten::_atexit");
// TODO: implement atexit properly
// __ATEXIT__.unshift({
@@ -39,38 +39,38 @@ pub fn _atexit(_ctx: ContextMut<'_, EmEnv>, _func: i32) -> i32 {
// });
0
}
pub fn __Unwind_Backtrace(_ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn __Unwind_Backtrace(_ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
debug!("emscripten::__Unwind_Backtrace");
0
}
pub fn __Unwind_FindEnclosingFunction(_ctx: ContextMut<'_, EmEnv>, _a: i32) -> i32 {
pub fn __Unwind_FindEnclosingFunction(_ctx: FunctionEnvMut<EmEnv>, _a: i32) -> i32 {
debug!("emscripten::__Unwind_FindEnclosingFunction");
0
}
pub fn __Unwind_GetIPInfo(_ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn __Unwind_GetIPInfo(_ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
debug!("emscripten::__Unwind_GetIPInfo");
0
}
pub fn ___cxa_find_matching_catch_2(_ctx: ContextMut<'_, EmEnv>) -> i32 {
pub fn ___cxa_find_matching_catch_2(_ctx: FunctionEnvMut<EmEnv>) -> i32 {
debug!("emscripten::___cxa_find_matching_catch_2");
0
}
pub fn ___cxa_find_matching_catch_3(_ctx: ContextMut<'_, EmEnv>, _a: i32) -> i32 {
pub fn ___cxa_find_matching_catch_3(_ctx: FunctionEnvMut<EmEnv>, _a: i32) -> i32 {
debug!("emscripten::___cxa_find_matching_catch_3");
0
}
pub fn ___cxa_free_exception(_ctx: ContextMut<'_, EmEnv>, _a: i32) {
pub fn ___cxa_free_exception(_ctx: FunctionEnvMut<EmEnv>, _a: i32) {
debug!("emscripten::___cxa_free_exception");
}
pub fn ___resumeException(_ctx: ContextMut<'_, EmEnv>, _a: i32) {
pub fn ___resumeException(_ctx: FunctionEnvMut<EmEnv>, _a: i32) {
debug!("emscripten::___resumeException");
}
pub fn _dladdr(_ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn _dladdr(_ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_dladdr");
0
}
pub fn ___gxx_personality_v0(
_ctx: ContextMut<'_, EmEnv>,
_ctx: FunctionEnvMut<EmEnv>,
_a: i32,
_b: i32,
_c: i32,
@@ -83,25 +83,25 @@ pub fn ___gxx_personality_v0(
}
#[cfg(target_os = "linux")]
pub fn _getdtablesize(_ctx: ContextMut<'_, EmEnv>) -> i32 {
pub fn _getdtablesize(_ctx: FunctionEnvMut<EmEnv>) -> i32 {
debug!("emscripten::getdtablesize");
unsafe { getdtablesize() }
}
#[cfg(not(target_os = "linux"))]
pub fn _getdtablesize(_ctx: ContextMut<'_, EmEnv>) -> i32 {
pub fn _getdtablesize(_ctx: FunctionEnvMut<EmEnv>) -> i32 {
debug!("emscripten::getdtablesize");
-1
}
pub fn _gethostbyaddr(_ctx: ContextMut<'_, EmEnv>, _addr: i32, _addrlen: i32, _atype: i32) -> i32 {
pub fn _gethostbyaddr(_ctx: FunctionEnvMut<EmEnv>, _addr: i32, _addrlen: i32, _atype: i32) -> i32 {
debug!("emscripten::gethostbyaddr");
0
}
pub fn _gethostbyname(_ctx: ContextMut<'_, EmEnv>, _name: i32) -> i32 {
pub fn _gethostbyname(_ctx: FunctionEnvMut<EmEnv>, _name: i32) -> i32 {
debug!("emscripten::gethostbyname_r");
0
}
pub fn _gethostbyname_r(
_ctx: ContextMut<'_, EmEnv>,
_ctx: FunctionEnvMut<EmEnv>,
_name: i32,
_ret: i32,
_buf: i32,
@@ -113,13 +113,13 @@ pub fn _gethostbyname_r(
0
}
// NOTE: php.js has proper impl; libc has proper impl for linux
pub fn _getloadavg(_ctx: ContextMut<'_, EmEnv>, _loadavg: i32, _nelem: i32) -> i32 {
pub fn _getloadavg(_ctx: FunctionEnvMut<EmEnv>, _loadavg: i32, _nelem: i32) -> i32 {
debug!("emscripten::getloadavg");
0
}
#[allow(clippy::too_many_arguments)]
pub fn _getnameinfo(
_ctx: ContextMut<'_, EmEnv>,
_ctx: FunctionEnvMut<EmEnv>,
_addr: i32,
_addrlen: i32,
_host: i32,
@@ -142,7 +142,7 @@ pub fn _getnameinfo(
macro_rules! invoke {
($ctx: ident, $name:ident, $name_ref:ident, $( $arg:ident ),*) => {{
let funcs = get_emscripten_funcs(&$ctx).clone();
let sp = funcs.stack_save_ref().expect("stack_save is None").call(&mut $ctx.as_context_mut()).expect("stack_save call failed");
let sp = funcs.stack_save_ref().expect("stack_save is None").call(&mut $ctx).expect("stack_save call failed");
let call = funcs.$name_ref().expect(concat!("Dynamic call is None: ", stringify!($name))).clone();
match call.call(&mut $ctx, $($arg),*) {
Ok(v) => v,
@@ -183,50 +183,50 @@ macro_rules! invoke_no_stack_save {
let funcs = get_emscripten_funcs(&$ctx).clone();
let call = funcs.$name_ref().expect(concat!(stringify!($name), " is set to None")).clone();
call.call(&mut $ctx.as_context_mut(), $($arg),*).unwrap()
call.call(&mut $ctx, $($arg),*).unwrap()
}}
}
// Invoke functions
pub fn invoke_i(mut ctx: ContextMut<'_, EmEnv>, index: i32) -> i32 {
pub fn invoke_i(mut ctx: FunctionEnvMut<EmEnv>, index: i32) -> i32 {
debug!("emscripten::invoke_i");
invoke!(ctx, dyn_call_i, dyn_call_i_ref, index)
}
pub fn invoke_ii(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32) -> i32 {
pub fn invoke_ii(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32) -> i32 {
debug!("emscripten::invoke_ii");
invoke!(ctx, dyn_call_ii, dyn_call_ii_ref, index, a1)
}
pub fn invoke_iii(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32, a2: i32) -> i32 {
pub fn invoke_iii(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32, a2: i32) -> i32 {
debug!("emscripten::invoke_iii");
invoke!(ctx, dyn_call_iii, dyn_call_iii_ref, index, a1, a2)
}
pub fn invoke_iiii(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32, a2: i32, a3: i32) -> i32 {
pub fn invoke_iiii(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32, a2: i32, a3: i32) -> i32 {
debug!("emscripten::invoke_iiii");
invoke!(ctx, dyn_call_iiii, dyn_call_iiii_ref, index, a1, a2, a3)
}
pub fn invoke_iifi(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32, a2: f64, a3: i32) -> i32 {
pub fn invoke_iifi(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32, a2: f64, a3: i32) -> i32 {
debug!("emscripten::invoke_iifi");
invoke!(ctx, dyn_call_iifi, dyn_call_iifi_ref, index, a1, a2, a3)
}
pub fn invoke_v(mut ctx: ContextMut<'_, EmEnv>, index: i32) {
pub fn invoke_v(mut ctx: FunctionEnvMut<EmEnv>, index: i32) {
debug!("emscripten::invoke_v");
invoke_no_return!(ctx, dyn_call_v, dyn_call_v_ref, index);
}
pub fn invoke_vi(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32) {
pub fn invoke_vi(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32) {
debug!("emscripten::invoke_vi");
invoke_no_return!(ctx, dyn_call_vi, dyn_call_vi_ref, index, a1);
}
pub fn invoke_vii(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32, a2: i32) {
pub fn invoke_vii(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32, a2: i32) {
debug!("emscripten::invoke_vii");
invoke_no_return!(ctx, dyn_call_vii, dyn_call_vii_ref, index, a1, a2);
}
pub fn invoke_viii(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32, a2: i32, a3: i32) {
pub fn invoke_viii(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32, a2: i32, a3: i32) {
debug!("emscripten::invoke_viii");
invoke_no_return!(ctx, dyn_call_viii, dyn_call_viii_ref, index, a1, a2, a3);
}
pub fn invoke_viiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -245,12 +245,12 @@ pub fn invoke_viiii(
a4
);
}
pub fn invoke_dii(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32, a2: i32) -> f64 {
pub fn invoke_dii(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32, a2: i32) -> f64 {
debug!("emscripten::invoke_dii");
invoke!(ctx, dyn_call_dii, dyn_call_dii_ref, index, a1, a2)
}
pub fn invoke_diiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -270,7 +270,7 @@ pub fn invoke_diiii(
)
}
pub fn invoke_iiiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -290,7 +290,7 @@ pub fn invoke_iiiii(
)
}
pub fn invoke_iiiiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -313,7 +313,7 @@ pub fn invoke_iiiiii(
}
#[allow(clippy::too_many_arguments)]
pub fn invoke_iiiiiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -338,7 +338,7 @@ pub fn invoke_iiiiiii(
}
#[allow(clippy::too_many_arguments)]
pub fn invoke_iiiiiiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -365,7 +365,7 @@ pub fn invoke_iiiiiiii(
}
#[allow(clippy::too_many_arguments)]
pub fn invoke_iiiiiiiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -394,7 +394,7 @@ pub fn invoke_iiiiiiiii(
}
#[allow(clippy::too_many_arguments)]
pub fn invoke_iiiiiiiiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -425,7 +425,7 @@ pub fn invoke_iiiiiiiiii(
}
#[allow(clippy::too_many_arguments)]
pub fn invoke_iiiiiiiiiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -456,12 +456,12 @@ pub fn invoke_iiiiiiiiiii(
a10
)
}
pub fn invoke_vd(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: f64) {
pub fn invoke_vd(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: f64) {
debug!("emscripten::invoke_vd");
invoke_no_return!(ctx, dyn_call_vd, dyn_call_vd_ref, index, a1)
}
pub fn invoke_viiiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -484,7 +484,7 @@ pub fn invoke_viiiii(
}
#[allow(clippy::too_many_arguments)]
pub fn invoke_viiiiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -509,7 +509,7 @@ pub fn invoke_viiiiii(
}
#[allow(clippy::too_many_arguments)]
pub fn invoke_viiiiiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -536,7 +536,7 @@ pub fn invoke_viiiiiii(
}
#[allow(clippy::too_many_arguments)]
pub fn invoke_viiiiiiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -565,7 +565,7 @@ pub fn invoke_viiiiiiii(
}
#[allow(clippy::too_many_arguments)]
pub fn invoke_viiiiiiiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -596,7 +596,7 @@ pub fn invoke_viiiiiiiii(
}
#[allow(clippy::too_many_arguments)]
pub fn invoke_viiiiiiiiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -628,18 +628,18 @@ pub fn invoke_viiiiiiiiii(
)
}
pub fn invoke_iij(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32, a2: i32, a3: i32) -> i32 {
pub fn invoke_iij(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32, a2: i32, a3: i32) -> i32 {
debug!("emscripten::invoke_iij");
invoke!(ctx, dyn_call_iij, dyn_call_iij_ref, index, a1, a2, a3)
}
pub fn invoke_iji(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32, a2: i32, a3: i32) -> i32 {
pub fn invoke_iji(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32, a2: i32, a3: i32) -> i32 {
debug!("emscripten::invoke_iji");
invoke!(ctx, dyn_call_iji, dyn_call_iji_ref, index, a1, a2, a3)
}
pub fn invoke_iiji(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -652,7 +652,7 @@ pub fn invoke_iiji(
#[allow(clippy::too_many_arguments)]
pub fn invoke_iiijj(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -675,25 +675,25 @@ pub fn invoke_iiijj(
a6
)
}
pub fn invoke_j(mut ctx: ContextMut<'_, EmEnv>, index: i32) -> i32 {
pub fn invoke_j(mut ctx: FunctionEnvMut<EmEnv>, index: i32) -> i32 {
debug!("emscripten::invoke_j");
invoke_no_stack_save!(ctx, dyn_call_j, dyn_call_j_ref, index)
}
pub fn invoke_ji(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32) -> i32 {
pub fn invoke_ji(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32) -> i32 {
debug!("emscripten::invoke_ji");
invoke_no_stack_save!(ctx, dyn_call_ji, dyn_call_ji_ref, index, a1)
}
pub fn invoke_jii(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32, a2: i32) -> i32 {
pub fn invoke_jii(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32, a2: i32) -> i32 {
debug!("emscripten::invoke_jii");
invoke_no_stack_save!(ctx, dyn_call_jii, dyn_call_jii_ref, index, a1, a2)
}
pub fn invoke_jij(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32, a2: i32, a3: i32) -> i32 {
pub fn invoke_jij(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32, a2: i32, a3: i32) -> i32 {
debug!("emscripten::invoke_jij");
invoke_no_stack_save!(ctx, dyn_call_jij, dyn_call_jij_ref, index, a1, a2, a3)
}
pub fn invoke_jjj(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -704,7 +704,7 @@ pub fn invoke_jjj(
invoke_no_stack_save!(ctx, dyn_call_jjj, dyn_call_jjj_ref, index, a1, a2, a3, a4)
}
pub fn invoke_viiij(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -727,7 +727,7 @@ pub fn invoke_viiij(
}
#[allow(clippy::too_many_arguments)]
pub fn invoke_viiijiiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -758,7 +758,7 @@ pub fn invoke_viiijiiii(
}
#[allow(clippy::too_many_arguments)]
pub fn invoke_viiijiiiiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -791,12 +791,12 @@ pub fn invoke_viiijiiiiii(
a11
)
}
pub fn invoke_viij(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) {
pub fn invoke_viij(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) {
debug!("emscripten::invoke_viij");
invoke_no_stack_save!(ctx, dyn_call_viij, dyn_call_viij_ref, index, a1, a2, a3, a4)
}
pub fn invoke_viiji(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -819,7 +819,7 @@ pub fn invoke_viiji(
}
#[allow(clippy::too_many_arguments)]
pub fn invoke_viijiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -846,7 +846,7 @@ pub fn invoke_viijiii(
}
#[allow(clippy::too_many_arguments)]
pub fn invoke_viijj(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -869,12 +869,12 @@ pub fn invoke_viijj(
a6
)
}
pub fn invoke_vj(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32, a2: i32) {
pub fn invoke_vj(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32, a2: i32) {
debug!("emscripten::invoke_vj");
invoke_no_stack_save!(ctx, dyn_call_vj, dyn_call_vj_ref, index, a1, a2)
}
pub fn invoke_vjji(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -895,17 +895,17 @@ pub fn invoke_vjji(
a5
)
}
pub fn invoke_vij(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32, a2: i32, a3: i32) {
pub fn invoke_vij(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32, a2: i32, a3: i32) {
debug!("emscripten::invoke_vij");
invoke_no_stack_save!(ctx, dyn_call_vij, dyn_call_vij_ref, index, a1, a2, a3)
}
pub fn invoke_viji(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) {
pub fn invoke_viji(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32, a2: i32, a3: i32, a4: i32) {
debug!("emscripten::invoke_viji");
invoke_no_stack_save!(ctx, dyn_call_viji, dyn_call_viji_ref, index, a1, a2, a3, a4)
}
#[allow(clippy::too_many_arguments)]
pub fn invoke_vijiii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -929,7 +929,7 @@ pub fn invoke_vijiii(
)
}
pub fn invoke_vijj(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -950,16 +950,16 @@ pub fn invoke_vijj(
a5
)
}
pub fn invoke_vidd(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32, a2: f64, a3: f64) {
pub fn invoke_vidd(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32, a2: f64, a3: f64) {
debug!("emscripten::invoke_viid");
invoke_no_return!(ctx, dyn_call_vidd, dyn_call_vidd_ref, index, a1, a2, a3);
}
pub fn invoke_viid(mut ctx: ContextMut<'_, EmEnv>, index: i32, a1: i32, a2: i32, a3: f64) {
pub fn invoke_viid(mut ctx: FunctionEnvMut<EmEnv>, index: i32, a1: i32, a2: i32, a3: f64) {
debug!("emscripten::invoke_viid");
invoke_no_return!(ctx, dyn_call_viid, dyn_call_viid_ref, index, a1, a2, a3);
}
pub fn invoke_viidii(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,
@@ -982,7 +982,7 @@ pub fn invoke_viidii(
}
#[allow(clippy::too_many_arguments)]
pub fn invoke_viidddddddd(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
index: i32,
a1: i32,
a2: i32,

View File

@@ -19,65 +19,68 @@ use std::sync::MutexGuard;
use crate::EmEnv;
use wasmer::ValueType;
use wasmer::{AsContextMut, ContextMut, WasmPtr};
use wasmer::{FunctionEnvMut, WasmPtr};
pub fn call_malloc(mut ctx: ContextMut<'_, EmEnv>, size: u32) -> u32 {
let malloc_ref = get_emscripten_funcs(&ctx).malloc_ref().unwrap().clone();
malloc_ref.call(&mut ctx.as_context_mut(), size).unwrap()
pub fn call_malloc(mut ctx: &mut FunctionEnvMut<EmEnv>, size: u32) -> u32 {
let malloc_ref = get_emscripten_funcs(ctx).malloc_ref().unwrap().clone();
malloc_ref.call(&mut ctx, size).unwrap()
}
#[warn(dead_code)]
pub fn call_malloc_with_cast<T: Copy>(ctx: ContextMut<'_, EmEnv>, size: u32) -> WasmPtr<T> {
pub fn call_malloc_with_cast<T: Copy>(ctx: &mut FunctionEnvMut<EmEnv>, size: u32) -> WasmPtr<T> {
WasmPtr::new(call_malloc(ctx, size))
}
pub fn call_memalign(mut ctx: ContextMut<'_, EmEnv>, alignment: u32, size: u32) -> u32 {
let memalign_ref = get_emscripten_funcs(&ctx).memalign_ref().unwrap().clone();
pub fn call_memalign(mut ctx: &mut FunctionEnvMut<EmEnv>, alignment: u32, size: u32) -> u32 {
let memalign_ref = get_emscripten_funcs(ctx).memalign_ref().unwrap().clone();
memalign_ref.call(&mut ctx, alignment, size).unwrap()
}
pub fn call_memset(mut ctx: ContextMut<'_, EmEnv>, pointer: u32, value: u32, size: u32) -> u32 {
let memset_ref = get_emscripten_funcs(&ctx).memset_ref().unwrap().clone();
memset_ref
.call(&mut ctx.as_context_mut(), pointer, value, size)
.unwrap()
pub fn call_memset(
mut ctx: &mut FunctionEnvMut<EmEnv>,
pointer: u32,
value: u32,
size: u32,
) -> u32 {
let memset_ref = get_emscripten_funcs(ctx).memset_ref().unwrap().clone();
memset_ref.call(&mut ctx, pointer, value, size).unwrap()
}
pub(crate) fn get_emscripten_data<'a>(
ctx: &'a ContextMut<'_, EmEnv>,
ctx: &'a FunctionEnvMut<EmEnv>,
) -> MutexGuard<'a, Option<EmscriptenData>> {
ctx.data().data.lock().unwrap()
}
pub(crate) fn get_emscripten_funcs<'a>(
ctx: &'a ContextMut<'_, EmEnv>,
ctx: &'a FunctionEnvMut<EmEnv>,
) -> MutexGuard<'a, EmscriptenFunctions> {
ctx.data().funcs.lock().unwrap()
}
pub fn _getpagesize(_ctx: ContextMut<'_, EmEnv>) -> u32 {
pub fn _getpagesize(_ctx: FunctionEnvMut<EmEnv>) -> u32 {
debug!("emscripten::_getpagesize");
16384
}
pub fn _times(ctx: ContextMut<'_, EmEnv>, buffer: u32) -> u32 {
pub fn _times(mut ctx: FunctionEnvMut<EmEnv>, buffer: u32) -> u32 {
if buffer != 0 {
call_memset(ctx, buffer, 0, 16);
call_memset(&mut ctx, buffer, 0, 16);
}
0
}
#[allow(clippy::cast_ptr_alignment)]
pub fn ___build_environment(mut ctx: ContextMut<'_, EmEnv>, environ: c_int) {
pub fn ___build_environment(mut ctx: FunctionEnvMut<EmEnv>, environ: c_int) {
debug!("emscripten::___build_environment {}", environ);
const MAX_ENV_VALUES: u32 = 64;
const TOTAL_ENV_SIZE: u32 = 1024;
let environment = emscripten_memory_pointer!(ctx, ctx.data().memory(0), environ) as *mut c_int;
let (mut pool_offset, env_ptr, mut pool_ptr) = unsafe {
let (pool_offset, _pool_slice): (u32, &mut [u8]) =
allocate_on_stack(&mut ctx.as_context_mut(), TOTAL_ENV_SIZE as u32);
allocate_on_stack(&mut ctx, TOTAL_ENV_SIZE as u32);
let (env_offset, _env_slice): (u32, &mut [u8]) =
allocate_on_stack(&mut ctx.as_context_mut(), (MAX_ENV_VALUES * 4) as u32);
allocate_on_stack(&mut ctx, (MAX_ENV_VALUES * 4) as u32);
let env_ptr =
emscripten_memory_pointer!(ctx, ctx.data().memory(0), env_offset) as *mut c_int;
let pool_ptr =
@@ -122,13 +125,13 @@ pub fn ___build_environment(mut ctx: ContextMut<'_, EmEnv>, environ: c_int) {
}
}
pub fn ___assert_fail(_ctx: ContextMut<'_, EmEnv>, _a: c_int, _b: c_int, _c: c_int, _d: c_int) {
pub fn ___assert_fail(_ctx: FunctionEnvMut<EmEnv>, _a: c_int, _b: c_int, _c: c_int, _d: c_int) {
debug!("emscripten::___assert_fail {} {} {} {}", _a, _b, _c, _d);
// TODO: Implement like emscripten expects regarding memory/page size
// TODO raise an error
}
pub fn _pathconf(ctx: ContextMut<'_, EmEnv>, path_addr: c_int, name: c_int) -> c_int {
pub fn _pathconf(ctx: FunctionEnvMut<EmEnv>, path_addr: c_int, name: c_int) -> c_int {
debug!(
"emscripten::_pathconf {} {} - UNIMPLEMENTED",
path_addr, name
@@ -149,7 +152,7 @@ pub fn _pathconf(ctx: ContextMut<'_, EmEnv>, path_addr: c_int, name: c_int) -> c
}
}
pub fn _fpathconf(_ctx: ContextMut<'_, EmEnv>, _fildes: c_int, name: c_int) -> c_int {
pub fn _fpathconf(_ctx: FunctionEnvMut<EmEnv>, _fildes: c_int, name: c_int) -> c_int {
debug!("emscripten::_fpathconf {} {}", _fildes, name);
match name {
0 => 32000,

View File

@@ -10,11 +10,11 @@ use std::os::raw::c_char;
use crate::env::{call_malloc, call_malloc_with_cast, EmAddrInfo, EmSockAddr};
use crate::utils::{copy_cstr_into_wasm, copy_terminated_array_of_cstrs};
use crate::EmEnv;
use wasmer::{AsContextMut, ContextMut, WasmPtr};
use wasmer::{FunctionEnvMut, WasmPtr};
// #[no_mangle]
/// emscripten: _getenv // (name: *const char) -> *const c_char;
pub fn _getenv(ctx: ContextMut<'_, EmEnv>, name: i32) -> u32 {
pub fn _getenv(mut ctx: FunctionEnvMut<EmEnv>, name: i32) -> u32 {
debug!("emscripten::_getenv");
let name_addr = emscripten_memory_pointer!(ctx, ctx.data().memory(0), name) as *const c_char;
@@ -26,11 +26,11 @@ pub fn _getenv(ctx: ContextMut<'_, EmEnv>, name: i32) -> u32 {
return 0;
}
unsafe { copy_cstr_into_wasm(ctx, c_str) }
unsafe { copy_cstr_into_wasm(&mut ctx, c_str) }
}
/// emscripten: _setenv // (name: *const char, name: *const value, overwrite: int);
pub fn _setenv(ctx: ContextMut<'_, EmEnv>, name: c_int, value: c_int, overwrite: c_int) -> c_int {
pub fn _setenv(ctx: FunctionEnvMut<EmEnv>, name: c_int, value: c_int, overwrite: c_int) -> c_int {
debug!("emscripten::_setenv");
let name_addr = emscripten_memory_pointer!(ctx, ctx.data().memory(0), name) as *const c_char;
@@ -43,7 +43,7 @@ pub fn _setenv(ctx: ContextMut<'_, EmEnv>, name: c_int, value: c_int, overwrite:
}
/// emscripten: _putenv // (name: *const char);
pub fn _putenv(ctx: ContextMut<'_, EmEnv>, name: c_int) -> c_int {
pub fn _putenv(ctx: FunctionEnvMut<EmEnv>, name: c_int) -> c_int {
debug!("emscripten::_putenv");
let name_addr = emscripten_memory_pointer!(ctx, ctx.data().memory(0), name) as *const c_char;
@@ -54,7 +54,7 @@ pub fn _putenv(ctx: ContextMut<'_, EmEnv>, name: c_int) -> c_int {
}
/// emscripten: _unsetenv // (name: *const char);
pub fn _unsetenv(ctx: ContextMut<'_, EmEnv>, name: c_int) -> c_int {
pub fn _unsetenv(ctx: FunctionEnvMut<EmEnv>, name: c_int) -> c_int {
debug!("emscripten::_unsetenv");
let name_addr = emscripten_memory_pointer!(ctx, ctx.data().memory(0), name) as *const c_char;
@@ -65,7 +65,7 @@ pub fn _unsetenv(ctx: ContextMut<'_, EmEnv>, name: c_int) -> c_int {
}
#[allow(clippy::cast_ptr_alignment)]
pub fn _getpwnam(mut ctx: ContextMut<'_, EmEnv>, name_ptr: c_int) -> c_int {
pub fn _getpwnam(mut ctx: FunctionEnvMut<EmEnv>, name_ptr: c_int) -> c_int {
debug!("emscripten::_getpwnam {}", name_ptr);
#[cfg(feature = "debug")]
let _ = name_ptr;
@@ -89,18 +89,16 @@ pub fn _getpwnam(mut ctx: ContextMut<'_, EmEnv>, name_ptr: c_int) -> c_int {
unsafe {
let passwd = &*libc_getpwnam(name.as_ptr());
let passwd_struct_offset =
call_malloc(ctx.as_context_mut(), mem::size_of::<GuestPasswd>() as _);
let passwd_struct_offset = call_malloc(&mut ctx, mem::size_of::<GuestPasswd>() as _);
let memory = ctx.data().memory(0);
let passwd_struct_ptr =
emscripten_memory_pointer!(ctx, memory, passwd_struct_offset) as *mut GuestPasswd;
(*passwd_struct_ptr).pw_name = copy_cstr_into_wasm(ctx.as_context_mut(), passwd.pw_name);
(*passwd_struct_ptr).pw_passwd =
copy_cstr_into_wasm(ctx.as_context_mut(), passwd.pw_passwd);
(*passwd_struct_ptr).pw_gecos = copy_cstr_into_wasm(ctx.as_context_mut(), passwd.pw_gecos);
(*passwd_struct_ptr).pw_dir = copy_cstr_into_wasm(ctx.as_context_mut(), passwd.pw_dir);
(*passwd_struct_ptr).pw_shell = copy_cstr_into_wasm(ctx.as_context_mut(), passwd.pw_shell);
(*passwd_struct_ptr).pw_name = copy_cstr_into_wasm(&mut ctx, passwd.pw_name);
(*passwd_struct_ptr).pw_passwd = copy_cstr_into_wasm(&mut ctx, passwd.pw_passwd);
(*passwd_struct_ptr).pw_gecos = copy_cstr_into_wasm(&mut ctx, passwd.pw_gecos);
(*passwd_struct_ptr).pw_dir = copy_cstr_into_wasm(&mut ctx, passwd.pw_dir);
(*passwd_struct_ptr).pw_shell = copy_cstr_into_wasm(&mut ctx, passwd.pw_shell);
(*passwd_struct_ptr).pw_uid = passwd.pw_uid;
(*passwd_struct_ptr).pw_gid = passwd.pw_gid;
@@ -109,7 +107,7 @@ pub fn _getpwnam(mut ctx: ContextMut<'_, EmEnv>, name_ptr: c_int) -> c_int {
}
#[allow(clippy::cast_ptr_alignment)]
pub fn _getgrnam(mut ctx: ContextMut<'_, EmEnv>, name_ptr: c_int) -> c_int {
pub fn _getgrnam(mut ctx: FunctionEnvMut<EmEnv>, name_ptr: c_int) -> c_int {
debug!("emscripten::_getgrnam {}", name_ptr);
#[repr(C)]
@@ -128,14 +126,13 @@ pub fn _getgrnam(mut ctx: ContextMut<'_, EmEnv>, name_ptr: c_int) -> c_int {
unsafe {
let group = &*libc_getgrnam(name.as_ptr());
let group_struct_offset =
call_malloc(ctx.as_context_mut(), mem::size_of::<GuestGroup>() as _);
let group_struct_offset = call_malloc(&mut ctx, mem::size_of::<GuestGroup>() as _);
let group_struct_ptr =
emscripten_memory_pointer!(ctx, ctx.data().memory(0), group_struct_offset)
as *mut GuestGroup;
(*group_struct_ptr).gr_name = copy_cstr_into_wasm(ctx.as_context_mut(), group.gr_name);
(*group_struct_ptr).gr_passwd = copy_cstr_into_wasm(ctx.as_context_mut(), group.gr_passwd);
(*group_struct_ptr).gr_name = copy_cstr_into_wasm(&mut ctx, group.gr_name);
(*group_struct_ptr).gr_passwd = copy_cstr_into_wasm(&mut ctx, group.gr_passwd);
(*group_struct_ptr).gr_gid = group.gr_gid;
(*group_struct_ptr).gr_mem = copy_terminated_array_of_cstrs(ctx, group.gr_mem);
@@ -143,20 +140,19 @@ pub fn _getgrnam(mut ctx: ContextMut<'_, EmEnv>, name_ptr: c_int) -> c_int {
}
}
pub fn _sysconf(_ctx: ContextMut<'_, EmEnv>, name: c_int) -> i32 {
pub fn _sysconf(_ctx: FunctionEnvMut<EmEnv>, name: c_int) -> i32 {
debug!("emscripten::_sysconf {}", name);
// TODO: Implement like emscripten expects regarding memory/page size
unsafe { sysconf(name) as i32 } // TODO review i64
}
// this may be a memory leak, probably not though because emscripten does the same thing
pub fn _gai_strerror(mut ctx: ContextMut<'_, EmEnv>, ecode: i32) -> i32 {
pub fn _gai_strerror(mut ctx: FunctionEnvMut<EmEnv>, ecode: i32) -> i32 {
debug!("emscripten::_gai_strerror({})", ecode);
let cstr = unsafe { std::ffi::CStr::from_ptr(libc::gai_strerror(ecode)) };
let bytes = cstr.to_bytes_with_nul();
let string_on_guest: WasmPtr<c_char> =
call_malloc_with_cast(ctx.as_context_mut(), bytes.len() as _);
let string_on_guest: WasmPtr<c_char> = call_malloc_with_cast(&mut ctx, bytes.len() as _);
let memory = ctx.data().memory(0);
let writer = string_on_guest
@@ -170,7 +166,7 @@ pub fn _gai_strerror(mut ctx: ContextMut<'_, EmEnv>, ecode: i32) -> i32 {
}
pub fn _getaddrinfo(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
node_ptr: WasmPtr<c_char>,
service_str_ptr: WasmPtr<c_char>,
hints_ptr: WasmPtr<EmAddrInfo>,
@@ -244,7 +240,7 @@ pub fn _getaddrinfo(
while !current_host_node.is_null() {
let current_guest_node_ptr: WasmPtr<EmAddrInfo> =
call_malloc_with_cast(ctx.as_context_mut(), std::mem::size_of::<EmAddrInfo>() as _);
call_malloc_with_cast(&mut ctx, std::mem::size_of::<EmAddrInfo>() as _);
if head_of_list.is_none() {
head_of_list = Some(current_guest_node_ptr);
}
@@ -264,7 +260,7 @@ pub fn _getaddrinfo(
let guest_sockaddr_ptr = {
let host_sockaddr_ptr = (*current_host_node).ai_addr;
let guest_sockaddr_ptr: WasmPtr<EmSockAddr> =
call_malloc_with_cast(ctx.as_context_mut(), host_addrlen as _);
call_malloc_with_cast(&mut ctx, host_addrlen as _);
let derefed_guest_sockaddr = guest_sockaddr_ptr.deref(&ctx, &memory);
let mut gs = derefed_guest_sockaddr.read().unwrap();
@@ -283,7 +279,7 @@ pub fn _getaddrinfo(
let canonname_bytes = canonname_cstr.to_bytes_with_nul();
let str_size = canonname_bytes.len();
let guest_canonname: WasmPtr<c_char> =
call_malloc_with_cast(ctx.as_context_mut(), str_size as _);
call_malloc_with_cast(&mut ctx, str_size as _);
let guest_canonname_writer =
guest_canonname.slice(&ctx, &memory, str_size as _).unwrap();

View File

@@ -8,7 +8,7 @@ use std::os::raw::c_char;
use crate::env::{call_malloc, EmAddrInfo};
use crate::utils::{copy_cstr_into_wasm, read_string_from_wasm};
use crate::EmEnv;
use wasmer::{AsContextMut, ContextMut, WasmPtr};
use wasmer::{FunctionEnvMut, WasmPtr};
extern "C" {
#[link_name = "_putenv"]
@@ -17,24 +17,24 @@ extern "C" {
// #[no_mangle]
/// emscripten: _getenv // (name: *const char) -> *const c_char;
pub fn _getenv(mut ctx: ContextMut<'_, EmEnv>, name: u32) -> u32 {
pub fn _getenv(mut ctx: FunctionEnvMut<EmEnv>, name: u32) -> u32 {
debug!("emscripten::_getenv");
let memory = ctx.data().memory(0);
let name_string = read_string_from_wasm(ctx.as_context_mut(), &memory, name);
let name_string = read_string_from_wasm(ctx.as_mut(), &memory, name);
debug!("=> name({:?})", name_string);
let c_str = unsafe { getenv(name_string.as_ptr() as *const libc::c_char) };
if c_str.is_null() {
return 0;
}
unsafe { copy_cstr_into_wasm(ctx, c_str as *const c_char) }
unsafe { copy_cstr_into_wasm(&mut ctx, c_str as *const c_char) }
}
/// emscripten: _setenv // (name: *const char, name: *const value, overwrite: int);
pub fn _setenv(mut ctx: ContextMut<'_, EmEnv>, name: u32, value: u32, _overwrite: u32) -> c_int {
pub fn _setenv(mut ctx: FunctionEnvMut<EmEnv>, name: u32, value: u32, _overwrite: u32) -> c_int {
debug!("emscripten::_setenv");
let memory = ctx.data().memory(0);
// setenv does not exist on windows, so we hack it with _putenv
let name = read_string_from_wasm(ctx.as_context_mut(), &memory, name);
let name = read_string_from_wasm(ctx.as_mut(), &memory, name);
let value = read_string_from_wasm(ctx, &memory, value);
let putenv_string = format!("{}={}", name, value);
let putenv_cstring = CString::new(putenv_string).unwrap();
@@ -45,7 +45,7 @@ pub fn _setenv(mut ctx: ContextMut<'_, EmEnv>, name: u32, value: u32, _overwrite
}
/// emscripten: _putenv // (name: *const char);
pub fn _putenv(ctx: ContextMut<'_, EmEnv>, name: c_int) -> c_int {
pub fn _putenv(ctx: FunctionEnvMut<EmEnv>, name: c_int) -> c_int {
debug!("emscripten::_putenv");
let memory = ctx.data().memory(0);
let name_addr = emscripten_memory_pointer!(ctx, &memory, name) as *const c_char;
@@ -56,7 +56,7 @@ pub fn _putenv(ctx: ContextMut<'_, EmEnv>, name: c_int) -> c_int {
}
/// emscripten: _unsetenv // (name: *const char);
pub fn _unsetenv(ctx: ContextMut<'_, EmEnv>, name: u32) -> c_int {
pub fn _unsetenv(ctx: FunctionEnvMut<EmEnv>, name: u32) -> c_int {
debug!("emscripten::_unsetenv");
let memory = ctx.data().memory(0);
let name = read_string_from_wasm(ctx, &memory, name);
@@ -69,7 +69,7 @@ pub fn _unsetenv(ctx: ContextMut<'_, EmEnv>, name: u32) -> c_int {
}
#[allow(clippy::cast_ptr_alignment)]
pub fn _getpwnam(mut ctx: ContextMut<'_, EmEnv>, name_ptr: c_int) -> c_int {
pub fn _getpwnam(mut ctx: FunctionEnvMut<EmEnv>, name_ptr: c_int) -> c_int {
debug!("emscripten::_getpwnam {}", name_ptr);
#[cfg(not(feature = "debug"))]
let _ = name_ptr;
@@ -88,8 +88,7 @@ pub fn _getpwnam(mut ctx: ContextMut<'_, EmEnv>, name_ptr: c_int) -> c_int {
// stub this in windows as it is not valid
unsafe {
let passwd_struct_offset =
call_malloc(ctx.as_context_mut(), mem::size_of::<GuestPasswd>() as _);
let passwd_struct_offset = call_malloc(&mut ctx, mem::size_of::<GuestPasswd>() as _);
let passwd_struct_ptr =
emscripten_memory_pointer!(ctx, memory, passwd_struct_offset) as *mut GuestPasswd;
(*passwd_struct_ptr).pw_name = 0;
@@ -105,7 +104,7 @@ pub fn _getpwnam(mut ctx: ContextMut<'_, EmEnv>, name_ptr: c_int) -> c_int {
}
#[allow(clippy::cast_ptr_alignment)]
pub fn _getgrnam(mut ctx: ContextMut<'_, EmEnv>, name_ptr: c_int) -> c_int {
pub fn _getgrnam(mut ctx: FunctionEnvMut<EmEnv>, name_ptr: c_int) -> c_int {
debug!("emscripten::_getgrnam {}", name_ptr);
#[cfg(not(feature = "debug"))]
let _ = name_ptr;
@@ -121,8 +120,7 @@ pub fn _getgrnam(mut ctx: ContextMut<'_, EmEnv>, name_ptr: c_int) -> c_int {
// stub the group struct as it is not supported on windows
unsafe {
let group_struct_offset =
call_malloc(ctx.as_context_mut(), mem::size_of::<GuestGroup>() as _);
let group_struct_offset = call_malloc(&mut ctx, mem::size_of::<GuestGroup>() as _);
let group_struct_ptr =
emscripten_memory_pointer!(ctx, memory, group_struct_offset) as *mut GuestGroup;
(*group_struct_ptr).gr_name = 0;
@@ -133,7 +131,7 @@ pub fn _getgrnam(mut ctx: ContextMut<'_, EmEnv>, name_ptr: c_int) -> c_int {
}
}
pub fn _sysconf(_ctx: ContextMut<'_, EmEnv>, name: c_int) -> c_long {
pub fn _sysconf(_ctx: FunctionEnvMut<EmEnv>, name: c_int) -> c_long {
debug!("emscripten::_sysconf {}", name);
#[cfg(not(feature = "debug"))]
let _ = name;
@@ -141,13 +139,13 @@ pub fn _sysconf(_ctx: ContextMut<'_, EmEnv>, name: c_int) -> c_long {
0
}
pub fn _gai_strerror(_ctx: ContextMut<'_, EmEnv>, _ecode: i32) -> i32 {
pub fn _gai_strerror(_ctx: FunctionEnvMut<EmEnv>, _ecode: i32) -> i32 {
debug!("emscripten::_gai_strerror({}) - stub", _ecode);
-1
}
pub fn _getaddrinfo(
_ctx: ContextMut<'_, EmEnv>,
_ctx: FunctionEnvMut<EmEnv>,
_node_ptr: WasmPtr<c_char>,
_service_str_ptr: WasmPtr<c_char>,
_hints_ptr: WasmPtr<EmAddrInfo>,

View File

@@ -1,8 +1,8 @@
// use std::collections::HashMap;
use crate::EmEnv;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
pub fn ___seterrno(mut _ctx: ContextMut<'_, EmEnv>, _value: i32) {
pub fn ___seterrno(mut _ctx: FunctionEnvMut<EmEnv>, _value: i32) {
debug!("emscripten::___seterrno {}", _value);
// TODO: Incomplete impl
eprintln!("failed to set errno!");

View File

@@ -1,57 +1,57 @@
use super::env;
use super::process::_abort;
use crate::EmEnv;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
/// emscripten: ___cxa_allocate_exception
pub fn ___cxa_allocate_exception(ctx: ContextMut<'_, EmEnv>, size: u32) -> u32 {
pub fn ___cxa_allocate_exception(mut ctx: FunctionEnvMut<EmEnv>, size: u32) -> u32 {
debug!("emscripten::___cxa_allocate_exception");
env::call_malloc(ctx, size as _)
env::call_malloc(&mut ctx.as_mut(), size as _)
}
pub fn ___cxa_current_primary_exception(_ctx: ContextMut<'_, EmEnv>) -> u32 {
pub fn ___cxa_current_primary_exception(_ctx: FunctionEnvMut<EmEnv>) -> u32 {
debug!("emscripten::___cxa_current_primary_exception");
unimplemented!("emscripten::___cxa_current_primary_exception")
}
pub fn ___cxa_decrement_exception_refcount(_ctx: ContextMut<'_, EmEnv>, _a: u32) {
pub fn ___cxa_decrement_exception_refcount(_ctx: FunctionEnvMut<EmEnv>, _a: u32) {
debug!("emscripten::___cxa_decrement_exception_refcount({})", _a);
unimplemented!("emscripten::___cxa_decrement_exception_refcount({})", _a)
}
pub fn ___cxa_increment_exception_refcount(_ctx: ContextMut<'_, EmEnv>, _a: u32) {
pub fn ___cxa_increment_exception_refcount(_ctx: FunctionEnvMut<EmEnv>, _a: u32) {
debug!("emscripten::___cxa_increment_exception_refcount({})", _a);
unimplemented!("emscripten::___cxa_increment_exception_refcount({})", _a)
}
pub fn ___cxa_rethrow_primary_exception(_ctx: ContextMut<'_, EmEnv>, _a: u32) {
pub fn ___cxa_rethrow_primary_exception(_ctx: FunctionEnvMut<EmEnv>, _a: u32) {
debug!("emscripten::___cxa_rethrow_primary_exception({})", _a);
unimplemented!("emscripten::___cxa_rethrow_primary_exception({})", _a)
}
/// emscripten: ___cxa_throw
/// TODO: We don't have support for exceptions yet
pub fn ___cxa_throw(ctx: ContextMut<'_, EmEnv>, _ptr: u32, _ty: u32, _destructor: u32) {
pub fn ___cxa_throw(ctx: FunctionEnvMut<EmEnv>, _ptr: u32, _ty: u32, _destructor: u32) {
debug!("emscripten::___cxa_throw");
eprintln!("Throwing exceptions not yet implemented: aborting!");
_abort(ctx);
}
pub fn ___cxa_begin_catch(_ctx: ContextMut<'_, EmEnv>, _exception_object_ptr: u32) -> i32 {
pub fn ___cxa_begin_catch(_ctx: FunctionEnvMut<EmEnv>, _exception_object_ptr: u32) -> i32 {
debug!("emscripten::___cxa_begin_catch");
-1
}
pub fn ___cxa_end_catch(_ctx: ContextMut<'_, EmEnv>) {
pub fn ___cxa_end_catch(_ctx: FunctionEnvMut<EmEnv>) {
debug!("emscripten::___cxa_end_catch");
}
pub fn ___cxa_uncaught_exception(_ctx: ContextMut<'_, EmEnv>) -> i32 {
pub fn ___cxa_uncaught_exception(_ctx: FunctionEnvMut<EmEnv>) -> i32 {
debug!("emscripten::___cxa_uncaught_exception");
-1
}
pub fn ___cxa_pure_virtual(_ctx: ContextMut<'_, EmEnv>) {
pub fn ___cxa_pure_virtual(_ctx: FunctionEnvMut<EmEnv>) {
debug!("emscripten::___cxa_pure_virtual");
// ABORT = true
panic!("Pure virtual function called!");

View File

@@ -3,9 +3,9 @@ use crate::EmEnv;
use libc::c_char;
use libc::execvp as libc_execvp;
use std::ffi::CString;
use wasmer::{ContextMut, WasmPtr};
use wasmer::{FunctionEnvMut, WasmPtr};
pub fn execvp(ctx: ContextMut<'_, EmEnv>, command_name_offset: u32, argv_offset: u32) -> i32 {
pub fn execvp(ctx: FunctionEnvMut<EmEnv>, command_name_offset: u32, argv_offset: u32) -> i32 {
// a single reference to re-use
let emscripten_memory = ctx.data().memory(0);
@@ -41,7 +41,7 @@ pub fn execvp(ctx: ContextMut<'_, EmEnv>, command_name_offset: u32, argv_offset:
/// execl
pub fn execl(
_ctx: ContextMut<'_, EmEnv>,
_ctx: FunctionEnvMut<EmEnv>,
_path_ptr: i32,
_arg0_ptr: i32,
_varargs: VarArgs,
@@ -52,7 +52,7 @@ pub fn execl(
/// execle
pub fn execle(
_ctx: ContextMut<'_, EmEnv>,
_ctx: FunctionEnvMut<EmEnv>,
_path_ptr: i32,
_arg0_ptr: i32,
_varargs: VarArgs,

View File

@@ -1,8 +1,8 @@
use crate::EmEnv;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
// __exit
pub fn exit(mut _ctx: ContextMut<'_, EmEnv>, value: i32) {
pub fn exit(mut _ctx: FunctionEnvMut<EmEnv>, value: i32) {
debug!("emscripten::exit {}", value);
::std::process::exit(value);
}

View File

@@ -1,7 +1,7 @@
use crate::EmEnv;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
pub fn addr(mut _ctx: ContextMut<'_, EmEnv>, _cp: i32) -> i32 {
pub fn addr(mut _ctx: FunctionEnvMut<EmEnv>, _cp: i32) -> i32 {
debug!("inet::addr({})", _cp);
0
}

View File

@@ -11,22 +11,22 @@ pub use self::unix::*;
pub use self::windows::*;
use crate::EmEnv;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
/// getprotobyname
pub fn getprotobyname(_ctx: ContextMut<'_, EmEnv>, _name_ptr: i32) -> i32 {
pub fn getprotobyname(_ctx: FunctionEnvMut<EmEnv>, _name_ptr: i32) -> i32 {
debug!("emscripten::getprotobyname");
unimplemented!("emscripten::getprotobyname")
}
/// getprotobynumber
pub fn getprotobynumber(_ctx: ContextMut<'_, EmEnv>, _one: i32) -> i32 {
pub fn getprotobynumber(_ctx: FunctionEnvMut<EmEnv>, _one: i32) -> i32 {
debug!("emscripten::getprotobynumber");
unimplemented!("emscripten::getprotobynumber")
}
/// sigdelset
pub fn sigdelset(ctx: ContextMut<'_, EmEnv>, set: i32, signum: i32) -> i32 {
pub fn sigdelset(ctx: FunctionEnvMut<EmEnv>, set: i32, signum: i32) -> i32 {
debug!("emscripten::sigdelset");
let memory = ctx.data().memory(0);
#[allow(clippy::cast_ptr_alignment)]
@@ -38,7 +38,7 @@ pub fn sigdelset(ctx: ContextMut<'_, EmEnv>, set: i32, signum: i32) -> i32 {
}
/// sigfillset
pub fn sigfillset(ctx: ContextMut<'_, EmEnv>, set: i32) -> i32 {
pub fn sigfillset(ctx: FunctionEnvMut<EmEnv>, set: i32) -> i32 {
debug!("emscripten::sigfillset");
let memory = ctx.data().memory(0);
#[allow(clippy::cast_ptr_alignment)]
@@ -52,13 +52,13 @@ pub fn sigfillset(ctx: ContextMut<'_, EmEnv>, set: i32) -> i32 {
}
/// tzset
pub fn tzset(_ctx: ContextMut<'_, EmEnv>) {
pub fn tzset(_ctx: FunctionEnvMut<EmEnv>) {
debug!("emscripten::tzset - stub");
//unimplemented!("emscripten::tzset - stub")
}
/// strptime
pub fn strptime(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32, _three: i32) -> i32 {
pub fn strptime(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32, _three: i32) -> i32 {
debug!("emscripten::strptime");
unimplemented!("emscripten::strptime")
}

View File

@@ -4,15 +4,15 @@ use libc::{chroot as _chroot, getpwuid as _getpwuid, printf as _printf};
use std::mem;
use crate::EmEnv;
use wasmer::{AsContextMut, ContextMut};
use wasmer::FunctionEnvMut;
/// putchar
pub fn putchar(_ctx: ContextMut<'_, EmEnv>, chr: i32) {
pub fn putchar(_ctx: FunctionEnvMut<EmEnv>, chr: i32) {
unsafe { libc::putchar(chr) };
}
/// printf
pub fn printf(ctx: ContextMut<'_, EmEnv>, memory_offset: i32, extra: i32) -> i32 {
pub fn printf(ctx: FunctionEnvMut<EmEnv>, memory_offset: i32, extra: i32) -> i32 {
debug!("emscripten::printf {}, {}", memory_offset, extra);
unsafe {
let addr = emscripten_memory_pointer!(ctx, ctx.data().memory(0), memory_offset) as _;
@@ -21,7 +21,7 @@ pub fn printf(ctx: ContextMut<'_, EmEnv>, memory_offset: i32, extra: i32) -> i32
}
/// chroot
pub fn chroot(ctx: ContextMut<'_, EmEnv>, name_ptr: i32) -> i32 {
pub fn chroot(ctx: FunctionEnvMut<EmEnv>, name_ptr: i32) -> i32 {
debug!("emscripten::chroot");
let name = emscripten_memory_pointer!(ctx, ctx.data().memory(0), name_ptr) as *const i8;
unsafe { _chroot(name as *const _) }
@@ -29,7 +29,7 @@ pub fn chroot(ctx: ContextMut<'_, EmEnv>, name_ptr: i32) -> i32 {
/// getpwuid
#[allow(clippy::cast_ptr_alignment)]
pub fn getpwuid(mut ctx: ContextMut<'_, EmEnv>, uid: i32) -> i32 {
pub fn getpwuid(mut ctx: FunctionEnvMut<EmEnv>, uid: i32) -> i32 {
debug!("emscripten::getpwuid {}", uid);
#[repr(C)]
@@ -45,8 +45,7 @@ pub fn getpwuid(mut ctx: ContextMut<'_, EmEnv>, uid: i32) -> i32 {
unsafe {
let passwd = &*_getpwuid(uid as _);
let passwd_struct_offset =
call_malloc(ctx.as_context_mut(), mem::size_of::<GuestPasswd>() as _);
let passwd_struct_offset = call_malloc(&mut ctx, mem::size_of::<GuestPasswd>() as _);
let passwd_struct_ptr =
emscripten_memory_pointer!(ctx, ctx.data().memory(0), passwd_struct_offset)
as *mut GuestPasswd;
@@ -54,12 +53,11 @@ pub fn getpwuid(mut ctx: ContextMut<'_, EmEnv>, uid: i32) -> i32 {
passwd_struct_ptr as usize % std::mem::align_of::<GuestPasswd>(),
0
);
(*passwd_struct_ptr).pw_name = copy_cstr_into_wasm(ctx.as_context_mut(), passwd.pw_name);
(*passwd_struct_ptr).pw_passwd =
copy_cstr_into_wasm(ctx.as_context_mut(), passwd.pw_passwd);
(*passwd_struct_ptr).pw_gecos = copy_cstr_into_wasm(ctx.as_context_mut(), passwd.pw_gecos);
(*passwd_struct_ptr).pw_dir = copy_cstr_into_wasm(ctx.as_context_mut(), passwd.pw_dir);
(*passwd_struct_ptr).pw_shell = copy_cstr_into_wasm(ctx.as_context_mut(), passwd.pw_shell);
(*passwd_struct_ptr).pw_name = copy_cstr_into_wasm(&mut ctx, passwd.pw_name);
(*passwd_struct_ptr).pw_passwd = copy_cstr_into_wasm(&mut ctx, passwd.pw_passwd);
(*passwd_struct_ptr).pw_gecos = copy_cstr_into_wasm(&mut ctx, passwd.pw_gecos);
(*passwd_struct_ptr).pw_dir = copy_cstr_into_wasm(&mut ctx, passwd.pw_dir);
(*passwd_struct_ptr).pw_shell = copy_cstr_into_wasm(&mut ctx, passwd.pw_shell);
(*passwd_struct_ptr).pw_uid = passwd.pw_uid;
(*passwd_struct_ptr).pw_gid = passwd.pw_gid;

View File

@@ -1,5 +1,5 @@
use crate::EmEnv;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
// This may be problematic for msvc which uses inline functions for the printf family
// this cfg_attr will try to link with the legacy lib that does not inline printf
@@ -15,12 +15,12 @@ use wasmer::ContextMut;
//}
/// putchar
pub fn putchar(_ctx: ContextMut<'_, EmEnv>, chr: i32) {
pub fn putchar(_ctx: FunctionEnvMut<EmEnv>, chr: i32) {
unsafe { libc::putchar(chr) };
}
/// printf
pub fn printf(_ctx: ContextMut<'_, EmEnv>, memory_offset: i32, extra: i32) -> i32 {
pub fn printf(_ctx: FunctionEnvMut<EmEnv>, memory_offset: i32, extra: i32) -> i32 {
debug!("emscripten::printf {}, {}", memory_offset, extra);
#[cfg(not(feature = "debug"))]
{
@@ -35,13 +35,13 @@ pub fn printf(_ctx: ContextMut<'_, EmEnv>, memory_offset: i32, extra: i32) -> i3
}
/// chroot
pub fn chroot(_ctx: ContextMut<'_, EmEnv>, _name_ptr: i32) -> i32 {
pub fn chroot(_ctx: FunctionEnvMut<EmEnv>, _name_ptr: i32) -> i32 {
debug!("emscripten::chroot");
unimplemented!("emscripten::chroot")
}
/// getpwuid
pub fn getpwuid(_ctx: ContextMut<'_, EmEnv>, _uid: i32) -> i32 {
pub fn getpwuid(_ctx: FunctionEnvMut<EmEnv>, _uid: i32) -> i32 {
debug!("emscripten::getpwuid");
unimplemented!("emscripten::getpwuid")
}

View File

@@ -5,10 +5,10 @@ use libc::c_int;
use crate::EmEnv;
use std::error::Error;
use std::fmt;
use wasmer::{AsContextMut, ContextMut};
use wasmer::FunctionEnvMut;
/// setjmp
pub fn __setjmp(ctx: ContextMut<'_, EmEnv>, _env_addr: u32) -> c_int {
pub fn __setjmp(ctx: FunctionEnvMut<EmEnv>, _env_addr: u32) -> c_int {
debug!("emscripten::__setjmp (setjmp)");
abort_with_message(ctx, "missing function: _setjmp");
unreachable!()
@@ -31,7 +31,7 @@ pub fn __setjmp(ctx: ContextMut<'_, EmEnv>, _env_addr: u32) -> c_int {
/// longjmp
#[allow(unreachable_code)]
pub fn __longjmp(ctx: ContextMut<'_, EmEnv>, _env_addr: u32, _val: c_int) {
pub fn __longjmp(ctx: FunctionEnvMut<EmEnv>, _env_addr: u32, _val: c_int) {
debug!("emscripten::__longjmp (longmp)");
abort_with_message(ctx, "missing function: _longjmp");
// unsafe {
@@ -59,7 +59,7 @@ impl Error for LongJumpRet {}
// This function differs from the js implementation, it should return Result<(), &'static str>
#[allow(unreachable_code)]
pub fn _longjmp(
mut ctx: ContextMut<'_, EmEnv>,
mut ctx: FunctionEnvMut<EmEnv>,
env_addr: i32,
val: c_int,
) -> Result<(), LongJumpRet> {
@@ -69,7 +69,7 @@ pub fn _longjmp(
.expect("set_threw is None")
.clone();
threw
.call(&mut ctx.as_context_mut(), env_addr, val)
.call(&mut ctx, env_addr, val)
.expect("set_threw failed to call");
Err(LongJumpRet)
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,77 +1,77 @@
extern crate libc;
use crate::EmEnv;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
#[cfg(unix)]
use std::convert::TryInto;
pub fn current_sigrtmax(_ctx: ContextMut<'_, EmEnv>) -> i32 {
pub fn current_sigrtmax(_ctx: FunctionEnvMut<EmEnv>) -> i32 {
debug!("emscripten::current_sigrtmax");
0
}
pub fn current_sigrtmin(_ctx: ContextMut<'_, EmEnv>) -> i32 {
pub fn current_sigrtmin(_ctx: FunctionEnvMut<EmEnv>) -> i32 {
debug!("emscripten::current_sigrtmin");
0
}
pub fn endpwent(_ctx: ContextMut<'_, EmEnv>) {
pub fn endpwent(_ctx: FunctionEnvMut<EmEnv>) {
debug!("emscripten::endpwent");
}
pub fn execv(_ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn execv(_ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
debug!("emscripten::execv");
0
}
pub fn fexecve(_ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32, _c: i32) -> i32 {
pub fn fexecve(_ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32, _c: i32) -> i32 {
debug!("emscripten::fexecve");
0
}
pub fn fpathconf(_ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn fpathconf(_ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
debug!("emscripten::fpathconf");
0
}
pub fn getitimer(_ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn getitimer(_ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
debug!("emscripten::getitimer");
0
}
pub fn getpwent(_ctx: ContextMut<'_, EmEnv>) -> i32 {
pub fn getpwent(_ctx: FunctionEnvMut<EmEnv>) -> i32 {
debug!("emscripten::getpwent");
0
}
pub fn killpg(_ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn killpg(_ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
debug!("emscripten::killpg");
0
}
#[cfg(unix)]
pub fn pathconf(ctx: ContextMut<'_, EmEnv>, path_ptr: i32, name: i32) -> i32 {
pub fn pathconf(ctx: FunctionEnvMut<EmEnv>, path_ptr: i32, name: i32) -> i32 {
debug!("emscripten::pathconf");
let path = emscripten_memory_pointer!(ctx, ctx.data().memory(0), path_ptr) as *const i8;
unsafe { libc::pathconf(path as *const _, name).try_into().unwrap() }
}
#[cfg(not(unix))]
pub fn pathconf(_ctx: ContextMut<'_, EmEnv>, _path_ptr: i32, _name: i32) -> i32 {
pub fn pathconf(_ctx: FunctionEnvMut<EmEnv>, _path_ptr: i32, _name: i32) -> i32 {
debug!("emscripten::pathconf");
0
}
pub fn setpwent(_ctx: ContextMut<'_, EmEnv>) {
pub fn setpwent(_ctx: FunctionEnvMut<EmEnv>) {
debug!("emscripten::setpwent");
}
pub fn sigismember(_ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn sigismember(_ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
debug!("emscripten::sigismember");
0
}
pub fn sigpending(_ctx: ContextMut<'_, EmEnv>, _a: i32) -> i32 {
pub fn sigpending(_ctx: FunctionEnvMut<EmEnv>, _a: i32) -> i32 {
debug!("emscripten::sigpending");
0
}

View File

@@ -1,28 +1,28 @@
use crate::EmEnv;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
// TODO: Need to implement.
/// emscripten: dlopen(filename: *const c_char, flag: c_int) -> *mut c_void
pub fn _dlopen(mut _ctx: ContextMut<'_, EmEnv>, _filename: u32, _flag: u32) -> i32 {
pub fn _dlopen(mut _ctx: FunctionEnvMut<EmEnv>, _filename: u32, _flag: u32) -> i32 {
debug!("emscripten::_dlopen");
-1
}
/// emscripten: dlclose(handle: *mut c_void) -> c_int
pub fn _dlclose(mut _ctx: ContextMut<'_, EmEnv>, _filename: u32) -> i32 {
pub fn _dlclose(mut _ctx: FunctionEnvMut<EmEnv>, _filename: u32) -> i32 {
debug!("emscripten::_dlclose");
-1
}
/// emscripten: dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void
pub fn _dlsym(mut _ctx: ContextMut<'_, EmEnv>, _filepath: u32, _symbol: u32) -> i32 {
pub fn _dlsym(mut _ctx: FunctionEnvMut<EmEnv>, _filepath: u32, _symbol: u32) -> i32 {
debug!("emscripten::_dlsym");
-1
}
/// emscripten: dlerror() -> *mut c_char
pub fn _dlerror(mut _ctx: ContextMut<'_, EmEnv>) -> i32 {
pub fn _dlerror(mut _ctx: FunctionEnvMut<EmEnv>) -> i32 {
debug!("emscripten::_dlerror");
-1
}

View File

@@ -1,20 +1,20 @@
use crate::EmEnv;
use libc::c_int;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
// NOTE: Not implemented by Emscripten
pub fn ___lock(mut _ctx: ContextMut<'_, EmEnv>, _what: c_int) {
pub fn ___lock(mut _ctx: FunctionEnvMut<EmEnv>, _what: c_int) {
debug!("emscripten::___lock {}", _what);
}
// NOTE: Not implemented by Emscripten
pub fn ___unlock(mut _ctx: ContextMut<'_, EmEnv>, _what: c_int) {
pub fn ___unlock(mut _ctx: FunctionEnvMut<EmEnv>, _what: c_int) {
debug!("emscripten::___unlock {}", _what);
}
// NOTE: Not implemented by Emscripten
pub fn ___wait(
mut _ctx: ContextMut<'_, EmEnv>,
mut _ctx: FunctionEnvMut<EmEnv>,
_which: u32,
_varargs: u32,
_three: u32,
@@ -23,7 +23,7 @@ pub fn ___wait(
debug!("emscripten::___wait");
}
pub fn _flock(mut _ctx: ContextMut<'_, EmEnv>, _fd: u32, _op: u32) -> u32 {
pub fn _flock(mut _ctx: FunctionEnvMut<EmEnv>, _fd: u32, _op: u32) -> u32 {
debug!("emscripten::_flock");
0
}

View File

@@ -1,111 +1,111 @@
use crate::EmEnv;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
pub fn _llvm_copysign_f32(mut _ctx: ContextMut<'_, EmEnv>, x: f64, y: f64) -> f64 {
pub fn _llvm_copysign_f32(mut _ctx: FunctionEnvMut<EmEnv>, x: f64, y: f64) -> f64 {
x.copysign(y)
}
pub fn _llvm_copysign_f64(mut _ctx: ContextMut<'_, EmEnv>, x: f64, y: f64) -> f64 {
pub fn _llvm_copysign_f64(mut _ctx: FunctionEnvMut<EmEnv>, x: f64, y: f64) -> f64 {
x.copysign(y)
}
/// emscripten: _llvm_log10_f64
pub fn _llvm_log10_f64(mut _ctx: ContextMut<'_, EmEnv>, value: f64) -> f64 {
pub fn _llvm_log10_f64(mut _ctx: FunctionEnvMut<EmEnv>, value: f64) -> f64 {
debug!("emscripten::_llvm_log10_f64");
value.log10()
}
/// emscripten: _llvm_log2_f64
pub fn _llvm_log2_f64(mut _ctx: ContextMut<'_, EmEnv>, value: f64) -> f64 {
pub fn _llvm_log2_f64(mut _ctx: FunctionEnvMut<EmEnv>, value: f64) -> f64 {
debug!("emscripten::_llvm_log2_f64");
value.log2()
}
/// emscripten: _llvm_sin_f64
pub fn _llvm_sin_f64(mut _ctx: ContextMut<'_, EmEnv>, value: f64) -> f64 {
pub fn _llvm_sin_f64(mut _ctx: FunctionEnvMut<EmEnv>, value: f64) -> f64 {
debug!("emscripten::_llvm_sin_f64");
value.sin()
}
/// emscripten: _llvm_cos_f64
pub fn _llvm_cos_f64(mut _ctx: ContextMut<'_, EmEnv>, value: f64) -> f64 {
pub fn _llvm_cos_f64(mut _ctx: FunctionEnvMut<EmEnv>, value: f64) -> f64 {
debug!("emscripten::_llvm_cos_f64");
value.cos()
}
pub fn _llvm_log10_f32(mut _ctx: ContextMut<'_, EmEnv>, _value: f64) -> f64 {
pub fn _llvm_log10_f32(mut _ctx: FunctionEnvMut<EmEnv>, _value: f64) -> f64 {
debug!("emscripten::_llvm_log10_f32");
-1.0
}
pub fn _llvm_log2_f32(mut _ctx: ContextMut<'_, EmEnv>, _value: f64) -> f64 {
pub fn _llvm_log2_f32(mut _ctx: FunctionEnvMut<EmEnv>, _value: f64) -> f64 {
debug!("emscripten::_llvm_log10_f32");
-1.0
}
pub fn _llvm_exp2_f32(mut _ctx: ContextMut<'_, EmEnv>, value: f32) -> f32 {
pub fn _llvm_exp2_f32(mut _ctx: FunctionEnvMut<EmEnv>, value: f32) -> f32 {
debug!("emscripten::_llvm_exp2_f32");
2f32.powf(value)
}
pub fn _llvm_exp2_f64(mut _ctx: ContextMut<'_, EmEnv>, value: f64) -> f64 {
pub fn _llvm_exp2_f64(mut _ctx: FunctionEnvMut<EmEnv>, value: f64) -> f64 {
debug!("emscripten::_llvm_exp2_f64");
2f64.powf(value)
}
pub fn _llvm_trunc_f64(mut _ctx: ContextMut<'_, EmEnv>, value: f64) -> f64 {
pub fn _llvm_trunc_f64(mut _ctx: FunctionEnvMut<EmEnv>, value: f64) -> f64 {
debug!("emscripten::_llvm_trunc_f64");
value.trunc()
}
pub fn _llvm_fma_f64(mut _ctx: ContextMut<'_, EmEnv>, value: f64, a: f64, b: f64) -> f64 {
pub fn _llvm_fma_f64(mut _ctx: FunctionEnvMut<EmEnv>, value: f64, a: f64, b: f64) -> f64 {
debug!("emscripten::_llvm_fma_f64");
value.mul_add(a, b)
}
pub fn _emscripten_random(mut _ctx: ContextMut<'_, EmEnv>) -> f64 {
pub fn _emscripten_random(mut _ctx: FunctionEnvMut<EmEnv>) -> f64 {
debug!("emscripten::_emscripten_random");
-1.0
}
// emscripten: asm2wasm.f64-rem
pub fn f64_rem(mut _ctx: ContextMut<'_, EmEnv>, x: f64, y: f64) -> f64 {
pub fn f64_rem(mut _ctx: FunctionEnvMut<EmEnv>, x: f64, y: f64) -> f64 {
debug!("emscripten::f64-rem");
x % y
}
// emscripten: global.Math pow
pub fn pow(mut _ctx: ContextMut<'_, EmEnv>, x: f64, y: f64) -> f64 {
pub fn pow(mut _ctx: FunctionEnvMut<EmEnv>, x: f64, y: f64) -> f64 {
x.powf(y)
}
// emscripten: global.Math exp
pub fn exp(mut _ctx: ContextMut<'_, EmEnv>, value: f64) -> f64 {
pub fn exp(mut _ctx: FunctionEnvMut<EmEnv>, value: f64) -> f64 {
value.exp()
}
// emscripten: global.Math log
pub fn log(mut _ctx: ContextMut<'_, EmEnv>, value: f64) -> f64 {
pub fn log(mut _ctx: FunctionEnvMut<EmEnv>, value: f64) -> f64 {
value.ln()
}
// emscripten: global.Math sqrt
pub fn sqrt(mut _ctx: ContextMut<'_, EmEnv>, value: f64) -> f64 {
pub fn sqrt(mut _ctx: FunctionEnvMut<EmEnv>, value: f64) -> f64 {
value.sqrt()
}
// emscripten: global.Math floor
pub fn floor(mut _ctx: ContextMut<'_, EmEnv>, value: f64) -> f64 {
pub fn floor(mut _ctx: FunctionEnvMut<EmEnv>, value: f64) -> f64 {
value.floor()
}
// emscripten: global.Math fabs
pub fn fabs(mut _ctx: ContextMut<'_, EmEnv>, value: f64) -> f64 {
pub fn fabs(mut _ctx: FunctionEnvMut<EmEnv>, value: f64) -> f64 {
value.abs()
}
// emscripten: asm2wasm.f64-to-int
pub fn f64_to_int(mut _ctx: ContextMut<'_, EmEnv>, value: f64) -> i32 {
pub fn f64_to_int(mut _ctx: FunctionEnvMut<EmEnv>, value: f64) -> i32 {
debug!("emscripten::f64_to_int {}", value);
value as i32
}

View File

@@ -3,12 +3,10 @@ use super::process::abort_with_message;
use crate::EmEnv;
use libc::{c_int, c_void, memcpy, size_t};
// TODO: investigate max pages etc. probably in Wasm Common, maybe reexport
use wasmer::{
AsContextMut, ContextMut, Pages, WasmPtr, WASM_MAX_PAGES, WASM_MIN_PAGES, WASM_PAGE_SIZE,
};
use wasmer::{FunctionEnvMut, Pages, WasmPtr, WASM_MAX_PAGES, WASM_MIN_PAGES, WASM_PAGE_SIZE};
/// emscripten: _emscripten_memcpy_big
pub fn _emscripten_memcpy_big(ctx: ContextMut<'_, EmEnv>, dest: u32, src: u32, len: u32) -> u32 {
pub fn _emscripten_memcpy_big(ctx: FunctionEnvMut<EmEnv>, dest: u32, src: u32, len: u32) -> u32 {
debug!(
"emscripten::_emscripten_memcpy_big {}, {}, {}",
dest, src, len
@@ -21,12 +19,12 @@ pub fn _emscripten_memcpy_big(ctx: ContextMut<'_, EmEnv>, dest: u32, src: u32, l
dest
}
fn get_heap_size(ctx: &ContextMut<'_, EmEnv>) -> u32 {
fn get_heap_size(ctx: &FunctionEnvMut<EmEnv>) -> u32 {
ctx.data().memory(0).size(&ctx).bytes().0 as u32
}
/// emscripten: _emscripten_get_heap_size
pub fn _emscripten_get_heap_size(ctx: ContextMut<'_, EmEnv>) -> u32 {
pub fn _emscripten_get_heap_size(ctx: FunctionEnvMut<EmEnv>) -> u32 {
trace!("emscripten::_emscripten_get_heap_size");
let result = get_heap_size(&ctx);
trace!("=> {}", result);
@@ -42,7 +40,7 @@ fn align_up(mut val: usize, multiple: usize) -> usize {
val
}
fn resize_heap(ctx: &mut ContextMut<'_, EmEnv>, requested_size: u32) -> u32 {
fn resize_heap(ctx: &mut FunctionEnvMut<EmEnv>, requested_size: u32) -> u32 {
debug!("emscripten::_emscripten_resize_heap {}", requested_size);
let current_memory_pages = ctx.data().memory(0).size(&ctx);
let current_memory = current_memory_pages.bytes().0 as u32;
@@ -67,7 +65,7 @@ fn resize_heap(ctx: &mut ContextMut<'_, EmEnv>, requested_size: u32) -> u32 {
if let Ok(_pages_allocated) = ctx
.data()
.memory(0)
.grow(&mut ctx.as_context_mut(), Pages(amount_to_grow as u32))
.grow(&mut ctx.as_mut(), Pages(amount_to_grow as u32))
{
debug!("{} pages allocated", _pages_allocated.0);
1
@@ -78,12 +76,12 @@ fn resize_heap(ctx: &mut ContextMut<'_, EmEnv>, requested_size: u32) -> u32 {
/// emscripten: _emscripten_resize_heap
/// Note: this function only allows growing the size of heap
pub fn _emscripten_resize_heap(mut ctx: ContextMut<'_, EmEnv>, requested_size: u32) -> u32 {
pub fn _emscripten_resize_heap(mut ctx: FunctionEnvMut<EmEnv>, requested_size: u32) -> u32 {
resize_heap(&mut ctx, requested_size)
}
/// emscripten: sbrk
pub fn sbrk(mut ctx: ContextMut<'_, EmEnv>, increment: i32) -> i32 {
pub fn sbrk(mut ctx: FunctionEnvMut<EmEnv>, increment: i32) -> i32 {
debug!("emscripten::sbrk");
// let old_dynamic_top = 0;
// let new_dynamic_top = 0;
@@ -122,7 +120,7 @@ pub fn sbrk(mut ctx: ContextMut<'_, EmEnv>, increment: i32) -> i32 {
}
/// emscripten: getTotalMemory
pub fn get_total_memory(ctx: ContextMut<'_, EmEnv>) -> u32 {
pub fn get_total_memory(ctx: FunctionEnvMut<EmEnv>) -> u32 {
debug!("emscripten::get_total_memory");
// instance.memories[0].current_pages()
// TODO: Fix implementation
@@ -130,7 +128,7 @@ pub fn get_total_memory(ctx: ContextMut<'_, EmEnv>) -> u32 {
}
/// emscripten: enlargeMemory
pub fn enlarge_memory(_ctx: ContextMut<'_, EmEnv>) -> u32 {
pub fn enlarge_memory(_ctx: FunctionEnvMut<EmEnv>) -> u32 {
debug!("emscripten::enlarge_memory");
// instance.memories[0].grow(100);
// TODO: Fix implementation
@@ -138,7 +136,7 @@ pub fn enlarge_memory(_ctx: ContextMut<'_, EmEnv>) -> u32 {
}
/// emscripten: abortOnCannotGrowMemory
pub fn abort_on_cannot_grow_memory(ctx: ContextMut<'_, EmEnv>, _requested_size: u32) -> u32 {
pub fn abort_on_cannot_grow_memory(ctx: FunctionEnvMut<EmEnv>, _requested_size: u32) -> u32 {
debug!(
"emscripten::abort_on_cannot_grow_memory {}",
_requested_size
@@ -148,32 +146,32 @@ pub fn abort_on_cannot_grow_memory(ctx: ContextMut<'_, EmEnv>, _requested_size:
}
/// emscripten: abortOnCannotGrowMemory
pub fn abort_on_cannot_grow_memory_old(ctx: ContextMut<'_, EmEnv>) -> u32 {
pub fn abort_on_cannot_grow_memory_old(ctx: FunctionEnvMut<EmEnv>) -> u32 {
debug!("emscripten::abort_on_cannot_grow_memory");
abort_with_message(ctx, "Cannot enlarge memory arrays!");
0
}
/// emscripten: segfault
pub fn segfault(ctx: ContextMut<'_, EmEnv>) {
pub fn segfault(ctx: FunctionEnvMut<EmEnv>) {
debug!("emscripten::segfault");
abort_with_message(ctx, "segmentation fault");
}
/// emscripten: alignfault
pub fn alignfault(ctx: ContextMut<'_, EmEnv>) {
pub fn alignfault(ctx: FunctionEnvMut<EmEnv>) {
debug!("emscripten::alignfault");
abort_with_message(ctx, "alignment fault");
}
/// emscripten: ftfault
pub fn ftfault(ctx: ContextMut<'_, EmEnv>) {
pub fn ftfault(ctx: FunctionEnvMut<EmEnv>) {
debug!("emscripten::ftfault");
abort_with_message(ctx, "Function table mask error");
}
/// emscripten: ___map_file
pub fn ___map_file(_ctx: ContextMut<'_, EmEnv>, _one: u32, _two: u32) -> c_int {
pub fn ___map_file(_ctx: FunctionEnvMut<EmEnv>, _one: u32, _two: u32) -> c_int {
debug!("emscripten::___map_file");
// NOTE: TODO: Em returns -1 here as well. May need to implement properly
-1

View File

@@ -6,35 +6,35 @@ type PidT = libc::pid_t;
type PidT = c_int;
use crate::EmEnv;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
pub fn abort_with_message(ctx: ContextMut<'_, EmEnv>, message: &str) {
pub fn abort_with_message(ctx: FunctionEnvMut<EmEnv>, message: &str) {
debug!("emscripten::abort_with_message");
println!("{}", message);
_abort(ctx);
}
/// The name of this call is `abort` but we want to avoid conflicts with libc::abort
pub fn em_abort(ctx: ContextMut<'_, EmEnv>, arg: u32) {
pub fn em_abort(ctx: FunctionEnvMut<EmEnv>, arg: u32) {
debug!("emscripten::abort");
eprintln!("Program aborted with value {}", arg);
_abort(ctx);
}
pub fn _abort(_ctx: ContextMut<'_, EmEnv>) {
pub fn _abort(_ctx: FunctionEnvMut<EmEnv>) {
debug!("emscripten::_abort");
unsafe {
abort();
}
}
pub fn _prctl(ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn _prctl(ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_prctl");
abort_with_message(ctx, "missing function: prctl");
-1
}
pub fn _fork(_ctx: ContextMut<'_, EmEnv>) -> PidT {
pub fn _fork(_ctx: FunctionEnvMut<EmEnv>) -> PidT {
debug!("emscripten::_fork");
// unsafe {
// fork()
@@ -42,132 +42,132 @@ pub fn _fork(_ctx: ContextMut<'_, EmEnv>) -> PidT {
-1
}
pub fn _endgrent(_ctx: ContextMut<'_, EmEnv>) {
pub fn _endgrent(_ctx: FunctionEnvMut<EmEnv>) {
debug!("emscripten::_endgrent");
}
pub fn _execve(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32, _three: i32) -> i32 {
pub fn _execve(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32, _three: i32) -> i32 {
debug!("emscripten::_execve");
-1
}
#[allow(unreachable_code)]
pub fn _exit(_ctx: ContextMut<'_, EmEnv>, status: c_int) {
pub fn _exit(_ctx: FunctionEnvMut<EmEnv>, status: c_int) {
// -> !
debug!("emscripten::_exit {}", status);
unsafe { exit(status) }
}
pub fn _kill(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn _kill(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::_kill");
-1
}
pub fn _sched_yield(_ctx: ContextMut<'_, EmEnv>) -> i32 {
pub fn _sched_yield(_ctx: FunctionEnvMut<EmEnv>) -> i32 {
debug!("emscripten::_sched_yield");
-1
}
pub fn _llvm_stacksave(_ctx: ContextMut<'_, EmEnv>) -> i32 {
pub fn _llvm_stacksave(_ctx: FunctionEnvMut<EmEnv>) -> i32 {
debug!("emscripten::_llvm_stacksave");
-1
}
pub fn _llvm_stackrestore(_ctx: ContextMut<'_, EmEnv>, _one: i32) {
pub fn _llvm_stackrestore(_ctx: FunctionEnvMut<EmEnv>, _one: i32) {
debug!("emscripten::_llvm_stackrestore");
}
pub fn _raise(_ctx: ContextMut<'_, EmEnv>, _one: i32) -> i32 {
pub fn _raise(_ctx: FunctionEnvMut<EmEnv>, _one: i32) -> i32 {
debug!("emscripten::_raise");
-1
}
pub fn _sem_init(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32, _three: i32) -> i32 {
pub fn _sem_init(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32, _three: i32) -> i32 {
debug!("emscripten::_sem_init: {}, {}, {}", _one, _two, _three);
0
}
pub fn _sem_destroy(_ctx: ContextMut<'_, EmEnv>, _one: i32) -> i32 {
pub fn _sem_destroy(_ctx: FunctionEnvMut<EmEnv>, _one: i32) -> i32 {
debug!("emscripten::_sem_destroy");
0
}
pub fn _sem_post(_ctx: ContextMut<'_, EmEnv>, _one: i32) -> i32 {
pub fn _sem_post(_ctx: FunctionEnvMut<EmEnv>, _one: i32) -> i32 {
debug!("emscripten::_sem_post");
-1
}
pub fn _sem_wait(_ctx: ContextMut<'_, EmEnv>, _one: i32) -> i32 {
pub fn _sem_wait(_ctx: FunctionEnvMut<EmEnv>, _one: i32) -> i32 {
debug!("emscripten::_sem_post");
-1
}
#[allow(clippy::cast_ptr_alignment)]
pub fn _getgrent(_ctx: ContextMut<'_, EmEnv>) -> c_int {
pub fn _getgrent(_ctx: FunctionEnvMut<EmEnv>) -> c_int {
debug!("emscripten::_getgrent");
-1
}
pub fn _setgrent(_ctx: ContextMut<'_, EmEnv>) {
pub fn _setgrent(_ctx: FunctionEnvMut<EmEnv>) {
debug!("emscripten::_setgrent");
}
pub fn _setgroups(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn _setgroups(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::_setgroups");
-1
}
pub fn _setitimer(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32, _three: i32) -> i32 {
pub fn _setitimer(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32, _three: i32) -> i32 {
debug!("emscripten::_setitimer");
-1
}
pub fn _usleep(_ctx: ContextMut<'_, EmEnv>, _one: i32) -> i32 {
pub fn _usleep(_ctx: FunctionEnvMut<EmEnv>, _one: i32) -> i32 {
debug!("emscripten::_usleep");
-1
}
pub fn _nanosleep(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn _nanosleep(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::_nanosleep");
-1
}
pub fn _utime(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn _utime(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::_utime");
-1
}
pub fn _utimes(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn _utimes(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::_utimes");
-1
}
pub fn _wait(_ctx: ContextMut<'_, EmEnv>, _one: i32) -> i32 {
pub fn _wait(_ctx: FunctionEnvMut<EmEnv>, _one: i32) -> i32 {
debug!("emscripten::_wait");
-1
}
pub fn _wait3(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32, _three: i32) -> i32 {
pub fn _wait3(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32, _three: i32) -> i32 {
debug!("emscripten::_wait3");
-1
}
pub fn _wait4(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32, _three: i32, _d: i32) -> i32 {
pub fn _wait4(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32, _three: i32, _d: i32) -> i32 {
debug!("emscripten::_wait4");
-1
}
pub fn _waitid(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32, _three: i32, _d: i32) -> i32 {
pub fn _waitid(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32, _three: i32, _d: i32) -> i32 {
debug!("emscripten::_waitid");
-1
}
pub fn _waitpid(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32, _three: i32) -> i32 {
pub fn _waitpid(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32, _three: i32) -> i32 {
debug!("emscripten::_waitpid");
-1
}
pub fn abort_stack_overflow(ctx: ContextMut<'_, EmEnv>, _what: c_int) {
pub fn abort_stack_overflow(ctx: FunctionEnvMut<EmEnv>, _what: c_int) {
debug!("emscripten::abort_stack_overflow");
// TODO: Message incomplete. Need to finish em runtime data first
abort_with_message(
@@ -176,24 +176,24 @@ pub fn abort_stack_overflow(ctx: ContextMut<'_, EmEnv>, _what: c_int) {
);
}
pub fn _llvm_trap(ctx: ContextMut<'_, EmEnv>) {
pub fn _llvm_trap(ctx: FunctionEnvMut<EmEnv>) {
debug!("emscripten::_llvm_trap");
abort_with_message(ctx, "abort!");
}
pub fn _llvm_eh_typeid_for(_ctx: ContextMut<'_, EmEnv>, _type_info_addr: u32) -> i32 {
pub fn _llvm_eh_typeid_for(_ctx: FunctionEnvMut<EmEnv>, _type_info_addr: u32) -> i32 {
debug!("emscripten::_llvm_eh_typeid_for");
-1
}
pub fn _system(_ctx: ContextMut<'_, EmEnv>, _one: i32) -> c_int {
pub fn _system(_ctx: FunctionEnvMut<EmEnv>, _one: i32) -> c_int {
debug!("emscripten::_system");
// TODO: May need to change this Em impl to a working version
eprintln!("Can't call external programs");
EAGAIN
}
pub fn _popen(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> c_int {
pub fn _popen(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> c_int {
debug!("emscripten::_popen");
// TODO: May need to change this Em impl to a working version
eprintln!("Missing function: popen");

View File

@@ -1,13 +1,13 @@
use crate::EmEnv;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
pub fn _pthread_attr_destroy(mut _ctx: ContextMut<'_, EmEnv>, _a: i32) -> i32 {
pub fn _pthread_attr_destroy(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32) -> i32 {
trace!("emscripten::_pthread_attr_destroy");
0
}
pub fn _pthread_attr_getstack(
mut _ctx: ContextMut<'_, EmEnv>,
mut _ctx: FunctionEnvMut<EmEnv>,
_stackaddr: i32,
_stacksize: i32,
_other: i32,
@@ -24,175 +24,175 @@ pub fn _pthread_attr_getstack(
0
}
pub fn _pthread_attr_init(mut _ctx: ContextMut<'_, EmEnv>, _a: i32) -> i32 {
pub fn _pthread_attr_init(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32) -> i32 {
trace!("emscripten::_pthread_attr_init({})", _a);
0
}
pub fn _pthread_attr_setstacksize(mut _ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn _pthread_attr_setstacksize(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
trace!("emscripten::_pthread_attr_setstacksize");
0
}
pub fn _pthread_cleanup_pop(mut _ctx: ContextMut<'_, EmEnv>, _a: i32) {
pub fn _pthread_cleanup_pop(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32) {
trace!("emscripten::_pthread_cleanup_pop");
}
pub fn _pthread_cleanup_push(mut _ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) {
pub fn _pthread_cleanup_push(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) {
trace!("emscripten::_pthread_cleanup_push");
}
pub fn _pthread_cond_destroy(mut _ctx: ContextMut<'_, EmEnv>, _a: i32) -> i32 {
pub fn _pthread_cond_destroy(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32) -> i32 {
trace!("emscripten::_pthread_cond_destroy");
0
}
pub fn _pthread_cond_init(mut _ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn _pthread_cond_init(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
trace!("emscripten::_pthread_cond_init");
0
}
pub fn _pthread_cond_signal(mut _ctx: ContextMut<'_, EmEnv>, _a: i32) -> i32 {
pub fn _pthread_cond_signal(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32) -> i32 {
trace!("emscripten::_pthread_cond_signal");
0
}
pub fn _pthread_cond_timedwait(mut _ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32, _c: i32) -> i32 {
pub fn _pthread_cond_timedwait(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32, _c: i32) -> i32 {
trace!("emscripten::_pthread_cond_timedwait");
0
}
pub fn _pthread_cond_wait(mut _ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn _pthread_cond_wait(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
trace!("emscripten::_pthread_cond_wait");
0
}
pub fn _pthread_condattr_destroy(mut _ctx: ContextMut<'_, EmEnv>, _a: i32) -> i32 {
pub fn _pthread_condattr_destroy(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32) -> i32 {
trace!("emscripten::_pthread_condattr_destroy");
0
}
pub fn _pthread_condattr_init(mut _ctx: ContextMut<'_, EmEnv>, _a: i32) -> i32 {
pub fn _pthread_condattr_init(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32) -> i32 {
trace!("emscripten::_pthread_condattr_init");
0
}
pub fn _pthread_condattr_setclock(mut _ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn _pthread_condattr_setclock(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
trace!("emscripten::_pthread_condattr_setclock");
0
}
pub fn _pthread_create(mut _ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32, _c: i32, _d: i32) -> i32 {
pub fn _pthread_create(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32, _c: i32, _d: i32) -> i32 {
trace!("emscripten::_pthread_create");
// 11 seems to mean "no"
11
}
pub fn _pthread_detach(mut _ctx: ContextMut<'_, EmEnv>, _a: i32) -> i32 {
pub fn _pthread_detach(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32) -> i32 {
trace!("emscripten::_pthread_detach");
0
}
pub fn _pthread_equal(mut _ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn _pthread_equal(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
trace!("emscripten::_pthread_equal");
0
}
pub fn _pthread_exit(mut _ctx: ContextMut<'_, EmEnv>, _a: i32) {
pub fn _pthread_exit(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32) {
trace!("emscripten::_pthread_exit");
}
pub fn _pthread_getattr_np(mut _ctx: ContextMut<'_, EmEnv>, _thread: i32, _attr: i32) -> i32 {
pub fn _pthread_getattr_np(mut _ctx: FunctionEnvMut<EmEnv>, _thread: i32, _attr: i32) -> i32 {
trace!("emscripten::_pthread_getattr_np({}, {})", _thread, _attr);
0
}
pub fn _pthread_getspecific(mut _ctx: ContextMut<'_, EmEnv>, _a: i32) -> i32 {
pub fn _pthread_getspecific(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32) -> i32 {
trace!("emscripten::_pthread_getspecific");
0
}
pub fn _pthread_join(mut _ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn _pthread_join(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
trace!("emscripten::_pthread_join");
0
}
pub fn _pthread_self(mut _ctx: ContextMut<'_, EmEnv>) -> i32 {
pub fn _pthread_self(mut _ctx: FunctionEnvMut<EmEnv>) -> i32 {
trace!("emscripten::_pthread_self");
0
}
pub fn _pthread_key_create(mut _ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn _pthread_key_create(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
trace!("emscripten::_pthread_key_create");
0
}
pub fn _pthread_mutex_destroy(mut _ctx: ContextMut<'_, EmEnv>, _a: i32) -> i32 {
pub fn _pthread_mutex_destroy(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32) -> i32 {
trace!("emscripten::_pthread_mutex_destroy");
0
}
pub fn _pthread_mutex_init(mut _ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn _pthread_mutex_init(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
trace!("emscripten::_pthread_mutex_init");
0
}
pub fn _pthread_mutexattr_destroy(mut _ctx: ContextMut<'_, EmEnv>, _a: i32) -> i32 {
pub fn _pthread_mutexattr_destroy(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32) -> i32 {
trace!("emscripten::_pthread_mutexattr_destroy");
0
}
pub fn _pthread_mutexattr_init(mut _ctx: ContextMut<'_, EmEnv>, _a: i32) -> i32 {
pub fn _pthread_mutexattr_init(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32) -> i32 {
trace!("emscripten::_pthread_mutexattr_init");
0
}
pub fn _pthread_mutexattr_settype(mut _ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn _pthread_mutexattr_settype(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
trace!("emscripten::_pthread_mutexattr_settype");
0
}
pub fn _pthread_once(mut _ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn _pthread_once(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
trace!("emscripten::_pthread_once");
0
}
pub fn _pthread_rwlock_destroy(mut _ctx: ContextMut<'_, EmEnv>, _rwlock: i32) -> i32 {
pub fn _pthread_rwlock_destroy(mut _ctx: FunctionEnvMut<EmEnv>, _rwlock: i32) -> i32 {
trace!("emscripten::_pthread_rwlock_destroy({})", _rwlock);
0
}
pub fn _pthread_rwlock_init(mut _ctx: ContextMut<'_, EmEnv>, _rwlock: i32, _attr: i32) -> i32 {
pub fn _pthread_rwlock_init(mut _ctx: FunctionEnvMut<EmEnv>, _rwlock: i32, _attr: i32) -> i32 {
trace!("emscripten::_pthread_rwlock_init({}, {})", _rwlock, _attr);
0
}
pub fn _pthread_rwlock_rdlock(mut _ctx: ContextMut<'_, EmEnv>, _a: i32) -> i32 {
pub fn _pthread_rwlock_rdlock(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32) -> i32 {
trace!("emscripten::_pthread_rwlock_rdlock");
0
}
pub fn _pthread_rwlock_unlock(mut _ctx: ContextMut<'_, EmEnv>, _a: i32) -> i32 {
pub fn _pthread_rwlock_unlock(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32) -> i32 {
trace!("emscripten::_pthread_rwlock_unlock");
0
}
pub fn _pthread_rwlock_wrlock(mut _ctx: ContextMut<'_, EmEnv>, _rwlock: i32) -> i32 {
pub fn _pthread_rwlock_wrlock(mut _ctx: FunctionEnvMut<EmEnv>, _rwlock: i32) -> i32 {
trace!("emscripten::_pthread_rwlock_wrlock({})", _rwlock);
0
}
pub fn _pthread_setcancelstate(mut _ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn _pthread_setcancelstate(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
trace!("emscripten::_pthread_setcancelstate");
0
}
pub fn _pthread_setspecific(mut _ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32) -> i32 {
pub fn _pthread_setspecific(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32) -> i32 {
trace!("emscripten::_pthread_setspecific");
0
}
pub fn _pthread_sigmask(mut _ctx: ContextMut<'_, EmEnv>, _a: i32, _b: i32, _c: i32) -> i32 {
pub fn _pthread_sigmask(mut _ctx: FunctionEnvMut<EmEnv>, _a: i32, _b: i32, _c: i32) -> i32 {
trace!("emscripten::_pthread_sigmask");
0
}

View File

@@ -1,9 +1,9 @@
// use super::varargs::VarArgs;
use crate::EmEnv;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
#[allow(clippy::cast_ptr_alignment)]
pub fn _sigemptyset(ctx: ContextMut<'_, EmEnv>, set: u32) -> i32 {
pub fn _sigemptyset(ctx: FunctionEnvMut<EmEnv>, set: u32) -> i32 {
debug!("emscripten::_sigemptyset");
let set_addr = emscripten_memory_pointer!(ctx, ctx.data().memory(0), set) as *mut u32;
unsafe {
@@ -12,18 +12,18 @@ pub fn _sigemptyset(ctx: ContextMut<'_, EmEnv>, set: u32) -> i32 {
0
}
pub fn _sigaction(_ctx: ContextMut<'_, EmEnv>, _signum: u32, _act: u32, _oldact: u32) -> i32 {
pub fn _sigaction(_ctx: FunctionEnvMut<EmEnv>, _signum: u32, _act: u32, _oldact: u32) -> i32 {
debug!("emscripten::_sigaction {}, {}, {}", _signum, _act, _oldact);
0
}
pub fn _siginterrupt(_ctx: ContextMut<'_, EmEnv>, _a: u32, _b: u32) -> i32 {
pub fn _siginterrupt(_ctx: FunctionEnvMut<EmEnv>, _a: u32, _b: u32) -> i32 {
debug!("emscripten::_siginterrupt {}, {}", _a, _b);
0
}
#[allow(clippy::cast_ptr_alignment)]
pub fn _sigaddset(ctx: ContextMut<'_, EmEnv>, set: u32, signum: u32) -> i32 {
pub fn _sigaddset(ctx: FunctionEnvMut<EmEnv>, set: u32, signum: u32) -> i32 {
debug!("emscripten::_sigaddset {}, {}", set, signum);
let set_addr = emscripten_memory_pointer!(ctx, ctx.data().memory(0), set) as *mut u32;
unsafe {
@@ -32,17 +32,17 @@ pub fn _sigaddset(ctx: ContextMut<'_, EmEnv>, set: u32, signum: u32) -> i32 {
0
}
pub fn _sigsuspend(_ctx: ContextMut<'_, EmEnv>, _one: i32) -> i32 {
pub fn _sigsuspend(_ctx: FunctionEnvMut<EmEnv>, _one: i32) -> i32 {
debug!("emscripten::_sigsuspend");
-1
}
pub fn _sigprocmask(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32, _three: i32) -> i32 {
pub fn _sigprocmask(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32, _three: i32) -> i32 {
debug!("emscripten::_sigprocmask");
0
}
pub fn _signal(_ctx: ContextMut<'_, EmEnv>, _sig: u32, _two: i32) -> i32 {
pub fn _signal(_ctx: FunctionEnvMut<EmEnv>, _sig: u32, _two: i32) -> i32 {
debug!("emscripten::_signal ({})", _sig);
0
}

View File

@@ -48,10 +48,10 @@ use super::env;
#[allow(unused_imports)]
use std::io::Error;
use std::slice;
use wasmer::{AsContextMut, ContextMut, WasmPtr};
use wasmer::{FunctionEnvMut, WasmPtr};
/// exit
pub fn ___syscall1(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) {
pub fn ___syscall1(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) {
debug!("emscripten::___syscall1 (exit) {}", _which);
let status: i32 = varargs.get(&ctx);
unsafe {
@@ -60,7 +60,7 @@ pub fn ___syscall1(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarAr
}
/// read
pub fn ___syscall3(ctx: ContextMut<'_, EmEnv>, _which: i32, mut varargs: VarArgs) -> i32 {
pub fn ___syscall3(ctx: FunctionEnvMut<EmEnv>, _which: i32, mut varargs: VarArgs) -> i32 {
// -> ssize_t
debug!("emscripten::___syscall3 (read) {}", _which);
let fd: i32 = varargs.get(&ctx);
@@ -74,7 +74,7 @@ pub fn ___syscall3(ctx: ContextMut<'_, EmEnv>, _which: i32, mut varargs: VarArgs
}
/// write
pub fn ___syscall4(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall4(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall4 (write) {}", _which);
let fd: i32 = varargs.get(&ctx);
let buf: i32 = varargs.get(&ctx);
@@ -85,7 +85,7 @@ pub fn ___syscall4(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarAr
}
/// close
pub fn ___syscall6(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall6(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall6 (close) {}", _which);
let fd: i32 = varargs.get(&ctx);
debug!("fd: {}", fd);
@@ -93,7 +93,7 @@ pub fn ___syscall6(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarAr
}
// chdir
pub fn ___syscall12(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall12(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall12 (chdir) {}", _which);
let path_ptr = varargs.get_str(&ctx);
let real_path_owned = get_cstr_path(ctx, path_ptr as *const _);
@@ -111,63 +111,63 @@ pub fn ___syscall12(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarA
ret
}
pub fn ___syscall10(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall10(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall10");
-1
}
pub fn ___syscall14(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall14(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall14");
-1
}
pub fn ___syscall15(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall15(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall15");
-1
}
// getpid
pub fn ___syscall20(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall20(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall20 (getpid)");
unsafe { getpid() }
}
pub fn ___syscall21(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall21(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall21");
-1
}
pub fn ___syscall25(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall25(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall25");
-1
}
pub fn ___syscall29(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall29(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall29");
-1
}
pub fn ___syscall32(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall32(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall32");
-1
}
pub fn ___syscall33(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall33(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall33");
-1
}
pub fn ___syscall36(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall36(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall36");
-1
}
// rename
pub fn ___syscall38(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> i32 {
pub fn ___syscall38(mut ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> i32 {
debug!("emscripten::___syscall38 (rename)");
let old_path = varargs.get_str(&ctx);
let new_path = varargs.get_str(&ctx);
let real_old_path_owned = get_cstr_path(ctx.as_context_mut(), old_path as *const _);
let real_old_path_owned = get_cstr_path(ctx.as_mut(), old_path as *const _);
let real_old_path = if let Some(ref rp) = real_old_path_owned {
rp.as_c_str().as_ptr()
} else {
@@ -190,7 +190,7 @@ pub fn ___syscall38(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs:
}
// rmdir
pub fn ___syscall40(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall40(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall40 (rmdir)");
let pathname_addr = varargs.get_str(&ctx);
let real_path_owned = get_cstr_path(ctx, pathname_addr as *const _);
@@ -203,7 +203,7 @@ pub fn ___syscall40(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarA
}
// pipe
pub fn ___syscall42(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall42(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall42 (pipe)");
// offset to a file descriptor, which contains a read end and write end, 2 integers
let fd_offset: u32 = varargs.get(&ctx);
@@ -230,28 +230,28 @@ pub fn ___syscall42(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarA
result
}
pub fn ___syscall51(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall51(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall51");
-1
}
pub fn ___syscall52(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall52(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall52");
-1
}
pub fn ___syscall53(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall53(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall53");
-1
}
pub fn ___syscall60(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall60(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall60");
-1
}
// dup2
pub fn ___syscall63(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall63(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall63 (dup2) {}", _which);
let src: i32 = varargs.get(&ctx);
@@ -261,97 +261,97 @@ pub fn ___syscall63(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarA
}
// getppid
pub fn ___syscall64(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall64(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall64 (getppid)");
unsafe { getpid() }
}
pub fn ___syscall66(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall66(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall66");
-1
}
pub fn ___syscall75(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall75(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall75");
-1
}
pub fn ___syscall91(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall91(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall91 - stub");
0
}
pub fn ___syscall96(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall96(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall96");
-1
}
pub fn ___syscall97(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall97(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall97");
-1
}
pub fn ___syscall110(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall110(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall110");
-1
}
pub fn ___syscall121(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall121(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall121");
-1
}
pub fn ___syscall125(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall125(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall125");
-1
}
pub fn ___syscall133(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall133(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall133");
-1
}
pub fn ___syscall144(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall144(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall144");
-1
}
pub fn ___syscall147(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall147(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall147");
-1
}
pub fn ___syscall150(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall150(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall150");
-1
}
pub fn ___syscall151(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall151(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall151");
-1
}
pub fn ___syscall152(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall152(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall152");
-1
}
pub fn ___syscall153(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall153(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall153");
-1
}
pub fn ___syscall163(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall163(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall163");
-1
}
// getcwd
pub fn ___syscall183(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> i32 {
pub fn ___syscall183(mut ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> i32 {
debug!("emscripten::___syscall183");
let buf_offset: WasmPtr<libc::c_char> = varargs.get(&ctx);
let _size: c_int = varargs.get(&ctx);
let path = get_current_directory(ctx.as_context_mut());
let path = get_current_directory(ctx.as_mut());
let path_string = path.unwrap().display().to_string();
let len = path_string.len();
let memory = ctx.data().memory(0);
@@ -365,7 +365,7 @@ pub fn ___syscall183(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs:
}
// mmap2
pub fn ___syscall192(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall192(mut ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall192 (mmap2) {}", _which);
let _addr: i32 = varargs.get(&ctx);
let len: u32 = varargs.get(&ctx);
@@ -379,13 +379,13 @@ pub fn ___syscall192(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs:
);
if fd == -1 {
let ptr = env::call_memalign(ctx.as_context_mut(), 16384, len);
let ptr = env::call_memalign(&mut ctx, 16384, len);
if ptr == 0 {
// ENOMEM
return -12;
}
let real_ptr = emscripten_memory_pointer!(ctx, ctx.data().memory(0), ptr) as *const u8;
env::call_memset(ctx, ptr, 0, len);
env::call_memset(&mut ctx, ptr, 0, len);
for i in 0..(len as usize) {
unsafe {
assert_eq!(*real_ptr.add(i), 0);
@@ -400,7 +400,7 @@ pub fn ___syscall192(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs:
}
/// lseek
pub fn ___syscall140(ctx: ContextMut<'_, EmEnv>, _which: i32, mut varargs: VarArgs) -> i32 {
pub fn ___syscall140(ctx: FunctionEnvMut<EmEnv>, _which: i32, mut varargs: VarArgs) -> i32 {
// -> c_int
debug!("emscripten::___syscall140 (lseek) {}", _which);
let fd: i32 = varargs.get(&ctx);
@@ -429,7 +429,7 @@ pub fn ___syscall140(ctx: ContextMut<'_, EmEnv>, _which: i32, mut varargs: VarAr
/// readv
#[allow(clippy::cast_ptr_alignment)]
pub fn ___syscall145(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> i32 {
pub fn ___syscall145(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> i32 {
// -> ssize_t
debug!("emscripten::___syscall145 (readv) {}", _which);
@@ -468,7 +468,7 @@ pub fn ___syscall145(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: Var
// writev
#[allow(clippy::cast_ptr_alignment)]
pub fn ___syscall146(ctx: ContextMut<'_, EmEnv>, _which: i32, mut varargs: VarArgs) -> i32 {
pub fn ___syscall146(ctx: FunctionEnvMut<EmEnv>, _which: i32, mut varargs: VarArgs) -> i32 {
// -> ssize_t
debug!("emscripten::___syscall146 (writev) {}", _which);
let fd: i32 = varargs.get(&ctx);
@@ -511,7 +511,7 @@ pub fn ___syscall146(ctx: ContextMut<'_, EmEnv>, _which: i32, mut varargs: VarAr
ret as _
}
pub fn ___syscall191(ctx: ContextMut<'_, EmEnv>, _which: i32, mut varargs: VarArgs) -> i32 {
pub fn ___syscall191(ctx: FunctionEnvMut<EmEnv>, _which: i32, mut varargs: VarArgs) -> i32 {
let _resource: i32 = varargs.get(&ctx);
debug!(
"emscripten::___syscall191 - mostly stub, resource: {}",
@@ -528,18 +528,18 @@ pub fn ___syscall191(ctx: ContextMut<'_, EmEnv>, _which: i32, mut varargs: VarAr
0
}
pub fn ___syscall193(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall193(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall193");
-1
}
// stat64
pub fn ___syscall195(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall195(mut ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall195 (stat64) {}", _which);
let pathname_addr = varargs.get_str(&ctx);
let buf: u32 = varargs.get(&ctx);
let real_path_owned = get_cstr_path(ctx.as_context_mut(), pathname_addr as *const _);
let real_path_owned = get_cstr_path(ctx.as_mut(), pathname_addr as *const _);
let real_path = if let Some(ref rp) = real_path_owned {
rp.as_c_str().as_ptr()
} else {
@@ -565,7 +565,7 @@ pub fn ___syscall195(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs:
}
// fstat64
pub fn ___syscall197(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall197(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall197 (fstat64) {}", _which);
let fd: c_int = varargs.get(&ctx);
@@ -584,129 +584,129 @@ pub fn ___syscall197(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: Var
0
}
pub fn ___syscall209(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall209(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall209");
-1
}
pub fn ___syscall211(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall211(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall211");
-1
}
pub fn ___syscall218(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall218(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall218");
-1
}
pub fn ___syscall268(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall268(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall268");
-1
}
pub fn ___syscall269(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall269(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall269");
-1
}
pub fn ___syscall272(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall272(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall272");
-1
}
pub fn ___syscall295(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall295(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall295");
-1
}
pub fn ___syscall296(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall296(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall296");
-1
}
pub fn ___syscall297(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall297(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall297");
-1
}
pub fn ___syscall298(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall298(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall298");
-1
}
pub fn ___syscall300(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall300(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall300");
-1
}
pub fn ___syscall301(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall301(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall301");
-1
}
pub fn ___syscall302(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall302(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall302");
-1
}
pub fn ___syscall303(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall303(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall303");
-1
}
pub fn ___syscall304(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall304(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall304");
-1
}
pub fn ___syscall305(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall305(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall305");
-1
}
pub fn ___syscall306(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall306(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall306");
-1
}
pub fn ___syscall307(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall307(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall307");
-1
}
pub fn ___syscall308(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall308(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall308");
-1
}
// utimensat
pub fn ___syscall320(_ctx: ContextMut<'_, EmEnv>, _which: c_int, mut _varargs: VarArgs) -> c_int {
pub fn ___syscall320(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall320 (utimensat), {}", _which);
0
}
pub fn ___syscall331(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall331(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall331");
-1
}
pub fn ___syscall333(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall333(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall333");
-1
}
pub fn ___syscall334(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall334(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall334");
-1
}
pub fn ___syscall337(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall337(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall337");
-1
}
// prlimit64
pub fn ___syscall340(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall340(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall340 (prlimit64), {}", _which);
// NOTE: Doesn't really matter. Wasm modules cannot exceed WASM_PAGE_SIZE anyway.
let _pid: i32 = varargs.get(&ctx);
@@ -732,7 +732,7 @@ pub fn ___syscall340(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: Var
0
}
pub fn ___syscall345(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall345(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall345");
-1
}

View File

@@ -81,7 +81,7 @@ use libc::{
// TCGETS,
// TCSETSW,
};
use wasmer::{AsContextMut, ContextMut, ValueType, WasmPtr};
use wasmer::{FunctionEnvMut, ValueType, WasmPtr};
// They are not exposed in in Rust libc in macOS
const TCGETS: u64 = 0x5401;
@@ -157,12 +157,12 @@ use libc::SO_NOSIGPIPE;
const SO_NOSIGPIPE: c_int = 0;
/// open
pub fn ___syscall5(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall5(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall5 (open) {}", _which);
let pathname_addr = varargs.get_str(&ctx);
let flags: i32 = varargs.get(&ctx);
let mode: u32 = varargs.get(&ctx);
let real_path_owned = utils::get_cstr_path(ctx.as_context_mut(), pathname_addr as *const _);
let real_path_owned = utils::get_cstr_path(ctx, pathname_addr as *const _);
let real_path = if let Some(ref rp) = real_path_owned {
rp.as_c_str().as_ptr()
} else {
@@ -181,7 +181,7 @@ pub fn ___syscall5(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: V
}
/// link
pub fn ___syscall9(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall9(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall9 (link) {}", _which);
let oldname_ptr = varargs.get_str(&ctx);
@@ -197,7 +197,7 @@ pub fn ___syscall9(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarAr
}
/// getrusage
pub fn ___syscall77(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall77(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall77 (getrusage) {}", _which);
let resource: c_int = varargs.get(&ctx);
@@ -209,18 +209,18 @@ pub fn ___syscall77(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarA
}
/// symlink
pub fn ___syscall83(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall83(mut ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall83 (symlink) {}", _which);
let path1 = varargs.get_str(&ctx);
let path2 = varargs.get_str(&ctx);
let real_path1_owned = utils::get_cstr_path(ctx.as_context_mut(), path1 as *const _);
let real_path1_owned = utils::get_cstr_path(ctx.as_mut(), path1 as *const _);
let real_path1 = if let Some(ref rp) = real_path1_owned {
rp.as_c_str().as_ptr()
} else {
path1
};
let real_path2_owned = utils::get_cstr_path(ctx.as_context_mut(), path2 as *const _);
let real_path2_owned = utils::get_cstr_path(ctx, path2 as *const _);
let real_path2 = if let Some(ref rp) = real_path2_owned {
rp.as_c_str().as_ptr()
} else {
@@ -237,13 +237,13 @@ pub fn ___syscall83(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs:
}
/// readlink
pub fn ___syscall85(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> i32 {
pub fn ___syscall85(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> i32 {
debug!("emscripten::___syscall85 (readlink)");
let pathname_addr = varargs.get_str(&ctx);
let buf = varargs.get_str(&ctx);
// let buf_addr: i32 = varargs.get(&ctx);
let buf_size: i32 = varargs.get(&ctx);
let real_path_owned = get_cstr_path(ctx.as_context_mut(), pathname_addr as *const _);
let real_path_owned = get_cstr_path(ctx, pathname_addr as *const _);
let real_path = if let Some(ref rp) = real_path_owned {
rp.as_c_str().as_ptr()
} else {
@@ -266,7 +266,7 @@ pub fn ___syscall85(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs:
}
/// ftruncate64
pub fn ___syscall194(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall194(ctx: FunctionEnvMut<EmEnv>, _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);
@@ -283,10 +283,10 @@ pub fn ___syscall194(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: Var
}
/// lchown
pub fn ___syscall198(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall198(mut ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall198 (lchown) {}", _which);
let path_ptr = varargs.get_str(&ctx);
let real_path_owned = utils::get_cstr_path(ctx.as_context_mut(), path_ptr as *const _);
let real_path_owned = utils::get_cstr_path(ctx.as_mut(), path_ptr as *const _);
let real_path = if let Some(ref rp) = real_path_owned {
rp.as_c_str().as_ptr()
} else {
@@ -306,7 +306,7 @@ pub fn ___syscall198(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs:
}
/// getgroups
pub fn ___syscall205(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall205(ctx: FunctionEnvMut<EmEnv>, _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);
@@ -323,11 +323,11 @@ pub fn ___syscall205(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: Var
}
// chown
pub fn ___syscall212(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall212(mut ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall212 (chown) {}", _which);
let pathname_addr = varargs.get_str(&ctx);
let real_path_owned = utils::get_cstr_path(ctx.as_context_mut(), pathname_addr as *const _);
let real_path_owned = utils::get_cstr_path(ctx.as_mut(), pathname_addr as *const _);
let real_path = if let Some(ref rp) = real_path_owned {
rp.as_c_str().as_ptr()
} else {
@@ -340,7 +340,7 @@ pub fn ___syscall212(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs:
}
/// madvise
pub fn ___syscall219(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall219(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall212 (chown) {}", _which);
let addr_ptr: c_int = varargs.get(&ctx);
@@ -353,10 +353,10 @@ pub fn ___syscall219(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: Var
}
/// access
pub fn ___syscall33(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall33(mut ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall33 (access) {}", _which);
let path = varargs.get_str(&ctx);
let real_path_owned = utils::get_cstr_path(ctx.as_context_mut(), path as *const _);
let real_path_owned = utils::get_cstr_path(ctx.as_mut(), path as *const _);
let real_path = if let Some(ref rp) = real_path_owned {
rp.as_c_str().as_ptr()
} else {
@@ -374,17 +374,17 @@ pub fn ___syscall33(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs:
}
/// nice
pub fn ___syscall34(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall34(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall34 (nice) {}", _which);
let inc_r: c_int = varargs.get(&ctx);
unsafe { nice(inc_r) }
}
// mkdir
pub fn ___syscall39(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall39(mut ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall39 (mkdir) {}", _which);
let pathname_addr = varargs.get_str(&ctx);
let real_path_owned = utils::get_cstr_path(ctx.as_context_mut(), pathname_addr as *const _);
let real_path_owned = utils::get_cstr_path(ctx.as_mut(), pathname_addr as *const _);
let real_path = if let Some(ref rp) = real_path_owned {
rp.as_c_str().as_ptr()
} else {
@@ -395,20 +395,20 @@ pub fn ___syscall39(mut ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs:
}
/// dup
pub fn ___syscall41(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall41(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall41 (dup) {}", _which);
let fd: c_int = varargs.get(&ctx);
unsafe { dup(fd) }
}
/// getgid32
pub fn ___syscall200(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall200(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall200 (getgid32)");
unsafe { getgid() as i32 }
}
// geteuid32
pub fn ___syscall201(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall201(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall201 (geteuid32)");
unsafe {
// Maybe fix: Emscripten returns 0 always
@@ -417,7 +417,7 @@ pub fn ___syscall201(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
}
// getegid32
pub fn ___syscall202(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall202(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
// gid_t
debug!("emscripten::___syscall202 (getegid32)");
unsafe {
@@ -427,7 +427,7 @@ pub fn ___syscall202(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
}
/// fchown
pub fn ___syscall207(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall207(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall207 (fchown) {}", _which);
let fd: c_int = varargs.get(&ctx);
let owner: uid_t = varargs.get(&ctx);
@@ -436,7 +436,7 @@ pub fn ___syscall207(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: Var
}
/// dup3
pub fn ___syscall330(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> pid_t {
pub fn ___syscall330(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> pid_t {
// Implementation based on description at https://linux.die.net/man/2/dup3
debug!("emscripten::___syscall330 (dup3)");
let oldfd: c_int = varargs.get(&ctx);
@@ -474,7 +474,7 @@ pub fn ___syscall330(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: Var
}
/// ioctl
pub fn ___syscall54(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall54(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall54 (ioctl) {}", _which);
let fd: i32 = varargs.get(&ctx);
@@ -517,7 +517,7 @@ const SOCK_CLOEXC: i32 = 0x80000;
// socketcall
#[allow(clippy::cast_ptr_alignment)]
pub fn ___syscall102(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall102(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall102 (socketcall) {}", _which);
let call: u32 = varargs.get(&ctx);
let mut socket_varargs: VarArgs = varargs.get(&ctx);
@@ -833,7 +833,7 @@ fn translate_socket_name_flag(name: i32) -> i32 {
}
/// getpgid
pub fn ___syscall132(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall132(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall132 (getpgid)");
let pid: pid_t = varargs.get(&ctx);
@@ -855,7 +855,7 @@ pub struct EmPollFd {
}
/// poll
pub fn ___syscall168(ctx: ContextMut<'_, EmEnv>, _which: i32, mut varargs: VarArgs) -> i32 {
pub fn ___syscall168(ctx: FunctionEnvMut<EmEnv>, _which: i32, mut varargs: VarArgs) -> i32 {
debug!("emscripten::___syscall168(poll)");
let fds: WasmPtr<EmPollFd> = varargs.get(&ctx);
let nfds: u32 = varargs.get(&ctx);
@@ -874,7 +874,7 @@ pub fn ___syscall168(ctx: ContextMut<'_, EmEnv>, _which: i32, mut varargs: VarAr
}
// pread
pub fn ___syscall180(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall180(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall180 (pread) {}", _which);
let fd: i32 = varargs.get(&ctx);
let buf: u32 = varargs.get(&ctx);
@@ -891,7 +891,7 @@ pub fn ___syscall180(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: Var
}
// pwrite
pub fn ___syscall181(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall181(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall181 (pwrite) {}", _which);
let fd: i32 = varargs.get(&ctx);
let buf: u32 = varargs.get(&ctx);
@@ -912,7 +912,7 @@ pub fn ___syscall181(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: Var
}
/// fchmod
pub fn ___syscall94(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall94(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall118 (fchmod) {}", _which);
let fd: c_int = varargs.get(&ctx);
let mode: mode_t = varargs.get(&ctx);
@@ -921,7 +921,7 @@ pub fn ___syscall94(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarA
/// wait4
#[allow(clippy::cast_ptr_alignment)]
pub fn ___syscall114(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> pid_t {
pub fn ___syscall114(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> pid_t {
debug!("emscripten::___syscall114 (wait4)");
let pid: pid_t = varargs.get(&ctx);
let status: u32 = varargs.get(&ctx);
@@ -939,7 +939,7 @@ pub fn ___syscall114(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: Var
}
/// fsync
pub fn ___syscall118(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall118(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall118 (fsync) {}", _which);
let fd: c_int = varargs.get(&ctx);
unsafe { fsync(fd) }
@@ -947,7 +947,7 @@ pub fn ___syscall118(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: Var
// select
#[allow(clippy::cast_ptr_alignment)]
pub fn ___syscall142(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall142(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall142 (newselect) {}", _which);
let nfds: i32 = varargs.get(&ctx);
@@ -969,7 +969,7 @@ pub fn ___syscall142(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: Var
}
/// fdatasync
pub fn ___syscall148(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall148(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall148 (fdatasync) {}", _which);
let fd: i32 = varargs.get(&ctx);
@@ -978,7 +978,7 @@ pub fn ___syscall148(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: Var
}
// setpgid
pub fn ___syscall57(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall57(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall57 (setpgid) {}", _which);
let pid: i32 = varargs.get(&ctx);
@@ -994,7 +994,7 @@ pub fn ___syscall57(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarA
/// uname
// NOTE: Wondering if we should return custom utsname, like Emscripten.
pub fn ___syscall122(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall122(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall122 (uname) {}", _which);
let buf: u32 = varargs.get(&ctx);
debug!("=> buf: {}", buf);
@@ -1003,10 +1003,10 @@ pub fn ___syscall122(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: Var
}
/// lstat64
pub fn ___syscall196(mut ctx: ContextMut<'_, EmEnv>, _which: i32, mut varargs: VarArgs) -> i32 {
pub fn ___syscall196(mut ctx: FunctionEnvMut<EmEnv>, _which: i32, mut varargs: VarArgs) -> i32 {
debug!("emscripten::___syscall196 (lstat64) {}", _which);
let path = varargs.get_str(&ctx);
let real_path_owned = utils::get_cstr_path(ctx.as_context_mut(), path as *const _);
let real_path_owned = utils::get_cstr_path(ctx.as_mut(), path as *const _);
let real_path = if let Some(ref rp) = real_path_owned {
rp.as_c_str().as_ptr()
} else {
@@ -1036,7 +1036,7 @@ pub fn ___syscall196(mut ctx: ContextMut<'_, EmEnv>, _which: i32, mut varargs: V
}
// getuid
pub fn ___syscall199(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall199(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall199 (getuid)");
let uid = unsafe { getuid() as _ };
debug!(" => {}", uid);
@@ -1046,7 +1046,7 @@ pub fn ___syscall199(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
// getdents
// dirent structure is
// i64, i64, u16 (280), i8, [i8; 256]
pub fn ___syscall220(ctx: ContextMut<'_, EmEnv>, _which: i32, mut varargs: VarArgs) -> i32 {
pub fn ___syscall220(ctx: FunctionEnvMut<EmEnv>, _which: i32, mut varargs: VarArgs) -> i32 {
use super::super::env::get_emscripten_data;
let fd: i32 = varargs.get(&ctx);
@@ -1111,7 +1111,7 @@ pub fn ___syscall220(ctx: ContextMut<'_, EmEnv>, _which: i32, mut varargs: VarAr
}
// fcntl64
pub fn ___syscall221(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall221(ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall221 (fcntl64) {}", _which);
let fd: i32 = varargs.get(&ctx);
let cmd: i32 = varargs.get(&ctx);
@@ -1129,7 +1129,7 @@ pub fn ___syscall221(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: Var
}
/// fallocate
pub fn ___syscall324(ctx: ContextMut<'_, EmEnv>, _which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall324(ctx: FunctionEnvMut<EmEnv>, _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);

View File

@@ -8,18 +8,18 @@ use std::ffi::CString;
use std::fs::File;
use std::io::Write;
use std::os::raw::c_int;
use wasmer::{AsContextMut, ContextMut};
use wasmer::FunctionEnvMut;
#[allow(non_camel_case_types)]
type pid_t = c_int;
/// open
pub fn ___syscall5(mut ctx: ContextMut<'_, EmEnv>, which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall5(mut ctx: FunctionEnvMut<EmEnv>, which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall5 (open) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
let pathname_addr = varargs.get_str(&ctx);
let real_path_owned = get_cstr_path(ctx.as_context_mut(), pathname_addr);
let real_path_owned = get_cstr_path(ctx.as_mut(), pathname_addr);
let real_path = if let Some(ref rp) = real_path_owned {
rp.as_c_str().as_ptr()
} else {
@@ -45,7 +45,7 @@ pub fn ___syscall5(mut ctx: ContextMut<'_, EmEnv>, which: c_int, mut varargs: Va
getrandom::getrandom(&mut random_bytes).unwrap();
let _ = urandom_file.write_all(&random_bytes).unwrap();
// put the file path string into wasm memory
let urandom_file_offset = unsafe { copy_cstr_into_wasm(ctx.as_context_mut(), ptr) };
let urandom_file_offset = unsafe { copy_cstr_into_wasm(&mut ctx, ptr) };
let raw_pointer_to_urandom_file =
emscripten_memory_pointer!(ctx, memory, urandom_file_offset) as *const i8;
let fd = unsafe { open(raw_pointer_to_urandom_file, flags, mode) };
@@ -67,19 +67,19 @@ pub fn ___syscall5(mut ctx: ContextMut<'_, EmEnv>, which: c_int, mut varargs: Va
}
/// link
pub fn ___syscall9(_ctx: ContextMut<'_, EmEnv>, _which: c_int, mut _varargs: VarArgs) -> c_int {
pub fn ___syscall9(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall9 (link) {}", _which);
unimplemented!("emscripten::___syscall9 (link) {}", _which);
}
/// ftruncate64
pub fn ___syscall194(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall194(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall194 - stub");
unimplemented!("emscripten::___syscall194 - stub")
}
// chown
pub fn ___syscall212(_ctx: ContextMut<'_, EmEnv>, which: c_int, mut _varargs: VarArgs) -> c_int {
pub fn ___syscall212(_ctx: FunctionEnvMut<EmEnv>, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall212 (chown) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
@@ -87,19 +87,19 @@ pub fn ___syscall212(_ctx: ContextMut<'_, EmEnv>, which: c_int, mut _varargs: Va
}
/// access
pub fn ___syscall33(_ctx: ContextMut<'_, EmEnv>, _which: c_int, mut _varargs: VarArgs) -> c_int {
pub fn ___syscall33(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall33 (access) {}", _which);
unimplemented!("emscripten::___syscall33 (access) {}", _which);
}
/// nice
pub fn ___syscall34(_ctx: ContextMut<'_, EmEnv>, _which: c_int, mut _varargs: VarArgs) -> c_int {
pub fn ___syscall34(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall34 (nice) {}", _which);
unimplemented!("emscripten::___syscall34 (nice) {}", _which);
}
// mkdir
pub fn ___syscall39(ctx: ContextMut<'_, EmEnv>, which: c_int, mut varargs: VarArgs) -> c_int {
pub fn ___syscall39(ctx: FunctionEnvMut<EmEnv>, which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall39 (mkdir) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
@@ -114,80 +114,80 @@ pub fn ___syscall39(ctx: ContextMut<'_, EmEnv>, which: c_int, mut varargs: VarAr
}
/// dup
pub fn ___syscall41(_ctx: ContextMut<'_, EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
pub fn ___syscall41(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall41 (dup) {}", _which);
unimplemented!("emscripten::___syscall41 (dup) {}", _which);
}
/// getrusage
pub fn ___syscall77(_ctx: ContextMut<'_, EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
pub fn ___syscall77(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall77 (getrusage) {}", _which);
unimplemented!("emscripten::___syscall77 (getrusage) {}", _which);
}
/// symlink
pub fn ___syscall83(_ctx: ContextMut<'_, EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
pub fn ___syscall83(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall83 (symlink) {}", _which);
unimplemented!("emscripten::___syscall83 (symlink) {}", _which);
}
/// readlink
pub fn ___syscall85(_ctx: ContextMut<'_, EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
pub fn ___syscall85(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall85 (readlink) {}", _which);
-1
}
/// getpgid
pub fn ___syscall132(_ctx: ContextMut<'_, EmEnv>, _which: c_int, mut _varargs: VarArgs) -> c_int {
pub fn ___syscall132(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall132 (getpgid)");
-1
}
/// lchown
pub fn ___syscall198(_ctx: ContextMut<'_, EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
pub fn ___syscall198(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall198 (lchown) {}", _which);
unimplemented!("emscripten::___syscall198 (lchown) {}", _which);
}
/// getgid32
pub fn ___syscall200(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall200(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall200 (getgid32)");
unimplemented!("emscripten::___syscall200 (getgid32)");
}
// geteuid32
pub fn ___syscall201(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall201(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall201 (geteuid32)");
unimplemented!("emscripten::___syscall201 (geteuid32)");
}
// getegid32
pub fn ___syscall202(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall202(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
// gid_t
debug!("emscripten::___syscall202 (getegid32)");
unimplemented!("emscripten::___syscall202 (getegid32)");
}
/// getgroups
pub fn ___syscall205(_ctx: ContextMut<'_, EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
pub fn ___syscall205(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall205 (getgroups) {}", _which);
unimplemented!("emscripten::___syscall205 (getgroups) {}", _which);
}
/// madvise
pub fn ___syscall219(_ctx: ContextMut<'_, EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
pub fn ___syscall219(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall212 (chown) {}", _which);
unimplemented!("emscripten::___syscall212 (chown) {}", _which);
}
/// dup3
pub fn ___syscall330(_ctx: ContextMut<'_, EmEnv>, _which: c_int, mut _varargs: VarArgs) -> pid_t {
pub fn ___syscall330(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut _varargs: VarArgs) -> pid_t {
debug!("emscripten::___syscall330 (dup3)");
-1
}
/// ioctl
pub fn ___syscall54(_ctx: ContextMut<'_, EmEnv>, which: c_int, mut _varargs: VarArgs) -> c_int {
pub fn ___syscall54(_ctx: FunctionEnvMut<EmEnv>, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall54 (ioctl) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
@@ -195,14 +195,14 @@ pub fn ___syscall54(_ctx: ContextMut<'_, EmEnv>, which: c_int, mut _varargs: Var
}
/// fchmod
pub fn ___syscall94(_ctx: ContextMut<'_, EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
pub fn ___syscall94(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall118 (fchmod) {}", _which);
unimplemented!("emscripten::___syscall118 (fchmod) {}", _which);
}
// socketcall
#[allow(clippy::cast_ptr_alignment)]
pub fn ___syscall102(_ctx: ContextMut<'_, EmEnv>, which: c_int, mut _varargs: VarArgs) -> c_int {
pub fn ___syscall102(_ctx: FunctionEnvMut<EmEnv>, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall102 (socketcall) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
@@ -210,13 +210,13 @@ pub fn ___syscall102(_ctx: ContextMut<'_, EmEnv>, which: c_int, mut _varargs: Va
}
/// fsync
pub fn ___syscall118(_ctx: ContextMut<'_, EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
pub fn ___syscall118(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall118 (fsync) {}", _which);
unimplemented!("emscripten::___syscall118 (fsync) {}", _which);
}
// pread
pub fn ___syscall180(_ctx: ContextMut<'_, EmEnv>, which: c_int, mut _varargs: VarArgs) -> c_int {
pub fn ___syscall180(_ctx: FunctionEnvMut<EmEnv>, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall180 (pread) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
@@ -224,7 +224,7 @@ pub fn ___syscall180(_ctx: ContextMut<'_, EmEnv>, which: c_int, mut _varargs: Va
}
// pwrite
pub fn ___syscall181(_ctx: ContextMut<'_, EmEnv>, which: c_int, mut _varargs: VarArgs) -> c_int {
pub fn ___syscall181(_ctx: FunctionEnvMut<EmEnv>, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall181 (pwrite) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
@@ -233,14 +233,14 @@ pub fn ___syscall181(_ctx: ContextMut<'_, EmEnv>, which: c_int, mut _varargs: Va
/// wait4
#[allow(clippy::cast_ptr_alignment)]
pub fn ___syscall114(_ctx: ContextMut<'_, EmEnv>, _which: c_int, mut _varargs: VarArgs) -> pid_t {
pub fn ___syscall114(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut _varargs: VarArgs) -> pid_t {
debug!("emscripten::___syscall114 (wait4)");
-1
}
// select
#[allow(clippy::cast_ptr_alignment)]
pub fn ___syscall142(_ctx: ContextMut<'_, EmEnv>, which: c_int, mut _varargs: VarArgs) -> c_int {
pub fn ___syscall142(_ctx: FunctionEnvMut<EmEnv>, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall142 (newselect) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
@@ -248,13 +248,13 @@ pub fn ___syscall142(_ctx: ContextMut<'_, EmEnv>, which: c_int, mut _varargs: Va
}
/// fdatasync
pub fn ___syscall148(_ctx: ContextMut<'_, EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
pub fn ___syscall148(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall148 (fdatasync) {}", _which);
unimplemented!("emscripten::___syscall148 (fdatasync) {}", _which);
}
// setpgid
pub fn ___syscall57(_ctx: ContextMut<'_, EmEnv>, which: c_int, mut _varargs: VarArgs) -> c_int {
pub fn ___syscall57(_ctx: FunctionEnvMut<EmEnv>, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall57 (setpgid) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
@@ -263,7 +263,7 @@ pub fn ___syscall57(_ctx: ContextMut<'_, EmEnv>, which: c_int, mut _varargs: Var
/// uname
// NOTE: Wondering if we should return custom utsname, like Emscripten.
pub fn ___syscall122(_ctx: ContextMut<'_, EmEnv>, which: c_int, mut _varargs: VarArgs) -> c_int {
pub fn ___syscall122(_ctx: FunctionEnvMut<EmEnv>, which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall122 (uname) {}", which);
#[cfg(not(feature = "debug"))]
let _ = which;
@@ -271,43 +271,43 @@ pub fn ___syscall122(_ctx: ContextMut<'_, EmEnv>, which: c_int, mut _varargs: Va
}
/// poll
pub fn ___syscall168(_ctx: ContextMut<'_, EmEnv>, _which: i32, _varargs: VarArgs) -> i32 {
pub fn ___syscall168(_ctx: FunctionEnvMut<EmEnv>, _which: i32, _varargs: VarArgs) -> i32 {
debug!("emscripten::___syscall168(poll) - stub");
-1
}
/// lstat64
pub fn ___syscall196(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall196(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall196 (lstat64) - stub");
-1
}
// getuid
pub fn ___syscall199(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall199(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall199 (getuid)");
-1
}
// getdents
pub fn ___syscall220(_ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn ___syscall220(_ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall220");
-1
}
// fcntl64
pub fn ___syscall221(_ctx: ContextMut<'_, EmEnv>, _which: c_int, mut _varargs: VarArgs) -> c_int {
pub fn ___syscall221(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall221 (fcntl64) {}", _which);
-1
}
/// fchown
pub fn ___syscall207(_ctx: ContextMut<'_, EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
pub fn ___syscall207(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall207 (fchown) {}", _which);
unimplemented!("emscripten::___syscall207 (fchown) {}", _which)
}
/// fallocate
pub fn ___syscall324(_ctx: ContextMut<'_, EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
pub fn ___syscall324(_ctx: FunctionEnvMut<EmEnv>, _which: c_int, _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall324 (fallocate) {}", _which);
unimplemented!("emscripten::___syscall324 (fallocate) {}", _which)
}

View File

@@ -13,7 +13,7 @@ use std::ffi::CString;
#[cfg(target_os = "windows")]
use libc::time_t;
use wasmer::{AsContextMut, ContextMut};
use wasmer::FunctionEnvMut;
#[cfg(target_os = "windows")]
#[allow(non_camel_case_types)]
@@ -52,7 +52,7 @@ const CLOCK_MONOTONIC_COARSE: clockid_t = 6;
/// emscripten: _gettimeofday
#[allow(clippy::cast_ptr_alignment)]
pub fn _gettimeofday(ctx: ContextMut<'_, EmEnv>, tp: c_int, tz: c_int) -> c_int {
pub fn _gettimeofday(ctx: FunctionEnvMut<EmEnv>, tp: c_int, tz: c_int) -> c_int {
debug!("emscripten::_gettimeofday {} {}", tp, tz);
#[repr(C)]
struct GuestTimeVal {
@@ -76,7 +76,7 @@ pub fn _gettimeofday(ctx: ContextMut<'_, EmEnv>, tp: c_int, tz: c_int) -> c_int
0
}
pub fn _clock_getres(mut _ctx: ContextMut<'_, EmEnv>, _clk_id: i32, _tp: i32) -> i32 {
pub fn _clock_getres(mut _ctx: FunctionEnvMut<EmEnv>, _clk_id: i32, _tp: i32) -> i32 {
debug!("emscripten::_clock_getres");
// clock_getres(clk_id, tp)
0
@@ -84,7 +84,7 @@ pub fn _clock_getres(mut _ctx: ContextMut<'_, EmEnv>, _clk_id: i32, _tp: i32) ->
/// emscripten: _clock_gettime
#[allow(clippy::cast_ptr_alignment)]
pub fn _clock_gettime(ctx: ContextMut<'_, EmEnv>, clk_id: clockid_t, tp: c_int) -> c_int {
pub fn _clock_gettime(ctx: FunctionEnvMut<EmEnv>, clk_id: clockid_t, tp: c_int) -> c_int {
debug!("emscripten::_clock_gettime {} {}", clk_id, tp);
// debug!("Memory {:?}", ctx.memory(0)[..]);
#[repr(C)]
@@ -116,41 +116,41 @@ pub fn _clock_gettime(ctx: ContextMut<'_, EmEnv>, clk_id: clockid_t, tp: c_int)
0
}
pub fn _clock_settime(mut _ctx: ContextMut<'_, EmEnv>, _clk_id: i32, _tp: i32) -> i32 {
pub fn _clock_settime(mut _ctx: FunctionEnvMut<EmEnv>, _clk_id: i32, _tp: i32) -> i32 {
debug!("emscripten::_clock_settime");
// clock_settime(clk_id, tp)
0
}
/// emscripten: ___clock_gettime
pub fn ___clock_gettime(ctx: ContextMut<'_, EmEnv>, clk_id: clockid_t, tp: c_int) -> c_int {
pub fn ___clock_gettime(ctx: FunctionEnvMut<EmEnv>, clk_id: clockid_t, tp: c_int) -> c_int {
debug!("emscripten::___clock_gettime {} {}", clk_id, tp);
_clock_gettime(ctx, clk_id, tp)
}
/// emscripten: _clock
pub fn _clock(mut _ctx: ContextMut<'_, EmEnv>) -> c_int {
pub fn _clock(mut _ctx: FunctionEnvMut<EmEnv>) -> c_int {
debug!("emscripten::_clock");
0 // TODO: unimplemented
}
/// emscripten: _difftime
pub fn _difftime(mut _ctx: ContextMut<'_, EmEnv>, t0: u32, t1: u32) -> f64 {
pub fn _difftime(mut _ctx: FunctionEnvMut<EmEnv>, t0: u32, t1: u32) -> f64 {
debug!("emscripten::_difftime");
(t0 - t1) as _
}
pub fn _gmtime_r(mut _ctx: ContextMut<'_, EmEnv>, _one: i32, _two: i32) -> i32 {
pub fn _gmtime_r(mut _ctx: FunctionEnvMut<EmEnv>, _one: i32, _two: i32) -> i32 {
debug!("emscripten::_gmtime_r");
-1
}
pub fn _mktime(mut _ctx: ContextMut<'_, EmEnv>, _one: i32) -> i32 {
pub fn _mktime(mut _ctx: FunctionEnvMut<EmEnv>, _one: i32) -> i32 {
debug!("emscripten::_mktime");
-1
}
pub fn _gmtime(mut _ctx: ContextMut<'_, EmEnv>, _one: i32) -> i32 {
pub fn _gmtime(mut _ctx: FunctionEnvMut<EmEnv>, _one: i32) -> i32 {
debug!("emscripten::_gmtime");
-1
}
@@ -171,13 +171,13 @@ struct guest_tm {
}
/// emscripten: _tvset
pub fn _tvset(mut _ctx: ContextMut<'_, EmEnv>) {
pub fn _tvset(mut _ctx: FunctionEnvMut<EmEnv>) {
debug!("emscripten::_tvset UNIMPLEMENTED");
}
/// formats time as a C string
#[allow(clippy::cast_ptr_alignment)]
unsafe fn fmt_time(ctx: ContextMut<'_, EmEnv>, time: u32) -> *const c_char {
unsafe fn fmt_time(ctx: FunctionEnvMut<EmEnv>, time: u32) -> *const c_char {
let date = &*(emscripten_memory_pointer!(ctx, ctx.data().memory(0), time) as *mut guest_tm);
let days = vec!["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
@@ -202,12 +202,12 @@ unsafe fn fmt_time(ctx: ContextMut<'_, EmEnv>, time: u32) -> *const c_char {
}
/// emscripten: _asctime
pub fn _asctime(mut ctx: ContextMut<'_, EmEnv>, time: u32) -> u32 {
pub fn _asctime(mut ctx: FunctionEnvMut<EmEnv>, time: u32) -> u32 {
debug!("emscripten::_asctime {}", time);
unsafe {
let time_str_ptr = fmt_time(ctx.as_context_mut(), time);
copy_cstr_into_wasm(ctx, time_str_ptr)
let time_str_ptr = fmt_time(ctx.as_mut(), time);
copy_cstr_into_wasm(&mut ctx, time_str_ptr)
// let c_str = emscripten_memory_pointer!(ctx, ctx.data().memory(0), res) as *mut i8;
// use std::ffi::CStr;
@@ -216,7 +216,7 @@ pub fn _asctime(mut ctx: ContextMut<'_, EmEnv>, time: u32) -> u32 {
}
/// emscripten: _asctime_r
pub fn _asctime_r(mut ctx: ContextMut<'_, EmEnv>, time: u32, buf: u32) -> u32 {
pub fn _asctime_r(mut ctx: FunctionEnvMut<EmEnv>, time: u32, buf: u32) -> u32 {
debug!("emscripten::_asctime_r {}, {}", time, buf);
unsafe {
@@ -224,7 +224,7 @@ pub fn _asctime_r(mut ctx: ContextMut<'_, EmEnv>, time: u32, buf: u32) -> u32 {
// to write out more than 26 bytes (including the null terminator).
// See http://pubs.opengroup.org/onlinepubs/9699919799/functions/asctime.html
// Our undefined behavior is to truncate the write to at most 26 bytes, including null terminator.
let time_str_ptr = fmt_time(ctx.as_context_mut(), time);
let time_str_ptr = fmt_time(ctx.as_mut(), time);
write_to_buf(ctx, time_str_ptr, buf, 26)
// let c_str = emscripten_memory_pointer!(ctx, ctx.data().memory(0), res) as *mut i8;
@@ -235,7 +235,7 @@ pub fn _asctime_r(mut ctx: ContextMut<'_, EmEnv>, time: u32, buf: u32) -> u32 {
/// emscripten: _localtime
#[allow(clippy::cast_ptr_alignment)]
pub fn _localtime(mut ctx: ContextMut<'_, EmEnv>, time_p: u32) -> c_int {
pub fn _localtime(mut ctx: FunctionEnvMut<EmEnv>, time_p: u32) -> c_int {
debug!("emscripten::_localtime {}", time_p);
// NOTE: emscripten seems to want tzset() called in this function
// https://stackoverflow.com/questions/19170721/real-time-awareness-of-timezone-change-in-localtime-vs-localtime-r
@@ -247,8 +247,7 @@ pub fn _localtime(mut ctx: ContextMut<'_, EmEnv>, time_p: u32) -> c_int {
};
unsafe {
let tm_struct_offset =
env::call_malloc(ctx.as_context_mut(), mem::size_of::<guest_tm>() as _);
let tm_struct_offset = env::call_malloc(&mut ctx, mem::size_of::<guest_tm>() as _);
let tm_struct_ptr = emscripten_memory_pointer!(ctx, ctx.data().memory(0), tm_struct_offset)
as *mut guest_tm;
// debug!(
@@ -273,7 +272,7 @@ pub fn _localtime(mut ctx: ContextMut<'_, EmEnv>, time_p: u32) -> c_int {
}
/// emscripten: _localtime_r
#[allow(clippy::cast_ptr_alignment)]
pub fn _localtime_r(ctx: ContextMut<'_, EmEnv>, time_p: u32, result: u32) -> c_int {
pub fn _localtime_r(ctx: FunctionEnvMut<EmEnv>, time_p: u32, result: u32) -> c_int {
debug!("emscripten::_localtime_r {}", time_p);
// NOTE: emscripten seems to want tzset() called in this function
@@ -310,7 +309,7 @@ pub fn _localtime_r(ctx: ContextMut<'_, EmEnv>, time_p: u32, result: u32) -> c_i
/// emscripten: _time
#[allow(clippy::cast_ptr_alignment)]
pub fn _time(ctx: ContextMut<'_, EmEnv>, time_p: u32) -> i32 {
pub fn _time(ctx: FunctionEnvMut<EmEnv>, time_p: u32) -> i32 {
debug!("emscripten::_time {}", time_p);
unsafe {
@@ -319,18 +318,18 @@ pub fn _time(ctx: ContextMut<'_, EmEnv>, time_p: u32) -> i32 {
}
}
pub fn _ctime_r(mut ctx: ContextMut<'_, EmEnv>, time_p: u32, buf: u32) -> u32 {
pub fn _ctime_r(mut ctx: FunctionEnvMut<EmEnv>, time_p: u32, buf: u32) -> u32 {
debug!("emscripten::_ctime_r {} {}", time_p, buf);
// var stack = stackSave();
let (result_offset, _result_slice): (u32, &mut [u8]) =
unsafe { allocate_on_stack(&mut ctx.as_context_mut(), 44) };
let time = _localtime_r(ctx.as_context_mut(), time_p, result_offset) as u32;
unsafe { allocate_on_stack(&mut ctx, 44) };
let time = _localtime_r(ctx.as_mut(), time_p, result_offset) as u32;
_asctime_r(ctx, time, buf)
// stackRestore(stack);
}
pub fn _ctime(ctx: ContextMut<'_, EmEnv>, time_p: u32) -> u32 {
pub fn _ctime(ctx: FunctionEnvMut<EmEnv>, time_p: u32) -> u32 {
debug!("emscripten::_ctime {}", time_p);
let tm_current = 2414544;
_ctime_r(ctx, time_p, tm_current)
@@ -339,7 +338,7 @@ pub fn _ctime(ctx: ContextMut<'_, EmEnv>, time_p: u32) -> u32 {
/// emscripten: _timegm
#[cfg(not(target_os = "windows"))]
#[allow(clippy::cast_ptr_alignment)]
pub fn _timegm(ctx: ContextMut<'_, EmEnv>, time_ptr: u32) -> i32 {
pub fn _timegm(ctx: FunctionEnvMut<EmEnv>, time_ptr: u32) -> i32 {
debug!("emscripten::_timegm {}", time_ptr);
unsafe {
@@ -380,7 +379,7 @@ pub fn _timegm(ctx: ContextMut<'_, EmEnv>, time_ptr: u32) -> i32 {
}
#[cfg(target_os = "windows")]
pub fn _timegm(mut _ctx: ContextMut<'_, EmEnv>, _time_ptr: c_int) -> i32 {
pub fn _timegm(mut _ctx: FunctionEnvMut<EmEnv>, _time_ptr: c_int) -> i32 {
debug!(
"emscripten::_timegm - UNIMPLEMENTED IN WINDOWS {}",
_time_ptr
@@ -390,7 +389,7 @@ pub fn _timegm(mut _ctx: ContextMut<'_, EmEnv>, _time_ptr: c_int) -> i32 {
/// emscripten: _strftime
pub fn _strftime(
ctx: ContextMut<'_, EmEnv>,
ctx: FunctionEnvMut<EmEnv>,
s_ptr: c_int,
maxsize: u32,
format_ptr: c_int,
@@ -443,7 +442,7 @@ pub fn _strftime(
/// emscripten: _strftime_l
pub fn _strftime_l(
ctx: ContextMut<'_, EmEnv>,
ctx: FunctionEnvMut<EmEnv>,
s_ptr: c_int,
maxsize: u32,
format_ptr: c_int,

View File

@@ -1,12 +1,12 @@
use crate::EmEnv;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
pub fn _getcontext(mut _ctx: ContextMut<'_, EmEnv>, _ucp: i32) -> i32 {
pub fn _getcontext(mut _ctx: FunctionEnvMut<EmEnv>, _ucp: i32) -> i32 {
debug!("emscripten::_getcontext({})", _ucp);
0
}
pub fn _makecontext(
mut _ctx: ContextMut<'_, EmEnv>,
mut _ctx: FunctionEnvMut<EmEnv>,
_ucp: i32,
_func: i32,
_argc: i32,
@@ -17,11 +17,11 @@ pub fn _makecontext(
_ucp, _func, _argc, _argv
);
}
pub fn _setcontext(mut _ctx: ContextMut<'_, EmEnv>, _ucp: i32) -> i32 {
pub fn _setcontext(mut _ctx: FunctionEnvMut<EmEnv>, _ucp: i32) -> i32 {
debug!("emscripten::_setcontext({})", _ucp);
0
}
pub fn _swapcontext(mut _ctx: ContextMut<'_, EmEnv>, _oucp: i32, _ucp: i32) -> i32 {
pub fn _swapcontext(mut _ctx: FunctionEnvMut<EmEnv>, _oucp: i32, _ucp: i32) -> i32 {
debug!("emscripten::_swapcontext({}, {})", _oucp, _ucp);
0
}

View File

@@ -1,7 +1,7 @@
use crate::EmEnv;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
pub fn confstr(mut _ctx: ContextMut<'_, EmEnv>, _name: i32, _buf_pointer: i32, _len: i32) -> i32 {
pub fn confstr(mut _ctx: FunctionEnvMut<EmEnv>, _name: i32, _buf_pointer: i32, _len: i32) -> i32 {
debug!("unistd::confstr({}, {}, {})", _name, _buf_pointer, _len);
0
}

View File

@@ -8,7 +8,7 @@ use std::mem::size_of;
use std::os::raw::c_char;
use std::path::PathBuf;
use std::slice;
use wasmer::{AsContextMut, ContextMut, GlobalInit, Memory, Module, Pages, WasmPtr};
use wasmer::{FunctionEnvMut, GlobalInit, Memory, Module, Pages, WasmPtr};
/// We check if a provided module is an Emscripten generated one
pub fn is_emscripten_module(module: &Module) -> bool {
@@ -94,7 +94,7 @@ pub fn get_emscripten_metadata(module: &Module) -> Result<Option<(u32, u32)>, St
}
pub unsafe fn write_to_buf(
ctx: ContextMut<'_, EmEnv>,
ctx: FunctionEnvMut<EmEnv>,
string: *const c_char,
buf: u32,
max: u32,
@@ -109,10 +109,10 @@ pub unsafe fn write_to_buf(
}
/// This function expects nullbyte to be appended.
pub unsafe fn copy_cstr_into_wasm(mut ctx: ContextMut<'_, EmEnv>, cstr: *const c_char) -> u32 {
pub unsafe fn copy_cstr_into_wasm(ctx: &mut FunctionEnvMut<EmEnv>, cstr: *const c_char) -> u32 {
let s = CStr::from_ptr(cstr).to_str().unwrap();
let cstr_len = s.len();
let space_offset = env::call_malloc(ctx.as_context_mut(), (cstr_len as u32) + 1);
let space_offset = env::call_malloc(ctx, (cstr_len as u32) + 1);
let raw_memory =
emscripten_memory_pointer!(ctx, ctx.data().memory(0), space_offset) as *mut c_char;
let slice = slice::from_raw_parts_mut(raw_memory, cstr_len);
@@ -131,12 +131,12 @@ pub unsafe fn copy_cstr_into_wasm(mut ctx: ContextMut<'_, EmEnv>, cstr: *const c
/// # Safety
/// This method is unsafe because it operates directly with the slice of memory represented by the address
pub unsafe fn allocate_on_stack<'a, T: Copy>(
ctx: &mut ContextMut<'a, EmEnv>,
mut ctx: &mut FunctionEnvMut<'a, EmEnv>,
count: u32,
) -> (u32, &'a mut [T]) {
let stack_alloc_ref = get_emscripten_funcs(ctx).stack_alloc_ref().unwrap().clone();
let offset = stack_alloc_ref
.call(&mut ctx.as_context_mut(), count * (size_of::<T>() as u32))
.call(&mut ctx, count * (size_of::<T>() as u32))
.unwrap();
let addr = emscripten_memory_pointer!(ctx, ctx.data().memory(0), offset) as *mut T;
@@ -148,7 +148,7 @@ pub unsafe fn allocate_on_stack<'a, T: Copy>(
/// # Safety
/// This method is unsafe because it uses `allocate_on_stack` which is unsafe
pub unsafe fn allocate_cstr_on_stack<'a>(
ctx: &'a mut ContextMut<'a, EmEnv>,
ctx: &'a mut FunctionEnvMut<'a, EmEnv>,
s: &str,
) -> (u32, &'a [u8]) {
let (offset, slice) = allocate_on_stack(ctx, (s.len() + 1) as u32);
@@ -163,7 +163,7 @@ pub unsafe fn allocate_cstr_on_stack<'a>(
#[cfg(not(target_os = "windows"))]
pub unsafe fn copy_terminated_array_of_cstrs(
mut _ctx: ContextMut<'_, EmEnv>,
mut _ctx: FunctionEnvMut<EmEnv>,
cstrs: *mut *mut c_char,
) -> u32 {
let _total_num = {
@@ -203,7 +203,7 @@ pub struct GuestStat {
}
#[allow(clippy::cast_ptr_alignment)]
pub unsafe fn copy_stat_into_wasm(ctx: ContextMut<'_, EmEnv>, buf: u32, stat: &stat) {
pub unsafe fn copy_stat_into_wasm(ctx: FunctionEnvMut<EmEnv>, buf: u32, stat: &stat) {
let stat_ptr = emscripten_memory_pointer!(ctx, ctx.data().memory(0), buf) as *mut GuestStat;
(*stat_ptr).st_dev = stat.st_dev as _;
(*stat_ptr).__st_dev_padding = 0;
@@ -231,7 +231,7 @@ pub unsafe fn copy_stat_into_wasm(ctx: ContextMut<'_, EmEnv>, buf: u32, stat: &s
}
#[allow(dead_code)] // it's used in `env/windows/mod.rs`.
pub fn read_string_from_wasm(ctx: ContextMut<'_, EmEnv>, memory: &Memory, offset: u32) -> String {
pub fn read_string_from_wasm(ctx: FunctionEnvMut<EmEnv>, memory: &Memory, offset: u32) -> String {
WasmPtr::<u8>::new(offset)
.read_utf8_string_with_nul(&ctx, memory)
.unwrap()
@@ -239,7 +239,7 @@ pub fn read_string_from_wasm(ctx: ContextMut<'_, EmEnv>, memory: &Memory, offset
/// This function trys to find an entry in mapdir
/// translating paths into their correct value
pub fn get_cstr_path(ctx: ContextMut<'_, EmEnv>, path: *const i8) -> Option<std::ffi::CString> {
pub fn get_cstr_path(ctx: FunctionEnvMut<EmEnv>, path: *const i8) -> Option<std::ffi::CString> {
use std::collections::VecDeque;
let path_str =
@@ -277,7 +277,7 @@ pub fn get_cstr_path(ctx: ContextMut<'_, EmEnv>, path: *const i8) -> Option<std:
/// gets the current directory
/// handles mapdir logic
pub fn get_current_directory(ctx: ContextMut<'_, EmEnv>) -> Option<PathBuf> {
pub fn get_current_directory(ctx: FunctionEnvMut<EmEnv>) -> Option<PathBuf> {
if let Some(val) = get_emscripten_data(&ctx)
.as_ref()
.unwrap()

View File

@@ -3,7 +3,7 @@ use std::mem;
use wasmer::FromToNativeWasmType;
// use std::ffi::CStr;
use std::os::raw::c_char;
use wasmer::ContextMut;
use wasmer::FunctionEnvMut;
#[repr(transparent)]
#[derive(Copy, Clone)]
@@ -12,14 +12,14 @@ pub struct VarArgs {
}
impl VarArgs {
pub fn get<T: Sized>(&mut self, ctx: &ContextMut<'_, EmEnv>) -> T {
pub fn get<T: Sized>(&mut self, ctx: &FunctionEnvMut<EmEnv>) -> T {
let ptr = emscripten_memory_pointer!(ctx, ctx.data().memory(0), self.pointer);
self.pointer += mem::size_of::<T>() as u32;
unsafe { (ptr as *const T).read() }
}
// pub fn getStr<'a>(&mut self, ctx: &mut Ctx) -> &'a CStr {
pub fn get_str(&mut self, ctx: &ContextMut<'_, EmEnv>) -> *const c_char {
pub fn get_str(&mut self, ctx: &FunctionEnvMut<EmEnv>) -> *const c_char {
let ptr_addr: u32 = self.get(ctx);
let ptr = emscripten_memory_pointer!(ctx, ctx.data().memory(0), ptr_addr) as *const c_char;
ptr