diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 000000000..1c2f0d31e
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,33 @@
+# How to Contribute to Wasmer
+
+Thank you for your interest in contributing to Wasmer. This document outlines some recommendations on how to contribute.
+
+## Issues & Feature Requests
+Please use the issue template and provide a failing example if possible to help us recreate the issue.
+
+## Pull Requests
+For large changes, please try reaching the Wasmer using Github Issues or Spectrum Chat to ensure we can accept the change once it is ready.
+
+We recommend trying the following commands before sending a pull request to ensure code quality:
+- `cargo fmt --all` Ensures all code is correctly formatted.
+- Run `cargo test` in the crates that you are modifying.
+- Run `cargo build --all` (nightly) or `cargo build --all --exclude wasmer-singlepass-backend`
+
+A comprehensive CI test suite will be run by a Wasmer team member after the PR has been created.
+
+### Common Build Issues
+
+**LLVM Dependency**
+
+The LLVM backend requires LLVM to be installed to compile.
+
+So, you may run into the following error:
+```
+Didn't find usable system-wide LLVM.
+No suitable version of LLVM was found system-wide or pointed
+```
+
+**Singlepass Nightly Only**
+
+The singlepass crate depends on nightly so you may need to add the `+nightly` cargo flag to compile this crate.
+`error[E0554]: #![feature] may not be used on the stable release channel`
diff --git a/Cargo.lock b/Cargo.lock
index 81f2655e8..e1c67d6d7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -66,7 +66,7 @@ name = "backtrace-sys"
version = "0.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -144,7 +144,7 @@ name = "capstone-sys"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -180,7 +180,7 @@ dependencies = [
[[package]]
name = "cc"
-version = "1.0.38"
+version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -243,7 +243,7 @@ name = "cmake"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -658,7 +658,7 @@ name = "libloading"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -667,7 +667,7 @@ name = "llvm-sys"
version = "80.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -730,7 +730,7 @@ version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -956,7 +956,7 @@ version = "6.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1373,7 +1373,7 @@ name = "wabt-sys"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
"cmake 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1507,7 +1507,7 @@ version = "0.6.0"
dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"capstone 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
"goblin 0.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"inkwell 0.1.0 (git+https://github.com/wasmerio/inkwell?branch=llvm8-0)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1566,7 +1566,7 @@ version = "0.6.0"
dependencies = [
"bincode 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"blake2b_simd 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
"colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1747,7 +1747,7 @@ dependencies = [
"checksum cargo_toml 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "097f5ce64ba566a83d9d914fd005de1e5937fdd57d8c5d99a7593040955d75a9"
"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427"
"checksum cbindgen 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7e19db9a3892c88c74cbbdcd218196068a928f1b60e736c448b13a1e81f277"
-"checksum cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)" = "ce400c638d48ee0e9ab75aef7997609ec57367ccfe1463f21bf53c3eca67bf46"
+"checksum cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "b548a4ee81fccb95919d4e22cfea83c7693ebfd78f0495493178db20b3139da7"
"checksum cexpr 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7fa24eb00d5ffab90eaeaf1092ac85c04c64aaf358ea6f84505b8116d24c6af"
"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
"checksum cgmath 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)" = "64a4b57c8f4e3a2e9ac07e0f6abc9c24b6fc9e1b54c3478cfb598f3d0023e51c"
diff --git a/README.md b/README.md
index 5b7e038b2..67b8d04e9 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-
+
diff --git a/lib/clif-backend/src/lib.rs b/lib/clif-backend/src/lib.rs
index cdaae7688..eed22d39e 100644
--- a/lib/clif-backend/src/lib.rs
+++ b/lib/clif-backend/src/lib.rs
@@ -1,6 +1,8 @@
#![deny(
dead_code,
+ nonstandard_style,
unused_imports,
+ unused_mut,
unused_variables,
unused_unsafe,
unreachable_patterns
diff --git a/lib/emscripten-tests/tests/emtests/_common.rs b/lib/emscripten-tests/tests/emtests/_common.rs
index 8e4a70534..1e5dfba6e 100644
--- a/lib/emscripten-tests/tests/emtests/_common.rs
+++ b/lib/emscripten-tests/tests/emtests/_common.rs
@@ -42,7 +42,7 @@ macro_rules! assert_emscripten_output {
// let module = compile(&wasm_bytes[..])
// .map_err(|err| format!("Can't create the WebAssembly module: {}", err)).unwrap(); // NOTE: Need to figure what the unwrap is for ??
- let mut emscripten_globals = EmscriptenGlobals::new(&module);
+ let mut emscripten_globals = EmscriptenGlobals::new(&module).expect("globals are valid");
let import_object = generate_emscripten_env(&mut emscripten_globals);
let mut instance = module.instantiate(&import_object)
diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs
index d2ddc03d6..c09f9b772 100644
--- a/lib/emscripten/src/lib.rs
+++ b/lib/emscripten/src/lib.rs
@@ -1,6 +1,8 @@
#![deny(
dead_code,
+ nonstandard_style,
unused_imports,
+ unused_mut,
unused_variables,
unused_unsafe,
unreachable_patterns
@@ -14,7 +16,7 @@ use std::collections::HashMap;
use std::path::PathBuf;
use std::{f64, ffi::c_void};
use wasmer_runtime_core::{
- error::CallResult,
+ error::{CallError, CallResult, ResolveError},
export::Export,
func,
global::Global,
@@ -371,10 +373,11 @@ pub fn run_emscripten_instance(
0 => {
instance.call(func_name, &[])?;
}
- _ => panic!(
- "The emscripten main function has received an incorrect number of params {}",
- num_params
- ),
+ _ => {
+ return Err(CallError::Resolve(ResolveError::ExportWrongType {
+ name: "main".to_string(),
+ }))
+ }
};
}
@@ -402,11 +405,18 @@ fn store_module_arguments(ctx: &mut Ctx, args: Vec<&str>) -> (u32, u32) {
(argc as u32 - 1, argv_offset)
}
-pub fn emscripten_set_up_memory(memory: &Memory, globals: &EmscriptenGlobalsData) {
+pub fn emscripten_set_up_memory(
+ memory: &Memory,
+ globals: &EmscriptenGlobalsData,
+) -> Result<(), String> {
let dynamictop_ptr = globals.dynamictop_ptr;
let dynamic_base = globals.dynamic_base;
+ if (dynamictop_ptr / 4) as usize >= memory.view::().len() {
+ return Err("dynamictop_ptr beyond memory len".to_string());
+ }
memory.view::()[(dynamictop_ptr / 4) as usize].set(dynamic_base);
+ Ok(())
}
pub struct EmscriptenGlobalsData {
@@ -434,7 +444,7 @@ pub struct EmscriptenGlobals {
}
impl EmscriptenGlobals {
- pub fn new(module: &Module /*, static_bump: u32 */) -> Self {
+ pub fn new(module: &Module /*, static_bump: u32 */) -> Result {
let mut use_old_abort_on_cannot_grow_memory = false;
for (
index,
@@ -456,8 +466,8 @@ impl EmscriptenGlobals {
}
}
- let (table_min, table_max) = get_emscripten_table_size(&module);
- let (memory_min, memory_max, shared) = get_emscripten_memory_size(&module);
+ let (table_min, table_max) = get_emscripten_table_size(&module)?;
+ let (memory_min, memory_max, shared) = get_emscripten_memory_size(&module)?;
// Memory initialization
let memory_type = MemoryDescriptor {
@@ -486,7 +496,7 @@ impl EmscriptenGlobals {
static_top += 16;
let (dynamic_base, dynamictop_ptr) =
- get_emscripten_metadata(&module).unwrap_or_else(|| {
+ get_emscripten_metadata(&module)?.unwrap_or_else(|| {
let dynamictop_ptr = static_alloc(&mut static_top, 4);
(
align_memory(align_memory(static_top) + TOTAL_STACK),
@@ -510,7 +520,7 @@ impl EmscriptenGlobals {
}
};
- emscripten_set_up_memory(&memory, &data);
+ emscripten_set_up_memory(&memory, &data)?;
let mut null_func_names = vec![];
for (
@@ -528,14 +538,14 @@ impl EmscriptenGlobals {
}
}
- Self {
+ Ok(Self {
data,
memory,
table,
memory_min,
memory_max,
null_func_names,
- }
+ })
}
}
diff --git a/lib/emscripten/src/utils.rs b/lib/emscripten/src/utils.rs
index 37d3ae870..57d26f24e 100644
--- a/lib/emscripten/src/utils.rs
+++ b/lib/emscripten/src/utils.rs
@@ -33,37 +33,43 @@ pub fn is_emscripten_module(module: &Module) -> bool {
false
}
-pub fn get_emscripten_table_size(module: &Module) -> (u32, Option) {
- assert!(
- module.info().imported_tables.len() > 0,
- "Emscripten requires at least one imported table"
- );
+pub fn get_emscripten_table_size(module: &Module) -> Result<(u32, Option), String> {
+ if module.info().imported_tables.len() == 0 {
+ return Err("Emscripten requires at least one imported table".to_string());
+ }
let (_, table) = &module.info().imported_tables[ImportedTableIndex::new(0)];
- (table.minimum, table.maximum)
+ Ok((table.minimum, table.maximum))
}
-pub fn get_emscripten_memory_size(module: &Module) -> (Pages, Option, bool) {
- assert!(
- module.info().imported_tables.len() > 0,
- "Emscripten requires at least one imported memory"
- );
+pub fn get_emscripten_memory_size(module: &Module) -> Result<(Pages, Option, bool), String> {
+ if module.info().imported_memories.len() == 0 {
+ return Err("Emscripten requires at least one imported memory".to_string());
+ }
let (_, memory) = &module.info().imported_memories[ImportedMemoryIndex::new(0)];
- (memory.minimum, memory.maximum, memory.shared)
+ Ok((memory.minimum, memory.maximum, memory.shared))
}
/// Reads values written by `-s EMIT_EMSCRIPTEN_METADATA=1`
/// Assumes values start from the end in this order:
/// Last export: Dynamic Base
/// Second-to-Last export: Dynamic top pointer
-pub fn get_emscripten_metadata(module: &Module) -> Option<(u32, u32)> {
- let max_idx = &module.info().globals.iter().map(|(k, _)| k).max()?;
- let snd_max_idx = &module
+pub fn get_emscripten_metadata(module: &Module) -> Result