diff --git a/Cargo.toml b/Cargo.toml index b082502ad..7a928a24e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ wasmer-runtime-core = { path = "lib/runtime-core" } wasmer-emscripten = { path = "lib/emscripten" } [target.'cfg(not(windows))'.dependencies] -wasmer-llvm-backend = { path = "lib/llvm-backend" } +wasmer-llvm-backend = { path = "lib/llvm-backend", optional = true } [workspace] members = ["lib/clif-backend", "lib/dynasm-backend", "lib/runtime", "lib/runtime-core", "lib/emscripten", "lib/spectests", "lib/win-exception-handler", "lib/runtime-c-api", "lib/llvm-backend"] @@ -37,8 +37,8 @@ wabt = "0.7.2" glob = "0.2.11" [features] -default = ["fast-tests"] - debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] +default = ["fast-tests"] # This feature will allow cargo test to run much faster fast-tests = [] +llvm = ["wasmer-llvm-backend"] diff --git a/lib/clif-backend/src/signal/windows.rs b/lib/clif-backend/src/signal/windows.rs index e5bd41994..99145869e 100644 --- a/lib/clif-backend/src/signal/windows.rs +++ b/lib/clif-backend/src/signal/windows.rs @@ -4,13 +4,9 @@ use crate::trampoline::Trampoline; use std::cell::Cell; use std::ffi::c_void; use std::ptr; +use wasmer_runtime_core::error::{RuntimeError, RuntimeResult}; use wasmer_runtime_core::vm::Ctx; use wasmer_runtime_core::vm::Func; -use wasmer_runtime_core::{ - error::{RuntimeError, RuntimeResult}, - structures::TypedIndex, - types::{MemoryIndex, TableIndex}, -}; use wasmer_win_exception_handler::CallProtectedData; pub use wasmer_win_exception_handler::_call_protected; use winapi::shared::minwindef::DWORD; @@ -47,8 +43,8 @@ pub fn call_protected( let CallProtectedData { code: signum, - exceptionAddress: exception_address, - instructionPointer: instruction_pointer, + exception_address, + instruction_pointer, } = result.unwrap_err(); if let Some(TrapData { diff --git a/lib/emscripten/src/env/unix/mod.rs b/lib/emscripten/src/env/unix/mod.rs index cc7e01b03..7c846150f 100644 --- a/lib/emscripten/src/env/unix/mod.rs +++ b/lib/emscripten/src/env/unix/mod.rs @@ -66,6 +66,8 @@ pub fn _unsetenv(ctx: &mut Ctx, name: c_int) -> c_int { #[allow(clippy::cast_ptr_alignment)] pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { debug!("emscripten::_getpwnam {}", name_ptr); + #[cfg(feature = "debug")] + let _ = name_ptr; #[repr(C)] struct GuestPasswd { diff --git a/lib/emscripten/src/env/windows/mod.rs b/lib/emscripten/src/env/windows/mod.rs index e95a66ec2..f738eccbb 100644 --- a/lib/emscripten/src/env/windows/mod.rs +++ b/lib/emscripten/src/env/windows/mod.rs @@ -7,7 +7,6 @@ use std::os::raw::c_char; use crate::env::call_malloc; use crate::utils::{copy_cstr_into_wasm, read_string_from_wasm}; -use std::ffi::CStr; use wasmer_runtime_core::vm::Ctx; extern "C" { @@ -29,10 +28,8 @@ pub fn _getenv(ctx: &mut Ctx, name: u32) -> u32 { } /// emscripten: _setenv // (name: *const char, name: *const value, overwrite: int); -pub fn _setenv(ctx: &mut Ctx, name: u32, value: u32, overwrite: u32) -> c_int { +pub fn _setenv(ctx: &mut Ctx, name: u32, value: u32, _overwrite: u32) -> c_int { debug!("emscripten::_setenv"); - let name_addr = emscripten_memory_pointer!(ctx.memory(0), name); - let value_addr = emscripten_memory_pointer!(ctx.memory(0), value); // setenv does not exist on windows, so we hack it with _putenv let name = read_string_from_wasm(ctx.memory(0), name); let value = read_string_from_wasm(ctx.memory(0), value); @@ -47,17 +44,16 @@ pub fn _setenv(ctx: &mut Ctx, name: u32, value: u32, overwrite: u32) -> c_int { /// emscripten: _putenv // (name: *const char); pub fn _putenv(ctx: &mut Ctx, name: c_int) -> c_int { debug!("emscripten::_putenv"); - let name_addr = emscripten_memory_pointer!(ctx.memory(0), name) as *const c_char; - - debug!("=> name({:?})", unsafe { CStr::from_ptr(name_addr) }); + debug!("=> name({:?})", unsafe { + std::ffi::CStr::from_ptr(name_addr) + }); unsafe { putenv(name_addr) } } /// emscripten: _unsetenv // (name: *const char); pub fn _unsetenv(ctx: &mut Ctx, name: u32) -> c_int { debug!("emscripten::_unsetenv"); - let name_addr = emscripten_memory_pointer!(ctx.memory(0), name); let name = read_string_from_wasm(ctx.memory(0), name); // no unsetenv on windows, so use putenv with an empty value let unsetenv_string = format!("{}=", name); @@ -70,6 +66,8 @@ pub fn _unsetenv(ctx: &mut Ctx, name: u32) -> c_int { #[allow(clippy::cast_ptr_alignment)] pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { debug!("emscripten::_getpwnam {}", name_ptr); + #[cfg(not(feature = "debug"))] + let _ = name_ptr; #[repr(C)] struct GuestPasswd { @@ -102,6 +100,8 @@ pub fn _getpwnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { #[allow(clippy::cast_ptr_alignment)] pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { debug!("emscripten::_getgrnam {}", name_ptr); + #[cfg(not(feature = "debug"))] + let _ = name_ptr; #[repr(C)] struct GuestGroup { @@ -126,6 +126,8 @@ pub fn _getgrnam(ctx: &mut Ctx, name_ptr: c_int) -> c_int { pub fn _sysconf(_ctx: &mut Ctx, name: c_int) -> c_long { debug!("emscripten::_sysconf {}", name); + #[cfg(not(feature = "debug"))] + let _ = name; // stub because sysconf is not valid on windows 0 } diff --git a/lib/emscripten/src/io/windows.rs b/lib/emscripten/src/io/windows.rs index 903d05900..99c67a0be 100644 --- a/lib/emscripten/src/io/windows.rs +++ b/lib/emscripten/src/io/windows.rs @@ -1,4 +1,3 @@ -use libc::{c_char, c_int}; use wasmer_runtime_core::vm::Ctx; // This may be problematic for msvc which uses inline functions for the printf family @@ -15,13 +14,18 @@ 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) }; } /// printf -pub fn printf(ctx: &mut Ctx, memory_offset: i32, extra: i32) -> i32 { +pub fn printf(_ctx: &mut Ctx, memory_offset: i32, extra: i32) -> i32 { debug!("emscripten::printf {}, {}", memory_offset, extra); + #[cfg(not(feature = "debug"))] + { + let _ = memory_offset; + let _ = extra; + } // unsafe { // let addr = emscripten_memory_pointer!(ctx.memory(0), memory_offset) as _; // _printf(addr, extra) diff --git a/lib/emscripten/src/process.rs b/lib/emscripten/src/process.rs index 2dbf90ca5..17a31d912 100644 --- a/lib/emscripten/src/process.rs +++ b/lib/emscripten/src/process.rs @@ -1,10 +1,9 @@ use libc::{abort, c_char, c_int, exit, EAGAIN}; #[cfg(not(target_os = "windows"))] -use libc::pid_t; - +type PidT = libc::pid_t; #[cfg(target_os = "windows")] -type pid_t = c_int; +type PidT = c_int; use std::ffi::CStr; use wasmer_runtime_core::vm::Ctx; @@ -22,7 +21,7 @@ pub fn _abort(_ctx: &mut Ctx) { } } -pub fn _fork(_ctx: &mut Ctx) -> pid_t { +pub fn _fork(_ctx: &mut Ctx) -> PidT { debug!("emscripten::_fork"); // unsafe { // fork() diff --git a/lib/emscripten/src/stdio.rs b/lib/emscripten/src/stdio.rs index d7d8ab736..2b95bafc7 100644 --- a/lib/emscripten/src/stdio.rs +++ b/lib/emscripten/src/stdio.rs @@ -15,7 +15,7 @@ pub struct StdioCapturer { use libc::{STDERR_FILENO, STDOUT_FILENO}; #[cfg(target_os = "windows")] -const STDIN_FILENO: libc::c_int = 0; +const _STDIN_FILENO: libc::c_int = 0; #[cfg(target_os = "windows")] const STDOUT_FILENO: libc::c_int = 1; #[cfg(target_os = "windows")] diff --git a/lib/emscripten/src/syscalls/windows.rs b/lib/emscripten/src/syscalls/windows.rs index bd32d3b53..b65ca158e 100644 --- a/lib/emscripten/src/syscalls/windows.rs +++ b/lib/emscripten/src/syscalls/windows.rs @@ -4,18 +4,20 @@ use libc::mkdir; use libc::open; use rand::Rng; use std::env; -use std::ffi::CStr; use std::ffi::CString; use std::fs::File; use std::io::Write; use std::os::raw::c_int; use wasmer_runtime_core::vm::Ctx; +#[allow(non_camel_case_types)] type pid_t = c_int; /// open pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall5 (open) {}", which); + #[cfg(not(feature = "debug"))] + let _ = which; let pathname: u32 = varargs.get(ctx); let flags: i32 = varargs.get(ctx); let mode: u32 = varargs.get(ctx); @@ -33,15 +35,15 @@ pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { let mut urandom_file = File::create(tmp_dir).unwrap(); // create some random bytes and put them into the file let random_bytes = rand::thread_rng().gen::<[u8; 32]>(); - urandom_file.write_all(&random_bytes); + 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, ptr) }; let raw_pointer_to_urandom_file = emscripten_memory_pointer!(ctx.memory(0), urandom_file_offset) as *const i8; let fd = unsafe { open(raw_pointer_to_urandom_file, flags, mode) }; debug!( - "=> pathname: {}, flags: {}, mode: {} = fd: {}\npath: {}", - pathname, flags, mode, fd, s + "=> pathname: {}, flags: {}, mode: {} = fd: {}", + pathname, flags, mode, fd ); fd } @@ -57,16 +59,19 @@ pub fn ___syscall5(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { } // chown -pub fn ___syscall212(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall212(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall212 (chown) {}", which); + #[cfg(not(feature = "debug"))] + let _ = which; -1 } // mkdir pub fn ___syscall39(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { debug!("emscripten::___syscall39 (mkdir) {}", which); + #[cfg(not(feature = "debug"))] + let _ = 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; unsafe { mkdir(pathname_addr) } } @@ -85,59 +90,73 @@ pub fn ___syscall202(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { } /// dup3 -pub fn ___syscall330(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> pid_t { +pub fn ___syscall330(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> pid_t { debug!("emscripten::___syscall330 (dup3)"); -1 } /// ioctl -pub fn ___syscall54(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall54(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall54 (ioctl) {}", which); + #[cfg(not(feature = "debug"))] + let _ = which; -1 } // socketcall #[allow(clippy::cast_ptr_alignment)] -pub fn ___syscall102(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall102(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall102 (socketcall) {}", which); + #[cfg(not(feature = "debug"))] + let _ = which; -1 } // pread -pub fn ___syscall180(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall180(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall180 (pread) {}", which); + #[cfg(not(feature = "debug"))] + let _ = which; -1 } // pwrite -pub fn ___syscall181(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall181(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall181 (pwrite) {}", which); + #[cfg(not(feature = "debug"))] + let _ = which; -1 } /// wait4 #[allow(clippy::cast_ptr_alignment)] -pub fn ___syscall114(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> pid_t { +pub fn ___syscall114(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> pid_t { debug!("emscripten::___syscall114 (wait4)"); -1 } // select #[allow(clippy::cast_ptr_alignment)] -pub fn ___syscall142(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall142(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall142 (newselect) {}", which); + #[cfg(not(feature = "debug"))] + let _ = which; -1 } // setpgid -pub fn ___syscall57(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int { +pub fn ___syscall57(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall57 (setpgid) {}", which); + #[cfg(not(feature = "debug"))] + let _ = which; -1 } /// 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 { +pub fn ___syscall122(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int { debug!("emscripten::___syscall122 (uname) {}", which); + #[cfg(not(feature = "debug"))] + let _ = which; -1 } diff --git a/lib/emscripten/src/time.rs b/lib/emscripten/src/time.rs index 459124f10..28a60ec34 100644 --- a/lib/emscripten/src/time.rs +++ b/lib/emscripten/src/time.rs @@ -10,6 +10,7 @@ use libc::{clockid_t, time as libc_time}; use libc::time_t; #[cfg(target_os = "windows")] +#[allow(non_camel_case_types)] type clockid_t = c_int; #[cfg(target_os = "windows")] diff --git a/lib/emscripten/src/utils.rs b/lib/emscripten/src/utils.rs index dfb7f6f64..5dcfd4e11 100644 --- a/lib/emscripten/src/utils.rs +++ b/lib/emscripten/src/utils.rs @@ -90,6 +90,7 @@ pub unsafe fn allocate_cstr_on_stack<'a>(ctx: &'a mut Ctx, s: &str) -> (u32, &'a (offset, slice) } +#[cfg(not(target_os = "windows"))] pub unsafe fn copy_terminated_array_of_cstrs(_ctx: &mut Ctx, cstrs: *mut *mut c_char) -> u32 { let _total_num = { let mut ptr = cstrs; diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index b63e69d9c..a66f584e4 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -159,13 +159,13 @@ pub struct wasmer_byte_array { #[allow(clippy::cast_ptr_alignment)] #[no_mangle] pub unsafe extern "C" fn wasmer_validate( - wasm_bytes: *mut uint8_t, + wasm_bytes: *const uint8_t, wasm_bytes_len: uint32_t, ) -> bool { if wasm_bytes.is_null() { return false; } - let bytes: &[u8] = ::std::slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); + let bytes: &[u8] = ::std::slice::from_raw_parts(wasm_bytes, wasm_bytes_len as usize); wasmer_runtime_core::validate(bytes) } diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 43d97ecb8..9a49d7617 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -535,6 +535,6 @@ wasmer_result_t wasmer_table_new(wasmer_table_t **table, wasmer_limits_t limits) /** * Returns true for valid wasm bytes and false for invalid bytes */ -bool wasmer_validate(uint8_t *wasm_bytes, uint32_t wasm_bytes_len); +bool wasmer_validate(const uint8_t *wasm_bytes, uint32_t wasm_bytes_len); #endif /* WASMER_H */ diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 76c27d46e..97260fe4b 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -418,7 +418,7 @@ uint32_t wasmer_table_length(wasmer_table_t *table); wasmer_result_t wasmer_table_new(wasmer_table_t **table, wasmer_limits_t limits); /// Returns true for valid wasm bytes and false for invalid bytes -bool wasmer_validate(uint8_t *wasm_bytes, uint32_t wasm_bytes_len); +bool wasmer_validate(const uint8_t *wasm_bytes, uint32_t wasm_bytes_len); } // extern "C" diff --git a/lib/runtime-core/src/memory/mod.rs b/lib/runtime-core/src/memory/mod.rs index 4a9dccba7..6f532b6d4 100644 --- a/lib/runtime-core/src/memory/mod.rs +++ b/lib/runtime-core/src/memory/mod.rs @@ -284,6 +284,7 @@ impl Clone for UnsharedMemory { } pub struct SharedMemory { + #[allow(dead_code)] desc: MemoryDescriptor, } diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index 0b7a3ea43..8f2c3c2ff 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -29,12 +29,14 @@ wabt = "0.7.4" [target.'cfg(not(windows))'.dependencies.wasmer-llvm-backend] path = "../llvm-backend" +optional = true [features] default = ["default-compiler"] default-compiler = ["wasmer-clif-backend", "wasmer-dynasm-backend"] cache = ["default-compiler"] debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] +llvm = ["wasmer-llvm-backend"] [[bench]] name = "nginx" diff --git a/lib/spectests/Cargo.toml b/lib/spectests/Cargo.toml index 6881e29ef..3318589f7 100644 --- a/lib/spectests/Cargo.toml +++ b/lib/spectests/Cargo.toml @@ -19,12 +19,12 @@ wasmer-clif-backend = { path = "../clif-backend", version = "0.2.0" } wasmer-dynasm-backend = { path = "../dynasm-backend", version = "0.1.0" } wabt = "0.7.2" -[target.'cfg(not(windows))'.dev-dependencies] -wasmer-llvm-backend = { path = "../llvm-backend", version = "0.1.0" } +[target.'cfg(not(windows))'.dependencies] +wasmer-llvm-backend = { path = "../llvm-backend", version = "0.1.0", optional = true } [features] default = ["fast-tests"] fast-tests = [] clif = [] -llvm = [] +llvm = ["wasmer-llvm-backend"] dynasm = [] \ No newline at end of file diff --git a/lib/win-exception-handler/exception_handling/exception_handling.c b/lib/win-exception-handler/exception_handling/exception_handling.c index eb45b204d..3c7990ec2 100644 --- a/lib/win-exception-handler/exception_handling/exception_handling.c +++ b/lib/win-exception-handler/exception_handling/exception_handling.c @@ -67,16 +67,16 @@ uint8_t callProtected(trampoline_t trampoline, savedStackPointer = get_callee_frame_address(); trampoline(ctx, func, param_vec, return_vec); out_result->code = 0; - out_result->exceptionAddress = 0; - out_result->instructionPointer = 0; + out_result->exception_address = 0; + out_result->instruction_pointer = 0; removeExceptionHandler(); return TRUE; } out_result->code = (uint64_t)signum; - out_result->exceptionAddress = (uint64_t)caughtExceptionAddress; - out_result->instructionPointer = caughtInstructionPointer; + out_result->exception_address = (uint64_t)caughtExceptionAddress; + out_result->instruction_pointer = caughtInstructionPointer; caughtExceptionAddress = 0; caughtInstructionPointer = 0; diff --git a/lib/win-exception-handler/exception_handling/exception_handling.h b/lib/win-exception-handler/exception_handling/exception_handling.h index cd5472149..f00227600 100644 --- a/lib/win-exception-handler/exception_handling/exception_handling.h +++ b/lib/win-exception-handler/exception_handling/exception_handling.h @@ -10,8 +10,8 @@ typedef void(*trampoline_t)(struct wasmer_instance_context_t*, const struct fun struct call_protected_result_t { uint64_t code; - uint64_t exceptionAddress; - uint64_t instructionPointer; + uint64_t exception_address; + uint64_t instruction_pointer; }; uint8_t callProtected( diff --git a/lib/win-exception-handler/src/exception_handling.rs b/lib/win-exception-handler/src/exception_handling.rs index 04c3c7f2e..966432a70 100644 --- a/lib/win-exception-handler/src/exception_handling.rs +++ b/lib/win-exception-handler/src/exception_handling.rs @@ -7,8 +7,8 @@ type CallProtectedResult = Result<(), CallProtectedData>; #[repr(C)] pub struct CallProtectedData { pub code: u64, - pub exceptionAddress: u64, - pub instructionPointer: u64, + pub exception_address: u64, + pub instruction_pointer: u64, } extern "C" { @@ -32,8 +32,8 @@ pub fn _call_protected( ) -> CallProtectedResult { let mut out_result = CallProtectedData { code: 0, - exceptionAddress: 0, - instructionPointer: 0, + exception_address: 0, + instruction_pointer: 0, }; let result = unsafe { __call_protected(