From 3fea07dc8a290a8cca42d056283e32d0283f10e6 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 11 Mar 2019 14:35:51 +0100 Subject: [PATCH 1/9] fix(runtime-c-api) Fix the `imports` length. `imports` contains `func_import`, `global_import`, `memory_import` and `table_import`, so 4 items. This patch updates the length of `imports` when calling the `wasmer_instantiate` function. --- lib/runtime-c-api/tests/test-imports.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime-c-api/tests/test-imports.c b/lib/runtime-c-api/tests/test-imports.c index cecb9ec94..9c0c45467 100644 --- a/lib/runtime-c-api/tests/test-imports.c +++ b/lib/runtime-c-api/tests/test-imports.c @@ -127,7 +127,7 @@ int main() // Creates a WebAssembly Instance from wasm bytes and imports wasmer_instance_t *instance = NULL; - wasmer_result_t compile_result = wasmer_instantiate(&instance, bytes, len, imports, 3); + wasmer_result_t compile_result = wasmer_instantiate(&instance, bytes, len, imports, 4); printf("Compile result: %d\n", compile_result); if (compile_result != WASMER_OK) { From a11d45413057d34d1ddd00ea7ebd07a6d3d7411d Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 11 Mar 2019 16:50:18 +0100 Subject: [PATCH 2/9] feat(runtime-c-api) Add an API to update `vm::Ctx.data`. This patch adds 2 functions for the runtime C API, respectively `wasmer_instance_context_data_set` and `wasmer_instance_context_data_get`. The goal is to modify the `vm::Ctx.data` field in the `runtime-core` library. This is required to pass dynamic data to imported functions for instance. --- lib/runtime-c-api/src/lib.rs | 20 ++++++++++++++++++++ lib/runtime-c-api/wasmer.h | 15 +++++++++++++-- lib/runtime-c-api/wasmer.hh | 11 +++++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index 8055fc445..3d571533d 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -947,6 +947,17 @@ pub unsafe extern "C" fn wasmer_instance_exports( *exports = Box::into_raw(named_exports) as *mut wasmer_exports_t; } +/// Sets the `data` field of the instance context. This context will be +/// passed to all imported function for instance. +#[no_mangle] +pub extern "C" fn wasmer_instance_context_data_set( + instance: *mut wasmer_instance_t, + data_ptr: *mut c_void, +) { + let instance_ref = unsafe { &mut *(instance as *mut Instance) }; + instance_ref.context_mut().data = data_ptr; +} + pub struct NamedExports(Vec); /// Frees the memory for the given exports @@ -1350,6 +1361,15 @@ pub extern "C" fn wasmer_instance_context_memory( memory as *const Memory as *const wasmer_memory_t } +/// Gets the `data` field within the context. +#[no_mangle] +pub extern "C" fn wasmer_instance_context_data_get( + ctx: *const wasmer_instance_context_t, +) -> *mut c_void { + let ctx = unsafe { &*(ctx as *const Ctx) }; + ctx.data +} + /// Gets the start pointer to the bytes within a Memory #[allow(clippy::cast_ptr_alignment)] #[no_mangle] diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index c9cb61709..43d97ecb8 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -95,11 +95,11 @@ typedef struct { typedef struct { -} wasmer_memory_t; +} wasmer_instance_context_t; typedef struct { -} wasmer_instance_context_t; +} wasmer_memory_t; typedef struct { @@ -382,6 +382,17 @@ wasmer_result_t wasmer_instance_call(wasmer_instance_t *instance, wasmer_value_t *results, int results_len); +/** + * Gets the `data` field within the context. + */ +void *wasmer_instance_context_data_get(const wasmer_instance_context_t *ctx); + +/** + * Sets the `data` field of the instance context. This context will be + * passed to all imported function for instance. + */ +void wasmer_instance_context_data_set(wasmer_instance_t *instance, void *data_ptr); + /** * Gets the memory within the context at the index `memory_idx`. * The index is always 0 until multiple memories are supported. diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 4578eae49..76c27d46e 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -90,11 +90,11 @@ struct wasmer_instance_t { }; -struct wasmer_memory_t { +struct wasmer_instance_context_t { }; -struct wasmer_instance_context_t { +struct wasmer_memory_t { }; @@ -307,6 +307,13 @@ wasmer_result_t wasmer_instance_call(wasmer_instance_t *instance, wasmer_value_t *results, int results_len); +/// Gets the `data` field within the context. +void *wasmer_instance_context_data_get(const wasmer_instance_context_t *ctx); + +/// Sets the `data` field of the instance context. This context will be +/// passed to all imported function for instance. +void wasmer_instance_context_data_set(wasmer_instance_t *instance, void *data_ptr); + /// Gets the memory within the context at the index `memory_idx`. /// The index is always 0 until multiple memories are supported. const wasmer_memory_t *wasmer_instance_context_memory(const wasmer_instance_context_t *ctx, From 170de02dd3acb587ba7c177c5894d91306bccc43 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 11 Mar 2019 17:34:13 +0100 Subject: [PATCH 3/9] test(runtime-c-api) Test the `wasmer_instance_context_data_*` functions. --- lib/runtime-c-api/tests/test-import-function.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/runtime-c-api/tests/test-import-function.c b/lib/runtime-c-api/tests/test-import-function.c index f8214535c..a0027f9fd 100644 --- a/lib/runtime-c-api/tests/test-import-function.c +++ b/lib/runtime-c-api/tests/test-import-function.c @@ -8,6 +8,11 @@ static bool print_str_called = false; static int memory_len = 0; static int ptr_len = 0; static char actual_str[14] = {}; +static int actual_context_data_value = 0; + +typedef struct { + int value; +} context_data; void print_str(wasmer_instance_context_t *ctx, int32_t ptr, int32_t len) { @@ -23,6 +28,8 @@ void print_str(wasmer_instance_context_t *ctx, int32_t ptr, int32_t len) print_str_called = true; memory_len = mem_len; ptr_len = len; + + actual_context_data_value = ((context_data *) wasmer_instance_context_data_get(ctx))->value; } int main() @@ -65,6 +72,11 @@ int main() assert(compile_result == WASMER_OK); + context_data* context_data = malloc(sizeof(context_data)); + int context_data_value = 42; + context_data->value = context_data_value; + wasmer_instance_context_data_set(instance, context_data); + wasmer_value_t params[] = {}; wasmer_value_t results[] = {}; wasmer_result_t call_result = wasmer_instance_call(instance, "hello_wasm", params, 0, results, 0); @@ -82,6 +94,7 @@ int main() assert(memory_len == 17); assert(ptr_len == 13); assert(0 == strcmp(actual_str, "Hello, World!")); + assert(context_data_value == actual_context_data_value); printf("Destroying func\n"); wasmer_import_func_destroy(func); From 675f6817baa48843c895ddc80917394f103f695d Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 11 Mar 2019 17:41:17 +0100 Subject: [PATCH 4/9] test(runtime-c-api) Free allocations. Don't forget to free `context_data` :-). --- lib/runtime-c-api/tests/test-import-function.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/runtime-c-api/tests/test-import-function.c b/lib/runtime-c-api/tests/test-import-function.c index a0027f9fd..ce6736deb 100644 --- a/lib/runtime-c-api/tests/test-import-function.c +++ b/lib/runtime-c-api/tests/test-import-function.c @@ -100,5 +100,6 @@ int main() wasmer_import_func_destroy(func); printf("Destroy instance\n"); wasmer_instance_destroy(instance); + free(context_data); return 0; } From a390a28384826166bade832a04685119ad2818e6 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 12 Mar 2019 08:58:22 +0100 Subject: [PATCH 5/9] fix(runtime-c-api) Fix Clippy errors. --- lib/runtime-c-api/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index 3d571533d..b63e69d9c 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -949,6 +949,7 @@ pub unsafe extern "C" fn wasmer_instance_exports( /// Sets the `data` field of the instance context. This context will be /// passed to all imported function for instance. +#[allow(clippy::cast_ptr_alignment)] #[no_mangle] pub extern "C" fn wasmer_instance_context_data_set( instance: *mut wasmer_instance_t, @@ -1362,6 +1363,7 @@ pub extern "C" fn wasmer_instance_context_memory( } /// Gets the `data` field within the context. +#[allow(clippy::cast_ptr_alignment)] #[no_mangle] pub extern "C" fn wasmer_instance_context_data_get( ctx: *const wasmer_instance_context_t, From 6e62ea7cfb9a5f51bd393a4ddec224ce08d0da0f Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 12 Mar 2019 09:51:54 +0100 Subject: [PATCH 6/9] fix(runtime-core) Remove unused imports. This patch removes unused imports as reported by `rustc` as warnings. --- lib/runtime-core/src/error.rs | 7 ++----- lib/runtime-core/src/typed_func.rs | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/runtime-core/src/error.rs b/lib/runtime-core/src/error.rs index 45c627aec..9e99c2833 100644 --- a/lib/runtime-core/src/error.rs +++ b/lib/runtime-core/src/error.rs @@ -1,9 +1,6 @@ -use crate::types::{ - FuncSig, GlobalDescriptor, MemoryDescriptor, MemoryIndex, TableDescriptor, TableIndex, Type, - Value, -}; +use crate::types::{FuncSig, GlobalDescriptor, MemoryDescriptor, TableDescriptor, Type, Value}; use core::borrow::Borrow; -use std::{any::Any, sync::Arc}; +use std::any::Any; pub type Result = std::result::Result; pub type CompileResult = std::result::Result; diff --git a/lib/runtime-core/src/typed_func.rs b/lib/runtime-core/src/typed_func.rs index 6e2a4d26c..4191f347e 100644 --- a/lib/runtime-core/src/typed_func.rs +++ b/lib/runtime-core/src/typed_func.rs @@ -6,7 +6,7 @@ use crate::{ types::{FuncSig, Type, WasmExternType}, vm::Ctx, }; -use std::{any::Any, cell::UnsafeCell, fmt, marker::PhantomData, mem, panic, ptr, sync::Arc}; +use std::{any::Any, cell::UnsafeCell, marker::PhantomData, mem, panic, ptr, sync::Arc}; thread_local! { pub static EARLY_TRAPPER: UnsafeCell>> = UnsafeCell::new(None); From 2c8fc5238d64c156b649e0be99c5297e2e77982e Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 12 Mar 2019 10:03:55 +0100 Subject: [PATCH 7/9] fix(clif-backend) Remove unused imports. This patch removes unused imports reported by `rustc` as warnings. --- lib/clif-backend/src/signal/unix.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/clif-backend/src/signal/unix.rs b/lib/clif-backend/src/signal/unix.rs index 86cc53638..feaf4e2e2 100644 --- a/lib/clif-backend/src/signal/unix.rs +++ b/lib/clif-backend/src/signal/unix.rs @@ -18,11 +18,7 @@ use nix::sys::signal::{ use std::cell::{Cell, UnsafeCell}; use std::ptr; use std::sync::Once; -use wasmer_runtime_core::{ - error::{RuntimeError, RuntimeResult}, - structures::TypedIndex, - types::{MemoryIndex, TableIndex}, -}; +use wasmer_runtime_core::error::{RuntimeError, RuntimeResult}; extern "C" fn signal_trap_handler( signum: ::nix::libc::c_int, From ef69f6151c686805b1065e46341215e90209d0a1 Mon Sep 17 00:00:00 2001 From: Syrus Date: Tue, 12 Mar 2019 10:07:23 -0700 Subject: [PATCH 8/9] Run test-and-build always on master --- .circleci/config.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1ca2ddcb1..1a462b680 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -325,14 +325,12 @@ workflows: filters: branches: only: - - trying - - staging + - master - test-and-build-macos: filters: branches: only: - - trying - - staging + - master - test-rust-nightly: filters: branches: From 20d1023abeff06106d09fcf359d2c00633809049 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 12 Mar 2019 22:00:33 +0100 Subject: [PATCH 9/9] fix(emscripten) Various warning fixes and cleanups (#266) * fix(emscripten) Remove unused imports. This patch removes unused imports reported by `rustc` as warnings. * fix(emscripten) Allow unreachable patterns in `_clock_gettime`. The compiler thinks `CLOCK_MONOTONIC_COARSE` is unreachable, which is not always the case. Add an attribute to allow unreachable patterns to remove the warning. * fix(emscripten) Rename unused variables. This patch renames various unused variables by appending an underscore to them. * fix(emscripten) Declare `table` as immutable. The `table` variable in `EmscriptenGlobals::new` was declared as mutable, but it's never mutated. * fix(emscripten) Remove an unnecessary `unsafe` block. * fix(emscripten) Remove duplicate definition of `SO_NOSIGPIPE`. The `SO_NOSIGPIPE` constant is defined in `syscalls/mod.rs` and `syscalls/unix.rs`. It's never used in the first case. We can safely remove it in this file, and keep it in `unix.rs`. * fix(emscripten) `read_string_from_wasm` is used only on Windows. Mark `read_string_from_wasm` as possible deadcode, since it's used only on Windows. * fix(emscripten) Remove `DYNAMICTOP_PTR_DIFF`, `stacktop`, `stack_max`, `dynamic_base` and `dynamic_ptr`. Four functions and one constant are used together but never used inside or outside this file. They are deadcode. * fix(emscripten) Remove `infinity` and `nan` fields of `EmscriptenGlobalsData`. Those fields are never used. * fix(emscripten) Allow non snake case in `emscripten_target.rs`. Many functions in this file don't follow the snake case style for Rust function names. The reason is that we want the names to match the emscripten symbol names; even if a mapping is done in `lib.rs`, it's easier to get the same names. * fix(emscripten) Rename `STATIC_TOP` to `static_top`. This variable is not a constant. --- lib/emscripten/src/emscripten_target.rs | 104 +++++++++++++----------- lib/emscripten/src/env/mod.rs | 4 +- lib/emscripten/src/errno.rs | 4 +- lib/emscripten/src/io/unix.rs | 2 +- lib/emscripten/src/lib.rs | 37 ++------- lib/emscripten/src/lock.rs | 8 +- lib/emscripten/src/memory.rs | 13 +-- lib/emscripten/src/nullfunc.rs | 44 +++++----- lib/emscripten/src/process.rs | 2 +- lib/emscripten/src/signal.rs | 8 +- lib/emscripten/src/syscalls/mod.rs | 91 ++++++++------------- lib/emscripten/src/syscalls/unix.rs | 52 ++++++------ lib/emscripten/src/syscalls/windows.rs | 1 - lib/emscripten/src/time.rs | 12 +-- lib/emscripten/src/utils.rs | 5 +- 15 files changed, 177 insertions(+), 210 deletions(-) diff --git a/lib/emscripten/src/emscripten_target.rs b/lib/emscripten/src/emscripten_target.rs index e850757f6..4508f4f54 100644 --- a/lib/emscripten/src/emscripten_target.rs +++ b/lib/emscripten/src/emscripten_target.rs @@ -1,14 +1,16 @@ +#![allow(non_snake_case)] + use crate::env::get_emscripten_data; use wasmer_runtime_core::vm::Ctx; -pub fn setTempRet0(ctx: &mut Ctx, a: i32) { +pub fn setTempRet0(_ctx: &mut Ctx, _a: i32) { debug!("emscripten::setTempRet0"); } -pub fn getTempRet0(ctx: &mut Ctx) -> i32 { +pub fn getTempRet0(_ctx: &mut Ctx) -> i32 { debug!("emscripten::getTempRet0"); 0 } -pub fn nullFunc_ji(ctx: &mut Ctx, a: i32) { +pub fn nullFunc_ji(_ctx: &mut Ctx, _a: i32) { debug!("emscripten::nullFunc_ji"); } pub fn invoke_i(ctx: &mut Ctx, index: i32) -> i32 { @@ -83,158 +85,166 @@ pub fn invoke_viiii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32, a3: i32, a4: i3 panic!("dyn_call_viiii is set to None"); } } -pub fn __Unwind_Backtrace(ctx: &mut Ctx, a: i32, b: i32) -> i32 { +pub fn __Unwind_Backtrace(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { debug!("emscripten::__Unwind_Backtrace"); 0 } -pub fn __Unwind_FindEnclosingFunction(ctx: &mut Ctx, a: i32) -> i32 { +pub fn __Unwind_FindEnclosingFunction(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::__Unwind_FindEnclosingFunction"); 0 } -pub fn __Unwind_GetIPInfo(ctx: &mut Ctx, a: i32, b: i32) -> i32 { +pub fn __Unwind_GetIPInfo(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { debug!("emscripten::__Unwind_GetIPInfo"); 0 } -pub fn ___cxa_find_matching_catch_2(ctx: &mut Ctx) -> i32 { +pub fn ___cxa_find_matching_catch_2(_ctx: &mut Ctx) -> i32 { debug!("emscripten::___cxa_find_matching_catch_2"); 0 } -pub fn ___cxa_find_matching_catch_3(ctx: &mut Ctx, a: i32) -> i32 { +pub fn ___cxa_find_matching_catch_3(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::___cxa_find_matching_catch_3"); 0 } -pub fn ___cxa_free_exception(ctx: &mut Ctx, a: i32) { +pub fn ___cxa_free_exception(_ctx: &mut Ctx, _a: i32) { debug!("emscripten::___cxa_free_exception"); } -pub fn ___resumeException(ctx: &mut Ctx, a: i32) { +pub fn ___resumeException(_ctx: &mut Ctx, _a: i32) { debug!("emscripten::___resumeException"); } -pub fn _dladdr(ctx: &mut Ctx, a: i32, b: i32) -> i32 { +pub fn _dladdr(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { debug!("emscripten::_dladdr"); 0 } -pub fn _pthread_cond_destroy(ctx: &mut Ctx, a: i32) -> i32 { +pub fn _pthread_cond_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::_pthread_cond_destroy"); 0 } -pub fn _pthread_cond_init(ctx: &mut Ctx, a: i32, b: i32) -> i32 { +pub fn _pthread_cond_init(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { debug!("emscripten::_pthread_cond_init"); 0 } -pub fn _pthread_cond_signal(ctx: &mut Ctx, a: i32) -> i32 { +pub fn _pthread_cond_signal(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::_pthread_cond_signal"); 0 } -pub fn _pthread_cond_wait(ctx: &mut Ctx, a: i32, b: i32) -> i32 { +pub fn _pthread_cond_wait(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { debug!("emscripten::_pthread_cond_wait"); 0 } -pub fn _pthread_condattr_destroy(ctx: &mut Ctx, a: i32) -> i32 { +pub fn _pthread_condattr_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::_pthread_condattr_destroy"); 0 } -pub fn _pthread_condattr_init(ctx: &mut Ctx, a: i32) -> i32 { +pub fn _pthread_condattr_init(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::_pthread_condattr_init"); 0 } -pub fn _pthread_condattr_setclock(ctx: &mut Ctx, a: i32, b: i32) -> i32 { +pub fn _pthread_condattr_setclock(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { debug!("emscripten::_pthread_condattr_setclock"); 0 } -pub fn _pthread_mutex_destroy(ctx: &mut Ctx, a: i32) -> i32 { +pub fn _pthread_mutex_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::_pthread_mutex_destroy"); 0 } -pub fn _pthread_mutex_init(ctx: &mut Ctx, a: i32, b: i32) -> i32 { +pub fn _pthread_mutex_init(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { debug!("emscripten::_pthread_mutex_init"); 0 } -pub fn _pthread_mutexattr_destroy(ctx: &mut Ctx, a: i32) -> i32 { +pub fn _pthread_mutexattr_destroy(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::_pthread_mutexattr_destroy"); 0 } -pub fn _pthread_mutexattr_init(ctx: &mut Ctx, a: i32) -> i32 { +pub fn _pthread_mutexattr_init(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::_pthread_mutexattr_init"); 0 } -pub fn _pthread_mutexattr_settype(ctx: &mut Ctx, a: i32, b: i32) -> i32 { +pub fn _pthread_mutexattr_settype(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 { debug!("emscripten::_pthread_mutexattr_settype"); 0 } -pub fn _pthread_rwlock_rdlock(ctx: &mut Ctx, a: i32) -> i32 { +pub fn _pthread_rwlock_rdlock(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::_pthread_rwlock_rdlock"); 0 } -pub fn _pthread_rwlock_unlock(ctx: &mut Ctx, a: i32) -> i32 { +pub fn _pthread_rwlock_unlock(_ctx: &mut Ctx, _a: i32) -> i32 { debug!("emscripten::_pthread_rwlock_unlock"); 0 } -pub fn ___gxx_personality_v0(ctx: &mut Ctx, a: i32, b: i32, c: i32, d: i32, e: i32, f: i32) -> i32 { +pub fn ___gxx_personality_v0( + _ctx: &mut Ctx, + _a: i32, + _b: i32, + _c: i32, + _d: i32, + _e: i32, + _f: i32, +) -> i32 { debug!("emscripten::___gxx_personality_v0"); 0 } // round 2 -pub fn nullFunc_dii(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_dii(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_dii"); } -pub fn nullFunc_diiii(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_diiii(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_diiii"); } -pub fn nullFunc_iiji(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_iiji(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_iiji"); } -pub fn nullFunc_j(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_j(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_j"); } -pub fn nullFunc_jij(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_jij(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_jij"); } -pub fn nullFunc_jjj(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_jjj(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_jjj"); } -pub fn nullFunc_vd(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_vd(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_vd"); } -pub fn nullFunc_viiiiiii(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_viiiiiii(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_viiiiiii"); } -pub fn nullFunc_viiiiiiii(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_viiiiiiii(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_viiiiiiii"); } -pub fn nullFunc_viiiiiiiii(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_viiiiiiiii(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_viiiiiiiii"); } -pub fn nullFunc_viiij(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_viiij(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_viiij"); } -pub fn nullFunc_viiijiiii(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_viiijiiii(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_viiijiiii"); } -pub fn nullFunc_viiijiiiiii(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_viiijiiiiii(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_viiijiiiiii"); } -pub fn nullFunc_viij(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_viij(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_viij"); } -pub fn nullFunc_viiji(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_viiji(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_viiji"); } -pub fn nullFunc_viijiii(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_viijiii(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_viijiii"); } -pub fn nullFunc_viijj(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_viijj(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_viijj"); } -pub fn nullFunc_vij(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_vij(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_vij"); } -pub fn nullFunc_viji(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_viji(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_viji"); } -pub fn nullFunc_vijiii(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_vijiii(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_vijiii"); } -pub fn nullFunc_vijj(ctx: &mut Ctx, index: i32) { +pub fn nullFunc_vijj(_ctx: &mut Ctx, _index: i32) { debug!("emscripten::nullFunc_vijj"); } pub fn invoke_dii(ctx: &mut Ctx, index: i32, a1: i32, a2: i32) -> f64 { diff --git a/lib/emscripten/src/env/mod.rs b/lib/emscripten/src/env/mod.rs index 89f55fd09..662d4ba94 100644 --- a/lib/emscripten/src/env/mod.rs +++ b/lib/emscripten/src/env/mod.rs @@ -70,8 +70,8 @@ pub fn ___build_environment(ctx: &mut Ctx, environ: c_int) { // }; } -pub fn ___assert_fail(_ctx: &mut Ctx, a: c_int, b: c_int, c: c_int, d: c_int) { - debug!("emscripten::___assert_fail {} {} {} {}", a, b, c, d); +pub fn ___assert_fail(_ctx: &mut Ctx, _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 } diff --git a/lib/emscripten/src/errno.rs b/lib/emscripten/src/errno.rs index 06267e210..ff1d09b7f 100644 --- a/lib/emscripten/src/errno.rs +++ b/lib/emscripten/src/errno.rs @@ -1,8 +1,8 @@ // use std::collections::HashMap; use wasmer_runtime_core::vm::Ctx; -pub fn ___seterrno(_ctx: &mut Ctx, value: i32) { - debug!("emscripten::___seterrno {}", value); +pub fn ___seterrno(_ctx: &mut Ctx, _value: i32) { + debug!("emscripten::___seterrno {}", _value); // TODO: Incomplete impl eprintln!("failed to set errno!"); // value diff --git a/lib/emscripten/src/io/unix.rs b/lib/emscripten/src/io/unix.rs index 38324ac1e..da3ddeff9 100644 --- a/lib/emscripten/src/io/unix.rs +++ b/lib/emscripten/src/io/unix.rs @@ -3,7 +3,7 @@ use libc::printf as _printf; use wasmer_runtime_core::vm::Ctx; /// putchar -pub fn putchar(ctx: &mut Ctx, chr: i32) { +pub fn putchar(_ctx: &mut Ctx, chr: i32) { unsafe { libc::putchar(chr) }; } diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 66d9b75ff..1cde93620 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -56,8 +56,6 @@ pub use self::utils::{ // TODO: Magic number - how is this calculated? const TOTAL_STACK: u32 = 5_242_880; -// TODO: Magic number - how is this calculated? -const DYNAMICTOP_PTR_DIFF: u32 = 1088; // TODO: make this variable const STATIC_BUMP: u32 = 215_536; @@ -73,22 +71,6 @@ lazy_static! { const GLOBAL_BASE: u32 = 1024; const STATIC_BASE: u32 = GLOBAL_BASE; -fn stacktop(static_bump: u32) -> u32 { - align_memory(dynamictop_ptr(static_bump) + 4) -} - -fn stack_max(static_bump: u32) -> u32 { - stacktop(static_bump) + TOTAL_STACK -} - -fn dynamic_base(static_bump: u32) -> u32 { - align_memory(stack_max(static_bump)) -} - -fn dynamictop_ptr(static_bump: u32) -> u32 { - static_bump + DYNAMICTOP_PTR_DIFF -} - pub struct EmscriptenData<'a> { pub malloc: Func<'a, u32, u32>, pub free: Func<'a, u32>, @@ -311,10 +293,6 @@ pub struct EmscriptenGlobalsData { table_base: u32, temp_double_ptr: u32, use_old_abort_on_cannot_grow_memory: bool, - - // Global namespace - infinity: f64, - nan: f64, } pub struct EmscriptenGlobals { @@ -366,22 +344,22 @@ impl EmscriptenGlobals { minimum: table_min, maximum: table_max, }; - let mut table = Table::new(table_type).unwrap(); + let table = Table::new(table_type).unwrap(); let data = { let static_bump = STATIC_BUMP; - let mut STATIC_TOP = STATIC_BASE + static_bump; + let mut static_top = STATIC_BASE + static_bump; let memory_base = STATIC_BASE; let table_base = 0; - let temp_double_ptr = STATIC_TOP; - STATIC_TOP += 16; + let temp_double_ptr = static_top; + static_top += 16; - let dynamictop_ptr = static_alloc(&mut STATIC_TOP, 4); + let dynamictop_ptr = static_alloc(&mut static_top, 4); - let stacktop = align_memory(STATIC_TOP); + let stacktop = align_memory(static_top); let stack_max = stacktop + TOTAL_STACK; EmscriptenGlobalsData { @@ -393,9 +371,6 @@ impl EmscriptenGlobals { table_base, temp_double_ptr, use_old_abort_on_cannot_grow_memory, - - infinity: std::f64::INFINITY, - nan: std::f64::NAN, } }; diff --git a/lib/emscripten/src/lock.rs b/lib/emscripten/src/lock.rs index 45f09581f..badb47a1b 100644 --- a/lib/emscripten/src/lock.rs +++ b/lib/emscripten/src/lock.rs @@ -2,13 +2,13 @@ use libc::c_int; use wasmer_runtime_core::vm::Ctx; // NOTE: Not implemented by Emscripten -pub fn ___lock(_ctx: &mut Ctx, what: c_int) { - debug!("emscripten::___lock {}", what); +pub fn ___lock(_ctx: &mut Ctx, _what: c_int) { + debug!("emscripten::___lock {}", _what); } // NOTE: Not implemented by Emscripten -pub fn ___unlock(_ctx: &mut Ctx, what: c_int) { - debug!("emscripten::___unlock {}", what); +pub fn ___unlock(_ctx: &mut Ctx, _what: c_int) { + debug!("emscripten::___unlock {}", _what); } // NOTE: Not implemented by Emscripten diff --git a/lib/emscripten/src/memory.rs b/lib/emscripten/src/memory.rs index dcd98c317..02877a011 100644 --- a/lib/emscripten/src/memory.rs +++ b/lib/emscripten/src/memory.rs @@ -17,15 +17,15 @@ pub fn _emscripten_memcpy_big(ctx: &mut Ctx, dest: u32, src: u32, len: u32) -> u } /// emscripten: _emscripten_get_heap_size -pub fn _emscripten_get_heap_size(ctx: &mut Ctx) -> u32 { +pub fn _emscripten_get_heap_size(_ctx: &mut Ctx) -> u32 { debug!("emscripten::_emscripten_get_heap_size",); // TODO: Fix implementation 16_777_216 } /// emscripten: _emscripten_resize_heap -pub fn _emscripten_resize_heap(ctx: &mut Ctx, requested_size: u32) -> u32 { - debug!("emscripten::_emscripten_resize_heap {}", requested_size); +pub fn _emscripten_resize_heap(_ctx: &mut Ctx, _requested_size: u32) -> u32 { + debug!("emscripten::_emscripten_resize_heap {}", _requested_size); // TODO: Fix implementation 0 } @@ -47,8 +47,11 @@ pub fn enlarge_memory(_ctx: &mut Ctx) -> u32 { } /// emscripten: abortOnCannotGrowMemory -pub fn abort_on_cannot_grow_memory(ctx: &mut Ctx, requested_size: u32) -> u32 { - debug!("emscripten::abort_on_cannot_grow_memory {}", requested_size); +pub fn abort_on_cannot_grow_memory(ctx: &mut Ctx, _requested_size: u32) -> u32 { + debug!( + "emscripten::abort_on_cannot_grow_memory {}", + _requested_size + ); abort_with_message(ctx, "Cannot enlarge memory arrays!"); 0 } diff --git a/lib/emscripten/src/nullfunc.rs b/lib/emscripten/src/nullfunc.rs index 7fb44ab11..8f289599b 100644 --- a/lib/emscripten/src/nullfunc.rs +++ b/lib/emscripten/src/nullfunc.rs @@ -1,58 +1,58 @@ use super::process::abort_with_message; use wasmer_runtime_core::vm::Ctx; -pub fn nullfunc_i(ctx: &mut Ctx, x: u32) { - debug!("emscripten::nullfunc_i {}", x); +pub fn nullfunc_i(ctx: &mut Ctx, _x: u32) { + debug!("emscripten::nullfunc_i {}", _x); abort_with_message(ctx, "Invalid function pointer called with signature 'i'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub fn nullfunc_ii(ctx: &mut Ctx, x: u32) { - debug!("emscripten::nullfunc_ii {}", x); +pub fn nullfunc_ii(ctx: &mut Ctx, _x: u32) { + debug!("emscripten::nullfunc_ii {}", _x); abort_with_message(ctx, "Invalid function pointer called with signature 'ii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub fn nullfunc_iii(ctx: &mut Ctx, x: u32) { - debug!("emscripten::nullfunc_iii {}", x); +pub fn nullfunc_iii(ctx: &mut Ctx, _x: u32) { + debug!("emscripten::nullfunc_iii {}", _x); abort_with_message(ctx, "Invalid function pointer called with signature 'iii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub fn nullfunc_iiii(ctx: &mut Ctx, x: u32) { - debug!("emscripten::nullfunc_iiii {}", x); +pub fn nullfunc_iiii(ctx: &mut Ctx, _x: u32) { + debug!("emscripten::nullfunc_iiii {}", _x); abort_with_message(ctx, "Invalid function pointer called with signature 'iiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub fn nullfunc_iiiii(ctx: &mut Ctx, x: u32) { - debug!("emscripten::nullfunc_iiiii {}", x); +pub fn nullfunc_iiiii(ctx: &mut Ctx, _x: u32) { + debug!("emscripten::nullfunc_iiiii {}", _x); abort_with_message(ctx, "Invalid function pointer called with signature 'iiiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub fn nullfunc_iiiiii(ctx: &mut Ctx, x: u32) { - debug!("emscripten::nullfunc_iiiiii {}", x); +pub fn nullfunc_iiiiii(ctx: &mut Ctx, _x: u32) { + debug!("emscripten::nullfunc_iiiiii {}", _x); abort_with_message(ctx, "Invalid function pointer called with signature 'iiiiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub fn nullfunc_v(ctx: &mut Ctx, x: u32) { - debug!("emscripten::nullfunc_v {}", x); +pub fn nullfunc_v(ctx: &mut Ctx, _x: u32) { + debug!("emscripten::nullfunc_v {}", _x); abort_with_message(ctx, "Invalid function pointer called with signature 'v'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub fn nullfunc_vi(ctx: &mut Ctx, x: u32) { - debug!("emscripten::nullfunc_vi {}", x); +pub fn nullfunc_vi(ctx: &mut Ctx, _x: u32) { + debug!("emscripten::nullfunc_vi {}", _x); abort_with_message(ctx, "Invalid function pointer called with signature 'vi'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub fn nullfunc_vii(ctx: &mut Ctx, x: u32) { - debug!("emscripten::nullfunc_vii {}", x); +pub fn nullfunc_vii(ctx: &mut Ctx, _x: u32) { + debug!("emscripten::nullfunc_vii {}", _x); abort_with_message(ctx, "Invalid function pointer called with signature 'vii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub fn nullfunc_viii(ctx: &mut Ctx, x: u32) { - debug!("emscripten::nullfunc_viii {}", x); +pub fn nullfunc_viii(ctx: &mut Ctx, _x: u32) { + debug!("emscripten::nullfunc_viii {}", _x); abort_with_message(ctx, "Invalid function pointer called with signature 'viii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } -pub fn nullfunc_viiii(ctx: &mut Ctx, x: u32) { - debug!("emscripten::nullfunc_viiii {}", x); +pub fn nullfunc_viiii(ctx: &mut Ctx, _x: u32) { + debug!("emscripten::nullfunc_viiii {}", _x); abort_with_message(ctx, "Invalid function pointer called with signature 'viiii'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)"); } diff --git a/lib/emscripten/src/process.rs b/lib/emscripten/src/process.rs index 8d1dddb48..2dbf90ca5 100644 --- a/lib/emscripten/src/process.rs +++ b/lib/emscripten/src/process.rs @@ -98,7 +98,7 @@ pub fn _sem_wait(_ctx: &mut Ctx, _one: i32) -> i32 { } #[allow(clippy::cast_ptr_alignment)] -pub fn _getgrent(ctx: &mut Ctx) -> c_int { +pub fn _getgrent(_ctx: &mut Ctx) -> c_int { debug!("emscripten::_getgrent"); -1 } diff --git a/lib/emscripten/src/signal.rs b/lib/emscripten/src/signal.rs index f7657630b..37c3ed8df 100644 --- a/lib/emscripten/src/signal.rs +++ b/lib/emscripten/src/signal.rs @@ -11,8 +11,8 @@ pub fn _sigemptyset(ctx: &mut Ctx, set: u32) -> i32 { 0 } -pub fn _sigaction(_ctx: &mut Ctx, signum: u32, act: u32, oldact: u32) -> i32 { - debug!("emscripten::_sigaction {}, {}, {}", signum, act, oldact); +pub fn _sigaction(_ctx: &mut Ctx, _signum: u32, _act: u32, _oldact: u32) -> i32 { + debug!("emscripten::_sigaction {}, {}, {}", _signum, _act, _oldact); 0 } @@ -36,7 +36,7 @@ pub fn _sigprocmask(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 { 0 } -pub fn _signal(_ctx: &mut Ctx, sig: u32, _two: i32) -> i32 { - debug!("emscripten::_signal ({})", sig); +pub fn _signal(_ctx: &mut Ctx, _sig: u32, _two: i32) -> i32 { + debug!("emscripten::_signal ({})", _sig); 0 } diff --git a/lib/emscripten/src/syscalls/mod.rs b/lib/emscripten/src/syscalls/mod.rs index 39bd2750d..806ea8187 100644 --- a/lib/emscripten/src/syscalls/mod.rs +++ b/lib/emscripten/src/syscalls/mod.rs @@ -42,24 +42,10 @@ use wasmer_runtime_core::vm::Ctx; use super::env; use std::cell::Cell; use std::slice; -// use std::sys::fd::FileDesc; - -// Another conditional constant for name resolution: Macos et iOS use -// SO_NOSIGPIPE as a setsockopt flag to disable SIGPIPE emission on socket. -// Other platforms do otherwise. -use crate::env::get_emscripten_data; -use crate::utils::copy_cstr_into_wasm; -use crate::utils::read_string_from_wasm; -#[cfg(target_os = "darwin")] -use libc::SO_NOSIGPIPE; -use std::ffi::CString; - -#[cfg(not(target_os = "darwin"))] -const SO_NOSIGPIPE: c_int = 0; /// exit -pub fn ___syscall1(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) { - debug!("emscripten::___syscall1 (exit) {}", which); +pub fn ___syscall1(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) { + debug!("emscripten::___syscall1 (exit) {}", _which); let status: i32 = varargs.get(ctx); unsafe { exit(status); @@ -67,9 +53,9 @@ pub fn ___syscall1(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) { } /// read -pub fn ___syscall3(ctx: &mut Ctx, which: i32, mut varargs: VarArgs) -> i32 { +pub fn ___syscall3(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { // -> ssize_t - debug!("emscripten::___syscall3 (read) {}", which); + debug!("emscripten::___syscall3 (read) {}", _which); let fd: i32 = varargs.get(ctx); let buf: u32 = varargs.get(ctx); let count: i32 = varargs.get(ctx); @@ -81,8 +67,8 @@ pub fn ___syscall3(ctx: &mut Ctx, which: i32, mut varargs: VarArgs) -> i32 { } /// write -pub fn ___syscall4(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall4 (write) {}", which); +pub fn ___syscall4(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall4 (write) {}", _which); let fd: i32 = varargs.get(ctx); let buf: u32 = varargs.get(ctx); let count: i32 = varargs.get(ctx); @@ -92,22 +78,22 @@ pub fn ___syscall4(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { } /// close -pub fn ___syscall6(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall6 (close) {}", which); +pub fn ___syscall6(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall6 (close) {}", _which); let fd: i32 = varargs.get(ctx); debug!("fd: {}", fd); unsafe { close(fd) } } // chdir -pub fn ___syscall12(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall12 (chdir) {}", which); +pub fn ___syscall12(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall12 (chdir) {}", _which); let path_addr: i32 = varargs.get(ctx); unsafe { let path_ptr = emscripten_memory_pointer!(ctx.memory(0), path_addr) as *const i8; - let path = std::ffi::CStr::from_ptr(path_ptr); + let _path = std::ffi::CStr::from_ptr(path_ptr); let ret = chdir(path_ptr); - debug!("=> path: {:?}, ret: {}", path, ret); + debug!("=> path: {:?}, ret: {}", _path, ret); ret } } @@ -147,7 +133,6 @@ pub fn ___syscall42(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int // offset to a file descriptor, which contains a read end and write end, 2 integers let fd_offset: u32 = varargs.get(ctx); - use std::cell::Cell; let emscripten_memory = ctx.memory(0); // convert the file descriptor into a vec with two slots @@ -174,8 +159,8 @@ pub fn ___syscall60(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { } // dup2 -pub fn ___syscall63(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall63 (dup2) {}", which); +pub fn ___syscall63(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall63 (dup2) {}", _which); let src: i32 = varargs.get(ctx); let dst: i32 = varargs.get(ctx); @@ -239,17 +224,17 @@ pub fn ___syscall183(ctx: &mut Ctx, buf_offset: u32, _size: u32) -> u32 { } // mmap2 -pub fn ___syscall192(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall192 (mmap2) {}", which); - let addr: i32 = varargs.get(ctx); +pub fn ___syscall192(ctx: &mut Ctx, _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); - let prot: i32 = varargs.get(ctx); - let flags: i32 = varargs.get(ctx); + let _prot: i32 = varargs.get(ctx); + let _flags: i32 = varargs.get(ctx); let fd: i32 = varargs.get(ctx); - let off: i32 = varargs.get(ctx); + let _off: i32 = varargs.get(ctx); debug!( "=> addr: {}, len: {}, prot: {}, flags: {}, fd: {}, off: {}", - addr, len, prot, flags, fd, off + _addr, len, _prot, _flags, fd, _off ); if fd == -1 { @@ -265,9 +250,9 @@ pub fn ___syscall192(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int } /// lseek -pub fn ___syscall140(ctx: &mut Ctx, which: i32, mut varargs: VarArgs) -> i32 { +pub fn ___syscall140(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { // -> c_int - debug!("emscripten::___syscall140 (lseek) {}", which); + debug!("emscripten::___syscall140 (lseek) {}", _which); let fd: i32 = varargs.get(ctx); let offset: i32 = varargs.get(ctx); let whence: i32 = varargs.get(ctx); @@ -277,15 +262,9 @@ pub fn ___syscall140(ctx: &mut Ctx, which: i32, mut varargs: VarArgs) -> i32 { /// readv #[allow(clippy::cast_ptr_alignment)] -pub fn ___syscall145(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> i32 { +pub fn ___syscall145(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> i32 { // -> ssize_t - debug!("emscripten::___syscall145 (readv) {}", which); - // let fd: i32 = varargs.get(ctx); - // let iov: u32 = varargs.get(ctx); - // let iovcnt: i32 = varargs.get(ctx); - // debug!("=> fd: {}, iov: {}, iovcnt = {}", fd, iov, iovcnt); - // let iov_addr = emscripten_memory_pointer!(ctx.memory(0), iov) as *mut iovec; - // unsafe { readv(fd, iov_addr, iovcnt) } + debug!("emscripten::___syscall145 (readv) {}", _which); let fd: i32 = varargs.get(ctx); let iov: i32 = varargs.get(ctx); @@ -320,9 +299,9 @@ pub fn ___syscall145(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> i32 { // writev #[allow(clippy::cast_ptr_alignment)] -pub fn ___syscall146(ctx: &mut Ctx, which: i32, mut varargs: VarArgs) -> i32 { +pub fn ___syscall146(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 { // -> ssize_t - debug!("emscripten::___syscall146 (writev) {}", which); + debug!("emscripten::___syscall146 (writev) {}", _which); let fd: i32 = varargs.get(ctx); let iov: i32 = varargs.get(ctx); let iovcnt: i32 = varargs.get(ctx); @@ -380,8 +359,8 @@ pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { } // stat64 -pub fn ___syscall195(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall195 (stat64) {}", which); +pub fn ___syscall195(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall195 (stat64) {}", _which); let pathname: u32 = varargs.get(ctx); let buf: u32 = varargs.get(ctx); @@ -400,8 +379,8 @@ pub fn ___syscall195(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int } // fstat64 -pub fn ___syscall197(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall197 (fstat64) {}", which); +pub fn ___syscall197(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall197 (fstat64) {}", _which); let fd: c_int = varargs.get(ctx); let buf: u32 = varargs.get(ctx); @@ -424,8 +403,8 @@ pub fn ___syscall220(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { } // fcntl64 -pub fn ___syscall221(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall221 (fcntl64) {}", which); +pub fn ___syscall221(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall221 (fcntl64) {}", _which); // fcntl64 let _fd: i32 = varargs.get(ctx); let cmd: u32 = varargs.get(ctx); @@ -461,8 +440,8 @@ pub fn ___syscall334(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { } // prlimit64 -pub fn ___syscall340(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall340 (prlimit64), {}", which); +pub fn ___syscall340(ctx: &mut Ctx, _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); let _resource: i32 = varargs.get(ctx); diff --git a/lib/emscripten/src/syscalls/unix.rs b/lib/emscripten/src/syscalls/unix.rs index a73456d09..1102b7a59 100644 --- a/lib/emscripten/src/syscalls/unix.rs +++ b/lib/emscripten/src/syscalls/unix.rs @@ -78,24 +78,24 @@ use libc::SO_NOSIGPIPE; const SO_NOSIGPIPE: c_int = 0; /// open -pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall5 (open) {}", which); +pub fn ___syscall5(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall5 (open) {}", _which); let pathname: u32 = varargs.get(ctx); let flags: i32 = varargs.get(ctx); let mode: u32 = varargs.get(ctx); let pathname_addr = emscripten_memory_pointer!(ctx.memory(0), pathname) as *const i8; - let path_str = unsafe { std::ffi::CStr::from_ptr(pathname_addr).to_str().unwrap() }; + let _path_str = unsafe { std::ffi::CStr::from_ptr(pathname_addr).to_str().unwrap() }; let fd = unsafe { open(pathname_addr, flags, mode) }; debug!( "=> pathname: {}, flags: {}, mode: {} = fd: {}\npath: {}", - pathname, flags, mode, fd, path_str + pathname, flags, mode, fd, _path_str ); fd } // chown -pub fn ___syscall212(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall212 (chown) {}", which); +pub fn ___syscall212(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall212 (chown) {}", _which); let pathname: u32 = varargs.get(ctx); let owner: u32 = varargs.get(ctx); @@ -107,8 +107,8 @@ pub fn ___syscall212(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int } // mkdir -pub fn ___syscall39(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall39 (mkdir) {}", which); +pub fn ___syscall39(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall39 (mkdir) {}", _which); let pathname: u32 = varargs.get(ctx); let mode: u32 = varargs.get(ctx); let pathname_addr = emscripten_memory_pointer!(ctx.memory(0), pathname) as *const i8; @@ -169,8 +169,8 @@ pub fn ___syscall330(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> pid_ } /// ioctl -pub fn ___syscall54(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall54 (ioctl) {}", which); +pub fn ___syscall54(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall54 (ioctl) {}", _which); let fd: i32 = varargs.get(ctx); let request: u32 = varargs.get(ctx); debug!("fd: {}, op: {}", fd, request); @@ -212,8 +212,8 @@ pub fn ___syscall54(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int // socketcall #[allow(clippy::cast_ptr_alignment)] -pub fn ___syscall102(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall102 (socketcall) {}", which); +pub fn ___syscall102(ctx: &mut Ctx, _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); @@ -279,13 +279,11 @@ pub fn ___syscall102(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int let address = emscripten_memory_pointer!(ctx.memory(0), address) as *mut sockaddr; // Debug received address - unsafe { - let proper_address = address as *const GuestSockaddrIn; - debug!( + let _proper_address = address as *const GuestSockaddrIn; + debug!( "=> address.sin_family: {:?}, address.sin_port: {:?}, address.sin_addr.s_addr: {:?}", - (*proper_address).sin_family, (*proper_address).sin_port, (*proper_address).sin_addr.s_addr + (*_proper_address).sin_family, (*_proper_address).sin_port, (*_proper_address).sin_addr.s_addr ); - } let status = unsafe { bind(socket, address, address_len) }; // debug!("=> status: {}", status); @@ -464,8 +462,8 @@ pub fn ___syscall102(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int } // pread -pub fn ___syscall180(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall180 (pread) {}", which); +pub fn ___syscall180(ctx: &mut Ctx, _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); let count: u32 = varargs.get(ctx); @@ -481,8 +479,8 @@ pub fn ___syscall180(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int } // pwrite -pub fn ___syscall181(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall181 (pwrite) {}", which); +pub fn ___syscall181(ctx: &mut Ctx, _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); let count: u32 = varargs.get(ctx); @@ -521,8 +519,8 @@ pub fn ___syscall114(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> pid_ // select #[allow(clippy::cast_ptr_alignment)] -pub fn ___syscall142(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall142 (newselect) {}", which); +pub fn ___syscall142(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall142 (newselect) {}", _which); let nfds: i32 = varargs.get(ctx); let readfds: u32 = varargs.get(ctx); @@ -540,8 +538,8 @@ pub fn ___syscall142(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int } // setpgid -pub fn ___syscall57(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall57 (setpgid) {}", which); +pub fn ___syscall57(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall57 (setpgid) {}", _which); let pid: i32 = varargs.get(ctx); let pgid: i32 = varargs.get(ctx); unsafe { setpgid(pid, pgid) } @@ -549,8 +547,8 @@ pub fn ___syscall57(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int /// uname // NOTE: Wondering if we should return custom utsname, like Emscripten. -pub fn ___syscall122(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { - debug!("emscripten::___syscall122 (uname) {}", which); +pub fn ___syscall122(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int { + debug!("emscripten::___syscall122 (uname) {}", _which); let buf: u32 = varargs.get(ctx); debug!("=> buf: {}", buf); let buf_addr = emscripten_memory_pointer!(ctx.memory(0), buf) as *mut utsname; diff --git a/lib/emscripten/src/syscalls/windows.rs b/lib/emscripten/src/syscalls/windows.rs index d2584bbd4..bd32d3b53 100644 --- a/lib/emscripten/src/syscalls/windows.rs +++ b/lib/emscripten/src/syscalls/windows.rs @@ -1,5 +1,4 @@ use crate::utils::copy_cstr_into_wasm; -use crate::utils::read_string_from_wasm; use crate::varargs::VarArgs; use libc::mkdir; use libc::open; diff --git a/lib/emscripten/src/time.rs b/lib/emscripten/src/time.rs index 7efb22e15..459124f10 100644 --- a/lib/emscripten/src/time.rs +++ b/lib/emscripten/src/time.rs @@ -75,8 +75,10 @@ pub fn _clock_gettime(ctx: &mut Ctx, clk_id: clockid_t, tp: c_int) -> c_int { tv_nsec: i32, } + #[allow(unreachable_patterns)] let timespec = match clk_id { CLOCK_REALTIME => time::get_time(), + CLOCK_MONOTONIC | CLOCK_MONOTONIC_COARSE => { let precise_ns = time::precise_time_ns(); time::Timespec::new( @@ -296,14 +298,14 @@ pub fn _time(ctx: &mut Ctx, time_p: u32) -> i32 { /// emscripten: _strftime pub fn _strftime( _ctx: &mut Ctx, - s_ptr: c_int, - maxsize: u32, - format_ptr: c_int, - tm_ptr: c_int, + _s_ptr: c_int, + _maxsize: u32, + _format_ptr: c_int, + _tm_ptr: c_int, ) -> i32 { debug!( "emscripten::_strftime {} {} {} {}", - s_ptr, maxsize, format_ptr, tm_ptr + _s_ptr, _maxsize, _format_ptr, _tm_ptr ); 0 } diff --git a/lib/emscripten/src/utils.rs b/lib/emscripten/src/utils.rs index 56b080207..79936f2f4 100644 --- a/lib/emscripten/src/utils.rs +++ b/lib/emscripten/src/utils.rs @@ -91,7 +91,7 @@ pub unsafe fn allocate_cstr_on_stack<'a>(ctx: &'a mut Ctx, s: &str) -> (u32, &'a } pub unsafe fn copy_terminated_array_of_cstrs(_ctx: &mut Ctx, cstrs: *mut *mut c_char) -> u32 { - let total_num = { + let _total_num = { let mut ptr = cstrs; let mut counter = 0; while !(*ptr).is_null() { @@ -102,7 +102,7 @@ pub unsafe fn copy_terminated_array_of_cstrs(_ctx: &mut Ctx, cstrs: *mut *mut c_ }; debug!( "emscripten::copy_terminated_array_of_cstrs::total_num: {}", - total_num + _total_num ); 0 } @@ -155,6 +155,7 @@ pub unsafe fn copy_stat_into_wasm(ctx: &mut Ctx, buf: u32, stat: &stat) { (*stat_ptr).st_ino = stat.st_ino as _; } +#[allow(dead_code)] // it's used in `env/windows/mod.rs`. pub fn read_string_from_wasm(memory: &Memory, offset: u32) -> String { let v: Vec = memory.view()[(offset as usize)..] .iter()