Fixed all Rust warnings

This commit is contained in:
Syrus Akbary
2018-11-26 20:28:13 -08:00
parent 30d4688fe3
commit 50f6ea3bd4
10 changed files with 30 additions and 39 deletions

View File

@@ -25,10 +25,6 @@ release:
# If you are in OS-X, you will need mingw-w64 for cross compiling to windows
# brew install mingw-w64
cargo build --release
# mkdir -p artifacts
# BINARY_NAME := $(./binary-name.sh)
# cp ./target/release/wasmer ./artifacts/$(./binary-name.sh)
# cp ./target/release/wasmer ./artifacts/${BINARY_NAME}
debug-release:
cargo build --release --features "debug"

View File

@@ -1,17 +1,15 @@
use super::super::host;
/// NOTE: These syscalls only support wasm_32 for now because they take u32 offset
use libc::{
c_int, getpwnam as libc_getpwnam, passwd,
getgrnam as libc_getgrnam, group, clock_gettime as libc_clock_gettime, timespec,
// uname as libc_uname, utsname,
c_int, getpwnam as libc_getpwnam,
getgrnam as libc_getgrnam,
};
use std::ffi::CStr;
use std::os::raw::c_char;
use std::{slice, mem};
use std::mem;
use crate::webassembly::Instance;
use super::utils::{copy_cstr_into_wasm, copy_terminated_array_of_cstrs};
use crate::webassembly::LinearMemory;
/// emscripten: _getenv
pub extern "C" fn _getenv(name_ptr: c_int, instance: &mut Instance) -> c_int {

View File

@@ -19,7 +19,7 @@ pub extern "C" fn _emscripten_memcpy_big(
}
/// emscripten: getTotalMemory
pub extern "C" fn get_total_memory(instance: &mut Instance) -> u32 {
pub extern "C" fn get_total_memory(_instance: &mut Instance) -> u32 {
debug!("emscripten::get_total_memory");
// instance.memories[0].current_pages()
16777216

View File

@@ -1,39 +1,39 @@
use super::process::abort_with_message;
use crate::webassembly::Instance;
pub extern "C" fn nullfunc_ii(x: u32, instance: &Instance) {
pub extern "C" fn nullfunc_ii(_x: u32, _instance: &Instance) {
abort_with_message("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 extern "C" fn nullfunc_iii(x: u32, instance: &Instance) {
pub extern "C" fn nullfunc_iii(_x: u32, _instance: &Instance) {
abort_with_message("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 extern "C" fn nullfunc_iiii(x: u32, instance: &Instance) {
pub extern "C" fn nullfunc_iiii(_x: u32, _instance: &Instance) {
abort_with_message("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 extern "C" fn nullfunc_iiiii(x: u32, instance: &Instance) {
pub extern "C" fn nullfunc_iiiii(_x: u32, _instance: &Instance) {
abort_with_message("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 extern "C" fn nullfunc_iiiiii(x: u32, instance: &Instance) {
pub extern "C" fn nullfunc_iiiiii(_x: u32, _instance: &Instance) {
abort_with_message("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 extern "C" fn nullfunc_vi(x: u32, instance: &Instance) {
pub extern "C" fn nullfunc_vi(_x: u32, _instance: &Instance) {
abort_with_message("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 extern "C" fn nullfunc_vii(x: u32, instance: &Instance) {
pub extern "C" fn nullfunc_vii(_x: u32, _instance: &Instance) {
abort_with_message("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 extern "C" fn nullfunc_viii(x: u32, instance: &Instance) {
pub extern "C" fn nullfunc_viii(_x: u32, _instance: &Instance) {
abort_with_message("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 extern "C" fn nullfunc_viiii(x: u32, instance: &Instance) {
pub extern "C" fn nullfunc_viiii(_x: u32, _instance: &Instance) {
abort_with_message("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)");
}

View File

@@ -1,5 +1,5 @@
use crate::webassembly::{LinearMemory, Instance};
use crate::webassembly::LinearMemory;
pub fn align_memory(ptr: u32) -> u32 {
(ptr + 15) & !15

View File

@@ -3,21 +3,21 @@
use libc::{
c_int, c_void, utsname, off_t,
ssize_t, write, exit, read,
open, close, ioctl,
uname, fcntl, lseek, readv,
open, close,
uname, lseek, readv,
iovec, writev, socklen_t,
sockaddr, socket, bind,
connect, listen, accept,
getsockname, getpeername,
sendto, recvfrom, setsockopt,
sendto, recvfrom,
getsockopt, sendmsg, recvmsg,
msghdr, getpid, getppid, pid_t,
msghdr, getpid, pid_t,
gid_t, getgid, fstat, stat,
pread, mkdir, chown,
// fcntl, ioctl, setsockopt, getppid
};
use crate::webassembly::Instance;
use super::varargs::VarArgs;
use std::{slice, mem};
use super::utils::copy_stat_into_wasm;
/// sys_exit
@@ -77,8 +77,8 @@ pub extern "C" fn ___syscall6(_which: c_int, mut varargs: VarArgs, instance: &mu
/// sys_ioctl
pub extern "C" fn ___syscall54(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int {
debug!("emscripten::___syscall54");
// let fd: i32 = varargs.get(instance);
// let request: u32 = varargs.get(instance);
let _fd: i32 = varargs.get(instance);
let _request: u32 = varargs.get(instance);
// debug!("fd: {}, op: {}", fd, request);
// unsafe { ioctl(fd, request as _) }
0
@@ -304,7 +304,7 @@ pub extern "C" fn ___syscall202() -> gid_t {
}
// sys_prlimit64
pub extern "C" fn ___syscall340(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int {
pub extern "C" fn ___syscall340(_which: c_int, mut _varargs: VarArgs, _instance: &mut Instance) -> c_int {
debug!("emscripten::___syscall340");
// NOTE: Doesn't really matter. Wasm modules cannot exceed WASM_PAGE_SIZE anyway.
0
@@ -398,7 +398,7 @@ pub extern "C" fn ___syscall212(_which: c_int, mut varargs: VarArgs, instance: &
// sys_fcntl64
pub extern "C" fn ___syscall221(_which: c_int, mut varargs: VarArgs, instance: &mut Instance) -> c_int {
let fd: i32 = varargs.get(instance);
let _fd: i32 = varargs.get(instance);
let cmd: u32 = varargs.get(instance);
match cmd {
2 => 0,

View File

@@ -3,7 +3,7 @@ use libc::{
c_long,
clock_gettime as libc_clock_gettime,
timespec,
tm,
// tm,
localtime,
time_t,
time
@@ -116,7 +116,7 @@ pub extern "C" fn _time(time_p: u32, instance: &mut Instance) -> time_t {
}
/// emscripten: _strftime
pub extern "C" fn _strftime(s_ptr: c_int, maxsize: u32, format_ptr: c_int, tm_ptr: c_int, instance: &mut Instance) -> time_t {
pub extern "C" fn _strftime(s_ptr: c_int, maxsize: u32, format_ptr: c_int, tm_ptr: c_int, _instance: &mut Instance) -> time_t {
debug!("emscripten::_strftime {} {} {} {}", s_ptr, maxsize, format_ptr, tm_ptr);
0
}

View File

@@ -2,7 +2,7 @@ use crate::webassembly::module::Module;
use crate::webassembly::Instance;
use std::ffi::CStr;
use std::os::raw::c_char;
use std::{slice, mem};
use std::slice;
use libc::stat;
use byteorder::{ByteOrder, LittleEndian};
@@ -20,7 +20,7 @@ pub unsafe fn copy_cstr_into_wasm(instance: &mut Instance, cstr: *const c_char)
let s = CStr::from_ptr(cstr).to_str().unwrap();
let space_offset = (instance.emscripten_data.malloc)(s.len() as _, instance);
let raw_memory = instance.memory_offset_addr(0, space_offset as _) as *mut u8;
let mut slice = slice::from_raw_parts_mut(raw_memory, s.len());
let slice = slice::from_raw_parts_mut(raw_memory, s.len());
for (byte, loc) in s.bytes().zip(slice.iter_mut()) {
*loc = byte;
@@ -28,7 +28,7 @@ pub unsafe fn copy_cstr_into_wasm(instance: &mut Instance, cstr: *const c_char)
space_offset
}
pub unsafe fn copy_terminated_array_of_cstrs(instance: &mut Instance, cstrs: *mut *mut c_char) -> u32 {
pub unsafe fn copy_terminated_array_of_cstrs(_instance: &mut Instance, cstrs: *mut *mut c_char) -> u32 {
let total_num = {
let mut ptr = cstrs;
let mut counter = 0;
@@ -44,7 +44,7 @@ pub unsafe fn copy_terminated_array_of_cstrs(instance: &mut Instance, cstrs: *mu
pub unsafe fn copy_stat_into_wasm(instance: &mut Instance, buf: u32, stat: &stat) {
let buf_ptr = instance.memory_offset_addr(0, buf as _) as *mut u8;
let mut buf = unsafe { slice::from_raw_parts_mut(buf_ptr, 76) };
let buf = slice::from_raw_parts_mut(buf_ptr, 76);
LittleEndian::write_u32(&mut buf[..], stat.st_dev as _);
LittleEndian::write_u32(&mut buf[4..], 0);

View File

@@ -5,9 +5,6 @@
//! unless you have memory unsafety elsewhere in your code.
use std::cell::UnsafeCell;
use nix::sys::signal::{Signal, SIGFPE, SIGILL, SIGSEGV, SIGBUS};
use super::webassembly::ErrorKind;
use super::sighandler::install_sighandler;
extern "C" {
pub fn setjmp(env: *mut ::nix::libc::c_void) -> ::nix::libc::c_int;

View File

@@ -22,7 +22,6 @@ use std::{fmt, slice, mem};
use std::sync::Arc;
use super::super::common::slice::{BoundedSlice, UncheckedSlice};
use super::super::recovery;
use super::errors::ErrorKind;
use super::import_object::{ImportObject, ImportValue};
use super::math_intrinsics;
@@ -144,6 +143,7 @@ extern "C" fn mock_fn() -> i32 {
return 0;
}
#[allow(dead_code)]
struct CompiledFunction {
code_buf: Vec<u8>,
reloc_sink: RelocSink,