diff --git a/src/build_spectests.rs b/src/build_spectests.rs index 04e06f4e4..cf1fefc8d 100644 --- a/src/build_spectests.rs +++ b/src/build_spectests.rs @@ -207,8 +207,7 @@ fn test_module_{}() {{ module, module, calls.join("\n ") - ) - .as_str(), + ).as_str(), ); } self.module_calls.remove(&module); @@ -234,8 +233,7 @@ fn test_module_{}() {{ .replace("\n", "\n ") .replace("\\", "\\\\") .replace("\"", "\\\""), - ) - .as_str(), + ).as_str(), ); // We set the start call to the module @@ -246,8 +244,7 @@ fn test_module_{}() {{ result_object.instance.start(); }}\n", start_module_call - ) - .as_str(), + ).as_str(), ); self.module_calls .entry(self.last_module) @@ -272,8 +269,7 @@ fn {}_assert_invalid() {{ // We do this to ident four spaces back // String::from_utf8_lossy(&wasm_binary), // wast_string.replace("\n", "\n "), - ) - .as_str(), + ).as_str(), ); } @@ -315,8 +311,7 @@ fn {}_assert_invalid() {{ func_return, args_values.join(", "), assertion, - ) - .as_str(), + ).as_str(), ); self.module_calls .entry(self.last_module) @@ -373,8 +368,7 @@ fn {}_assert_invalid() {{ func_return, args_values.join(", "), assertion, - ) - .as_str(), + ).as_str(), ); self.module_calls .entry(self.last_module) @@ -404,8 +398,7 @@ fn {}_assert_malformed() {{ // We do this to ident four spaces back // String::from_utf8_lossy(&wasm_binary), // wast_string.replace("\n", "\n "), - ) - .as_str(), + ).as_str(), ); } @@ -469,8 +462,7 @@ fn {}_assert_malformed() {{ func_return, args_values.join(", "), assertion, - ) - .as_str(), + ).as_str(), ); Some(func_name) // let mut module_calls = self.module_calls.get(&self.last_module).unwrap(); @@ -491,7 +483,7 @@ fn {}_assert_malformed() {{ .or_insert(Vec::new()) .push(action_fn_name.unwrap()); } - + fn visit_perform_action(&mut self, action: &Action) { let action_fn_name = self.visit_action(action, None); @@ -525,8 +517,7 @@ fn {}() {{ trap_func_name, self.last_module, action_fn_name.unwrap(), - ) - .as_str(), + ).as_str(), ); // We don't group trap calls as they may cause memory faults diff --git a/src/linkers/emscripten/abort.rs b/src/linkers/emscripten/abort.rs index bb4cfa117..e2662bd19 100644 --- a/src/linkers/emscripten/abort.rs +++ b/src/linkers/emscripten/abort.rs @@ -1,9 +1,7 @@ - use crate::webassembly::Instance; use std::process; - pub extern "C" fn abort(_code: i32, _instance: &Instance) { process::abort(); // abort!("Aborted") -} \ No newline at end of file +} diff --git a/src/linkers/emscripten/mod.rs b/src/linkers/emscripten/mod.rs index 235814ed0..2ae7ab420 100644 --- a/src/linkers/emscripten/mod.rs +++ b/src/linkers/emscripten/mod.rs @@ -1,8 +1,8 @@ use crate::webassembly::ImportObject; +mod abort; mod printf; mod putchar; -mod abort; pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> { let mut import_object = ImportObject::new(); diff --git a/src/linkers/mod.rs b/src/linkers/mod.rs index c21b7bcbd..ef78d9e06 100644 --- a/src/linkers/mod.rs +++ b/src/linkers/mod.rs @@ -1,4 +1,3 @@ - pub mod emscripten; pub use self::emscripten::generate_emscripten_env; diff --git a/src/main.rs b/src/main.rs index 348787817..317fecf14 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,15 @@ #[macro_use] extern crate error_chain; -extern crate libc; extern crate cranelift_codegen; extern crate cranelift_entity; extern crate cranelift_native; extern crate cranelift_wasm; +extern crate libc; +extern crate memmap; +extern crate region; extern crate structopt; extern crate wabt; extern crate wasmparser; -extern crate memmap; -extern crate region; #[macro_use] extern crate target_lexicon; extern crate nix; @@ -68,10 +68,16 @@ fn read_file_contents(path: &PathBuf) -> Result, io::Error> { /// Execute a WASM/WAT file fn execute_wasm(wasm_path: PathBuf) -> Result<(), String> { - let mut wasm_binary: Vec = - read_file_contents(&wasm_path).map_err(|err| format!("Can't read the file {}: {}", wasm_path.as_os_str().to_string_lossy(), err))?; + let mut wasm_binary: Vec = read_file_contents(&wasm_path).map_err(|err| { + format!( + "Can't read the file {}: {}", + wasm_path.as_os_str().to_string_lossy(), + err + ) + })?; if !webassembly::utils::is_wasm_binary(&wasm_binary) { - wasm_binary = wabt::wat2wasm(wasm_binary).map_err(|err| format!("Can't convert from wast to wasm: {:?}", err))?; + wasm_binary = wabt::wat2wasm(wasm_binary) + .map_err(|err| format!("Can't convert from wast to wasm: {:?}", err))?; } let import_object = linkers::generate_emscripten_env(); diff --git a/src/sighandler.rs b/src/sighandler.rs index d64bba470..d75fb179b 100644 --- a/src/sighandler.rs +++ b/src/sighandler.rs @@ -5,7 +5,7 @@ //! Please read more about this here: https://github.com/CraneStation/wasmtime/issues/15 //! This code is inspired by: https://github.com/pepyakin/wasmtime/commit/625a2b6c0815b21996e111da51b9664feb174622 use nix::sys::signal::{ - sigaction, Signal, SaFlags, SigAction, SigHandler, SigSet, SIGBUS, SIGFPE, SIGILL, SIGSEGV, + sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal, SIGBUS, SIGFPE, SIGILL, SIGSEGV, }; static mut SETJMP_BUFFER: [::nix::libc::c_int; 27] = [0; 27]; diff --git a/src/webassembly/instance.rs b/src/webassembly/instance.rs index de8cf8b27..f357608ae 100644 --- a/src/webassembly/instance.rs +++ b/src/webassembly/instance.rs @@ -131,7 +131,7 @@ pub struct InstanceOptions { pub mock_missing_imports: bool, } -extern fn mock_fn() -> i32 { +extern "C" fn mock_fn() -> i32 { return 0; } @@ -167,15 +167,16 @@ impl Instance { // We walk through the imported functions and set the relocations // for each of this functions to be an empty vector (as is defined outside of wasm) for (module, field) in module.info.imported_funcs.iter() { - let function = import_object - .get(&module.as_str(), &field.as_str()); + let function = import_object.get(&module.as_str(), &field.as_str()); let function = if options.mock_missing_imports { function.unwrap_or_else(|| { - debug!("The import {}.{} is not provided, therefore will be mocked.", module, field); + debug!( + "The import {}.{} is not provided, therefore will be mocked.", + module, field + ); mock_fn as *const u8 }) - } - else { + } else { function.ok_or_else(|| { ErrorKind::LinkError(format!( "Imported function {}.{} was not provided in the import_functions", diff --git a/src/webassembly/memory.rs b/src/webassembly/memory.rs index 5330a60f3..b67253d7f 100644 --- a/src/webassembly/memory.rs +++ b/src/webassembly/memory.rs @@ -108,7 +108,7 @@ impl LinearMemory { // Copy old mem to new mem. Will a while loop be faster or is this going to be optimized? // TODO: Consider static heap for efficiency. for i in 0..prev_bytes { - unsafe { + unsafe { let new_mmap_index = new_mmap.get_unchecked_mut(i); let old_mmap_index = self.mmap.get_unchecked(i); *new_mmap_index = *old_mmap_index; diff --git a/src/webassembly/mod.rs b/src/webassembly/mod.rs index a3be88647..2beb17e88 100644 --- a/src/webassembly/mod.rs +++ b/src/webassembly/mod.rs @@ -47,7 +47,13 @@ pub fn instantiate( ) -> Result { let module = compile(buffer_source)?; debug!("webassembly - creating instance"); - let instance = Instance::new(&module, &import_object, InstanceOptions { mock_missing_imports: true })?; + let instance = Instance::new( + &module, + &import_object, + InstanceOptions { + mock_missing_imports: true, + }, + )?; debug!("webassembly - instance created"); Ok(ResultObject { module, instance }) } @@ -100,7 +106,12 @@ pub fn validate_or_error(bytes: &[u8]) -> Result<(), ErrorKind> { let state = parser.read(); match *state { wasmparser::ParserState::EndWasm => return Ok(()), - wasmparser::ParserState::Error(err) => return Err(ErrorKind::CompileError(format!("Validation error: {}", err.message))), + wasmparser::ParserState::Error(err) => { + return Err(ErrorKind::CompileError(format!( + "Validation error: {}", + err.message + ))) + } _ => (), } } diff --git a/src/webassembly/module.rs b/src/webassembly/module.rs index 27fd8b785..1094fdcdc 100644 --- a/src/webassembly/module.rs +++ b/src/webassembly/module.rs @@ -427,9 +427,7 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> { base: heap_base, min_size: Imm64::new(0), guard_size: Imm64::new(LinearMemory::DEFAULT_GUARD_SIZE as i64), - style: ir::HeapStyle::Dynamic { - bound_gv, - }, + style: ir::HeapStyle::Dynamic { bound_gv }, index_type: I32, }) @@ -535,7 +533,6 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> { .special_param(ir::ArgumentPurpose::VMContext) .expect("Missing vmctx parameter"); - // The `callee` value is an index into a table of function pointers. // Apparently, that table is stored at absolute address 0 in this dummy environment. // TODO: Generate bounds checking code.