From 9c14c2e208b42d87a312d0da0dbbf5c68f6fdc44 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 29 Aug 2019 20:22:25 +0200 Subject: [PATCH 001/129] Add metering feature --- Cargo.lock | 1 + lib/runtime-c-api/Cargo.toml | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 3d8c85a48c9b..e49b74b61c3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1633,6 +1633,7 @@ dependencies = [ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime 0.7.0", "wasmer-runtime-core 0.7.0", + "wasmer-middleware-common 0.7.0", ] [[package]] diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index 8aac30da31e3..ceebed20d3f8 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -24,12 +24,18 @@ default-features = false path = "../runtime-core" version = "0.7.0" +[dependencies.wasmer-middleware-common] +path = "../middleware-common" +version = "0.6.0" +optional = true + [features] -default = ["cranelift-backend"] +#default = ["cranelift-backend"] debug = ["wasmer-runtime/debug"] cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift"] llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm"] singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass"] +metering = ["singlepass-backend", "wasmer-middleware-common"] [build-dependencies] cbindgen = "0.9.1" From 90a7fb4b197232d3864a7c708ab5487d9463ea62 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 29 Aug 2019 21:38:25 +0200 Subject: [PATCH 002/129] Add wasmer_compile_with_limit api --- Cargo.lock | 1 + lib/runtime-c-api/Cargo.toml | 10 ++++- lib/runtime-c-api/src/lib.rs | 1 + lib/runtime-c-api/src/metering.rs | 74 +++++++++++++++++++++++++++++++ lib/runtime-c-api/wasmer.h | 11 +++++ lib/runtime-c-api/wasmer.hh | 9 ++++ 6 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 lib/runtime-c-api/src/metering.rs diff --git a/Cargo.lock b/Cargo.lock index e49b74b61c3b..c101523e9be9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1634,6 +1634,7 @@ dependencies = [ "wasmer-runtime 0.7.0", "wasmer-runtime-core 0.7.0", "wasmer-middleware-common 0.7.0", + "wasmer-singlepass-backend 0.7.0", ] [[package]] diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index ceebed20d3f8..d893fd647743 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -29,13 +29,19 @@ path = "../middleware-common" version = "0.6.0" optional = true +[dependencies.wasmer-singlepass-backend] +path = "../singlepass-backend" +version = "0.6.0" +optional = true + + [features] -#default = ["cranelift-backend"] +default = ["cranelift-backend"] debug = ["wasmer-runtime/debug"] cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift"] llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm"] singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass"] -metering = ["singlepass-backend", "wasmer-middleware-common"] +metering = ["wasmer-runtime/singlepass", "wasmer-middleware-common", "wasmer-singlepass-backend"] [build-dependencies] cbindgen = "0.9.1" diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index 4dae18cd590b..a2777b2f0472 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -98,6 +98,7 @@ pub mod export; pub mod global; pub mod import; pub mod instance; +pub mod metering; pub mod memory; pub mod module; pub mod table; diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs new file mode 100644 index 000000000000..77986c88dc5e --- /dev/null +++ b/lib/runtime-c-api/src/metering.rs @@ -0,0 +1,74 @@ +use crate::{ + error::{update_last_error}, + module::{wasmer_module_t}, + wasmer_result_t, +}; +use std::{slice}; + + +#[cfg(feature = "metering")] +use wasmer_middleware_common::metering; +use wasmer_runtime_core::backend::{Compiler}; +use wasmer_runtime_core::{compile_with}; + +/// Creates a new Module with gas limit from the given wasm bytes. +/// +/// Returns `wasmer_result_t::WASMER_OK` upon success. +/// +/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` +/// and `wasmer_last_error_message` to get an error message. +#[allow(clippy::cast_ptr_alignment)] +#[cfg(feature = "metering")] +#[no_mangle] +pub unsafe extern "C" fn wasmer_compile_with_limit( + module: *mut *mut wasmer_module_t, + wasm_bytes: *mut u8, + wasm_bytes_len: u32, + gas_limit: u32, // TODO: allow more than 4 billion? +) -> wasmer_result_t { + let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); + let result = compile_with(bytes, &get_metered_compiler(gas_limit as u64)); + let new_module = match result { + Ok(instance) => instance, + Err(error) => { + update_last_error(error); + return wasmer_result_t::WASMER_ERROR; + } + }; + *module = Box::into_raw(Box::new(new_module)) as *mut wasmer_module_t; + wasmer_result_t::WASMER_OK +} + +#[cfg(feature = "metering")] +fn get_metered_compiler(limit: u64) -> impl Compiler { + use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler}; + use wasmer_singlepass_backend::ModuleCodeGenerator as SinglePassMCG; + let c: StreamingCompiler = StreamingCompiler::new(move || { + let mut chain = MiddlewareChain::new(); + chain.push(metering::Metering::new(limit)); + chain + }); + c +} + +// Without metering, wasmer_compile_with_limit is a copy of wasmer_compile +#[cfg(not(feature = "metering"))] +#[no_mangle] +pub unsafe extern "C" fn wasmer_compile_with_limit( + module: *mut *mut wasmer_module_t, + wasm_bytes: *mut u8, + wasm_bytes_len: u32, + _: u32, // TODO: allow more than 4 billion? +) -> wasmer_result_t { + let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); + let result = compile(bytes); + let new_module = match result { + Ok(instance) => instance, + Err(error) => { + update_last_error(error); + return wasmer_result_t::WASMER_ERROR; + } + }; + *module = Box::into_raw(Box::new(new_module)) as *mut wasmer_module_t; + wasmer_result_t::WASMER_OK +} diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 447d31075971..b483e6333784 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -182,6 +182,17 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, uint8_t *wasm_bytes, uint32_t wasm_bytes_len); +/** + * Creates a new Module with gas limit from the given wasm bytes. + * Returns `wasmer_result_t::WASMER_OK` upon success. + * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` + * and `wasmer_last_error_message` to get an error message. + */ +wasmer_result_t wasmer_compile_with_limit(wasmer_module_t **module, + uint8_t *wasm_bytes, + uint32_t wasm_bytes_len, + uint32_t gas_limit); + /** * Gets export descriptor kind */ diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index d372d8eb3e2d..a4961f595a8c 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -166,6 +166,15 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, uint8_t *wasm_bytes, uint32_t wasm_bytes_len); +/// Creates a new Module with gas limit from the given wasm bytes. +/// Returns `wasmer_result_t::WASMER_OK` upon success. +/// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` +/// and `wasmer_last_error_message` to get an error message. +wasmer_result_t wasmer_compile_with_limit(wasmer_module_t **module, + uint8_t *wasm_bytes, + uint32_t wasm_bytes_len, + uint32_t gas_limit); + /// Gets export descriptor kind wasmer_import_export_kind wasmer_export_descriptor_kind(wasmer_export_descriptor_t *export_); From 1e4c01ec8744fb9557a3795ea7fb809b010c1c1a Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 29 Aug 2019 21:49:52 +0200 Subject: [PATCH 003/129] Try adding metering functions - need help to compile --- lib/runtime-c-api/src/metering.rs | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 77986c88dc5e..7988a0d00356 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -1,5 +1,6 @@ use crate::{ error::{update_last_error}, + instance::{wasmer_instance_t}, module::{wasmer_module_t}, wasmer_result_t, }; @@ -10,6 +11,7 @@ use std::{slice}; use wasmer_middleware_common::metering; use wasmer_runtime_core::backend::{Compiler}; use wasmer_runtime_core::{compile_with}; +//use wasmer_runtime::{Instance}; /// Creates a new Module with gas limit from the given wasm bytes. /// @@ -51,6 +53,37 @@ fn get_metered_compiler(limit: u64) -> impl Compiler { c } +// returns gas used +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +#[cfg(feature = "metering")] +pub unsafe extern "C" fn wasmer_instance_get_points_used( + _: *mut wasmer_instance_t, +) -> u32 { // TODO: return u64 + 0 + // TODO +// let instance_ref = &*(instance as *const Instance); +// let points = metering::get_points_used(instance); +// points as u32 +} + +// sets gas used +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +#[cfg(feature = "metering")] +pub unsafe extern "C" fn wasmer_instance_set_points_used( + _: *mut wasmer_instance_t, + _: u32, +) { + // TODO +// let instance_ref = &*(instance as *const Instance); +// metering::set_points_used(instance, new_gas as u64) +} + + +/*** placeholder implementation if metering feature off ***/ +// + // Without metering, wasmer_compile_with_limit is a copy of wasmer_compile #[cfg(not(feature = "metering"))] #[no_mangle] @@ -72,3 +105,22 @@ pub unsafe extern "C" fn wasmer_compile_with_limit( *module = Box::into_raw(Box::new(new_module)) as *mut wasmer_module_t; wasmer_result_t::WASMER_OK } + +// returns gas used +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +#[cfg(not(feature = "metering"))] +pub unsafe extern "C" fn wasmer_instance_get_points_used( + _: *mut wasmer_instance_t, +) -> u32 { + 0 +} + +// sets gas used +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +#[cfg(not(feature = "metering"))] +pub unsafe extern "C" fn wasmer_instance_set_points_used( + _: *mut wasmer_instance_t, + _: u32, +) { } \ No newline at end of file From a9d79884e3ac6d930c26584ad1ef1890b9a692bb Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 30 Aug 2019 13:04:47 +0200 Subject: [PATCH 004/129] Metering api compiles with feature flag on and off --- lib/runtime-c-api/src/metering.rs | 36 ++++++++++++++----------------- lib/runtime-c-api/wasmer.h | 4 ++++ lib/runtime-c-api/wasmer.hh | 4 ++++ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 7988a0d00356..32bc88eabc75 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -6,12 +6,8 @@ use crate::{ }; use std::{slice}; - #[cfg(feature = "metering")] -use wasmer_middleware_common::metering; use wasmer_runtime_core::backend::{Compiler}; -use wasmer_runtime_core::{compile_with}; -//use wasmer_runtime::{Instance}; /// Creates a new Module with gas limit from the given wasm bytes. /// @@ -29,7 +25,7 @@ pub unsafe extern "C" fn wasmer_compile_with_limit( gas_limit: u32, // TODO: allow more than 4 billion? ) -> wasmer_result_t { let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); - let result = compile_with(bytes, &get_metered_compiler(gas_limit as u64)); + let result = wasmer_runtime_core::compile_with(bytes, &get_metered_compiler(gas_limit as u64)); let new_module = match result { Ok(instance) => instance, Err(error) => { @@ -43,6 +39,7 @@ pub unsafe extern "C" fn wasmer_compile_with_limit( #[cfg(feature = "metering")] fn get_metered_compiler(limit: u64) -> impl Compiler { + use wasmer_middleware_common::metering; use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler}; use wasmer_singlepass_backend::ModuleCodeGenerator as SinglePassMCG; let c: StreamingCompiler = StreamingCompiler::new(move || { @@ -58,13 +55,12 @@ fn get_metered_compiler(limit: u64) -> impl Compiler { #[no_mangle] #[cfg(feature = "metering")] pub unsafe extern "C" fn wasmer_instance_get_points_used( - _: *mut wasmer_instance_t, -) -> u32 { // TODO: return u64 - 0 - // TODO -// let instance_ref = &*(instance as *const Instance); -// let points = metering::get_points_used(instance); -// points as u32 + instance: *mut wasmer_instance_t, +) -> u64 { + use wasmer_middleware_common::metering; + let instance = &*(instance as *const wasmer_runtime::Instance); + let points = metering::get_points_used(instance); + points } // sets gas used @@ -72,12 +68,12 @@ pub unsafe extern "C" fn wasmer_instance_get_points_used( #[no_mangle] #[cfg(feature = "metering")] pub unsafe extern "C" fn wasmer_instance_set_points_used( - _: *mut wasmer_instance_t, - _: u32, + instance: *mut wasmer_instance_t, + new_gas: u64, ) { - // TODO -// let instance_ref = &*(instance as *const Instance); -// metering::set_points_used(instance, new_gas as u64) + use wasmer_middleware_common::metering; + let instance = &mut *(instance as *mut wasmer_runtime::Instance); + metering::set_points_used(instance, new_gas) } @@ -94,7 +90,7 @@ pub unsafe extern "C" fn wasmer_compile_with_limit( _: u32, // TODO: allow more than 4 billion? ) -> wasmer_result_t { let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); - let result = compile(bytes); + let result = wasmer_runtime::compile(bytes); let new_module = match result { Ok(instance) => instance, Err(error) => { @@ -112,7 +108,7 @@ pub unsafe extern "C" fn wasmer_compile_with_limit( #[cfg(not(feature = "metering"))] pub unsafe extern "C" fn wasmer_instance_get_points_used( _: *mut wasmer_instance_t, -) -> u32 { +) -> u64 { 0 } @@ -122,5 +118,5 @@ pub unsafe extern "C" fn wasmer_instance_get_points_used( #[cfg(not(feature = "metering"))] pub unsafe extern "C" fn wasmer_instance_set_points_used( _: *mut wasmer_instance_t, - _: u32, + _: u64, ) { } \ No newline at end of file diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index b483e6333784..e971784538db 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -522,6 +522,10 @@ void wasmer_instance_destroy(wasmer_instance_t *instance); */ void wasmer_instance_exports(wasmer_instance_t *instance, wasmer_exports_t **exports); +uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); + +void wasmer_instance_set_points_used(wasmer_instance_t *instance, uint64_t new_gas); + /** * Creates a new Instance from the given wasm bytes and imports. * diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index a4961f595a8c..bc8d3f565ca2 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -412,6 +412,10 @@ void wasmer_instance_destroy(wasmer_instance_t *instance); /// The caller owns the object and should call `wasmer_exports_destroy` to free it. void wasmer_instance_exports(wasmer_instance_t *instance, wasmer_exports_t **exports); +uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); + +void wasmer_instance_set_points_used(wasmer_instance_t *instance, uint64_t new_gas); + /// Creates a new Instance from the given wasm bytes and imports. /// /// Returns `wasmer_result_t::WASMER_OK` upon success. From ab8f3c59b301073d637c7ae15ce3d80cc8564609 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 30 Aug 2019 13:26:19 +0200 Subject: [PATCH 005/129] Fixed linter errors in metering.rs --- lib/runtime-c-api/src/metering.rs | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 32bc88eabc75..011f2bb1f777 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -1,13 +1,10 @@ use crate::{ - error::{update_last_error}, - instance::{wasmer_instance_t}, - module::{wasmer_module_t}, - wasmer_result_t, + error::update_last_error, instance::wasmer_instance_t, module::wasmer_module_t, wasmer_result_t, }; -use std::{slice}; +use std::slice; #[cfg(feature = "metering")] -use wasmer_runtime_core::backend::{Compiler}; +use wasmer_runtime_core::backend::Compiler; /// Creates a new Module with gas limit from the given wasm bytes. /// @@ -54,9 +51,7 @@ fn get_metered_compiler(limit: u64) -> impl Compiler { #[allow(clippy::cast_ptr_alignment)] #[no_mangle] #[cfg(feature = "metering")] -pub unsafe extern "C" fn wasmer_instance_get_points_used( - instance: *mut wasmer_instance_t, -) -> u64 { +pub unsafe extern "C" fn wasmer_instance_get_points_used(instance: *mut wasmer_instance_t) -> u64 { use wasmer_middleware_common::metering; let instance = &*(instance as *const wasmer_runtime::Instance); let points = metering::get_points_used(instance); @@ -76,9 +71,7 @@ pub unsafe extern "C" fn wasmer_instance_set_points_used( metering::set_points_used(instance, new_gas) } - /*** placeholder implementation if metering feature off ***/ -// // Without metering, wasmer_compile_with_limit is a copy of wasmer_compile #[cfg(not(feature = "metering"))] @@ -106,9 +99,7 @@ pub unsafe extern "C" fn wasmer_compile_with_limit( #[allow(clippy::cast_ptr_alignment)] #[no_mangle] #[cfg(not(feature = "metering"))] -pub unsafe extern "C" fn wasmer_instance_get_points_used( - _: *mut wasmer_instance_t, -) -> u64 { +pub unsafe extern "C" fn wasmer_instance_get_points_used(_: *mut wasmer_instance_t) -> u64 { 0 } @@ -116,7 +107,4 @@ pub unsafe extern "C" fn wasmer_instance_get_points_used( #[allow(clippy::cast_ptr_alignment)] #[no_mangle] #[cfg(not(feature = "metering"))] -pub unsafe extern "C" fn wasmer_instance_set_points_used( - _: *mut wasmer_instance_t, - _: u64, -) { } \ No newline at end of file +pub unsafe extern "C" fn wasmer_instance_set_points_used(_: *mut wasmer_instance_t, _: u64, ) {} \ No newline at end of file From abf6445b3c3d9d5716ccf700b557956b67431f36 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 30 Aug 2019 16:29:25 +0200 Subject: [PATCH 006/129] Added some TODOs to check serialization failure --- lib/runtime-c-api/src/metering.rs | 1 + lib/runtime-c-api/src/module.rs | 2 ++ lib/runtime/src/cache.rs | 1 + 3 files changed, 4 insertions(+) diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 011f2bb1f777..fdd1c5df14e9 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -83,6 +83,7 @@ pub unsafe extern "C" fn wasmer_compile_with_limit( _: u32, // TODO: allow more than 4 billion? ) -> wasmer_result_t { let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); + // TODO: this implicitly uses default_compiler() is that proper? maybe we override default_compiler let result = wasmer_runtime::compile(bytes); let new_module = match result { Ok(instance) => instance, diff --git a/lib/runtime-c-api/src/module.rs b/lib/runtime-c-api/src/module.rs index fbced49ead33..e1d5b319fac3 100644 --- a/lib/runtime-c-api/src/module.rs +++ b/lib/runtime-c-api/src/module.rs @@ -32,6 +32,7 @@ pub unsafe extern "C" fn wasmer_compile( wasm_bytes_len: u32, ) -> wasmer_result_t { let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); + // TODO: this implicitly uses default_compiler() is that proper? a better way to handle metering? let result = compile(bytes); let new_module = match result { Ok(instance) => instance, @@ -244,6 +245,7 @@ pub unsafe extern "C" fn wasmer_module_deserialize( let serialized_module: &[u8] = &*(serialized_module as *const &[u8]); match Artifact::deserialize(serialized_module) { + // TODO: we need to use a different call here to support middleware (or modify wasmer-runtime) Ok(artifact) => match load_cache_with(artifact, &default_compiler()) { Ok(deserialized_module) => { *module = Box::into_raw(Box::new(deserialized_module)) as _; diff --git a/lib/runtime/src/cache.rs b/lib/runtime/src/cache.rs index fe39b512aead..f649804cd962 100644 --- a/lib/runtime/src/cache.rs +++ b/lib/runtime/src/cache.rs @@ -109,6 +109,7 @@ impl Cache for FileSystemCache { fn store(&mut self, key: WasmHash, module: Module) -> Result<(), CacheError> { let filename = key.encode(); + // TODO: is the backend enough, or do we need the metering as well? let backend_str = module.info().backend.to_string(); let mut new_path_buf = self.path.clone(); new_path_buf.push(backend_str); From f68c77b8f0678ecd15fbf88c27d5546d7fb47878 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 30 Aug 2019 16:44:18 +0200 Subject: [PATCH 007/129] Fix u32 -> u64 in gas limit --- lib/runtime-c-api/src/metering.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index fdd1c5df14e9..838526f45554 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -19,10 +19,10 @@ pub unsafe extern "C" fn wasmer_compile_with_limit( module: *mut *mut wasmer_module_t, wasm_bytes: *mut u8, wasm_bytes_len: u32, - gas_limit: u32, // TODO: allow more than 4 billion? + gas_limit: u64, ) -> wasmer_result_t { let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); - let result = wasmer_runtime_core::compile_with(bytes, &get_metered_compiler(gas_limit as u64)); + let result = wasmer_runtime_core::compile_with(bytes, &get_metered_compiler(gas_limit)); let new_module = match result { Ok(instance) => instance, Err(error) => { @@ -80,7 +80,7 @@ pub unsafe extern "C" fn wasmer_compile_with_limit( module: *mut *mut wasmer_module_t, wasm_bytes: *mut u8, wasm_bytes_len: u32, - _: u32, // TODO: allow more than 4 billion? + _: u64, ) -> wasmer_result_t { let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); // TODO: this implicitly uses default_compiler() is that proper? maybe we override default_compiler From 1406bac9eee6e157dbb68f7f5c75e5d6181021b4 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 30 Aug 2019 16:57:49 +0200 Subject: [PATCH 008/129] Try to make C test case for using wasmer_compile_with_limit --- lib/runtime-c-api/tests/test-module-limit.c | 64 +++++++++++++++++++++ lib/runtime-c-api/wasmer.h | 2 +- lib/runtime-c-api/wasmer.hh | 2 +- 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 lib/runtime-c-api/tests/test-module-limit.c diff --git a/lib/runtime-c-api/tests/test-module-limit.c b/lib/runtime-c-api/tests/test-module-limit.c new file mode 100644 index 000000000000..a8a80c622f48 --- /dev/null +++ b/lib/runtime-c-api/tests/test-module-limit.c @@ -0,0 +1,64 @@ +#include +#include "../wasmer.h" +#include +#include + +// TODO: this only passes with "--features metering" +int main() +{ + // Read the wasm file bytes + FILE *file = fopen("assets/sum.wasm", "r"); + fseek(file, 0, SEEK_END); + long len = ftell(file); + uint8_t *bytes = malloc(len); + fseek(file, 0, SEEK_SET); + fread(bytes, 1, len, file); + fclose(file); + + wasmer_module_t *module = NULL; + wasmer_result_t compile_result = wasmer_compile_with_limit(&module, bytes, len, 20000); + printf("Compile result: %d\n", compile_result); + assert(compile_result == WASMER_OK); + + wasmer_import_t imports[] = {}; + wasmer_instance_t *instance = NULL; + wasmer_result_t instantiate_result = wasmer_module_instantiate(module, &instance, imports, 0); + printf("Instantiate result: %d\n", compile_result); + assert(instantiate_result == WASMER_OK); + + // ensure points works + long long points = wasmer_instance_get_points_used(instance); + assert(point == 0); + wasmer_instance_set_points_used(instance, 23); + points = wasmer_instance_get_points_used(instance); + assert(point == 23); + + wasmer_value_t param_one; + param_one.tag = WASM_I32; + param_one.value.I32 = 7; + wasmer_value_t param_two; + param_two.tag = WASM_I32; + param_two.value.I32 = 8; + wasmer_value_t params[] = {param_one, param_two}; + + wasmer_value_t result_one; + wasmer_value_t results[] = {result_one}; + + wasmer_result_t call_result = wasmer_instance_call(instance, "sum", params, 2, results, 1); + printf("Call result: %d\n", call_result); + printf("Result: %d\n", results[0].value.I32); + assert(results[0].value.I32 == 15); + assert(call_result == WASMER_OK); + + // ensure points updated, at least 2 + points = wasmer_instance_get_points_used(instance); + assert(point > 24); + + + printf("Destroy instance\n"); + wasmer_instance_destroy(instance); + + printf("Destroy module\n"); + wasmer_module_destroy(module); + return 0; +} diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index e971784538db..00c782aac84d 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -191,7 +191,7 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, wasmer_result_t wasmer_compile_with_limit(wasmer_module_t **module, uint8_t *wasm_bytes, uint32_t wasm_bytes_len, - uint32_t gas_limit); + uint64_t gas_limit); /** * Gets export descriptor kind diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index bc8d3f565ca2..4c9f07fe96d1 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -173,7 +173,7 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, wasmer_result_t wasmer_compile_with_limit(wasmer_module_t **module, uint8_t *wasm_bytes, uint32_t wasm_bytes_len, - uint32_t gas_limit); + uint64_t gas_limit); /// Gets export descriptor kind wasmer_import_export_kind wasmer_export_descriptor_kind(wasmer_export_descriptor_t *export_); From d9e884cb2bbfb7f780345cf749d809765279e847 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 30 Aug 2019 19:58:05 +0200 Subject: [PATCH 009/129] Run cargo +stable fmt --all --- lib/runtime-c-api/src/lib.rs | 2 +- lib/runtime-c-api/src/metering.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index a2777b2f0472..345c465d9a3f 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -98,8 +98,8 @@ pub mod export; pub mod global; pub mod import; pub mod instance; -pub mod metering; pub mod memory; +pub mod metering; pub mod module; pub mod table; #[cfg(all(unix, target_arch = "x86_64"))] diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 838526f45554..00793a2fee7b 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -51,7 +51,7 @@ fn get_metered_compiler(limit: u64) -> impl Compiler { #[allow(clippy::cast_ptr_alignment)] #[no_mangle] #[cfg(feature = "metering")] -pub unsafe extern "C" fn wasmer_instance_get_points_used(instance: *mut wasmer_instance_t) -> u64 { +pub unsafe extern "C" fn wasmer_instance_get_points_used(instance: *mut wasmer_instance_t) -> u64 { use wasmer_middleware_common::metering; let instance = &*(instance as *const wasmer_runtime::Instance); let points = metering::get_points_used(instance); @@ -100,7 +100,7 @@ pub unsafe extern "C" fn wasmer_compile_with_limit( #[allow(clippy::cast_ptr_alignment)] #[no_mangle] #[cfg(not(feature = "metering"))] -pub unsafe extern "C" fn wasmer_instance_get_points_used(_: *mut wasmer_instance_t) -> u64 { +pub unsafe extern "C" fn wasmer_instance_get_points_used(_: *mut wasmer_instance_t) -> u64 { 0 } @@ -108,4 +108,4 @@ pub unsafe extern "C" fn wasmer_instance_get_points_used(_: *mut wasmer_instance #[allow(clippy::cast_ptr_alignment)] #[no_mangle] #[cfg(not(feature = "metering"))] -pub unsafe extern "C" fn wasmer_instance_set_points_used(_: *mut wasmer_instance_t, _: u64, ) {} \ No newline at end of file +pub unsafe extern "C" fn wasmer_instance_set_points_used(_: *mut wasmer_instance_t, _: u64) {} From c9c7efc2e801a8db6b261e9bc52577caed070dad Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Wed, 18 Sep 2019 22:50:46 +0200 Subject: [PATCH 010/129] Clean up feature setup with --no-default-features, singlepass-backend fails --- lib/runtime-c-api/Cargo.toml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index d893fd647743..22e838af3254 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -39,9 +39,11 @@ optional = true default = ["cranelift-backend"] debug = ["wasmer-runtime/debug"] cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift"] +# to enable any of the below, you must disable the default cranelift backend with --no-default--features flag +# or adding default-features=false to the toml dependencies llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm"] -singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass"] -metering = ["wasmer-runtime/singlepass", "wasmer-middleware-common", "wasmer-singlepass-backend"] +singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass", "wasmer-singlepass-backend"] +metering = ["wasmer-middleware-common", "singlepass-backend"] [build-dependencies] cbindgen = "0.9.1" From 3d92bf3df2d581d8831db8c7a2870acdced6f33c Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 19 Sep 2019 18:34:22 +0200 Subject: [PATCH 011/129] get_metered_compiler uses whatever default backend --- lib/runtime-c-api/Cargo.toml | 13 +++++++++++-- lib/runtime-c-api/src/metering.rs | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index 22e838af3254..7a18ad9722f3 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -34,14 +34,23 @@ path = "../singlepass-backend" version = "0.6.0" optional = true +[dependencies.wasmer-llvm-backend] +path = "../llvm-backend" +version = "0.6.0" +optional = true + +[dependencies.wasmer-clif-backend] +path = "../clif-backend" +version = "0.6.0" +optional = true [features] default = ["cranelift-backend"] debug = ["wasmer-runtime/debug"] -cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift"] +cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift", "wasmer-clif-backend"] # to enable any of the below, you must disable the default cranelift backend with --no-default--features flag # or adding default-features=false to the toml dependencies -llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm"] +llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm", "wasmer-llvm-backend"] singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass", "wasmer-singlepass-backend"] metering = ["wasmer-middleware-common", "singlepass-backend"] diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 00793a2fee7b..79125ef043a1 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -38,8 +38,17 @@ pub unsafe extern "C" fn wasmer_compile_with_limit( fn get_metered_compiler(limit: u64) -> impl Compiler { use wasmer_middleware_common::metering; use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler}; - use wasmer_singlepass_backend::ModuleCodeGenerator as SinglePassMCG; - let c: StreamingCompiler = StreamingCompiler::new(move || { + + #[cfg(feature = "llvm-backend")] + use wasmer_llvm_backend::ModuleCodeGenerator as MeteredMCG; + + #[cfg(feature = "singlepass-backend")] + use wasmer_singlepass_backend::ModuleCodeGenerator as MeteredMCG; + + #[cfg(feature = "cranelift-backend")] + use wasmer_clif_backend::ModuleCodeGenerator as MeteredMCG; + + let c: StreamingCompiler = StreamingCompiler::new(move || { let mut chain = MiddlewareChain::new(); chain.push(metering::Metering::new(limit)); chain From 4dcafd56e3434bf767492efde252e059e912d919 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 19 Sep 2019 18:42:01 +0200 Subject: [PATCH 012/129] Handle null input in metering api --- lib/runtime-c-api/src/metering.rs | 42 ++++++++++++++++++++++++++++--- lib/runtime/src/cache.rs | 1 - 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 79125ef043a1..af45eca6c55c 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -1,6 +1,8 @@ use crate::{ - error::update_last_error, instance::wasmer_instance_t, module::wasmer_module_t, wasmer_result_t, + error::{update_last_error, CApiError}, instance::wasmer_instance_t, module::wasmer_module_t, wasmer_result_t, }; + + use std::slice; #[cfg(feature = "metering")] @@ -21,12 +23,27 @@ pub unsafe extern "C" fn wasmer_compile_with_limit( wasm_bytes_len: u32, gas_limit: u64, ) -> wasmer_result_t { + if module.is_null() { + update_last_error(CApiError { + msg: "module is null".to_string(), + }); + return wasmer_result_t::WASMER_ERROR; + } + if wasm_bytes.is_null() { + update_last_error(CApiError { + msg: "wasm bytes is null".to_string(), + }); + return wasmer_result_t::WASMER_ERROR; + } + let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); let result = wasmer_runtime_core::compile_with(bytes, &get_metered_compiler(gas_limit)); let new_module = match result { Ok(instance) => instance, - Err(error) => { - update_last_error(error); + Err(_) => { + update_last_error(CApiError { + msg: "compile error".to_string(), + }); return wasmer_result_t::WASMER_ERROR; } }; @@ -61,6 +78,9 @@ fn get_metered_compiler(limit: u64) -> impl Compiler { #[no_mangle] #[cfg(feature = "metering")] pub unsafe extern "C" fn wasmer_instance_get_points_used(instance: *mut wasmer_instance_t) -> u64 { + if instance.is_null() { + return 0; + } use wasmer_middleware_common::metering; let instance = &*(instance as *const wasmer_runtime::Instance); let points = metering::get_points_used(instance); @@ -75,6 +95,9 @@ pub unsafe extern "C" fn wasmer_instance_set_points_used( instance: *mut wasmer_instance_t, new_gas: u64, ) { + if instance.is_null() { + return; + } use wasmer_middleware_common::metering; let instance = &mut *(instance as *mut wasmer_runtime::Instance); metering::set_points_used(instance, new_gas) @@ -91,6 +114,19 @@ pub unsafe extern "C" fn wasmer_compile_with_limit( wasm_bytes_len: u32, _: u64, ) -> wasmer_result_t { + if module.is_null() { + update_last_error(CApiError { + msg: "module is null".to_string(), + }); + return wasmer_result_t::WASMER_ERROR; + } + if wasm_bytes.is_null() { + update_last_error(CApiError { + msg: "wasm bytes is null".to_string(), + }); + return wasmer_result_t::WASMER_ERROR; + } + let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); // TODO: this implicitly uses default_compiler() is that proper? maybe we override default_compiler let result = wasmer_runtime::compile(bytes); diff --git a/lib/runtime/src/cache.rs b/lib/runtime/src/cache.rs index f649804cd962..fe39b512aead 100644 --- a/lib/runtime/src/cache.rs +++ b/lib/runtime/src/cache.rs @@ -109,7 +109,6 @@ impl Cache for FileSystemCache { fn store(&mut self, key: WasmHash, module: Module) -> Result<(), CacheError> { let filename = key.encode(); - // TODO: is the backend enough, or do we need the metering as well? let backend_str = module.info().backend.to_string(); let mut new_path_buf = self.path.clone(); new_path_buf.push(backend_str); From 44d11742e779f0a2d409d3cd57713568ac25f211 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 19 Sep 2019 20:06:32 +0200 Subject: [PATCH 013/129] wasmer_compile_with_limit -> wasmer_compile_with_gas_metering --- lib/runtime-c-api/src/metering.rs | 6 +++--- lib/runtime-c-api/wasmer.h | 8 ++++---- lib/runtime-c-api/wasmer.hh | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index af45eca6c55c..7b0f3e520c24 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -17,7 +17,7 @@ use wasmer_runtime_core::backend::Compiler; #[allow(clippy::cast_ptr_alignment)] #[cfg(feature = "metering")] #[no_mangle] -pub unsafe extern "C" fn wasmer_compile_with_limit( +pub unsafe extern "C" fn wasmer_compile_with_gas_metering( module: *mut *mut wasmer_module_t, wasm_bytes: *mut u8, wasm_bytes_len: u32, @@ -105,10 +105,10 @@ pub unsafe extern "C" fn wasmer_instance_set_points_used( /*** placeholder implementation if metering feature off ***/ -// Without metering, wasmer_compile_with_limit is a copy of wasmer_compile +// Without metering, wasmer_compile_with_gas_metering is a copy of wasmer_compile #[cfg(not(feature = "metering"))] #[no_mangle] -pub unsafe extern "C" fn wasmer_compile_with_limit( +pub unsafe extern "C" fn wasmer_compile_with_gas_metering( module: *mut *mut wasmer_module_t, wasm_bytes: *mut u8, wasm_bytes_len: u32, diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 00c782aac84d..bf6423b11cd3 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -188,10 +188,10 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` * and `wasmer_last_error_message` to get an error message. */ -wasmer_result_t wasmer_compile_with_limit(wasmer_module_t **module, - uint8_t *wasm_bytes, - uint32_t wasm_bytes_len, - uint64_t gas_limit); +wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, + uint8_t *wasm_bytes, + uint32_t wasm_bytes_len, + uint64_t gas_limit); /** * Gets export descriptor kind diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 4c9f07fe96d1..3ef69b68acf8 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -170,10 +170,10 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, /// Returns `wasmer_result_t::WASMER_OK` upon success. /// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` /// and `wasmer_last_error_message` to get an error message. -wasmer_result_t wasmer_compile_with_limit(wasmer_module_t **module, - uint8_t *wasm_bytes, - uint32_t wasm_bytes_len, - uint64_t gas_limit); +wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, + uint8_t *wasm_bytes, + uint32_t wasm_bytes_len, + uint64_t gas_limit); /// Gets export descriptor kind wasmer_import_export_kind wasmer_export_descriptor_kind(wasmer_export_descriptor_t *export_); From 9f0e7184f39b7cd7e6763d58d03c885277d36db3 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 19 Sep 2019 20:10:23 +0200 Subject: [PATCH 014/129] Update deps to 0.7.0 after rebase --- Cargo.lock | 4 +++- lib/runtime-c-api/Cargo.toml | 8 ++++---- lib/runtime-c-api/wasmer.h | 2 ++ lib/runtime-c-api/wasmer.hh | 2 ++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c101523e9be9..e648642e1082 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1631,9 +1631,11 @@ version = "0.7.0" dependencies = [ "cbindgen 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmer-clif-backend 0.7.0", + "wasmer-llvm-backend 0.7.0", + "wasmer-middleware-common 0.7.0", "wasmer-runtime 0.7.0", "wasmer-runtime-core 0.7.0", - "wasmer-middleware-common 0.7.0", "wasmer-singlepass-backend 0.7.0", ] diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index 7a18ad9722f3..f4a31f948e19 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -26,22 +26,22 @@ version = "0.7.0" [dependencies.wasmer-middleware-common] path = "../middleware-common" -version = "0.6.0" +version = "0.7.0" optional = true [dependencies.wasmer-singlepass-backend] path = "../singlepass-backend" -version = "0.6.0" +version = "0.7.0" optional = true [dependencies.wasmer-llvm-backend] path = "../llvm-backend" -version = "0.6.0" +version = "0.7.0" optional = true [dependencies.wasmer-clif-backend] path = "../clif-backend" -version = "0.6.0" +version = "0.7.0" optional = true [features] diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index bf6423b11cd3..a23ecafd1913 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -184,7 +184,9 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, /** * Creates a new Module with gas limit from the given wasm bytes. + * * Returns `wasmer_result_t::WASMER_OK` upon success. + * * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` * and `wasmer_last_error_message` to get an error message. */ diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 3ef69b68acf8..7c9bccbfc765 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -167,7 +167,9 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, uint32_t wasm_bytes_len); /// Creates a new Module with gas limit from the given wasm bytes. +/// /// Returns `wasmer_result_t::WASMER_OK` upon success. +/// /// Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` /// and `wasmer_last_error_message` to get an error message. wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, From e51f332c9a0f178e9340bc4f6f5e2535aa4aae1e Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 19 Sep 2019 20:11:21 +0200 Subject: [PATCH 015/129] Use llvm backend by default for metering - all tests pass --- lib/runtime-c-api/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index f4a31f948e19..05bc38311311 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -52,7 +52,7 @@ cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend # or adding default-features=false to the toml dependencies llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm", "wasmer-llvm-backend"] singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass", "wasmer-singlepass-backend"] -metering = ["wasmer-middleware-common", "singlepass-backend"] +metering = ["wasmer-middleware-common", "llvm-backend"] [build-dependencies] cbindgen = "0.9.1" From 9b493bbf0f8b3d2d31ffc938e4fd1fe9ef05d639 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 19 Sep 2019 20:17:14 +0200 Subject: [PATCH 016/129] Add basic test-module-metering-serialize test Only passes with --features metering --- lib/runtime-c-api/tests/.gitignore | 1 + lib/runtime-c-api/tests/CMakeLists.txt | 5 + lib/runtime-c-api/tests/test-module-limit.c | 64 --------- .../tests/test-module-metering-serialize.c | 131 ++++++++++++++++++ 4 files changed, 137 insertions(+), 64 deletions(-) delete mode 100644 lib/runtime-c-api/tests/test-module-limit.c create mode 100644 lib/runtime-c-api/tests/test-module-metering-serialize.c diff --git a/lib/runtime-c-api/tests/.gitignore b/lib/runtime-c-api/tests/.gitignore index 26a85aceed74..8c1651b3f913 100644 --- a/lib/runtime-c-api/tests/.gitignore +++ b/lib/runtime-c-api/tests/.gitignore @@ -21,6 +21,7 @@ test-module test-module-exports test-module-imports test-module-serialize +test-module-metering-serialize test-tables test-validate test-context diff --git a/lib/runtime-c-api/tests/CMakeLists.txt b/lib/runtime-c-api/tests/CMakeLists.txt index 7db3cbcb06d7..1007ce361a6e 100644 --- a/lib/runtime-c-api/tests/CMakeLists.txt +++ b/lib/runtime-c-api/tests/CMakeLists.txt @@ -12,6 +12,7 @@ add_executable(test-module test-module.c) add_executable(test-module-exports test-module-exports.c) add_executable(test-module-imports test-module-imports.c) add_executable(test-module-serialize test-module-serialize.c) +add_executable(test-module-metering-serialize test-module-metering-serialize.c) add_executable(test-tables test-tables.c) add_executable(test-validate test-validate.c) add_executable(test-context test-context.c) @@ -82,6 +83,10 @@ target_link_libraries(test-module-serialize general ${WASMER_LIB}) target_compile_options(test-module-serialize PRIVATE ${COMPILER_OPTIONS}) add_test(test-module-serialize test-module-serialize) +target_link_libraries(test-module-metering-serialize general ${WASMER_LIB}) +target_compile_options(test-module-metering-serialize PRIVATE ${COMPILER_OPTIONS}) +add_test(test-module-metering-serialize test-module-metering-serialize) + target_link_libraries(test-tables general ${WASMER_LIB}) target_compile_options(test-tables PRIVATE ${COMPILER_OPTIONS}) add_test(test-tables test-tables) diff --git a/lib/runtime-c-api/tests/test-module-limit.c b/lib/runtime-c-api/tests/test-module-limit.c deleted file mode 100644 index a8a80c622f48..000000000000 --- a/lib/runtime-c-api/tests/test-module-limit.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include "../wasmer.h" -#include -#include - -// TODO: this only passes with "--features metering" -int main() -{ - // Read the wasm file bytes - FILE *file = fopen("assets/sum.wasm", "r"); - fseek(file, 0, SEEK_END); - long len = ftell(file); - uint8_t *bytes = malloc(len); - fseek(file, 0, SEEK_SET); - fread(bytes, 1, len, file); - fclose(file); - - wasmer_module_t *module = NULL; - wasmer_result_t compile_result = wasmer_compile_with_limit(&module, bytes, len, 20000); - printf("Compile result: %d\n", compile_result); - assert(compile_result == WASMER_OK); - - wasmer_import_t imports[] = {}; - wasmer_instance_t *instance = NULL; - wasmer_result_t instantiate_result = wasmer_module_instantiate(module, &instance, imports, 0); - printf("Instantiate result: %d\n", compile_result); - assert(instantiate_result == WASMER_OK); - - // ensure points works - long long points = wasmer_instance_get_points_used(instance); - assert(point == 0); - wasmer_instance_set_points_used(instance, 23); - points = wasmer_instance_get_points_used(instance); - assert(point == 23); - - wasmer_value_t param_one; - param_one.tag = WASM_I32; - param_one.value.I32 = 7; - wasmer_value_t param_two; - param_two.tag = WASM_I32; - param_two.value.I32 = 8; - wasmer_value_t params[] = {param_one, param_two}; - - wasmer_value_t result_one; - wasmer_value_t results[] = {result_one}; - - wasmer_result_t call_result = wasmer_instance_call(instance, "sum", params, 2, results, 1); - printf("Call result: %d\n", call_result); - printf("Result: %d\n", results[0].value.I32); - assert(results[0].value.I32 == 15); - assert(call_result == WASMER_OK); - - // ensure points updated, at least 2 - points = wasmer_instance_get_points_used(instance); - assert(point > 24); - - - printf("Destroy instance\n"); - wasmer_instance_destroy(instance); - - printf("Destroy module\n"); - wasmer_module_destroy(module); - return 0; -} diff --git a/lib/runtime-c-api/tests/test-module-metering-serialize.c b/lib/runtime-c-api/tests/test-module-metering-serialize.c new file mode 100644 index 000000000000..65ad94562095 --- /dev/null +++ b/lib/runtime-c-api/tests/test-module-metering-serialize.c @@ -0,0 +1,131 @@ +#include +#include "../wasmer.h" +#include +#include + +int main() +{ + // Read the wasm file bytes + FILE *file = fopen("assets/sum.wasm", "r"); + fseek(file, 0, SEEK_END); + long len = ftell(file); + uint8_t *bytes = malloc(len); + fseek(file, 0, SEEK_SET); + fread(bytes, 1, len, file); + fclose(file); + + wasmer_module_t *module_one = NULL; + unsigned long long gas_limit = 100; + wasmer_result_t compile_result = wasmer_compile_with_gas_metering(&module_one, bytes, len, gas_limit); + printf("Compile result: %d\n", compile_result); + assert(compile_result == WASMER_OK); + + // first run before serialization + wasmer_import_t imports[] = {}; + wasmer_instance_t *instance_one = NULL; + wasmer_result_t instantiate_result = wasmer_module_instantiate(module_one, &instance_one, imports, 0); + printf("Instantiate result: %d\n", instantiate_result); + assert(instantiate_result == WASMER_OK); + + // check behavior of getting/setting points, also no error on null + assert(wasmer_instance_get_points_used(instance_one) == 0); + wasmer_instance_set_points_used(instance_one, 50); + assert(wasmer_instance_get_points_used(instance_one) == 50); + assert(wasmer_instance_get_points_used(NULL) == 0); + + wasmer_value_t param_one; + param_one.tag = WASM_I32; + param_one.value.I32 = 7; + wasmer_value_t param_two; + param_two.tag = WASM_I32; + param_two.value.I32 = 8; + wasmer_value_t params[] = {param_one, param_two}; + + wasmer_value_t result_one; + wasmer_value_t results[] = {result_one}; + + wasmer_result_t call_result = wasmer_instance_call(instance_one, "sum", params, 2, results, 1); + printf("Call result: %d\n", call_result); + printf("Result: %d\n", results[0].value.I32); + assert(results[0].value.I32 == 15); + assert(call_result == WASMER_OK); + + // ensure we got charged some gas + assert(wasmer_instance_get_points_used(instance_one) == 54); + // TODO: try again an ensure limit enforced... need another function + + // end first run + + wasmer_serialized_module_t *serialized_module = NULL; + wasmer_result_t serialize_result = wasmer_module_serialize(&serialized_module, module_one); + printf("Serialize result: %d\n", serialize_result); + assert(serialize_result == WASMER_OK); + + wasmer_byte_array serialized_module_bytes = wasmer_serialized_module_bytes(serialized_module); + printf("Serialized module pointer: %p\n", serialized_module_bytes.bytes); + printf("Serialized module length: %d\n", serialized_module_bytes.bytes_len); + assert(serialized_module_bytes.bytes != NULL); + assert(serialized_module_bytes.bytes_len > 8); + assert(serialized_module_bytes.bytes[0] == 'W'); + assert(serialized_module_bytes.bytes[1] == 'A'); + assert(serialized_module_bytes.bytes[2] == 'S'); + assert(serialized_module_bytes.bytes[3] == 'M'); + assert(serialized_module_bytes.bytes[4] == 'E'); + assert(serialized_module_bytes.bytes[5] == 'R'); + + wasmer_module_t *module_two = NULL; + wasmer_result_t unserialize_result = wasmer_module_deserialize(&module_two, serialized_module); + assert(unserialize_result == WASMER_OK); + + // second run with deserialized module + wasmer_instance_t *instance_two = NULL; + instantiate_result = wasmer_module_instantiate(module_two, &instance_two, imports, 0); + printf("Instantiate result: %d\n", instantiate_result); + assert(instantiate_result == WASMER_OK); + + // ensure points independent of other instance + assert(wasmer_instance_get_points_used(instance_one) > 50); + assert(wasmer_instance_get_points_used(instance_two) == 0); + wasmer_instance_set_points_used(instance_two, 20); + assert(wasmer_instance_get_points_used(instance_one) > 50); + assert(wasmer_instance_get_points_used(instance_two) == 20); + + call_result = wasmer_instance_call(instance_two, "sum", params, 2, results, 1); + printf("Call result: %d\n", call_result); + printf("Result: %d\n", results[0].value.I32); + assert(results[0].value.I32 == 15); + assert(call_result == WASMER_OK); + + // and we charge the right one + assert(wasmer_instance_get_points_used(instance_two) == 24); + + wasmer_serialized_module_t *serialized_module_two = NULL; + wasmer_result_t serialized_module_from_bytes_result = wasmer_serialized_module_from_bytes( + &serialized_module_two, + serialized_module_bytes.bytes, + serialized_module_bytes.bytes_len + ); + assert(serialized_module_from_bytes_result == WASMER_OK); + + wasmer_module_t *module_three = NULL; + wasmer_result_t unserialized_result_two = wasmer_module_deserialize(&module_three, serialized_module_two); + assert(unserialized_result_two == WASMER_OK); + + wasmer_instance_t *instance_three = NULL; + wasmer_result_t instantiate_result_two = wasmer_module_instantiate(module_three, &instance_three, imports, 0); + assert(instantiate_result_two == WASMER_OK); + + printf("Destroy the serialized module\n"); + wasmer_serialized_module_destroy(serialized_module); + wasmer_serialized_module_destroy(serialized_module_two); + + printf("Destroy instance\n"); + wasmer_instance_destroy(instance_one); + wasmer_instance_destroy(instance_two); + wasmer_instance_destroy(instance_three); + + printf("Destroy modules\n"); + wasmer_module_destroy(module_one); + wasmer_module_destroy(module_two); + return 0; +} From f72b4cfead838b22e49e12df78b3b9091d7cce83 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 20 Sep 2019 12:30:06 +0200 Subject: [PATCH 017/129] Expose CraneliftModuleCodeGenerator to test with --metering, document issues --- lib/clif-backend/src/lib.rs | 2 ++ lib/runtime-c-api/Cargo.toml | 3 ++- lib/runtime-c-api/README.md | 25 +++++++++++++++++++++++++ lib/runtime-c-api/src/metering.rs | 2 +- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/clif-backend/src/lib.rs b/lib/clif-backend/src/lib.rs index 60f19a877ed3..9dc717486ea5 100644 --- a/lib/clif-backend/src/lib.rs +++ b/lib/clif-backend/src/lib.rs @@ -59,3 +59,5 @@ pub type CraneliftCompiler = SimpleStreamingCompilerGen< signal::Caller, code::CodegenError, >; + +pub use code::CraneliftModuleCodeGenerator; diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index 05bc38311311..82b566e72599 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -52,7 +52,8 @@ cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend # or adding default-features=false to the toml dependencies llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm", "wasmer-llvm-backend"] singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass", "wasmer-singlepass-backend"] -metering = ["wasmer-middleware-common", "llvm-backend"] +# you need to enable llvm or singlepass backend for this to work (middleware not supported in cranelift) +metering = ["wasmer-middleware-common"] [build-dependencies] cbindgen = "0.9.1" diff --git a/lib/runtime-c-api/README.md b/lib/runtime-c-api/README.md index 1e741cfd121d..1fe2e982727f 100644 --- a/lib/runtime-c-api/README.md +++ b/lib/runtime-c-api/README.md @@ -119,6 +119,31 @@ $ make $ make test ``` +# Feature Flags + +By default this uses the cranelift compiler. You can enable a different compiler +by using feature flags. However, make sure to disable default features, as exactly +one default compiler must be enabled. + +LLVM: `cargo build --no-default-features --features llvm-backend` +single-pass: `cargo build --no-default-features --features singlepass-backend` + +Note that the single-pass backend +[does not currently support serialization](https://github.com/wasmerio/wasmer/issues/811), +so the serialization related tests will fail there. + +There is also a flag to enable gas metering which provides three new api endpoints: + +These are replaced with stubs of a normal compiler if the metering flag is not provided, +to provide a consistent API and not break upstream packages at link time. + +Note that the gas metering middleware is +[not currently compatible with the cranelift backend](https://github.com/wasmerio/wasmer/issues/819), +so you must select a different backend (see above) if you enable metering.eg + +`cargo build --no-default-features --features llvm-backend,metering` + +Once that issue is resolved, `cargo build --features metering` will give you a useful binary. # License diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 7b0f3e520c24..bac6fb3334b1 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -63,7 +63,7 @@ fn get_metered_compiler(limit: u64) -> impl Compiler { use wasmer_singlepass_backend::ModuleCodeGenerator as MeteredMCG; #[cfg(feature = "cranelift-backend")] - use wasmer_clif_backend::ModuleCodeGenerator as MeteredMCG; + use wasmer_clif_backend::CraneliftModuleCodeGenerator as MeteredMCG; let c: StreamingCompiler = StreamingCompiler::new(move || { let mut chain = MiddlewareChain::new(); From 304a16eaeacf593ec21b148efddd2aeb49ddba3e Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 20 Sep 2019 12:41:42 +0200 Subject: [PATCH 018/129] Fix linter issue --- lib/runtime-c-api/src/metering.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index bac6fb3334b1..4cd3feee2486 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -1,8 +1,10 @@ use crate::{ - error::{update_last_error, CApiError}, instance::wasmer_instance_t, module::wasmer_module_t, wasmer_result_t, + error::{update_last_error, CApiError}, + instance::wasmer_instance_t, + module::wasmer_module_t, + wasmer_result_t, }; - use std::slice; #[cfg(feature = "metering")] From f08823b34f60dd6e4feb5a2d09006cad798f1964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Mon, 21 Oct 2019 10:40:11 +0300 Subject: [PATCH 019/129] Update versions in Cargo.lock and lib/runtime-c-api/Cargo.toml --- Cargo.lock | 268 +++++++++++++++++------------------ lib/runtime-c-api/Cargo.toml | 8 +- 2 files changed, 138 insertions(+), 138 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd757d8c162f..533b4c548bd9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,10 +23,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "arrayvec" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "nodrop 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -34,7 +34,7 @@ name = "atty" version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -45,7 +45,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bincode" -version = "1.1.4" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -58,16 +58,16 @@ name = "bindgen" version = "0.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "cexpr 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "clang-sys 0.28.1 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -77,7 +77,7 @@ dependencies = [ [[package]] name = "bitflags" -version = "1.1.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -86,7 +86,7 @@ version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -128,7 +128,7 @@ name = "capstone-sys" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -153,10 +153,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -164,7 +164,7 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.45" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -177,7 +177,7 @@ dependencies = [ [[package]] name = "cfg-if" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -186,7 +186,7 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -197,7 +197,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -209,7 +209,7 @@ name = "cloudabi" version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -217,7 +217,7 @@ name = "cmake" version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -242,8 +242,8 @@ dependencies = [ "cranelift-codegen-meta 0.44.0 (registry+https://github.com/rust-lang/crates.io-index)", "cranelift-codegen-shared 0.44.0 (registry+https://github.com/rust-lang/crates.io-index)", "cranelift-entity 0.44.0 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "target-lexicon 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -290,7 +290,7 @@ dependencies = [ "csv 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -299,7 +299,7 @@ dependencies = [ "rayon-core 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "tinytemplate 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -328,8 +328,8 @@ name = "crossbeam-epoch" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -349,7 +349,7 @@ name = "crossbeam-utils" version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -361,7 +361,7 @@ dependencies = [ "bstr 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "csv-core 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -375,7 +375,7 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.10" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -395,7 +395,7 @@ name = "dynasm" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -416,7 +416,7 @@ dependencies = [ [[package]] name = "either" -version = "1.5.2" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -454,7 +454,7 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -464,26 +464,26 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "failure" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "failure_derive" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", - "synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -506,7 +506,7 @@ name = "generational-arena" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -523,8 +523,8 @@ name = "getrandom" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -533,7 +533,7 @@ name = "ghost" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -592,11 +592,11 @@ name = "inkwell" version = "0.1.0" source = "git+https://github.com/wasmerio/inkwell?branch=llvm8-0#8f480124663b812ee76cd4370f3ee170135b9d0e" dependencies = [ - "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "enum-methods 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "inkwell_internal_macros 0.1.0 (git+https://github.com/wasmerio/inkwell?branch=llvm8-0)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "llvm-sys 80.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -617,7 +617,7 @@ name = "inventory" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "ctor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "ctor 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "ghost 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "inventory-impl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -627,7 +627,7 @@ name = "inventory-impl" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -637,7 +637,7 @@ name = "itertools" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -665,7 +665,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.62" +version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -673,7 +673,7 @@ name = "libloading" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -682,9 +682,9 @@ name = "llvm-sys" version = "80.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -702,7 +702,7 @@ name = "log" version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -715,7 +715,7 @@ name = "memchr" version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -723,7 +723,7 @@ name = "memmap" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -732,7 +732,7 @@ name = "memmap" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -749,16 +749,16 @@ name = "nix" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.45 (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.62 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "nodrop" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -783,7 +783,7 @@ name = "num_cpus" version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -800,7 +800,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -837,9 +837,9 @@ name = "parking_lot_core" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -870,7 +870,7 @@ name = "proc-macro-error" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -885,7 +885,7 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.3" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -914,7 +914,7 @@ name = "quote" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -923,7 +923,7 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -974,7 +974,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -994,8 +994,8 @@ name = "raw-cpuid" version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1005,7 +1005,7 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "rayon-core 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1084,7 +1084,7 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1162,18 +1162,18 @@ name = "serde_derive" version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_json" -version = "1.0.40" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1213,7 +1213,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro-error 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1243,7 +1243,7 @@ name = "syn" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1258,13 +1258,13 @@ dependencies = [ [[package]] name = "synstructure" -version = "0.10.2" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1277,9 +1277,9 @@ name = "target-lexicon" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1287,8 +1287,8 @@ name = "tempfile" version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1324,7 +1324,7 @@ name = "time" version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1335,7 +1335,7 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1376,7 +1376,7 @@ name = "typetag-impl" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1428,7 +1428,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "wabt-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1437,7 +1437,7 @@ name = "wabt-sys" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)", "cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1492,7 +1492,7 @@ dependencies = [ "cranelift-codegen 0.44.0 (registry+https://github.com/rust-lang/crates.io-index)", "cranelift-entity 0.44.0 (registry+https://github.com/rust-lang/crates.io-index)", "cranelift-native 0.44.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1504,7 +1504,7 @@ dependencies = [ "wasmer-clif-fork-wasm 0.44.0 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime-core 0.8.0", "wasmer-win-exception-handler 0.8.0", - "wasmparser 0.39.1 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmparser 0.39.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1526,18 +1526,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cranelift-codegen 0.44.0 (registry+https://github.com/rust-lang/crates.io-index)", "cranelift-entity 0.44.0 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-clif-fork-frontend 0.44.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmparser 0.39.1 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmparser 0.39.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasmer-dev-utils" version = "0.8.0" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1546,7 +1546,7 @@ version = "0.8.0" dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime-core 0.8.0", @@ -1570,7 +1570,7 @@ dependencies = [ name = "wasmer-kernel-loader" version = "0.1.0" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime-core 0.8.0", ] @@ -1580,11 +1580,11 @@ version = "0.8.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.45 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.46 (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.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1592,7 +1592,7 @@ dependencies = [ "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "wabt 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime-core 0.8.0", - "wasmparser 0.39.1 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmparser 0.39.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1636,12 +1636,12 @@ name = "wasmer-runtime-c-api" version = "0.8.0" dependencies = [ "cbindgen 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmer-runtime 0.8.0", - "wasmer-runtime-core 0.8.0", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-clif-backend 0.8.0", "wasmer-llvm-backend 0.8.0", "wasmer-middleware-common 0.8.0", + "wasmer-runtime 0.8.0", + "wasmer-runtime-core 0.8.0", "wasmer-singlepass-backend 0.8.0", ] @@ -1649,16 +1649,16 @@ dependencies = [ name = "wasmer-runtime-core" version = "0.8.0" dependencies = [ - "bincode 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "blake2b_simd 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.46 (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)", "field-offset 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "page_size 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1668,7 +1668,7 @@ dependencies = [ "serde_bytes 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmparser 0.39.1 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmparser 0.39.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1680,11 +1680,11 @@ dependencies = [ "dynasm 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "dynasmrt 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime-core 0.8.0", - "wasmparser 0.39.1 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmparser 0.39.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1703,10 +1703,10 @@ dependencies = [ name = "wasmer-wasi" version = "0.8.0" dependencies = [ - "bincode 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "generational-arena 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1736,7 +1736,7 @@ version = "0.8.0" dependencies = [ "bindgen 0.51.1 (registry+https://github.com/rust-lang/crates.io-index)", "cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "wasmer-runtime-core 0.8.0", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1744,7 +1744,7 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.39.1" +version = "0.39.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1752,7 +1752,7 @@ name = "which" version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1805,12 +1805,12 @@ dependencies = [ "checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" -"checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba" +"checksum arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9" "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" "checksum autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b671c8fb71b457dd4ae18c4ba1e59aa81793daacc361d82fcd410cef0d491875" -"checksum bincode 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9f04a5e50dc80b3d5d35320889053637d15011aed5e66b66b37ae798c65da6f7" +"checksum bincode 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8ab639324e3ee8774d296864fbc0dbbb256cf1a41c490b94cba90c082915f92" "checksum bindgen 0.51.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ebd71393f1ec0509b553aa012b9b58e81dadbdff7130bd3b8cba576e69b32f75" -"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" +"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum blake2b_simd 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)" = "5850aeee1552f495dd0250014cf64b82b7c8879a89d83b33bbdace2cc4f63182" "checksum bstr 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8d6c2c5b58ab920a4f5aeaaca34b4488074e8cc7596af94e6f8c6ff247c60245" "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" @@ -1820,9 +1820,9 @@ 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.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9daec6140ab4dcd38c3dd57e580b59a621172a526ac79f1527af760a55afeafd" -"checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be" +"checksum cc 1.0.46 (registry+https://github.com/rust-lang/crates.io-index)" = "0213d356d3c4ea2c18c40b037c3be23cd639825c18f25ee670ac7813beeef99c" "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 cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum clang-sys 0.28.1 (registry+https://github.com/rust-lang/crates.io-index)" = "81de550971c976f176130da4b2978d3b524eaa0fd9ac31f3ceb5ae1231fb4853" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" @@ -1842,18 +1842,18 @@ dependencies = [ "checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" "checksum csv 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "37519ccdfd73a75821cac9319d4fce15a81b9fcf75f951df5b9988aa3a0af87d" "checksum csv-core 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9b5cadb6b25c77aeff80ba701712494213f4a8418fcda2ee11b6560c3ad0bf4c" -"checksum ctor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "5b6b2f4752cc29efbfd03474c532ce8f916f2d44ec5bb8c21f93bc76e5365528" +"checksum ctor 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "cd8ce37ad4184ab2ce004c33bf6379185d3b1c95801cab51026bd271bf68eedc" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" "checksum dynasm 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f36d49ab6f8ecc642d2c6ee10fda04ba68003ef0277300866745cdde160e6b40" "checksum dynasmrt 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a4c408a211e7f5762829f5e46bdff0c14bc3b1517a21a4bb781c716bf88b0c68" -"checksum either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5527cfe0d098f36e3f8839852688e63c8fff1c90b2b405aef730615f9a7bcf7b" +"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" "checksum enum-methods 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7798e7da2d4cb0d6d6fc467e8d6b5bf247e9e989f786dde1732d79899c32bb10" "checksum env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aafcde04e90a5226a6443b7aabdb016ba2f8307c847d524724bd9b346dd1a2d3" "checksum erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3beee4bc16478a1b26f2e80ad819a52d24745e292f521a63c16eea5f74b7eb60" "checksum errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2a071601ed01b988f896ab14b95e67335d1eeb50190932a1320f7fe3cadc84e" "checksum errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" -"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" -"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" +"checksum failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9" +"checksum failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08" "checksum field-offset 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "64e9bc339e426139e02601fa69d101e96a92aee71b58bc01697ec2a63a5c9e68" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" @@ -1876,7 +1876,7 @@ dependencies = [ "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -"checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba" +"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" "checksum libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" "checksum llvm-sys 80.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2110cd4daf9cd8e39dd3b933b1a2a2ac7315e91f7c92b3a20beab526c63b5978" "checksum lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8912e782533a93a167888781b836336a6ca5da6175c05944c86cf28c31104dc" @@ -1887,7 +1887,7 @@ dependencies = [ "checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" "checksum memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce6075db033bbbb7ee5a0bbd3a3186bbae616f57fb001c485c7ff77955f8177f" "checksum nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3b2e0b4f3320ed72aaedb9a5ac838690a8047c7b275da22711fddff4f8a14229" -"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" +"checksum nodrop 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" "checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" "checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" "checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273" @@ -1900,7 +1900,7 @@ dependencies = [ "checksum ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e3cbf9f658cdb5000fcf6f362b8ea2ba154b9f146a61c7a20d647034c6b6561b" "checksum proc-macro-error 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aeccfe4d5d8ea175d5f0e4a2ad0637e0f4121d63bd99d356fb1f39ab2e7c6097" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -"checksum proc-macro2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e98a83a9f9b331f54b924e68a66acb1bb35cb01fb0a23645139967abefb697e8" +"checksum proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90cf5f418035b98e655e9cdb225047638296b862b42411c4e45bb88d700f7fc0" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" @@ -1924,7 +1924,7 @@ dependencies = [ "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997" +"checksum ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8" "checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421" "checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" "checksum scroll 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2f84d114ef17fd144153d608fba7c446b0145d038985e7a8cc5d08bb0ce20383" @@ -1935,7 +1935,7 @@ dependencies = [ "checksum serde-bench 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d733da87e79faaac25616e33d26299a41143fd4cd42746cbb0e91d8feea243fd" "checksum serde_bytes 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "45af0182ff64abaeea290235eb67da3825a576c5d53e642c4d5b652e12e6effc" "checksum serde_derive 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)" = "4b133a43a1ecd55d4086bd5b4dc6c1751c68b1bfbeba7a5040442022c7e7c02e" -"checksum serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "051c49229f282f7c6f3813f8286cc1e3323e8051823fce42c7ea80fe13521704" +"checksum serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)" = "2f72eb2a68a7dc3f9a691bfda9305a1c017a6215e5a4545c258500d2099a37c2" "checksum shlex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" "checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" @@ -1946,7 +1946,7 @@ dependencies = [ "checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" "checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" -"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f" +"checksum synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f085a5855930c0441ca1288cf044ea4aecf4f43a91668abdb870b4ba546a203" "checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" "checksum target-lexicon 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7975cb2c6f37d77b190bc5004a2bb015971464756fde9514651a525ada2a741a" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" @@ -1974,7 +1974,7 @@ dependencies = [ "checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d" "checksum wasmer-clif-fork-frontend 0.44.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0cf2f552a9c1fda0555087170424bd8fedc63a079a97bb5638a4ef9b0d9656aa" "checksum wasmer-clif-fork-wasm 0.44.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0073b512e1af5948d34be7944b74c747bbe735ccff2e2f28c26ed4c90725de8e" -"checksum wasmparser 0.39.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a026c1436af49d5537c7561c7474f81f7a754e36445fe52e6e88795a9747291c" +"checksum wasmparser 0.39.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e5083b449454f7de0b15f131eee17de54b5a71dcb9adcf11df2b2f78fad0cd82" "checksum which 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "240a31163872f7e8e49f35b42b58485e35355b07eb009d9f3686733541339a69" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index ab1ca25167d2..e911e5db1bf2 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -26,22 +26,22 @@ version = "0.8.0" [dependencies.wasmer-middleware-common] path = "../middleware-common" -version = "0.7.0" +version = "0.8.0" optional = true [dependencies.wasmer-singlepass-backend] path = "../singlepass-backend" -version = "0.7.0" +version = "0.8.0" optional = true [dependencies.wasmer-llvm-backend] path = "../llvm-backend" -version = "0.7.0" +version = "0.8.0" optional = true [dependencies.wasmer-clif-backend] path = "../clif-backend" -version = "0.7.0" +version = "0.8.0" optional = true [features] From 0a15b723c1e273cbffab084b858afa5dd12b2513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Mon, 21 Oct 2019 11:05:46 +0300 Subject: [PATCH 020/129] =?UTF-8?q?Update=20repository=20name=20in=20confi?= =?UTF-8?q?guration=20files=20(wasmerio=20=E2=86=92=20ElrondNetwork)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Cargo.toml | 2 +- azure-pipelines.yml | 2 +- bors.toml | 2 +- examples/parallel/Cargo.toml | 2 +- examples/plugin-for-example/wapm.toml | 4 ++-- lib/clif-backend/Cargo.toml | 2 +- lib/dev-utils/Cargo.toml | 2 +- lib/emscripten/Cargo.toml | 2 +- lib/middleware-common-tests/Cargo.toml | 2 +- lib/middleware-common/Cargo.toml | 2 +- lib/runtime-c-api/Cargo.toml | 2 +- lib/runtime-core/Cargo.toml | 2 +- lib/runtime/Cargo.toml | 2 +- lib/singlepass-backend/Cargo.toml | 2 +- lib/spectests/Cargo.toml | 2 +- lib/wasi/Cargo.toml | 2 +- lib/win-exception-handler/Cargo.toml | 2 +- 18 files changed, 19 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index d1122a79877e..7291273dcd2c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ .idea **/.vscode install/ +tags diff --git a/Cargo.toml b/Cargo.toml index 4d619059e357..681175465728 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "wasmer" version = "0.8.0" authors = ["The Wasmer Engineering Team "] edition = "2018" -repository = "https://github.com/wasmerio/wasmer" +repository = "https://github.com/ElrondNetwork/wasmer" publish = true description = "High-Performance WebAssembly JIT interpreter" license = "MIT" diff --git a/azure-pipelines.yml b/azure-pipelines.yml index db05b2d340d2..b824f45e275f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -221,7 +221,7 @@ jobs: condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) inputs: gitHubConnection: wasmer - repositoryName: wasmerio/wasmer + repositoryName: ElrondNetwork/wasmer tag: dev assets: $(Build.ArtifactStagingDirectory) diff --git a/bors.toml b/bors.toml index 1003d9678c12..c52879be80d1 100644 --- a/bors.toml +++ b/bors.toml @@ -1,5 +1,5 @@ status = [ - "wasmerio.wasmer" + "ElrondNetwork.wasmer" ] required_approvals = 1 timeout_sec = 7200 diff --git a/examples/parallel/Cargo.toml b/examples/parallel/Cargo.toml index 2353cf232bce..2cb22900a430 100644 --- a/examples/parallel/Cargo.toml +++ b/examples/parallel/Cargo.toml @@ -3,7 +3,7 @@ name = "parallel" version = "0.1.0" authors = ["The Wasmer Engineering Team "] edition = "2018" -repository = "https://github.com/wasmerio/wasmer" +repository = "https://github.com/ElrondNetwork/wasmer" publish = false license = "MIT" diff --git a/examples/plugin-for-example/wapm.toml b/examples/plugin-for-example/wapm.toml index 7e2e261a7668..b4fd2e2f3582 100644 --- a/examples/plugin-for-example/wapm.toml +++ b/examples/plugin-for-example/wapm.toml @@ -3,10 +3,10 @@ name = "plugin-for-example" version = "0.1.0" description = "A plugin for our example system" readme = "README.md" -repository = "https://github.com/wasmerio/wasmer/examples/plugin-for-example" +repository = "https://github.com/ElrondNetwork/wasmer/examples/plugin-for-example" license = "MIT" [[module]] name = "plugin-for-example" source = "../../target/wasm32-unknown-wasi/release/plugin-for-example.wasm" -abi = "none" \ No newline at end of file +abi = "none" diff --git a/lib/clif-backend/Cargo.toml b/lib/clif-backend/Cargo.toml index c940b1b6eb94..3b6dbe09427f 100644 --- a/lib/clif-backend/Cargo.toml +++ b/lib/clif-backend/Cargo.toml @@ -4,7 +4,7 @@ version = "0.8.0" description = "Wasmer runtime Cranelift compiler backend" license = "MIT" authors = ["The Wasmer Engineering Team "] -repository = "https://github.com/wasmerio/wasmer" +repository = "https://github.com/ElrondNetwork/wasmer" edition = "2018" readme = "README.md" diff --git a/lib/dev-utils/Cargo.toml b/lib/dev-utils/Cargo.toml index bb6957b3a980..0f9c24caf5db 100644 --- a/lib/dev-utils/Cargo.toml +++ b/lib/dev-utils/Cargo.toml @@ -5,7 +5,7 @@ description = "Wasmer runtime core library" license = "MIT" authors = ["The Wasmer Engineering Team "] edition = "2018" -repository = "https://github.com/wasmerio/wasmer" +repository = "https://github.com/ElrondNetwork/wasmer" publish = false [dependencies] diff --git a/lib/emscripten/Cargo.toml b/lib/emscripten/Cargo.toml index e55fb221a53b..ea54a430bc2a 100644 --- a/lib/emscripten/Cargo.toml +++ b/lib/emscripten/Cargo.toml @@ -4,7 +4,7 @@ version = "0.8.0" description = "Wasmer runtime emscripten implementation library" license = "MIT" authors = ["The Wasmer Engineering Team "] -repository = "https://github.com/wasmerio/wasmer" +repository = "https://github.com/ElrondNetwork/wasmer" edition = "2018" [dependencies] diff --git a/lib/middleware-common-tests/Cargo.toml b/lib/middleware-common-tests/Cargo.toml index 48a5c68bd5f1..ff58565c0092 100644 --- a/lib/middleware-common-tests/Cargo.toml +++ b/lib/middleware-common-tests/Cargo.toml @@ -3,7 +3,7 @@ name = "wasmer-middleware-common-tests" version = "0.8.0" authors = ["The Wasmer Engineering Team "] edition = "2018" -repository = "https://github.com/wasmerio/wasmer" +repository = "https://github.com/ElrondNetwork/wasmer" license = "MIT" publish = false diff --git a/lib/middleware-common/Cargo.toml b/lib/middleware-common/Cargo.toml index 0da56b81d37c..6fdbe8387789 100644 --- a/lib/middleware-common/Cargo.toml +++ b/lib/middleware-common/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "wasmer-middleware-common" version = "0.8.0" -repository = "https://github.com/wasmerio/wasmer" +repository = "https://github.com/ElrondNetwork/wasmer" description = "Wasmer runtime common middlewares" license = "MIT" authors = ["The Wasmer Engineering Team "] diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index e911e5db1bf2..db207824366e 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -4,7 +4,7 @@ version = "0.8.0" description = "Wasmer C API library" license = "MIT" authors = ["The Wasmer Engineering Team "] -repository = "https://github.com/wasmerio/wasmer" +repository = "https://github.com/ElrondNetwork/wasmer" edition = "2018" readme = "README.md" diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index 7fd9e32e8359..eca0e681309a 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -4,7 +4,7 @@ version = "0.8.0" description = "Wasmer runtime core library" license = "MIT" authors = ["The Wasmer Engineering Team "] -repository = "https://github.com/wasmerio/wasmer" +repository = "https://github.com/ElrondNetwork/wasmer" edition = "2018" [dependencies] diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index 2e42055c2e4b..15db6afad3d9 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -4,7 +4,7 @@ version = "0.8.0" description = "Wasmer runtime library" license = "MIT" authors = ["The Wasmer Engineering Team "] -repository = "https://github.com/wasmerio/wasmer" +repository = "https://github.com/ElrondNetwork/wasmer" edition = "2018" readme = "README.md" diff --git a/lib/singlepass-backend/Cargo.toml b/lib/singlepass-backend/Cargo.toml index 5243cc601504..5e5f8185a036 100644 --- a/lib/singlepass-backend/Cargo.toml +++ b/lib/singlepass-backend/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "wasmer-singlepass-backend" version = "0.8.0" -repository = "https://github.com/wasmerio/wasmer" +repository = "https://github.com/ElrondNetwork/wasmer" description = "Wasmer runtime single pass compiler backend" license = "MIT" authors = ["The Wasmer Engineering Team "] diff --git a/lib/spectests/Cargo.toml b/lib/spectests/Cargo.toml index 6f62ab098c2a..343e69e666af 100644 --- a/lib/spectests/Cargo.toml +++ b/lib/spectests/Cargo.toml @@ -4,7 +4,7 @@ version = "0.8.0" description = "Wasmer spectests library" license = "MIT" authors = ["The Wasmer Engineering Team "] -repository = "https://github.com/wasmerio/wasmer" +repository = "https://github.com/ElrondNetwork/wasmer" edition = "2018" [dependencies] diff --git a/lib/wasi/Cargo.toml b/lib/wasi/Cargo.toml index 067894ddea0c..377a06cad086 100644 --- a/lib/wasi/Cargo.toml +++ b/lib/wasi/Cargo.toml @@ -4,7 +4,7 @@ version = "0.8.0" description = "Wasmer runtime WASI implementation library" license = "MIT" authors = ["The Wasmer Engineering Team "] -repository = "https://github.com/wasmerio/wasmer" +repository = "https://github.com/ElrondNetwork/wasmer" edition = "2018" [dependencies] diff --git a/lib/win-exception-handler/Cargo.toml b/lib/win-exception-handler/Cargo.toml index 12e5f6c0b43b..baf52584b738 100644 --- a/lib/win-exception-handler/Cargo.toml +++ b/lib/win-exception-handler/Cargo.toml @@ -4,7 +4,7 @@ version = "0.8.0" description = "Wasmer runtime exception handling for Windows" license = "MIT" authors = ["The Wasmer Engineering Team "] -repository = "https://github.com/wasmerio/wasmer" +repository = "https://github.com/ElrondNetwork/wasmer" edition = "2018" [target.'cfg(windows)'.dependencies] From 8d483f1b5cf2b2e772e0c67e5890f2df20cc312b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 23 Oct 2019 13:37:53 +0300 Subject: [PATCH 021/129] Change two Cargo.toml files so that backend-singlepass and metering are default features when building --- Cargo.toml | 2 +- lib/runtime-c-api/Cargo.toml | 2 +- lib/runtime/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 681175465728..fc4baddcbfe6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,7 +71,7 @@ serde = { version = "1", features = ["derive"] } # used by the plugin example typetag = "0.1" # used by the plugin example [features] -default = ["fast-tests", "wasi", "backend-cranelift"] +default = ["fast-tests", "wasi", "backend-singlepass"] "loader-kernel" = ["wasmer-kernel-loader"] debug = ["wasmer-runtime-core/debug"] trace = ["wasmer-runtime-core/trace"] diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index db207824366e..a1db10a3d36f 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -45,7 +45,7 @@ version = "0.8.0" optional = true [features] -default = ["cranelift-backend"] +default = ["singlepass-backend", "metering"] debug = ["wasmer-runtime/debug"] cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift", "wasmer-clif-backend"] # to enable any of the below, you must disable the default cranelift backend with --no-default--features flag diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index 15db6afad3d9..069bce86da40 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -32,7 +32,7 @@ path = "../llvm-backend" optional = true [features] -default = ["cranelift", "default-backend-cranelift"] +default = ["singlepass", "default-backend-singlepass"] cranelift = ["wasmer-clif-backend"] cache = ["cranelift"] debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] From e6d4e9d7076eb234afb69f71188ce6d4a70f4a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 23 Oct 2019 13:38:40 +0300 Subject: [PATCH 022/129] Create function wasmer_instantiate_with_metering() as external API function --- lib/runtime-c-api/src/metering.rs | 106 +++++++++++++++++++++++++++++- lib/runtime-c-api/wasmer.h | 7 ++ lib/runtime-c-api/wasmer.hh | 7 ++ 3 files changed, 118 insertions(+), 2 deletions(-) diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 4cd3feee2486..5140dbc88b8f 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -1,15 +1,117 @@ use crate::{ + export::{wasmer_import_export_kind}, + import::{wasmer_import_t}, error::{update_last_error, CApiError}, instance::wasmer_instance_t, module::wasmer_module_t, wasmer_result_t, }; - -use std::slice; +use libc::{c_int}; +use std::{collections::HashMap, slice}; +use wasmer_runtime::{Global, Memory, Table}; +use wasmer_runtime_core::{ + export::Export, + import::{ImportObject, Namespace}, +}; #[cfg(feature = "metering")] use wasmer_runtime_core::backend::Compiler; +#[allow(clippy::cast_ptr_alignment)] +#[cfg(feature = "metering")] +#[no_mangle] +pub unsafe extern "C" fn wasmer_instantiate_with_metering( + instance: *mut *mut wasmer_instance_t, + wasm_bytes: *mut u8, + wasm_bytes_len: u32, + imports: *mut wasmer_import_t, + imports_len: c_int, + gas_limit: u64, +) -> wasmer_result_t { + if wasm_bytes.is_null() { + update_last_error(CApiError { + msg: "wasm bytes ptr is null".to_string(), + }); + return wasmer_result_t::WASMER_ERROR; + } + let imports: &[wasmer_import_t] = slice::from_raw_parts(imports, imports_len as usize); + let mut import_object = ImportObject::new(); + let mut namespaces = HashMap::new(); + for import in imports { + let module_name = slice::from_raw_parts( + import.module_name.bytes, + import.module_name.bytes_len as usize, + ); + let module_name = if let Ok(s) = std::str::from_utf8(module_name) { + s + } else { + update_last_error(CApiError { + msg: "error converting module name to string".to_string(), + }); + return wasmer_result_t::WASMER_ERROR; + }; + let import_name = slice::from_raw_parts( + import.import_name.bytes, + import.import_name.bytes_len as usize, + ); + let import_name = if let Ok(s) = std::str::from_utf8(import_name) { + s + } else { + update_last_error(CApiError { + msg: "error converting import_name to string".to_string(), + }); + return wasmer_result_t::WASMER_ERROR; + }; + + let namespace = namespaces.entry(module_name).or_insert_with(Namespace::new); + + let export = match import.tag { + wasmer_import_export_kind::WASM_MEMORY => { + let mem = import.value.memory as *mut Memory; + Export::Memory((&*mem).clone()) + } + wasmer_import_export_kind::WASM_FUNCTION => { + let func_export = import.value.func as *mut Export; + (&*func_export).clone() + } + wasmer_import_export_kind::WASM_GLOBAL => { + let global = import.value.global as *mut Global; + Export::Global((&*global).clone()) + } + wasmer_import_export_kind::WASM_TABLE => { + let table = import.value.table as *mut Table; + Export::Table((&*table).clone()) + } + }; + namespace.insert(import_name, export); + } + for (module_name, namespace) in namespaces.into_iter() { + import_object.register(module_name, namespace); + } + + let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); + let result_compilation = wasmer_runtime_core::compile_with(bytes, &get_metered_compiler(gas_limit)); + let new_module = match result_compilation { + Ok(module) => module, + Err(_) => { + update_last_error(CApiError { + msg: "compile error".to_string(), + }); + return wasmer_result_t::WASMER_ERROR; + } + }; + let result_instantiation = new_module.instantiate(&import_object); + let new_instance = match result_instantiation { + Ok(instance) => instance, + Err(error) => { + update_last_error(error); + return wasmer_result_t::WASMER_ERROR; + } + }; + *instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t; + wasmer_result_t::WASMER_OK +} + /// Creates a new Module with gas limit from the given wasm bytes. /// /// Returns `wasmer_result_t::WASMER_OK` upon success. diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index a23ecafd1913..d0fb5ec4ac7c 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -542,6 +542,13 @@ wasmer_result_t wasmer_instantiate(wasmer_instance_t **instance, wasmer_import_t *imports, int imports_len); +wasmer_result_t wasmer_instantiate_with_metering(wasmer_instance_t **instance, + uint8_t *wasm_bytes, + uint32_t wasm_bytes_len, + wasmer_import_t *imports, + int imports_len, + uint64_t gas_limit); + /** * Gets the length in bytes of the last error. * This can be used to dynamically allocate a buffer with the correct number of diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 7c9bccbfc765..3895d44213f6 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -430,6 +430,13 @@ wasmer_result_t wasmer_instantiate(wasmer_instance_t **instance, wasmer_import_t *imports, int imports_len); +wasmer_result_t wasmer_instantiate_with_metering(wasmer_instance_t **instance, + uint8_t *wasm_bytes, + uint32_t wasm_bytes_len, + wasmer_import_t *imports, + int imports_len, + uint64_t gas_limit); + /// Gets the length in bytes of the last error. /// This can be used to dynamically allocate a buffer with the correct number of /// bytes needed to store a message. From d12a006b2d39eb276a60b2220f77b0a79ac999ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Thu, 24 Oct 2019 16:58:02 +0300 Subject: [PATCH 023/129] Add selectable metering costs table --- lib/middleware-common/src/lib.rs | 1 + lib/middleware-common/src/metering.rs | 9 +++++++-- lib/runtime-c-api/src/metering.rs | 15 +++++++++++---- lib/runtime-c-api/wasmer.h | 3 ++- lib/runtime-c-api/wasmer.hh | 3 ++- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/middleware-common/src/lib.rs b/lib/middleware-common/src/lib.rs index c7900c83a736..5a9b65a95a4e 100644 --- a/lib/middleware-common/src/lib.rs +++ b/lib/middleware-common/src/lib.rs @@ -12,3 +12,4 @@ pub mod call_trace; pub mod metering; +pub mod metering_costs; diff --git a/lib/middleware-common/src/metering.rs b/lib/middleware-common/src/metering.rs index a7d10aece104..82283dded1f2 100644 --- a/lib/middleware-common/src/metering.rs +++ b/lib/middleware-common/src/metering.rs @@ -6,6 +6,8 @@ use wasmer_runtime_core::{ Instance, }; +use crate::metering_costs::get_costs_table; + static INTERNAL_FIELD: InternalField = InternalField::allocate(); /// Metering is a compiler middleware that calculates the cost of WebAssembly instructions at compile @@ -20,16 +22,19 @@ static INTERNAL_FIELD: InternalField = InternalField::allocate(); /// Each compiler backend with Metering enabled should produce the same cost used at runtime for /// the same function calls so we can say that the metering is deterministic. /// + pub struct Metering { limit: u64, current_block: u64, + costs_table: fn(&Operator) -> u64, } impl Metering { - pub fn new(limit: u64) -> Metering { + pub fn new(limit: u64, table_name: &str) -> Metering { Metering { limit, current_block: 0, + costs_table: get_costs_table(table_name), } } } @@ -50,7 +55,7 @@ impl FunctionMiddleware for Metering { self.current_block = 0; } Event::Wasm(&ref op) | Event::WasmOwned(ref op) => { - self.current_block += 1; + self.current_block += (self.costs_table)(op); match *op { Operator::Loop { .. } | Operator::Block { .. } diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 5140dbc88b8f..1558cea1fe7f 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -14,6 +14,9 @@ use wasmer_runtime_core::{ import::{ImportObject, Namespace}, }; +use std::ffi::CStr; +use std::os::raw::c_char; + #[cfg(feature = "metering")] use wasmer_runtime_core::backend::Compiler; @@ -27,6 +30,7 @@ pub unsafe extern "C" fn wasmer_instantiate_with_metering( imports: *mut wasmer_import_t, imports_len: c_int, gas_limit: u64, + costs_table_name: *const c_char, ) -> wasmer_result_t { if wasm_bytes.is_null() { update_last_error(CApiError { @@ -90,7 +94,8 @@ pub unsafe extern "C" fn wasmer_instantiate_with_metering( } let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); - let result_compilation = wasmer_runtime_core::compile_with(bytes, &get_metered_compiler(gas_limit)); + let costs_table_name_owned = CStr::from_ptr(costs_table_name).to_string_lossy().into_owned(); + let result_compilation = wasmer_runtime_core::compile_with(bytes, &get_metered_compiler(gas_limit, &costs_table_name_owned)); let new_module = match result_compilation { Ok(module) => module, Err(_) => { @@ -141,7 +146,7 @@ pub unsafe extern "C" fn wasmer_compile_with_gas_metering( } let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); - let result = wasmer_runtime_core::compile_with(bytes, &get_metered_compiler(gas_limit)); + let result = wasmer_runtime_core::compile_with(bytes, &get_metered_compiler(gas_limit, "uniform_one")); let new_module = match result { Ok(instance) => instance, Err(_) => { @@ -156,7 +161,7 @@ pub unsafe extern "C" fn wasmer_compile_with_gas_metering( } #[cfg(feature = "metering")] -fn get_metered_compiler(limit: u64) -> impl Compiler { +fn get_metered_compiler(limit: u64, costs_table_name: &str) -> impl Compiler { use wasmer_middleware_common::metering; use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler}; @@ -169,9 +174,11 @@ fn get_metered_compiler(limit: u64) -> impl Compiler { #[cfg(feature = "cranelift-backend")] use wasmer_clif_backend::CraneliftModuleCodeGenerator as MeteredMCG; + let table_name = (*costs_table_name).to_string(); + let c: StreamingCompiler = StreamingCompiler::new(move || { let mut chain = MiddlewareChain::new(); - chain.push(metering::Metering::new(limit)); + chain.push(metering::Metering::new(limit, &table_name)); chain }); c diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index d0fb5ec4ac7c..662fbe6b9d35 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -547,7 +547,8 @@ wasmer_result_t wasmer_instantiate_with_metering(wasmer_instance_t **instance, uint32_t wasm_bytes_len, wasmer_import_t *imports, int imports_len, - uint64_t gas_limit); + uint64_t gas_limit, + const char *costs_table_name); /** * Gets the length in bytes of the last error. diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 3895d44213f6..f631d92c45f8 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -435,7 +435,8 @@ wasmer_result_t wasmer_instantiate_with_metering(wasmer_instance_t **instance, uint32_t wasm_bytes_len, wasmer_import_t *imports, int imports_len, - uint64_t gas_limit); + uint64_t gas_limit, + const char *costs_table_name); /// Gets the length in bytes of the last error. /// This can be used to dynamically allocate a buffer with the correct number of From 95a2cdb4612de6d8235ab0c3fdc890be8cc58d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 25 Oct 2019 16:30:29 +0300 Subject: [PATCH 024/129] Make the cranelift backend optional. And organize some imports --- Cargo.toml | 2 +- lib/middleware-common/src/lib.rs | 1 + lib/runtime-c-api/src/lib.rs | 1 + lib/runtime-c-api/src/metering.rs | 7 ++++--- src/bin/wasmer.rs | 6 ++++++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fc4baddcbfe6..fbd6849043e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ byteorder = "1.3" errno = "0.2" structopt = "0.3" wabt = "0.9.1" -wasmer-clif-backend = { path = "lib/clif-backend" } +wasmer-clif-backend = { path = "lib/clif-backend", optional = true } wasmer-singlepass-backend = { path = "lib/singlepass-backend", optional = true } wasmer-middleware-common = { path = "lib/middleware-common" } wasmer-runtime = { path = "lib/runtime" } diff --git a/lib/middleware-common/src/lib.rs b/lib/middleware-common/src/lib.rs index 5a9b65a95a4e..60517fc0ac3f 100644 --- a/lib/middleware-common/src/lib.rs +++ b/lib/middleware-common/src/lib.rs @@ -11,5 +11,6 @@ #![doc(html_logo_url = "https://avatars3.githubusercontent.com/u/44205449?s=200&v=4")] pub mod call_trace; + pub mod metering; pub mod metering_costs; diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index 345c465d9a3f..89778a9776a4 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -99,6 +99,7 @@ pub mod global; pub mod import; pub mod instance; pub mod memory; +#[cfg(feature = "metering")] pub mod metering; pub mod module; pub mod table; diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 1558cea1fe7f..e79f16852b28 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -20,6 +20,10 @@ use std::os::raw::c_char; #[cfg(feature = "metering")] use wasmer_runtime_core::backend::Compiler; +#[cfg(not(feature = "cranelift-backend"))] +use wasmer_middleware_common::metering; + + #[allow(clippy::cast_ptr_alignment)] #[cfg(feature = "metering")] #[no_mangle] @@ -162,7 +166,6 @@ pub unsafe extern "C" fn wasmer_compile_with_gas_metering( #[cfg(feature = "metering")] fn get_metered_compiler(limit: u64, costs_table_name: &str) -> impl Compiler { - use wasmer_middleware_common::metering; use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler}; #[cfg(feature = "llvm-backend")] @@ -192,7 +195,6 @@ pub unsafe extern "C" fn wasmer_instance_get_points_used(instance: *mut wasmer_i if instance.is_null() { return 0; } - use wasmer_middleware_common::metering; let instance = &*(instance as *const wasmer_runtime::Instance); let points = metering::get_points_used(instance); points @@ -209,7 +211,6 @@ pub unsafe extern "C" fn wasmer_instance_set_points_used( if instance.is_null() { return; } - use wasmer_middleware_common::metering; let instance = &mut *(instance as *mut wasmer_runtime::Instance); metering::set_points_used(instance, new_gas) } diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 4c51d9770adf..10a670d26cda 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -21,6 +21,7 @@ use std::collections::HashMap; use structopt::StructOpt; use wasmer::*; +#[cfg(feature = "backend-cranelift")] use wasmer_clif_backend::CraneliftCompiler; #[cfg(feature = "backend-llvm")] use wasmer_llvm_backend::{LLVMCompiler, LLVMOptions}; @@ -825,7 +826,12 @@ fn get_compiler_by_backend(backend: Backend) -> Option> { Backend::Singlepass => Box::new(SinglePassCompiler::new()), #[cfg(not(feature = "backend-singlepass"))] Backend::Singlepass => return None, + + #[cfg(feature = "backend-cranelift")] Backend::Cranelift => Box::new(CraneliftCompiler::new()), + #[cfg(not(feature = "backend-cranelift"))] + Backend::Cranelift => return None, + #[cfg(feature = "backend-llvm")] Backend::LLVM => Box::new(LLVMCompiler::new()), #[cfg(not(feature = "backend-llvm"))] From f7fc629d9969af79e474977e22f2021a2fdddcd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 25 Oct 2019 16:30:42 +0300 Subject: [PATCH 025/129] Add forgotten file metering_costs.rs --- lib/middleware-common/src/metering_costs.rs | 40 +++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 lib/middleware-common/src/metering_costs.rs diff --git a/lib/middleware-common/src/metering_costs.rs b/lib/middleware-common/src/metering_costs.rs new file mode 100644 index 000000000000..e2037967bae9 --- /dev/null +++ b/lib/middleware-common/src/metering_costs.rs @@ -0,0 +1,40 @@ +use wasmer_runtime_core:: { + wasmparser::Operator +}; + +pub fn get_costs_table(table_name: &str) -> fn(&Operator) -> u64 { + match table_name { + "uniform_one" => { uniform_one } + "expensive_loop_else_one" => { expensive_loop_else_one } + "expensive_branching_else_one" => { expensive_branching_else_one } + _ => { uniform_zero } + } +} + +fn expensive_branching_else_one(op: &Operator) -> u64 { + match *op { + Operator::Loop { .. } + | Operator::Br { .. } + | Operator::BrTable { .. } + | Operator::BrIf { .. } + | Operator::Call { .. } + | Operator::CallIndirect { .. } + | Operator::Return => { 12 } + _ => { 1 } + } +} + +fn expensive_loop_else_one(op: &Operator) -> u64 { + match *op { + Operator::Loop { .. } => { 12 } + _ => { 1 } + } +} + +fn uniform_one(_op: &Operator) -> u64 { + 1 +} + +fn uniform_zero(_op: &Operator) -> u64 { + 0 +} From f9776ff8b62a3542861ee4457bcb22f5c4bf14a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 25 Oct 2019 16:31:02 +0300 Subject: [PATCH 026/129] Add file instructions.txt, documenting the possible WASM instructions executed by Wasmer --- instructions.txt | 410 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 410 insertions(+) create mode 100644 instructions.txt diff --git a/instructions.txt b/instructions.txt new file mode 100644 index 000000000000..b240bbd8872f --- /dev/null +++ b/instructions.txt @@ -0,0 +1,410 @@ +Unreachable +Nop +Block +Loop +If +Else +End +Br +BrIf +BrTable +Return +Call +CallIndirect +Drop +Select +GetLocal +SetLocal +TeeLocal +GetGlobal +SetGlobal +I32Load +I64Load +F32Load +F64Load +I32Load8S +I32Load8U +I32Load16S +I32Load16U +I64Load8S +I64Load8U +I64Load16S +I64Load16U +I64Load32S +I64Load32U +I32Store +I64Store +F32Store +F64Store +I32Store8 +I32Store16 +I64Store8 +I64Store16 +I64Store32 +MemorySize +MemoryGrow +I32Const +I64Const +F32Const +F64Const +RefNull +RefIsNull +I32Eqz +I32Eq +I32Ne +I32LtS +I32LtU +I32GtS +I32GtU +I32LeS +I32LeU +I32GeS +I32GeU +I64Eqz +I64Eq +I64Ne +I64LtS +I64LtU +I64GtS +I64GtU +I64LeS +I64LeU +I64GeS +I64GeU +F32Eq +F32Ne +F32Lt +F32Gt +F32Le +F32Ge +F64Eq +F64Ne +F64Lt +F64Gt +F64Le +F64Ge +I32Clz +I32Ctz +I32Popcnt +I32Add +I32Sub +I32Mul +I32DivS +I32DivU +I32RemS +I32RemU +I32And +I32Or +I32Xor +I32Shl +I32ShrS +I32ShrU +I32Rotl +I32Rotr +I64Clz +I64Ctz +I64Popcnt +I64Add +I64Sub +I64Mul +I64DivS +I64DivU +I64RemS +I64RemU +I64And +I64Or +I64Xor +I64Shl +I64ShrS +I64ShrU +I64Rotl +I64Rotr +F32Abs +F32Neg +F32Ceil +F32Floor +F32Trunc +F32Nearest +F32Sqrt +F32Add +F32Sub +F32Mul +F32Div +F32Min +F32Max +F32Copysign +F64Abs +F64Neg +F64Ceil +F64Floor +F64Trunc +F64Nearest +F64Sqrt +F64Add +F64Sub +F64Mul +F64Div +F64Min +F64Max +F64Copysign +I32WrapI64 +I32TruncSF32 +I32TruncUF32 +I32TruncSF64 +I32TruncUF64 +I64ExtendSI32 +I64ExtendUI32 +I64TruncSF32 +I64TruncUF32 +I64TruncSF64 +I64TruncUF64 +F32ConvertSI32 +F32ConvertUI32 +F32ConvertSI64 +F32ConvertUI64 +F32DemoteF64 +F64ConvertSI32 +F64ConvertUI32 +F64ConvertSI64 +F64ConvertUI64 +F64PromoteF32 +I32ReinterpretF32 +I64ReinterpretF64 +F32ReinterpretI32 +F64ReinterpretI64 +I32Extend8S +I32Extend16S +I64Extend8S +I64Extend16S +I64Extend32S +I32TruncSSatF32 +I32TruncUSatF32 +I32TruncSSatF64 +I32TruncUSatF64 +I64TruncSSatF32 +I64TruncUSatF32 +I64TruncSSatF64 +I64TruncUSatF64 +MemoryInit +DataDrop +MemoryCopy +MemoryFill +TableInit +ElemDrop +TableCopy +TableGet +TableSet +TableGrow +TableSize +Wake +I32Wait +I64Wait +Fence +I32AtomicLoad +I64AtomicLoad +I32AtomicLoad8U +I32AtomicLoad16U +I64AtomicLoad8U +I64AtomicLoad16U +I64AtomicLoad32U +I32AtomicStore +I64AtomicStore +I32AtomicStore8 +I32AtomicStore16 +I64AtomicStore8 +I64AtomicStore16 +I64AtomicStore32 +I32AtomicRmwAdd +I64AtomicRmwAdd +I32AtomicRmw8UAdd +I32AtomicRmw16UAdd +I64AtomicRmw8UAdd +I64AtomicRmw16UAdd +I64AtomicRmw32UAdd +I32AtomicRmwSub +I64AtomicRmwSub +I32AtomicRmw8USub +I32AtomicRmw16USub +I64AtomicRmw8USub +I64AtomicRmw16USub +I64AtomicRmw32USub +I32AtomicRmwAnd +I64AtomicRmwAnd +I32AtomicRmw8UAnd +I32AtomicRmw16UAnd +I64AtomicRmw8UAnd +I64AtomicRmw16UAnd +I64AtomicRmw32UAnd +I32AtomicRmwOr +I64AtomicRmwOr +I32AtomicRmw8UOr +I32AtomicRmw16UOr +I64AtomicRmw8UOr +I64AtomicRmw16UOr +I64AtomicRmw32UOr +I32AtomicRmwXor +I64AtomicRmwXor +I32AtomicRmw8UXor +I32AtomicRmw16UXor +I64AtomicRmw8UXor +I64AtomicRmw16UXor +I64AtomicRmw32UXor +I32AtomicRmwXchg +I64AtomicRmwXchg +I32AtomicRmw8UXchg +I32AtomicRmw16UXchg +I64AtomicRmw8UXchg +I64AtomicRmw16UXchg +I64AtomicRmw32UXchg +I32AtomicRmwCmpxchg +I64AtomicRmwCmpxchg +I32AtomicRmw8UCmpxchg +I32AtomicRmw16UCmpxchg +I64AtomicRmw8UCmpxchg +I64AtomicRmw16UCmpxchg +I64AtomicRmw32UCmpxchg +V128Load +V128Store +V128Const +I8x16Splat +I8x16ExtractLaneS +I8x16ExtractLaneU +I8x16ReplaceLane +I16x8Splat +I16x8ExtractLaneS +I16x8ExtractLaneU +I16x8ReplaceLane +I32x4Splat +I32x4ExtractLane +I32x4ReplaceLane +I64x2Splat +I64x2ExtractLane +I64x2ReplaceLane +F32x4Splat +F32x4ExtractLane +F32x4ReplaceLane +F64x2Splat +F64x2ExtractLane +F64x2ReplaceLane +I8x16Eq +I8x16Ne +I8x16LtS +I8x16LtU +I8x16GtS +I8x16GtU +I8x16LeS +I8x16LeU +I8x16GeS +I8x16GeU +I16x8Eq +I16x8Ne +I16x8LtS +I16x8LtU +I16x8GtS +I16x8GtU +I16x8LeS +I16x8LeU +I16x8GeS +I16x8GeU +I32x4Eq +I32x4Ne +I32x4LtS +I32x4LtU +I32x4GtS +I32x4GtU +I32x4LeS +I32x4LeU +I32x4GeS +I32x4GeU +F32x4Eq +F32x4Ne +F32x4Lt +F32x4Gt +F32x4Le +F32x4Ge +F64x2Eq +F64x2Ne +F64x2Lt +F64x2Gt +F64x2Le +F64x2Ge +V128Not +V128And +V128Or +V128Xor +V128Bitselect +I8x16Neg +I8x16AnyTrue +I8x16AllTrue +I8x16Shl +I8x16ShrS +I8x16ShrU +I8x16Add +I8x16AddSaturateS +I8x16AddSaturateU +I8x16Sub +I8x16SubSaturateS +I8x16SubSaturateU +I8x16Mul +I16x8Neg +I16x8AnyTrue +I16x8AllTrue +I16x8Shl +I16x8ShrS +I16x8ShrU +I16x8Add +I16x8AddSaturateS +I16x8AddSaturateU +I16x8Sub +I16x8SubSaturateS +I16x8SubSaturateU +I16x8Mul +I32x4Neg +I32x4AnyTrue +I32x4AllTrue +I32x4Shl +I32x4ShrS +I32x4ShrU +I32x4Add +I32x4Sub +I32x4Mul +I64x2Neg +I64x2AnyTrue +I64x2AllTrue +I64x2Shl +I64x2ShrS +I64x2ShrU +I64x2Add +I64x2Sub +F32x4Abs +F32x4Neg +F32x4Sqrt +F32x4Add +F32x4Sub +F32x4Mul +F32x4Div +F32x4Min +F32x4Max +F64x2Abs +F64x2Neg +F64x2Sqrt +F64x2Add +F64x2Sub +F64x2Mul +F64x2Div +F64x2Min +F64x2Max +I32x4TruncSF32x4Sat +I32x4TruncUF32x4Sat +I64x2TruncSF64x2Sat +I64x2TruncUF64x2Sat +F32x4ConvertSI32x4 +F32x4ConvertUI32x4 +F64x2ConvertSI64x2 +F64x2ConvertUI64x2 +V8x16Swizzle +V8x16Shuffle +I8x16LoadSplat +I16x8LoadSplat +I32x4LoadSplat +I64x2LoadSplat From d893a6d960bc8ec8a22aa5c7e07566da7edad8a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Mon, 4 Nov 2019 14:31:25 +0200 Subject: [PATCH 027/129] Remove fixed tables and try to create an array-based costs table --- lib/middleware-common/src/metering.rs | 17 +- lib/middleware-common/src/metering_costs.rs | 444 ++++++++++++++++++-- lib/runtime-c-api/src/metering.rs | 27 +- lib/runtime-c-api/wasmer.h | 7 +- lib/runtime-c-api/wasmer.hh | 7 +- 5 files changed, 446 insertions(+), 56 deletions(-) diff --git a/lib/middleware-common/src/metering.rs b/lib/middleware-common/src/metering.rs index 82283dded1f2..78d6f6a552ae 100644 --- a/lib/middleware-common/src/metering.rs +++ b/lib/middleware-common/src/metering.rs @@ -6,7 +6,7 @@ use wasmer_runtime_core::{ Instance, }; -use crate::metering_costs::get_costs_table; +use crate::metering_costs::{get_opcode_index}; static INTERNAL_FIELD: InternalField = InternalField::allocate(); @@ -23,18 +23,18 @@ static INTERNAL_FIELD: InternalField = InternalField::allocate(); /// the same function calls so we can say that the metering is deterministic. /// -pub struct Metering { +pub struct Metering<'a> { limit: u64, current_block: u64, - costs_table: fn(&Operator) -> u64, + opcode_costs: &'a [u32], } -impl Metering { - pub fn new(limit: u64, table_name: &str) -> Metering { +impl<'a> Metering<'a> { + pub fn new(limit: u64, opcode_costs: &'a [u32]) -> Metering<'a> { Metering { limit, current_block: 0, - costs_table: get_costs_table(table_name), + opcode_costs: opcode_costs, } } } @@ -42,7 +42,7 @@ impl Metering { #[derive(Copy, Clone, Debug)] pub struct ExecutionLimitExceededError; -impl FunctionMiddleware for Metering { +impl<'q> FunctionMiddleware for Metering<'q> { type Error = String; fn feed_event<'a, 'b: 'a>( &mut self, @@ -55,7 +55,8 @@ impl FunctionMiddleware for Metering { self.current_block = 0; } Event::Wasm(&ref op) | Event::WasmOwned(ref op) => { - self.current_block += (self.costs_table)(op); + let opcode_index = get_opcode_index(op); + self.current_block += self.opcode_costs[opcode_index] as u64; match *op { Operator::Loop { .. } | Operator::Block { .. } diff --git a/lib/middleware-common/src/metering_costs.rs b/lib/middleware-common/src/metering_costs.rs index e2037967bae9..f0399d061e99 100644 --- a/lib/middleware-common/src/metering_costs.rs +++ b/lib/middleware-common/src/metering_costs.rs @@ -2,39 +2,417 @@ use wasmer_runtime_core:: { wasmparser::Operator }; -pub fn get_costs_table(table_name: &str) -> fn(&Operator) -> u64 { - match table_name { - "uniform_one" => { uniform_one } - "expensive_loop_else_one" => { expensive_loop_else_one } - "expensive_branching_else_one" => { expensive_branching_else_one } - _ => { uniform_zero } - } -} - -fn expensive_branching_else_one(op: &Operator) -> u64 { - match *op { - Operator::Loop { .. } - | Operator::Br { .. } - | Operator::BrTable { .. } - | Operator::BrIf { .. } - | Operator::Call { .. } - | Operator::CallIndirect { .. } - | Operator::Return => { 12 } - _ => { 1 } - } -} - -fn expensive_loop_else_one(op: &Operator) -> u64 { +pub fn get_opcode_index(op: &Operator) -> usize { match *op { - Operator::Loop { .. } => { 12 } - _ => { 1 } + Operator::Unreachable { .. } => { 0 } + Operator::Nop { .. } => { 1 } + Operator::Block { .. } => { 2 } + Operator::Loop { .. } => { 3 } + Operator::If { .. } => { 4 } + Operator::Else { .. } => { 5 } + Operator::End { .. } => { 6 } + Operator::Br { .. } => { 7 } + Operator::BrIf { .. } => { 8 } + Operator::BrTable { .. } => { 9 } + Operator::Return { .. } => { 10 } + Operator::Call { .. } => { 11 } + Operator::CallIndirect { .. } => { 12 } + Operator::Drop { .. } => { 13 } + Operator::Select { .. } => { 14 } + Operator::GetLocal { .. } => { 15 } + Operator::SetLocal { .. } => { 16 } + Operator::TeeLocal { .. } => { 17 } + Operator::GetGlobal { .. } => { 18 } + Operator::SetGlobal { .. } => { 19 } + Operator::I32Load { .. } => { 20 } + Operator::I64Load { .. } => { 21 } + Operator::F32Load { .. } => { 22 } + Operator::F64Load { .. } => { 23 } + Operator::I32Load8S { .. } => { 24 } + Operator::I32Load8U { .. } => { 25 } + Operator::I32Load16S { .. } => { 26 } + Operator::I32Load16U { .. } => { 27 } + Operator::I64Load8S { .. } => { 28 } + Operator::I64Load8U { .. } => { 29 } + Operator::I64Load16S { .. } => { 30 } + Operator::I64Load16U { .. } => { 31 } + Operator::I64Load32S { .. } => { 32 } + Operator::I64Load32U { .. } => { 33 } + Operator::I32Store { .. } => { 34 } + Operator::I64Store { .. } => { 35 } + Operator::F32Store { .. } => { 36 } + Operator::F64Store { .. } => { 37 } + Operator::I32Store8 { .. } => { 38 } + Operator::I32Store16 { .. } => { 39 } + Operator::I64Store8 { .. } => { 40 } + Operator::I64Store16 { .. } => { 41 } + Operator::I64Store32 { .. } => { 42 } + Operator::MemorySize { .. } => { 43 } + Operator::MemoryGrow { .. } => { 44 } + Operator::I32Const { .. } => { 45 } + Operator::I64Const { .. } => { 46 } + Operator::F32Const { .. } => { 47 } + Operator::F64Const { .. } => { 48 } + Operator::RefNull { .. } => { 49 } + Operator::RefIsNull { .. } => { 50 } + Operator::I32Eqz { .. } => { 51 } + Operator::I32Eq { .. } => { 52 } + Operator::I32Ne { .. } => { 53 } + Operator::I32LtS { .. } => { 54 } + Operator::I32LtU { .. } => { 55 } + Operator::I32GtS { .. } => { 56 } + Operator::I32GtU { .. } => { 57 } + Operator::I32LeS { .. } => { 58 } + Operator::I32LeU { .. } => { 59 } + Operator::I32GeS { .. } => { 60 } + Operator::I32GeU { .. } => { 61 } + Operator::I64Eqz { .. } => { 62 } + Operator::I64Eq { .. } => { 63 } + Operator::I64Ne { .. } => { 64 } + Operator::I64LtS { .. } => { 65 } + Operator::I64LtU { .. } => { 66 } + Operator::I64GtS { .. } => { 67 } + Operator::I64GtU { .. } => { 68 } + Operator::I64LeS { .. } => { 69 } + Operator::I64LeU { .. } => { 70 } + Operator::I64GeS { .. } => { 71 } + Operator::I64GeU { .. } => { 72 } + Operator::F32Eq { .. } => { 73 } + Operator::F32Ne { .. } => { 74 } + Operator::F32Lt { .. } => { 75 } + Operator::F32Gt { .. } => { 76 } + Operator::F32Le { .. } => { 77 } + Operator::F32Ge { .. } => { 78 } + Operator::F64Eq { .. } => { 79 } + Operator::F64Ne { .. } => { 80 } + Operator::F64Lt { .. } => { 81 } + Operator::F64Gt { .. } => { 82 } + Operator::F64Le { .. } => { 83 } + Operator::F64Ge { .. } => { 84 } + Operator::I32Clz { .. } => { 85 } + Operator::I32Ctz { .. } => { 86 } + Operator::I32Popcnt { .. } => { 87 } + Operator::I32Add { .. } => { 88 } + Operator::I32Sub { .. } => { 89 } + Operator::I32Mul { .. } => { 90 } + Operator::I32DivS { .. } => { 91 } + Operator::I32DivU { .. } => { 92 } + Operator::I32RemS { .. } => { 93 } + Operator::I32RemU { .. } => { 94 } + Operator::I32And { .. } => { 95 } + Operator::I32Or { .. } => { 96 } + Operator::I32Xor { .. } => { 97 } + Operator::I32Shl { .. } => { 98 } + Operator::I32ShrS { .. } => { 99 } + Operator::I32ShrU { .. } => { 100 } + Operator::I32Rotl { .. } => { 101 } + Operator::I32Rotr { .. } => { 102 } + Operator::I64Clz { .. } => { 103 } + Operator::I64Ctz { .. } => { 104 } + Operator::I64Popcnt { .. } => { 105 } + Operator::I64Add { .. } => { 106 } + Operator::I64Sub { .. } => { 107 } + Operator::I64Mul { .. } => { 108 } + Operator::I64DivS { .. } => { 109 } + Operator::I64DivU { .. } => { 110 } + Operator::I64RemS { .. } => { 111 } + Operator::I64RemU { .. } => { 112 } + Operator::I64And { .. } => { 113 } + Operator::I64Or { .. } => { 114 } + Operator::I64Xor { .. } => { 115 } + Operator::I64Shl { .. } => { 116 } + Operator::I64ShrS { .. } => { 117 } + Operator::I64ShrU { .. } => { 118 } + Operator::I64Rotl { .. } => { 119 } + Operator::I64Rotr { .. } => { 120 } + Operator::F32Abs { .. } => { 121 } + Operator::F32Neg { .. } => { 122 } + Operator::F32Ceil { .. } => { 123 } + Operator::F32Floor { .. } => { 124 } + Operator::F32Trunc { .. } => { 125 } + Operator::F32Nearest { .. } => { 126 } + Operator::F32Sqrt { .. } => { 127 } + Operator::F32Add { .. } => { 128 } + Operator::F32Sub { .. } => { 129 } + Operator::F32Mul { .. } => { 130 } + Operator::F32Div { .. } => { 131 } + Operator::F32Min { .. } => { 132 } + Operator::F32Max { .. } => { 133 } + Operator::F32Copysign { .. } => { 134 } + Operator::F64Abs { .. } => { 135 } + Operator::F64Neg { .. } => { 136 } + Operator::F64Ceil { .. } => { 137 } + Operator::F64Floor { .. } => { 138 } + Operator::F64Trunc { .. } => { 139 } + Operator::F64Nearest { .. } => { 140 } + Operator::F64Sqrt { .. } => { 141 } + Operator::F64Add { .. } => { 142 } + Operator::F64Sub { .. } => { 143 } + Operator::F64Mul { .. } => { 144 } + Operator::F64Div { .. } => { 145 } + Operator::F64Min { .. } => { 146 } + Operator::F64Max { .. } => { 147 } + Operator::F64Copysign { .. } => { 148 } + Operator::I32WrapI64 { .. } => { 149 } + Operator::I32TruncSF32 { .. } => { 150 } + Operator::I32TruncUF32 { .. } => { 151 } + Operator::I32TruncSF64 { .. } => { 152 } + Operator::I32TruncUF64 { .. } => { 153 } + Operator::I64ExtendSI32 { .. } => { 154 } + Operator::I64ExtendUI32 { .. } => { 155 } + Operator::I64TruncSF32 { .. } => { 156 } + Operator::I64TruncUF32 { .. } => { 157 } + Operator::I64TruncSF64 { .. } => { 158 } + Operator::I64TruncUF64 { .. } => { 159 } + Operator::F32ConvertSI32 { .. } => { 160 } + Operator::F32ConvertUI32 { .. } => { 161 } + Operator::F32ConvertSI64 { .. } => { 162 } + Operator::F32ConvertUI64 { .. } => { 163 } + Operator::F32DemoteF64 { .. } => { 164 } + Operator::F64ConvertSI32 { .. } => { 165 } + Operator::F64ConvertUI32 { .. } => { 166 } + Operator::F64ConvertSI64 { .. } => { 167 } + Operator::F64ConvertUI64 { .. } => { 168 } + Operator::F64PromoteF32 { .. } => { 169 } + Operator::I32ReinterpretF32 { .. } => { 170 } + Operator::I64ReinterpretF64 { .. } => { 171 } + Operator::F32ReinterpretI32 { .. } => { 172 } + Operator::F64ReinterpretI64 { .. } => { 173 } + Operator::I32Extend8S { .. } => { 174 } + Operator::I32Extend16S { .. } => { 175 } + Operator::I64Extend8S { .. } => { 176 } + Operator::I64Extend16S { .. } => { 177 } + Operator::I64Extend32S { .. } => { 178 } + Operator::I32TruncSSatF32 { .. } => { 179 } + Operator::I32TruncUSatF32 { .. } => { 180 } + Operator::I32TruncSSatF64 { .. } => { 181 } + Operator::I32TruncUSatF64 { .. } => { 182 } + Operator::I64TruncSSatF32 { .. } => { 183 } + Operator::I64TruncUSatF32 { .. } => { 184 } + Operator::I64TruncSSatF64 { .. } => { 185 } + Operator::I64TruncUSatF64 { .. } => { 186 } + Operator::MemoryInit { .. } => { 187 } + Operator::DataDrop { .. } => { 188 } + Operator::MemoryCopy { .. } => { 189 } + Operator::MemoryFill { .. } => { 190 } + Operator::TableInit { .. } => { 191 } + Operator::ElemDrop { .. } => { 192 } + Operator::TableCopy { .. } => { 193 } + Operator::TableGet { .. } => { 194 } + Operator::TableSet { .. } => { 195 } + Operator::TableGrow { .. } => { 196 } + Operator::TableSize { .. } => { 197 } + Operator::Wake { .. } => { 198 } + Operator::I32Wait { .. } => { 199 } + Operator::I64Wait { .. } => { 200 } + Operator::Fence { .. } => { 201 } + Operator::I32AtomicLoad { .. } => { 202 } + Operator::I64AtomicLoad { .. } => { 203 } + Operator::I32AtomicLoad8U { .. } => { 204 } + Operator::I32AtomicLoad16U { .. } => { 205 } + Operator::I64AtomicLoad8U { .. } => { 206 } + Operator::I64AtomicLoad16U { .. } => { 207 } + Operator::I64AtomicLoad32U { .. } => { 208 } + Operator::I32AtomicStore { .. } => { 209 } + Operator::I64AtomicStore { .. } => { 210 } + Operator::I32AtomicStore8 { .. } => { 211 } + Operator::I32AtomicStore16 { .. } => { 212 } + Operator::I64AtomicStore8 { .. } => { 213 } + Operator::I64AtomicStore16 { .. } => { 214 } + Operator::I64AtomicStore32 { .. } => { 215 } + Operator::I32AtomicRmwAdd { .. } => { 216 } + Operator::I64AtomicRmwAdd { .. } => { 217 } + Operator::I32AtomicRmw8UAdd { .. } => { 218 } + Operator::I32AtomicRmw16UAdd { .. } => { 219 } + Operator::I64AtomicRmw8UAdd { .. } => { 220 } + Operator::I64AtomicRmw16UAdd { .. } => { 221 } + Operator::I64AtomicRmw32UAdd { .. } => { 222 } + Operator::I32AtomicRmwSub { .. } => { 223 } + Operator::I64AtomicRmwSub { .. } => { 224 } + Operator::I32AtomicRmw8USub { .. } => { 225 } + Operator::I32AtomicRmw16USub { .. } => { 226 } + Operator::I64AtomicRmw8USub { .. } => { 227 } + Operator::I64AtomicRmw16USub { .. } => { 228 } + Operator::I64AtomicRmw32USub { .. } => { 229 } + Operator::I32AtomicRmwAnd { .. } => { 230 } + Operator::I64AtomicRmwAnd { .. } => { 231 } + Operator::I32AtomicRmw8UAnd { .. } => { 232 } + Operator::I32AtomicRmw16UAnd { .. } => { 233 } + Operator::I64AtomicRmw8UAnd { .. } => { 234 } + Operator::I64AtomicRmw16UAnd { .. } => { 235 } + Operator::I64AtomicRmw32UAnd { .. } => { 236 } + Operator::I32AtomicRmwOr { .. } => { 237 } + Operator::I64AtomicRmwOr { .. } => { 238 } + Operator::I32AtomicRmw8UOr { .. } => { 239 } + Operator::I32AtomicRmw16UOr { .. } => { 240 } + Operator::I64AtomicRmw8UOr { .. } => { 241 } + Operator::I64AtomicRmw16UOr { .. } => { 242 } + Operator::I64AtomicRmw32UOr { .. } => { 243 } + Operator::I32AtomicRmwXor { .. } => { 244 } + Operator::I64AtomicRmwXor { .. } => { 245 } + Operator::I32AtomicRmw8UXor { .. } => { 246 } + Operator::I32AtomicRmw16UXor { .. } => { 247 } + Operator::I64AtomicRmw8UXor { .. } => { 248 } + Operator::I64AtomicRmw16UXor { .. } => { 249 } + Operator::I64AtomicRmw32UXor { .. } => { 250 } + Operator::I32AtomicRmwXchg { .. } => { 251 } + Operator::I64AtomicRmwXchg { .. } => { 252 } + Operator::I32AtomicRmw8UXchg { .. } => { 253 } + Operator::I32AtomicRmw16UXchg { .. } => { 254 } + Operator::I64AtomicRmw8UXchg { .. } => { 255 } + Operator::I64AtomicRmw16UXchg { .. } => { 256 } + Operator::I64AtomicRmw32UXchg { .. } => { 257 } + Operator::I32AtomicRmwCmpxchg { .. } => { 258 } + Operator::I64AtomicRmwCmpxchg { .. } => { 259 } + Operator::I32AtomicRmw8UCmpxchg { .. } => { 260 } + Operator::I32AtomicRmw16UCmpxchg { .. } => { 261 } + Operator::I64AtomicRmw8UCmpxchg { .. } => { 262 } + Operator::I64AtomicRmw16UCmpxchg { .. } => { 263 } + Operator::I64AtomicRmw32UCmpxchg { .. } => { 264 } + Operator::V128Load { .. } => { 265 } + Operator::V128Store { .. } => { 266 } + Operator::V128Const { .. } => { 267 } + Operator::I8x16Splat { .. } => { 268 } + Operator::I8x16ExtractLaneS { .. } => { 269 } + Operator::I8x16ExtractLaneU { .. } => { 270 } + Operator::I8x16ReplaceLane { .. } => { 271 } + Operator::I16x8Splat { .. } => { 272 } + Operator::I16x8ExtractLaneS { .. } => { 273 } + Operator::I16x8ExtractLaneU { .. } => { 274 } + Operator::I16x8ReplaceLane { .. } => { 275 } + Operator::I32x4Splat { .. } => { 276 } + Operator::I32x4ExtractLane { .. } => { 277 } + Operator::I32x4ReplaceLane { .. } => { 278 } + Operator::I64x2Splat { .. } => { 279 } + Operator::I64x2ExtractLane { .. } => { 280 } + Operator::I64x2ReplaceLane { .. } => { 281 } + Operator::F32x4Splat { .. } => { 282 } + Operator::F32x4ExtractLane { .. } => { 283 } + Operator::F32x4ReplaceLane { .. } => { 284 } + Operator::F64x2Splat { .. } => { 285 } + Operator::F64x2ExtractLane { .. } => { 286 } + Operator::F64x2ReplaceLane { .. } => { 287 } + Operator::I8x16Eq { .. } => { 288 } + Operator::I8x16Ne { .. } => { 289 } + Operator::I8x16LtS { .. } => { 290 } + Operator::I8x16LtU { .. } => { 291 } + Operator::I8x16GtS { .. } => { 292 } + Operator::I8x16GtU { .. } => { 293 } + Operator::I8x16LeS { .. } => { 294 } + Operator::I8x16LeU { .. } => { 295 } + Operator::I8x16GeS { .. } => { 296 } + Operator::I8x16GeU { .. } => { 297 } + Operator::I16x8Eq { .. } => { 298 } + Operator::I16x8Ne { .. } => { 299 } + Operator::I16x8LtS { .. } => { 300 } + Operator::I16x8LtU { .. } => { 301 } + Operator::I16x8GtS { .. } => { 302 } + Operator::I16x8GtU { .. } => { 303 } + Operator::I16x8LeS { .. } => { 304 } + Operator::I16x8LeU { .. } => { 305 } + Operator::I16x8GeS { .. } => { 306 } + Operator::I16x8GeU { .. } => { 307 } + Operator::I32x4Eq { .. } => { 308 } + Operator::I32x4Ne { .. } => { 309 } + Operator::I32x4LtS { .. } => { 310 } + Operator::I32x4LtU { .. } => { 311 } + Operator::I32x4GtS { .. } => { 312 } + Operator::I32x4GtU { .. } => { 313 } + Operator::I32x4LeS { .. } => { 314 } + Operator::I32x4LeU { .. } => { 315 } + Operator::I32x4GeS { .. } => { 316 } + Operator::I32x4GeU { .. } => { 317 } + Operator::F32x4Eq { .. } => { 318 } + Operator::F32x4Ne { .. } => { 319 } + Operator::F32x4Lt { .. } => { 320 } + Operator::F32x4Gt { .. } => { 321 } + Operator::F32x4Le { .. } => { 322 } + Operator::F32x4Ge { .. } => { 323 } + Operator::F64x2Eq { .. } => { 324 } + Operator::F64x2Ne { .. } => { 325 } + Operator::F64x2Lt { .. } => { 326 } + Operator::F64x2Gt { .. } => { 327 } + Operator::F64x2Le { .. } => { 328 } + Operator::F64x2Ge { .. } => { 329 } + Operator::V128Not { .. } => { 330 } + Operator::V128And { .. } => { 331 } + Operator::V128Or { .. } => { 332 } + Operator::V128Xor { .. } => { 333 } + Operator::V128Bitselect { .. } => { 334 } + Operator::I8x16Neg { .. } => { 335 } + Operator::I8x16AnyTrue { .. } => { 336 } + Operator::I8x16AllTrue { .. } => { 337 } + Operator::I8x16Shl { .. } => { 338 } + Operator::I8x16ShrS { .. } => { 339 } + Operator::I8x16ShrU { .. } => { 340 } + Operator::I8x16Add { .. } => { 341 } + Operator::I8x16AddSaturateS { .. } => { 342 } + Operator::I8x16AddSaturateU { .. } => { 343 } + Operator::I8x16Sub { .. } => { 344 } + Operator::I8x16SubSaturateS { .. } => { 345 } + Operator::I8x16SubSaturateU { .. } => { 346 } + Operator::I8x16Mul { .. } => { 347 } + Operator::I16x8Neg { .. } => { 348 } + Operator::I16x8AnyTrue { .. } => { 349 } + Operator::I16x8AllTrue { .. } => { 350 } + Operator::I16x8Shl { .. } => { 351 } + Operator::I16x8ShrS { .. } => { 352 } + Operator::I16x8ShrU { .. } => { 353 } + Operator::I16x8Add { .. } => { 354 } + Operator::I16x8AddSaturateS { .. } => { 355 } + Operator::I16x8AddSaturateU { .. } => { 356 } + Operator::I16x8Sub { .. } => { 357 } + Operator::I16x8SubSaturateS { .. } => { 358 } + Operator::I16x8SubSaturateU { .. } => { 359 } + Operator::I16x8Mul { .. } => { 360 } + Operator::I32x4Neg { .. } => { 361 } + Operator::I32x4AnyTrue { .. } => { 362 } + Operator::I32x4AllTrue { .. } => { 363 } + Operator::I32x4Shl { .. } => { 364 } + Operator::I32x4ShrS { .. } => { 365 } + Operator::I32x4ShrU { .. } => { 366 } + Operator::I32x4Add { .. } => { 367 } + Operator::I32x4Sub { .. } => { 368 } + Operator::I32x4Mul { .. } => { 369 } + Operator::I64x2Neg { .. } => { 370 } + Operator::I64x2AnyTrue { .. } => { 371 } + Operator::I64x2AllTrue { .. } => { 372 } + Operator::I64x2Shl { .. } => { 373 } + Operator::I64x2ShrS { .. } => { 374 } + Operator::I64x2ShrU { .. } => { 375 } + Operator::I64x2Add { .. } => { 376 } + Operator::I64x2Sub { .. } => { 377 } + Operator::F32x4Abs { .. } => { 378 } + Operator::F32x4Neg { .. } => { 379 } + Operator::F32x4Sqrt { .. } => { 380 } + Operator::F32x4Add { .. } => { 381 } + Operator::F32x4Sub { .. } => { 382 } + Operator::F32x4Mul { .. } => { 383 } + Operator::F32x4Div { .. } => { 384 } + Operator::F32x4Min { .. } => { 385 } + Operator::F32x4Max { .. } => { 386 } + Operator::F64x2Abs { .. } => { 387 } + Operator::F64x2Neg { .. } => { 388 } + Operator::F64x2Sqrt { .. } => { 389 } + Operator::F64x2Add { .. } => { 390 } + Operator::F64x2Sub { .. } => { 391 } + Operator::F64x2Mul { .. } => { 392 } + Operator::F64x2Div { .. } => { 393 } + Operator::F64x2Min { .. } => { 394 } + Operator::F64x2Max { .. } => { 395 } + Operator::I32x4TruncSF32x4Sat { .. } => { 396 } + Operator::I32x4TruncUF32x4Sat { .. } => { 397 } + Operator::I64x2TruncSF64x2Sat { .. } => { 398 } + Operator::I64x2TruncUF64x2Sat { .. } => { 399 } + Operator::F32x4ConvertSI32x4 { .. } => { 400 } + Operator::F32x4ConvertUI32x4 { .. } => { 401 } + Operator::F64x2ConvertSI64x2 { .. } => { 402 } + Operator::F64x2ConvertUI64x2 { .. } => { 403 } + Operator::V8x16Swizzle { .. } => { 404 } + Operator::V8x16Shuffle { .. } => { 405 } + Operator::I8x16LoadSplat { .. } => { 406 } + Operator::I16x8LoadSplat { .. } => { 407 } + Operator::I32x4LoadSplat { .. } => { 408 } + Operator::I64x2LoadSplat { .. } => { 409 } } } - -fn uniform_one(_op: &Operator) -> u64 { - 1 -} - -fn uniform_zero(_op: &Operator) -> u64 { - 0 -} diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index e79f16852b28..43d22e59d148 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -14,15 +14,15 @@ use wasmer_runtime_core::{ import::{ImportObject, Namespace}, }; -use std::ffi::CStr; -use std::os::raw::c_char; - #[cfg(feature = "metering")] use wasmer_runtime_core::backend::Compiler; #[cfg(not(feature = "cranelift-backend"))] use wasmer_middleware_common::metering; +pub const OPCODE_COUNT: usize = 410; +static mut OPCODE_COSTS: [u32; OPCODE_COUNT] = [0; OPCODE_COUNT]; + #[allow(clippy::cast_ptr_alignment)] #[cfg(feature = "metering")] @@ -34,7 +34,7 @@ pub unsafe extern "C" fn wasmer_instantiate_with_metering( imports: *mut wasmer_import_t, imports_len: c_int, gas_limit: u64, - costs_table_name: *const c_char, + opcode_costs_pointer: *const u32, ) -> wasmer_result_t { if wasm_bytes.is_null() { update_last_error(CApiError { @@ -97,9 +97,11 @@ pub unsafe extern "C" fn wasmer_instantiate_with_metering( import_object.register(module_name, namespace); } + OPCODE_COSTS.copy_from_slice(slice::from_raw_parts(opcode_costs_pointer, OPCODE_COUNT)); + let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); - let costs_table_name_owned = CStr::from_ptr(costs_table_name).to_string_lossy().into_owned(); - let result_compilation = wasmer_runtime_core::compile_with(bytes, &get_metered_compiler(gas_limit, &costs_table_name_owned)); + let compiler = get_metered_compiler(gas_limit); + let result_compilation = wasmer_runtime_core::compile_with(bytes, &compiler); let new_module = match result_compilation { Ok(module) => module, Err(_) => { @@ -135,6 +137,7 @@ pub unsafe extern "C" fn wasmer_compile_with_gas_metering( wasm_bytes: *mut u8, wasm_bytes_len: u32, gas_limit: u64, + opcode_costs_pointer: *const u32, ) -> wasmer_result_t { if module.is_null() { update_last_error(CApiError { @@ -149,8 +152,11 @@ pub unsafe extern "C" fn wasmer_compile_with_gas_metering( return wasmer_result_t::WASMER_ERROR; } + OPCODE_COSTS.copy_from_slice(slice::from_raw_parts(opcode_costs_pointer, OPCODE_COUNT)); + let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); - let result = wasmer_runtime_core::compile_with(bytes, &get_metered_compiler(gas_limit, "uniform_one")); + let compiler = get_metered_compiler(gas_limit); + let result = wasmer_runtime_core::compile_with(bytes, &compiler); let new_module = match result { Ok(instance) => instance, Err(_) => { @@ -165,7 +171,7 @@ pub unsafe extern "C" fn wasmer_compile_with_gas_metering( } #[cfg(feature = "metering")] -fn get_metered_compiler(limit: u64, costs_table_name: &str) -> impl Compiler { +unsafe fn get_metered_compiler(limit: u64) -> impl Compiler { use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler}; #[cfg(feature = "llvm-backend")] @@ -177,11 +183,10 @@ fn get_metered_compiler(limit: u64, costs_table_name: &str) -> impl Compiler { #[cfg(feature = "cranelift-backend")] use wasmer_clif_backend::CraneliftModuleCodeGenerator as MeteredMCG; - let table_name = (*costs_table_name).to_string(); - let c: StreamingCompiler = StreamingCompiler::new(move || { let mut chain = MiddlewareChain::new(); - chain.push(metering::Metering::new(limit, &table_name)); + + chain.push(metering::Metering::new(limit, &OPCODE_COSTS)); chain }); c diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 662fbe6b9d35..e16a7c39c6eb 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -6,6 +6,8 @@ #include #include +#define OPCODE_COUNT 410 + /** * List of export/import kinds. */ @@ -193,7 +195,8 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, uint8_t *wasm_bytes, uint32_t wasm_bytes_len, - uint64_t gas_limit); + uint64_t gas_limit, + const uint32_t *opcode_costs_pointer); /** * Gets export descriptor kind @@ -548,7 +551,7 @@ wasmer_result_t wasmer_instantiate_with_metering(wasmer_instance_t **instance, wasmer_import_t *imports, int imports_len, uint64_t gas_limit, - const char *costs_table_name); + const uint32_t *opcode_costs_pointer); /** * Gets the length in bytes of the last error. diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index f631d92c45f8..f972c2bbf1ff 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -6,6 +6,8 @@ #include #include +static const uintptr_t OPCODE_COUNT = 410; + /// List of export/import kinds. enum class wasmer_import_export_kind : uint32_t { WASM_FUNCTION, @@ -175,7 +177,8 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, uint8_t *wasm_bytes, uint32_t wasm_bytes_len, - uint64_t gas_limit); + uint64_t gas_limit, + const uint32_t *opcode_costs_pointer); /// Gets export descriptor kind wasmer_import_export_kind wasmer_export_descriptor_kind(wasmer_export_descriptor_t *export_); @@ -436,7 +439,7 @@ wasmer_result_t wasmer_instantiate_with_metering(wasmer_instance_t **instance, wasmer_import_t *imports, int imports_len, uint64_t gas_limit, - const char *costs_table_name); + const uint32_t *opcode_costs_pointer); /// Gets the length in bytes of the last error. /// This can be used to dynamically allocate a buffer with the correct number of From c421a54bce5a5fe7619c1d6e8addfd332f3c233e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 12 Nov 2019 17:18:36 +0200 Subject: [PATCH 028/129] Isolate building imports --- lib/runtime-c-api/src/import.rs | 72 ++++++++++++++++++++++++++++++- lib/runtime-c-api/src/metering.rs | 65 ++++++---------------------- 2 files changed, 83 insertions(+), 54 deletions(-) diff --git a/lib/runtime-c-api/src/import.rs b/lib/runtime-c-api/src/import.rs index 2d6f9e99d31d..cbb53584a9f8 100644 --- a/lib/runtime-c-api/src/import.rs +++ b/lib/runtime-c-api/src/import.rs @@ -8,15 +8,22 @@ use crate::{ value::wasmer_value_tag, wasmer_byte_array, wasmer_result_t, }; -use libc::c_uint; +use libc::{c_int, c_uint}; use std::{ffi::c_void, ptr, slice, sync::Arc}; +use std::result::Result; use wasmer_runtime::{Global, Memory, Module, Table}; use wasmer_runtime_core::{ export::{Context, Export, FuncPointer}, - import::ImportObject, + import::{ImportObject, Namespace}, module::ImportName, types::{FuncSig, Type}, }; +use std::{collections::HashMap}; + +pub enum ImportError { + ModuleNameError, + ImportNameError, +} #[repr(C)] pub struct wasmer_import_t { @@ -51,6 +58,67 @@ pub unsafe extern "C" fn wasmer_import_object_new() -> *mut wasmer_import_object Box::into_raw(import_object) as *mut wasmer_import_object_t } +/// Assembles an ImportObject from a list of imports received on the C API +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe fn wasmer_create_import_object_from_imports( + imports: *mut wasmer_import_t, + imports_len: c_int, +) -> Result { + let imports: &[wasmer_import_t] = slice::from_raw_parts(imports, imports_len as usize); + let mut import_object = ImportObject::new(); + let mut namespaces = HashMap::new(); + + for import in imports { + let module_name = slice::from_raw_parts( + import.module_name.bytes, + import.module_name.bytes_len as usize, + ); + let module_name = if let Ok(s) = std::str::from_utf8(module_name) { + s + } else { + return Err(ImportError::ModuleNameError) + }; + let import_name = slice::from_raw_parts( + import.import_name.bytes, + import.import_name.bytes_len as usize, + ); + let import_name = if let Ok(s) = std::str::from_utf8(import_name) { + s + } else { + return Err(ImportError::ImportNameError) + }; + + let namespace = namespaces.entry(module_name).or_insert_with(Namespace::new); + + let export = match import.tag { + wasmer_import_export_kind::WASM_MEMORY => { + let mem = import.value.memory as *mut Memory; + Export::Memory((&*mem).clone()) + } + wasmer_import_export_kind::WASM_FUNCTION => { + let func_export = import.value.func as *mut Export; + (&*func_export).clone() + } + wasmer_import_export_kind::WASM_GLOBAL => { + let global = import.value.global as *mut Global; + Export::Global((&*global).clone()) + } + wasmer_import_export_kind::WASM_TABLE => { + let table = import.value.table as *mut Table; + Export::Table((&*table).clone()) + } + }; + namespace.insert(import_name, export); + } + + for (module_name, namespace) in namespaces.into_iter() { + import_object.register(module_name, namespace); + } + + Ok(import_object) +} + /// Extends an existing import object with new imports #[allow(clippy::cast_ptr_alignment)] #[no_mangle] diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 43d22e59d148..6993874337f1 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -1,5 +1,4 @@ use crate::{ - export::{wasmer_import_export_kind}, import::{wasmer_import_t}, error::{update_last_error, CApiError}, instance::wasmer_instance_t, @@ -7,11 +6,10 @@ use crate::{ wasmer_result_t, }; use libc::{c_int}; -use std::{collections::HashMap, slice}; -use wasmer_runtime::{Global, Memory, Table}; -use wasmer_runtime_core::{ - export::Export, - import::{ImportObject, Namespace}, +use std::{slice}; +use crate::import::{ + wasmer_create_import_object_from_imports, + ImportError, }; #[cfg(feature = "metering")] @@ -42,60 +40,23 @@ pub unsafe extern "C" fn wasmer_instantiate_with_metering( }); return wasmer_result_t::WASMER_ERROR; } - let imports: &[wasmer_import_t] = slice::from_raw_parts(imports, imports_len as usize); - let mut import_object = ImportObject::new(); - let mut namespaces = HashMap::new(); - for import in imports { - let module_name = slice::from_raw_parts( - import.module_name.bytes, - import.module_name.bytes_len as usize, - ); - let module_name = if let Ok(s) = std::str::from_utf8(module_name) { - s - } else { + + let imports_result = wasmer_create_import_object_from_imports(imports, imports_len); + let import_object = match imports_result { + Err(ImportError::ModuleNameError) => { update_last_error(CApiError { msg: "error converting module name to string".to_string(), }); return wasmer_result_t::WASMER_ERROR; - }; - let import_name = slice::from_raw_parts( - import.import_name.bytes, - import.import_name.bytes_len as usize, - ); - let import_name = if let Ok(s) = std::str::from_utf8(import_name) { - s - } else { + } + Err(ImportError::ImportNameError) => { update_last_error(CApiError { msg: "error converting import_name to string".to_string(), }); return wasmer_result_t::WASMER_ERROR; - }; - - let namespace = namespaces.entry(module_name).or_insert_with(Namespace::new); - - let export = match import.tag { - wasmer_import_export_kind::WASM_MEMORY => { - let mem = import.value.memory as *mut Memory; - Export::Memory((&*mem).clone()) - } - wasmer_import_export_kind::WASM_FUNCTION => { - let func_export = import.value.func as *mut Export; - (&*func_export).clone() - } - wasmer_import_export_kind::WASM_GLOBAL => { - let global = import.value.global as *mut Global; - Export::Global((&*global).clone()) - } - wasmer_import_export_kind::WASM_TABLE => { - let table = import.value.table as *mut Table; - Export::Table((&*table).clone()) - } - }; - namespace.insert(import_name, export); - } - for (module_name, namespace) in namespaces.into_iter() { - import_object.register(module_name, namespace); - } + } + Ok(created_imports_object) => created_imports_object + }; OPCODE_COSTS.copy_from_slice(slice::from_raw_parts(opcode_costs_pointer, OPCODE_COUNT)); From 599cb2aea4c48b13ed8d87dfdaf91523d6cf45c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 13 Nov 2019 16:55:53 +0200 Subject: [PATCH 029/129] Create ImportObject constructors; create instance constructors that reuse ImportObjects --- lib/runtime-c-api/src/import.rs | 23 ++++++++++++ lib/runtime-c-api/src/metering.rs | 61 ++++++++++++++++++++++++++----- lib/runtime-c-api/wasmer.h | 11 ++++++ lib/runtime-c-api/wasmer.hh | 11 ++++++ lib/runtime-core/src/lib.rs | 2 + 5 files changed, 99 insertions(+), 9 deletions(-) diff --git a/lib/runtime-c-api/src/import.rs b/lib/runtime-c-api/src/import.rs index cbb53584a9f8..895ab12a5413 100644 --- a/lib/runtime-c-api/src/import.rs +++ b/lib/runtime-c-api/src/import.rs @@ -58,6 +58,29 @@ pub unsafe extern "C" fn wasmer_import_object_new() -> *mut wasmer_import_object Box::into_raw(import_object) as *mut wasmer_import_object_t } +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_import_object_new_from_imports( + external_import_object: *mut *mut wasmer_import_object_t, + imports: *mut wasmer_import_t, + imports_len: c_int, +) -> wasmer_result_t { + let imports_result = wasmer_create_import_object_from_imports(imports, imports_len); + let import_object = match imports_result { + Err(ImportError::ModuleNameError) => { + update_last_error(CApiError { msg: "error converting module name to string".to_string() }); + return wasmer_result_t::WASMER_ERROR; + } + Err(ImportError::ImportNameError) => { + update_last_error(CApiError { msg: "error converting import_name to string".to_string() }); + return wasmer_result_t::WASMER_ERROR; + } + Ok(created_imports_object) => created_imports_object + }; + *external_import_object = Box::into_raw(Box::new(import_object)) as *mut wasmer_import_object_t; + return wasmer_result_t::WASMER_OK +} + /// Assembles an ImportObject from a list of imports received on the C API #[allow(clippy::cast_ptr_alignment)] #[no_mangle] diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 6993874337f1..1277acf35068 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -12,6 +12,8 @@ use crate::import::{ ImportError, }; +use wasmer_runtime_core::import::ImportObject; + #[cfg(feature = "metering")] use wasmer_runtime_core::backend::Compiler; @@ -21,6 +23,8 @@ use wasmer_middleware_common::metering; pub const OPCODE_COUNT: usize = 410; static mut OPCODE_COSTS: [u32; OPCODE_COUNT] = [0; OPCODE_COUNT]; +#[repr(C)] +pub struct wasmer_import_object_t; #[allow(clippy::cast_ptr_alignment)] #[cfg(feature = "metering")] @@ -44,15 +48,11 @@ pub unsafe extern "C" fn wasmer_instantiate_with_metering( let imports_result = wasmer_create_import_object_from_imports(imports, imports_len); let import_object = match imports_result { Err(ImportError::ModuleNameError) => { - update_last_error(CApiError { - msg: "error converting module name to string".to_string(), - }); + update_last_error(CApiError { msg: "error converting module name to string".to_string() }); return wasmer_result_t::WASMER_ERROR; } Err(ImportError::ImportNameError) => { - update_last_error(CApiError { - msg: "error converting import_name to string".to_string(), - }); + update_last_error(CApiError { msg: "error converting import_name to string".to_string() }); return wasmer_result_t::WASMER_ERROR; } Ok(created_imports_object) => created_imports_object @@ -66,12 +66,54 @@ pub unsafe extern "C" fn wasmer_instantiate_with_metering( let new_module = match result_compilation { Ok(module) => module, Err(_) => { - update_last_error(CApiError { - msg: "compile error".to_string(), - }); + update_last_error(CApiError { msg: "compile error".to_string() }); + return wasmer_result_t::WASMER_ERROR; + } + }; + let result_instantiation = new_module.instantiate(&import_object); + let new_instance = match result_instantiation { + Ok(instance) => instance, + Err(error) => { + update_last_error(error); + return wasmer_result_t::WASMER_ERROR; + } + }; + *instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t; + wasmer_result_t::WASMER_OK +} + +#[allow(clippy::cast_ptr_alignment)] +#[cfg(feature = "metering")] +#[no_mangle] +pub unsafe extern "C" fn wasmer_instantiate_with_metering_and_import_object( + instance: *mut *mut wasmer_instance_t, + wasm_bytes: *mut u8, + wasm_bytes_len: u32, + external_import_object: *mut wasmer_import_object_t, + gas_limit: u64, + opcode_costs_pointer: *mut u32, +) -> wasmer_result_t { + if wasm_bytes.is_null() { + update_last_error(CApiError { + msg: "wasm bytes ptr is null".to_string(), + }); + return wasmer_result_t::WASMER_ERROR; + } + + OPCODE_COSTS.copy_from_slice(slice::from_raw_parts(opcode_costs_pointer, OPCODE_COUNT)); + + let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); + let compiler = get_metered_compiler(gas_limit); + let result_compilation = wasmer_runtime_core::compile_with(bytes, &compiler); + let new_module = match result_compilation { + Ok(module) => module, + Err(_) => { + update_last_error(CApiError { msg: "compile error".to_string() }); return wasmer_result_t::WASMER_ERROR; } }; + + let import_object: &mut ImportObject = &mut *(external_import_object as *mut ImportObject); let result_instantiation = new_module.instantiate(&import_object); let new_instance = match result_instantiation { Ok(instance) => instance, @@ -84,6 +126,7 @@ pub unsafe extern "C" fn wasmer_instantiate_with_metering( wasmer_result_t::WASMER_OK } + /// Creates a new Module with gas limit from the given wasm bytes. /// /// Returns `wasmer_result_t::WASMER_OK` upon success. diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index e16a7c39c6eb..ee99c171954f 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -476,6 +476,10 @@ wasmer_result_t wasmer_import_object_extend(wasmer_import_object_t *import_objec */ wasmer_import_object_t *wasmer_import_object_new(void); +wasmer_result_t wasmer_import_object_new_from_imports(wasmer_import_object_t **external_import_object, + wasmer_import_t *imports, + int imports_len); + /** * Calls an instances exported function by `name` with the provided parameters. * Results are set using the provided `results` pointer. @@ -553,6 +557,13 @@ wasmer_result_t wasmer_instantiate_with_metering(wasmer_instance_t **instance, uint64_t gas_limit, const uint32_t *opcode_costs_pointer); +wasmer_result_t wasmer_instantiate_with_metering_and_import_object(wasmer_instance_t **instance, + uint8_t *wasm_bytes, + uint32_t wasm_bytes_len, + wasmer_import_object_t *external_import_object, + uint64_t gas_limit, + uint32_t *opcode_costs_pointer); + /** * Gets the length in bytes of the last error. * This can be used to dynamically allocate a buffer with the correct number of diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index f972c2bbf1ff..9550af1d10b0 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -380,6 +380,10 @@ wasmer_result_t wasmer_import_object_extend(wasmer_import_object_t *import_objec /// See also `wasmer_import_object_append` wasmer_import_object_t *wasmer_import_object_new(); +wasmer_result_t wasmer_import_object_new_from_imports(wasmer_import_object_t **external_import_object, + wasmer_import_t *imports, + int imports_len); + /// Calls an instances exported function by `name` with the provided parameters. /// Results are set using the provided `results` pointer. /// @@ -441,6 +445,13 @@ wasmer_result_t wasmer_instantiate_with_metering(wasmer_instance_t **instance, uint64_t gas_limit, const uint32_t *opcode_costs_pointer); +wasmer_result_t wasmer_instantiate_with_metering_and_import_object(wasmer_instance_t **instance, + uint8_t *wasm_bytes, + uint32_t wasm_bytes_len, + wasmer_import_object_t *external_import_object, + uint64_t gas_limit, + uint32_t *opcode_costs_pointer); + /// Gets the length in bytes of the last error. /// This can be used to dynamically allocate a buffer with the correct number of /// bytes needed to store a message. diff --git a/lib/runtime-core/src/lib.rs b/lib/runtime-core/src/lib.rs index 26a76f7dbf61..c4f5083d43c5 100644 --- a/lib/runtime-core/src/lib.rs +++ b/lib/runtime-core/src/lib.rs @@ -87,6 +87,8 @@ pub mod prelude { pub use crate::{func, imports}; } +pub use crate::import::{ImportObject, Namespace}; + /// Compile a [`Module`] using the provided compiler from /// WebAssembly binary code. This function is useful if it /// is necessary to a compile a module before it can be instantiated From 6d5099618fb2746fd3bf14179f0b1d0ff5f5f32b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 15 Nov 2019 10:29:10 +0200 Subject: [PATCH 030/129] Implement external setters for ImportObject and OPCODE_COSTS and clean up instance constructors --- lib/runtime-c-api/src/import.rs | 7 ++-- lib/runtime-c-api/src/metering.rs | 68 +++---------------------------- lib/runtime-c-api/wasmer.h | 31 +++++--------- lib/runtime-c-api/wasmer.hh | 31 +++++--------- 4 files changed, 30 insertions(+), 107 deletions(-) diff --git a/lib/runtime-c-api/src/import.rs b/lib/runtime-c-api/src/import.rs index 895ab12a5413..7e4c49478802 100644 --- a/lib/runtime-c-api/src/import.rs +++ b/lib/runtime-c-api/src/import.rs @@ -25,6 +25,8 @@ pub enum ImportError { ImportNameError, } +pub static mut GLOBAL_IMPORT_OBJECT: *mut ImportObject = 0 as *mut ImportObject; + #[repr(C)] pub struct wasmer_import_t { pub module_name: wasmer_byte_array, @@ -60,8 +62,7 @@ pub unsafe extern "C" fn wasmer_import_object_new() -> *mut wasmer_import_object #[allow(clippy::cast_ptr_alignment)] #[no_mangle] -pub unsafe extern "C" fn wasmer_import_object_new_from_imports( - external_import_object: *mut *mut wasmer_import_object_t, +pub unsafe extern "C" fn wasmer_import_object_cache_from_imports( imports: *mut wasmer_import_t, imports_len: c_int, ) -> wasmer_result_t { @@ -77,7 +78,7 @@ pub unsafe extern "C" fn wasmer_import_object_new_from_imports( } Ok(created_imports_object) => created_imports_object }; - *external_import_object = Box::into_raw(Box::new(import_object)) as *mut wasmer_import_object_t; + GLOBAL_IMPORT_OBJECT = Box::into_raw(Box::new(import_object)); return wasmer_result_t::WASMER_OK } diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 1277acf35068..dd0d37065372 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -1,15 +1,12 @@ use crate::{ - import::{wasmer_import_t}, error::{update_last_error, CApiError}, instance::wasmer_instance_t, module::wasmer_module_t, wasmer_result_t, }; -use libc::{c_int}; use std::{slice}; use crate::import::{ - wasmer_create_import_object_from_imports, - ImportError, + GLOBAL_IMPORT_OBJECT, }; use wasmer_runtime_core::import::ImportObject; @@ -29,69 +26,21 @@ pub struct wasmer_import_object_t; #[allow(clippy::cast_ptr_alignment)] #[cfg(feature = "metering")] #[no_mangle] -pub unsafe extern "C" fn wasmer_instantiate_with_metering( - instance: *mut *mut wasmer_instance_t, - wasm_bytes: *mut u8, - wasm_bytes_len: u32, - imports: *mut wasmer_import_t, - imports_len: c_int, - gas_limit: u64, +pub unsafe extern "C" fn wasmer_set_opcode_costs( opcode_costs_pointer: *const u32, -) -> wasmer_result_t { - if wasm_bytes.is_null() { - update_last_error(CApiError { - msg: "wasm bytes ptr is null".to_string(), - }); - return wasmer_result_t::WASMER_ERROR; - } - - let imports_result = wasmer_create_import_object_from_imports(imports, imports_len); - let import_object = match imports_result { - Err(ImportError::ModuleNameError) => { - update_last_error(CApiError { msg: "error converting module name to string".to_string() }); - return wasmer_result_t::WASMER_ERROR; - } - Err(ImportError::ImportNameError) => { - update_last_error(CApiError { msg: "error converting import_name to string".to_string() }); - return wasmer_result_t::WASMER_ERROR; - } - Ok(created_imports_object) => created_imports_object - }; - +) { OPCODE_COSTS.copy_from_slice(slice::from_raw_parts(opcode_costs_pointer, OPCODE_COUNT)); - - let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); - let compiler = get_metered_compiler(gas_limit); - let result_compilation = wasmer_runtime_core::compile_with(bytes, &compiler); - let new_module = match result_compilation { - Ok(module) => module, - Err(_) => { - update_last_error(CApiError { msg: "compile error".to_string() }); - return wasmer_result_t::WASMER_ERROR; - } - }; - let result_instantiation = new_module.instantiate(&import_object); - let new_instance = match result_instantiation { - Ok(instance) => instance, - Err(error) => { - update_last_error(error); - return wasmer_result_t::WASMER_ERROR; - } - }; - *instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t; - wasmer_result_t::WASMER_OK } + #[allow(clippy::cast_ptr_alignment)] #[cfg(feature = "metering")] #[no_mangle] -pub unsafe extern "C" fn wasmer_instantiate_with_metering_and_import_object( +pub unsafe extern "C" fn wasmer_instantiate_with_metering( instance: *mut *mut wasmer_instance_t, wasm_bytes: *mut u8, wasm_bytes_len: u32, - external_import_object: *mut wasmer_import_object_t, gas_limit: u64, - opcode_costs_pointer: *mut u32, ) -> wasmer_result_t { if wasm_bytes.is_null() { update_last_error(CApiError { @@ -100,8 +49,6 @@ pub unsafe extern "C" fn wasmer_instantiate_with_metering_and_import_object( return wasmer_result_t::WASMER_ERROR; } - OPCODE_COSTS.copy_from_slice(slice::from_raw_parts(opcode_costs_pointer, OPCODE_COUNT)); - let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); let compiler = get_metered_compiler(gas_limit); let result_compilation = wasmer_runtime_core::compile_with(bytes, &compiler); @@ -113,7 +60,7 @@ pub unsafe extern "C" fn wasmer_instantiate_with_metering_and_import_object( } }; - let import_object: &mut ImportObject = &mut *(external_import_object as *mut ImportObject); + let import_object: &mut ImportObject = &mut *(GLOBAL_IMPORT_OBJECT as *mut ImportObject); let result_instantiation = new_module.instantiate(&import_object); let new_instance = match result_instantiation { Ok(instance) => instance, @@ -141,7 +88,6 @@ pub unsafe extern "C" fn wasmer_compile_with_gas_metering( wasm_bytes: *mut u8, wasm_bytes_len: u32, gas_limit: u64, - opcode_costs_pointer: *const u32, ) -> wasmer_result_t { if module.is_null() { update_last_error(CApiError { @@ -156,8 +102,6 @@ pub unsafe extern "C" fn wasmer_compile_with_gas_metering( return wasmer_result_t::WASMER_ERROR; } - OPCODE_COSTS.copy_from_slice(slice::from_raw_parts(opcode_costs_pointer, OPCODE_COUNT)); - let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); let compiler = get_metered_compiler(gas_limit); let result = wasmer_runtime_core::compile_with(bytes, &compiler); diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index ee99c171954f..d78ff85b5f1b 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -115,10 +115,6 @@ typedef struct { typedef struct { -} wasmer_import_object_t; - -typedef struct { - } wasmer_table_t; /** @@ -140,6 +136,10 @@ typedef struct { typedef struct { +} wasmer_import_object_t; + +typedef struct { + } wasmer_instance_t; typedef struct { @@ -195,8 +195,7 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, uint8_t *wasm_bytes, uint32_t wasm_bytes_len, - uint64_t gas_limit, - const uint32_t *opcode_costs_pointer); + uint64_t gas_limit); /** * Gets export descriptor kind @@ -458,6 +457,8 @@ wasmer_result_t wasmer_import_func_returns(const wasmer_import_func_t *func, wasmer_result_t wasmer_import_func_returns_arity(const wasmer_import_func_t *func, uint32_t *result); +wasmer_result_t wasmer_import_object_cache_from_imports(wasmer_import_t *imports, int imports_len); + /** * Frees memory of the given ImportObject */ @@ -476,10 +477,6 @@ wasmer_result_t wasmer_import_object_extend(wasmer_import_object_t *import_objec */ wasmer_import_object_t *wasmer_import_object_new(void); -wasmer_result_t wasmer_import_object_new_from_imports(wasmer_import_object_t **external_import_object, - wasmer_import_t *imports, - int imports_len); - /** * Calls an instances exported function by `name` with the provided parameters. * Results are set using the provided `results` pointer. @@ -552,17 +549,7 @@ wasmer_result_t wasmer_instantiate(wasmer_instance_t **instance, wasmer_result_t wasmer_instantiate_with_metering(wasmer_instance_t **instance, uint8_t *wasm_bytes, uint32_t wasm_bytes_len, - wasmer_import_t *imports, - int imports_len, - uint64_t gas_limit, - const uint32_t *opcode_costs_pointer); - -wasmer_result_t wasmer_instantiate_with_metering_and_import_object(wasmer_instance_t **instance, - uint8_t *wasm_bytes, - uint32_t wasm_bytes_len, - wasmer_import_object_t *external_import_object, - uint64_t gas_limit, - uint32_t *opcode_costs_pointer); + uint64_t gas_limit); /** * Gets the length in bytes of the last error. @@ -716,6 +703,8 @@ wasmer_result_t wasmer_serialized_module_from_bytes(wasmer_serialized_module_t * const uint8_t *serialized_module_bytes, uint32_t serialized_module_bytes_length); +void wasmer_set_opcode_costs(const uint32_t *opcode_costs_pointer); + /** * Frees memory for the given Table */ diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 9550af1d10b0..774a9e660042 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -99,10 +99,6 @@ struct wasmer_import_func_t { }; -struct wasmer_import_object_t { - -}; - struct wasmer_table_t { }; @@ -122,6 +118,10 @@ struct wasmer_import_t { wasmer_import_export_value value; }; +struct wasmer_import_object_t { + +}; + struct wasmer_instance_t { }; @@ -177,8 +177,7 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, uint8_t *wasm_bytes, uint32_t wasm_bytes_len, - uint64_t gas_limit, - const uint32_t *opcode_costs_pointer); + uint64_t gas_limit); /// Gets export descriptor kind wasmer_import_export_kind wasmer_export_descriptor_kind(wasmer_export_descriptor_t *export_); @@ -368,6 +367,8 @@ wasmer_result_t wasmer_import_func_returns(const wasmer_import_func_t *func, wasmer_result_t wasmer_import_func_returns_arity(const wasmer_import_func_t *func, uint32_t *result); +wasmer_result_t wasmer_import_object_cache_from_imports(wasmer_import_t *imports, int imports_len); + /// Frees memory of the given ImportObject void wasmer_import_object_destroy(wasmer_import_object_t *import_object); @@ -380,10 +381,6 @@ wasmer_result_t wasmer_import_object_extend(wasmer_import_object_t *import_objec /// See also `wasmer_import_object_append` wasmer_import_object_t *wasmer_import_object_new(); -wasmer_result_t wasmer_import_object_new_from_imports(wasmer_import_object_t **external_import_object, - wasmer_import_t *imports, - int imports_len); - /// Calls an instances exported function by `name` with the provided parameters. /// Results are set using the provided `results` pointer. /// @@ -440,17 +437,7 @@ wasmer_result_t wasmer_instantiate(wasmer_instance_t **instance, wasmer_result_t wasmer_instantiate_with_metering(wasmer_instance_t **instance, uint8_t *wasm_bytes, uint32_t wasm_bytes_len, - wasmer_import_t *imports, - int imports_len, - uint64_t gas_limit, - const uint32_t *opcode_costs_pointer); - -wasmer_result_t wasmer_instantiate_with_metering_and_import_object(wasmer_instance_t **instance, - uint8_t *wasm_bytes, - uint32_t wasm_bytes_len, - wasmer_import_object_t *external_import_object, - uint64_t gas_limit, - uint32_t *opcode_costs_pointer); + uint64_t gas_limit); /// Gets the length in bytes of the last error. /// This can be used to dynamically allocate a buffer with the correct number of @@ -572,6 +559,8 @@ wasmer_result_t wasmer_serialized_module_from_bytes(wasmer_serialized_module_t * const uint8_t *serialized_module_bytes, uint32_t serialized_module_bytes_length); +void wasmer_set_opcode_costs(const uint32_t *opcode_costs_pointer); + /// Frees memory for the given Table void wasmer_table_destroy(wasmer_table_t *table); From f7cf35d930f445ab161c3dc30822278e2e9293d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 22 Nov 2019 17:04:31 +0200 Subject: [PATCH 031/129] Add .ctags --- .ctags | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .ctags diff --git a/.ctags b/.ctags new file mode 100644 index 000000000000..334e97a35f95 --- /dev/null +++ b/.ctags @@ -0,0 +1,11 @@ +--exclude=target/* +--exclude=docs/* +--exclude=examples/* +--exclude=integration_tests/* +--exclude=fuzz/* +--exclude=*.md +--exclude=*.yml +--exclude=*.txt +--exclude=tags +--exclude=*.sh +--exclude=scripts/* From 6fa89e4d15817455ea9eb98244f88006d878477d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Mon, 2 Dec 2019 16:12:20 +0200 Subject: [PATCH 032/129] Update versions in lib/runtime-c-api/Cargo.toml --- lib/runtime-c-api/Cargo.toml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index 8a992421d97b..840d2309d36f 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -34,22 +34,22 @@ optional = true [dependencies.wasmer-middleware-common] path = "../middleware-common" -version = "0.8.0" +version = "0.11.0" optional = true [dependencies.wasmer-singlepass-backend] path = "../singlepass-backend" -version = "0.8.0" +version = "0.11.0" optional = true [dependencies.wasmer-llvm-backend] path = "../llvm-backend" -version = "0.8.0" +version = "0.11.0" optional = true [dependencies.wasmer-clif-backend] path = "../clif-backend" -version = "0.8.0" +version = "0.11.0" optional = true [features] @@ -58,6 +58,7 @@ debug = ["wasmer-runtime/debug"] cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift"] llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm"] singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass"] +metering = ["wasmer-middleware-common"] wasi = ["wasmer-wasi"] [build-dependencies] From 4cc0c22ab14567a0fc46abc363a345bd2fdea1d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Mon, 2 Dec 2019 17:05:29 +0200 Subject: [PATCH 033/129] Fix imports and other minor changes to make the merge function properly --- lib/clif-backend/src/lib.rs | 1 - lib/runtime-c-api/Cargo.toml | 6 +++--- lib/runtime-c-api/src/import/mod.rs | 3 +-- lib/runtime-c-api/wasmer.h | 4 ++++ lib/runtime-c-api/wasmer.hh | 4 ++++ lib/runtime/Cargo.toml | 13 +++++++++---- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/clif-backend/src/lib.rs b/lib/clif-backend/src/lib.rs index 743b314fb72d..e358df6052eb 100644 --- a/lib/clif-backend/src/lib.rs +++ b/lib/clif-backend/src/lib.rs @@ -4,7 +4,6 @@ #![deny( dead_code, - missing_docs, nonstandard_style, unused_imports, unused_mut, diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index 840d2309d36f..0dc84807c198 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -55,9 +55,9 @@ optional = true [features] default = ["singlepass-backend", "metering"] debug = ["wasmer-runtime/debug"] -cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift"] -llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm"] -singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass"] +cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift", "wasmer-clif-backend"] +llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm", "wasmer-llvm-backend"] +singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass", "wasmer-singlepass-backend"] metering = ["wasmer-middleware-common"] wasi = ["wasmer-wasi"] diff --git a/lib/runtime-c-api/src/import/mod.rs b/lib/runtime-c-api/src/import/mod.rs index 61875250423a..f92d746d6c32 100644 --- a/lib/runtime-c-api/src/import/mod.rs +++ b/lib/runtime-c-api/src/import/mod.rs @@ -9,9 +9,8 @@ use crate::{ wasmer_byte_array, wasmer_result_t, }; use libc::{c_int, c_uint}; -use std::{ffi::c_void, ptr, slice, sync::Arc}; +use std::{ffi::c_void, ptr, slice, sync::Arc, convert::TryFrom}; use std::result::Result; -use std::{convert::TryFrom, ffi::c_void, ptr, slice, sync::Arc}; use wasmer_runtime::{Global, Memory, Module, Table}; use wasmer_runtime_core::{ diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index d7a5e95b689b..95c1168ccf7f 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -155,6 +155,10 @@ typedef struct { typedef struct { +} wasmer_import_object_t; + +typedef struct { + } wasmer_import_object_iter_t; typedef struct { diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 299e741220aa..b4d319a6c0e3 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -137,6 +137,10 @@ struct wasmer_import_t { wasmer_import_export_value value; }; +struct wasmer_import_object_t { + +}; + struct wasmer_import_object_iter_t { }; diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index 107252bfea76..f9c825b03252 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -11,7 +11,6 @@ edition = "2018" readme = "README.md" [dependencies] -wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.11.0", optional = true } lazy_static = "1.4" memmap = "0.7" @@ -24,14 +23,20 @@ path = "../clif-backend" version = "0.11.0" optional = true +[dependencies.wasmer-llvm-backend] +path = "../llvm-backend" +optional = true + +[dependencies.wasmer-singlepass-backend] +path = "../singlepass-backend" +version = "0.11.0" +optional = true + [dev-dependencies] tempfile = "3.1" criterion = "0.2" wabt = "0.9.1" -[dependencies.wasmer-llvm-backend] -path = "../llvm-backend" -optional = true [features] default = ["singlepass", "default-backend-singlepass"] From a2dca094ffca07d763c93130528e627919001d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 3 Dec 2019 15:18:53 +0200 Subject: [PATCH 034/129] Fix feature configuration --- Makefile | 2 +- lib/runtime-c-api/Cargo.toml | 2 +- lib/runtime/src/lib.rs | 9 ++++++--- lib/singlepass-backend/Cargo.toml | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 4acde792584a..b560c84a7175 100644 --- a/Makefile +++ b/Makefile @@ -103,7 +103,7 @@ llvm: spectests-llvm emtests-llvm wasitests-llvm # All tests capi: - cargo build --release --features backend-cranelift + cargo build --release --features backend-singlepass cargo build -p wasmer-runtime-c-api --release test-capi: capi diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index 0dc84807c198..49b279ed0f66 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -53,7 +53,7 @@ version = "0.11.0" optional = true [features] -default = ["singlepass-backend", "metering"] +default = ["singlepass-backend", "metering", "wasmer-runtime/deterministic-execution"] debug = ["wasmer-runtime/debug"] cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift", "wasmer-clif-backend"] llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm", "wasmer-llvm-backend"] diff --git a/lib/runtime/src/lib.rs b/lib/runtime/src/lib.rs index e9b861f6316b..48bf98db0356 100644 --- a/lib/runtime/src/lib.rs +++ b/lib/runtime/src/lib.rs @@ -212,7 +212,6 @@ pub fn default_compiler() -> impl Compiler { any( feature = "default-backend-cranelift", feature = "default-backend-singlepass", - feature = "deterministic-execution" ) ), all( @@ -220,12 +219,16 @@ pub fn default_compiler() -> impl Compiler { feature = "default-backend-cranelift", any( feature = "default-backend-singlepass", - feature = "deterministic-execution" + feature = "default-backend-llvm", ) ), all( feature = "default-backend-singlepass", - feature = "deterministic-execution" + not(feature = "docs"), + any( + feature = "default-backend-cranelift", + feature = "default-backend-llvm", + ) ) ))] compile_error!( diff --git a/lib/singlepass-backend/Cargo.toml b/lib/singlepass-backend/Cargo.toml index b02ac2ec8db1..788f12efec6c 100644 --- a/lib/singlepass-backend/Cargo.toml +++ b/lib/singlepass-backend/Cargo.toml @@ -19,6 +19,7 @@ byteorder = "1.3" nix = "0.15" libc = "0.2.60" smallvec = "0.6" +wasmparser = "0.39.1" [features] default = [] From d450170d053165f8c2c0953f78cc2fab07dd2d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 4 Dec 2019 12:22:22 +0200 Subject: [PATCH 035/129] Disable the Cranelift backend from Cargo.toml files --- Cargo.toml | 18 +++++++++--------- lib/emscripten-tests/Cargo.toml | 4 ++-- lib/middleware-common-tests/Cargo.toml | 4 ++-- lib/runtime-c-api/Cargo.toml | 10 +++++----- lib/runtime-core-tests/Cargo.toml | 6 +++--- lib/runtime-core/Cargo.toml | 2 +- lib/runtime/Cargo.toml | 17 +++++++++-------- lib/spectests/Cargo.toml | 4 ++-- lib/wasi-tests/Cargo.toml | 4 ++-- 9 files changed, 35 insertions(+), 34 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9515d0b39ad7..cd439bbfba3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ byteorder = "1.3" errno = "0.2" structopt = "0.3" wabt = "0.9.1" -wasmer-clif-backend = { path = "lib/clif-backend", optional = true } +# wasmer-clif-backend = { path = "lib/clif-backend", optional = true } wasmer-singlepass-backend = { path = "lib/singlepass-backend", optional = true } wasmer-middleware-common = { path = "lib/middleware-common" } wasmer-runtime = { path = "lib/runtime" } @@ -40,7 +40,7 @@ wasmer-emscripten-tests = { path = "lib/emscripten-tests", optional = true } [workspace] members = [ - "lib/clif-backend", + # "lib/clif-backend", "lib/singlepass-backend", "lib/runtime", "lib/runtime-core", @@ -79,15 +79,15 @@ default = ["fast-tests", "wasi", "backend-singlepass"] debug = ["wasmer-runtime-core/debug"] trace = ["wasmer-runtime-core/trace"] docs = ["wasmer-runtime/docs"] -extra-debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] +# extra-debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] # This feature will allow cargo test to run much faster fast-tests = [] -backend-cranelift = [ - "wasmer-clif-backend", - "wasmer-runtime-core/backend-cranelift", - "wasmer-runtime/cranelift", - "wasmer-middleware-common-tests/clif", -] +# backend-cranelift = [ +# "wasmer-clif-backend", +# "wasmer-runtime-core/backend-cranelift", +# "wasmer-runtime/cranelift", +# "wasmer-middleware-common-tests/clif", +# ] backend-llvm = [ "wasmer-llvm-backend", "wasmer-runtime-core/backend-llvm", diff --git a/lib/emscripten-tests/Cargo.toml b/lib/emscripten-tests/Cargo.toml index 2439b4295784..91619d344355 100644 --- a/lib/emscripten-tests/Cargo.toml +++ b/lib/emscripten-tests/Cargo.toml @@ -11,7 +11,7 @@ build = "build/mod.rs" [dependencies] wasmer-emscripten = { path = "../emscripten", version = "0.11.0" } wasmer-runtime = { path = "../runtime", version = "0.11.0", default-features = false } -wasmer-clif-backend = { path = "../clif-backend", version = "0.11.0", optional = true} +# wasmer-clif-backend = { path = "../clif-backend", version = "0.11.0", optional = true} wasmer-llvm-backend = { path = "../llvm-backend", version = "0.11.0", optional = true, features = ["test"] } wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.11.0", optional = true } @@ -23,6 +23,6 @@ wasmer-dev-utils = { path = "../dev-utils", version = "0.11.0"} glob = "0.3" [features] -clif = ["wasmer-clif-backend", "wasmer-runtime/default-backend-cranelift"] +# clif = ["wasmer-clif-backend", "wasmer-runtime/default-backend-cranelift"] singlepass = ["wasmer-singlepass-backend", "wasmer-runtime/default-backend-singlepass"] llvm = ["wasmer-llvm-backend", "wasmer-runtime/default-backend-llvm"] diff --git a/lib/middleware-common-tests/Cargo.toml b/lib/middleware-common-tests/Cargo.toml index 929cce5fe11c..7a73885daa3e 100644 --- a/lib/middleware-common-tests/Cargo.toml +++ b/lib/middleware-common-tests/Cargo.toml @@ -10,12 +10,12 @@ publish = false [dependencies] wasmer-runtime-core = { path = "../runtime-core", version = "0.11.0" } wasmer-middleware-common = { path = "../middleware-common", version = "0.11.0" } -wasmer-clif-backend = { path = "../clif-backend", version = "0.11.0" } +# wasmer-clif-backend = { path = "../clif-backend", version = "0.11.0" } wasmer-llvm-backend = { path = "../llvm-backend", version = "0.11.0", features = ["test"], optional = true } wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.11.0", optional = true } [features] -clif = [] +# clif = [] llvm = ["wasmer-llvm-backend"] singlepass = ["wasmer-singlepass-backend"] diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index 49b279ed0f66..4a34e8116b99 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -47,15 +47,15 @@ path = "../llvm-backend" version = "0.11.0" optional = true -[dependencies.wasmer-clif-backend] -path = "../clif-backend" -version = "0.11.0" -optional = true +# [dependencies.wasmer-clif-backend] +# path = "../clif-backend" +# version = "0.11.0" +# optional = true [features] default = ["singlepass-backend", "metering", "wasmer-runtime/deterministic-execution"] debug = ["wasmer-runtime/debug"] -cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift", "wasmer-clif-backend"] +# cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift", "wasmer-clif-backend"] llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm", "wasmer-llvm-backend"] singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass", "wasmer-singlepass-backend"] metering = ["wasmer-middleware-common"] diff --git a/lib/runtime-core-tests/Cargo.toml b/lib/runtime-core-tests/Cargo.toml index 57e9e19f9cb8..1d745a574299 100644 --- a/lib/runtime-core-tests/Cargo.toml +++ b/lib/runtime-core-tests/Cargo.toml @@ -10,12 +10,12 @@ publish = false [dependencies] wabt = "0.9.1" wasmer-runtime-core = { path = "../runtime-core", version = "0.11.0" } -wasmer-clif-backend = { path = "../clif-backend", version = "0.11.0", optional = true } +# wasmer-clif-backend = { path = "../clif-backend", version = "0.11.0", optional = true } wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.11.0", optional = true } wasmer-llvm-backend = { path = "../llvm-backend", version = "0.11.0", features = ["test"], optional = true } [features] -default = ["backend-cranelift"] -backend-cranelift = ["wasmer-clif-backend"] +default = ["backend-singlepass"] +# backend-cranelift = ["wasmer-clif-backend"] backend-singlepass = ["wasmer-singlepass-backend"] backend-llvm = ["wasmer-llvm-backend"] diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index ab7c7af1ff79..796b3616c917 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -53,7 +53,7 @@ cc = "1.0" debug = [] trace = ["debug"] # backend flags used in conditional compilation of Backend::variants -"backend-cranelift" = [] +# "backend-cranelift" = [] "backend-singlepass" = [] "backend-llvm" = [] managed = [] diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index c7825b5886c1..9fd20d03efc4 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -18,10 +18,10 @@ memmap = "0.7" path = "../runtime-core" version = "0.11.0" -[dependencies.wasmer-clif-backend] -path = "../clif-backend" -version = "0.11.0" -optional = true +# [dependencies.wasmer-clif-backend] +# path = "../clif-backend" +# version = "0.11.0" +# optional = true [dependencies.wasmer-llvm-backend] path = "../llvm-backend" @@ -41,14 +41,15 @@ wabt = "0.9.1" [features] default = ["singlepass", "default-backend-singlepass"] docs = [] -cranelift = ["wasmer-clif-backend"] -cache = ["cranelift"] -debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] +# cranelift = ["wasmer-clif-backend"] +# cache = ["cranelift"] +# debug = ["wasmer-clif-backend/debug", "wasmer-runtime-core/debug"] +debug = ["wasmer-runtime-core/debug"] llvm = ["wasmer-llvm-backend"] singlepass = ["wasmer-singlepass-backend"] default-backend-singlepass = ["singlepass"] default-backend-llvm = ["llvm"] -default-backend-cranelift = ["cranelift"] +# default-backend-cranelift = ["cranelift"] deterministic-execution = ["wasmer-singlepass-backend/deterministic-execution", "wasmer-runtime-core/deterministic-execution"] [[bench]] diff --git a/lib/spectests/Cargo.toml b/lib/spectests/Cargo.toml index 1338b3b230a9..01f5d2fca821 100644 --- a/lib/spectests/Cargo.toml +++ b/lib/spectests/Cargo.toml @@ -10,7 +10,7 @@ edition = "2018" [dependencies] glob = "0.3" wasmer-runtime = { path = "../runtime", version = "0.11.0", default-features = false} -wasmer-clif-backend = { path = "../clif-backend", version = "0.11.0", optional = true} +# wasmer-clif-backend = { path = "../clif-backend", version = "0.11.0", optional = true} wasmer-llvm-backend = { path = "../llvm-backend", version = "0.11.0", features = ["test"], optional = true } wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.11.0", optional = true } @@ -23,6 +23,6 @@ wabt = "0.9.1" [features] default = ["fast-tests"] fast-tests = [] -clif = ["wasmer-clif-backend", "wasmer-runtime/default-backend-cranelift"] +# clif = ["wasmer-clif-backend", "wasmer-runtime/default-backend-cranelift"] singlepass = ["wasmer-singlepass-backend", "wasmer-runtime/default-backend-singlepass"] llvm = ["wasmer-llvm-backend", "wasmer-runtime/default-backend-llvm"] diff --git a/lib/wasi-tests/Cargo.toml b/lib/wasi-tests/Cargo.toml index 9b84e5ea91e6..d067164edf69 100644 --- a/lib/wasi-tests/Cargo.toml +++ b/lib/wasi-tests/Cargo.toml @@ -13,7 +13,7 @@ build = "build/mod.rs" wasmer-runtime = { path = "../runtime", version = "0.11.0", default-features = false } wasmer-wasi = { path = "../wasi", version = "0.11.0" } # hack to get tests to work -wasmer-clif-backend = { path = "../clif-backend", version = "0.11.0", optional = true} +# wasmer-clif-backend = { path = "../clif-backend", version = "0.11.0", optional = true} wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.11.0", optional = true } wasmer-llvm-backend = { path = "../llvm-backend", version = "0.11.0", features = ["test"], optional = true } @@ -24,6 +24,6 @@ glob = "0.3" wasmer-dev-utils = { path = "../dev-utils", version = "0.11.0"} [features] -clif = ["wasmer-clif-backend", "wasmer-runtime/default-backend-cranelift"] +# clif = ["wasmer-clif-backend", "wasmer-runtime/default-backend-cranelift"] singlepass = ["wasmer-singlepass-backend", "wasmer-runtime/default-backend-singlepass"] llvm = ["wasmer-llvm-backend", "wasmer-runtime/default-backend-llvm"] From 3a84b9a8dacf501cd5ba8194a874ac194cc84992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 4 Dec 2019 12:23:46 +0200 Subject: [PATCH 036/129] Enable Wasmparser deterministic execution, fix it in Wasmer and use a fixed fork of Wasmparser --- Cargo.toml | 1 + Makefile | 2 +- lib/clif-backend/Cargo.toml | 2 +- lib/llvm-backend/Cargo.toml | 2 +- lib/runtime-c-api/Cargo.toml | 2 +- lib/runtime-core/Cargo.toml | 2 +- lib/runtime-core/src/codegen.rs | 2 +- lib/singlepass-backend/Cargo.toml | 4 ++-- 8 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cd439bbfba3c..64f2932e4d22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -96,6 +96,7 @@ backend-llvm = [ ] backend-singlepass = [ "wasmer-singlepass-backend", + "wasmer-singlepass-backend/deterministic-execution", "wasmer-runtime-core/backend-singlepass", "wasmer-runtime/singlepass", "wasmer-middleware-common-tests/singlepass", diff --git a/Makefile b/Makefile index b560c84a7175..194d1712532d 100644 --- a/Makefile +++ b/Makefile @@ -104,7 +104,7 @@ llvm: spectests-llvm emtests-llvm wasitests-llvm # All tests capi: cargo build --release --features backend-singlepass - cargo build -p wasmer-runtime-c-api --release + cargo build -p wasmer-runtime-c-api --release --features backend-singlepass test-capi: capi cargo test -p wasmer-runtime-c-api --release diff --git a/lib/clif-backend/Cargo.toml b/lib/clif-backend/Cargo.toml index 87e188936ed6..f120bdc7bb2d 100644 --- a/lib/clif-backend/Cargo.toml +++ b/lib/clif-backend/Cargo.toml @@ -18,7 +18,7 @@ cranelift-entity = "0.44.0" cranelift-frontend = { package = "wasmer-clif-fork-frontend", version = "0.44.0" } cranelift-wasm = { package = "wasmer-clif-fork-wasm", version = "0.44.0" } target-lexicon = "0.8.1" -wasmparser = "0.39.1" +wasmparser = { git = "https://github.com/ElrondNetwork/wasmparser.rs" } byteorder = "1.3.2" nix = "0.15.0" libc = "0.2.60" diff --git a/lib/llvm-backend/Cargo.toml b/lib/llvm-backend/Cargo.toml index b9fa7e6a720e..beff2419417c 100644 --- a/lib/llvm-backend/Cargo.toml +++ b/lib/llvm-backend/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" [dependencies] wasmer-runtime-core = { path = "../runtime-core", version = "0.11.0" } -wasmparser = "0.39.1" +wasmparser = { git = "https://github.com/ElrondNetwork/wasmparser.rs" } smallvec = "0.6" goblin = "0.0.24" libc = "0.2.60" diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index 4a34e8116b99..da1eebb5e294 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -57,7 +57,7 @@ default = ["singlepass-backend", "metering", "wasmer-runtime/deterministic-execu debug = ["wasmer-runtime/debug"] # cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift", "wasmer-clif-backend"] llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm", "wasmer-llvm-backend"] -singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass", "wasmer-singlepass-backend"] +singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass", "wasmer-singlepass-backend", "wasmer-singlepass-backend/deterministic-execution"] metering = ["wasmer-middleware-common"] wasi = ["wasmer-wasi"] diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index 796b3616c917..a74adb50d099 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -12,7 +12,7 @@ edition = "2018" [dependencies] nix = "0.15" page_size = "0.4" -wasmparser = "0.39.1" +wasmparser = { git = "https://github.com/ElrondNetwork/wasmparser.rs" } parking_lot = "0.9" lazy_static = "1.4" errno = "0.2" diff --git a/lib/runtime-core/src/codegen.rs b/lib/runtime-core/src/codegen.rs index a3ed432e846e..f67ca095371b 100644 --- a/lib/runtime-core/src/codegen.rs +++ b/lib/runtime-core/src/codegen.rs @@ -267,7 +267,7 @@ fn requires_pre_validation(backend: Backend) -> bool { match backend { Backend::Cranelift => true, Backend::LLVM => true, - Backend::Singlepass => false, + Backend::Singlepass => true, Backend::Auto => false, } } diff --git a/lib/singlepass-backend/Cargo.toml b/lib/singlepass-backend/Cargo.toml index 788f12efec6c..8c2838b4acb3 100644 --- a/lib/singlepass-backend/Cargo.toml +++ b/lib/singlepass-backend/Cargo.toml @@ -19,8 +19,8 @@ byteorder = "1.3" nix = "0.15" libc = "0.2.60" smallvec = "0.6" -wasmparser = "0.39.1" +wasmparser = { git = "https://github.com/ElrondNetwork/wasmparser.rs" } [features] -default = [] +default = ["deterministic-execution"] deterministic-execution = ["wasmparser/deterministic", "wasmer-runtime-core/deterministic-execution"] From cf447d39854045aa41218467643d7b13ac6e48ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 4 Dec 2019 12:23:58 +0200 Subject: [PATCH 037/129] Update .ctags --- .ctags | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.ctags b/.ctags index 334e97a35f95..3c63175a86ba 100644 --- a/.ctags +++ b/.ctags @@ -1,4 +1,5 @@ --exclude=target/* +--exclude=*/target/* --exclude=docs/* --exclude=examples/* --exclude=integration_tests/* @@ -9,3 +10,4 @@ --exclude=tags --exclude=*.sh --exclude=scripts/* +--exclude=Makefile From 53bdbd3cbed3495dbea22a36ad50a2ecd11b4d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Thu, 5 Dec 2019 15:30:24 +0200 Subject: [PATCH 038/129] Implement runtime breakpoints and C API for setting them --- lib/middleware-common/src/lib.rs | 2 + .../src/runtime_breakpoints.rs | 61 +++++++++++++++++++ lib/runtime-c-api/Cargo.toml | 3 +- lib/runtime-c-api/src/lib.rs | 2 + lib/runtime-c-api/src/runtime_breakpoints.rs | 13 ++++ lib/runtime-c-api/wasmer.h | 2 + lib/runtime-c-api/wasmer.hh | 2 + 7 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 lib/middleware-common/src/runtime_breakpoints.rs create mode 100644 lib/runtime-c-api/src/runtime_breakpoints.rs diff --git a/lib/middleware-common/src/lib.rs b/lib/middleware-common/src/lib.rs index 2bb995dd320c..a2b0a9c96fec 100644 --- a/lib/middleware-common/src/lib.rs +++ b/lib/middleware-common/src/lib.rs @@ -16,3 +16,5 @@ pub mod call_trace; pub mod metering; pub mod metering_costs; + +pub mod runtime_breakpoints; diff --git a/lib/middleware-common/src/runtime_breakpoints.rs b/lib/middleware-common/src/runtime_breakpoints.rs new file mode 100644 index 000000000000..0d7e19d91616 --- /dev/null +++ b/lib/middleware-common/src/runtime_breakpoints.rs @@ -0,0 +1,61 @@ +use wasmer_runtime_core::{ + codegen::{Event, EventSink, FunctionMiddleware, InternalEvent}, + module::ModuleInfo, + vm::{InternalField}, + wasmparser::{Operator, Type as WpType, TypeOrFuncType as WpTypeOrFuncType}, + Instance, +}; + +static RUNTIME_BREAKPOINT_VALUE: InternalField = InternalField::allocate(); + +#[derive(Copy, Clone, Debug)] +pub struct RuntimeBreakpointReachedError; + + +pub struct RuntimeBreakpointHandler {} + +impl RuntimeBreakpointHandler { + pub fn new() -> RuntimeBreakpointHandler { + RuntimeBreakpointHandler {} + } +} + +impl FunctionMiddleware for RuntimeBreakpointHandler { + type Error = String; + fn feed_event<'a, 'b: 'a>( + &mut self, + op: Event<'a, 'b>, + _module_info: &ModuleInfo, + sink: &mut EventSink<'a, 'b>, + ) -> Result<(), Self::Error> { + match op { + Event::Wasm(&ref op) | Event::WasmOwned(ref op) => { + match *op { + Operator::Call { .. } + | Operator::CallIndirect { .. } => { + sink.push(Event::Internal(InternalEvent::GetInternal( + RUNTIME_BREAKPOINT_VALUE.index() as _, + ))); + sink.push(Event::WasmOwned(Operator::I32Eqz)); + sink.push(Event::WasmOwned(Operator::If { + ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), + })); + sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(|_| { + Err(Box::new(RuntimeBreakpointReachedError)) + })))); + sink.push(Event::WasmOwned(Operator::End)); + } + _ => {} + } + } + _ => {} + } + sink.push(op); + Ok(()) + } +} + + +pub fn set_runtime_breakpoint_value(instance: &mut Instance, value: u64) { + instance.set_internal(&RUNTIME_BREAKPOINT_VALUE, value); +} diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index da1eebb5e294..66c5a39fb38d 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -53,12 +53,13 @@ optional = true # optional = true [features] -default = ["singlepass-backend", "metering", "wasmer-runtime/deterministic-execution"] +default = ["singlepass-backend", "metering", "runtime-breakpoints", "wasmer-runtime/deterministic-execution"] debug = ["wasmer-runtime/debug"] # cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift", "wasmer-clif-backend"] llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm", "wasmer-llvm-backend"] singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass", "wasmer-singlepass-backend", "wasmer-singlepass-backend/deterministic-execution"] metering = ["wasmer-middleware-common"] +runtime-breakpoints = ["wasmer-middleware-common"] wasi = ["wasmer-wasi"] [build-dependencies] diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index da36735cf47b..12b37c831fd7 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -101,6 +101,8 @@ pub mod instance; pub mod memory; #[cfg(feature = "metering")] pub mod metering; +#[cfg(feature = "runtime-breakpoints")] +pub mod runtime_breakpoints; pub mod module; pub mod table; // `not(target_family = "windows")` is simpler than `unix`. See build.rs diff --git a/lib/runtime-c-api/src/runtime_breakpoints.rs b/lib/runtime-c-api/src/runtime_breakpoints.rs new file mode 100644 index 000000000000..ece845f9402c --- /dev/null +++ b/lib/runtime-c-api/src/runtime_breakpoints.rs @@ -0,0 +1,13 @@ +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +#[cfg(feature = "runtime_breakpoints")] +pub unsafe extern "C" fn wasmer_instance_set_runtime_breakpoint_value( + instance: *mut wasmer_instance_t, + value: u64, +) { + if instance.is_null() { + return; + } + let instance = &mut *(instance as *mut wasmer_runtime::Instance); + runtime_breakpoints::set_runtime_breakpoint_value(instance, value); +} diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 95c1168ccf7f..00fd658b5459 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -627,6 +627,8 @@ uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); void wasmer_instance_set_points_used(wasmer_instance_t *instance, uint64_t new_gas); +void wasmer_instance_set_runtime_breakpoint_value(wasmer_instance_t *instance, uint64_t value); + /** * Creates a new Instance from the given wasm bytes and imports. * diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index b4d319a6c0e3..431b1db334e7 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -499,6 +499,8 @@ uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); void wasmer_instance_set_points_used(wasmer_instance_t *instance, uint64_t new_gas); +void wasmer_instance_set_runtime_breakpoint_value(wasmer_instance_t *instance, uint64_t value); + /// Creates a new Instance from the given wasm bytes and imports. /// /// Returns `wasmer_result_t::WASMER_OK` upon success. From c856f4041122b77b5dc5ec8f6124190897b8469d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Thu, 5 Dec 2019 17:50:48 +0200 Subject: [PATCH 039/129] Enable runtime-breakpoints --- Makefile | 3 +-- lib/middleware-common/src/runtime_breakpoints.rs | 1 + lib/runtime-c-api/src/lib.rs | 4 +++- lib/runtime-c-api/src/runtime_breakpoints.rs | 7 +++++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 194d1712532d..2bb3facb0dc6 100644 --- a/Makefile +++ b/Makefile @@ -103,8 +103,7 @@ llvm: spectests-llvm emtests-llvm wasitests-llvm # All tests capi: - cargo build --release --features backend-singlepass - cargo build -p wasmer-runtime-c-api --release --features backend-singlepass + cargo build -p wasmer-runtime-c-api --release test-capi: capi cargo test -p wasmer-runtime-c-api --release diff --git a/lib/middleware-common/src/runtime_breakpoints.rs b/lib/middleware-common/src/runtime_breakpoints.rs index 0d7e19d91616..b64fdee89eea 100644 --- a/lib/middleware-common/src/runtime_breakpoints.rs +++ b/lib/middleware-common/src/runtime_breakpoints.rs @@ -57,5 +57,6 @@ impl FunctionMiddleware for RuntimeBreakpointHandler { pub fn set_runtime_breakpoint_value(instance: &mut Instance, value: u64) { + println!("Runtime breakpoint value set to {}", value); instance.set_internal(&RUNTIME_BREAKPOINT_VALUE, value); } diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index 12b37c831fd7..7770a871e315 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -99,10 +99,12 @@ pub mod global; pub mod import; pub mod instance; pub mod memory; + #[cfg(feature = "metering")] pub mod metering; -#[cfg(feature = "runtime-breakpoints")] + pub mod runtime_breakpoints; + pub mod module; pub mod table; // `not(target_family = "windows")` is simpler than `unix`. See build.rs diff --git a/lib/runtime-c-api/src/runtime_breakpoints.rs b/lib/runtime-c-api/src/runtime_breakpoints.rs index ece845f9402c..9e3ec08d347d 100644 --- a/lib/runtime-c-api/src/runtime_breakpoints.rs +++ b/lib/runtime-c-api/src/runtime_breakpoints.rs @@ -1,6 +1,9 @@ +use crate::instance::wasmer_instance_t; + +use wasmer_middleware_common::runtime_breakpoints::set_runtime_breakpoint_value; + #[allow(clippy::cast_ptr_alignment)] #[no_mangle] -#[cfg(feature = "runtime_breakpoints")] pub unsafe extern "C" fn wasmer_instance_set_runtime_breakpoint_value( instance: *mut wasmer_instance_t, value: u64, @@ -9,5 +12,5 @@ pub unsafe extern "C" fn wasmer_instance_set_runtime_breakpoint_value( return; } let instance = &mut *(instance as *mut wasmer_runtime::Instance); - runtime_breakpoints::set_runtime_breakpoint_value(instance, value); + set_runtime_breakpoint_value(instance, value); } From e710fdc2358c85c66316e82dd8513f0ef83a9792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 6 Dec 2019 16:51:32 +0200 Subject: [PATCH 040/129] Fix breakpoint injection --- .../src/runtime_breakpoints.rs | 45 ++++++++++++------- lib/runtime-c-api/src/metering.rs | 4 ++ lib/runtime-c-api/src/runtime_breakpoints.rs | 19 +++++++- lib/runtime-c-api/wasmer.h | 2 + lib/runtime-c-api/wasmer.hh | 2 + 5 files changed, 56 insertions(+), 16 deletions(-) diff --git a/lib/middleware-common/src/runtime_breakpoints.rs b/lib/middleware-common/src/runtime_breakpoints.rs index b64fdee89eea..28c91320a4eb 100644 --- a/lib/middleware-common/src/runtime_breakpoints.rs +++ b/lib/middleware-common/src/runtime_breakpoints.rs @@ -7,6 +7,7 @@ use wasmer_runtime_core::{ }; static RUNTIME_BREAKPOINT_VALUE: InternalField = InternalField::allocate(); +pub const BREAKPOINT_VALUE__NO_BREAKPOINT: u64 = 0; #[derive(Copy, Clone, Debug)] pub struct RuntimeBreakpointReachedError; @@ -28,29 +29,39 @@ impl FunctionMiddleware for RuntimeBreakpointHandler { _module_info: &ModuleInfo, sink: &mut EventSink<'a, 'b>, ) -> Result<(), Self::Error> { - match op { + + let must_add_breakpoint = match op { Event::Wasm(&ref op) | Event::WasmOwned(ref op) => { match *op { Operator::Call { .. } | Operator::CallIndirect { .. } => { - sink.push(Event::Internal(InternalEvent::GetInternal( - RUNTIME_BREAKPOINT_VALUE.index() as _, - ))); - sink.push(Event::WasmOwned(Operator::I32Eqz)); - sink.push(Event::WasmOwned(Operator::If { - ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), - })); - sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(|_| { - Err(Box::new(RuntimeBreakpointReachedError)) - })))); - sink.push(Event::WasmOwned(Operator::End)); + true } - _ => {} + _ => false } } - _ => {} - } + _ => false + }; + sink.push(op); + + if must_add_breakpoint { + sink.push(Event::Internal(InternalEvent::GetInternal( + RUNTIME_BREAKPOINT_VALUE.index() as _, + ))); + sink.push(Event::WasmOwned(Operator::I64Const { + value: BREAKPOINT_VALUE__NO_BREAKPOINT as i64, + })); + sink.push(Event::WasmOwned(Operator::I64Ne)); + sink.push(Event::WasmOwned(Operator::If { + ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), + })); + sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(|_| { + Err(Box::new(RuntimeBreakpointReachedError)) + })))); + sink.push(Event::WasmOwned(Operator::End)); + } + Ok(()) } } @@ -60,3 +71,7 @@ pub fn set_runtime_breakpoint_value(instance: &mut Instance, value: u64) { println!("Runtime breakpoint value set to {}", value); instance.set_internal(&RUNTIME_BREAKPOINT_VALUE, value); } + +pub fn get_runtime_breakpoint_value(instance: &mut Instance) -> u64 { + instance.get_internal(&RUNTIME_BREAKPOINT_VALUE) +} diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index dd0d37065372..6960cb459ca4 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -131,10 +131,14 @@ unsafe fn get_metered_compiler(limit: u64) -> impl Compiler { #[cfg(feature = "cranelift-backend")] use wasmer_clif_backend::CraneliftModuleCodeGenerator as MeteredMCG; + use wasmer_middleware_common::runtime_breakpoints; + let c: StreamingCompiler = StreamingCompiler::new(move || { let mut chain = MiddlewareChain::new(); chain.push(metering::Metering::new(limit, &OPCODE_COSTS)); + chain.push(runtime_breakpoints::RuntimeBreakpointHandler::new()); + chain }); c diff --git a/lib/runtime-c-api/src/runtime_breakpoints.rs b/lib/runtime-c-api/src/runtime_breakpoints.rs index 9e3ec08d347d..d91ae6764650 100644 --- a/lib/runtime-c-api/src/runtime_breakpoints.rs +++ b/lib/runtime-c-api/src/runtime_breakpoints.rs @@ -1,6 +1,10 @@ use crate::instance::wasmer_instance_t; -use wasmer_middleware_common::runtime_breakpoints::set_runtime_breakpoint_value; +use wasmer_middleware_common::runtime_breakpoints::{ + set_runtime_breakpoint_value, + get_runtime_breakpoint_value, + BREAKPOINT_VALUE__NO_BREAKPOINT +}; #[allow(clippy::cast_ptr_alignment)] #[no_mangle] @@ -14,3 +18,16 @@ pub unsafe extern "C" fn wasmer_instance_set_runtime_breakpoint_value( let instance = &mut *(instance as *mut wasmer_runtime::Instance); set_runtime_breakpoint_value(instance, value); } + +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_instance_get_runtime_breakpoint_value( + instance: *mut wasmer_instance_t, +) -> u64 { + if instance.is_null() { + return BREAKPOINT_VALUE__NO_BREAKPOINT; + } + let instance = &mut *(instance as *mut wasmer_runtime::Instance); + + get_runtime_breakpoint_value(instance) +} diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 00fd658b5459..f14036056e8a 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -625,6 +625,8 @@ void wasmer_instance_exports(wasmer_instance_t *instance, wasmer_exports_t **exp uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); +uint64_t wasmer_instance_get_runtime_breakpoint_value(wasmer_instance_t *instance); + void wasmer_instance_set_points_used(wasmer_instance_t *instance, uint64_t new_gas); void wasmer_instance_set_runtime_breakpoint_value(wasmer_instance_t *instance, uint64_t value); diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 431b1db334e7..b0080dcf1c0e 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -497,6 +497,8 @@ void wasmer_instance_exports(wasmer_instance_t *instance, wasmer_exports_t **exp uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); +uint64_t wasmer_instance_get_runtime_breakpoint_value(wasmer_instance_t *instance); + void wasmer_instance_set_points_used(wasmer_instance_t *instance, uint64_t new_gas); void wasmer_instance_set_runtime_breakpoint_value(wasmer_instance_t *instance, uint64_t value); From cdd16626b6191abb97db5867b625e886fced4e84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 17 Dec 2019 18:08:50 +0200 Subject: [PATCH 041/129] Add 'dev' profile for runtime-c-api and a build target in the Makefile --- Cargo.toml | 32 +++++++++++++++++++++++++------- Makefile | 3 +++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 64f2932e4d22..22ca093c0070 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -104,10 +104,28 @@ backend-singlepass = [ wasi = ["wasmer-wasi"] managed = ["backend-singlepass", "wasmer-runtime-core/managed"] -[[example]] -name = "plugin" -crate-type = ["bin"] - -[[example]] -name = "callback" -crate-type = ["bin"] +[profile.dev] +opt-level = 0 # controls the `--opt-level` the compiler builds with. + # 0-1 is good for debugging. 2 is well-optimized. Max is 3. + # 's' attempts to reduce size, 'z' reduces size even more. +debug = true # (u32 or bool) Include debug information (debug symbols). + # Equivalent to `-C debuginfo=2` compiler flag. +rpath = false # controls whether compiler should set loader paths. + # If true, passes `-C rpath` flag to the compiler. +lto = false # Link Time Optimization usually reduces size of binaries + # and static libraries. Increases compilation time. + # If true, passes `-C lto` flag to the compiler, and if a + # string is specified like 'thin' then `-C lto=thin` will + # be passed. +debug-assertions = true # controls whether debug assertions are enabled + # (e.g., debug_assert!() and arithmetic overflow checks) +codegen-units = 16 # if > 1 enables parallel code generation which improves + # compile times, but prevents some optimizations. + # Passes `-C codegen-units`. +panic = 'unwind' # panic strategy (`-C panic=...`), can also be 'abort' +incremental = true # whether or not incremental compilation is enabled + # This can be overridden globally with the CARGO_INCREMENTAL + # environment variable or `build.incremental` config + # variable. Incremental is only used for path sources. +overflow-checks = true # use overflow checks for integer arithmetic. + # Passes the `-C overflow-checks=...` flag to the compiler. diff --git a/Makefile b/Makefile index 2bb3facb0dc6..6582badda434 100644 --- a/Makefile +++ b/Makefile @@ -105,6 +105,9 @@ llvm: spectests-llvm emtests-llvm wasitests-llvm capi: cargo build -p wasmer-runtime-c-api --release +capi-dev: + cargo build -p wasmer-runtime-c-api --profile dev -Z unstable-options + test-capi: capi cargo test -p wasmer-runtime-c-api --release From 01d8bebc6a4e1fa6162daa26cf99094332f574c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 18 Dec 2019 21:41:57 +0200 Subject: [PATCH 042/129] Add locks against reinitialization of opcode costs and the import object --- lib/middleware-common/src/runtime_breakpoints.rs | 1 - lib/runtime-c-api/src/import/mod.rs | 8 ++++++++ lib/runtime-c-api/src/metering.rs | 9 ++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/middleware-common/src/runtime_breakpoints.rs b/lib/middleware-common/src/runtime_breakpoints.rs index 28c91320a4eb..e9c42bacb9ed 100644 --- a/lib/middleware-common/src/runtime_breakpoints.rs +++ b/lib/middleware-common/src/runtime_breakpoints.rs @@ -68,7 +68,6 @@ impl FunctionMiddleware for RuntimeBreakpointHandler { pub fn set_runtime_breakpoint_value(instance: &mut Instance, value: u64) { - println!("Runtime breakpoint value set to {}", value); instance.set_internal(&RUNTIME_BREAKPOINT_VALUE, value); } diff --git a/lib/runtime-c-api/src/import/mod.rs b/lib/runtime-c-api/src/import/mod.rs index f92d746d6c32..0368117eb2f2 100644 --- a/lib/runtime-c-api/src/import/mod.rs +++ b/lib/runtime-c-api/src/import/mod.rs @@ -27,6 +27,7 @@ pub enum ImportError { } pub static mut GLOBAL_IMPORT_OBJECT: *mut ImportObject = 0 as *mut ImportObject; +pub static mut GLOBAL_IMPORT_OBJECT_INITIALIZED: bool = false; #[repr(C)] pub struct wasmer_import_t { @@ -71,6 +72,11 @@ pub unsafe extern "C" fn wasmer_import_object_cache_from_imports( imports: *mut wasmer_import_t, imports_len: c_int, ) -> wasmer_result_t { + if GLOBAL_IMPORT_OBJECT_INITIALIZED { + println!("Global import object already initialized, skipping."); + return wasmer_result_t::WASMER_OK; + } + let imports_result = wasmer_create_import_object_from_imports(imports, imports_len); let import_object = match imports_result { Err(ImportError::ModuleNameError) => { @@ -84,6 +90,8 @@ pub unsafe extern "C" fn wasmer_import_object_cache_from_imports( Ok(created_imports_object) => created_imports_object }; GLOBAL_IMPORT_OBJECT = Box::into_raw(Box::new(import_object)); + GLOBAL_IMPORT_OBJECT_INITIALIZED = true; + println!("Global import object initialized."); return wasmer_result_t::WASMER_OK } diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 6960cb459ca4..faa832a35dee 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -19,6 +19,7 @@ use wasmer_middleware_common::metering; pub const OPCODE_COUNT: usize = 410; static mut OPCODE_COSTS: [u32; OPCODE_COUNT] = [0; OPCODE_COUNT]; +static mut OPCODE_COSTS_INITIALIZED: bool = false; #[repr(C)] pub struct wasmer_import_object_t; @@ -29,7 +30,13 @@ pub struct wasmer_import_object_t; pub unsafe extern "C" fn wasmer_set_opcode_costs( opcode_costs_pointer: *const u32, ) { - OPCODE_COSTS.copy_from_slice(slice::from_raw_parts(opcode_costs_pointer, OPCODE_COUNT)); + if !OPCODE_COSTS_INITIALIZED { + OPCODE_COSTS.copy_from_slice(slice::from_raw_parts(opcode_costs_pointer, OPCODE_COUNT)); + OPCODE_COSTS_INITIALIZED = true; + println!("Opcode costs have been initialized."); + } else { + println!("Opcode costs were already initialized."); + } } From 7184617ac73459ce112994f6685924fce9045093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Mon, 13 Jan 2020 12:36:22 +0200 Subject: [PATCH 043/129] Use RuntimeError::Trap in metering.rs and runtime_breakpoints.rs --- lib/middleware-common/src/metering.rs | 3 ++- lib/middleware-common/src/runtime_breakpoints.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/middleware-common/src/metering.rs b/lib/middleware-common/src/metering.rs index 78d6f6a552ae..798cdd3c79ac 100644 --- a/lib/middleware-common/src/metering.rs +++ b/lib/middleware-common/src/metering.rs @@ -3,6 +3,7 @@ use wasmer_runtime_core::{ module::ModuleInfo, vm::{Ctx, InternalField}, wasmparser::{Operator, Type as WpType, TypeOrFuncType as WpTypeOrFuncType}, + error::{RuntimeError}, Instance, }; @@ -101,7 +102,7 @@ impl<'q> FunctionMiddleware for Metering<'q> { ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), })); sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(|_| { - Err(Box::new(ExecutionLimitExceededError)) + Err(Box::new(RuntimeError::Trap { msg: Box::from("execution limit exceeded") })) })))); sink.push(Event::WasmOwned(Operator::End)); } diff --git a/lib/middleware-common/src/runtime_breakpoints.rs b/lib/middleware-common/src/runtime_breakpoints.rs index e9c42bacb9ed..3322e25821df 100644 --- a/lib/middleware-common/src/runtime_breakpoints.rs +++ b/lib/middleware-common/src/runtime_breakpoints.rs @@ -3,6 +3,7 @@ use wasmer_runtime_core::{ module::ModuleInfo, vm::{InternalField}, wasmparser::{Operator, Type as WpType, TypeOrFuncType as WpTypeOrFuncType}, + error::{RuntimeError}, Instance, }; @@ -57,7 +58,7 @@ impl FunctionMiddleware for RuntimeBreakpointHandler { ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), })); sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(|_| { - Err(Box::new(RuntimeBreakpointReachedError)) + Err(Box::new(RuntimeError::Trap { msg: Box::from("execution limit exceeded") })) })))); sink.push(Event::WasmOwned(Operator::End)); } From d4107c4057916136a67430a080c78ed558cd83b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Mon, 13 Jan 2020 12:42:43 +0200 Subject: [PATCH 044/129] Remove unneeded println!() --- lib/runtime-c-api/src/import/mod.rs | 2 -- lib/runtime-c-api/src/metering.rs | 3 --- 2 files changed, 5 deletions(-) diff --git a/lib/runtime-c-api/src/import/mod.rs b/lib/runtime-c-api/src/import/mod.rs index 0368117eb2f2..0afc51b68537 100644 --- a/lib/runtime-c-api/src/import/mod.rs +++ b/lib/runtime-c-api/src/import/mod.rs @@ -73,7 +73,6 @@ pub unsafe extern "C" fn wasmer_import_object_cache_from_imports( imports_len: c_int, ) -> wasmer_result_t { if GLOBAL_IMPORT_OBJECT_INITIALIZED { - println!("Global import object already initialized, skipping."); return wasmer_result_t::WASMER_OK; } @@ -91,7 +90,6 @@ pub unsafe extern "C" fn wasmer_import_object_cache_from_imports( }; GLOBAL_IMPORT_OBJECT = Box::into_raw(Box::new(import_object)); GLOBAL_IMPORT_OBJECT_INITIALIZED = true; - println!("Global import object initialized."); return wasmer_result_t::WASMER_OK } diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index faa832a35dee..1882904ef489 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -33,9 +33,6 @@ pub unsafe extern "C" fn wasmer_set_opcode_costs( if !OPCODE_COSTS_INITIALIZED { OPCODE_COSTS.copy_from_slice(slice::from_raw_parts(opcode_costs_pointer, OPCODE_COUNT)); OPCODE_COSTS_INITIALIZED = true; - println!("Opcode costs have been initialized."); - } else { - println!("Opcode costs were already initialized."); } } From c9c6b1ab8c1fa12b4964c6a0a537d4b588613689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Thu, 5 Mar 2020 16:56:18 +0200 Subject: [PATCH 045/129] Minor fixes after merge --- Makefile | 4 --- .../src/runtime_breakpoints.rs | 1 + lib/runtime-c-api/Cargo.toml | 16 ++++++------ lib/runtime-c-api/wasmer.h | 26 +++++++++---------- lib/runtime-c-api/wasmer.hh | 5 ---- lib/runtime/Cargo.toml | 2 +- lib/singlepass-backend/Cargo.toml | 2 ++ 7 files changed, 25 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index f8a44eb3ba3b..e17d3ab418ea 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,6 @@ llvm: spectests-llvm emtests-llvm wasitests-llvm # All tests -<<<<<<< HEAD capi: cargo build -p wasmer-runtime-c-api --release @@ -122,9 +121,6 @@ capi-emscripten: cargo build --manifest-path lib/runtime-c-api/Cargo.toml --release \ --no-default-features --features singlepass-backend,emscripten -# We use singlepass as the default backend for the capi for now -capi: capi-singlepass - test-capi-singlepass: capi-singlepass cargo test --manifest-path lib/runtime-c-api/Cargo.toml --release \ --no-default-features --features singlepass-backend,wasi diff --git a/lib/middleware-common/src/runtime_breakpoints.rs b/lib/middleware-common/src/runtime_breakpoints.rs index 3322e25821df..8336bfd89d85 100644 --- a/lib/middleware-common/src/runtime_breakpoints.rs +++ b/lib/middleware-common/src/runtime_breakpoints.rs @@ -29,6 +29,7 @@ impl FunctionMiddleware for RuntimeBreakpointHandler { op: Event<'a, 'b>, _module_info: &ModuleInfo, sink: &mut EventSink<'a, 'b>, + source_loc: u32, ) -> Result<(), Self::Error> { let must_add_breakpoint = match op { diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index bb9c2a8b9184..4596912c69de 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -40,28 +40,28 @@ optional = true [dependencies.wasmer-middleware-common] path = "../middleware-common" -version = "0.11.0" +version = "0.15.0" optional = true [dependencies.wasmer-singlepass-backend] path = "../singlepass-backend" -version = "0.11.0" +version = "0.15.0" optional = true [dependencies.wasmer-llvm-backend] path = "../llvm-backend" -version = "0.11.0" +version = "0.15.0" optional = true -# [dependencies.wasmer-clif-backend] -# path = "../clif-backend" -# version = "0.11.0" -# optional = true +[dependencies.wasmer-clif-backend] +path = "../clif-backend" +version = "0.15.0" +optional = true [features] default = ["singlepass-backend", "metering", "runtime-breakpoints", "wasmer-runtime/deterministic-execution"] debug = ["wasmer-runtime/debug"] -cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift", "wasmer-clif-backend"] +cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift"] llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm", "wasmer-llvm-backend"] singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass", "wasmer-singlepass-backend", "wasmer-singlepass-backend/deterministic-execution"] metering = ["wasmer-middleware-common"] diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index fc03d78f60c6..35867043625f 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -422,6 +422,19 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, uint8_t *wasm_bytes, uint32_t wasm_bytes_len); +/** + * Creates a new Module with gas limit from the given wasm bytes. + * + * Returns `wasmer_result_t::WASMER_OK` upon success. + * + * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` + * and `wasmer_last_error_message` to get an error message. + */ +wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, + uint8_t *wasm_bytes, + uint32_t wasm_bytes_len, + uint64_t gas_limit); + #if defined(WASMER_EMSCRIPTEN_ENABLED) /** * Convenience function for setting up arguments and calling the Emscripten @@ -480,19 +493,6 @@ wasmer_result_t wasmer_emscripten_set_up(wasmer_instance_t *instance, wasmer_emscripten_globals_t *globals); #endif -/** - * Creates a new Module with gas limit from the given wasm bytes. - * - * Returns `wasmer_result_t::WASMER_OK` upon success. - * - * Returns `wasmer_result_t::WASMER_ERROR` upon failure. Use `wasmer_last_error_length` - * and `wasmer_last_error_message` to get an error message. - */ -wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, - uint8_t *wasm_bytes, - uint32_t wasm_bytes_len, - uint64_t gas_limit); - /** * Gets export descriptor kind */ diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index e43f76495a87..6c17fc85c8a8 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -27,7 +27,6 @@ # define DEPRECATED(message) __declspec(deprecated(message)) #endif -#define WASMER_WASI_ENABLED #endif // WASMER_H_MACROS @@ -238,10 +237,6 @@ struct wasmer_import_t { wasmer_import_export_value value; }; -struct wasmer_import_object_t { - -}; - struct wasmer_import_object_iter_t { }; diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index 89d7961d1d5a..b33c5ab58d7f 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -11,7 +11,6 @@ edition = "2018" readme = "README.md" [dependencies] -wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.15.0", optional = true } lazy_static = "1.4" memmap = "0.7" @@ -56,6 +55,7 @@ cache = ["cranelift"] debug = ["wasmer-runtime-core/debug"] llvm = ["wasmer-llvm-backend"] singlepass = ["wasmer-singlepass-backend"] +default-backend-cranelift = ["cranelift"] default-backend-singlepass = ["singlepass"] default-backend-llvm = ["llvm"] deterministic-execution = ["wasmer-singlepass-backend/deterministic-execution", "wasmer-runtime-core/deterministic-execution"] diff --git a/lib/singlepass-backend/Cargo.toml b/lib/singlepass-backend/Cargo.toml index 7fe7d1a5c6e3..cb0d3b071278 100644 --- a/lib/singlepass-backend/Cargo.toml +++ b/lib/singlepass-backend/Cargo.toml @@ -20,6 +20,8 @@ nix = "0.15" libc = "0.2.60" smallvec = "0.6" wasmparser = "0.51.3" +[dependencies.serde_derive] +version = "1.0" [features] default = ["deterministic-execution"] From 646b475c1ffc257b35632f033861dcf4af8e6c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Thu, 5 Mar 2020 17:02:12 +0200 Subject: [PATCH 046/129] Update autogenerated files --- lib/runtime-c-api/wasmer.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 35867043625f..dde0441ef17e 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -27,7 +27,6 @@ # define DEPRECATED(message) __declspec(deprecated(message)) #endif -#define WASMER_WASI_ENABLED #endif // WASMER_H_MACROS @@ -303,10 +302,6 @@ typedef struct { typedef struct { -} wasmer_import_object_t; - -typedef struct { - } wasmer_import_object_iter_t; /** From 5c54e3b7bf85de94ac16a19cc6e160f478bd1585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Thu, 5 Mar 2020 17:19:58 +0200 Subject: [PATCH 047/129] Update Operator identifiers in metering_costs.rs --- lib/middleware-common/src/metering_costs.rs | 164 ++++++++++---------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/lib/middleware-common/src/metering_costs.rs b/lib/middleware-common/src/metering_costs.rs index f0399d061e99..b5c58a879d63 100644 --- a/lib/middleware-common/src/metering_costs.rs +++ b/lib/middleware-common/src/metering_costs.rs @@ -19,11 +19,11 @@ pub fn get_opcode_index(op: &Operator) -> usize { Operator::CallIndirect { .. } => { 12 } Operator::Drop { .. } => { 13 } Operator::Select { .. } => { 14 } - Operator::GetLocal { .. } => { 15 } - Operator::SetLocal { .. } => { 16 } - Operator::TeeLocal { .. } => { 17 } - Operator::GetGlobal { .. } => { 18 } - Operator::SetGlobal { .. } => { 19 } + Operator::LocalGet { .. } => { 15 } + Operator::LocalSet { .. } => { 16 } + Operator::LocalTee { .. } => { 17 } + Operator::GlobalGet { .. } => { 18 } + Operator::GlobalSet { .. } => { 19 } Operator::I32Load { .. } => { 20 } Operator::I64Load { .. } => { 21 } Operator::F32Load { .. } => { 22 } @@ -154,25 +154,25 @@ pub fn get_opcode_index(op: &Operator) -> usize { Operator::F64Max { .. } => { 147 } Operator::F64Copysign { .. } => { 148 } Operator::I32WrapI64 { .. } => { 149 } - Operator::I32TruncSF32 { .. } => { 150 } - Operator::I32TruncUF32 { .. } => { 151 } - Operator::I32TruncSF64 { .. } => { 152 } - Operator::I32TruncUF64 { .. } => { 153 } - Operator::I64ExtendSI32 { .. } => { 154 } - Operator::I64ExtendUI32 { .. } => { 155 } - Operator::I64TruncSF32 { .. } => { 156 } - Operator::I64TruncUF32 { .. } => { 157 } - Operator::I64TruncSF64 { .. } => { 158 } - Operator::I64TruncUF64 { .. } => { 159 } - Operator::F32ConvertSI32 { .. } => { 160 } - Operator::F32ConvertUI32 { .. } => { 161 } - Operator::F32ConvertSI64 { .. } => { 162 } - Operator::F32ConvertUI64 { .. } => { 163 } + Operator::I32TruncF32S { .. } => { 150 } + Operator::I32TruncF32U { .. } => { 151 } + Operator::I32TruncF64S { .. } => { 152 } + Operator::I32TruncF64U { .. } => { 153 } + Operator::I64ExtendI32S { .. } => { 154 } + Operator::I64ExtendI32U { .. } => { 155 } + Operator::I64TruncF32S { .. } => { 156 } + Operator::I64TruncF32U { .. } => { 157 } + Operator::I64TruncF64S { .. } => { 158 } + Operator::I64TruncF64U { .. } => { 159 } + Operator::F32ConvertI32S { .. } => { 160 } + Operator::F32ConvertI32U { .. } => { 161 } + Operator::F32ConvertI64S { .. } => { 162 } + Operator::F32ConvertI64U { .. } => { 163 } Operator::F32DemoteF64 { .. } => { 164 } - Operator::F64ConvertSI32 { .. } => { 165 } - Operator::F64ConvertUI32 { .. } => { 166 } - Operator::F64ConvertSI64 { .. } => { 167 } - Operator::F64ConvertUI64 { .. } => { 168 } + Operator::F64ConvertI32S { .. } => { 165 } + Operator::F64ConvertI32U { .. } => { 166 } + Operator::F64ConvertI64S { .. } => { 167 } + Operator::F64ConvertI64U { .. } => { 168 } Operator::F64PromoteF32 { .. } => { 169 } Operator::I32ReinterpretF32 { .. } => { 170 } Operator::I64ReinterpretF64 { .. } => { 171 } @@ -183,14 +183,14 @@ pub fn get_opcode_index(op: &Operator) -> usize { Operator::I64Extend8S { .. } => { 176 } Operator::I64Extend16S { .. } => { 177 } Operator::I64Extend32S { .. } => { 178 } - Operator::I32TruncSSatF32 { .. } => { 179 } - Operator::I32TruncUSatF32 { .. } => { 180 } - Operator::I32TruncSSatF64 { .. } => { 181 } - Operator::I32TruncUSatF64 { .. } => { 182 } - Operator::I64TruncSSatF32 { .. } => { 183 } - Operator::I64TruncUSatF32 { .. } => { 184 } - Operator::I64TruncSSatF64 { .. } => { 185 } - Operator::I64TruncUSatF64 { .. } => { 186 } + Operator::I32TruncSatF32S { .. } => { 179 } + Operator::I32TruncSatF32U { .. } => { 180 } + Operator::I32TruncSatF64S { .. } => { 181 } + Operator::I32TruncSatF64U { .. } => { 182 } + Operator::I64TruncSatF32S { .. } => { 183 } + Operator::I64TruncSatF32U { .. } => { 184 } + Operator::I64TruncSatF64S { .. } => { 185 } + Operator::I64TruncSatF64U { .. } => { 186 } Operator::MemoryInit { .. } => { 187 } Operator::DataDrop { .. } => { 188 } Operator::MemoryCopy { .. } => { 189 } @@ -202,10 +202,10 @@ pub fn get_opcode_index(op: &Operator) -> usize { Operator::TableSet { .. } => { 195 } Operator::TableGrow { .. } => { 196 } Operator::TableSize { .. } => { 197 } - Operator::Wake { .. } => { 198 } - Operator::I32Wait { .. } => { 199 } - Operator::I64Wait { .. } => { 200 } - Operator::Fence { .. } => { 201 } + Operator::AtomicNotify { .. } => { 198 } + Operator::I32AtomicWait { .. } => { 199 } + Operator::I64AtomicWait { .. } => { 200 } + Operator::AtomicFence { .. } => { 201 } Operator::I32AtomicLoad { .. } => { 202 } Operator::I64AtomicLoad { .. } => { 203 } Operator::I32AtomicLoad8U { .. } => { 204 } @@ -222,53 +222,53 @@ pub fn get_opcode_index(op: &Operator) -> usize { Operator::I64AtomicStore32 { .. } => { 215 } Operator::I32AtomicRmwAdd { .. } => { 216 } Operator::I64AtomicRmwAdd { .. } => { 217 } - Operator::I32AtomicRmw8UAdd { .. } => { 218 } - Operator::I32AtomicRmw16UAdd { .. } => { 219 } - Operator::I64AtomicRmw8UAdd { .. } => { 220 } - Operator::I64AtomicRmw16UAdd { .. } => { 221 } - Operator::I64AtomicRmw32UAdd { .. } => { 222 } + Operator::I32AtomicRmw8AddU { .. } => { 218 } + Operator::I32AtomicRmw16AddU { .. } => { 219 } + Operator::I64AtomicRmw8AddU { .. } => { 220 } + Operator::I64AtomicRmw16AddU { .. } => { 221 } + Operator::I64AtomicRmw32AddU { .. } => { 222 } Operator::I32AtomicRmwSub { .. } => { 223 } Operator::I64AtomicRmwSub { .. } => { 224 } - Operator::I32AtomicRmw8USub { .. } => { 225 } - Operator::I32AtomicRmw16USub { .. } => { 226 } - Operator::I64AtomicRmw8USub { .. } => { 227 } - Operator::I64AtomicRmw16USub { .. } => { 228 } - Operator::I64AtomicRmw32USub { .. } => { 229 } + Operator::I32AtomicRmw8SubU { .. } => { 225 } + Operator::I32AtomicRmw16SubU { .. } => { 226 } + Operator::I64AtomicRmw8SubU { .. } => { 227 } + Operator::I64AtomicRmw16SubU { .. } => { 228 } + Operator::I64AtomicRmw32SubU { .. } => { 229 } Operator::I32AtomicRmwAnd { .. } => { 230 } Operator::I64AtomicRmwAnd { .. } => { 231 } - Operator::I32AtomicRmw8UAnd { .. } => { 232 } - Operator::I32AtomicRmw16UAnd { .. } => { 233 } - Operator::I64AtomicRmw8UAnd { .. } => { 234 } - Operator::I64AtomicRmw16UAnd { .. } => { 235 } - Operator::I64AtomicRmw32UAnd { .. } => { 236 } + Operator::I32AtomicRmw8AndU { .. } => { 232 } + Operator::I32AtomicRmw16AndU { .. } => { 233 } + Operator::I64AtomicRmw8AndU { .. } => { 234 } + Operator::I64AtomicRmw16AndU { .. } => { 235 } + Operator::I64AtomicRmw32AndU { .. } => { 236 } Operator::I32AtomicRmwOr { .. } => { 237 } Operator::I64AtomicRmwOr { .. } => { 238 } - Operator::I32AtomicRmw8UOr { .. } => { 239 } - Operator::I32AtomicRmw16UOr { .. } => { 240 } - Operator::I64AtomicRmw8UOr { .. } => { 241 } - Operator::I64AtomicRmw16UOr { .. } => { 242 } - Operator::I64AtomicRmw32UOr { .. } => { 243 } + Operator::I32AtomicRmw8OrU { .. } => { 239 } + Operator::I32AtomicRmw16OrU { .. } => { 240 } + Operator::I64AtomicRmw8OrU { .. } => { 241 } + Operator::I64AtomicRmw16OrU { .. } => { 242 } + Operator::I64AtomicRmw32OrU { .. } => { 243 } Operator::I32AtomicRmwXor { .. } => { 244 } Operator::I64AtomicRmwXor { .. } => { 245 } - Operator::I32AtomicRmw8UXor { .. } => { 246 } - Operator::I32AtomicRmw16UXor { .. } => { 247 } - Operator::I64AtomicRmw8UXor { .. } => { 248 } - Operator::I64AtomicRmw16UXor { .. } => { 249 } - Operator::I64AtomicRmw32UXor { .. } => { 250 } + Operator::I32AtomicRmw8XorU { .. } => { 246 } + Operator::I32AtomicRmw16XorU { .. } => { 247 } + Operator::I64AtomicRmw8XorU { .. } => { 248 } + Operator::I64AtomicRmw16XorU { .. } => { 249 } + Operator::I64AtomicRmw32XorU { .. } => { 250 } Operator::I32AtomicRmwXchg { .. } => { 251 } Operator::I64AtomicRmwXchg { .. } => { 252 } - Operator::I32AtomicRmw8UXchg { .. } => { 253 } - Operator::I32AtomicRmw16UXchg { .. } => { 254 } - Operator::I64AtomicRmw8UXchg { .. } => { 255 } - Operator::I64AtomicRmw16UXchg { .. } => { 256 } - Operator::I64AtomicRmw32UXchg { .. } => { 257 } + Operator::I32AtomicRmw8XchgU { .. } => { 253 } + Operator::I32AtomicRmw16XchgU { .. } => { 254 } + Operator::I64AtomicRmw8XchgU { .. } => { 255 } + Operator::I64AtomicRmw16XchgU { .. } => { 256 } + Operator::I64AtomicRmw32XchgU { .. } => { 257 } Operator::I32AtomicRmwCmpxchg { .. } => { 258 } Operator::I64AtomicRmwCmpxchg { .. } => { 259 } - Operator::I32AtomicRmw8UCmpxchg { .. } => { 260 } - Operator::I32AtomicRmw16UCmpxchg { .. } => { 261 } - Operator::I64AtomicRmw8UCmpxchg { .. } => { 262 } - Operator::I64AtomicRmw16UCmpxchg { .. } => { 263 } - Operator::I64AtomicRmw32UCmpxchg { .. } => { 264 } + Operator::I32AtomicRmw8CmpxchgU { .. } => { 260 } + Operator::I32AtomicRmw16CmpxchgU { .. } => { 261 } + Operator::I64AtomicRmw8CmpxchgU { .. } => { 262 } + Operator::I64AtomicRmw16CmpxchgU { .. } => { 263 } + Operator::I64AtomicRmw32CmpxchgU { .. } => { 264 } Operator::V128Load { .. } => { 265 } Operator::V128Store { .. } => { 266 } Operator::V128Const { .. } => { 267 } @@ -400,19 +400,19 @@ pub fn get_opcode_index(op: &Operator) -> usize { Operator::F64x2Div { .. } => { 393 } Operator::F64x2Min { .. } => { 394 } Operator::F64x2Max { .. } => { 395 } - Operator::I32x4TruncSF32x4Sat { .. } => { 396 } - Operator::I32x4TruncUF32x4Sat { .. } => { 397 } - Operator::I64x2TruncSF64x2Sat { .. } => { 398 } - Operator::I64x2TruncUF64x2Sat { .. } => { 399 } - Operator::F32x4ConvertSI32x4 { .. } => { 400 } - Operator::F32x4ConvertUI32x4 { .. } => { 401 } - Operator::F64x2ConvertSI64x2 { .. } => { 402 } - Operator::F64x2ConvertUI64x2 { .. } => { 403 } + Operator::I32x4TruncSatF32x4S { .. } => { 396 } + Operator::I32x4TruncSatF32x4U { .. } => { 397 } + Operator::I64x2TruncSatF64x2S { .. } => { 398 } + Operator::I64x2TruncSatF64x2U { .. } => { 399 } + Operator::F32x4ConvertI32x4S { .. } => { 400 } + Operator::F32x4ConvertI32x4U { .. } => { 401 } + Operator::F64x2ConvertI64x2S { .. } => { 402 } + Operator::F64x2ConvertI64x2U { .. } => { 403 } Operator::V8x16Swizzle { .. } => { 404 } Operator::V8x16Shuffle { .. } => { 405 } - Operator::I8x16LoadSplat { .. } => { 406 } - Operator::I16x8LoadSplat { .. } => { 407 } - Operator::I32x4LoadSplat { .. } => { 408 } - Operator::I64x2LoadSplat { .. } => { 409 } + Operator::V8x16LoadSplat { .. } => { 406 } + Operator::V16x8LoadSplat { .. } => { 407 } + Operator::V32x4LoadSplat { .. } => { 408 } + Operator::V64x2LoadSplat { .. } => { 409 } } } From 1f419cb2e155508129ef6dbf38db10710be8280e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Thu, 5 Mar 2020 18:01:48 +0200 Subject: [PATCH 048/129] More fixes after merge --- lib/middleware-common/src/metering.rs | 2 +- lib/middleware-common/src/metering_costs.rs | 827 +++++++++--------- .../src/runtime_breakpoints.rs | 4 +- lib/runtime-c-api/src/metering.rs | 2 +- 4 files changed, 436 insertions(+), 399 deletions(-) diff --git a/lib/middleware-common/src/metering.rs b/lib/middleware-common/src/metering.rs index 0a8f992c5a41..01236603b87a 100644 --- a/lib/middleware-common/src/metering.rs +++ b/lib/middleware-common/src/metering.rs @@ -103,7 +103,7 @@ impl<'q> FunctionMiddleware for Metering<'q> { ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), })); sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(|_| { - Err(Box::new(RuntimeError::Trap { msg: Box::from("execution limit exceeded") })) + Err(Box::new(RuntimeError(Box::new("execution limit exceeded".to_string())))) })))); sink.push(Event::WasmOwned(Operator::End)); } diff --git a/lib/middleware-common/src/metering_costs.rs b/lib/middleware-common/src/metering_costs.rs index b5c58a879d63..b007ed3d160b 100644 --- a/lib/middleware-common/src/metering_costs.rs +++ b/lib/middleware-common/src/metering_costs.rs @@ -19,400 +19,437 @@ pub fn get_opcode_index(op: &Operator) -> usize { Operator::CallIndirect { .. } => { 12 } Operator::Drop { .. } => { 13 } Operator::Select { .. } => { 14 } - Operator::LocalGet { .. } => { 15 } - Operator::LocalSet { .. } => { 16 } - Operator::LocalTee { .. } => { 17 } - Operator::GlobalGet { .. } => { 18 } - Operator::GlobalSet { .. } => { 19 } - Operator::I32Load { .. } => { 20 } - Operator::I64Load { .. } => { 21 } - Operator::F32Load { .. } => { 22 } - Operator::F64Load { .. } => { 23 } - Operator::I32Load8S { .. } => { 24 } - Operator::I32Load8U { .. } => { 25 } - Operator::I32Load16S { .. } => { 26 } - Operator::I32Load16U { .. } => { 27 } - Operator::I64Load8S { .. } => { 28 } - Operator::I64Load8U { .. } => { 29 } - Operator::I64Load16S { .. } => { 30 } - Operator::I64Load16U { .. } => { 31 } - Operator::I64Load32S { .. } => { 32 } - Operator::I64Load32U { .. } => { 33 } - Operator::I32Store { .. } => { 34 } - Operator::I64Store { .. } => { 35 } - Operator::F32Store { .. } => { 36 } - Operator::F64Store { .. } => { 37 } - Operator::I32Store8 { .. } => { 38 } - Operator::I32Store16 { .. } => { 39 } - Operator::I64Store8 { .. } => { 40 } - Operator::I64Store16 { .. } => { 41 } - Operator::I64Store32 { .. } => { 42 } - Operator::MemorySize { .. } => { 43 } - Operator::MemoryGrow { .. } => { 44 } - Operator::I32Const { .. } => { 45 } - Operator::I64Const { .. } => { 46 } - Operator::F32Const { .. } => { 47 } - Operator::F64Const { .. } => { 48 } - Operator::RefNull { .. } => { 49 } - Operator::RefIsNull { .. } => { 50 } - Operator::I32Eqz { .. } => { 51 } - Operator::I32Eq { .. } => { 52 } - Operator::I32Ne { .. } => { 53 } - Operator::I32LtS { .. } => { 54 } - Operator::I32LtU { .. } => { 55 } - Operator::I32GtS { .. } => { 56 } - Operator::I32GtU { .. } => { 57 } - Operator::I32LeS { .. } => { 58 } - Operator::I32LeU { .. } => { 59 } - Operator::I32GeS { .. } => { 60 } - Operator::I32GeU { .. } => { 61 } - Operator::I64Eqz { .. } => { 62 } - Operator::I64Eq { .. } => { 63 } - Operator::I64Ne { .. } => { 64 } - Operator::I64LtS { .. } => { 65 } - Operator::I64LtU { .. } => { 66 } - Operator::I64GtS { .. } => { 67 } - Operator::I64GtU { .. } => { 68 } - Operator::I64LeS { .. } => { 69 } - Operator::I64LeU { .. } => { 70 } - Operator::I64GeS { .. } => { 71 } - Operator::I64GeU { .. } => { 72 } - Operator::F32Eq { .. } => { 73 } - Operator::F32Ne { .. } => { 74 } - Operator::F32Lt { .. } => { 75 } - Operator::F32Gt { .. } => { 76 } - Operator::F32Le { .. } => { 77 } - Operator::F32Ge { .. } => { 78 } - Operator::F64Eq { .. } => { 79 } - Operator::F64Ne { .. } => { 80 } - Operator::F64Lt { .. } => { 81 } - Operator::F64Gt { .. } => { 82 } - Operator::F64Le { .. } => { 83 } - Operator::F64Ge { .. } => { 84 } - Operator::I32Clz { .. } => { 85 } - Operator::I32Ctz { .. } => { 86 } - Operator::I32Popcnt { .. } => { 87 } - Operator::I32Add { .. } => { 88 } - Operator::I32Sub { .. } => { 89 } - Operator::I32Mul { .. } => { 90 } - Operator::I32DivS { .. } => { 91 } - Operator::I32DivU { .. } => { 92 } - Operator::I32RemS { .. } => { 93 } - Operator::I32RemU { .. } => { 94 } - Operator::I32And { .. } => { 95 } - Operator::I32Or { .. } => { 96 } - Operator::I32Xor { .. } => { 97 } - Operator::I32Shl { .. } => { 98 } - Operator::I32ShrS { .. } => { 99 } - Operator::I32ShrU { .. } => { 100 } - Operator::I32Rotl { .. } => { 101 } - Operator::I32Rotr { .. } => { 102 } - Operator::I64Clz { .. } => { 103 } - Operator::I64Ctz { .. } => { 104 } - Operator::I64Popcnt { .. } => { 105 } - Operator::I64Add { .. } => { 106 } - Operator::I64Sub { .. } => { 107 } - Operator::I64Mul { .. } => { 108 } - Operator::I64DivS { .. } => { 109 } - Operator::I64DivU { .. } => { 110 } - Operator::I64RemS { .. } => { 111 } - Operator::I64RemU { .. } => { 112 } - Operator::I64And { .. } => { 113 } - Operator::I64Or { .. } => { 114 } - Operator::I64Xor { .. } => { 115 } - Operator::I64Shl { .. } => { 116 } - Operator::I64ShrS { .. } => { 117 } - Operator::I64ShrU { .. } => { 118 } - Operator::I64Rotl { .. } => { 119 } - Operator::I64Rotr { .. } => { 120 } - Operator::F32Abs { .. } => { 121 } - Operator::F32Neg { .. } => { 122 } - Operator::F32Ceil { .. } => { 123 } - Operator::F32Floor { .. } => { 124 } - Operator::F32Trunc { .. } => { 125 } - Operator::F32Nearest { .. } => { 126 } - Operator::F32Sqrt { .. } => { 127 } - Operator::F32Add { .. } => { 128 } - Operator::F32Sub { .. } => { 129 } - Operator::F32Mul { .. } => { 130 } - Operator::F32Div { .. } => { 131 } - Operator::F32Min { .. } => { 132 } - Operator::F32Max { .. } => { 133 } - Operator::F32Copysign { .. } => { 134 } - Operator::F64Abs { .. } => { 135 } - Operator::F64Neg { .. } => { 136 } - Operator::F64Ceil { .. } => { 137 } - Operator::F64Floor { .. } => { 138 } - Operator::F64Trunc { .. } => { 139 } - Operator::F64Nearest { .. } => { 140 } - Operator::F64Sqrt { .. } => { 141 } - Operator::F64Add { .. } => { 142 } - Operator::F64Sub { .. } => { 143 } - Operator::F64Mul { .. } => { 144 } - Operator::F64Div { .. } => { 145 } - Operator::F64Min { .. } => { 146 } - Operator::F64Max { .. } => { 147 } - Operator::F64Copysign { .. } => { 148 } - Operator::I32WrapI64 { .. } => { 149 } - Operator::I32TruncF32S { .. } => { 150 } - Operator::I32TruncF32U { .. } => { 151 } - Operator::I32TruncF64S { .. } => { 152 } - Operator::I32TruncF64U { .. } => { 153 } - Operator::I64ExtendI32S { .. } => { 154 } - Operator::I64ExtendI32U { .. } => { 155 } - Operator::I64TruncF32S { .. } => { 156 } - Operator::I64TruncF32U { .. } => { 157 } - Operator::I64TruncF64S { .. } => { 158 } - Operator::I64TruncF64U { .. } => { 159 } - Operator::F32ConvertI32S { .. } => { 160 } - Operator::F32ConvertI32U { .. } => { 161 } - Operator::F32ConvertI64S { .. } => { 162 } - Operator::F32ConvertI64U { .. } => { 163 } - Operator::F32DemoteF64 { .. } => { 164 } - Operator::F64ConvertI32S { .. } => { 165 } - Operator::F64ConvertI32U { .. } => { 166 } - Operator::F64ConvertI64S { .. } => { 167 } - Operator::F64ConvertI64U { .. } => { 168 } - Operator::F64PromoteF32 { .. } => { 169 } - Operator::I32ReinterpretF32 { .. } => { 170 } - Operator::I64ReinterpretF64 { .. } => { 171 } - Operator::F32ReinterpretI32 { .. } => { 172 } - Operator::F64ReinterpretI64 { .. } => { 173 } - Operator::I32Extend8S { .. } => { 174 } - Operator::I32Extend16S { .. } => { 175 } - Operator::I64Extend8S { .. } => { 176 } - Operator::I64Extend16S { .. } => { 177 } - Operator::I64Extend32S { .. } => { 178 } - Operator::I32TruncSatF32S { .. } => { 179 } - Operator::I32TruncSatF32U { .. } => { 180 } - Operator::I32TruncSatF64S { .. } => { 181 } - Operator::I32TruncSatF64U { .. } => { 182 } - Operator::I64TruncSatF32S { .. } => { 183 } - Operator::I64TruncSatF32U { .. } => { 184 } - Operator::I64TruncSatF64S { .. } => { 185 } - Operator::I64TruncSatF64U { .. } => { 186 } - Operator::MemoryInit { .. } => { 187 } - Operator::DataDrop { .. } => { 188 } - Operator::MemoryCopy { .. } => { 189 } - Operator::MemoryFill { .. } => { 190 } - Operator::TableInit { .. } => { 191 } - Operator::ElemDrop { .. } => { 192 } - Operator::TableCopy { .. } => { 193 } - Operator::TableGet { .. } => { 194 } - Operator::TableSet { .. } => { 195 } - Operator::TableGrow { .. } => { 196 } - Operator::TableSize { .. } => { 197 } - Operator::AtomicNotify { .. } => { 198 } - Operator::I32AtomicWait { .. } => { 199 } - Operator::I64AtomicWait { .. } => { 200 } - Operator::AtomicFence { .. } => { 201 } - Operator::I32AtomicLoad { .. } => { 202 } - Operator::I64AtomicLoad { .. } => { 203 } - Operator::I32AtomicLoad8U { .. } => { 204 } - Operator::I32AtomicLoad16U { .. } => { 205 } - Operator::I64AtomicLoad8U { .. } => { 206 } - Operator::I64AtomicLoad16U { .. } => { 207 } - Operator::I64AtomicLoad32U { .. } => { 208 } - Operator::I32AtomicStore { .. } => { 209 } - Operator::I64AtomicStore { .. } => { 210 } - Operator::I32AtomicStore8 { .. } => { 211 } - Operator::I32AtomicStore16 { .. } => { 212 } - Operator::I64AtomicStore8 { .. } => { 213 } - Operator::I64AtomicStore16 { .. } => { 214 } - Operator::I64AtomicStore32 { .. } => { 215 } - Operator::I32AtomicRmwAdd { .. } => { 216 } - Operator::I64AtomicRmwAdd { .. } => { 217 } - Operator::I32AtomicRmw8AddU { .. } => { 218 } - Operator::I32AtomicRmw16AddU { .. } => { 219 } - Operator::I64AtomicRmw8AddU { .. } => { 220 } - Operator::I64AtomicRmw16AddU { .. } => { 221 } - Operator::I64AtomicRmw32AddU { .. } => { 222 } - Operator::I32AtomicRmwSub { .. } => { 223 } - Operator::I64AtomicRmwSub { .. } => { 224 } - Operator::I32AtomicRmw8SubU { .. } => { 225 } - Operator::I32AtomicRmw16SubU { .. } => { 226 } - Operator::I64AtomicRmw8SubU { .. } => { 227 } - Operator::I64AtomicRmw16SubU { .. } => { 228 } - Operator::I64AtomicRmw32SubU { .. } => { 229 } - Operator::I32AtomicRmwAnd { .. } => { 230 } - Operator::I64AtomicRmwAnd { .. } => { 231 } - Operator::I32AtomicRmw8AndU { .. } => { 232 } - Operator::I32AtomicRmw16AndU { .. } => { 233 } - Operator::I64AtomicRmw8AndU { .. } => { 234 } - Operator::I64AtomicRmw16AndU { .. } => { 235 } - Operator::I64AtomicRmw32AndU { .. } => { 236 } - Operator::I32AtomicRmwOr { .. } => { 237 } - Operator::I64AtomicRmwOr { .. } => { 238 } - Operator::I32AtomicRmw8OrU { .. } => { 239 } - Operator::I32AtomicRmw16OrU { .. } => { 240 } - Operator::I64AtomicRmw8OrU { .. } => { 241 } - Operator::I64AtomicRmw16OrU { .. } => { 242 } - Operator::I64AtomicRmw32OrU { .. } => { 243 } - Operator::I32AtomicRmwXor { .. } => { 244 } - Operator::I64AtomicRmwXor { .. } => { 245 } - Operator::I32AtomicRmw8XorU { .. } => { 246 } - Operator::I32AtomicRmw16XorU { .. } => { 247 } - Operator::I64AtomicRmw8XorU { .. } => { 248 } - Operator::I64AtomicRmw16XorU { .. } => { 249 } - Operator::I64AtomicRmw32XorU { .. } => { 250 } - Operator::I32AtomicRmwXchg { .. } => { 251 } - Operator::I64AtomicRmwXchg { .. } => { 252 } - Operator::I32AtomicRmw8XchgU { .. } => { 253 } - Operator::I32AtomicRmw16XchgU { .. } => { 254 } - Operator::I64AtomicRmw8XchgU { .. } => { 255 } - Operator::I64AtomicRmw16XchgU { .. } => { 256 } - Operator::I64AtomicRmw32XchgU { .. } => { 257 } - Operator::I32AtomicRmwCmpxchg { .. } => { 258 } - Operator::I64AtomicRmwCmpxchg { .. } => { 259 } - Operator::I32AtomicRmw8CmpxchgU { .. } => { 260 } - Operator::I32AtomicRmw16CmpxchgU { .. } => { 261 } - Operator::I64AtomicRmw8CmpxchgU { .. } => { 262 } - Operator::I64AtomicRmw16CmpxchgU { .. } => { 263 } - Operator::I64AtomicRmw32CmpxchgU { .. } => { 264 } - Operator::V128Load { .. } => { 265 } - Operator::V128Store { .. } => { 266 } - Operator::V128Const { .. } => { 267 } - Operator::I8x16Splat { .. } => { 268 } - Operator::I8x16ExtractLaneS { .. } => { 269 } - Operator::I8x16ExtractLaneU { .. } => { 270 } - Operator::I8x16ReplaceLane { .. } => { 271 } - Operator::I16x8Splat { .. } => { 272 } - Operator::I16x8ExtractLaneS { .. } => { 273 } - Operator::I16x8ExtractLaneU { .. } => { 274 } - Operator::I16x8ReplaceLane { .. } => { 275 } - Operator::I32x4Splat { .. } => { 276 } - Operator::I32x4ExtractLane { .. } => { 277 } - Operator::I32x4ReplaceLane { .. } => { 278 } - Operator::I64x2Splat { .. } => { 279 } - Operator::I64x2ExtractLane { .. } => { 280 } - Operator::I64x2ReplaceLane { .. } => { 281 } - Operator::F32x4Splat { .. } => { 282 } - Operator::F32x4ExtractLane { .. } => { 283 } - Operator::F32x4ReplaceLane { .. } => { 284 } - Operator::F64x2Splat { .. } => { 285 } - Operator::F64x2ExtractLane { .. } => { 286 } - Operator::F64x2ReplaceLane { .. } => { 287 } - Operator::I8x16Eq { .. } => { 288 } - Operator::I8x16Ne { .. } => { 289 } - Operator::I8x16LtS { .. } => { 290 } - Operator::I8x16LtU { .. } => { 291 } - Operator::I8x16GtS { .. } => { 292 } - Operator::I8x16GtU { .. } => { 293 } - Operator::I8x16LeS { .. } => { 294 } - Operator::I8x16LeU { .. } => { 295 } - Operator::I8x16GeS { .. } => { 296 } - Operator::I8x16GeU { .. } => { 297 } - Operator::I16x8Eq { .. } => { 298 } - Operator::I16x8Ne { .. } => { 299 } - Operator::I16x8LtS { .. } => { 300 } - Operator::I16x8LtU { .. } => { 301 } - Operator::I16x8GtS { .. } => { 302 } - Operator::I16x8GtU { .. } => { 303 } - Operator::I16x8LeS { .. } => { 304 } - Operator::I16x8LeU { .. } => { 305 } - Operator::I16x8GeS { .. } => { 306 } - Operator::I16x8GeU { .. } => { 307 } - Operator::I32x4Eq { .. } => { 308 } - Operator::I32x4Ne { .. } => { 309 } - Operator::I32x4LtS { .. } => { 310 } - Operator::I32x4LtU { .. } => { 311 } - Operator::I32x4GtS { .. } => { 312 } - Operator::I32x4GtU { .. } => { 313 } - Operator::I32x4LeS { .. } => { 314 } - Operator::I32x4LeU { .. } => { 315 } - Operator::I32x4GeS { .. } => { 316 } - Operator::I32x4GeU { .. } => { 317 } - Operator::F32x4Eq { .. } => { 318 } - Operator::F32x4Ne { .. } => { 319 } - Operator::F32x4Lt { .. } => { 320 } - Operator::F32x4Gt { .. } => { 321 } - Operator::F32x4Le { .. } => { 322 } - Operator::F32x4Ge { .. } => { 323 } - Operator::F64x2Eq { .. } => { 324 } - Operator::F64x2Ne { .. } => { 325 } - Operator::F64x2Lt { .. } => { 326 } - Operator::F64x2Gt { .. } => { 327 } - Operator::F64x2Le { .. } => { 328 } - Operator::F64x2Ge { .. } => { 329 } - Operator::V128Not { .. } => { 330 } - Operator::V128And { .. } => { 331 } - Operator::V128Or { .. } => { 332 } - Operator::V128Xor { .. } => { 333 } - Operator::V128Bitselect { .. } => { 334 } - Operator::I8x16Neg { .. } => { 335 } - Operator::I8x16AnyTrue { .. } => { 336 } - Operator::I8x16AllTrue { .. } => { 337 } - Operator::I8x16Shl { .. } => { 338 } - Operator::I8x16ShrS { .. } => { 339 } - Operator::I8x16ShrU { .. } => { 340 } - Operator::I8x16Add { .. } => { 341 } - Operator::I8x16AddSaturateS { .. } => { 342 } - Operator::I8x16AddSaturateU { .. } => { 343 } - Operator::I8x16Sub { .. } => { 344 } - Operator::I8x16SubSaturateS { .. } => { 345 } - Operator::I8x16SubSaturateU { .. } => { 346 } - Operator::I8x16Mul { .. } => { 347 } - Operator::I16x8Neg { .. } => { 348 } - Operator::I16x8AnyTrue { .. } => { 349 } - Operator::I16x8AllTrue { .. } => { 350 } - Operator::I16x8Shl { .. } => { 351 } - Operator::I16x8ShrS { .. } => { 352 } - Operator::I16x8ShrU { .. } => { 353 } - Operator::I16x8Add { .. } => { 354 } - Operator::I16x8AddSaturateS { .. } => { 355 } - Operator::I16x8AddSaturateU { .. } => { 356 } - Operator::I16x8Sub { .. } => { 357 } - Operator::I16x8SubSaturateS { .. } => { 358 } - Operator::I16x8SubSaturateU { .. } => { 359 } - Operator::I16x8Mul { .. } => { 360 } - Operator::I32x4Neg { .. } => { 361 } - Operator::I32x4AnyTrue { .. } => { 362 } - Operator::I32x4AllTrue { .. } => { 363 } - Operator::I32x4Shl { .. } => { 364 } - Operator::I32x4ShrS { .. } => { 365 } - Operator::I32x4ShrU { .. } => { 366 } - Operator::I32x4Add { .. } => { 367 } - Operator::I32x4Sub { .. } => { 368 } - Operator::I32x4Mul { .. } => { 369 } - Operator::I64x2Neg { .. } => { 370 } - Operator::I64x2AnyTrue { .. } => { 371 } - Operator::I64x2AllTrue { .. } => { 372 } - Operator::I64x2Shl { .. } => { 373 } - Operator::I64x2ShrS { .. } => { 374 } - Operator::I64x2ShrU { .. } => { 375 } - Operator::I64x2Add { .. } => { 376 } - Operator::I64x2Sub { .. } => { 377 } - Operator::F32x4Abs { .. } => { 378 } - Operator::F32x4Neg { .. } => { 379 } - Operator::F32x4Sqrt { .. } => { 380 } - Operator::F32x4Add { .. } => { 381 } - Operator::F32x4Sub { .. } => { 382 } - Operator::F32x4Mul { .. } => { 383 } - Operator::F32x4Div { .. } => { 384 } - Operator::F32x4Min { .. } => { 385 } - Operator::F32x4Max { .. } => { 386 } - Operator::F64x2Abs { .. } => { 387 } - Operator::F64x2Neg { .. } => { 388 } - Operator::F64x2Sqrt { .. } => { 389 } - Operator::F64x2Add { .. } => { 390 } - Operator::F64x2Sub { .. } => { 391 } - Operator::F64x2Mul { .. } => { 392 } - Operator::F64x2Div { .. } => { 393 } - Operator::F64x2Min { .. } => { 394 } - Operator::F64x2Max { .. } => { 395 } - Operator::I32x4TruncSatF32x4S { .. } => { 396 } - Operator::I32x4TruncSatF32x4U { .. } => { 397 } - Operator::I64x2TruncSatF64x2S { .. } => { 398 } - Operator::I64x2TruncSatF64x2U { .. } => { 399 } - Operator::F32x4ConvertI32x4S { .. } => { 400 } - Operator::F32x4ConvertI32x4U { .. } => { 401 } - Operator::F64x2ConvertI64x2S { .. } => { 402 } - Operator::F64x2ConvertI64x2U { .. } => { 403 } - Operator::V8x16Swizzle { .. } => { 404 } - Operator::V8x16Shuffle { .. } => { 405 } - Operator::V8x16LoadSplat { .. } => { 406 } - Operator::V16x8LoadSplat { .. } => { 407 } - Operator::V32x4LoadSplat { .. } => { 408 } - Operator::V64x2LoadSplat { .. } => { 409 } + Operator::TypedSelect { .. } => { 15 } + Operator::LocalGet { .. } => { 16 } + Operator::LocalSet { .. } => { 17 } + Operator::LocalTee { .. } => { 18 } + Operator::GlobalGet { .. } => { 19 } + Operator::GlobalSet { .. } => { 20 } + Operator::I32Load { .. } => { 21 } + Operator::I64Load { .. } => { 22 } + Operator::F32Load { .. } => { 23 } + Operator::F64Load { .. } => { 24 } + Operator::I32Load8S { .. } => { 25 } + Operator::I32Load8U { .. } => { 26 } + Operator::I32Load16S { .. } => { 27 } + Operator::I32Load16U { .. } => { 28 } + Operator::I64Load8S { .. } => { 29 } + Operator::I64Load8U { .. } => { 30 } + Operator::I64Load16S { .. } => { 31 } + Operator::I64Load16U { .. } => { 32 } + Operator::I64Load32S { .. } => { 33 } + Operator::I64Load32U { .. } => { 34 } + Operator::I32Store { .. } => { 35 } + Operator::I64Store { .. } => { 36 } + Operator::F32Store { .. } => { 37 } + Operator::F64Store { .. } => { 38 } + Operator::I32Store8 { .. } => { 39 } + Operator::I32Store16 { .. } => { 40 } + Operator::I64Store8 { .. } => { 41 } + Operator::I64Store16 { .. } => { 42 } + Operator::I64Store32 { .. } => { 43 } + Operator::MemorySize { .. } => { 44 } + Operator::MemoryGrow { .. } => { 45 } + Operator::I32Const { .. } => { 46 } + Operator::I64Const { .. } => { 47 } + Operator::F32Const { .. } => { 48 } + Operator::F64Const { .. } => { 49 } + Operator::RefNull { .. } => { 50 } + Operator::RefIsNull { .. } => { 51 } + Operator::RefFunc { .. } => { 52 } + Operator::I32Eqz { .. } => { 53 } + Operator::I32Eq { .. } => { 54 } + Operator::I32Ne { .. } => { 55 } + Operator::I32LtS { .. } => { 56 } + Operator::I32LtU { .. } => { 57 } + Operator::I32GtS { .. } => { 58 } + Operator::I32GtU { .. } => { 59 } + Operator::I32LeS { .. } => { 60 } + Operator::I32LeU { .. } => { 61 } + Operator::I32GeS { .. } => { 62 } + Operator::I32GeU { .. } => { 63 } + Operator::I64Eqz { .. } => { 64 } + Operator::I64Eq { .. } => { 65 } + Operator::I64Ne { .. } => { 66 } + Operator::I64LtS { .. } => { 67 } + Operator::I64LtU { .. } => { 68 } + Operator::I64GtS { .. } => { 69 } + Operator::I64GtU { .. } => { 70 } + Operator::I64LeS { .. } => { 71 } + Operator::I64LeU { .. } => { 72 } + Operator::I64GeS { .. } => { 73 } + Operator::I64GeU { .. } => { 74 } + Operator::F32Eq { .. } => { 75 } + Operator::F32Ne { .. } => { 76 } + Operator::F32Lt { .. } => { 77 } + Operator::F32Gt { .. } => { 78 } + Operator::F32Le { .. } => { 79 } + Operator::F32Ge { .. } => { 80 } + Operator::F64Eq { .. } => { 81 } + Operator::F64Ne { .. } => { 82 } + Operator::F64Lt { .. } => { 83 } + Operator::F64Gt { .. } => { 84 } + Operator::F64Le { .. } => { 85 } + Operator::F64Ge { .. } => { 86 } + Operator::I32Clz { .. } => { 87 } + Operator::I32Ctz { .. } => { 88 } + Operator::I32Popcnt { .. } => { 89 } + Operator::I32Add { .. } => { 90 } + Operator::I32Sub { .. } => { 91 } + Operator::I32Mul { .. } => { 92 } + Operator::I32DivS { .. } => { 93 } + Operator::I32DivU { .. } => { 94 } + Operator::I32RemS { .. } => { 95 } + Operator::I32RemU { .. } => { 96 } + Operator::I32And { .. } => { 97 } + Operator::I32Or { .. } => { 98 } + Operator::I32Xor { .. } => { 99 } + Operator::I32Shl { .. } => { 100 } + Operator::I32ShrS { .. } => { 101 } + Operator::I32ShrU { .. } => { 102 } + Operator::I32Rotl { .. } => { 103 } + Operator::I32Rotr { .. } => { 104 } + Operator::I64Clz { .. } => { 105 } + Operator::I64Ctz { .. } => { 106 } + Operator::I64Popcnt { .. } => { 107 } + Operator::I64Add { .. } => { 108 } + Operator::I64Sub { .. } => { 109 } + Operator::I64Mul { .. } => { 110 } + Operator::I64DivS { .. } => { 111 } + Operator::I64DivU { .. } => { 112 } + Operator::I64RemS { .. } => { 113 } + Operator::I64RemU { .. } => { 114 } + Operator::I64And { .. } => { 115 } + Operator::I64Or { .. } => { 116 } + Operator::I64Xor { .. } => { 117 } + Operator::I64Shl { .. } => { 118 } + Operator::I64ShrS { .. } => { 119 } + Operator::I64ShrU { .. } => { 120 } + Operator::I64Rotl { .. } => { 121 } + Operator::I64Rotr { .. } => { 122 } + Operator::F32Abs { .. } => { 123 } + Operator::F32Neg { .. } => { 124 } + Operator::F32Ceil { .. } => { 125 } + Operator::F32Floor { .. } => { 126 } + Operator::F32Trunc { .. } => { 127 } + Operator::F32Nearest { .. } => { 128 } + Operator::F32Sqrt { .. } => { 129 } + Operator::F32Add { .. } => { 130 } + Operator::F32Sub { .. } => { 131 } + Operator::F32Mul { .. } => { 132 } + Operator::F32Div { .. } => { 133 } + Operator::F32Min { .. } => { 134 } + Operator::F32Max { .. } => { 135 } + Operator::F32Copysign { .. } => { 136 } + Operator::F64Abs { .. } => { 137 } + Operator::F64Neg { .. } => { 138 } + Operator::F64Ceil { .. } => { 139 } + Operator::F64Floor { .. } => { 140 } + Operator::F64Trunc { .. } => { 141 } + Operator::F64Nearest { .. } => { 142 } + Operator::F64Sqrt { .. } => { 143 } + Operator::F64Add { .. } => { 144 } + Operator::F64Sub { .. } => { 145 } + Operator::F64Mul { .. } => { 146 } + Operator::F64Div { .. } => { 147 } + Operator::F64Min { .. } => { 148 } + Operator::F64Max { .. } => { 149 } + Operator::F64Copysign { .. } => { 150 } + Operator::I32WrapI64 { .. } => { 151 } + Operator::I32TruncF32S { .. } => { 152 } + Operator::I32TruncF32U { .. } => { 153 } + Operator::I32TruncF64S { .. } => { 154 } + Operator::I32TruncF64U { .. } => { 155 } + Operator::I64ExtendI32S { .. } => { 156 } + Operator::I64ExtendI32U { .. } => { 157 } + Operator::I64TruncF32S { .. } => { 158 } + Operator::I64TruncF32U { .. } => { 159 } + Operator::I64TruncF64S { .. } => { 160 } + Operator::I64TruncF64U { .. } => { 161 } + Operator::F32ConvertI32S { .. } => { 162 } + Operator::F32ConvertI32U { .. } => { 163 } + Operator::F32ConvertI64S { .. } => { 164 } + Operator::F32ConvertI64U { .. } => { 165 } + Operator::F32DemoteF64 { .. } => { 166 } + Operator::F64ConvertI32S { .. } => { 167 } + Operator::F64ConvertI32U { .. } => { 168 } + Operator::F64ConvertI64S { .. } => { 169 } + Operator::F64ConvertI64U { .. } => { 170 } + Operator::F64PromoteF32 { .. } => { 171 } + Operator::I32ReinterpretF32 { .. } => { 172 } + Operator::I64ReinterpretF64 { .. } => { 173 } + Operator::F32ReinterpretI32 { .. } => { 174 } + Operator::F64ReinterpretI64 { .. } => { 175 } + Operator::I32Extend8S { .. } => { 176 } + Operator::I32Extend16S { .. } => { 177 } + Operator::I64Extend8S { .. } => { 178 } + Operator::I64Extend16S { .. } => { 179 } + Operator::I64Extend32S { .. } => { 180 } + Operator::I32TruncSatF32S { .. } => { 181 } + Operator::I32TruncSatF32U { .. } => { 182 } + Operator::I32TruncSatF64S { .. } => { 183 } + Operator::I32TruncSatF64U { .. } => { 184 } + Operator::I64TruncSatF32S { .. } => { 185 } + Operator::I64TruncSatF32U { .. } => { 186 } + Operator::I64TruncSatF64S { .. } => { 187 } + Operator::I64TruncSatF64U { .. } => { 188 } + Operator::MemoryInit { .. } => { 189 } + Operator::DataDrop { .. } => { 190 } + Operator::MemoryCopy { .. } => { 191 } + Operator::MemoryFill { .. } => { 192 } + Operator::TableInit { .. } => { 193 } + Operator::ElemDrop { .. } => { 194 } + Operator::TableCopy { .. } => { 195 } + Operator::TableFill { .. } => {194 } + Operator::TableGet { .. } => { 197 } + Operator::TableSet { .. } => { 198 } + Operator::TableGrow { .. } => { 199 } + Operator::TableSize { .. } => { 200 } + Operator::AtomicNotify { .. } => { 201 } + Operator::I32AtomicWait { .. } => { 202 } + Operator::I64AtomicWait { .. } => { 203 } + Operator::AtomicFence { .. } => { 204 } + Operator::I32AtomicLoad { .. } => { 205 } + Operator::I64AtomicLoad { .. } => { 206 } + Operator::I32AtomicLoad8U { .. } => { 207 } + Operator::I32AtomicLoad16U { .. } => { 208 } + Operator::I64AtomicLoad8U { .. } => { 209 } + Operator::I64AtomicLoad16U { .. } => { 210 } + Operator::I64AtomicLoad32U { .. } => { 211 } + Operator::I32AtomicStore { .. } => { 212 } + Operator::I64AtomicStore { .. } => { 213 } + Operator::I32AtomicStore8 { .. } => { 214 } + Operator::I32AtomicStore16 { .. } => { 215 } + Operator::I64AtomicStore8 { .. } => { 216 } + Operator::I64AtomicStore16 { .. } => { 217 } + Operator::I64AtomicStore32 { .. } => { 218 } + Operator::I32AtomicRmwAdd { .. } => { 219 } + Operator::I64AtomicRmwAdd { .. } => { 220 } + Operator::I32AtomicRmw8AddU { .. } => { 221 } + Operator::I32AtomicRmw16AddU { .. } => { 222 } + Operator::I64AtomicRmw8AddU { .. } => { 223 } + Operator::I64AtomicRmw16AddU { .. } => { 224 } + Operator::I64AtomicRmw32AddU { .. } => { 225 } + Operator::I32AtomicRmwSub { .. } => { 226 } + Operator::I64AtomicRmwSub { .. } => { 227 } + Operator::I32AtomicRmw8SubU { .. } => { 228 } + Operator::I32AtomicRmw16SubU { .. } => { 229 } + Operator::I64AtomicRmw8SubU { .. } => { 230 } + Operator::I64AtomicRmw16SubU { .. } => { 231 } + Operator::I64AtomicRmw32SubU { .. } => { 232 } + Operator::I32AtomicRmwAnd { .. } => { 233 } + Operator::I64AtomicRmwAnd { .. } => { 234 } + Operator::I32AtomicRmw8AndU { .. } => { 235 } + Operator::I32AtomicRmw16AndU { .. } => { 236 } + Operator::I64AtomicRmw8AndU { .. } => { 237 } + Operator::I64AtomicRmw16AndU { .. } => { 238 } + Operator::I64AtomicRmw32AndU { .. } => { 239 } + Operator::I32AtomicRmwOr { .. } => { 240 } + Operator::I64AtomicRmwOr { .. } => { 241 } + Operator::I32AtomicRmw8OrU { .. } => { 242 } + Operator::I32AtomicRmw16OrU { .. } => { 243 } + Operator::I64AtomicRmw8OrU { .. } => { 244 } + Operator::I64AtomicRmw16OrU { .. } => { 245 } + Operator::I64AtomicRmw32OrU { .. } => { 246 } + Operator::I32AtomicRmwXor { .. } => { 247 } + Operator::I64AtomicRmwXor { .. } => { 248 } + Operator::I32AtomicRmw8XorU { .. } => { 249 } + Operator::I32AtomicRmw16XorU { .. } => { 250 } + Operator::I64AtomicRmw8XorU { .. } => { 251 } + Operator::I64AtomicRmw16XorU { .. } => { 252 } + Operator::I64AtomicRmw32XorU { .. } => { 253 } + Operator::I32AtomicRmwXchg { .. } => { 254 } + Operator::I64AtomicRmwXchg { .. } => { 255 } + Operator::I32AtomicRmw8XchgU { .. } => { 256 } + Operator::I32AtomicRmw16XchgU { .. } => { 257 } + Operator::I64AtomicRmw8XchgU { .. } => { 258 } + Operator::I64AtomicRmw16XchgU { .. } => { 259 } + Operator::I64AtomicRmw32XchgU { .. } => { 260 } + Operator::I32AtomicRmwCmpxchg { .. } => { 261 } + Operator::I64AtomicRmwCmpxchg { .. } => { 262 } + Operator::I32AtomicRmw8CmpxchgU { .. } => { 263 } + Operator::I32AtomicRmw16CmpxchgU { .. } => { 264 } + Operator::I64AtomicRmw8CmpxchgU { .. } => { 265 } + Operator::I64AtomicRmw16CmpxchgU { .. } => { 266 } + Operator::I64AtomicRmw32CmpxchgU { .. } => { 267 } + Operator::V128Load { .. } => { 268 } + Operator::V128Store { .. } => { 269 } + Operator::V128Const { .. } => { 270 } + Operator::I8x16Splat { .. } => { 271 } + Operator::I8x16ExtractLaneS { .. } => { 272 } + Operator::I8x16ExtractLaneU { .. } => { 273 } + Operator::I8x16ReplaceLane { .. } => { 274 } + Operator::I16x8Splat { .. } => { 275 } + Operator::I16x8ExtractLaneS { .. } => { 276 } + Operator::I16x8ExtractLaneU { .. } => { 277 } + Operator::I16x8ReplaceLane { .. } => { 278 } + Operator::I32x4Splat { .. } => { 279 } + Operator::I32x4ExtractLane { .. } => { 280 } + Operator::I32x4ReplaceLane { .. } => { 281 } + Operator::I64x2Splat { .. } => { 282 } + Operator::I64x2ExtractLane { .. } => { 283 } + Operator::I64x2ReplaceLane { .. } => { 284 } + Operator::F32x4Splat { .. } => { 285 } + Operator::F32x4ExtractLane { .. } => { 286 } + Operator::F32x4ReplaceLane { .. } => { 287 } + Operator::F64x2Splat { .. } => { 288 } + Operator::F64x2ExtractLane { .. } => { 289 } + Operator::F64x2ReplaceLane { .. } => { 290 } + Operator::I8x16Eq { .. } => { 291 } + Operator::I8x16Ne { .. } => { 292 } + Operator::I8x16LtS { .. } => { 293 } + Operator::I8x16LtU { .. } => { 294 } + Operator::I8x16GtS { .. } => { 295 } + Operator::I8x16GtU { .. } => { 296 } + Operator::I8x16LeS { .. } => { 297 } + Operator::I8x16LeU { .. } => { 298 } + Operator::I8x16GeS { .. } => { 299 } + Operator::I8x16GeU { .. } => { 300 } + Operator::I16x8Eq { .. } => { 301 } + Operator::I16x8Ne { .. } => { 302 } + Operator::I16x8LtS { .. } => { 303 } + Operator::I16x8LtU { .. } => { 304 } + Operator::I16x8GtS { .. } => { 305 } + Operator::I16x8GtU { .. } => { 306 } + Operator::I16x8LeS { .. } => { 307 } + Operator::I16x8LeU { .. } => { 308 } + Operator::I16x8GeS { .. } => { 309 } + Operator::I16x8GeU { .. } => { 310 } + Operator::I32x4Eq { .. } => { 311 } + Operator::I32x4Ne { .. } => { 312 } + Operator::I32x4LtS { .. } => { 313 } + Operator::I32x4LtU { .. } => { 314 } + Operator::I32x4GtS { .. } => { 315 } + Operator::I32x4GtU { .. } => { 316 } + Operator::I32x4LeS { .. } => { 317 } + Operator::I32x4LeU { .. } => { 318 } + Operator::I32x4GeS { .. } => { 319 } + Operator::I32x4GeU { .. } => { 320 } + Operator::F32x4Eq { .. } => { 321 } + Operator::F32x4Ne { .. } => { 322 } + Operator::F32x4Lt { .. } => { 323 } + Operator::F32x4Gt { .. } => { 324 } + Operator::F32x4Le { .. } => { 325 } + Operator::F32x4Ge { .. } => { 326 } + Operator::F64x2Eq { .. } => { 327 } + Operator::F64x2Ne { .. } => { 328 } + Operator::F64x2Lt { .. } => { 329 } + Operator::F64x2Gt { .. } => { 330 } + Operator::F64x2Le { .. } => { 331 } + Operator::F64x2Ge { .. } => { 332 } + Operator::V128Not { .. } => { 333 } + Operator::V128And { .. } => { 334 } + Operator::V128AndNot { .. } => { 335 } + Operator::V128Or { .. } => { 336 } + Operator::V128Xor { .. } => { 337 } + Operator::V128Bitselect { .. } => { 338 } + Operator::I8x16Neg { .. } => { 339 } + Operator::I8x16AnyTrue { .. } => { 340 } + Operator::I8x16AllTrue { .. } => { 341 } + Operator::I8x16Shl { .. } => { 342 } + Operator::I8x16ShrS { .. } => { 343 } + Operator::I8x16ShrU { .. } => { 344 } + Operator::I8x16Add { .. } => { 345 } + Operator::I8x16AddSaturateS { .. } => { 346 } + Operator::I8x16AddSaturateU { .. } => { 347 } + Operator::I8x16Sub { .. } => { 348 } + Operator::I8x16SubSaturateS { .. } => { 349 } + Operator::I8x16SubSaturateU { .. } => { 350 } + Operator::I8x16MinS { .. } => { 354 }, + Operator::I8x16MinU { .. } => { 354 }, + Operator::I8x16MaxS { .. } => { 354 }, + Operator::I8x16MaxU { .. } => { 354 }, + Operator::I8x16Mul { .. } => { 355 } + Operator::I16x8Neg { .. } => { 356 } + Operator::I16x8AnyTrue { .. } => { 357 } + Operator::I16x8AllTrue { .. } => { 358 } + Operator::I16x8Shl { .. } => { 359 } + Operator::I16x8ShrS { .. } => { 360 } + Operator::I16x8ShrU { .. } => { 361 } + Operator::I16x8Add { .. } => { 362 } + Operator::I16x8AddSaturateS { .. } => { 363 } + Operator::I16x8AddSaturateU { .. } => { 364 } + Operator::I16x8Sub { .. } => { 365 } + Operator::I16x8SubSaturateS { .. } => { 366 } + Operator::I16x8SubSaturateU { .. } => { 367 } + Operator::I16x8Mul { .. } => { 368 } + Operator::I16x8MinS { .. } => { 369 } + Operator::I16x8MinU { .. } => { 370 } + Operator::I16x8MaxS { .. } => { 371 } + Operator::I16x8MaxU { .. } => { 372 } + Operator::I32x4Neg { .. } => { 373 } + Operator::I32x4AnyTrue { .. } => { 374 } + Operator::I32x4AllTrue { .. } => { 375 } + Operator::I32x4Shl { .. } => { 376 } + Operator::I32x4ShrS { .. } => { 377 } + Operator::I32x4ShrU { .. } => { 378 } + Operator::I32x4Add { .. } => { 379 } + Operator::I32x4Sub { .. } => { 380 } + Operator::I32x4Mul { .. } => { 381 } + Operator::I32x4MinS { .. } => { 382 } + Operator::I32x4MinU { .. } => { 383 } + Operator::I32x4MaxS { .. } => { 384 } + Operator::I32x4MaxU { .. } => { 385 } + Operator::I64x2Neg { .. } => { 386 } + Operator::I64x2AnyTrue { .. } => { 387 } + Operator::I64x2AllTrue { .. } => { 388 } + Operator::I64x2Shl { .. } => { 389 } + Operator::I64x2ShrS { .. } => { 390 } + Operator::I64x2ShrU { .. } => { 391 } + Operator::I64x2Add { .. } => { 392 } + Operator::I64x2Sub { .. } => { 393 } + Operator::I64x2Mul { .. } => { 394 } + Operator::F32x4Abs { .. } => { 395 } + Operator::F32x4Neg { .. } => { 396 } + Operator::F32x4Sqrt { .. } => { 397 } + Operator::F32x4Add { .. } => { 398 } + Operator::F32x4Sub { .. } => { 399 } + Operator::F32x4Mul { .. } => { 400 } + Operator::F32x4Div { .. } => { 401 } + Operator::F32x4Min { .. } => { 402 } + Operator::F32x4Max { .. } => { 403 } + Operator::F64x2Abs { .. } => { 404 } + Operator::F64x2Neg { .. } => { 405 } + Operator::F64x2Sqrt { .. } => { 406 } + Operator::F64x2Add { .. } => { 407 } + Operator::F64x2Sub { .. } => { 408 } + Operator::F64x2Mul { .. } => { 409 } + Operator::F64x2Div { .. } => { 410 } + Operator::F64x2Min { .. } => { 411 } + Operator::F64x2Max { .. } => { 412 } + Operator::I32x4TruncSatF32x4S { .. } => { 413 } + Operator::I32x4TruncSatF32x4U { .. } => { 414 } + Operator::I64x2TruncSatF64x2S { .. } => { 415 } + Operator::I64x2TruncSatF64x2U { .. } => { 416 } + Operator::F32x4ConvertI32x4S { .. } => { 417 } + Operator::F32x4ConvertI32x4U { .. } => { 418 } + Operator::F64x2ConvertI64x2S { .. } => { 419 } + Operator::F64x2ConvertI64x2U { .. } => { 420 } + Operator::V8x16Swizzle { .. } => { 421 } + Operator::V8x16Shuffle { .. } => { 422 } + Operator::V8x16LoadSplat { .. } => { 423 } + Operator::V16x8LoadSplat { .. } => { 424 } + Operator::V32x4LoadSplat { .. } => { 425 } + Operator::V64x2LoadSplat { .. } => { 426 } + Operator::I8x16NarrowI16x8S { .. } => { 427 } + Operator::I8x16NarrowI16x8U { .. } => { 428 } + Operator::I16x8NarrowI32x4S { .. } => { 429 } + Operator::I16x8NarrowI32x4U { .. } => { 430 } + Operator::I16x8WidenLowI8x16S { .. } => { 431 } + Operator::I16x8WidenHighI8x16S { .. } => { 432 } + Operator::I16x8WidenLowI8x16U { .. } => { 433 } + Operator::I16x8WidenHighI8x16U { .. } => { 434 } + Operator::I32x4WidenLowI16x8S { .. } => { 435 } + Operator::I32x4WidenHighI16x8S { .. } => { 436 } + Operator::I32x4WidenLowI16x8U { .. } => { 437 } + Operator::I32x4WidenHighI16x8U { .. } => { 438 } + Operator::I16x8Load8x8S { .. } => { 439 } + Operator::I16x8Load8x8U { .. } => { 440 } + Operator::I32x4Load16x4S { .. } => { 441 } + Operator::I32x4Load16x4U { .. } => { 442 } + Operator::I64x2Load32x2S { .. } => { 443 } + Operator::I64x2Load32x2U { .. } => { 444 } + Operator::I8x16RoundingAverageU { .. } => { 445 } + Operator::I16x8RoundingAverageU { .. } => { 446 } } } diff --git a/lib/middleware-common/src/runtime_breakpoints.rs b/lib/middleware-common/src/runtime_breakpoints.rs index 8336bfd89d85..178d935b52e9 100644 --- a/lib/middleware-common/src/runtime_breakpoints.rs +++ b/lib/middleware-common/src/runtime_breakpoints.rs @@ -29,7 +29,7 @@ impl FunctionMiddleware for RuntimeBreakpointHandler { op: Event<'a, 'b>, _module_info: &ModuleInfo, sink: &mut EventSink<'a, 'b>, - source_loc: u32, + _source_loc: u32, ) -> Result<(), Self::Error> { let must_add_breakpoint = match op { @@ -59,7 +59,7 @@ impl FunctionMiddleware for RuntimeBreakpointHandler { ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), })); sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(|_| { - Err(Box::new(RuntimeError::Trap { msg: Box::from("execution limit exceeded") })) + Err(Box::new(RuntimeError(Box::new("breakpoint reached".to_string())))) })))); sink.push(Event::WasmOwned(Operator::End)); } diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 1882904ef489..e023d92d6fb1 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -17,7 +17,7 @@ use wasmer_runtime_core::backend::Compiler; #[cfg(not(feature = "cranelift-backend"))] use wasmer_middleware_common::metering; -pub const OPCODE_COUNT: usize = 410; +pub const OPCODE_COUNT: usize = 447; static mut OPCODE_COSTS: [u32; OPCODE_COUNT] = [0; OPCODE_COUNT]; static mut OPCODE_COSTS_INITIALIZED: bool = false; From fbeb61678a0857c707b57072765eb99ce1f49d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Thu, 5 Mar 2020 18:02:54 +0200 Subject: [PATCH 049/129] Adjustments and Cargo.lock --- Cargo.lock | 2219 +++++++++++++++++++++++++++++++++++ lib/runtime-c-api/wasmer.h | 2 +- lib/runtime-c-api/wasmer.hh | 2 +- 3 files changed, 2221 insertions(+), 2 deletions(-) create mode 100644 Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 000000000000..2e36eae45eca --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,2219 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aho-corasick" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5e63fd144e18ba274ae7095c0197a870a7b9468abc801dd62f190d80817d2ec" +dependencies = [ + "memchr", +] + +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi", +] + +[[package]] +name = "anyhow" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7825f6833612eb2414095684fcf6c635becf3ce97fe48cf6421321e93bfbd53c" + +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "arrayvec" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9" +dependencies = [ + "nodrop", +] + +[[package]] +name = "arrayvec" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" + +[[package]] +name = "autocfg" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" + +[[package]] +name = "bincode" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5753e2a71534719bf3f4e57006c3a4f0d2c672a4b676eec84161f763eca87dbf" +dependencies = [ + "byteorder", + "serde", +] + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "blake3" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46080006c1505f12f64dd2a09264b343381ed3190fa02c8005d5d662ac571c63" +dependencies = [ + "arrayref", + "arrayvec 0.5.1", + "cc", + "cfg-if", + "constant_time_eq", + "crypto-mac", + "digest", +] + +[[package]] +name = "bstr" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "502ae1441a0a5adb8fbd38a5955a6416b9493e92b465de5e4a9bde6a539c2c48" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata", + "serde", +] + +[[package]] +name = "byteorder" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" + +[[package]] +name = "c2-chacha" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb" +dependencies = [ + "ppv-lite86", +] + +[[package]] +name = "cast" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" +dependencies = [ + "rustc_version", +] + +[[package]] +name = "cbindgen" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9daec6140ab4dcd38c3dd57e580b59a621172a526ac79f1527af760a55afeafd" +dependencies = [ + "clap", + "log", + "proc-macro2 1.0.9", + "quote 1.0.3", + "serde", + "serde_json", + "syn 1.0.16", + "tempfile", + "toml", +] + +[[package]] +name = "cc" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "chrono" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31850b4a4d6bae316f7a09e691c944c28299298837edc0a03f755618c23cbc01" +dependencies = [ + "num-integer", + "num-traits", + "time", +] + +[[package]] +name = "clap" +version = "2.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "cmake" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62" +dependencies = [ + "cc", +] + +[[package]] +name = "colored" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" +dependencies = [ + "atty", + "lazy_static", + "winapi", +] + +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "cranelift-bforest" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45a9c21f8042b9857bda93f6c1910b9f9f24100187a3d3d52f214a34e3dc5818" +dependencies = [ + "cranelift-entity 0.59.0", +] + +[[package]] +name = "cranelift-codegen" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7853f77a6e4a33c67a69c40f5e1bb982bd2dc5c4a22e17e67b65bbccf9b33b2e" +dependencies = [ + "byteorder", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-entity 0.59.0", + "gimli", + "log", + "smallvec 1.2.0", + "target-lexicon 0.10.0", + "thiserror", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084cd6d5fb0d1da28acd72c199471bfb09acc703ec8f3bf07b1699584272a3b9" +dependencies = [ + "cranelift-codegen-shared", + "cranelift-entity 0.59.0", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "701b599783305a58c25027a4d73f2d6b599b2d8ef3f26677275f480b4d51e05d" + +[[package]] +name = "cranelift-entity" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "722957e05064d97a3157bf0976deed0f3e8ee4f8a4ce167a7c724ca63a4e8bd9" + +[[package]] +name = "cranelift-entity" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b88e792b28e1ebbc0187b72ba5ba880dad083abe9231a99d19604d10c9e73f38" + +[[package]] +name = "cranelift-native" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32daf082da21c0c05d93394ff4842c2ab7c4991b1f3186a1d952f8ac660edd0b" +dependencies = [ + "cranelift-codegen", + "raw-cpuid", + "target-lexicon 0.10.0", +] + +[[package]] +name = "criterion" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0363053954f3e679645fc443321ca128b7b950a6fe288cf5f9335cc22ee58394" +dependencies = [ + "atty", + "cast", + "clap", + "criterion-plot", + "csv", + "itertools", + "lazy_static", + "libc", + "num-traits", + "rand_core 0.3.1", + "rand_os", + "rand_xoshiro", + "rayon", + "rayon-core", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f9212ddf2f4a9eb2d401635190600656a1f88a932ef53d06e7fa4c7e02fb8e" +dependencies = [ + "byteorder", + "cast", + "itertools", +] + +[[package]] +name = "crossbeam-deque" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", + "maybe-uninit", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" +dependencies = [ + "autocfg 1.0.0", + "cfg-if", + "crossbeam-utils", + "lazy_static", + "maybe-uninit", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-queue" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c695eeca1e7173472a32221542ae469b3e9aac3a4fc81f7696bcad82029493db" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +dependencies = [ + "autocfg 1.0.0", + "cfg-if", + "lazy_static", +] + +[[package]] +name = "crypto-mac" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "csv" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00affe7f6ab566df61b4be3ce8cf16bc2576bca0963ceb0955e45d514bf9a279" +dependencies = [ + "bstr", + "csv-core", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" +dependencies = [ + "memchr", +] + +[[package]] +name = "ctor" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47c5e5ac752e18207b12e16b10631ae5f7f68f8805f335f9b817ead83d9ffce1" +dependencies = [ + "quote 1.0.3", + "syn 1.0.16", +] + +[[package]] +name = "digest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +dependencies = [ + "generic-array", +] + +[[package]] +name = "dynasm" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42a814e1edeb85dd2a3c6fc0d6bf76d02ca5695d438c70ecee3d90774f3259c5" +dependencies = [ + "bitflags", + "byteorder", + "lazy_static", + "owning_ref", + "proc-macro2 1.0.9", + "quote 1.0.3", + "syn 1.0.16", +] + +[[package]] +name = "dynasmrt" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a393aaeb4441a48bcf47b5b6155971f82cc1eb77e22855403ccc0415ac8328d" +dependencies = [ + "byteorder", + "memmap", +] + +[[package]] +name = "either" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" + +[[package]] +name = "erased-serde" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd7d80305c9bd8cd78e3c753eb9fb110f83621e5211f1a3afffcc812b104daf9" +dependencies = [ + "serde", +] + +[[package]] +name = "errno" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a071601ed01b988f896ab14b95e67335d1eeb50190932a1320f7fe3cadc84e" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" +dependencies = [ + "gcc", + "libc", +] + +[[package]] +name = "faerie" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f902f2af041f6c7177a2a04f805687cdc71e69c7cbef059a2755d8923f4cd7a8" +dependencies = [ + "anyhow", + "goblin 0.1.3", + "indexmap", + "log", + "scroll 0.10.1", + "string-interner", + "target-lexicon 0.9.0", + "thiserror", +] + +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + +[[package]] +name = "fern" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e69ab0d5aca163e388c3a49d284fed6c3d0810700e77c5ae2756a50ec1a4daaa" +dependencies = [ + "chrono", + "colored", + "log", +] + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "gcc" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" + +[[package]] +name = "generational-arena" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e40d0cee2e2fb4fba18b55a27bf96faf49fa86d49f178695bd3bf4500b156b4" +dependencies = [ + "cfg-if", + "serde", +] + +[[package]] +name = "generic-array" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +dependencies = [ + "typenum", +] + +[[package]] +name = "getrandom" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "ghost" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a36606a68532b5640dc86bb1f33c64b45c4682aad4c50f3937b317ea387f3d6" +dependencies = [ + "proc-macro2 1.0.9", + "quote 1.0.3", + "syn 1.0.16", +] + +[[package]] +name = "gimli" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81dd6190aad0f05ddbbf3245c54ed14ca4aa6dd32f22312b70d8f168c3e3e633" +dependencies = [ + "arrayvec 0.5.1", + "byteorder", + "fallible-iterator", + "indexmap", + "smallvec 1.2.0", + "stable_deref_trait", +] + +[[package]] +name = "glob" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" + +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + +[[package]] +name = "goblin" +version = "0.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3fa261d919c1ae9d1e4533c4a2f99e10938603c4208d56c05bec7a872b661b0" +dependencies = [ + "log", + "plain", + "scroll 0.9.2", +] + +[[package]] +name = "goblin" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3081214398d39e4bd7f2c1975f0488ed04614ffdd976c6fc7a0708278552c0da" +dependencies = [ + "log", + "plain", + "scroll 0.10.1", +] + +[[package]] +name = "heck" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1010591b26bbfe835e9faeabeb11866061cc7dcebffd56ad7d0942d0e61aefd8" +dependencies = [ + "libc", +] + +[[package]] +name = "hex" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" + +[[package]] +name = "indexmap" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "076f042c5b7b98f31d205f1249267e12a6518c1481e9dae9764af19b707d2292" +dependencies = [ + "autocfg 1.0.0", + "serde", +] + +[[package]] +name = "inkwell" +version = "0.1.0" +source = "git+https://github.com/TheDan64/inkwell?rev=0a864ebf68b33d4d514b67796264b03898aa0944#0a864ebf68b33d4d514b67796264b03898aa0944" +dependencies = [ + "either", + "inkwell_internals", + "libc", + "llvm-sys", + "once_cell", + "parking_lot", + "regex", +] + +[[package]] +name = "inkwell_internals" +version = "0.1.0" +source = "git+https://github.com/TheDan64/inkwell?rev=0a864ebf68b33d4d514b67796264b03898aa0944#0a864ebf68b33d4d514b67796264b03898aa0944" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", +] + +[[package]] +name = "inventory" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bf98296081bd2cb540acc09ef9c97f22b7e487841520350293605db1b2c7a27" +dependencies = [ + "ctor", + "ghost", + "inventory-impl", +] + +[[package]] +name = "inventory-impl" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a8e30575afe28eea36a9a39136b70b2fb6b0dd0a212a5bd1f30a498395c0274" +dependencies = [ + "proc-macro2 1.0.9", + "quote 1.0.3", + "syn 1.0.16", +] + +[[package]] +name = "itertools" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" + +[[package]] +name = "kernel-net" +version = "0.1.0" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "leb128" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" + +[[package]] +name = "lexical-core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7043aa5c05dd34fb73b47acb8c3708eac428de4545ea3682ed2f11293ebd890" +dependencies = [ + "arrayvec 0.4.12", + "cfg-if", + "rustc_version", + "ryu", + "static_assertions", +] + +[[package]] +name = "libc" +version = "0.2.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018" + +[[package]] +name = "llvm-sys" +version = "80.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf2969773884a5701f0c255e2a14d48d4522a66db898ec1088cb21879a228377" +dependencies = [ + "cc", + "lazy_static", + "libc", + "regex", + "semver", +] + +[[package]] +name = "lock_api" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79b2de95ecb4691949fea4716ca53cdbcfccb2c612e19644a8bad05edcf9f47b" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "maybe-uninit" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" + +[[package]] +name = "md5" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e6bcd6433cff03a4bfc3d9834d504467db1f1cf6d0ea765d37d330249ed629d" + +[[package]] +name = "memchr" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" + +[[package]] +name = "memmap" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "memoffset" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75189eb85871ea5c2e2c15abbdd541185f63b408415e5051f5cac122d8c774b9" +dependencies = [ + "rustc_version", +] + +[[package]] +name = "minifb" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cbdf43445926b65e07992f06019321e7481df8fd656dcb6871d00cdbd9fc73" +dependencies = [ + "cast", + "cc", + "orbclient", + "time", + "winapi", + "x11-dl", +] + +[[package]] +name = "more-asserts" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238" + +[[package]] +name = "nix" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2e0b4f3320ed72aaedb9a5ac838690a8047c7b275da22711fddff4f8a14229" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", + "void", +] + +[[package]] +name = "nodrop" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" + +[[package]] +name = "nom" +version = "5.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b471253da97532da4b61552249c521e01e736071f71c1a4f7ebbfbf0a06aad6" +dependencies = [ + "lexical-core", + "memchr", + "version_check", +] + +[[package]] +name = "num" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" +dependencies = [ + "num-integer", + "num-iter", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba" +dependencies = [ + "autocfg 1.0.0", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfb0800a0291891dd9f4fe7bd9c19384f98f7fbe0cd0f39a2c6b88b9868bbc00" +dependencies = [ + "autocfg 1.0.0", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" +dependencies = [ + "autocfg 1.0.0", +] + +[[package]] +name = "num_cpus" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46203554f085ff89c235cd12f7075f3233af9b11ed7c9e16dfe2560d03313ce6" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b" + +[[package]] +name = "orbclient" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8b18f57ab94fbd058e30aa57f712ec423c0bb7403f8493a6c58eef0c36d9402" +dependencies = [ + "redox_syscall", + "sdl2", +] + +[[package]] +name = "owning_ref" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff55baddef9e4ad00f88b6c743a2a8062d4c6ade126c2a528644b8e444d52ce" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "page_size" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eebde548fbbf1ea81a99b128872779c437752fb99f217c45245e1a61dcd9edcd" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "parallel" +version = "0.1.0" +dependencies = [ + "rayon", + "time", + "wasmer-runtime", + "wasmer-runtime-core", +] + +[[package]] +name = "parallel-guest" +version = "0.1.0" +dependencies = [ + "lazy_static", + "md5", +] + +[[package]] +name = "parking_lot" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e98c49ab0b7ce5b222f2cc9193fc4efe11c6d0bd4f648e374684a6857b1cfc" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7582838484df45743c8434fbff785e8edf260c28748353d44bc0da32e0ceabf1" +dependencies = [ + "cfg-if", + "cloudabi", + "libc", + "redox_syscall", + "smallvec 1.2.0", + "winapi", +] + +[[package]] +name = "pkg-config" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" + +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + +[[package]] +name = "plugin-for-example" +version = "0.1.0" + +[[package]] +name = "ppv-lite86" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" + +[[package]] +name = "proc-macro-error" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7959c6467d962050d639361f7703b2051c43036d03493c36f01d440fdd3138a" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2 1.0.9", + "quote 1.0.3", + "syn 1.0.16", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4002d9f55991d5e019fb940a90e1a95eb80c24e77cb2462dd4dc869604d543a" +dependencies = [ + "proc-macro2 1.0.9", + "quote 1.0.3", + "syn 1.0.16", + "syn-mid", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid 0.1.0", +] + +[[package]] +name = "proc-macro2" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435" +dependencies = [ + "unicode-xid 0.2.0", +] + +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", +] + +[[package]] +name = "quote" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" +dependencies = [ + "proc-macro2 1.0.9", +] + +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +dependencies = [ + "autocfg 0.1.7", + "libc", + "rand_chacha 0.1.1", + "rand_core 0.4.2", + "rand_hc 0.1.0", + "rand_isaac", + "rand_jitter", + "rand_os", + "rand_pcg", + "rand_xorshift", + "winapi", +] + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom", + "libc", + "rand_chacha 0.2.1", + "rand_core 0.5.1", + "rand_hc 0.2.0", +] + +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.3.1", +] + +[[package]] +name = "rand_chacha" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" +dependencies = [ + "c2-chacha", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_jitter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" +dependencies = [ + "libc", + "rand_core 0.4.2", + "winapi", +] + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +dependencies = [ + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.4.2", + "rdrand", + "winapi", +] + +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.4.2", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_xoshiro" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b418169fb9c46533f326efd6eed2576699c44ca92d3052a066214a8d828929" +dependencies = [ + "byteorder", + "rand_core 0.3.1", +] + +[[package]] +name = "raw-cpuid" +version = "7.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4a349ca83373cfa5d6dbb66fd76e58b2cca08da71a5f6400de0a0a6a9bceeaf" +dependencies = [ + "bitflags", + "cc", + "rustc_version", +] + +[[package]] +name = "rayon" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db6ce3297f9c85e16621bb8cca38a06779ffc31bb8184e1be4bed2be4678a098" +dependencies = [ + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08a89b46efaf957e52b18062fb2f4660f8b8a4dde1807ca002690868ef2c85a9" +dependencies = [ + "crossbeam-deque", + "crossbeam-queue", + "crossbeam-utils", + "lazy_static", + "num_cpus", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "redox_syscall" +version = "0.1.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" + +[[package]] +name = "ref_thread_local" +version = "0.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d813022b2e00774a48eaf43caaa3c20b45f040ba8cbf398e2e8911a06668dbe6" + +[[package]] +name = "regex" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "322cf97724bea3ee221b78fe25ac9c46114ebb51747ad5babd51a2fc6a8235a8" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", +] + +[[package]] +name = "regex-automata" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92b73c2a1770c255c240eaa4ee600df1704a38dc3feaa6e949e7fcd4f8dc09f9" +dependencies = [ + "byteorder", +] + +[[package]] +name = "regex-syntax" +version = "0.6.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1132f845907680735a84409c3bebc64d1364a5683ffbce899550cd09d5eaefc1" + +[[package]] +name = "remove_dir_all" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" +dependencies = [ + "winapi", +] + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] + +[[package]] +name = "ryu" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "scroll" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f84d114ef17fd144153d608fba7c446b0145d038985e7a8cc5d08bb0ce20383" +dependencies = [ + "rustc_version", + "scroll_derive 0.9.5", +] + +[[package]] +name = "scroll" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb2332cb595d33f7edd5700f4cbf94892e680c7f0ae56adab58a35190b66cb1" +dependencies = [ + "scroll_derive 0.10.1", +] + +[[package]] +name = "scroll_derive" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f1aa96c45e7f5a91cb7fabe7b279f02fea7126239fc40b732316e8b6a2d0fcb" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", +] + +[[package]] +name = "scroll_derive" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8584eea9b9ff42825b46faf46a8c24d2cff13ec152fa2a50df788b87c07ee28" +dependencies = [ + "proc-macro2 1.0.9", + "quote 1.0.3", + "syn 1.0.16", +] + +[[package]] +name = "sdl2" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d051a07231e303f5f719da78cb6f7394f6d5b54f733aef5b0b447804a83edd7b" +dependencies = [ + "bitflags", + "lazy_static", + "libc", + "num", + "rand 0.6.5", + "sdl2-sys", +] + +[[package]] +name = "sdl2-sys" +version = "0.32.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34e71125077d297d57e4c1acfe8981b5bdfbf5a20e7b589abfdcb33bf1127f86" +dependencies = [ + "cfg-if", + "libc", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "serde" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-bench" +version = "0.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d733da87e79faaac25616e33d26299a41143fd4cd42746cbb0e91d8feea243fd" +dependencies = [ + "byteorder", + "serde", +] + +[[package]] +name = "serde_bytes" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "325a073952621257820e7a3469f55ba4726d8b28657e7e36653d1c36dc2c84ae" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" +dependencies = [ + "proc-macro2 1.0.9", + "quote 1.0.3", + "syn 1.0.16", +] + +[[package]] +name = "serde_json" +version = "1.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9371ade75d4c2d6cb154141b9752cf3781ec9c05e0e5cf35060e1e70ee7b9c25" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "smallvec" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" +dependencies = [ + "maybe-uninit", +] + +[[package]] +name = "smallvec" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c2fb2ec9bcd216a5b0d0ccf31ab17b5ed1d627960edff65bbe95d3ce221cefc" + +[[package]] +name = "stable_deref_trait" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" + +[[package]] +name = "static_assertions" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f3eb36b47e512f8f1c9e3d10c2c1965bc992bd9cdb024fa581e2194501c83d3" + +[[package]] +name = "string-interner" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd710eadff449a1531351b0e43eb81ea404336fa2f56c777427ab0e32a4cf183" +dependencies = [ + "serde", +] + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "structopt" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fe43617218c0805c6eb37160119dc3c548110a67786da7218d1c6555212f073" +dependencies = [ + "clap", + "lazy_static", + "structopt-derive", +] + +[[package]] +name = "structopt-derive" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6e79c80e0f4efd86ca960218d4e056249be189ff1c42824dcd9a7f51a56f0bd" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2 1.0.9", + "quote 1.0.3", + "syn 1.0.16", +] + +[[package]] +name = "subtle" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" + +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid 0.1.0", +] + +[[package]] +name = "syn" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "123bd9499cfb380418d509322d7a6d52e5315f064fe4b3ad18a53d6b92c07859" +dependencies = [ + "proc-macro2 1.0.9", + "quote 1.0.3", + "unicode-xid 0.2.0", +] + +[[package]] +name = "syn-mid" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a" +dependencies = [ + "proc-macro2 1.0.9", + "quote 1.0.3", + "syn 1.0.16", +] + +[[package]] +name = "target-lexicon" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f4c118a7a38378f305a9e111fcb2f7f838c0be324bfb31a77ea04f7f6e684b4" + +[[package]] +name = "target-lexicon" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab0e7238dcc7b40a7be719a25365910f6807bd864f4cce6b2e6b873658e2b19d" + +[[package]] +name = "tempfile" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +dependencies = [ + "cfg-if", + "libc", + "rand 0.7.3", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "thiserror" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee14bf8e6767ab4c687c9e8bc003879e042a96fd67a3ba5934eadb6536bef4db" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7b51e1fbc44b5a0840be594fbc0f960be09050f2617e61e6aa43bef97cd3ef4" +dependencies = [ + "proc-macro2 1.0.9", + "quote 1.0.3", + "syn 1.0.16", +] + +[[package]] +name = "thread_local" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "time" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" +dependencies = [ + "libc", + "redox_syscall", + "winapi", +] + +[[package]] +name = "tinytemplate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57a3c6667d3e65eb1bc3aed6fd14011c6cbc3a0665218ab7f5daf040b9ec371a" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "toml" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a" +dependencies = [ + "serde", +] + +[[package]] +name = "typenum" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" + +[[package]] +name = "typetag" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ebb2c484029d695fb68a06d80e1536c68d491b3e0cf874c66abed255e831cfe" +dependencies = [ + "erased-serde", + "inventory", + "lazy_static", + "serde", + "typetag-impl", +] + +[[package]] +name = "typetag-impl" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63fd4799e4d0ec5cf0b055ebb8e2c3a657bbf76a84f6edc77ca60780e000204" +dependencies = [ + "proc-macro2 1.0.9", + "quote 1.0.3", + "syn 1.0.16", +] + +[[package]] +name = "unicode-segmentation" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" + +[[package]] +name = "unicode-width" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + +[[package]] +name = "unicode-xid" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" + +[[package]] +name = "vec_map" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" + +[[package]] +name = "version_check" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "wabt" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5c5c1286c6e578416982609f47594265f9d489f9b836157d403ad605a46693" +dependencies = [ + "serde", + "serde_derive", + "serde_json", + "wabt-sys", +] + +[[package]] +name = "wabt-sys" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af5d153dc96aad7dc13ab90835b892c69867948112d95299e522d370c4e13a08" +dependencies = [ + "cc", + "cmake", + "glob 0.2.11", +] + +[[package]] +name = "walkdir" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasm-debug" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86840eccceaf682e29be7810dcae5785b9c3b0349ce44d3eaecd9e50f893aee0" +dependencies = [ + "anyhow", + "cranelift-entity 0.52.0", + "faerie", + "gimli", + "more-asserts", + "target-lexicon 0.9.0", + "thiserror", + "wasmparser 0.39.3", +] + +[[package]] +name = "wasmer" +version = "0.15.0" +dependencies = [ + "atty", + "byteorder", + "errno", + "fern", + "glob 0.3.0", + "log", + "rustc_version", + "serde", + "structopt", + "typetag", + "wabt", + "wasmer-clif-backend", + "wasmer-dev-utils", + "wasmer-emscripten", + "wasmer-emscripten-tests", + "wasmer-kernel-loader", + "wasmer-llvm-backend", + "wasmer-middleware-common", + "wasmer-middleware-common-tests", + "wasmer-runtime", + "wasmer-runtime-core", + "wasmer-singlepass-backend", + "wasmer-wasi", + "wasmer-wasi-experimental-io-devices", + "wasmer-wasi-tests", +] + +[[package]] +name = "wasmer-clif-backend" +version = "0.15.0" +dependencies = [ + "byteorder", + "cranelift-codegen", + "cranelift-entity 0.59.0", + "cranelift-native", + "libc", + "nix", + "rayon", + "serde", + "serde-bench", + "serde_bytes", + "serde_derive", + "target-lexicon 0.10.0", + "wasm-debug", + "wasmer-clif-fork-frontend", + "wasmer-clif-fork-wasm", + "wasmer-runtime-core", + "wasmer-win-exception-handler", + "wasmparser 0.51.4", + "winapi", +] + +[[package]] +name = "wasmer-clif-fork-frontend" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c23f2824f354a00a77e4b040eef6e1d4c595a8a3e9013bad65199cc8dade9a5a" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec 1.2.0", + "target-lexicon 0.10.0", +] + +[[package]] +name = "wasmer-clif-fork-wasm" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a35e21d3aebc51cc6ebc0e830cf8458a9891c3482fb3c65ad18d408102929ae5" +dependencies = [ + "cranelift-codegen", + "cranelift-entity 0.59.0", + "log", + "thiserror", + "wasmer-clif-fork-frontend", + "wasmparser 0.51.4", +] + +[[package]] +name = "wasmer-dev-utils" +version = "0.15.0" +dependencies = [ + "libc", +] + +[[package]] +name = "wasmer-emscripten" +version = "0.15.0" +dependencies = [ + "byteorder", + "getrandom", + "lazy_static", + "libc", + "log", + "time", + "wasmer-runtime-core", +] + +[[package]] +name = "wasmer-emscripten-tests" +version = "0.15.0" +dependencies = [ + "glob 0.3.0", + "wabt", + "wasmer-clif-backend", + "wasmer-dev-utils", + "wasmer-emscripten", + "wasmer-llvm-backend", + "wasmer-runtime", + "wasmer-singlepass-backend", +] + +[[package]] +name = "wasmer-interface-types" +version = "0.15.0" +dependencies = [ + "nom", + "wast", +] + +[[package]] +name = "wasmer-kernel-loader" +version = "0.1.0" +dependencies = [ + "libc", + "wasmer-runtime-core", +] + +[[package]] +name = "wasmer-llvm-backend" +version = "0.15.0" +dependencies = [ + "byteorder", + "cc", + "goblin 0.0.24", + "inkwell", + "lazy_static", + "libc", + "nix", + "regex", + "rustc_version", + "semver", + "smallvec 0.6.13", + "wabt", + "wasmer-runtime-core", + "wasmparser 0.51.4", + "winapi", +] + +[[package]] +name = "wasmer-llvm-backend-tests" +version = "0.10.2" +dependencies = [ + "wabt", + "wasmer-llvm-backend", + "wasmer-runtime", + "wasmer-runtime-core", +] + +[[package]] +name = "wasmer-middleware-common" +version = "0.15.0" +dependencies = [ + "wasmer-runtime-core", +] + +[[package]] +name = "wasmer-middleware-common-tests" +version = "0.15.0" +dependencies = [ + "criterion", + "wabt", + "wasmer-clif-backend", + "wasmer-llvm-backend", + "wasmer-middleware-common", + "wasmer-runtime-core", + "wasmer-singlepass-backend", +] + +[[package]] +name = "wasmer-runtime" +version = "0.15.0" +dependencies = [ + "criterion", + "lazy_static", + "memmap", + "serde", + "serde_derive", + "tempfile", + "wabt", + "wasmer-clif-backend", + "wasmer-llvm-backend", + "wasmer-runtime-core", + "wasmer-singlepass-backend", +] + +[[package]] +name = "wasmer-runtime-c-api" +version = "0.15.0" +dependencies = [ + "cbindgen", + "libc", + "wasmer-clif-backend", + "wasmer-emscripten", + "wasmer-llvm-backend", + "wasmer-middleware-common", + "wasmer-runtime", + "wasmer-runtime-core", + "wasmer-singlepass-backend", + "wasmer-wasi", +] + +[[package]] +name = "wasmer-runtime-core" +version = "0.15.0" +dependencies = [ + "bincode", + "blake3", + "cc", + "digest", + "errno", + "hex", + "indexmap", + "lazy_static", + "libc", + "nix", + "page_size", + "parking_lot", + "rustc_version", + "serde", + "serde-bench", + "serde_bytes", + "serde_derive", + "smallvec 0.6.13", + "target-lexicon 0.9.0", + "wasm-debug", + "wasmparser 0.51.4", + "winapi", +] + +[[package]] +name = "wasmer-runtime-core-tests" +version = "0.15.0" +dependencies = [ + "wabt", + "wasmer-clif-backend", + "wasmer-llvm-backend", + "wasmer-runtime-core", + "wasmer-singlepass-backend", +] + +[[package]] +name = "wasmer-singlepass-backend" +version = "0.15.0" +dependencies = [ + "byteorder", + "dynasm", + "dynasmrt", + "lazy_static", + "libc", + "nix", + "serde_derive", + "smallvec 0.6.13", + "wasmer-runtime-core", + "wasmparser 0.51.4", +] + +[[package]] +name = "wasmer-spectests" +version = "0.15.0" +dependencies = [ + "glob 0.3.0", + "wabt", + "wasmer-clif-backend", + "wasmer-llvm-backend", + "wasmer-runtime", + "wasmer-singlepass-backend", +] + +[[package]] +name = "wasmer-wasi" +version = "0.15.0" +dependencies = [ + "bincode", + "byteorder", + "generational-arena", + "getrandom", + "libc", + "log", + "serde", + "time", + "typetag", + "wasmer-runtime-core", + "winapi", +] + +[[package]] +name = "wasmer-wasi-experimental-io-devices" +version = "0.15.0" +dependencies = [ + "log", + "minifb", + "ref_thread_local", + "serde", + "typetag", + "wasmer-runtime-core", + "wasmer-wasi", +] + +[[package]] +name = "wasmer-wasi-tests" +version = "0.15.0" +dependencies = [ + "glob 0.3.0", + "wasmer-clif-backend", + "wasmer-dev-utils", + "wasmer-llvm-backend", + "wasmer-runtime", + "wasmer-singlepass-backend", + "wasmer-wasi", +] + +[[package]] +name = "wasmer-win-exception-handler" +version = "0.15.0" +dependencies = [ + "cmake", + "libc", + "wasmer-runtime-core", + "winapi", +] + +[[package]] +name = "wasmparser" +version = "0.39.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c702914acda5feeeffbc29e4d953e5b9ce79d8b98da4dbf18a77086e116c5470" + +[[package]] +name = "wasmparser" +version = "0.51.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" + +[[package]] +name = "wast" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9df3d716118a503b2f6bbb6ff46b21997ab0cc167b01de7a188e45e4b01e8d" +dependencies = [ + "leb128", +] + +[[package]] +name = "winapi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "x11-dl" +version = "2.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bf981e3a5b3301209754218f962052d4d9ee97e478f4d26d4a6eced34c1fef8" +dependencies = [ + "lazy_static", + "libc", + "maybe-uninit", + "pkg-config", +] diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index dde0441ef17e..9c899efb4664 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -38,7 +38,7 @@ #include #include -#define OPCODE_COUNT 410 +#define OPCODE_COUNT 447 #if defined(WASMER_WASI_ENABLED) enum Version { diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 6c17fc85c8a8..1f85114e27cd 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -38,7 +38,7 @@ #include #include -static const uintptr_t OPCODE_COUNT = 410; +static const uintptr_t OPCODE_COUNT = 447; #if defined(WASMER_WASI_ENABLED) enum class Version : uint8_t { From c207b318dadce2e21d3e9c42dbed7a1e06ee073c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Thu, 5 Mar 2020 19:08:38 +0200 Subject: [PATCH 050/129] More updates and fixes after merge from upstream --- Cargo.lock | 17 ++++++++++++----- lib/clif-backend/Cargo.toml | 2 +- lib/llvm-backend/Cargo.toml | 2 +- lib/runtime-c-api/src/import/mod.rs | 4 ++-- lib/runtime-c-api/wasmer.h | 3 ++- lib/runtime-c-api/wasmer.hh | 3 ++- lib/runtime-core/Cargo.toml | 2 +- lib/singlepass-backend/Cargo.toml | 7 ++++--- lib/singlepass-backend/src/codegen_x64.rs | 5 ++++- 9 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e36eae45eca..506557110765 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1870,7 +1870,7 @@ dependencies = [ "wasmer-clif-fork-wasm", "wasmer-runtime-core", "wasmer-win-exception-handler", - "wasmparser 0.51.4", + "wasmparser 0.51.4 (git+https://github.com/ElrondNetwork/wasmparser.rs)", "winapi", ] @@ -1897,7 +1897,7 @@ dependencies = [ "log", "thiserror", "wasmer-clif-fork-frontend", - "wasmparser 0.51.4", + "wasmparser 0.51.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1967,7 +1967,7 @@ dependencies = [ "smallvec 0.6.13", "wabt", "wasmer-runtime-core", - "wasmparser 0.51.4", + "wasmparser 0.51.4 (git+https://github.com/ElrondNetwork/wasmparser.rs)", "winapi", ] @@ -2058,7 +2058,7 @@ dependencies = [ "smallvec 0.6.13", "target-lexicon 0.9.0", "wasm-debug", - "wasmparser 0.51.4", + "wasmparser 0.51.4 (git+https://github.com/ElrondNetwork/wasmparser.rs)", "winapi", ] @@ -2077,16 +2077,18 @@ dependencies = [ name = "wasmer-singlepass-backend" version = "0.15.0" dependencies = [ + "bincode", "byteorder", "dynasm", "dynasmrt", "lazy_static", "libc", "nix", + "serde", "serde_derive", "smallvec 0.6.13", "wasmer-runtime-core", - "wasmparser 0.51.4", + "wasmparser 0.51.4 (git+https://github.com/ElrondNetwork/wasmparser.rs)", ] [[package]] @@ -2160,6 +2162,11 @@ version = "0.39.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c702914acda5feeeffbc29e4d953e5b9ce79d8b98da4dbf18a77086e116c5470" +[[package]] +name = "wasmparser" +version = "0.51.4" +source = "git+https://github.com/ElrondNetwork/wasmparser.rs#57f8cec1a47850cb804776cc858e83300576fea2" + [[package]] name = "wasmparser" version = "0.51.4" diff --git a/lib/clif-backend/Cargo.toml b/lib/clif-backend/Cargo.toml index 2b5cbedb301c..c186bd37dc4f 100644 --- a/lib/clif-backend/Cargo.toml +++ b/lib/clif-backend/Cargo.toml @@ -18,7 +18,7 @@ cranelift-entity = "0.59.0" cranelift-frontend = { package = "wasmer-clif-fork-frontend", version = "0.59.0" } cranelift-wasm = { package = "wasmer-clif-fork-wasm", version = "0.59.0" } target-lexicon = "0.10" -wasmparser = "0.51.3" +wasmparser = { git = "https://github.com/ElrondNetwork/wasmparser.rs" } byteorder = "1.3.2" nix = "0.15.0" libc = "0.2.60" diff --git a/lib/llvm-backend/Cargo.toml b/lib/llvm-backend/Cargo.toml index 9d8b94b67cf8..5fa8665cdaad 100644 --- a/lib/llvm-backend/Cargo.toml +++ b/lib/llvm-backend/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" [dependencies] wasmer-runtime-core = { path = "../runtime-core", version = "0.15.0" } -wasmparser = "0.51.3" +wasmparser = { git = "https://github.com/ElrondNetwork/wasmparser.rs" } smallvec = "0.6" goblin = "0.0.24" libc = "0.2.60" diff --git a/lib/runtime-c-api/src/import/mod.rs b/lib/runtime-c-api/src/import/mod.rs index 53b53ed5032a..2641b7d3edc8 100644 --- a/lib/runtime-c-api/src/import/mod.rs +++ b/lib/runtime-c-api/src/import/mod.rs @@ -76,7 +76,7 @@ pub unsafe extern "C" fn wasmer_import_object_new() -> *mut wasmer_import_object #[no_mangle] pub unsafe extern "C" fn wasmer_import_object_cache_from_imports( imports: *mut wasmer_import_t, - imports_len: c_int, + imports_len: c_uint, ) -> wasmer_result_t { if GLOBAL_IMPORT_OBJECT_INITIALIZED { return wasmer_result_t::WASMER_OK; @@ -104,7 +104,7 @@ pub unsafe extern "C" fn wasmer_import_object_cache_from_imports( #[no_mangle] pub unsafe fn wasmer_create_import_object_from_imports( imports: *mut wasmer_import_t, - imports_len: c_int, + imports_len: c_uint, ) -> Result { let imports: &[wasmer_import_t] = slice::from_raw_parts(imports, imports_len as usize); let mut import_object = ImportObject::new(); diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 9c899efb4664..296e0facd165 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -778,7 +778,8 @@ wasmer_result_t wasmer_import_func_returns(const wasmer_import_func_t *func, wasmer_result_t wasmer_import_func_returns_arity(const wasmer_import_func_t *func, uint32_t *result); -wasmer_result_t wasmer_import_object_cache_from_imports(wasmer_import_t *imports, int imports_len); +wasmer_result_t wasmer_import_object_cache_from_imports(wasmer_import_t *imports, + unsigned int imports_len); /** * Frees memory of the given ImportObject diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 1f85114e27cd..dc16dd308f22 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -611,7 +611,8 @@ wasmer_result_t wasmer_import_func_returns(const wasmer_import_func_t *func, wasmer_result_t wasmer_import_func_returns_arity(const wasmer_import_func_t *func, uint32_t *result); -wasmer_result_t wasmer_import_object_cache_from_imports(wasmer_import_t *imports, int imports_len); +wasmer_result_t wasmer_import_object_cache_from_imports(wasmer_import_t *imports, + unsigned int imports_len); /// Frees memory of the given ImportObject void wasmer_import_object_destroy(wasmer_import_object_t *import_object); diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index 44888c87d0af..f7278a1cdadc 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -12,7 +12,7 @@ edition = "2018" [dependencies] nix = "0.15" page_size = "0.4" -wasmparser = "0.51.3" +wasmparser = { git = "https://github.com/ElrondNetwork/wasmparser.rs" } parking_lot = "0.10.0" lazy_static = "1.4" errno = "0.2" diff --git a/lib/singlepass-backend/Cargo.toml b/lib/singlepass-backend/Cargo.toml index cb0d3b071278..15aacb848cff 100644 --- a/lib/singlepass-backend/Cargo.toml +++ b/lib/singlepass-backend/Cargo.toml @@ -19,9 +19,10 @@ byteorder = "1.3" nix = "0.15" libc = "0.2.60" smallvec = "0.6" -wasmparser = "0.51.3" -[dependencies.serde_derive] -version = "1.0" +wasmparser = { git = "https://github.com/ElrondNetwork/wasmparser.rs" } +bincode = "1.2" +serde = "1.0" +serde_derive = "1.0" [features] default = ["deterministic-execution"] diff --git a/lib/singlepass-backend/src/codegen_x64.rs b/lib/singlepass-backend/src/codegen_x64.rs index 78bc0af9a02f..5f3f258126ac 100644 --- a/lib/singlepass-backend/src/codegen_x64.rs +++ b/lib/singlepass-backend/src/codegen_x64.rs @@ -19,6 +19,9 @@ use std::{ sync::{Arc, RwLock}, usize, }; + +use bincode; + use wasmer_runtime_core::{ backend::{ sys::{Memory, Protect}, @@ -664,7 +667,7 @@ impl ModuleCodeGenerator /// Singlepass does validation as it compiles fn requires_pre_validation() -> bool { - false + true } fn backend_id() -> &'static str { From 9375fe4143130a8feec491e17f2ff81413fc5b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Thu, 28 May 2020 17:16:04 +0300 Subject: [PATCH 051/129] Implement opcode tracing and middleware options --- lib/middleware-common/src/lib.rs | 1 + lib/middleware-common/src/opcode_trace.rs | 91 +++++++++++++++ .../src/runtime_breakpoints.rs | 1 - lib/runtime-c-api/src/instance.rs | 106 +++++++++++++++++- lib/runtime-c-api/src/metering.rs | 102 +++++------------ lib/runtime-c-api/wasmer.h | 12 +- lib/runtime-c-api/wasmer.hh | 12 +- 7 files changed, 240 insertions(+), 85 deletions(-) create mode 100644 lib/middleware-common/src/opcode_trace.rs diff --git a/lib/middleware-common/src/lib.rs b/lib/middleware-common/src/lib.rs index a2b0a9c96fec..7eb19b48d545 100644 --- a/lib/middleware-common/src/lib.rs +++ b/lib/middleware-common/src/lib.rs @@ -18,3 +18,4 @@ pub mod metering; pub mod metering_costs; pub mod runtime_breakpoints; +pub mod opcode_trace; diff --git a/lib/middleware-common/src/opcode_trace.rs b/lib/middleware-common/src/opcode_trace.rs new file mode 100644 index 000000000000..a241f940d0bc --- /dev/null +++ b/lib/middleware-common/src/opcode_trace.rs @@ -0,0 +1,91 @@ +use std::fs::File; +use std::io; +use std::io::Write; + +use wasmer_runtime_core::{ + codegen::{Event, EventSink, FunctionMiddleware, InternalEvent}, + module::{ModuleInfo}, + vm::{InternalField}, + wasmparser::Operator, + Instance, +}; + + +static OPCODE_LAST_LOCATION: InternalField = InternalField::allocate(); + +pub struct OpcodeTracer { + pub output_file: File, +} + +impl OpcodeTracer { + pub fn new() -> OpcodeTracer { + OpcodeTracer { + output_file: File::create("opcode.trace").unwrap(), + } + } + + pub fn trace_instance_exports(&mut self, instance: &Instance) -> io::Result<()> { + write!(self.output_file, "{:#?}\n", instance.module.info.exports) + } + + pub fn trace_event(&mut self, ev: &Event, source_loc: u32) -> io::Result<()> { + match *ev { + Event::Internal(InternalEvent::FunctionBegin(function_index)) => { + self.trace_function_begin(function_index) + } + Event::Internal(InternalEvent::FunctionEnd) => { + self.trace_function_end() + } + _ => { + self.trace_opcode_event(ev, source_loc) + } + } + } + + pub fn trace_function_begin(&mut self, function_index: u32) -> io::Result<()>{ + write!(self.output_file, "FUNCTION BEGIN: {}\n", function_index) + } + + pub fn trace_function_end(&mut self) -> io::Result<()> { + write!(self.output_file, "FUNCTION END\n") + } + + pub fn trace_opcode_event(&mut self, ev: &Event, source_loc: u32) -> io::Result<()> { + match ev { + Event::Wasm(&ref op) + | Event::WasmOwned(ref op) => { + write!(self.output_file, "\t{}:\t{:?}\n", source_loc, *op) + } + _ => Ok(()) + } + } + + pub fn push_last_location_tracer(&self, sink: &mut EventSink, source_loc: u32) { + sink.push(Event::WasmOwned(Operator::I64Const { + value: source_loc as i64, + })); + sink.push(Event::Internal(InternalEvent::SetInternal( + OPCODE_LAST_LOCATION.index() as _, + ))); + } +} + +impl FunctionMiddleware for OpcodeTracer { + type Error = String; + fn feed_event<'a, 'b: 'a>( + &mut self, + op: Event<'a, 'b>, + _module_info: &ModuleInfo, + sink: &mut EventSink<'a, 'b>, + source_loc: u32, + ) -> Result<(), Self::Error> { + self.trace_event(&op, source_loc).expect("failed to trace event"); + self.push_last_location_tracer(sink, source_loc); + sink.push(op); + Ok(()) + } +} + +pub fn get_runtime_last_location(instance: &mut Instance) -> u64 { + instance.get_internal(&OPCODE_LAST_LOCATION) +} diff --git a/lib/middleware-common/src/runtime_breakpoints.rs b/lib/middleware-common/src/runtime_breakpoints.rs index 178d935b52e9..debc29af4cf1 100644 --- a/lib/middleware-common/src/runtime_breakpoints.rs +++ b/lib/middleware-common/src/runtime_breakpoints.rs @@ -68,7 +68,6 @@ impl FunctionMiddleware for RuntimeBreakpointHandler { } } - pub fn set_runtime_breakpoint_value(instance: &mut Instance, value: u64) { instance.set_internal(&RUNTIME_BREAKPOINT_VALUE, value); } diff --git a/lib/runtime-c-api/src/instance.rs b/lib/runtime-c-api/src/instance.rs index 9fd63fc39fe4..225f75e48e72 100644 --- a/lib/runtime-c-api/src/instance.rs +++ b/lib/runtime-c-api/src/instance.rs @@ -3,7 +3,7 @@ use crate::{ error::{update_last_error, CApiError}, export::{wasmer_exports_t, wasmer_import_export_kind, NamedExport, NamedExports}, - import::wasmer_import_t, + import::{wasmer_import_t, GLOBAL_IMPORT_OBJECT}, memory::wasmer_memory_t, value::{wasmer_value, wasmer_value_t, wasmer_value_tag}, wasmer_result_t, @@ -16,6 +16,14 @@ use wasmer_runtime_core::{ import::{ImportObject, Namespace}, }; +use wasmer_runtime_core::backend::Compiler; +use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler}; +use crate::metering::OPCODE_COSTS; + +#[cfg(not(feature = "cranelift-backend"))] +use wasmer_middleware_common::metering; + + /// Opaque pointer to a `wasmer_runtime::Instance` value in Rust. /// /// A `wasmer_runtime::Instance` represents a WebAssembly instance. It @@ -178,6 +186,102 @@ pub unsafe extern "C" fn wasmer_instantiate( wasmer_result_t::WASMER_OK } + +#[repr(C)] +pub struct wasmer_import_object_t; + +#[repr(C)] +pub struct wasmer_compilation_options_t; + +pub struct CompilationOptions { + pub gas_limit: u64, + pub opcode_trace: bool, +} + +#[allow(clippy::cast_ptr_alignment)] +#[cfg(feature = "metering")] +#[no_mangle] +pub unsafe extern "C" fn wasmer_instantiate_with_options( + instance: *mut *mut wasmer_instance_t, + wasm_bytes: *mut u8, + wasm_bytes_len: u32, + options: *const wasmer_compilation_options_t, +) -> wasmer_result_t { + if wasm_bytes.is_null() { + update_last_error(CApiError { + msg: "wasm bytes ptr is null".to_string(), + }); + return wasmer_result_t::WASMER_ERROR; + } + + let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); + let options: &CompilationOptions = &*(options as *const CompilationOptions); + let compiler_chain_generator = prepare_middleware_chain_generator(&options); + let compiler = get_compiler(compiler_chain_generator); + let result_compilation = wasmer_runtime_core::compile_with(bytes, &compiler); + let new_module = match result_compilation { + Ok(module) => module, + Err(_) => { + println!("compiler error"); + update_last_error(CApiError { msg: "compile error".to_string() }); + return wasmer_result_t::WASMER_ERROR; + } + }; + + println!("compiled ok"); + let import_object: &mut ImportObject = &mut *(GLOBAL_IMPORT_OBJECT as *mut ImportObject); + let result_instantiation = new_module.instantiate(&import_object); + let new_instance = match result_instantiation { + Ok(instance) => instance, + Err(error) => { + update_last_error(error); + return wasmer_result_t::WASMER_ERROR; + } + }; + *instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t; + wasmer_result_t::WASMER_OK +} + +unsafe fn prepare_middleware_chain_generator(options: &CompilationOptions) -> impl Fn() -> MiddlewareChain { + let gas_limit = options.gas_limit; + let opcode_trace = options.opcode_trace; + + let chain_generator = move || { + let mut chain = MiddlewareChain::new(); + + use wasmer_middleware_common::runtime_breakpoints; + use wasmer_middleware_common::opcode_trace; + + #[cfg(feature = "metering")] + chain.push(metering::Metering::new(gas_limit, &OPCODE_COSTS)); + + chain.push(runtime_breakpoints::RuntimeBreakpointHandler::new()); + + if opcode_trace { + chain.push(opcode_trace::OpcodeTracer::new()); + }; + + chain + }; + + chain_generator +} + +unsafe fn get_compiler(chain_generator: impl Fn() -> MiddlewareChain) -> impl Compiler { + #[cfg(feature = "llvm-backend")] + use wasmer_llvm_backend::ModuleCodeGenerator as MeteredMCG; + + #[cfg(feature = "singlepass-backend")] + use wasmer_singlepass_backend::ModuleCodeGenerator as MeteredMCG; + + #[cfg(feature = "cranelift-backend")] + use wasmer_clif_backend::CraneliftModuleCodeGenerator as MeteredMCG; + + let compiler: StreamingCompiler = StreamingCompiler::new(chain_generator); + compiler +} + + /// Returns the instance context. Learn more by looking at the /// `wasmer_instance_context_t` struct. /// diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index e023d92d6fb1..f5fa92c3523f 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -5,11 +5,6 @@ use crate::{ wasmer_result_t, }; use std::{slice}; -use crate::import::{ - GLOBAL_IMPORT_OBJECT, -}; - -use wasmer_runtime_core::import::ImportObject; #[cfg(feature = "metering")] use wasmer_runtime_core::backend::Compiler; @@ -18,12 +13,9 @@ use wasmer_runtime_core::backend::Compiler; use wasmer_middleware_common::metering; pub const OPCODE_COUNT: usize = 447; -static mut OPCODE_COSTS: [u32; OPCODE_COUNT] = [0; OPCODE_COUNT]; +pub static mut OPCODE_COSTS: [u32; OPCODE_COUNT] = [0; OPCODE_COUNT]; static mut OPCODE_COSTS_INITIALIZED: bool = false; -#[repr(C)] -pub struct wasmer_import_object_t; - #[allow(clippy::cast_ptr_alignment)] #[cfg(feature = "metering")] #[no_mangle] @@ -36,47 +28,33 @@ pub unsafe extern "C" fn wasmer_set_opcode_costs( } } - +// returns gas used #[allow(clippy::cast_ptr_alignment)] -#[cfg(feature = "metering")] #[no_mangle] -pub unsafe extern "C" fn wasmer_instantiate_with_metering( - instance: *mut *mut wasmer_instance_t, - wasm_bytes: *mut u8, - wasm_bytes_len: u32, - gas_limit: u64, -) -> wasmer_result_t { - if wasm_bytes.is_null() { - update_last_error(CApiError { - msg: "wasm bytes ptr is null".to_string(), - }); - return wasmer_result_t::WASMER_ERROR; +#[cfg(feature = "metering")] +pub unsafe extern "C" fn wasmer_instance_get_points_used(instance: *mut wasmer_instance_t) -> u64 { + if instance.is_null() { + return 0; } - - let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); - let compiler = get_metered_compiler(gas_limit); - let result_compilation = wasmer_runtime_core::compile_with(bytes, &compiler); - let new_module = match result_compilation { - Ok(module) => module, - Err(_) => { - update_last_error(CApiError { msg: "compile error".to_string() }); - return wasmer_result_t::WASMER_ERROR; - } - }; - - let import_object: &mut ImportObject = &mut *(GLOBAL_IMPORT_OBJECT as *mut ImportObject); - let result_instantiation = new_module.instantiate(&import_object); - let new_instance = match result_instantiation { - Ok(instance) => instance, - Err(error) => { - update_last_error(error); - return wasmer_result_t::WASMER_ERROR; - } - }; - *instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t; - wasmer_result_t::WASMER_OK + let instance = &*(instance as *const wasmer_runtime::Instance); + let points = metering::get_points_used(instance); + points } +// sets gas used +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +#[cfg(feature = "metering")] +pub unsafe extern "C" fn wasmer_instance_set_points_used( + instance: *mut wasmer_instance_t, + new_gas: u64, +) { + if instance.is_null() { + return; + } + let instance = &mut *(instance as *mut wasmer_runtime::Instance); + metering::set_points_used(instance, new_gas) +} /// Creates a new Module with gas limit from the given wasm bytes. /// @@ -106,8 +84,9 @@ pub unsafe extern "C" fn wasmer_compile_with_gas_metering( return wasmer_result_t::WASMER_ERROR; } - let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); let compiler = get_metered_compiler(gas_limit); + + let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); let result = wasmer_runtime_core::compile_with(bytes, &compiler); let new_module = match result { Ok(instance) => instance, @@ -148,33 +127,6 @@ unsafe fn get_metered_compiler(limit: u64) -> impl Compiler { c } -// returns gas used -#[allow(clippy::cast_ptr_alignment)] -#[no_mangle] -#[cfg(feature = "metering")] -pub unsafe extern "C" fn wasmer_instance_get_points_used(instance: *mut wasmer_instance_t) -> u64 { - if instance.is_null() { - return 0; - } - let instance = &*(instance as *const wasmer_runtime::Instance); - let points = metering::get_points_used(instance); - points -} - -// sets gas used -#[allow(clippy::cast_ptr_alignment)] -#[no_mangle] -#[cfg(feature = "metering")] -pub unsafe extern "C" fn wasmer_instance_set_points_used( - instance: *mut wasmer_instance_t, - new_gas: u64, -) { - if instance.is_null() { - return; - } - let instance = &mut *(instance as *mut wasmer_runtime::Instance); - metering::set_points_used(instance, new_gas) -} /*** placeholder implementation if metering feature off ***/ @@ -214,7 +166,7 @@ pub unsafe extern "C" fn wasmer_compile_with_gas_metering( wasmer_result_t::WASMER_OK } -// returns gas used +// returns gas used -- placeholder implementation, when "metering" is disabled #[allow(clippy::cast_ptr_alignment)] #[no_mangle] #[cfg(not(feature = "metering"))] @@ -222,7 +174,7 @@ pub unsafe extern "C" fn wasmer_instance_get_points_used(_: *mut wasmer_instance 0 } -// sets gas used +// sets gas used -- placeholder implementation, when "metering" is disabled #[allow(clippy::cast_ptr_alignment)] #[no_mangle] #[cfg(not(feature = "metering"))] diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 296e0facd165..01cf23e3c37b 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -335,6 +335,10 @@ typedef struct { } wasmer_instance_context_t; +typedef struct { + +} wasmer_compilation_options_t; + /** * The `wasmer_limit_option_t` struct represents an optional limit * for `wasmer_limits_t`. @@ -1121,10 +1125,10 @@ wasmer_result_t wasmer_instantiate(wasmer_instance_t **instance, wasmer_import_t *imports, int imports_len); -wasmer_result_t wasmer_instantiate_with_metering(wasmer_instance_t **instance, - uint8_t *wasm_bytes, - uint32_t wasm_bytes_len, - uint64_t gas_limit); +wasmer_result_t wasmer_instantiate_with_options(wasmer_instance_t **instance, + uint8_t *wasm_bytes, + uint32_t wasm_bytes_len, + const wasmer_compilation_options_t *options); /** * Gets the length in bytes of the last error if any. diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index dc16dd308f22..2bdfdbb30e5a 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -270,6 +270,10 @@ struct wasmer_instance_context_t { }; +struct wasmer_compilation_options_t { + +}; + /// The `wasmer_limit_option_t` struct represents an optional limit /// for `wasmer_limits_t`. struct wasmer_limit_option_t { @@ -920,10 +924,10 @@ wasmer_result_t wasmer_instantiate(wasmer_instance_t **instance, wasmer_import_t *imports, int imports_len); -wasmer_result_t wasmer_instantiate_with_metering(wasmer_instance_t **instance, - uint8_t *wasm_bytes, - uint32_t wasm_bytes_len, - uint64_t gas_limit); +wasmer_result_t wasmer_instantiate_with_options(wasmer_instance_t **instance, + uint8_t *wasm_bytes, + uint32_t wasm_bytes_len, + const wasmer_compilation_options_t *options); /// Gets the length in bytes of the last error if any. /// From 23102fa59d4343dc0887c72990d17e0767cb8d14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Thu, 28 May 2020 18:26:52 +0300 Subject: [PATCH 052/129] Print runtime postlude if opcode tracing is enabled --- lib/middleware-common/src/opcode_trace.rs | 6 +++++- lib/runtime-c-api/src/instance.rs | 24 ++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/middleware-common/src/opcode_trace.rs b/lib/middleware-common/src/opcode_trace.rs index a241f940d0bc..13b8b3b2cd3b 100644 --- a/lib/middleware-common/src/opcode_trace.rs +++ b/lib/middleware-common/src/opcode_trace.rs @@ -86,6 +86,10 @@ impl FunctionMiddleware for OpcodeTracer { } } -pub fn get_runtime_last_location(instance: &mut Instance) -> u64 { +pub fn get_opcodetracer_last_location(instance: &mut Instance) -> u64 { instance.get_internal(&OPCODE_LAST_LOCATION) } + +pub fn reset_opcodetracer_last_location(instance: &mut Instance) { + instance.set_internal(&OPCODE_LAST_LOCATION, 0); +} diff --git a/lib/runtime-c-api/src/instance.rs b/lib/runtime-c-api/src/instance.rs index 225f75e48e72..5bfb1e109a7b 100644 --- a/lib/runtime-c-api/src/instance.rs +++ b/lib/runtime-c-api/src/instance.rs @@ -23,6 +23,10 @@ use crate::metering::OPCODE_COSTS; #[cfg(not(feature = "cranelift-backend"))] use wasmer_middleware_common::metering; +use wasmer_middleware_common::runtime_breakpoints; +use wasmer_middleware_common::opcode_trace; + + /// Opaque pointer to a `wasmer_runtime::Instance` value in Rust. /// @@ -222,13 +226,11 @@ pub unsafe extern "C" fn wasmer_instantiate_with_options( let new_module = match result_compilation { Ok(module) => module, Err(_) => { - println!("compiler error"); update_last_error(CApiError { msg: "compile error".to_string() }); return wasmer_result_t::WASMER_ERROR; } }; - println!("compiled ok"); let import_object: &mut ImportObject = &mut *(GLOBAL_IMPORT_OBJECT as *mut ImportObject); let result_instantiation = new_module.instantiate(&import_object); let new_instance = match result_instantiation { @@ -249,9 +251,6 @@ unsafe fn prepare_middleware_chain_generator(options: &CompilationOptions) -> im let chain_generator = move || { let mut chain = MiddlewareChain::new(); - use wasmer_middleware_common::runtime_breakpoints; - use wasmer_middleware_common::opcode_trace; - #[cfg(feature = "metering")] chain.push(metering::Metering::new(gas_limit, &OPCODE_COSTS)); @@ -401,9 +400,12 @@ pub unsafe extern "C" fn wasmer_instance_call( let func_name_r = func_name_c.to_str().unwrap(); let results: &mut [wasmer_value_t] = slice::from_raw_parts_mut(results, results_len as usize); - let result = (&*(instance as *mut Instance)).call(func_name_r, ¶ms[..]); + let instance = &mut *(instance as *mut Instance); + + wasmer_middleware_common::opcode_trace::reset_opcodetracer_last_location(instance); + let result = instance.call(func_name_r, ¶ms[..]); - match result { + let result = match result { Ok(results_vec) => { if !results_vec.is_empty() { let ret = match results_vec[0] { @@ -433,7 +435,15 @@ pub unsafe extern "C" fn wasmer_instance_call( update_last_error(err); wasmer_result_t::WASMER_ERROR } + }; + + let last_opcode_location = wasmer_middleware_common::opcode_trace::get_opcodetracer_last_location(instance); + if last_opcode_location > 0 { + println!("wasmer_instance_call MODULE_EXPORTS {:#?}\n", instance.module.info.exports); + println!("wasmer_instance_call OPCODE_LAST_LOCATION = {}", last_opcode_location); } + + result } /// Gets all the exports of the given WebAssembly instance. From 2e191ea276728c1db1c6dba47ed6c3c133433c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 29 May 2020 16:28:53 +0300 Subject: [PATCH 053/129] Change singlepass codegen_x64.rs to make exception_table optional --- lib/singlepass-backend/src/codegen_x64.rs | 382 +++++++++++++--------- 1 file changed, 220 insertions(+), 162 deletions(-) diff --git a/lib/singlepass-backend/src/codegen_x64.rs b/lib/singlepass-backend/src/codegen_x64.rs index 5f3f258126ac..60948b86d22f 100644 --- a/lib/singlepass-backend/src/codegen_x64.rs +++ b/lib/singlepass-backend/src/codegen_x64.rs @@ -248,7 +248,7 @@ pub struct X64ExecutionContext { breakpoints: BreakpointMap, func_import_count: usize, msm: ModuleStateMap, - exception_table: ExceptionTable, + exception_table: Option, } /// On-disk cache format. @@ -273,7 +273,7 @@ pub struct CacheImage { msm: ModuleStateMap, /// An exception table that maps instruction offsets to exception codes. - exception_table: ExceptionTable, + exception_table: Option, } #[derive(Debug)] @@ -333,7 +333,10 @@ impl RunnableModule for X64ExecutionContext { } fn get_exception_table(&self) -> Option<&ExceptionTable> { - Some(&self.exception_table) + match &self.exception_table { + Some(etable) => { Some(&etable) } + None => None + } } unsafe fn patch_local_function(&self, idx: usize, target_address: usize) -> bool { @@ -693,13 +696,13 @@ impl ModuleCodeGenerator x.assembler.take().unwrap(), x.function_labels.take().unwrap(), x.breakpoints.take().unwrap(), - x.exception_table.take().unwrap(), + x.exception_table.take(), ), None => ( self.assembler.take().unwrap(), self.function_labels.take().unwrap(), HashMap::new(), - ExceptionTable::new(), + None, ), }; @@ -735,7 +738,7 @@ impl ModuleCodeGenerator machine, unreachable_depth: 0, config: self.config.as_ref().unwrap().clone(), - exception_table: Some(exception_table), + exception_table: exception_table, }; self.functions.push(code); Ok(self.functions.last_mut().unwrap()) @@ -758,13 +761,13 @@ impl ModuleCodeGenerator x.assembler.take().unwrap(), x.function_labels.take().unwrap(), x.breakpoints.take().unwrap(), - x.exception_table.take().unwrap(), + x.exception_table.take(), ), None => ( self.assembler.take().unwrap(), self.function_labels.take().unwrap(), HashMap::new(), - ExceptionTable::new(), + None, ), }; @@ -852,7 +855,7 @@ impl ModuleCodeGenerator function_pointers: out_labels, function_offsets: out_offsets, msm: msm, - exception_table, + exception_table: exception_table, }, None, Box::new(cache), @@ -1011,7 +1014,7 @@ impl X64FunctionCode { fn emit_relaxed_xdiv( a: &mut Assembler, m: &mut Machine, - etable: &mut ExceptionTable, + exception_table: &mut Option, op: fn(&mut Assembler, Size, Location), sz: Size, loc: Location, @@ -1023,16 +1026,26 @@ impl X64FunctionCode { Location::Imm64(_) | Location::Imm32(_) => { a.emit_mov(sz, loc, Location::GPR(GPR::RCX)); // must not be used during div (rax, rdx) Self::mark_trappable(a, m, fsm, control_stack); - etable - .offset_to_code - .insert(a.get_offset().0, ExceptionCode::IllegalArithmetic); + + match exception_table { + Some(etable) => { etable + .offset_to_code + .insert(a.get_offset().0, ExceptionCode::IllegalArithmetic); } + None => {} + }; + op(a, sz, Location::GPR(GPR::RCX)); } _ => { Self::mark_trappable(a, m, fsm, control_stack); - etable - .offset_to_code - .insert(a.get_offset().0, ExceptionCode::IllegalArithmetic); + + match exception_table { + Some(etable) => { etable + .offset_to_code + .insert(a.get_offset().0, ExceptionCode::IllegalArithmetic); } + None => {} + }; + op(a, sz, loc); } } @@ -1927,7 +1940,7 @@ impl X64FunctionCode { config: &CodegenConfig, a: &mut Assembler, m: &mut Machine, - etable: &mut ExceptionTable, + exception_table: &mut Option, addr: Location, memarg: &MemoryImmediate, check_alignment: bool, @@ -2002,12 +2015,18 @@ impl X64FunctionCode { a.emit_add(Size::S64, Location::GPR(tmp_base), Location::GPR(tmp_addr)); a.emit_cmp(Size::S64, Location::GPR(tmp_bound), Location::GPR(tmp_addr)); - Self::mark_range_with_exception_code( - a, - etable, - ExceptionCode::MemoryOutOfBounds, - |a| a.emit_conditional_trap(Condition::Above), - ); + match exception_table { + Some(etable) => { + Self::mark_range_with_exception_code( + a, + etable, + ExceptionCode::MemoryOutOfBounds, + |a| a.emit_conditional_trap(Condition::Above), + ); + } + None => { a.emit_conditional_trap(Condition::Above); } + }; + m.release_temp_gpr(tmp_bound); } @@ -2047,18 +2066,30 @@ impl X64FunctionCode { Location::Imm32(align - 1), Location::GPR(tmp_aligncheck), ); - Self::mark_range_with_exception_code( - a, - etable, - ExceptionCode::MemoryOutOfBounds, - |a| a.emit_conditional_trap(Condition::NotEqual), - ); + match exception_table { + Some(etable) => { + Self::mark_range_with_exception_code( + a, + etable, + ExceptionCode::MemoryOutOfBounds, + |a| a.emit_conditional_trap(Condition::NotEqual), + ); + } + None => { a.emit_conditional_trap(Condition::NotEqual); } + }; + + m.release_temp_gpr(tmp_aligncheck); } - Self::mark_range_with_exception_code(a, etable, ExceptionCode::MemoryOutOfBounds, |a| { - cb(a, m, tmp_addr) - })?; + match exception_table { + Some(etable) => { + Self::mark_range_with_exception_code(a, etable, ExceptionCode::MemoryOutOfBounds, |a| { + cb(a, m, tmp_addr) + })?; + } + None => { cb(a, m, tmp_addr)?; } + }; m.release_temp_gpr(tmp_addr); Ok(()) @@ -2070,7 +2101,7 @@ impl X64FunctionCode { config: &CodegenConfig, a: &mut Assembler, m: &mut Machine, - etable: &mut ExceptionTable, + exception_table: &mut Option, loc: Location, target: Location, ret: Location, @@ -2104,7 +2135,7 @@ impl X64FunctionCode { config, a, m, - etable, + exception_table, target, memarg, true, @@ -2179,7 +2210,7 @@ impl X64FunctionCode { fn emit_f32_int_conv_check_trap( a: &mut Assembler, m: &mut Machine, - etable: &mut ExceptionTable, + exception_table: &mut Option, reg: XMM, lower_bound: f32, upper_bound: f32, @@ -2189,9 +2220,14 @@ impl X64FunctionCode { Self::emit_f32_int_conv_check(a, m, reg, lower_bound, upper_bound, trap, trap, trap, end); a.emit_label(trap); - etable - .offset_to_code - .insert(a.get_offset().0, ExceptionCode::IllegalArithmetic); + + match exception_table { + Some(etable) => { etable + .offset_to_code + .insert(a.get_offset().0, ExceptionCode::IllegalArithmetic); } + None => {} + }; + a.emit_ud2(); a.emit_label(end); } @@ -2307,7 +2343,7 @@ impl X64FunctionCode { fn emit_f64_int_conv_check_trap( a: &mut Assembler, m: &mut Machine, - etable: &mut ExceptionTable, + exception_table: &mut Option, reg: XMM, lower_bound: f64, upper_bound: f64, @@ -2317,9 +2353,14 @@ impl X64FunctionCode { Self::emit_f64_int_conv_check(a, m, reg, lower_bound, upper_bound, trap, trap, trap, end); a.emit_label(trap); - etable - .offset_to_code - .insert(a.get_offset().0, ExceptionCode::IllegalArithmetic); + + match exception_table { + Some(etable) => { etable + .offset_to_code + .insert(a.get_offset().0, ExceptionCode::IllegalArithmetic); } + None => {} + }; + a.emit_ud2(); a.emit_label(end); } @@ -2444,12 +2485,17 @@ impl FunctionCodeGenerator for X64FunctionCode { ), Location::GPR(GPR::RSP), ); - Self::mark_range_with_exception_code( - a, - self.exception_table.as_mut().unwrap(), - ExceptionCode::MemoryOutOfBounds, - |a| a.emit_conditional_trap(Condition::Below), - ); + match &mut self.exception_table { + Some(etable) => { + Self::mark_range_with_exception_code( + a, + etable, + ExceptionCode::MemoryOutOfBounds, + |a| a.emit_conditional_trap(Condition::Below), + ); + } + None => { a.emit_conditional_trap(Condition::Below); } + }; } self.locals = self @@ -2880,7 +2926,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Self::emit_relaxed_xdiv( a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, Assembler::emit_div, Size::S32, loc_b, @@ -2906,7 +2952,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Self::emit_relaxed_xdiv( a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, Assembler::emit_idiv, Size::S32, loc_b, @@ -2932,7 +2978,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Self::emit_relaxed_xdiv( a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, Assembler::emit_div, Size::S32, loc_b, @@ -2984,7 +3030,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Self::emit_relaxed_xdiv( a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, Assembler::emit_idiv, Size::S32, loc_b, @@ -3283,7 +3329,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Self::emit_relaxed_xdiv( a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, Assembler::emit_div, Size::S64, loc_b, @@ -3309,7 +3355,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Self::emit_relaxed_xdiv( a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, Assembler::emit_idiv, Size::S64, loc_b, @@ -3335,7 +3381,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Self::emit_relaxed_xdiv( a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, Assembler::emit_div, Size::S64, loc_b, @@ -3395,7 +3441,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Self::emit_relaxed_xdiv( a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, Assembler::emit_idiv, Size::S64, loc_b, @@ -4848,7 +4894,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Self::emit_f32_int_conv_check_trap( a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, tmp_in, GEF32_LT_U32_MIN, LEF32_GT_U32_MAX, @@ -4960,7 +5006,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Self::emit_f32_int_conv_check_trap( a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, tmp_in, GEF32_LT_I32_MIN, LEF32_GT_I32_MAX, @@ -5078,7 +5124,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Self::emit_f32_int_conv_check_trap( a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, tmp_in, GEF32_LT_I64_MIN, LEF32_GT_I64_MAX, @@ -5196,7 +5242,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Self::emit_f32_int_conv_check_trap( a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, tmp_in, GEF32_LT_U64_MIN, LEF32_GT_U64_MAX, @@ -5357,7 +5403,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Self::emit_f64_int_conv_check_trap( a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, tmp_in, GEF64_LT_U32_MIN, LEF64_GT_U32_MAX, @@ -5475,7 +5521,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Self::emit_f64_int_conv_check_trap( a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, real_in, GEF64_LT_I32_MIN, LEF64_GT_I32_MAX, @@ -5599,7 +5645,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Self::emit_f64_int_conv_check_trap( a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, tmp_in, GEF64_LT_I64_MIN, LEF64_GT_I64_MAX, @@ -5718,7 +5764,7 @@ impl FunctionCodeGenerator for X64FunctionCode { Self::emit_f64_int_conv_check_trap( a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, tmp_in, GEF64_LT_U64_MIN, LEF64_GT_U64_MAX, @@ -6318,12 +6364,19 @@ impl FunctionCodeGenerator for X64FunctionCode { Location::GPR(table_base), ); a.emit_cmp(Size::S32, func_index, Location::GPR(table_count)); - Self::mark_range_with_exception_code( - a, - self.exception_table.as_mut().unwrap(), - ExceptionCode::CallIndirectOOB, - |a| a.emit_conditional_trap(Condition::BelowEqual), - ); + + match &mut self.exception_table { + Some(etable) => { + Self::mark_range_with_exception_code( + a, + etable, + ExceptionCode::CallIndirectOOB, + |a| a.emit_conditional_trap(Condition::BelowEqual), + ); + } + None => { a.emit_conditional_trap(Condition::BelowEqual); } + }; + a.emit_mov(Size::S32, func_index, Location::GPR(table_count)); a.emit_imul_imm32_gpr64(vm::Anyfunc::size() as u32, table_count); a.emit_add( @@ -6349,12 +6402,17 @@ impl FunctionCodeGenerator for X64FunctionCode { Location::GPR(sigidx), Location::Memory(table_count, (vm::Anyfunc::offset_sig_id() as usize) as i32), ); - Self::mark_range_with_exception_code( - a, - self.exception_table.as_mut().unwrap(), - ExceptionCode::IncorrectCallIndirectSignature, - |a| a.emit_conditional_trap(Condition::NotEqual), - ); + match &mut self.exception_table { + Some(etable) => { + Self::mark_range_with_exception_code( + a, + etable, + ExceptionCode::IncorrectCallIndirectSignature, + |a| a.emit_conditional_trap(Condition::NotEqual), + ); + } + None => { a.emit_conditional_trap(Condition::NotEqual); } + } self.machine.release_temp_gpr(sigidx); self.machine.release_temp_gpr(table_count); @@ -6707,7 +6765,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, false, @@ -6740,7 +6798,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, false, @@ -6773,7 +6831,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, false, @@ -6807,7 +6865,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, false, @@ -6841,7 +6899,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, false, @@ -6875,7 +6933,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, false, @@ -6905,7 +6963,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target_addr, memarg, false, @@ -6934,7 +6992,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target_addr, memarg, false, @@ -6963,7 +7021,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target_addr, memarg, false, @@ -6992,7 +7050,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target_addr, memarg, false, @@ -7025,7 +7083,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, false, @@ -7058,7 +7116,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, false, @@ -7091,7 +7149,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, false, @@ -7125,7 +7183,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, false, @@ -7159,7 +7217,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, false, @@ -7193,7 +7251,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, false, @@ -7227,7 +7285,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, false, @@ -7275,7 +7333,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, false, @@ -7305,7 +7363,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target_addr, memarg, false, @@ -7334,7 +7392,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target_addr, memarg, false, @@ -7363,7 +7421,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target_addr, memarg, false, @@ -7392,7 +7450,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target_addr, memarg, false, @@ -7421,7 +7479,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target_addr, memarg, false, @@ -7674,7 +7732,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -7707,7 +7765,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -7741,7 +7799,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -7771,7 +7829,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target_addr, memarg, true, @@ -7800,7 +7858,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target_addr, memarg, true, @@ -7829,7 +7887,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target_addr, memarg, true, @@ -7862,7 +7920,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -7895,7 +7953,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -7929,7 +7987,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -7963,7 +8021,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -8007,7 +8065,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target_addr, memarg, true, @@ -8036,7 +8094,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target_addr, memarg, true, @@ -8065,7 +8123,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target_addr, memarg, true, @@ -8094,7 +8152,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target_addr, memarg, true, @@ -8131,7 +8189,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -8167,7 +8225,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -8203,7 +8261,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -8235,7 +8293,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -8271,7 +8329,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -8303,7 +8361,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -8339,7 +8397,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -8376,7 +8434,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -8413,7 +8471,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -8450,7 +8508,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -8483,7 +8541,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -8520,7 +8578,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -8553,7 +8611,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -8590,7 +8648,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -8624,7 +8682,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -8654,7 +8712,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -8684,7 +8742,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -8714,7 +8772,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -8744,7 +8802,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -8774,7 +8832,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -8804,7 +8862,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -8834,7 +8892,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -8864,7 +8922,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -8894,7 +8952,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -8924,7 +8982,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -8954,7 +9012,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -8984,7 +9042,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -9014,7 +9072,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -9044,7 +9102,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -9074,7 +9132,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -9104,7 +9162,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -9134,7 +9192,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -9164,7 +9222,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -9194,7 +9252,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -9224,7 +9282,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, loc, target, ret, @@ -9256,7 +9314,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -9288,7 +9346,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -9320,7 +9378,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -9352,7 +9410,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -9384,7 +9442,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -9416,7 +9474,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -9448,7 +9506,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -9494,7 +9552,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -9545,7 +9603,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -9596,7 +9654,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -9647,7 +9705,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -9698,7 +9756,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -9749,7 +9807,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, @@ -9800,7 +9858,7 @@ impl FunctionCodeGenerator for X64FunctionCode { &self.config, a, &mut self.machine, - self.exception_table.as_mut().unwrap(), + &mut self.exception_table, target, memarg, true, From 4baa24bea92b714fdd418eb8e27a8f1396d1516d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 29 May 2020 17:03:28 +0300 Subject: [PATCH 054/129] Minor comments --- lib/singlepass-backend/src/codegen_x64.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/singlepass-backend/src/codegen_x64.rs b/lib/singlepass-backend/src/codegen_x64.rs index 60948b86d22f..a556af474d4f 100644 --- a/lib/singlepass-backend/src/codegen_x64.rs +++ b/lib/singlepass-backend/src/codegen_x64.rs @@ -702,7 +702,7 @@ impl ModuleCodeGenerator self.assembler.take().unwrap(), self.function_labels.take().unwrap(), HashMap::new(), - None, + None, // Some(ExceptionTable::new()), ), }; @@ -767,7 +767,7 @@ impl ModuleCodeGenerator self.assembler.take().unwrap(), self.function_labels.take().unwrap(), HashMap::new(), - None, + None, // Some(ExceptionTable::new()), ), }; From 4fac4cbb7522b4829878b18d36e498896a576b6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 1 Jun 2020 11:41:05 +0300 Subject: [PATCH 055/129] Rename .travis.yml to .travis.upstream.yml --- .travis.yml => .travis.upstream.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .travis.yml => .travis.upstream.yml (100%) diff --git a/.travis.yml b/.travis.upstream.yml similarity index 100% rename from .travis.yml rename to .travis.upstream.yml From 1dae68aa2ef0340b2d44ace3db576552778e7301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 1 Jun 2020 12:03:26 +0300 Subject: [PATCH 056/129] Create .travis.yml --- .travis.yml | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000000..c259d4d87273 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,59 @@ +os: + - linux + - osx +arch: + - amd64 + - arm64 +osx_image: xcode11.3 + +language: rust +install: travis_retry +rust: + - nightly-2019-12-19 + +cache: + directories: + - /home/travis/.sccache/ + - /home/travis/.cargo/bin/ + +script: + - test -f /home/travis/.cargo/bin/sccache || travis_retry cargo install sccache + - export RUSTC_WRAPPER=/home/travis/.cargo/bin/sccache + - mkdir -p /home/travis/.sccache/ + - export SCCACHE_DIR="/home/travis/.sccache/" + - SCCACHE_ERROR_LOG=`pwd`/sccache.log RUST_LOG=debug $RUSTC_WRAPPER --start-server + - $RUSTC_WRAPPER -s + + - make capi + - ls ./target/release + - mkdir artifacts + + - if [[ "$TRAVIS_OS_NAME" == osx ]]; + then + mv ./target/release/libwasmer_runtime_c_api.dylib ./artifacts/libwasmer_darwin_amd64.dylib; + fi + - if [[ "$TRAVIS_OS_NAME" == linux && "$TRAVIS_CPU_ARCH" == amd64 ]]; + then + mv ./target/release/libwasmer_runtime_c_api.so ./artifacts/libwasmer_linux_amd64.so; + fi + - if [[ "$TRAVIS_OS_NAME" == linux && "$TRAVIS_CPU_ARCH" == arm64 ]]; + then + mv ./target/release/libwasmer_runtime_c_api.so ./artifacts/libwasmer_linux_arm64.so; + fi + +deploy: + provider: releases + file_glob: true + file: artifacts/* + api_key: $GITHUB_OAUTH_TOKEN + skip_cleanup: true + draft: true + +addons: + apt: + packages: + - cmake + +branches: + only: + - master From f428bc5fc6b16ca184092febebcde818bfad6d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 1 Jun 2020 12:25:29 +0300 Subject: [PATCH 057/129] Update .travis.yml --- .travis.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index c259d4d87273..7d8f3508bff5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ os: - - linux + #- linux - osx arch: - amd64 - - arm64 + #- arm64 osx_image: xcode11.3 language: rust @@ -13,14 +13,14 @@ rust: cache: directories: - - /home/travis/.sccache/ - - /home/travis/.cargo/bin/ + - $HOME/.sccache/ + - $HOME/.cargo/bin/ script: - - test -f /home/travis/.cargo/bin/sccache || travis_retry cargo install sccache - - export RUSTC_WRAPPER=/home/travis/.cargo/bin/sccache - - mkdir -p /home/travis/.sccache/ - - export SCCACHE_DIR="/home/travis/.sccache/" + - test -f $HOME/.cargo/bin/sccache || travis_retry cargo install sccache + - export RUSTC_WRAPPER=$HOME/.cargo/bin/sccache + - mkdir -p $HOME/.sccache/ + - export SCCACHE_DIR="$HOME/.sccache/" - SCCACHE_ERROR_LOG=`pwd`/sccache.log RUST_LOG=debug $RUSTC_WRAPPER --start-server - $RUSTC_WRAPPER -s @@ -31,6 +31,7 @@ script: - if [[ "$TRAVIS_OS_NAME" == osx ]]; then mv ./target/release/libwasmer_runtime_c_api.dylib ./artifacts/libwasmer_darwin_amd64.dylib; + install_name_tool -id @executable_path/libwasmer_darwin_amd64.dylib ./artifacts/libwasmer_darwin_amd64.dylib; fi - if [[ "$TRAVIS_OS_NAME" == linux && "$TRAVIS_CPU_ARCH" == amd64 ]]; then From 37a08d4c7d0a7b6253933b15b875b5d39c711efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 1 Jun 2020 12:49:44 +0300 Subject: [PATCH 058/129] Update .travis.yml --- .travis.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7d8f3508bff5..6128105d6ed5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,14 @@ os: - #- linux + - linux - osx arch: - amd64 - #- arm64 + - arm64 osx_image: xcode11.3 language: rust +before_install: +- if [[ $TRAVIS_OS_NAME == linux ]]; then sudo apt-get install -y patchelf; fi install: travis_retry rust: - nightly-2019-12-19 @@ -36,12 +38,14 @@ script: - if [[ "$TRAVIS_OS_NAME" == linux && "$TRAVIS_CPU_ARCH" == amd64 ]]; then mv ./target/release/libwasmer_runtime_c_api.so ./artifacts/libwasmer_linux_amd64.so; + patchelf --set-soname libwasmer_linux_amd64.so ./artifacts/libwasmer_linux_amd64.so; fi - if [[ "$TRAVIS_OS_NAME" == linux && "$TRAVIS_CPU_ARCH" == arm64 ]]; then mv ./target/release/libwasmer_runtime_c_api.so ./artifacts/libwasmer_linux_arm64.so; + patchelf --set-soname libwasmer_linux_arm64.so ./artifacts/libwasmer_linux_arm64.so; fi - + deploy: provider: releases file_glob: true From 456cc54dbd0fc3cafc430ba28247b50523ac52b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Mon, 1 Jun 2020 14:33:13 +0300 Subject: [PATCH 059/129] Add options for metering and runtime_breakpoints --- lib/runtime-c-api/src/instance.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/runtime-c-api/src/instance.rs b/lib/runtime-c-api/src/instance.rs index 5bfb1e109a7b..c1d431a4f1e6 100644 --- a/lib/runtime-c-api/src/instance.rs +++ b/lib/runtime-c-api/src/instance.rs @@ -200,6 +200,8 @@ pub struct wasmer_compilation_options_t; pub struct CompilationOptions { pub gas_limit: u64, pub opcode_trace: bool, + pub metering: bool, + pub runtime_breakpoints: bool, } #[allow(clippy::cast_ptr_alignment)] @@ -247,14 +249,20 @@ pub unsafe extern "C" fn wasmer_instantiate_with_options( unsafe fn prepare_middleware_chain_generator(options: &CompilationOptions) -> impl Fn() -> MiddlewareChain { let gas_limit = options.gas_limit; let opcode_trace = options.opcode_trace; + let metering = options.metering; + let runtime_breakpoints = options.runtime_breakpoints; let chain_generator = move || { let mut chain = MiddlewareChain::new(); - #[cfg(feature = "metering")] - chain.push(metering::Metering::new(gas_limit, &OPCODE_COSTS)); + if metering { + #[cfg(feature = "metering")] + chain.push(metering::Metering::new(gas_limit, &OPCODE_COSTS)); + } - chain.push(runtime_breakpoints::RuntimeBreakpointHandler::new()); + if runtime_breakpoints { + chain.push(runtime_breakpoints::RuntimeBreakpointHandler::new()); + } if opcode_trace { chain.push(opcode_trace::OpcodeTracer::new()); From 26e713afb440804e20c59ff35b8bf49187b58a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Mon, 1 Jun 2020 15:17:46 +0300 Subject: [PATCH 060/129] Add more debugging information when opcode tracing is enabled --- lib/runtime-c-api/src/instance.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/runtime-c-api/src/instance.rs b/lib/runtime-c-api/src/instance.rs index c1d431a4f1e6..bb75c6b97bf5 100644 --- a/lib/runtime-c-api/src/instance.rs +++ b/lib/runtime-c-api/src/instance.rs @@ -447,6 +447,7 @@ pub unsafe extern "C" fn wasmer_instance_call( let last_opcode_location = wasmer_middleware_common::opcode_trace::get_opcodetracer_last_location(instance); if last_opcode_location > 0 { + println!("wasmer_instance_call MODULE_IMPORTS {:#?}\n", instance.module.info.imported_functions); println!("wasmer_instance_call MODULE_EXPORTS {:#?}\n", instance.module.info.exports); println!("wasmer_instance_call OPCODE_LAST_LOCATION = {}", last_opcode_location); } From d3a2e85012bfba3cd3f23b35392931f4a53be1c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Mon, 1 Jun 2020 17:31:41 +0300 Subject: [PATCH 061/129] Improve debugging prints when tracing is enabled --- lib/runtime-c-api/src/instance.rs | 11 +++++++++-- lib/runtime-core/src/module.rs | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/runtime-c-api/src/instance.rs b/lib/runtime-c-api/src/instance.rs index bb75c6b97bf5..6ed0df9c9b70 100644 --- a/lib/runtime-c-api/src/instance.rs +++ b/lib/runtime-c-api/src/instance.rs @@ -447,8 +447,15 @@ pub unsafe extern "C" fn wasmer_instance_call( let last_opcode_location = wasmer_middleware_common::opcode_trace::get_opcodetracer_last_location(instance); if last_opcode_location > 0 { - println!("wasmer_instance_call MODULE_IMPORTS {:#?}\n", instance.module.info.imported_functions); - println!("wasmer_instance_call MODULE_EXPORTS {:#?}\n", instance.module.info.exports); + let imported_functions = instance.module.info.name_table.to_vec(); + for i in 0..imported_functions.len() { + println!("Import {}\t{}", i, imported_functions[i]); + } + + for (k, v) in instance.module.info.exports.iter() { + println!("Export {:?}\t{}", v, k); + } + println!("wasmer_instance_call OPCODE_LAST_LOCATION = {}", last_opcode_location); } diff --git a/lib/runtime-core/src/module.rs b/lib/runtime-core/src/module.rs index e7af6a7daec7..47a38ae8babf 100644 --- a/lib/runtime-core/src/module.rs +++ b/lib/runtime-core/src/module.rs @@ -306,6 +306,15 @@ impl StringTable { &self.buffer[offset..offset + length] } + + /// Gets all the strings in the StringTable as a Vec. + pub fn to_vec(&self) -> Vec<&str> { + self.table + .values() + .map(|(offset, length)| + &self.buffer[(*offset as usize)..(*offset as usize) + (*length as usize)]) + .collect() + } } /// A type-safe handle referring to a module namespace. From b5a51c8b3b90760ccc9f5fd85e689ac1b700ed67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 2 Jun 2020 12:26:38 +0300 Subject: [PATCH 062/129] Fix omitted self.exception_table.unwrap() --- lib/singlepass-backend/src/codegen_x64.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/singlepass-backend/src/codegen_x64.rs b/lib/singlepass-backend/src/codegen_x64.rs index a556af474d4f..ec44ddb1efa3 100644 --- a/lib/singlepass-backend/src/codegen_x64.rs +++ b/lib/singlepass-backend/src/codegen_x64.rs @@ -7499,11 +7499,12 @@ impl FunctionCodeGenerator for X64FunctionCode { } Operator::Unreachable => { Self::mark_trappable(a, &self.machine, &mut self.fsm, &mut self.control_stack); - self.exception_table - .as_mut() - .unwrap() - .offset_to_code - .insert(a.get_offset().0, ExceptionCode::Unreachable); + match &mut self.exception_table { + Some(etable) => { + etable.offset_to_code.insert(a.get_offset().0, ExceptionCode::Unreachable); + } + None => {} + }; a.emit_ud2(); self.unreachable_depth = 1; } From 88e04069263344042846503728a471cd19050224 Mon Sep 17 00:00:00 2001 From: Andrei Bancioiu Date: Tue, 30 Jun 2020 18:25:06 +0300 Subject: [PATCH 063/129] Allow build of branch development. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6128105d6ed5..c5ff08d649d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -62,3 +62,4 @@ addons: branches: only: - master + - development From b2a6fa68d37aad8ff4f23337253b99f9f13548b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 22 Jul 2020 12:02:09 +0300 Subject: [PATCH 064/129] Add out-of-gas runtime breakpoint --- lib/middleware-common/src/metering.rs | 23 +++++++++---------- .../src/runtime_breakpoints.rs | 21 +++++++++++++---- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/lib/middleware-common/src/metering.rs b/lib/middleware-common/src/metering.rs index 01236603b87a..1a95030d237c 100644 --- a/lib/middleware-common/src/metering.rs +++ b/lib/middleware-common/src/metering.rs @@ -3,13 +3,14 @@ use wasmer_runtime_core::{ module::ModuleInfo, vm::{Ctx, InternalField}, wasmparser::{Operator, Type as WpType, TypeOrFuncType as WpTypeOrFuncType}, - error::{RuntimeError}, Instance, }; use crate::metering_costs::{get_opcode_index}; +use crate::runtime_breakpoints::{push_runtime_breakpoint}; -static INTERNAL_FIELD: InternalField = InternalField::allocate(); +static FIELD_USED_POINTS: InternalField = InternalField::allocate(); +pub const BREAKPOINT_VALUE__OUT_OF_GAS: u64 = 4; /// Metering is a compiler middleware that calculates the cost of WebAssembly instructions at compile /// time and will count the cost of executed instructions at runtime. Within the Metering functionality, @@ -73,14 +74,14 @@ impl<'q> FunctionMiddleware for Metering<'q> { | Operator::CallIndirect { .. } | Operator::Return => { sink.push(Event::Internal(InternalEvent::GetInternal( - INTERNAL_FIELD.index() as _, + FIELD_USED_POINTS.index() as _, ))); sink.push(Event::WasmOwned(Operator::I64Const { value: self.current_block as i64, })); sink.push(Event::WasmOwned(Operator::I64Add)); sink.push(Event::Internal(InternalEvent::SetInternal( - INTERNAL_FIELD.index() as _, + FIELD_USED_POINTS.index() as _, ))); self.current_block = 0; } @@ -93,7 +94,7 @@ impl<'q> FunctionMiddleware for Metering<'q> { | Operator::Call { .. } | Operator::CallIndirect { .. } => { sink.push(Event::Internal(InternalEvent::GetInternal( - INTERNAL_FIELD.index() as _, + FIELD_USED_POINTS.index() as _, ))); sink.push(Event::WasmOwned(Operator::I64Const { value: self.limit as i64, @@ -102,9 +103,7 @@ impl<'q> FunctionMiddleware for Metering<'q> { sink.push(Event::WasmOwned(Operator::If { ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), })); - sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(|_| { - Err(Box::new(RuntimeError(Box::new("execution limit exceeded".to_string())))) - })))); + push_runtime_breakpoint(sink, BREAKPOINT_VALUE__OUT_OF_GAS); sink.push(Event::WasmOwned(Operator::End)); } _ => {} @@ -119,20 +118,20 @@ impl<'q> FunctionMiddleware for Metering<'q> { /// Returns the number of points used by an Instance. pub fn get_points_used(instance: &Instance) -> u64 { - instance.get_internal(&INTERNAL_FIELD) + instance.get_internal(&FIELD_USED_POINTS) } /// Sets the number of points used by an Instance. pub fn set_points_used(instance: &mut Instance, value: u64) { - instance.set_internal(&INTERNAL_FIELD, value); + instance.set_internal(&FIELD_USED_POINTS, value); } /// Returns the number of points used in a Ctx. pub fn get_points_used_ctx(ctx: &Ctx) -> u64 { - ctx.get_internal(&INTERNAL_FIELD) + ctx.get_internal(&FIELD_USED_POINTS) } /// Sets the number of points used in a Ctx. pub fn set_points_used_ctx(ctx: &mut Ctx, value: u64) { - ctx.set_internal(&INTERNAL_FIELD, value); + ctx.set_internal(&FIELD_USED_POINTS, value); } diff --git a/lib/middleware-common/src/runtime_breakpoints.rs b/lib/middleware-common/src/runtime_breakpoints.rs index debc29af4cf1..dd867b7c486f 100644 --- a/lib/middleware-common/src/runtime_breakpoints.rs +++ b/lib/middleware-common/src/runtime_breakpoints.rs @@ -7,9 +7,10 @@ use wasmer_runtime_core::{ Instance, }; -static RUNTIME_BREAKPOINT_VALUE: InternalField = InternalField::allocate(); +pub static FIELD_RUNTIME_BREAKPOINT_VALUE: InternalField = InternalField::allocate(); pub const BREAKPOINT_VALUE__NO_BREAKPOINT: u64 = 0; + #[derive(Copy, Clone, Debug)] pub struct RuntimeBreakpointReachedError; @@ -49,7 +50,7 @@ impl FunctionMiddleware for RuntimeBreakpointHandler { if must_add_breakpoint { sink.push(Event::Internal(InternalEvent::GetInternal( - RUNTIME_BREAKPOINT_VALUE.index() as _, + FIELD_RUNTIME_BREAKPOINT_VALUE.index() as _, ))); sink.push(Event::WasmOwned(Operator::I64Const { value: BREAKPOINT_VALUE__NO_BREAKPOINT as i64, @@ -68,10 +69,22 @@ impl FunctionMiddleware for RuntimeBreakpointHandler { } } +pub fn push_runtime_breakpoint(sink: &mut EventSink, value: u64) { + sink.push(Event::WasmOwned(Operator::I64Const { + value: value as i64, + })); + sink.push(Event::Internal(InternalEvent::SetInternal( + FIELD_RUNTIME_BREAKPOINT_VALUE.index() as _, + ))); + sink.push(Event::Internal(InternalEvent::Breakpoint(Box::new(|_| { + Err(Box::new(RuntimeError(Box::new("breakpoint reached".to_string())))) + })))); +} + pub fn set_runtime_breakpoint_value(instance: &mut Instance, value: u64) { - instance.set_internal(&RUNTIME_BREAKPOINT_VALUE, value); + instance.set_internal(&FIELD_RUNTIME_BREAKPOINT_VALUE, value); } pub fn get_runtime_breakpoint_value(instance: &mut Instance) -> u64 { - instance.get_internal(&RUNTIME_BREAKPOINT_VALUE) + instance.get_internal(&FIELD_RUNTIME_BREAKPOINT_VALUE) } From 85190e4e0af6f26143ab9784b8f7b97480337585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 1 Sep 2020 18:30:22 +0300 Subject: [PATCH 065/129] Change wasmparser dependency to local folder --- Cargo.lock | 9 ++++----- lib/clif-backend/Cargo.toml | 2 +- lib/llvm-backend/Cargo.toml | 2 +- lib/runtime-core/Cargo.toml | 2 +- lib/singlepass-backend/Cargo.toml | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 506557110765..66c0ecaa377f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1870,7 +1870,7 @@ dependencies = [ "wasmer-clif-fork-wasm", "wasmer-runtime-core", "wasmer-win-exception-handler", - "wasmparser 0.51.4 (git+https://github.com/ElrondNetwork/wasmparser.rs)", + "wasmparser 0.51.4", "winapi", ] @@ -1967,7 +1967,7 @@ dependencies = [ "smallvec 0.6.13", "wabt", "wasmer-runtime-core", - "wasmparser 0.51.4 (git+https://github.com/ElrondNetwork/wasmparser.rs)", + "wasmparser 0.51.4", "winapi", ] @@ -2058,7 +2058,7 @@ dependencies = [ "smallvec 0.6.13", "target-lexicon 0.9.0", "wasm-debug", - "wasmparser 0.51.4 (git+https://github.com/ElrondNetwork/wasmparser.rs)", + "wasmparser 0.51.4", "winapi", ] @@ -2088,7 +2088,7 @@ dependencies = [ "serde_derive", "smallvec 0.6.13", "wasmer-runtime-core", - "wasmparser 0.51.4 (git+https://github.com/ElrondNetwork/wasmparser.rs)", + "wasmparser 0.51.4", ] [[package]] @@ -2165,7 +2165,6 @@ checksum = "c702914acda5feeeffbc29e4d953e5b9ce79d8b98da4dbf18a77086e116c5470" [[package]] name = "wasmparser" version = "0.51.4" -source = "git+https://github.com/ElrondNetwork/wasmparser.rs#57f8cec1a47850cb804776cc858e83300576fea2" [[package]] name = "wasmparser" diff --git a/lib/clif-backend/Cargo.toml b/lib/clif-backend/Cargo.toml index c186bd37dc4f..cd6030761647 100644 --- a/lib/clif-backend/Cargo.toml +++ b/lib/clif-backend/Cargo.toml @@ -18,7 +18,7 @@ cranelift-entity = "0.59.0" cranelift-frontend = { package = "wasmer-clif-fork-frontend", version = "0.59.0" } cranelift-wasm = { package = "wasmer-clif-fork-wasm", version = "0.59.0" } target-lexicon = "0.10" -wasmparser = { git = "https://github.com/ElrondNetwork/wasmparser.rs" } +wasmparser = { path = "../../../wasmparser.rs" } byteorder = "1.3.2" nix = "0.15.0" libc = "0.2.60" diff --git a/lib/llvm-backend/Cargo.toml b/lib/llvm-backend/Cargo.toml index 5fa8665cdaad..0710e17a3ef5 100644 --- a/lib/llvm-backend/Cargo.toml +++ b/lib/llvm-backend/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" [dependencies] wasmer-runtime-core = { path = "../runtime-core", version = "0.15.0" } -wasmparser = { git = "https://github.com/ElrondNetwork/wasmparser.rs" } +wasmparser = { path = "../../../wasmparser.rs" } smallvec = "0.6" goblin = "0.0.24" libc = "0.2.60" diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index f7278a1cdadc..3a36a1c43519 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -12,7 +12,7 @@ edition = "2018" [dependencies] nix = "0.15" page_size = "0.4" -wasmparser = { git = "https://github.com/ElrondNetwork/wasmparser.rs" } +wasmparser = { path = "../../../wasmparser.rs" } parking_lot = "0.10.0" lazy_static = "1.4" errno = "0.2" diff --git a/lib/singlepass-backend/Cargo.toml b/lib/singlepass-backend/Cargo.toml index 15aacb848cff..6ba7847fecf3 100644 --- a/lib/singlepass-backend/Cargo.toml +++ b/lib/singlepass-backend/Cargo.toml @@ -19,7 +19,7 @@ byteorder = "1.3" nix = "0.15" libc = "0.2.60" smallvec = "0.6" -wasmparser = { git = "https://github.com/ElrondNetwork/wasmparser.rs" } +wasmparser = { path = "../../../wasmparser.rs" } bincode = "1.2" serde = "1.0" serde_derive = "1.0" From 52aabb1c194f89f5259491be09caf2d1f5be88ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 4 Sep 2020 17:34:01 +0300 Subject: [PATCH 066/129] Add feed_local() to the FunctionMiddleware trait and the Metering middleware --- lib/middleware-common/src/metering.rs | 25 ++++++++++-- lib/middleware-common/src/metering_costs.rs | 8 ++-- lib/runtime-c-api/src/metering.rs | 4 +- lib/runtime-c-api/wasmer.h | 2 +- lib/runtime-c-api/wasmer.hh | 2 +- lib/runtime-core/src/codegen.rs | 42 +++++++++++++++++++++ lib/runtime-core/src/parse.rs | 2 + 7 files changed, 74 insertions(+), 11 deletions(-) diff --git a/lib/middleware-common/src/metering.rs b/lib/middleware-common/src/metering.rs index 1a95030d237c..4bd871566f65 100644 --- a/lib/middleware-common/src/metering.rs +++ b/lib/middleware-common/src/metering.rs @@ -6,8 +6,8 @@ use wasmer_runtime_core::{ Instance, }; -use crate::metering_costs::{get_opcode_index}; -use crate::runtime_breakpoints::{push_runtime_breakpoint}; +use crate::metering_costs::{get_opcode_index, get_local_allocate_cost_index}; +use crate::runtime_breakpoints::push_runtime_breakpoint; static FIELD_USED_POINTS: InternalField = InternalField::allocate(); pub const BREAKPOINT_VALUE__OUT_OF_GAS: u64 = 4; @@ -28,6 +28,7 @@ pub const BREAKPOINT_VALUE__OUT_OF_GAS: u64 = 4; pub struct Metering<'a> { limit: u64, current_block: u64, + func_locals_costs: u32, opcode_costs: &'a [u32], } @@ -36,7 +37,8 @@ impl<'a> Metering<'a> { Metering { limit, current_block: 0, - opcode_costs: opcode_costs, + func_locals_costs: 0, + opcode_costs, } } } @@ -46,6 +48,7 @@ pub struct ExecutionLimitExceededError; impl<'q> FunctionMiddleware for Metering<'q> { type Error = String; + fn feed_event<'a, 'b: 'a>( &mut self, op: Event<'a, 'b>, @@ -55,7 +58,7 @@ impl<'q> FunctionMiddleware for Metering<'q> { ) -> Result<(), Self::Error> { match op { Event::Internal(InternalEvent::FunctionBegin(_)) => { - self.current_block = 0; + self.current_block = self.func_locals_costs as u64; } Event::Wasm(&ref op) | Event::WasmOwned(ref op) => { let opcode_index = get_opcode_index(op); @@ -111,7 +114,21 @@ impl<'q> FunctionMiddleware for Metering<'q> { } _ => {} } + sink.push(op); + + Ok(()) + } + + fn feed_local( + &mut self, + _ty: WpType, + n: usize, + _loc: u32, + ) -> Result<(), Self::Error>{ + let cost_index = get_local_allocate_cost_index(); + let cost = self.opcode_costs[cost_index]; + self.func_locals_costs += cost; Ok(()) } } diff --git a/lib/middleware-common/src/metering_costs.rs b/lib/middleware-common/src/metering_costs.rs index b007ed3d160b..64c6f24646e6 100644 --- a/lib/middleware-common/src/metering_costs.rs +++ b/lib/middleware-common/src/metering_costs.rs @@ -1,6 +1,8 @@ -use wasmer_runtime_core:: { - wasmparser::Operator -}; +use wasmer_runtime_core::wasmparser::Operator; + +pub fn get_local_allocate_cost_index() -> usize { + 447 +} pub fn get_opcode_index(op: &Operator) -> usize { match *op { diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index f5fa92c3523f..a970de522d6a 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -4,7 +4,7 @@ use crate::{ module::wasmer_module_t, wasmer_result_t, }; -use std::{slice}; +use std::slice; #[cfg(feature = "metering")] use wasmer_runtime_core::backend::Compiler; @@ -12,7 +12,7 @@ use wasmer_runtime_core::backend::Compiler; #[cfg(not(feature = "cranelift-backend"))] use wasmer_middleware_common::metering; -pub const OPCODE_COUNT: usize = 447; +pub const OPCODE_COUNT: usize = 448; pub static mut OPCODE_COSTS: [u32; OPCODE_COUNT] = [0; OPCODE_COUNT]; static mut OPCODE_COSTS_INITIALIZED: bool = false; diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 01cf23e3c37b..36f34648ab15 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -38,7 +38,7 @@ #include #include -#define OPCODE_COUNT 447 +#define OPCODE_COUNT 448 #if defined(WASMER_WASI_ENABLED) enum Version { diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 2bdfdbb30e5a..18f22ee51614 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -38,7 +38,7 @@ #include #include -static const uintptr_t OPCODE_COUNT = 447; +static const uintptr_t OPCODE_COUNT = 448; #if defined(WASMER_WASI_ENABLED) enum class Version : uint8_t { diff --git a/lib/runtime-core/src/codegen.rs b/lib/runtime-core/src/codegen.rs index b65234cf4dcd..bf035aee3b6e 100644 --- a/lib/runtime-core/src/codegen.rs +++ b/lib/runtime-core/src/codegen.rs @@ -424,6 +424,21 @@ impl MiddlewareChain { Ok(()) } + + /// Notify this chain about a given local variable. + pub(crate) fn run_func_local( + &mut self, + ty: WpType, + n: usize, + loc: u32, + ) -> Result<(), String> { + for m in &mut self.chain { + m.feed_local(ty, n, loc) + .map_err(|x| format!("{:?}", x))?; + } + + Ok(()) + } } /// A trait that represents the signature required to implement middleware for a function. @@ -438,6 +453,16 @@ pub trait FunctionMiddleware { sink: &mut EventSink<'a, 'b>, source_loc: u32, ) -> Result<(), Self::Error>; + + /// Notify the middleware about a given local variable. + fn feed_local( + &mut self, + _ty: WpType, + _n: usize, + _source_loc: u32, + ) -> Result<(), Self::Error> { + Ok(()) + } } pub(crate) trait GenericFunctionMiddleware { @@ -448,6 +473,13 @@ pub(crate) trait GenericFunctionMiddleware { sink: &mut EventSink<'a, 'b>, source_loc: u32, ) -> Result<(), String>; + + fn feed_local( + &mut self, + _ty: WpType, + _n: usize, + _source_loc: u32, + ) -> Result<(), String>; } impl> GenericFunctionMiddleware for T { @@ -461,6 +493,16 @@ impl> GenericFunctionMiddleware for T ::feed_event(self, op, module_info, sink, source_loc) .map_err(|x| format!("{:?}", x)) } + + fn feed_local( + &mut self, + ty: WpType, + n: usize, + source_loc: u32, + ) -> Result<(), String> { + ::feed_local(self, ty, n, source_loc) + .map_err(|x| format!("{:?}", x)) + } } /// The function-scope code generator trait. diff --git a/lib/runtime-core/src/parse.rs b/lib/runtime-core/src/parse.rs index d2b88f07ad38..8f042e4272ae 100644 --- a/lib/runtime-core/src/parse.rs +++ b/lib/runtime-core/src/parse.rs @@ -277,6 +277,8 @@ pub fn read_module< for &(count, ty) in locals.iter() { fcg.feed_local(ty, count as usize, cur_pos) .map_err(|x| LoadError::Codegen(format!("{:?}", x)))?; + middlewares.run_func_local(ty, count as usize, cur_pos) + .map_err(|x| LoadError::Codegen(format!("{:?}", x)))?; } } ParserState::CodeOperator(_) => { From 3516b203a2eb1b81f8dcffe91190f1fc434c4091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 4 Sep 2020 17:44:25 +0300 Subject: [PATCH 067/129] Restore Cargo.toml files --- lib/clif-backend/Cargo.toml | 2 +- lib/llvm-backend/Cargo.toml | 2 +- lib/runtime-core/Cargo.toml | 2 +- lib/singlepass-backend/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/clif-backend/Cargo.toml b/lib/clif-backend/Cargo.toml index cd6030761647..c186bd37dc4f 100644 --- a/lib/clif-backend/Cargo.toml +++ b/lib/clif-backend/Cargo.toml @@ -18,7 +18,7 @@ cranelift-entity = "0.59.0" cranelift-frontend = { package = "wasmer-clif-fork-frontend", version = "0.59.0" } cranelift-wasm = { package = "wasmer-clif-fork-wasm", version = "0.59.0" } target-lexicon = "0.10" -wasmparser = { path = "../../../wasmparser.rs" } +wasmparser = { git = "https://github.com/ElrondNetwork/wasmparser.rs" } byteorder = "1.3.2" nix = "0.15.0" libc = "0.2.60" diff --git a/lib/llvm-backend/Cargo.toml b/lib/llvm-backend/Cargo.toml index 0710e17a3ef5..5fa8665cdaad 100644 --- a/lib/llvm-backend/Cargo.toml +++ b/lib/llvm-backend/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" [dependencies] wasmer-runtime-core = { path = "../runtime-core", version = "0.15.0" } -wasmparser = { path = "../../../wasmparser.rs" } +wasmparser = { git = "https://github.com/ElrondNetwork/wasmparser.rs" } smallvec = "0.6" goblin = "0.0.24" libc = "0.2.60" diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index 3a36a1c43519..f7278a1cdadc 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -12,7 +12,7 @@ edition = "2018" [dependencies] nix = "0.15" page_size = "0.4" -wasmparser = { path = "../../../wasmparser.rs" } +wasmparser = { git = "https://github.com/ElrondNetwork/wasmparser.rs" } parking_lot = "0.10.0" lazy_static = "1.4" errno = "0.2" diff --git a/lib/singlepass-backend/Cargo.toml b/lib/singlepass-backend/Cargo.toml index 6ba7847fecf3..15aacb848cff 100644 --- a/lib/singlepass-backend/Cargo.toml +++ b/lib/singlepass-backend/Cargo.toml @@ -19,7 +19,7 @@ byteorder = "1.3" nix = "0.15" libc = "0.2.60" smallvec = "0.6" -wasmparser = { path = "../../../wasmparser.rs" } +wasmparser = { git = "https://github.com/ElrondNetwork/wasmparser.rs" } bincode = "1.2" serde = "1.0" serde_derive = "1.0" From 2120df82fe783c887bd6a5d1e1c50bde580ca993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 4 Sep 2020 17:49:28 +0300 Subject: [PATCH 068/129] Minor fix --- Cargo.lock | 9 +++++---- lib/middleware-common/src/metering.rs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 66c0ecaa377f..506557110765 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1870,7 +1870,7 @@ dependencies = [ "wasmer-clif-fork-wasm", "wasmer-runtime-core", "wasmer-win-exception-handler", - "wasmparser 0.51.4", + "wasmparser 0.51.4 (git+https://github.com/ElrondNetwork/wasmparser.rs)", "winapi", ] @@ -1967,7 +1967,7 @@ dependencies = [ "smallvec 0.6.13", "wabt", "wasmer-runtime-core", - "wasmparser 0.51.4", + "wasmparser 0.51.4 (git+https://github.com/ElrondNetwork/wasmparser.rs)", "winapi", ] @@ -2058,7 +2058,7 @@ dependencies = [ "smallvec 0.6.13", "target-lexicon 0.9.0", "wasm-debug", - "wasmparser 0.51.4", + "wasmparser 0.51.4 (git+https://github.com/ElrondNetwork/wasmparser.rs)", "winapi", ] @@ -2088,7 +2088,7 @@ dependencies = [ "serde_derive", "smallvec 0.6.13", "wasmer-runtime-core", - "wasmparser 0.51.4", + "wasmparser 0.51.4 (git+https://github.com/ElrondNetwork/wasmparser.rs)", ] [[package]] @@ -2165,6 +2165,7 @@ checksum = "c702914acda5feeeffbc29e4d953e5b9ce79d8b98da4dbf18a77086e116c5470" [[package]] name = "wasmparser" version = "0.51.4" +source = "git+https://github.com/ElrondNetwork/wasmparser.rs#57f8cec1a47850cb804776cc858e83300576fea2" [[package]] name = "wasmparser" diff --git a/lib/middleware-common/src/metering.rs b/lib/middleware-common/src/metering.rs index 4bd871566f65..0d9fec6fc44a 100644 --- a/lib/middleware-common/src/metering.rs +++ b/lib/middleware-common/src/metering.rs @@ -123,7 +123,7 @@ impl<'q> FunctionMiddleware for Metering<'q> { fn feed_local( &mut self, _ty: WpType, - n: usize, + _n: usize, _loc: u32, ) -> Result<(), Self::Error>{ let cost_index = get_local_allocate_cost_index(); From ac18301b230204e0bb8157529fbd4c6f997a3ea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Mon, 7 Sep 2020 16:21:20 +0300 Subject: [PATCH 069/129] Add unmetered locals --- lib/middleware-common/src/metering.rs | 15 ++++++++++----- lib/runtime-c-api/src/instance.rs | 22 +++++++++++++--------- lib/runtime-c-api/src/metering.rs | 2 +- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/middleware-common/src/metering.rs b/lib/middleware-common/src/metering.rs index 0d9fec6fc44a..b7436cc614ec 100644 --- a/lib/middleware-common/src/metering.rs +++ b/lib/middleware-common/src/metering.rs @@ -27,15 +27,17 @@ pub const BREAKPOINT_VALUE__OUT_OF_GAS: u64 = 4; pub struct Metering<'a> { limit: u64, + unmetered_locals: usize, current_block: u64, func_locals_costs: u32, opcode_costs: &'a [u32], } impl<'a> Metering<'a> { - pub fn new(limit: u64, opcode_costs: &'a [u32]) -> Metering<'a> { + pub fn new(limit: u64, opcode_costs: &'a [u32], unmetered_locals: usize) -> Metering<'a> { Metering { limit, + unmetered_locals, current_block: 0, func_locals_costs: 0, opcode_costs, @@ -123,12 +125,15 @@ impl<'q> FunctionMiddleware for Metering<'q> { fn feed_local( &mut self, _ty: WpType, - _n: usize, + n: usize, _loc: u32, ) -> Result<(), Self::Error>{ - let cost_index = get_local_allocate_cost_index(); - let cost = self.opcode_costs[cost_index]; - self.func_locals_costs += cost; + println!("current local: {}", n); + if n >= self.unmetered_locals { + let cost_index = get_local_allocate_cost_index(); + let cost = self.opcode_costs[cost_index]; + self.func_locals_costs += cost; + } Ok(()) } } diff --git a/lib/runtime-c-api/src/instance.rs b/lib/runtime-c-api/src/instance.rs index 6ed0df9c9b70..974d5d327a82 100644 --- a/lib/runtime-c-api/src/instance.rs +++ b/lib/runtime-c-api/src/instance.rs @@ -199,6 +199,7 @@ pub struct wasmer_compilation_options_t; pub struct CompilationOptions { pub gas_limit: u64, + pub unmetered_locals: usize, pub opcode_trace: bool, pub metering: bool, pub runtime_breakpoints: bool, @@ -246,25 +247,28 @@ pub unsafe extern "C" fn wasmer_instantiate_with_options( wasmer_result_t::WASMER_OK } -unsafe fn prepare_middleware_chain_generator(options: &CompilationOptions) -> impl Fn() -> MiddlewareChain { - let gas_limit = options.gas_limit; - let opcode_trace = options.opcode_trace; - let metering = options.metering; - let runtime_breakpoints = options.runtime_breakpoints; +unsafe fn prepare_middleware_chain_generator( + options: &CompilationOptions + ) -> impl Fn() -> MiddlewareChain + '_ { + let options = options.clone(); let chain_generator = move || { let mut chain = MiddlewareChain::new(); - if metering { + if options.metering { #[cfg(feature = "metering")] - chain.push(metering::Metering::new(gas_limit, &OPCODE_COSTS)); + chain.push(metering::Metering::new( + options.gas_limit, + &OPCODE_COSTS, + options.unmetered_locals + )); } - if runtime_breakpoints { + if options.runtime_breakpoints { chain.push(runtime_breakpoints::RuntimeBreakpointHandler::new()); } - if opcode_trace { + if options.opcode_trace { chain.push(opcode_trace::OpcodeTracer::new()); }; diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index a970de522d6a..d7ed59856826 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -119,7 +119,7 @@ unsafe fn get_metered_compiler(limit: u64) -> impl Compiler { let c: StreamingCompiler = StreamingCompiler::new(move || { let mut chain = MiddlewareChain::new(); - chain.push(metering::Metering::new(limit, &OPCODE_COSTS)); + chain.push(metering::Metering::new(limit, &OPCODE_COSTS, 0)); chain.push(runtime_breakpoints::RuntimeBreakpointHandler::new()); chain From c37845a90d6814b807d6bc6649f6a28cc65855ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 8 Sep 2020 16:27:55 +0300 Subject: [PATCH 070/129] Fix cost computation --- lib/middleware-common/src/metering.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/middleware-common/src/metering.rs b/lib/middleware-common/src/metering.rs index b7436cc614ec..1a1bb5bcab7c 100644 --- a/lib/middleware-common/src/metering.rs +++ b/lib/middleware-common/src/metering.rs @@ -128,11 +128,13 @@ impl<'q> FunctionMiddleware for Metering<'q> { n: usize, _loc: u32, ) -> Result<(), Self::Error>{ - println!("current local: {}", n); if n >= self.unmetered_locals { let cost_index = get_local_allocate_cost_index(); let cost = self.opcode_costs[cost_index]; - self.func_locals_costs += cost; + // n is already limited by Wasmparser; the following casting and multiplication are + // safe from overflowing + let n = n as u32; + self.func_locals_costs += cost * n; } Ok(()) } From 171d855efda03257aaae84f915b7b764e0b69be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 8 Sep 2020 16:49:23 +0300 Subject: [PATCH 071/129] Update Cargo.lock --- Cargo.lock | 493 +++++++++++++++++++++++++---------------------------- 1 file changed, 235 insertions(+), 258 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 506557110765..3195ad13d986 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,9 +2,9 @@ # It is not intended for manual editing. [[package]] name = "aho-corasick" -version = "0.7.9" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5e63fd144e18ba274ae7095c0197a870a7b9468abc801dd62f190d80817d2ec" +checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" dependencies = [ "memchr", ] @@ -20,9 +20,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.26" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7825f6833612eb2414095684fcf6c635becf3ce97fe48cf6421321e93bfbd53c" +checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b" [[package]] name = "arrayref" @@ -30,15 +30,6 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" -[[package]] -name = "arrayvec" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9" -dependencies = [ - "nodrop", -] - [[package]] name = "arrayvec" version = "0.5.1" @@ -64,15 +55,15 @@ checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" [[package]] name = "autocfg" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bincode" -version = "1.2.1" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5753e2a71534719bf3f4e57006c3a4f0d2c672a4b676eec84161f763eca87dbf" +checksum = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d" dependencies = [ "byteorder", "serde", @@ -91,7 +82,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46080006c1505f12f64dd2a09264b343381ed3190fa02c8005d5d662ac571c63" dependencies = [ "arrayref", - "arrayvec 0.5.1", + "arrayvec", "cc", "cfg-if", "constant_time_eq", @@ -101,9 +92,9 @@ dependencies = [ [[package]] name = "bstr" -version = "0.2.11" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "502ae1441a0a5adb8fbd38a5955a6416b9493e92b465de5e4a9bde6a539c2c48" +checksum = "31accafdb70df7871592c058eca3985b71104e15ac32f64706022c58867da931" dependencies = [ "lazy_static", "memchr", @@ -117,15 +108,6 @@ version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" -[[package]] -name = "c2-chacha" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb" -dependencies = [ - "ppv-lite86", -] - [[package]] name = "cast" version = "0.2.3" @@ -143,20 +125,20 @@ checksum = "9daec6140ab4dcd38c3dd57e580b59a621172a526ac79f1527af760a55afeafd" dependencies = [ "clap", "log", - "proc-macro2 1.0.9", - "quote 1.0.3", + "proc-macro2 1.0.20", + "quote 1.0.7", "serde", "serde_json", - "syn 1.0.16", + "syn 1.0.40", "tempfile", "toml", ] [[package]] name = "cc" -version = "1.0.50" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd" +checksum = "66120af515773fb005778dc07c261bd201ec8ce50bd6e7144c927753fe013381" [[package]] name = "cfg-if" @@ -166,9 +148,9 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "chrono" -version = "0.4.10" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31850b4a4d6bae316f7a09e691c944c28299298837edc0a03f755618c23cbc01" +checksum = "942f72db697d8767c22d46a598e01f2d3b475501ea43d0db4f16d90259182d0b" dependencies = [ "num-integer", "num-traits", @@ -177,9 +159,9 @@ dependencies = [ [[package]] name = "clap" -version = "2.33.0" +version = "2.33.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" dependencies = [ "ansi_term", "atty", @@ -201,9 +183,9 @@ dependencies = [ [[package]] name = "cmake" -version = "0.1.42" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62" +checksum = "0e56268c17a6248366d66d4a47a3381369d068cce8409bb1716ed77ea32163bb" dependencies = [ "cc", ] @@ -247,7 +229,7 @@ dependencies = [ "cranelift-entity 0.59.0", "gimli", "log", - "smallvec 1.2.0", + "smallvec 1.4.2", "target-lexicon 0.10.0", "thiserror", ] @@ -329,6 +311,16 @@ dependencies = [ "itertools", ] +[[package]] +name = "crossbeam-channel" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87" +dependencies = [ + "crossbeam-utils", + "maybe-uninit", +] + [[package]] name = "crossbeam-deque" version = "0.7.3" @@ -346,7 +338,7 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" dependencies = [ - "autocfg 1.0.0", + "autocfg 1.0.1", "cfg-if", "crossbeam-utils", "lazy_static", @@ -355,23 +347,13 @@ dependencies = [ "scopeguard", ] -[[package]] -name = "crossbeam-queue" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c695eeca1e7173472a32221542ae469b3e9aac3a4fc81f7696bcad82029493db" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - [[package]] name = "crossbeam-utils" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" dependencies = [ - "autocfg 1.0.0", + "autocfg 1.0.1", "cfg-if", "lazy_static", ] @@ -410,12 +392,12 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.13" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47c5e5ac752e18207b12e16b10631ae5f7f68f8805f335f9b817ead83d9ffce1" +checksum = "39858aa5bac06462d4dd4b9164848eb81ffc4aa5c479746393598fd193afa227" dependencies = [ - "quote 1.0.3", - "syn 1.0.16", + "quote 1.0.7", + "syn 1.0.40", ] [[package]] @@ -437,9 +419,9 @@ dependencies = [ "byteorder", "lazy_static", "owning_ref", - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.16", + "proc-macro2 1.0.20", + "quote 1.0.7", + "syn 1.0.40", ] [[package]] @@ -454,24 +436,24 @@ dependencies = [ [[package]] name = "either" -version = "1.5.3" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f" [[package]] name = "erased-serde" -version = "0.3.10" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd7d80305c9bd8cd78e3c753eb9fb110f83621e5211f1a3afffcc812b104daf9" +checksum = "6ca8b296792113e1500fd935ae487be6e00ce318952a6880555554824d6ebf38" dependencies = [ "serde", ] [[package]] name = "errno" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2a071601ed01b988f896ab14b95e67335d1eeb50190932a1320f7fe3cadc84e" +checksum = "6eab5ee3df98a279d9b316b1af6ac95422127b1290317e6d18c1743c99418b01" dependencies = [ "errno-dragonfly", "libc", @@ -535,9 +517,9 @@ checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" [[package]] name = "generational-arena" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e40d0cee2e2fb4fba18b55a27bf96faf49fa86d49f178695bd3bf4500b156b4" +checksum = "8e1d3b771574f62d0548cee0ad9057857e9fc25d7a3335f140c84f6acd0bf601" dependencies = [ "cfg-if", "serde", @@ -560,18 +542,18 @@ checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.9.0+wasi-snapshot-preview1", ] [[package]] name = "ghost" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a36606a68532b5640dc86bb1f33c64b45c4682aad4c50f3937b317ea387f3d6" +checksum = "1a5bcf1bbeab73aa4cf2fde60a846858dc036163c7c33bec309f8d17de785479" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.16", + "proc-macro2 1.0.20", + "quote 1.0.7", + "syn 1.0.40", ] [[package]] @@ -580,11 +562,11 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81dd6190aad0f05ddbbf3245c54ed14ca4aa6dd32f22312b70d8f168c3e3e633" dependencies = [ - "arrayvec 0.5.1", + "arrayvec", "byteorder", "fallible-iterator", "indexmap", - "smallvec 1.2.0", + "smallvec 1.4.2", "stable_deref_trait", ] @@ -622,6 +604,12 @@ dependencies = [ "scroll 0.10.1", ] +[[package]] +name = "hashbrown" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d63df3d41950fb462ed38308eea019113ad1508da725bbedcd0fa5a85ef5f7" + [[package]] name = "heck" version = "0.3.1" @@ -633,9 +621,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.8" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1010591b26bbfe835e9faeabeb11866061cc7dcebffd56ad7d0942d0e61aefd8" +checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" dependencies = [ "libc", ] @@ -648,11 +636,12 @@ checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" [[package]] name = "indexmap" -version = "1.3.2" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076f042c5b7b98f31d205f1249267e12a6518c1481e9dae9764af19b707d2292" +checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2" dependencies = [ - "autocfg 1.0.0", + "autocfg 1.0.1", + "hashbrown", "serde", ] @@ -682,9 +671,9 @@ dependencies = [ [[package]] name = "inventory" -version = "0.1.5" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bf98296081bd2cb540acc09ef9c97f22b7e487841520350293605db1b2c7a27" +checksum = "fedd49de24d8c263613701406611410687148ae8c37cd6452650b250f753a0dd" dependencies = [ "ctor", "ghost", @@ -693,13 +682,13 @@ dependencies = [ [[package]] name = "inventory-impl" -version = "0.1.5" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a8e30575afe28eea36a9a39136b70b2fb6b0dd0a212a5bd1f30a498395c0274" +checksum = "ddead8880bc50f57fcd3b5869a7f6ff92570bb4e8f6870c22e2483272f2256da" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.16", + "proc-macro2 1.0.20", + "quote 1.0.7", + "syn 1.0.40", ] [[package]] @@ -713,9 +702,9 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" +checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" [[package]] name = "kernel-net" @@ -735,28 +724,28 @@ checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" [[package]] name = "lexical-core" -version = "0.6.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7043aa5c05dd34fb73b47acb8c3708eac428de4545ea3682ed2f11293ebd890" +checksum = "db65c6da02e61f55dae90a0ae427b2a5f6b3e8db09f58d10efab23af92592616" dependencies = [ - "arrayvec 0.4.12", + "arrayvec", + "bitflags", "cfg-if", - "rustc_version", "ryu", "static_assertions", ] [[package]] name = "libc" -version = "0.2.67" +version = "0.2.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018" +checksum = "755456fae044e6fa1ebbbd1b3e902ae19e73097ed4ed87bb79934a867c007bc3" [[package]] name = "llvm-sys" -version = "80.1.2" +version = "80.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf2969773884a5701f0c255e2a14d48d4522a66db898ec1088cb21879a228377" +checksum = "cf4fb7d47ccdd80d10f82f418571d11da166ef5180c39a327c32060cf3dad7a1" dependencies = [ "cc", "lazy_static", @@ -767,18 +756,18 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79b2de95ecb4691949fea4716ca53cdbcfccb2c612e19644a8bad05edcf9f47b" +checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" dependencies = [ "scopeguard", ] [[package]] name = "log" -version = "0.4.8" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" dependencies = [ "cfg-if", ] @@ -813,11 +802,11 @@ dependencies = [ [[package]] name = "memoffset" -version = "0.5.3" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75189eb85871ea5c2e2c15abbdd541185f63b408415e5051f5cac122d8c774b9" +checksum = "c198b026e1bbf08a937e94c6c60f9ec4a2267f5b0d2eec9c1b21b061ce2be55f" dependencies = [ - "rustc_version", + "autocfg 1.0.1", ] [[package]] @@ -853,17 +842,11 @@ dependencies = [ "void", ] -[[package]] -name = "nodrop" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" - [[package]] name = "nom" -version = "5.1.1" +version = "5.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b471253da97532da4b61552249c521e01e736071f71c1a4f7ebbfbf0a06aad6" +checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" dependencies = [ "lexical-core", "memchr", @@ -883,39 +866,39 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.42" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba" +checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" dependencies = [ - "autocfg 1.0.0", + "autocfg 1.0.1", "num-traits", ] [[package]] name = "num-iter" -version = "0.1.40" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfb0800a0291891dd9f4fe7bd9c19384f98f7fbe0cd0f39a2c6b88b9868bbc00" +checksum = "7a6e6b7c748f995c4c29c5f5ae0248536e04a5739927c74ec0fa564805094b9f" dependencies = [ - "autocfg 1.0.0", + "autocfg 1.0.1", "num-integer", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" +checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" dependencies = [ - "autocfg 1.0.0", + "autocfg 1.0.1", ] [[package]] name = "num_cpus" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46203554f085ff89c235cd12f7075f3233af9b11ed7c9e16dfe2560d03313ce6" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" dependencies = [ "hermit-abi", "libc", @@ -923,9 +906,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.3.1" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b" +checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" [[package]] name = "orbclient" @@ -976,9 +959,9 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.10.0" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92e98c49ab0b7ce5b222f2cc9193fc4efe11c6d0bd4f648e374684a6857b1cfc" +checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" dependencies = [ "lock_api", "parking_lot_core", @@ -986,23 +969,23 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7582838484df45743c8434fbff785e8edf260c28748353d44bc0da32e0ceabf1" +checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" dependencies = [ "cfg-if", "cloudabi", "libc", "redox_syscall", - "smallvec 1.2.0", + "smallvec 1.4.2", "winapi", ] [[package]] name = "pkg-config" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" +checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" [[package]] name = "plain" @@ -1016,33 +999,31 @@ version = "0.1.0" [[package]] name = "ppv-lite86" -version = "0.2.6" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" +checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" [[package]] name = "proc-macro-error" -version = "0.4.11" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7959c6467d962050d639361f7703b2051c43036d03493c36f01d440fdd3138a" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.16", + "proc-macro2 1.0.20", + "quote 1.0.7", + "syn 1.0.40", "version_check", ] [[package]] name = "proc-macro-error-attr" -version = "0.4.11" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4002d9f55991d5e019fb940a90e1a95eb80c24e77cb2462dd4dc869604d543a" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.16", - "syn-mid", + "proc-macro2 1.0.20", + "quote 1.0.7", "version_check", ] @@ -1057,11 +1038,11 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.9" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435" +checksum = "175c513d55719db99da20232b06cda8bab6b83ec2d04e3283edf0213c37c1a29" dependencies = [ - "unicode-xid 0.2.0", + "unicode-xid 0.2.1", ] [[package]] @@ -1075,11 +1056,11 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.3" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" dependencies = [ - "proc-macro2 1.0.9", + "proc-macro2 1.0.20", ] [[package]] @@ -1109,7 +1090,7 @@ checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ "getrandom", "libc", - "rand_chacha 0.2.1", + "rand_chacha 0.2.2", "rand_core 0.5.1", "rand_hc 0.2.0", ] @@ -1126,11 +1107,11 @@ dependencies = [ [[package]] name = "rand_chacha" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ - "c2-chacha", + "ppv-lite86", "rand_core 0.5.1", ] @@ -1252,10 +1233,11 @@ dependencies = [ [[package]] name = "rayon" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db6ce3297f9c85e16621bb8cca38a06779ffc31bb8184e1be4bed2be4678a098" +checksum = "cfd016f0c045ad38b5251be2c9c0ab806917f82da4d36b2a327e5166adad9270" dependencies = [ + "autocfg 1.0.1", "crossbeam-deque", "either", "rayon-core", @@ -1263,12 +1245,12 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08a89b46efaf957e52b18062fb2f4660f8b8a4dde1807ca002690868ef2c85a9" +checksum = "91739a34c4355b5434ce54c9086c5895604a9c278586d1f1aa95e04f66b525a0" dependencies = [ + "crossbeam-channel", "crossbeam-deque", - "crossbeam-queue", "crossbeam-utils", "lazy_static", "num_cpus", @@ -1285,9 +1267,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "ref_thread_local" @@ -1297,9 +1279,9 @@ checksum = "d813022b2e00774a48eaf43caaa3c20b45f040ba8cbf398e2e8911a06668dbe6" [[package]] name = "regex" -version = "1.3.4" +version = "1.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322cf97724bea3ee221b78fe25ac9c46114ebb51747ad5babd51a2fc6a8235a8" +checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" dependencies = [ "aho-corasick", "memchr", @@ -1309,24 +1291,24 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92b73c2a1770c255c240eaa4ee600df1704a38dc3feaa6e949e7fcd4f8dc09f9" +checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" dependencies = [ "byteorder", ] [[package]] name = "regex-syntax" -version = "0.6.16" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1132f845907680735a84409c3bebc64d1364a5683ffbce899550cd09d5eaefc1" +checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" [[package]] name = "remove_dir_all" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ "winapi", ] @@ -1342,9 +1324,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.2" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "same-file" @@ -1377,7 +1359,7 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb2332cb595d33f7edd5700f4cbf94892e680c7f0ae56adab58a35190b66cb1" dependencies = [ - "scroll_derive 0.10.1", + "scroll_derive 0.10.2", ] [[package]] @@ -1393,13 +1375,13 @@ dependencies = [ [[package]] name = "scroll_derive" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8584eea9b9ff42825b46faf46a8c24d2cff13ec152fa2a50df788b87c07ee28" +checksum = "e367622f934864ffa1c704ba2b82280aab856e3d8213c84c5720257eb34b15b9" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.16", + "proc-macro2 1.0.20", + "quote 1.0.7", + "syn 1.0.40", ] [[package]] @@ -1443,9 +1425,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.104" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" +checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5" dependencies = [ "serde_derive", ] @@ -1462,29 +1444,29 @@ dependencies = [ [[package]] name = "serde_bytes" -version = "0.11.3" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "325a073952621257820e7a3469f55ba4726d8b28657e7e36653d1c36dc2c84ae" +checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9" dependencies = [ "serde", ] [[package]] name = "serde_derive" -version = "1.0.104" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" +checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.16", + "proc-macro2 1.0.20", + "quote 1.0.7", + "syn 1.0.40", ] [[package]] name = "serde_json" -version = "1.0.48" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9371ade75d4c2d6cb154141b9752cf3781ec9c05e0e5cf35060e1e70ee7b9c25" +checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c" dependencies = [ "itoa", "ryu", @@ -1502,21 +1484,21 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.2.0" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c2fb2ec9bcd216a5b0d0ccf31ab17b5ed1d627960edff65bbe95d3ce221cefc" +checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" [[package]] name = "stable_deref_trait" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "static_assertions" -version = "0.3.4" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f3eb36b47e512f8f1c9e3d10c2c1965bc992bd9cdb024fa581e2194501c83d3" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "string-interner" @@ -1535,9 +1517,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.11" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fe43617218c0805c6eb37160119dc3c548110a67786da7218d1c6555212f073" +checksum = "6cc388d94ffabf39b5ed5fadddc40147cb21e605f53db6f8f36a625d27489ac5" dependencies = [ "clap", "lazy_static", @@ -1546,15 +1528,15 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.4" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6e79c80e0f4efd86ca960218d4e056249be189ff1c42824dcd9a7f51a56f0bd" +checksum = "5e2513111825077552a6751dfad9e11ce0fba07d7276a3943a037d7e93e64c5f" dependencies = [ "heck", "proc-macro-error", - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.16", + "proc-macro2 1.0.20", + "quote 1.0.7", + "syn 1.0.40", ] [[package]] @@ -1576,24 +1558,13 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.16" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "123bd9499cfb380418d509322d7a6d52e5315f064fe4b3ad18a53d6b92c07859" +checksum = "963f7d3cc59b59b9325165add223142bbf1df27655d07789f109896d353d8350" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "unicode-xid 0.2.0", -] - -[[package]] -name = "syn-mid" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a" -dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.16", + "proc-macro2 1.0.20", + "quote 1.0.7", + "unicode-xid 0.2.1", ] [[package]] @@ -1633,22 +1604,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.11" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee14bf8e6767ab4c687c9e8bc003879e042a96fd67a3ba5934eadb6536bef4db" +checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.11" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7b51e1fbc44b5a0840be594fbc0f960be09050f2617e61e6aa43bef97cd3ef4" +checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.16", + "proc-macro2 1.0.20", + "quote 1.0.7", + "syn 1.0.40", ] [[package]] @@ -1662,20 +1633,20 @@ dependencies = [ [[package]] name = "time" -version = "0.1.42" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ "libc", - "redox_syscall", + "wasi 0.10.0+wasi-snapshot-preview1", "winapi", ] [[package]] name = "tinytemplate" -version = "1.0.3" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a3c6667d3e65eb1bc3aed6fd14011c6cbc3a0665218ab7f5daf040b9ec371a" +checksum = "6d3dc76004a03cec1c5932bca4cdc2e39aaa798e3f82363dd94f9adf6098c12f" dependencies = [ "serde", "serde_json", @@ -1692,15 +1663,15 @@ dependencies = [ [[package]] name = "typenum" -version = "1.11.2" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" [[package]] name = "typetag" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ebb2c484029d695fb68a06d80e1536c68d491b3e0cf874c66abed255e831cfe" +checksum = "9275125decb5d75fe57ebfe92debd119b15757aae27c56d7cb61ecab871960bc" dependencies = [ "erased-serde", "inventory", @@ -1711,13 +1682,13 @@ dependencies = [ [[package]] name = "typetag-impl" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b63fd4799e4d0ec5cf0b055ebb8e2c3a657bbf76a84f6edc77ca60780e000204" +checksum = "dc232cda3b1d82664153e6c95d1071809aa0f1011f306c3d6989f33d8c6ede17" dependencies = [ - "proc-macro2 1.0.9", - "quote 1.0.3", - "syn 1.0.16", + "proc-macro2 1.0.20", + "quote 1.0.7", + "syn 1.0.40", ] [[package]] @@ -1728,9 +1699,9 @@ checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" [[package]] name = "unicode-width" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" @@ -1740,21 +1711,21 @@ checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" [[package]] name = "unicode-xid" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "vec_map" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "version_check" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" +checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" [[package]] name = "void" @@ -1764,9 +1735,9 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" [[package]] name = "wabt" -version = "0.9.2" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5c5c1286c6e578416982609f47594265f9d489f9b836157d403ad605a46693" +checksum = "94b5f5d6984ca42df66280baa8a15ac188a173ddaf4580b574a98931c01920e7" dependencies = [ "serde", "serde_derive", @@ -1776,9 +1747,9 @@ dependencies = [ [[package]] name = "wabt-sys" -version = "0.7.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af5d153dc96aad7dc13ab90835b892c69867948112d95299e522d370c4e13a08" +checksum = "b064c81821100adb4b71923cecfc67fef083db21c3bbd454b0162c7ffe63eeaa" dependencies = [ "cc", "cmake", @@ -1802,6 +1773,12 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + [[package]] name = "wasm-debug" version = "0.1.0" @@ -1882,7 +1859,7 @@ checksum = "c23f2824f354a00a77e4b040eef6e1d4c595a8a3e9013bad65199cc8dade9a5a" dependencies = [ "cranelift-codegen", "log", - "smallvec 1.2.0", + "smallvec 1.4.2", "target-lexicon 0.10.0", ] @@ -2165,7 +2142,7 @@ checksum = "c702914acda5feeeffbc29e4d953e5b9ce79d8b98da4dbf18a77086e116c5470" [[package]] name = "wasmparser" version = "0.51.4" -source = "git+https://github.com/ElrondNetwork/wasmparser.rs#57f8cec1a47850cb804776cc858e83300576fea2" +source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" [[package]] name = "wasmparser" @@ -2184,9 +2161,9 @@ dependencies = [ [[package]] name = "winapi" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", @@ -2200,9 +2177,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ "winapi", ] From 666d2be13c1548f4eae4a5dc79293fac0a6f8d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 8 Sep 2020 18:05:32 +0300 Subject: [PATCH 072/129] Allow exactly self.unmetered_locals --- lib/middleware-common/src/metering.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/middleware-common/src/metering.rs b/lib/middleware-common/src/metering.rs index 1a1bb5bcab7c..e310d7362cf0 100644 --- a/lib/middleware-common/src/metering.rs +++ b/lib/middleware-common/src/metering.rs @@ -128,7 +128,7 @@ impl<'q> FunctionMiddleware for Metering<'q> { n: usize, _loc: u32, ) -> Result<(), Self::Error>{ - if n >= self.unmetered_locals { + if n > self.unmetered_locals { let cost_index = get_local_allocate_cost_index(); let cost = self.opcode_costs[cost_index]; // n is already limited by Wasmparser; the following casting and multiplication are From 0285feb406b723191d59bdcc366f47e607756fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 8 Sep 2020 21:59:55 +0300 Subject: [PATCH 073/129] Fix metered locals --- lib/middleware-common/src/metering.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/middleware-common/src/metering.rs b/lib/middleware-common/src/metering.rs index e310d7362cf0..573274242ab9 100644 --- a/lib/middleware-common/src/metering.rs +++ b/lib/middleware-common/src/metering.rs @@ -129,12 +129,12 @@ impl<'q> FunctionMiddleware for Metering<'q> { _loc: u32, ) -> Result<(), Self::Error>{ if n > self.unmetered_locals { + let metered_locals = (n - self.unmetered_locals) as u32; let cost_index = get_local_allocate_cost_index(); let cost = self.opcode_costs[cost_index]; // n is already limited by Wasmparser; the following casting and multiplication are // safe from overflowing - let n = n as u32; - self.func_locals_costs += cost * n; + self.func_locals_costs += cost * metered_locals; } Ok(()) } From 3b78f9a4f8860f118962771db7829908755e8789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Thu, 29 Oct 2020 19:46:16 +0200 Subject: [PATCH 074/129] Add instance caching functionality and C API (WIP) --- Cargo.lock | 6 +-- lib/middleware-common/src/metering.rs | 16 +++--- lib/runtime-c-api/src/instance.rs | 4 +- lib/runtime-c-api/src/instance_cache.rs | 66 +++++++++++++++++++++++++ lib/runtime-c-api/src/lib.rs | 2 + lib/runtime-c-api/src/metering.rs | 20 +++++++- lib/runtime-c-api/wasmer.h | 10 ++++ lib/runtime-c-api/wasmer.hh | 10 ++++ 8 files changed, 121 insertions(+), 13 deletions(-) create mode 100644 lib/runtime-c-api/src/instance_cache.rs diff --git a/Cargo.lock b/Cargo.lock index 3195ad13d986..0db7432398d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2142,13 +2142,13 @@ checksum = "c702914acda5feeeffbc29e4d953e5b9ce79d8b98da4dbf18a77086e116c5470" [[package]] name = "wasmparser" version = "0.51.4" -source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" [[package]] name = "wasmparser" version = "0.51.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" +source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" [[package]] name = "wast" diff --git a/lib/middleware-common/src/metering.rs b/lib/middleware-common/src/metering.rs index 573274242ab9..0bcf94dc28a3 100644 --- a/lib/middleware-common/src/metering.rs +++ b/lib/middleware-common/src/metering.rs @@ -10,6 +10,7 @@ use crate::metering_costs::{get_opcode_index, get_local_allocate_cost_index}; use crate::runtime_breakpoints::push_runtime_breakpoint; static FIELD_USED_POINTS: InternalField = InternalField::allocate(); +static FIELD_POINTS_LIMIT: InternalField = InternalField::allocate(); pub const BREAKPOINT_VALUE__OUT_OF_GAS: u64 = 4; /// Metering is a compiler middleware that calculates the cost of WebAssembly instructions at compile @@ -26,7 +27,6 @@ pub const BREAKPOINT_VALUE__OUT_OF_GAS: u64 = 4; /// pub struct Metering<'a> { - limit: u64, unmetered_locals: usize, current_block: u64, func_locals_costs: u32, @@ -34,9 +34,8 @@ pub struct Metering<'a> { } impl<'a> Metering<'a> { - pub fn new(limit: u64, opcode_costs: &'a [u32], unmetered_locals: usize) -> Metering<'a> { + pub fn new(opcode_costs: &'a [u32], unmetered_locals: usize) -> Metering<'a> { Metering { - limit, unmetered_locals, current_block: 0, func_locals_costs: 0, @@ -101,9 +100,9 @@ impl<'q> FunctionMiddleware for Metering<'q> { sink.push(Event::Internal(InternalEvent::GetInternal( FIELD_USED_POINTS.index() as _, ))); - sink.push(Event::WasmOwned(Operator::I64Const { - value: self.limit as i64, - })); + sink.push(Event::Internal(InternalEvent::GetInternal( + FIELD_POINTS_LIMIT.index() as _, + ))); sink.push(Event::WasmOwned(Operator::I64GeU)); sink.push(Event::WasmOwned(Operator::If { ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), @@ -150,6 +149,11 @@ pub fn set_points_used(instance: &mut Instance, value: u64) { instance.set_internal(&FIELD_USED_POINTS, value); } +/// Sets the limit of points to be used by an Instance. +pub fn set_points_limit(instance: &mut Instance, value: u64) { + instance.set_internal(&FIELD_POINTS_LIMIT, value); +} + /// Returns the number of points used in a Ctx. pub fn get_points_used_ctx(ctx: &Ctx) -> u64 { ctx.get_internal(&FIELD_USED_POINTS) diff --git a/lib/runtime-c-api/src/instance.rs b/lib/runtime-c-api/src/instance.rs index 974d5d327a82..c4e8ac586eb4 100644 --- a/lib/runtime-c-api/src/instance.rs +++ b/lib/runtime-c-api/src/instance.rs @@ -236,13 +236,14 @@ pub unsafe extern "C" fn wasmer_instantiate_with_options( let import_object: &mut ImportObject = &mut *(GLOBAL_IMPORT_OBJECT as *mut ImportObject); let result_instantiation = new_module.instantiate(&import_object); - let new_instance = match result_instantiation { + let mut new_instance = match result_instantiation { Ok(instance) => instance, Err(error) => { update_last_error(error); return wasmer_result_t::WASMER_ERROR; } }; + metering::set_points_limit(&mut new_instance, options.gas_limit); *instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t; wasmer_result_t::WASMER_OK } @@ -258,7 +259,6 @@ unsafe fn prepare_middleware_chain_generator( if options.metering { #[cfg(feature = "metering")] chain.push(metering::Metering::new( - options.gas_limit, &OPCODE_COSTS, options.unmetered_locals )); diff --git a/lib/runtime-c-api/src/instance_cache.rs b/lib/runtime-c-api/src/instance_cache.rs new file mode 100644 index 000000000000..b6762a226819 --- /dev/null +++ b/lib/runtime-c-api/src/instance_cache.rs @@ -0,0 +1,66 @@ +use crate::{ + error::{update_last_error, CApiError}, + instance::wasmer_instance_t, + wasmer_result_t, +}; +// use wasmer_runtime::{ +// Instance, Module +// }; +// use wasmer_runtime_core::cache::{Artifact, Error as CacheError}; + + +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_instance_cache( + instance: *mut wasmer_instance_t, + cache_bytes: *mut *const u8, + cache_len: *mut u32, +) -> wasmer_result_t { + if instance.is_null() { + update_last_error(CApiError { + msg: "null instance".to_string(), + }); + return wasmer_result_t::WASMER_ERROR; + } + let instance = &mut *(instance as *mut wasmer_runtime::Instance); + let module = instance.module(); + let cache_result = module.cache(); + match cache_result { + Err(error) => { + update_last_error(CApiError { + msg: format!("{:?}", error), + }); + return wasmer_result_t::WASMER_ERROR; + } + Ok(artifact) => { + let serialize_result = artifact.serialize(); + match serialize_result { + Err(error) => { + update_last_error(CApiError { + msg: format!("{:?}", error), + }); + return wasmer_result_t::WASMER_ERROR; + } + Ok(bytes_vec) => { + if !bytes_vec.is_empty() { + *cache_bytes = bytes_vec.as_ptr(); + *cache_len = bytes_vec.len() as u32; + } + } + } + } + }; + + wasmer_result_t::WASMER_OK +} + +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_instance_from_cache( + _instance: *mut *mut wasmer_instance_t, + _cache_bytes: *mut u8, + _cache_len: u32, +) -> wasmer_result_t { + // TODO set points limit + wasmer_result_t::WASMER_OK +} diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index 0932b8d2efd4..50410b7795f8 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -103,6 +103,8 @@ pub mod memory; #[cfg(feature = "metering")] pub mod metering; +pub mod instance_cache; + pub mod runtime_breakpoints; pub mod module; diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index d7ed59856826..39eb1b2c77ac 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -56,6 +56,22 @@ pub unsafe extern "C" fn wasmer_instance_set_points_used( metering::set_points_used(instance, new_gas) } +// sets gas limit +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +#[cfg(feature = "metering")] +pub unsafe extern "C" fn wasmer_instance_set_points_limit( + instance: *mut wasmer_instance_t, + limit: u64, +) { + if instance.is_null() { + return; + } + let instance = &mut *(instance as *mut wasmer_runtime::Instance); + metering::set_points_limit(instance, limit) +} + + /// Creates a new Module with gas limit from the given wasm bytes. /// /// Returns `wasmer_result_t::WASMER_OK` upon success. @@ -102,7 +118,7 @@ pub unsafe extern "C" fn wasmer_compile_with_gas_metering( } #[cfg(feature = "metering")] -unsafe fn get_metered_compiler(limit: u64) -> impl Compiler { +unsafe fn get_metered_compiler(_limit: u64) -> impl Compiler { use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler}; #[cfg(feature = "llvm-backend")] @@ -119,7 +135,7 @@ unsafe fn get_metered_compiler(limit: u64) -> impl Compiler { let c: StreamingCompiler = StreamingCompiler::new(move || { let mut chain = MiddlewareChain::new(); - chain.push(metering::Metering::new(limit, &OPCODE_COSTS, 0)); + chain.push(metering::Metering::new(&OPCODE_COSTS, 0)); chain.push(runtime_breakpoints::RuntimeBreakpointHandler::new()); chain diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 36f34648ab15..8b6fd5ce2f8b 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -854,6 +854,10 @@ wasmer_import_object_iter_t *wasmer_import_object_iterate_functions(const wasmer */ wasmer_import_object_t *wasmer_import_object_new(void); +wasmer_result_t wasmer_instance_cache(wasmer_instance_t *instance, + const uint8_t **cache_bytes, + uint32_t *cache_len); + /** * Calls an exported function of a WebAssembly instance by `name` * with the provided parameters. The exported function results are @@ -1067,10 +1071,16 @@ void wasmer_instance_destroy(wasmer_instance_t *instance); */ void wasmer_instance_exports(wasmer_instance_t *instance, wasmer_exports_t **exports); +wasmer_result_t wasmer_instance_from_cache(wasmer_instance_t **_instance, + uint8_t *_cache_bytes, + uint32_t _cache_len); + uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); uint64_t wasmer_instance_get_runtime_breakpoint_value(wasmer_instance_t *instance); +void wasmer_instance_set_points_limit(wasmer_instance_t *instance, uint64_t limit); + void wasmer_instance_set_points_used(wasmer_instance_t *instance, uint64_t new_gas); void wasmer_instance_set_runtime_breakpoint_value(wasmer_instance_t *instance, uint64_t value); diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 18f22ee51614..4c7a53241730 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -669,6 +669,10 @@ wasmer_import_object_iter_t *wasmer_import_object_iterate_functions(const wasmer /// See also `wasmer_import_object_append` wasmer_import_object_t *wasmer_import_object_new(); +wasmer_result_t wasmer_instance_cache(wasmer_instance_t *instance, + const uint8_t **cache_bytes, + uint32_t *cache_len); + /// Calls an exported function of a WebAssembly instance by `name` /// with the provided parameters. The exported function results are /// stored on the provided `results` pointer. @@ -868,10 +872,16 @@ void wasmer_instance_destroy(wasmer_instance_t *instance); /// ``` void wasmer_instance_exports(wasmer_instance_t *instance, wasmer_exports_t **exports); +wasmer_result_t wasmer_instance_from_cache(wasmer_instance_t **_instance, + uint8_t *_cache_bytes, + uint32_t _cache_len); + uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); uint64_t wasmer_instance_get_runtime_breakpoint_value(wasmer_instance_t *instance); +void wasmer_instance_set_points_limit(wasmer_instance_t *instance, uint64_t limit); + void wasmer_instance_set_points_used(wasmer_instance_t *instance, uint64_t new_gas); void wasmer_instance_set_runtime_breakpoint_value(wasmer_instance_t *instance, uint64_t value); From 69c5b0d3cb71fd23930a70a1e81f779545cb2cf3 Mon Sep 17 00:00:00 2001 From: Robert Sasu Date: Fri, 30 Oct 2020 12:32:49 +0200 Subject: [PATCH 075/129] improvements here and there. not compiling yet. --- lib/runtime-c-api/src/instance_cache.rs | 38 +++++++++++++++++-- lib/runtime-c-api/src/metering.rs | 6 +-- .../tests/test-module-metering-serialize.c | 2 +- lib/runtime-c-api/wasmer.h | 3 +- lib/runtime-c-api/wasmer.hh | 3 +- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/lib/runtime-c-api/src/instance_cache.rs b/lib/runtime-c-api/src/instance_cache.rs index b6762a226819..485c1b0586b3 100644 --- a/lib/runtime-c-api/src/instance_cache.rs +++ b/lib/runtime-c-api/src/instance_cache.rs @@ -57,10 +57,40 @@ pub unsafe extern "C" fn wasmer_instance_cache( #[allow(clippy::cast_ptr_alignment)] #[no_mangle] pub unsafe extern "C" fn wasmer_instance_from_cache( - _instance: *mut *mut wasmer_instance_t, - _cache_bytes: *mut u8, - _cache_len: u32, + instance: *mut *mut wasmer_instance_t, + cache_bytes: *mut u8, + cache_len: u32, + gas_limit: u64, ) -> wasmer_result_t { - // TODO set points limit + if cache_bytes.is_null() { + update_last_error(CApiError { + msg: "cache bytes ptr is null".to_string(), + }); + return wasmer_result_t::WASMER_ERROR; + } + + let bytes: &[u8] = slice::from_raw_parts_mut(cache_bytes, cache_len as usize); + + + + let new_module = match result_compilation { + Ok(module) => module, + Err(_) => { + update_last_error(CApiError { msg: "compile error".to_string() }); + return wasmer_result_t::WASMER_ERROR; + } + }; + + let import_object: &mut ImportObject = &mut *(GLOBAL_IMPORT_OBJECT as *mut ImportObject); + let result_instantiation = new_module.instantiate(&import_object); + let mut new_instance = match result_instantiation { + Ok(instance) => instance, + Err(error) => { + update_last_error(error); + return wasmer_result_t::WASMER_ERROR; + } + }; + metering::set_points_limit(&mut new_instance, gas_limit); + *instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t; wasmer_result_t::WASMER_OK } diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 39eb1b2c77ac..72c4e6a12ab2 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -85,7 +85,6 @@ pub unsafe extern "C" fn wasmer_compile_with_gas_metering( module: *mut *mut wasmer_module_t, wasm_bytes: *mut u8, wasm_bytes_len: u32, - gas_limit: u64, ) -> wasmer_result_t { if module.is_null() { update_last_error(CApiError { @@ -100,7 +99,7 @@ pub unsafe extern "C" fn wasmer_compile_with_gas_metering( return wasmer_result_t::WASMER_ERROR; } - let compiler = get_metered_compiler(gas_limit); + let compiler = get_metered_compiler(); let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize); let result = wasmer_runtime_core::compile_with(bytes, &compiler); @@ -118,7 +117,7 @@ pub unsafe extern "C" fn wasmer_compile_with_gas_metering( } #[cfg(feature = "metering")] -unsafe fn get_metered_compiler(_limit: u64) -> impl Compiler { +unsafe fn get_metered_compiler() -> impl Compiler { use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler}; #[cfg(feature = "llvm-backend")] @@ -153,7 +152,6 @@ pub unsafe extern "C" fn wasmer_compile_with_gas_metering( module: *mut *mut wasmer_module_t, wasm_bytes: *mut u8, wasm_bytes_len: u32, - _: u64, ) -> wasmer_result_t { if module.is_null() { update_last_error(CApiError { diff --git a/lib/runtime-c-api/tests/test-module-metering-serialize.c b/lib/runtime-c-api/tests/test-module-metering-serialize.c index 65ad94562095..4b30f90558c2 100644 --- a/lib/runtime-c-api/tests/test-module-metering-serialize.c +++ b/lib/runtime-c-api/tests/test-module-metering-serialize.c @@ -16,7 +16,7 @@ int main() wasmer_module_t *module_one = NULL; unsigned long long gas_limit = 100; - wasmer_result_t compile_result = wasmer_compile_with_gas_metering(&module_one, bytes, len, gas_limit); + wasmer_result_t compile_result = wasmer_compile_with_gas_metering(&module_one, bytes, len); printf("Compile result: %d\n", compile_result); assert(compile_result == WASMER_OK); diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 8b6fd5ce2f8b..54d60b33f761 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -431,8 +431,7 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, */ wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, uint8_t *wasm_bytes, - uint32_t wasm_bytes_len, - uint64_t gas_limit); + uint32_t wasm_bytes_len); #if defined(WASMER_EMSCRIPTEN_ENABLED) /** diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 4c7a53241730..1f2a17ceb7a5 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -346,8 +346,7 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module, /// and `wasmer_last_error_message` to get an error message. wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, uint8_t *wasm_bytes, - uint32_t wasm_bytes_len, - uint64_t gas_limit); + uint32_t wasm_bytes_len); #if defined(WASMER_EMSCRIPTEN_ENABLED) /// Convenience function for setting up arguments and calling the Emscripten From f82834a5abc59dc6f235400998bba54a9e90f69d Mon Sep 17 00:00:00 2001 From: Robert Sasu Date: Fri, 30 Oct 2020 13:20:52 +0200 Subject: [PATCH 076/129] some impro --- Cargo.lock | 6 ++--- lib/runtime-c-api/src/instance_cache.rs | 29 +++++++++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0db7432398d8..3195ad13d986 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2142,13 +2142,13 @@ checksum = "c702914acda5feeeffbc29e4d953e5b9ce79d8b98da4dbf18a77086e116c5470" [[package]] name = "wasmparser" version = "0.51.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" +source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" [[package]] name = "wasmparser" version = "0.51.4" -source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" [[package]] name = "wast" diff --git a/lib/runtime-c-api/src/instance_cache.rs b/lib/runtime-c-api/src/instance_cache.rs index 485c1b0586b3..91d67a8976cd 100644 --- a/lib/runtime-c-api/src/instance_cache.rs +++ b/lib/runtime-c-api/src/instance_cache.rs @@ -3,10 +3,7 @@ use crate::{ instance::wasmer_instance_t, wasmer_result_t, }; -// use wasmer_runtime::{ -// Instance, Module -// }; -// use wasmer_runtime_core::cache::{Artifact, Error as CacheError}; +use wasmer_runtime_core::cache::{Artifact, Error as CacheError}; #[allow(clippy::cast_ptr_alignment)] @@ -70,8 +67,32 @@ pub unsafe extern "C" fn wasmer_instance_from_cache( } let bytes: &[u8] = slice::from_raw_parts_mut(cache_bytes, cache_len as usize); + let serialized_cache = Artifact::deserialize(bytes); + unsafe { + wasmer_runtime_core::load_cache_with(serialized_cache, &default_compiler()) + } + match serialized_cache { + Ok(artifact) => match load_cache_with(artifact, &default_compiler()) { + Ok(deserialized_module) => { + *module = Box::into_raw(Box::new(deserialized_module)) as _; + wasmer_result_t::WASMER_OK + } + Err(_) => { + update_last_error(CApiError { + msg: "Failed to compile the serialized module".to_string(), + }); + wasmer_result_t::WASMER_ERROR + } + }, + Err(_) => { + update_last_error(CApiError { + msg: "Failed to deserialize the module".to_string(), + }); + wasmer_result_t::WASMER_ERROR + } + } let new_module = match result_compilation { Ok(module) => module, From 26d7f3110529ac8f78b32a75afa7bebc0cfab514 Mon Sep 17 00:00:00 2001 From: andrei-marinica Date: Fri, 30 Oct 2020 13:29:45 +0200 Subject: [PATCH 077/129] instance cache error handling --- lib/runtime-c-api/src/instance_cache.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/runtime-c-api/src/instance_cache.rs b/lib/runtime-c-api/src/instance_cache.rs index 91d67a8976cd..22b6a2fe71c2 100644 --- a/lib/runtime-c-api/src/instance_cache.rs +++ b/lib/runtime-c-api/src/instance_cache.rs @@ -67,30 +67,24 @@ pub unsafe extern "C" fn wasmer_instance_from_cache( } let bytes: &[u8] = slice::from_raw_parts_mut(cache_bytes, cache_len as usize); - let serialized_cache = Artifact::deserialize(bytes); - unsafe { - wasmer_runtime_core::load_cache_with(serialized_cache, &default_compiler()) - } - - match serialized_cache { - Ok(artifact) => match load_cache_with(artifact, &default_compiler()) { + let module = match Artifact::deserialize(bytes) { + Ok(serialized_cache) => match wasmer_runtime_core::load_cache_with(serialized_cache, &default_compiler()) { Ok(deserialized_module) => { - *module = Box::into_raw(Box::new(deserialized_module)) as _; - wasmer_result_t::WASMER_OK + Box::into_raw(Box::new(deserialized_module)) as _; } Err(_) => { update_last_error(CApiError { msg: "Failed to compile the serialized module".to_string(), }); - wasmer_result_t::WASMER_ERROR + return wasmer_result_t::WASMER_ERROR; } }, Err(_) => { update_last_error(CApiError { msg: "Failed to deserialize the module".to_string(), }); - wasmer_result_t::WASMER_ERROR + return wasmer_result_t::WASMER_ERROR; } } From 239e90d6020a19a90f45b3888b6c43252267e0c2 Mon Sep 17 00:00:00 2001 From: Robert Sasu Date: Fri, 30 Oct 2020 13:55:24 +0200 Subject: [PATCH 078/129] finished cache implementation --- lib/runtime-c-api/src/instance_cache.rs | 23 ++++++++--------------- lib/runtime-c-api/wasmer.h | 3 ++- lib/runtime-c-api/wasmer.hh | 3 ++- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/runtime-c-api/src/instance_cache.rs b/lib/runtime-c-api/src/instance_cache.rs index 22b6a2fe71c2..0b7165443c91 100644 --- a/lib/runtime-c-api/src/instance_cache.rs +++ b/lib/runtime-c-api/src/instance_cache.rs @@ -3,8 +3,7 @@ use crate::{ instance::wasmer_instance_t, wasmer_result_t, }; -use wasmer_runtime_core::cache::{Artifact, Error as CacheError}; - +use wasmer_runtime_core::{cache::Artifact, load_cache_with}; #[allow(clippy::cast_ptr_alignment)] #[no_mangle] @@ -57,7 +56,7 @@ pub unsafe extern "C" fn wasmer_instance_from_cache( instance: *mut *mut wasmer_instance_t, cache_bytes: *mut u8, cache_len: u32, - gas_limit: u64, + options: *const wasmer_compilation_options_t, ) -> wasmer_result_t { if cache_bytes.is_null() { update_last_error(CApiError { @@ -67,9 +66,11 @@ pub unsafe extern "C" fn wasmer_instance_from_cache( } let bytes: &[u8] = slice::from_raw_parts_mut(cache_bytes, cache_len as usize); - - let module = match Artifact::deserialize(bytes) { - Ok(serialized_cache) => match wasmer_runtime_core::load_cache_with(serialized_cache, &default_compiler()) { + let options: &CompilationOptions = &*(options as *const CompilationOptions); + let compiler_chain_generator = prepare_middleware_chain_generator(&options); + let compiler = get_compiler(compiler_chain_generator); + let new_module = match Artifact::deserialize(bytes) { + Ok(serialized_cache) => match wasmer_runtime_core::load_cache_with(serialized_cache, compiler) { Ok(deserialized_module) => { Box::into_raw(Box::new(deserialized_module)) as _; } @@ -88,14 +89,6 @@ pub unsafe extern "C" fn wasmer_instance_from_cache( } } - let new_module = match result_compilation { - Ok(module) => module, - Err(_) => { - update_last_error(CApiError { msg: "compile error".to_string() }); - return wasmer_result_t::WASMER_ERROR; - } - }; - let import_object: &mut ImportObject = &mut *(GLOBAL_IMPORT_OBJECT as *mut ImportObject); let result_instantiation = new_module.instantiate(&import_object); let mut new_instance = match result_instantiation { @@ -105,7 +98,7 @@ pub unsafe extern "C" fn wasmer_instance_from_cache( return wasmer_result_t::WASMER_ERROR; } }; - metering::set_points_limit(&mut new_instance, gas_limit); + metering::set_points_limit(&mut new_instance, options.gas_limit); *instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t; wasmer_result_t::WASMER_OK } diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 54d60b33f761..973dc5a9bbfd 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -1072,7 +1072,8 @@ void wasmer_instance_exports(wasmer_instance_t *instance, wasmer_exports_t **exp wasmer_result_t wasmer_instance_from_cache(wasmer_instance_t **_instance, uint8_t *_cache_bytes, - uint32_t _cache_len); + uint32_t _cache_len, + const wasmer_compilation_options_t *options); uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 1f2a17ceb7a5..a96c9fb1254f 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -873,7 +873,8 @@ void wasmer_instance_exports(wasmer_instance_t *instance, wasmer_exports_t **exp wasmer_result_t wasmer_instance_from_cache(wasmer_instance_t **_instance, uint8_t *_cache_bytes, - uint32_t _cache_len); + uint32_t _cache_len, + const wasmer_compilation_options_t *options); uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); From 5b565a4527491cd323d7b70b4fb0684a979be575 Mon Sep 17 00:00:00 2001 From: Robert Sasu Date: Sat, 31 Oct 2020 16:14:14 +0200 Subject: [PATCH 079/129] finished implementation of aot --- lib/runtime-c-api/src/instance.rs | 4 +-- lib/runtime-c-api/src/instance_cache.rs | 33 +++++++++++++++---------- lib/runtime-c-api/wasmer.h | 10 +++++--- lib/runtime-c-api/wasmer.hh | 10 +++++--- lib/runtime-core/src/cache.rs | 25 ++++++++++--------- 5 files changed, 50 insertions(+), 32 deletions(-) diff --git a/lib/runtime-c-api/src/instance.rs b/lib/runtime-c-api/src/instance.rs index c4e8ac586eb4..202a737f2293 100644 --- a/lib/runtime-c-api/src/instance.rs +++ b/lib/runtime-c-api/src/instance.rs @@ -248,7 +248,7 @@ pub unsafe extern "C" fn wasmer_instantiate_with_options( wasmer_result_t::WASMER_OK } -unsafe fn prepare_middleware_chain_generator( +pub unsafe fn prepare_middleware_chain_generator( options: &CompilationOptions ) -> impl Fn() -> MiddlewareChain + '_ { let options = options.clone(); @@ -278,7 +278,7 @@ unsafe fn prepare_middleware_chain_generator( chain_generator } -unsafe fn get_compiler(chain_generator: impl Fn() -> MiddlewareChain) -> impl Compiler { +pub unsafe fn get_compiler(chain_generator: impl Fn() -> MiddlewareChain) -> impl Compiler { #[cfg(feature = "llvm-backend")] use wasmer_llvm_backend::ModuleCodeGenerator as MeteredMCG; diff --git a/lib/runtime-c-api/src/instance_cache.rs b/lib/runtime-c-api/src/instance_cache.rs index 0b7165443c91..18952fc18174 100644 --- a/lib/runtime-c-api/src/instance_cache.rs +++ b/lib/runtime-c-api/src/instance_cache.rs @@ -1,9 +1,14 @@ use crate::{ error::{update_last_error, CApiError}, - instance::wasmer_instance_t, + instance::{wasmer_instance_t, wasmer_compilation_options_t, CompilationOptions, prepare_middleware_chain_generator, get_compiler}, wasmer_result_t, }; -use wasmer_runtime_core::{cache::Artifact, load_cache_with}; +use wasmer_runtime_core::{cache::Artifact, import::ImportObject}; +use std::slice; +use crate::import::GLOBAL_IMPORT_OBJECT; + +#[cfg(not(feature = "cranelift-backend"))] +use wasmer_middleware_common::metering; #[allow(clippy::cast_ptr_alignment)] #[no_mangle] @@ -18,10 +23,10 @@ pub unsafe extern "C" fn wasmer_instance_cache( }); return wasmer_result_t::WASMER_ERROR; } + let instance = &mut *(instance as *mut wasmer_runtime::Instance); let module = instance.module(); - let cache_result = module.cache(); - match cache_result { + match module.cache() { Err(error) => { update_last_error(CApiError { msg: format!("{:?}", error), @@ -29,8 +34,7 @@ pub unsafe extern "C" fn wasmer_instance_cache( return wasmer_result_t::WASMER_ERROR; } Ok(artifact) => { - let serialize_result = artifact.serialize(); - match serialize_result { + match artifact.serialize() { Err(error) => { update_last_error(CApiError { msg: format!("{:?}", error), @@ -39,8 +43,10 @@ pub unsafe extern "C" fn wasmer_instance_cache( } Ok(bytes_vec) => { if !bytes_vec.is_empty() { - *cache_bytes = bytes_vec.as_ptr(); - *cache_len = bytes_vec.len() as u32; + let buf = bytes_vec.into_boxed_slice(); + *cache_bytes = buf.as_ptr(); + *cache_len = buf.len() as u32; + std::mem::forget(buf); } } } @@ -65,14 +71,14 @@ pub unsafe extern "C" fn wasmer_instance_from_cache( return wasmer_result_t::WASMER_ERROR; } - let bytes: &[u8] = slice::from_raw_parts_mut(cache_bytes, cache_len as usize); + let bytes: &[u8] = slice::from_raw_parts(cache_bytes, cache_len as usize); let options: &CompilationOptions = &*(options as *const CompilationOptions); let compiler_chain_generator = prepare_middleware_chain_generator(&options); let compiler = get_compiler(compiler_chain_generator); let new_module = match Artifact::deserialize(bytes) { - Ok(serialized_cache) => match wasmer_runtime_core::load_cache_with(serialized_cache, compiler) { + Ok(serialized_cache) => match wasmer_runtime_core::load_cache_with(serialized_cache, &compiler) { Ok(deserialized_module) => { - Box::into_raw(Box::new(deserialized_module)) as _; + deserialized_module } Err(_) => { update_last_error(CApiError { @@ -81,13 +87,14 @@ pub unsafe extern "C" fn wasmer_instance_from_cache( return wasmer_result_t::WASMER_ERROR; } }, - Err(_) => { + Err(err) => { + println!("{:?}", err); update_last_error(CApiError { msg: "Failed to deserialize the module".to_string(), }); return wasmer_result_t::WASMER_ERROR; } - } + }; let import_object: &mut ImportObject = &mut *(GLOBAL_IMPORT_OBJECT as *mut ImportObject); let result_instantiation = new_module.instantiate(&import_object); diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 973dc5a9bbfd..f1baffecb30c 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -433,6 +433,10 @@ wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, uint8_t *wasm_bytes, uint32_t wasm_bytes_len); +wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, + uint8_t *wasm_bytes, + uint32_t wasm_bytes_len); + #if defined(WASMER_EMSCRIPTEN_ENABLED) /** * Convenience function for setting up arguments and calling the Emscripten @@ -1070,9 +1074,9 @@ void wasmer_instance_destroy(wasmer_instance_t *instance); */ void wasmer_instance_exports(wasmer_instance_t *instance, wasmer_exports_t **exports); -wasmer_result_t wasmer_instance_from_cache(wasmer_instance_t **_instance, - uint8_t *_cache_bytes, - uint32_t _cache_len, +wasmer_result_t wasmer_instance_from_cache(wasmer_instance_t **instance, + uint8_t *cache_bytes, + uint32_t cache_len, const wasmer_compilation_options_t *options); uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index a96c9fb1254f..3563ecb7027b 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -348,6 +348,10 @@ wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, uint8_t *wasm_bytes, uint32_t wasm_bytes_len); +wasmer_result_t wasmer_compile_with_gas_metering(wasmer_module_t **module, + uint8_t *wasm_bytes, + uint32_t wasm_bytes_len); + #if defined(WASMER_EMSCRIPTEN_ENABLED) /// Convenience function for setting up arguments and calling the Emscripten /// main function. @@ -871,9 +875,9 @@ void wasmer_instance_destroy(wasmer_instance_t *instance); /// ``` void wasmer_instance_exports(wasmer_instance_t *instance, wasmer_exports_t **exports); -wasmer_result_t wasmer_instance_from_cache(wasmer_instance_t **_instance, - uint8_t *_cache_bytes, - uint32_t _cache_len, +wasmer_result_t wasmer_instance_from_cache(wasmer_instance_t **instance, + uint8_t *cache_bytes, + uint32_t cache_len, const wasmer_compilation_options_t *options); uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index 76a058f8bbbc..0e74ee4dc51d 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -112,12 +112,15 @@ impl ArtifactHeader { if header.version == CURRENT_CACHE_VERSION { Ok((header, body_slice)) } else { + println!("invalidated cache"); Err(Error::InvalidatedCache) } } else { + println!("invalid magic"); Err(Error::InvalidFile(InvalidFileType::InvalidMagic)) } } else { + println!("invalid size"); Err(Error::InvalidFile(InvalidFileType::InvalidSize)) } } @@ -148,6 +151,7 @@ impl ArtifactHeader { } } + #[derive(Serialize, Deserialize)] struct ArtifactInner { info: Box, @@ -177,16 +181,6 @@ impl Artifact { } } - /// Deserializes an `Artifact` from the given byte slice. - pub fn deserialize(bytes: &[u8]) -> Result { - let (_, body_slice) = ArtifactHeader::read_from_slice(bytes)?; - - let inner = serde_bench::deserialize(body_slice) - .map_err(|e| Error::DeserializeError(format!("{:#?}", e)))?; - - Ok(Artifact { inner }) - } - /// A reference to the `Artifact`'s stored `ModuleInfo` pub fn info(&self) -> &ModuleInfo { &self.inner.info @@ -201,6 +195,16 @@ impl Artifact { ) } + /// Deserializes an `Artifact` from the given byte slice. + pub fn deserialize(bytes: &[u8]) -> Result { + let (_, body_slice) = ArtifactHeader::read_from_slice(bytes)?; + + let inner = serde_bench::deserialize(body_slice) + .map_err(|e| Error::DeserializeError(format!("{:#?}", e)))?; + + Ok(Artifact { inner }) + } + /// Serializes the `Artifact` into a vector of bytes pub fn serialize(&self) -> Result, Error> { let cache_header = ArtifactHeader { @@ -215,7 +219,6 @@ impl Artifact { .map_err(|e| Error::SerializeError(e.to_string()))?; let data_len = (buffer.len() - mem::size_of::()) as u64; - let (header, _) = ArtifactHeader::read_from_slice_mut(&mut buffer)?; header.data_len = data_len; From f1e13277ae6a876831c20ec4f33f87338db2d384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Mon, 8 Feb 2021 18:01:36 +0200 Subject: [PATCH 080/129] Implement wasmer_instance_is_function_imported() for the C API --- Cargo.lock | 6 +++--- lib/runtime-c-api/src/instance.rs | 27 +++++++++++++++++++++++++++ lib/runtime-c-api/wasmer.h | 5 +++++ lib/runtime-c-api/wasmer.hh | 3 +++ lib/singlepass-backend/src/lib.rs | 1 - 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3195ad13d986..0db7432398d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2142,13 +2142,13 @@ checksum = "c702914acda5feeeffbc29e4d953e5b9ce79d8b98da4dbf18a77086e116c5470" [[package]] name = "wasmparser" version = "0.51.4" -source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" [[package]] name = "wasmparser" version = "0.51.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" +source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" [[package]] name = "wast" diff --git a/lib/runtime-c-api/src/instance.rs b/lib/runtime-c-api/src/instance.rs index 202a737f2293..31c2527daa57 100644 --- a/lib/runtime-c-api/src/instance.rs +++ b/lib/runtime-c-api/src/instance.rs @@ -322,6 +322,33 @@ pub extern "C" fn wasmer_instance_context_get( context as *const wasmer_instance_context_t } +/// Verifies whether the specified function name is imported by the given instance. +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_instance_is_function_imported( + instance: *mut wasmer_instance_t, + name: *const c_char, +) -> bool { + if instance.is_null() { + return false; + } + + if name.is_null() { + return false; + } + + let instance = &*(instance as *const Instance); + + let func_name_c = CStr::from_ptr(name); + let func_name_r = func_name_c.to_str().unwrap(); + + let module = instance.module(); + + let functions = module.info().name_table.to_vec(); + + functions.contains(&func_name_r) +} + /// Calls an exported function of a WebAssembly instance by `name` /// with the provided parameters. The exported function results are /// stored on the provided `results` pointer. diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index f1baffecb30c..455dbaaa58aa 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -1083,6 +1083,11 @@ uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); uint64_t wasmer_instance_get_runtime_breakpoint_value(wasmer_instance_t *instance); +/** + * Verifies whether the specified function name is imported by the given instance. + */ +bool wasmer_instance_is_function_imported(wasmer_instance_t *instance, const char *name); + void wasmer_instance_set_points_limit(wasmer_instance_t *instance, uint64_t limit); void wasmer_instance_set_points_used(wasmer_instance_t *instance, uint64_t new_gas); diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 3563ecb7027b..888cb07b3a25 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -884,6 +884,9 @@ uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); uint64_t wasmer_instance_get_runtime_breakpoint_value(wasmer_instance_t *instance); +/// Verifies whether the specified function name is imported by the given instance. +bool wasmer_instance_is_function_imported(wasmer_instance_t *instance, const char *name); + void wasmer_instance_set_points_limit(wasmer_instance_t *instance, uint64_t limit); void wasmer_instance_set_points_used(wasmer_instance_t *instance, uint64_t new_gas); diff --git a/lib/singlepass-backend/src/lib.rs b/lib/singlepass-backend/src/lib.rs index 98339cca304a..200181564a55 100644 --- a/lib/singlepass-backend/src/lib.rs +++ b/lib/singlepass-backend/src/lib.rs @@ -1,5 +1,4 @@ #![deny( - dead_code, nonstandard_style, unused_imports, unused_mut, From 48a61ed7f7946768b80cb1619122486b04f13c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 9 Feb 2021 11:31:03 +0200 Subject: [PATCH 081/129] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c5ff08d649d7..60c406ce151d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ before_install: - if [[ $TRAVIS_OS_NAME == linux ]]; then sudo apt-get install -y patchelf; fi install: travis_retry rust: - - nightly-2019-12-19 + - nightly-2021-01-25 cache: directories: From c71832e2fc3ff446e066bdf6bd8f29caa9d4387e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 4 Jun 2021 13:38:10 +0300 Subject: [PATCH 082/129] Add reset API function for the global import object cache --- Cargo.lock | 2 ++ lib/runtime-c-api/src/import/mod.rs | 7 +++++++ lib/runtime-c-api/wasmer.h | 2 ++ lib/runtime-c-api/wasmer.hh | 2 ++ 4 files changed, 13 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 0db7432398d8..cdbd151debf9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "aho-corasick" version = "0.7.13" diff --git a/lib/runtime-c-api/src/import/mod.rs b/lib/runtime-c-api/src/import/mod.rs index 2641b7d3edc8..7e4ae246f3a4 100644 --- a/lib/runtime-c-api/src/import/mod.rs +++ b/lib/runtime-c-api/src/import/mod.rs @@ -72,6 +72,13 @@ pub unsafe extern "C" fn wasmer_import_object_new() -> *mut wasmer_import_object Box::into_raw(import_object) as *mut wasmer_import_object_t } +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_import_object_cache_reset() { + GLOBAL_IMPORT_OBJECT = 0 as *mut ImportObject; + GLOBAL_IMPORT_OBJECT_INITIALIZED = false; +} + #[allow(clippy::cast_ptr_alignment)] #[no_mangle] pub unsafe extern "C" fn wasmer_import_object_cache_from_imports( diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 455dbaaa58aa..baa739dc194f 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -788,6 +788,8 @@ wasmer_result_t wasmer_import_func_returns_arity(const wasmer_import_func_t *fun wasmer_result_t wasmer_import_object_cache_from_imports(wasmer_import_t *imports, unsigned int imports_len); +void wasmer_import_object_cache_reset(void); + /** * Frees memory of the given ImportObject */ diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 888cb07b3a25..258a63d3641a 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -621,6 +621,8 @@ wasmer_result_t wasmer_import_func_returns_arity(const wasmer_import_func_t *fun wasmer_result_t wasmer_import_object_cache_from_imports(wasmer_import_t *imports, unsigned int imports_len); +void wasmer_import_object_cache_reset(); + /// Frees memory of the given ImportObject void wasmer_import_object_destroy(wasmer_import_object_t *import_object); From d1af7bc631df1d2b795604d240027666ff90c146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 4 Jun 2021 13:55:10 +0300 Subject: [PATCH 083/129] Remove global booleans that prevent setting opcode costs and import object --- lib/runtime-c-api/src/import/mod.rs | 15 ++------------- lib/runtime-c-api/src/metering.rs | 7 ++----- lib/runtime-c-api/wasmer.h | 2 -- lib/runtime-c-api/wasmer.hh | 2 -- 4 files changed, 4 insertions(+), 22 deletions(-) diff --git a/lib/runtime-c-api/src/import/mod.rs b/lib/runtime-c-api/src/import/mod.rs index 7e4ae246f3a4..6523409e8bfa 100644 --- a/lib/runtime-c-api/src/import/mod.rs +++ b/lib/runtime-c-api/src/import/mod.rs @@ -33,7 +33,6 @@ pub enum ImportError { } pub static mut GLOBAL_IMPORT_OBJECT: *mut ImportObject = 0 as *mut ImportObject; -pub static mut GLOBAL_IMPORT_OBJECT_INITIALIZED: bool = false; #[repr(C)] pub struct wasmer_import_t { @@ -72,23 +71,12 @@ pub unsafe extern "C" fn wasmer_import_object_new() -> *mut wasmer_import_object Box::into_raw(import_object) as *mut wasmer_import_object_t } -#[allow(clippy::cast_ptr_alignment)] -#[no_mangle] -pub unsafe extern "C" fn wasmer_import_object_cache_reset() { - GLOBAL_IMPORT_OBJECT = 0 as *mut ImportObject; - GLOBAL_IMPORT_OBJECT_INITIALIZED = false; -} - #[allow(clippy::cast_ptr_alignment)] #[no_mangle] pub unsafe extern "C" fn wasmer_import_object_cache_from_imports( imports: *mut wasmer_import_t, imports_len: c_uint, ) -> wasmer_result_t { - if GLOBAL_IMPORT_OBJECT_INITIALIZED { - return wasmer_result_t::WASMER_OK; - } - let imports_result = wasmer_create_import_object_from_imports(imports, imports_len); let import_object = match imports_result { Err(ImportError::ModuleNameError) => { @@ -101,8 +89,9 @@ pub unsafe extern "C" fn wasmer_import_object_cache_from_imports( } Ok(created_imports_object) => created_imports_object }; + + // TODO deallocate previous GLOBAL_IMPORT_OBJECT GLOBAL_IMPORT_OBJECT = Box::into_raw(Box::new(import_object)); - GLOBAL_IMPORT_OBJECT_INITIALIZED = true; return wasmer_result_t::WASMER_OK } diff --git a/lib/runtime-c-api/src/metering.rs b/lib/runtime-c-api/src/metering.rs index 72c4e6a12ab2..8feb1eb05a2e 100644 --- a/lib/runtime-c-api/src/metering.rs +++ b/lib/runtime-c-api/src/metering.rs @@ -14,7 +14,6 @@ use wasmer_middleware_common::metering; pub const OPCODE_COUNT: usize = 448; pub static mut OPCODE_COSTS: [u32; OPCODE_COUNT] = [0; OPCODE_COUNT]; -static mut OPCODE_COSTS_INITIALIZED: bool = false; #[allow(clippy::cast_ptr_alignment)] #[cfg(feature = "metering")] @@ -22,12 +21,10 @@ static mut OPCODE_COSTS_INITIALIZED: bool = false; pub unsafe extern "C" fn wasmer_set_opcode_costs( opcode_costs_pointer: *const u32, ) { - if !OPCODE_COSTS_INITIALIZED { - OPCODE_COSTS.copy_from_slice(slice::from_raw_parts(opcode_costs_pointer, OPCODE_COUNT)); - OPCODE_COSTS_INITIALIZED = true; - } + OPCODE_COSTS.copy_from_slice(slice::from_raw_parts(opcode_costs_pointer, OPCODE_COUNT)); } + // returns gas used #[allow(clippy::cast_ptr_alignment)] #[no_mangle] diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index baa739dc194f..455dbaaa58aa 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -788,8 +788,6 @@ wasmer_result_t wasmer_import_func_returns_arity(const wasmer_import_func_t *fun wasmer_result_t wasmer_import_object_cache_from_imports(wasmer_import_t *imports, unsigned int imports_len); -void wasmer_import_object_cache_reset(void); - /** * Frees memory of the given ImportObject */ diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 258a63d3641a..888cb07b3a25 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -621,8 +621,6 @@ wasmer_result_t wasmer_import_func_returns_arity(const wasmer_import_func_t *fun wasmer_result_t wasmer_import_object_cache_from_imports(wasmer_import_t *imports, unsigned int imports_len); -void wasmer_import_object_cache_reset(); - /// Frees memory of the given ImportObject void wasmer_import_object_destroy(wasmer_import_object_t *import_object); From 896905ee7cf2091b01b88475a352924bf4e621f3 Mon Sep 17 00:00:00 2001 From: andrei-marinica Date: Fri, 4 Jun 2021 16:48:16 +0300 Subject: [PATCH 084/129] deallocate previous GLOBAL_IMPORT_OBJECT --- lib/runtime-c-api/src/import/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime-c-api/src/import/mod.rs b/lib/runtime-c-api/src/import/mod.rs index 6523409e8bfa..17b6deb752f9 100644 --- a/lib/runtime-c-api/src/import/mod.rs +++ b/lib/runtime-c-api/src/import/mod.rs @@ -90,7 +90,7 @@ pub unsafe extern "C" fn wasmer_import_object_cache_from_imports( Ok(created_imports_object) => created_imports_object }; - // TODO deallocate previous GLOBAL_IMPORT_OBJECT + let _ = Box::from_raw(GLOBAL_IMPORT_OBJECT); // deallocate previous GLOBAL_IMPORT_OBJECT GLOBAL_IMPORT_OBJECT = Box::into_raw(Box::new(import_object)); return wasmer_result_t::WASMER_OK } From 5a490788a0d2899750330d1fde6b67d6cfbdc6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 4 Jun 2021 19:11:56 +0300 Subject: [PATCH 085/129] Guard against deallocating a null pointer --- lib/runtime-c-api/src/import/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/runtime-c-api/src/import/mod.rs b/lib/runtime-c-api/src/import/mod.rs index 17b6deb752f9..ad535680dc00 100644 --- a/lib/runtime-c-api/src/import/mod.rs +++ b/lib/runtime-c-api/src/import/mod.rs @@ -90,7 +90,10 @@ pub unsafe extern "C" fn wasmer_import_object_cache_from_imports( Ok(created_imports_object) => created_imports_object }; - let _ = Box::from_raw(GLOBAL_IMPORT_OBJECT); // deallocate previous GLOBAL_IMPORT_OBJECT + if GLOBAL_IMPORT_OBJECT != (0 as *mut ImportObject) { + let _ = Box::from_raw(GLOBAL_IMPORT_OBJECT); // deallocate previous GLOBAL_IMPORT_OBJECT + } + GLOBAL_IMPORT_OBJECT = Box::into_raw(Box::new(import_object)); return wasmer_result_t::WASMER_OK } From f891488ebb2f5b9920b4951f883d77529f6e8f3a Mon Sep 17 00:00:00 2001 From: Catalin Neagu Date: Thu, 7 Oct 2021 13:30:36 +0300 Subject: [PATCH 086/129] fix build --- Cargo.lock | 20 ++++++-------------- lib/singlepass-backend/Cargo.toml | 4 ++-- lib/singlepass-backend/src/lib.rs | 1 - 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cdbd151debf9..53c71099863a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -413,14 +413,14 @@ dependencies = [ [[package]] name = "dynasm" -version = "0.5.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42a814e1edeb85dd2a3c6fc0d6bf76d02ca5695d438c70ecee3d90774f3259c5" +checksum = "6a93688d3993e998336f7e31d1272bafc078f7665c8b883bd08f140e73d2e9cd" dependencies = [ "bitflags", "byteorder", "lazy_static", - "owning_ref", + "proc-macro-error", "proc-macro2 1.0.20", "quote 1.0.7", "syn 1.0.40", @@ -428,11 +428,12 @@ dependencies = [ [[package]] name = "dynasmrt" -version = "0.5.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a393aaeb4441a48bcf47b5b6155971f82cc1eb77e22855403ccc0415ac8328d" +checksum = "acae550ea0de09db4dcb18d4cd49f9f7963edd34783a4571429ba2c4e13e1e09" dependencies = [ "byteorder", + "dynasm", "memmap", ] @@ -922,15 +923,6 @@ dependencies = [ "sdl2", ] -[[package]] -name = "owning_ref" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff55baddef9e4ad00f88b6c743a2a8062d4c6ade126c2a528644b8e444d52ce" -dependencies = [ - "stable_deref_trait", -] - [[package]] name = "page_size" version = "0.4.2" diff --git a/lib/singlepass-backend/Cargo.toml b/lib/singlepass-backend/Cargo.toml index 15aacb848cff..0478b5ba7e53 100644 --- a/lib/singlepass-backend/Cargo.toml +++ b/lib/singlepass-backend/Cargo.toml @@ -12,8 +12,8 @@ readme = "README.md" [dependencies] wasmer-runtime-core = { path = "../runtime-core", version = "0.15.0" } -dynasm = "0.5" -dynasmrt = "0.5" +dynasm = "0.7" +dynasmrt = "0.7" lazy_static = "1.4" byteorder = "1.3" nix = "0.15" diff --git a/lib/singlepass-backend/src/lib.rs b/lib/singlepass-backend/src/lib.rs index 200181564a55..0704cd8eba60 100644 --- a/lib/singlepass-backend/src/lib.rs +++ b/lib/singlepass-backend/src/lib.rs @@ -6,7 +6,6 @@ unused_unsafe, unreachable_patterns )] -#![feature(proc_macro_hygiene)] #![doc(html_favicon_url = "https://wasmer.io/static/icons/favicon.ico")] #![doc(html_logo_url = "https://avatars3.githubusercontent.com/u/44205449?s=200&v=4")] From fe45b85b73079878e15ae2096fe5bd22966a46f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 2 Nov 2021 17:45:17 +0200 Subject: [PATCH 087/129] Add tentative workflow for linux-amd64 --- .github/workflows/build-linux-amd64.yml | 26 +++++++++++++++++++++++++ Cargo.lock | 6 +++--- Makefile | 12 ++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/build-linux-amd64.yml diff --git a/.github/workflows/build-linux-amd64.yml b/.github/workflows/build-linux-amd64.yml new file mode 100644 index 000000000000..86f5dbf54611 --- /dev/null +++ b/.github/workflows/build-linux-amd64.yml @@ -0,0 +1,26 @@ +name: build-linux-amd64-so + +on: + push: + tags: + - "v*.*.*" + +env: + CARGO_TERM_COLOR: always + +jobs: + build-so: + runs-on: ubuntu-18.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Make + run: make capi-linux-amd64 + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + prerelease: true + name: ${{ tag_name }}-linux-amd64 + files: | + target/release/libwasmer_linux_amd64.so diff --git a/Cargo.lock b/Cargo.lock index 53c71099863a..f6c7da54dc62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2136,13 +2136,13 @@ checksum = "c702914acda5feeeffbc29e4d953e5b9ce79d8b98da4dbf18a77086e116c5470" [[package]] name = "wasmparser" version = "0.51.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" +source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" [[package]] name = "wasmparser" version = "0.51.4" -source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" [[package]] name = "wast" diff --git a/Makefile b/Makefile index e17d3ab418ea..15c49c2a5c37 100644 --- a/Makefile +++ b/Makefile @@ -105,6 +105,18 @@ llvm: spectests-llvm emtests-llvm wasitests-llvm capi: cargo build -p wasmer-runtime-c-api --release +capi-linux-amd64: capi + mv target/release/libwasmer_runtime_c_api.so target/release/libwasmer_linux_amd64.so + patchelf --set-soname libwasmer_linux_amd64.so target/release/libwasmer_linux_amd64.so + +capi-linux-arm64: capi + mv target/release/libwasmer_runtime_c_api.so target/release/libwasmer_linux_arm64.so + patchelf --set-soname libwasmer_linux_arm64.so target/release/libwasmer_linux_arm64.so + +capi-osx-arm64: capi + mv target/release/libwasmer_runtime_c_api.dylib target/release/libwasmer_darwin_amd64.dylib + install_name_tool -id @executable_path/libwasmer_darwin_amd64.dylib target/release/libwasmer_darwin_amd64.dylib; + capi-singlepass: cargo build --manifest-path lib/runtime-c-api/Cargo.toml --release \ --no-default-features --features singlepass-backend,wasi From 06d3441c7688ed35ff51608d090a0d3af44439cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 2 Nov 2021 17:49:58 +0200 Subject: [PATCH 088/129] Trigger workflow on pull-requests to master --- .github/workflows/build-linux-amd64.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-linux-amd64.yml b/.github/workflows/build-linux-amd64.yml index 86f5dbf54611..bcf70dc75d93 100644 --- a/.github/workflows/build-linux-amd64.yml +++ b/.github/workflows/build-linux-amd64.yml @@ -4,6 +4,8 @@ on: push: tags: - "v*.*.*" + pull-requests: + branch: [ master ] env: CARGO_TERM_COLOR: always From 9bc983482408369566e7ffec32976014f263837a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 2 Nov 2021 17:55:43 +0200 Subject: [PATCH 089/129] Minor fix --- .github/workflows/build-linux-amd64.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-linux-amd64.yml b/.github/workflows/build-linux-amd64.yml index bcf70dc75d93..51680bf6dd93 100644 --- a/.github/workflows/build-linux-amd64.yml +++ b/.github/workflows/build-linux-amd64.yml @@ -4,8 +4,10 @@ on: push: tags: - "v*.*.*" - pull-requests: + pull_requests: branch: [ master ] + types: [opened, ready_for_review] + env: CARGO_TERM_COLOR: always From 471f8af6e71d7e9e854528d6909d352e0d9585ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 2 Nov 2021 18:01:25 +0200 Subject: [PATCH 090/129] Fix trigger name --- .github/workflows/build-linux-amd64.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-linux-amd64.yml b/.github/workflows/build-linux-amd64.yml index 51680bf6dd93..f6034161604a 100644 --- a/.github/workflows/build-linux-amd64.yml +++ b/.github/workflows/build-linux-amd64.yml @@ -4,7 +4,7 @@ on: push: tags: - "v*.*.*" - pull_requests: + pull_request: branch: [ master ] types: [opened, ready_for_review] From 044830ed1cb94d601c55d1cbc310066f636e8a34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 2 Nov 2021 18:03:11 +0200 Subject: [PATCH 091/129] Fix workflow --- .github/workflows/build-linux-amd64.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-linux-amd64.yml b/.github/workflows/build-linux-amd64.yml index f6034161604a..4d15c35db321 100644 --- a/.github/workflows/build-linux-amd64.yml +++ b/.github/workflows/build-linux-amd64.yml @@ -6,7 +6,7 @@ on: - "v*.*.*" pull_request: branch: [ master ] - types: [opened, ready_for_review] + types: env: From d8322f315a94ac06767e23baa80bbf933c3923c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 2 Nov 2021 18:05:11 +0200 Subject: [PATCH 092/129] Fix --- .github/workflows/build-linux-amd64.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/build-linux-amd64.yml b/.github/workflows/build-linux-amd64.yml index 4d15c35db321..2ecc079193b5 100644 --- a/.github/workflows/build-linux-amd64.yml +++ b/.github/workflows/build-linux-amd64.yml @@ -5,8 +5,6 @@ on: tags: - "v*.*.*" pull_request: - branch: [ master ] - types: env: @@ -25,6 +23,6 @@ jobs: if: startsWith(github.ref, 'refs/tags/') with: prerelease: true - name: ${{ tag_name }}-linux-amd64 + name: ${{ github.ref }}-linux-amd64 files: | target/release/libwasmer_linux_amd64.so From 48d9b6c28a1db396a3125adf42467d61e7d53ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 2 Nov 2021 18:13:35 +0200 Subject: [PATCH 093/129] Enable immediate releases (temporary) --- .github/workflows/build-linux-amd64.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build-linux-amd64.yml b/.github/workflows/build-linux-amd64.yml index 2ecc079193b5..6431ee262a6a 100644 --- a/.github/workflows/build-linux-amd64.yml +++ b/.github/workflows/build-linux-amd64.yml @@ -20,7 +20,6 @@ jobs: run: make capi-linux-amd64 - name: Release uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') with: prerelease: true name: ${{ github.ref }}-linux-amd64 From 76484773c8cc1db9ff3f7463db9c2b1f3358052a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 2 Nov 2021 18:18:57 +0200 Subject: [PATCH 094/129] Only enable releases with tags --- .github/workflows/build-linux-amd64.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-linux-amd64.yml b/.github/workflows/build-linux-amd64.yml index 6431ee262a6a..2ecc079193b5 100644 --- a/.github/workflows/build-linux-amd64.yml +++ b/.github/workflows/build-linux-amd64.yml @@ -20,6 +20,7 @@ jobs: run: make capi-linux-amd64 - name: Release uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') with: prerelease: true name: ${{ github.ref }}-linux-amd64 From 7b06231344075d785e7ba4c4388c44cb11eeddd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 2 Nov 2021 18:37:16 +0200 Subject: [PATCH 095/129] Add MacOS build --- .github/workflows/build-linux-amd64.yml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-linux-amd64.yml b/.github/workflows/build-linux-amd64.yml index 2ecc079193b5..9c4146a09571 100644 --- a/.github/workflows/build-linux-amd64.yml +++ b/.github/workflows/build-linux-amd64.yml @@ -11,18 +11,30 @@ env: CARGO_TERM_COLOR: always jobs: - build-so: - runs-on: ubuntu-18.04 + build: + name: Build dynamic library for ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: ubuntu-18.04 + artifact_name: libwasmer_linux_amd64.so + - os: macos-11 + artifact_name: libwasmer_darwin_amd64.dylib steps: - name: Checkout uses: actions/checkout@v2 - name: Make run: make capi-linux-amd64 + - name: Get the version + id: get_version + if: startsWith(github.ref, 'refs/tags/') + run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/} - name: Release uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/') with: prerelease: true - name: ${{ github.ref }}-linux-amd64 + name: ${{ steps.get_version.outputs.VERSION }}-linux-amd64 files: | - target/release/libwasmer_linux_amd64.so + target/release/${{ matrix.artifact_name }} From 2de2adf379b733e6a405e53df148bf9b4c3f4939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 2 Nov 2021 18:39:03 +0200 Subject: [PATCH 096/129] Enable building for all releases --- .github/workflows/build-linux-amd64.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build-linux-amd64.yml b/.github/workflows/build-linux-amd64.yml index 9c4146a09571..4189f8c8cfea 100644 --- a/.github/workflows/build-linux-amd64.yml +++ b/.github/workflows/build-linux-amd64.yml @@ -2,9 +2,8 @@ name: build-linux-amd64-so on: push: - tags: - - "v*.*.*" pull_request: + release: env: From df2946e76f351cc08bf1c1d4ff924ce2d65675b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 2 Nov 2021 18:43:02 +0200 Subject: [PATCH 097/129] Only build for releases (for now) --- .../{build-linux-amd64.yml => libwasmer-release.yml} | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) rename .github/workflows/{build-linux-amd64.yml => libwasmer-release.yml} (94%) diff --git a/.github/workflows/build-linux-amd64.yml b/.github/workflows/libwasmer-release.yml similarity index 94% rename from .github/workflows/build-linux-amd64.yml rename to .github/workflows/libwasmer-release.yml index 4189f8c8cfea..9cc43934395c 100644 --- a/.github/workflows/build-linux-amd64.yml +++ b/.github/workflows/libwasmer-release.yml @@ -1,8 +1,6 @@ -name: build-linux-amd64-so +name: libwasmer-release on: - push: - pull_request: release: From 878c48ff71678dc02b6b1f36df6e3687a2efb7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 2 Nov 2021 18:45:56 +0200 Subject: [PATCH 098/129] Isolate release types --- .github/workflows/libwasmer-release.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/libwasmer-release.yml b/.github/workflows/libwasmer-release.yml index 9cc43934395c..8771af2e2f33 100644 --- a/.github/workflows/libwasmer-release.yml +++ b/.github/workflows/libwasmer-release.yml @@ -2,6 +2,8 @@ name: libwasmer-release on: release: + types: + - created env: From 1f2cf0440f54c52ddc8843c683bd12982da7c0da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 2 Nov 2021 18:58:55 +0200 Subject: [PATCH 099/129] Fixes --- .github/workflows/libwasmer-release.yml | 3 ++- Makefile | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/libwasmer-release.yml b/.github/workflows/libwasmer-release.yml index 8771af2e2f33..ef0d8f71a1fb 100644 --- a/.github/workflows/libwasmer-release.yml +++ b/.github/workflows/libwasmer-release.yml @@ -18,8 +18,10 @@ jobs: include: - os: ubuntu-18.04 artifact_name: libwasmer_linux_amd64.so + make_target: capi-linux-amd64 - os: macos-11 artifact_name: libwasmer_darwin_amd64.dylib + make_target: capi-osx-amd64 steps: - name: Checkout uses: actions/checkout@v2 @@ -33,7 +35,6 @@ jobs: uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/') with: - prerelease: true name: ${{ steps.get_version.outputs.VERSION }}-linux-amd64 files: | target/release/${{ matrix.artifact_name }} diff --git a/Makefile b/Makefile index 15c49c2a5c37..bbf13bf5fac4 100644 --- a/Makefile +++ b/Makefile @@ -113,7 +113,7 @@ capi-linux-arm64: capi mv target/release/libwasmer_runtime_c_api.so target/release/libwasmer_linux_arm64.so patchelf --set-soname libwasmer_linux_arm64.so target/release/libwasmer_linux_arm64.so -capi-osx-arm64: capi +capi-osx-amd64: capi mv target/release/libwasmer_runtime_c_api.dylib target/release/libwasmer_darwin_amd64.dylib install_name_tool -id @executable_path/libwasmer_darwin_amd64.dylib target/release/libwasmer_darwin_amd64.dylib; From cddc73447833e6322269f7bf0209ec7e98c54ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 2 Nov 2021 19:08:40 +0200 Subject: [PATCH 100/129] Fix workflow again --- .github/workflows/libwasmer-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/libwasmer-release.yml b/.github/workflows/libwasmer-release.yml index ef0d8f71a1fb..ca42325504bf 100644 --- a/.github/workflows/libwasmer-release.yml +++ b/.github/workflows/libwasmer-release.yml @@ -26,7 +26,7 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Make - run: make capi-linux-amd64 + run: make ${{ matrix.make_target }} - name: Get the version id: get_version if: startsWith(github.ref, 'refs/tags/') From 3ec316a04d85e7685245094ef605f9a14b954700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 3 Nov 2021 11:13:56 +0200 Subject: [PATCH 101/129] Add libwasmer-build.yml --- .github/workflows/libwasmer-build.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/libwasmer-build.yml diff --git a/.github/workflows/libwasmer-build.yml b/.github/workflows/libwasmer-build.yml new file mode 100644 index 000000000000..4b7baa816caf --- /dev/null +++ b/.github/workflows/libwasmer-build.yml @@ -0,0 +1,26 @@ +name: libwasmer-build + +on: + push: + branches: + - master + pull_request: + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + name: Build dynamic library for ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: ubuntu-18.04 + artifact_name: libwasmer_linux_amd64.so + make_target: capi-linux-amd64 + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Make + run: make ${{ matrix.make_target }} From 26375c851eabd7c6da2cf0134c30d3b6feb873da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 3 Nov 2021 17:45:17 +0200 Subject: [PATCH 102/129] Implement the OpcodeControl middleware with memory.grow protection --- lib/middleware-common/src/lib.rs | 1 + lib/middleware-common/src/metering.rs | 5 +- lib/middleware-common/src/opcode_control.rs | 76 +++++++++++++++++++ lib/middleware-common/src/opcode_trace.rs | 4 +- .../src/runtime_breakpoints.rs | 10 ++- lib/runtime-c-api/src/instance.rs | 6 ++ lib/runtime-c-api/src/runtime_breakpoints.rs | 4 +- 7 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 lib/middleware-common/src/opcode_control.rs diff --git a/lib/middleware-common/src/lib.rs b/lib/middleware-common/src/lib.rs index 7eb19b48d545..e1be116f1554 100644 --- a/lib/middleware-common/src/lib.rs +++ b/lib/middleware-common/src/lib.rs @@ -19,3 +19,4 @@ pub mod metering_costs; pub mod runtime_breakpoints; pub mod opcode_trace; +pub mod opcode_control; diff --git a/lib/middleware-common/src/metering.rs b/lib/middleware-common/src/metering.rs index 0bcf94dc28a3..4678c7720e87 100644 --- a/lib/middleware-common/src/metering.rs +++ b/lib/middleware-common/src/metering.rs @@ -7,11 +7,10 @@ use wasmer_runtime_core::{ }; use crate::metering_costs::{get_opcode_index, get_local_allocate_cost_index}; -use crate::runtime_breakpoints::push_runtime_breakpoint; +use crate::runtime_breakpoints::{push_runtime_breakpoint, BREAKPOINT_VALUE_OUT_OF_GAS}; static FIELD_USED_POINTS: InternalField = InternalField::allocate(); static FIELD_POINTS_LIMIT: InternalField = InternalField::allocate(); -pub const BREAKPOINT_VALUE__OUT_OF_GAS: u64 = 4; /// Metering is a compiler middleware that calculates the cost of WebAssembly instructions at compile /// time and will count the cost of executed instructions at runtime. Within the Metering functionality, @@ -107,7 +106,7 @@ impl<'q> FunctionMiddleware for Metering<'q> { sink.push(Event::WasmOwned(Operator::If { ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), })); - push_runtime_breakpoint(sink, BREAKPOINT_VALUE__OUT_OF_GAS); + push_runtime_breakpoint(sink, BREAKPOINT_VALUE_OUT_OF_GAS); sink.push(Event::WasmOwned(Operator::End)); } _ => {} diff --git a/lib/middleware-common/src/opcode_control.rs b/lib/middleware-common/src/opcode_control.rs new file mode 100644 index 000000000000..f0e01d281914 --- /dev/null +++ b/lib/middleware-common/src/opcode_control.rs @@ -0,0 +1,76 @@ +use wasmer_runtime_core::{ + codegen::{Event, EventSink, FunctionMiddleware, InternalEvent}, + wasmparser::{Operator, Type as WpType, TypeOrFuncType as WpTypeOrFuncType}, + vm::InternalField, + module::ModuleInfo, +}; + +use crate::runtime_breakpoints::{push_runtime_breakpoint, BREAKPOINT_VALUE_EXECUTION_FAILED}; + +static FIELD_OPERAND_BACKUP: InternalField = InternalField::allocate(); + +pub struct OpcodeControl { + pub max_memory_grow_delta: usize, +} + +impl OpcodeControl { + pub fn new(max_memory_grow_delta: usize) -> OpcodeControl { + OpcodeControl { + max_memory_grow_delta, + } + } +} + +impl FunctionMiddleware for OpcodeControl { + type Error = String; + fn feed_event<'a, 'b: 'a>( + &mut self, + op: Event<'a, 'b>, + _: &ModuleInfo, + sink: &mut EventSink<'a, 'b>, + _: u32, + ) -> Result<(), Self::Error> { + match op { + Event::Wasm(&ref op) | Event::WasmOwned(ref op) => { + match *op { + Operator::MemoryGrow { reserved } => { + if reserved != 0 { + return Err("MemoryGrow must have memory index 0".to_string()); + } + + // Backup the top of the stack (the parameter for memory.grow) in order to + // duplicate it: once for the comparison against max_memory_grow_delta and + // again for memory.grow itself, assuming the comparison passes. + sink.push(Event::Internal(InternalEvent::SetInternal( + FIELD_OPERAND_BACKUP.index() as _, + ))); + + // Set up the comparison against max_memory_grow_delta. + sink.push(Event::Internal(InternalEvent::GetInternal( + FIELD_OPERAND_BACKUP.index() as _, + ))); + sink.push(Event::WasmOwned(Operator::I32Const { + value: self.max_memory_grow_delta as i32, + })); + sink.push(Event::WasmOwned(Operator::I64GtU)); + sink.push(Event::WasmOwned(Operator::If { + ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), + })); + push_runtime_breakpoint(sink, BREAKPOINT_VALUE_EXECUTION_FAILED); + sink.push(Event::WasmOwned(Operator::End)); + + // Bring back the backed-up operand for memory.grow. + sink.push(Event::Internal(InternalEvent::GetInternal( + FIELD_OPERAND_BACKUP.index() as _, + ))); + } + _ => {} + } + } + _ => {} + } + + sink.push(op); + Ok(()) + } +} diff --git a/lib/middleware-common/src/opcode_trace.rs b/lib/middleware-common/src/opcode_trace.rs index 13b8b3b2cd3b..57920e14b9c9 100644 --- a/lib/middleware-common/src/opcode_trace.rs +++ b/lib/middleware-common/src/opcode_trace.rs @@ -4,8 +4,8 @@ use std::io::Write; use wasmer_runtime_core::{ codegen::{Event, EventSink, FunctionMiddleware, InternalEvent}, - module::{ModuleInfo}, - vm::{InternalField}, + module::ModuleInfo, + vm::InternalField, wasmparser::Operator, Instance, }; diff --git a/lib/middleware-common/src/runtime_breakpoints.rs b/lib/middleware-common/src/runtime_breakpoints.rs index dd867b7c486f..6d0252b61efb 100644 --- a/lib/middleware-common/src/runtime_breakpoints.rs +++ b/lib/middleware-common/src/runtime_breakpoints.rs @@ -1,14 +1,16 @@ use wasmer_runtime_core::{ codegen::{Event, EventSink, FunctionMiddleware, InternalEvent}, module::ModuleInfo, - vm::{InternalField}, + vm::InternalField, wasmparser::{Operator, Type as WpType, TypeOrFuncType as WpTypeOrFuncType}, - error::{RuntimeError}, + error::RuntimeError, Instance, }; pub static FIELD_RUNTIME_BREAKPOINT_VALUE: InternalField = InternalField::allocate(); -pub const BREAKPOINT_VALUE__NO_BREAKPOINT: u64 = 0; +pub const BREAKPOINT_VALUE_NO_BREAKPOINT: u64 = 0; +pub const BREAKPOINT_VALUE_EXECUTION_FAILED: u64 = 1; +pub const BREAKPOINT_VALUE_OUT_OF_GAS: u64 = 4; #[derive(Copy, Clone, Debug)] @@ -53,7 +55,7 @@ impl FunctionMiddleware for RuntimeBreakpointHandler { FIELD_RUNTIME_BREAKPOINT_VALUE.index() as _, ))); sink.push(Event::WasmOwned(Operator::I64Const { - value: BREAKPOINT_VALUE__NO_BREAKPOINT as i64, + value: BREAKPOINT_VALUE_NO_BREAKPOINT as i64, })); sink.push(Event::WasmOwned(Operator::I64Ne)); sink.push(Event::WasmOwned(Operator::If { diff --git a/lib/runtime-c-api/src/instance.rs b/lib/runtime-c-api/src/instance.rs index 31c2527daa57..0faaddd996f9 100644 --- a/lib/runtime-c-api/src/instance.rs +++ b/lib/runtime-c-api/src/instance.rs @@ -25,6 +25,7 @@ use wasmer_middleware_common::metering; use wasmer_middleware_common::runtime_breakpoints; use wasmer_middleware_common::opcode_trace; +use wasmer_middleware_common::opcode_control; @@ -200,6 +201,7 @@ pub struct wasmer_compilation_options_t; pub struct CompilationOptions { pub gas_limit: u64, pub unmetered_locals: usize, + pub max_memory_grow_delta: usize, pub opcode_trace: bool, pub metering: bool, pub runtime_breakpoints: bool, @@ -264,6 +266,10 @@ pub unsafe fn prepare_middleware_chain_generator( )); } + chain.push(opcode_control::OpcodeControl::new(options.max_memory_grow_delta)); + + // The RuntimeBreakpointHandler must be the last middleware in the chain (OpcodeTracer is + // an exception since it does not alter the opcodes meaningfully. if options.runtime_breakpoints { chain.push(runtime_breakpoints::RuntimeBreakpointHandler::new()); } diff --git a/lib/runtime-c-api/src/runtime_breakpoints.rs b/lib/runtime-c-api/src/runtime_breakpoints.rs index d91ae6764650..dc64118963a1 100644 --- a/lib/runtime-c-api/src/runtime_breakpoints.rs +++ b/lib/runtime-c-api/src/runtime_breakpoints.rs @@ -3,7 +3,7 @@ use crate::instance::wasmer_instance_t; use wasmer_middleware_common::runtime_breakpoints::{ set_runtime_breakpoint_value, get_runtime_breakpoint_value, - BREAKPOINT_VALUE__NO_BREAKPOINT + BREAKPOINT_VALUE_NO_BREAKPOINT }; #[allow(clippy::cast_ptr_alignment)] @@ -25,7 +25,7 @@ pub unsafe extern "C" fn wasmer_instance_get_runtime_breakpoint_value( instance: *mut wasmer_instance_t, ) -> u64 { if instance.is_null() { - return BREAKPOINT_VALUE__NO_BREAKPOINT; + return BREAKPOINT_VALUE_NO_BREAKPOINT; } let instance = &mut *(instance as *mut wasmer_runtime::Instance); From aaae4eb818c7f9895b69746bf533f013787779b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 3 Nov 2021 18:09:34 +0200 Subject: [PATCH 103/129] Fix opcode type --- lib/middleware-common/src/opcode_control.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/middleware-common/src/opcode_control.rs b/lib/middleware-common/src/opcode_control.rs index f0e01d281914..9f4c9d7abb4c 100644 --- a/lib/middleware-common/src/opcode_control.rs +++ b/lib/middleware-common/src/opcode_control.rs @@ -52,7 +52,7 @@ impl FunctionMiddleware for OpcodeControl { sink.push(Event::WasmOwned(Operator::I32Const { value: self.max_memory_grow_delta as i32, })); - sink.push(Event::WasmOwned(Operator::I64GtU)); + sink.push(Event::WasmOwned(Operator::I32GtU)); sink.push(Event::WasmOwned(Operator::If { ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), })); From 09c626546f02f99305bb5e2a2ea5561971698ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 9 Nov 2021 12:15:37 +0200 Subject: [PATCH 104/129] Add memory.grow runtime limit and refactor OpcodeControl --- lib/middleware-common/src/opcode_control.rs | 67 +++++++++++++++++---- lib/runtime-c-api/src/instance.rs | 6 +- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/lib/middleware-common/src/opcode_control.rs b/lib/middleware-common/src/opcode_control.rs index 9f4c9d7abb4c..b97051b542d6 100644 --- a/lib/middleware-common/src/opcode_control.rs +++ b/lib/middleware-common/src/opcode_control.rs @@ -7,18 +7,65 @@ use wasmer_runtime_core::{ use crate::runtime_breakpoints::{push_runtime_breakpoint, BREAKPOINT_VALUE_EXECUTION_FAILED}; +static FIELD_MEMORY_GROW_COUNT: InternalField = InternalField::allocate(); + static FIELD_OPERAND_BACKUP: InternalField = InternalField::allocate(); pub struct OpcodeControl { + pub max_memory_grow: usize, pub max_memory_grow_delta: usize, } impl OpcodeControl { - pub fn new(max_memory_grow_delta: usize) -> OpcodeControl { + pub fn new(max_memory_grow: usize, max_memory_grow_delta: usize) -> OpcodeControl { OpcodeControl { + max_memory_grow, max_memory_grow_delta, } } + + fn inject_memory_grow_count_limit(&mut self, sink: &mut EventSink) { + sink.push(Event::Internal(InternalEvent::GetInternal( + FIELD_MEMORY_GROW_COUNT.index() as _, + ))); + sink.push(Event::WasmOwned(Operator::I64Const { + value: self.max_memory_grow as i64, + })); + sink.push(Event::WasmOwned(Operator::I64GeU)); + sink.push(Event::WasmOwned(Operator::If { + ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), + })); + push_runtime_breakpoint(sink, BREAKPOINT_VALUE_EXECUTION_FAILED); + sink.push(Event::WasmOwned(Operator::End)); + } + + fn inject_memory_grow_count_increment(&mut self, sink: &mut EventSink) { + sink.push(Event::Internal(InternalEvent::GetInternal( + FIELD_MEMORY_GROW_COUNT.index() as _, + ))); + sink.push(Event::WasmOwned(Operator::I64Const{ + value: 1 as i64, + })); + sink.push(Event::WasmOwned(Operator::I64Add)); + sink.push(Event::Internal(InternalEvent::SetInternal( + FIELD_MEMORY_GROW_COUNT.index() as _, + ))); + } + + fn inject_memory_grow_delta_limit(&mut self, sink: &mut EventSink) { + sink.push(Event::Internal(InternalEvent::GetInternal( + FIELD_OPERAND_BACKUP.index() as _, + ))); + sink.push(Event::WasmOwned(Operator::I64Const { + value: self.max_memory_grow_delta as i64, + })); + sink.push(Event::WasmOwned(Operator::I64GtU)); + sink.push(Event::WasmOwned(Operator::If { + ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), + })); + push_runtime_breakpoint(sink, BREAKPOINT_VALUE_EXECUTION_FAILED); + sink.push(Event::WasmOwned(Operator::End)); + } } impl FunctionMiddleware for OpcodeControl { @@ -38,6 +85,11 @@ impl FunctionMiddleware for OpcodeControl { return Err("MemoryGrow must have memory index 0".to_string()); } + // Before attempting anything with memory.grow, the current memory.grow + // count is checked against the self.max_memory_grow limit. + self.inject_memory_grow_count_limit(sink); + self.inject_memory_grow_count_increment(sink); + // Backup the top of the stack (the parameter for memory.grow) in order to // duplicate it: once for the comparison against max_memory_grow_delta and // again for memory.grow itself, assuming the comparison passes. @@ -46,18 +98,7 @@ impl FunctionMiddleware for OpcodeControl { ))); // Set up the comparison against max_memory_grow_delta. - sink.push(Event::Internal(InternalEvent::GetInternal( - FIELD_OPERAND_BACKUP.index() as _, - ))); - sink.push(Event::WasmOwned(Operator::I32Const { - value: self.max_memory_grow_delta as i32, - })); - sink.push(Event::WasmOwned(Operator::I32GtU)); - sink.push(Event::WasmOwned(Operator::If { - ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), - })); - push_runtime_breakpoint(sink, BREAKPOINT_VALUE_EXECUTION_FAILED); - sink.push(Event::WasmOwned(Operator::End)); + self.inject_memory_grow_delta_limit(sink); // Bring back the backed-up operand for memory.grow. sink.push(Event::Internal(InternalEvent::GetInternal( diff --git a/lib/runtime-c-api/src/instance.rs b/lib/runtime-c-api/src/instance.rs index 0faaddd996f9..cf7587198f26 100644 --- a/lib/runtime-c-api/src/instance.rs +++ b/lib/runtime-c-api/src/instance.rs @@ -201,6 +201,7 @@ pub struct wasmer_compilation_options_t; pub struct CompilationOptions { pub gas_limit: u64, pub unmetered_locals: usize, + pub max_memory_grow: usize, pub max_memory_grow_delta: usize, pub opcode_trace: bool, pub metering: bool, @@ -266,7 +267,10 @@ pub unsafe fn prepare_middleware_chain_generator( )); } - chain.push(opcode_control::OpcodeControl::new(options.max_memory_grow_delta)); + chain.push(opcode_control::OpcodeControl::new( + options.max_memory_grow, + options.max_memory_grow_delta + )); // The RuntimeBreakpointHandler must be the last middleware in the chain (OpcodeTracer is // an exception since it does not alter the opcodes meaningfully. From 397c57442da609790070f63882818ae1e62983e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Thu, 9 Dec 2021 23:46:10 +0200 Subject: [PATCH 105/129] Begin adding derivations of Archive for Artifact (WIP) --- .ycm_extra_conf.py | 5 + Cargo.lock | 155 +++++++++++++++++++--- lib/runtime-core/Cargo.toml | 1 + lib/runtime-core/src/cache.rs | 6 +- lib/runtime-core/src/lib.rs | 2 + lib/runtime-core/src/module.rs | 15 ++- lib/runtime-core/src/structures/map.rs | 4 +- lib/runtime-core/src/sys/unix/memory.rs | 5 +- lib/runtime-core/src/types.rs | 3 +- lib/runtime-core/src/wrapped_index_map.rs | 116 ++++++++++++++++ 10 files changed, 282 insertions(+), 30 deletions(-) create mode 100644 .ycm_extra_conf.py create mode 100644 lib/runtime-core/src/wrapped_index_map.rs diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py new file mode 100644 index 000000000000..57a3cb275edf --- /dev/null +++ b/.ycm_extra_conf.py @@ -0,0 +1,5 @@ +def Settings(**kwargs): + if kwargs['language'] == 'rust': + return { + 'diagnostics_disabled': ['unresolved-proc-macro', 'inactive-code'] + } diff --git a/Cargo.lock b/Cargo.lock index f6c7da54dc62..54076ce3aa81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,17 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom 0.2.3", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "0.7.13" @@ -86,7 +97,7 @@ dependencies = [ "arrayref", "arrayvec", "cc", - "cfg-if", + "cfg-if 0.1.10", "constant_time_eq", "crypto-mac", "digest", @@ -104,6 +115,27 @@ dependencies = [ "serde", ] +[[package]] +name = "bytecheck" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "314889ea31cda264cb7c3d6e6e5c9415a987ecb0e72c17c00d36fbb881d34abe" +dependencies = [ + "bytecheck_derive", + "ptr_meta", +] + +[[package]] +name = "bytecheck_derive" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a2b3b92c135dae665a6f760205b89187638e83bed17ef3e44e83c712cf30600" +dependencies = [ + "proc-macro2 1.0.20", + "quote 1.0.7", + "syn 1.0.40", +] + [[package]] name = "byteorder" version = "1.3.4" @@ -148,6 +180,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "chrono" version = "0.4.15" @@ -341,7 +379,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" dependencies = [ "autocfg 1.0.1", - "cfg-if", + "cfg-if 0.1.10", "crossbeam-utils", "lazy_static", "maybe-uninit", @@ -356,7 +394,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" dependencies = [ "autocfg 1.0.1", - "cfg-if", + "cfg-if 0.1.10", "lazy_static", ] @@ -524,7 +562,7 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e1d3b771574f62d0548cee0ad9057857e9fc25d7a3335f140c84f6acd0bf601" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "serde", ] @@ -543,11 +581,22 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "wasi 0.9.0+wasi-snapshot-preview1", ] +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", +] + [[package]] name = "ghost" version = "0.1.2" @@ -613,6 +662,15 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00d63df3d41950fb462ed38308eea019113ad1508da725bbedcd0fa5a85ef5f7" +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] + [[package]] name = "heck" version = "0.3.1" @@ -644,7 +702,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2" dependencies = [ "autocfg 1.0.1", - "hashbrown", + "hashbrown 0.9.0", "serde", ] @@ -733,7 +791,7 @@ checksum = "db65c6da02e61f55dae90a0ae427b2a5f6b3e8db09f58d10efab23af92592616" dependencies = [ "arrayvec", "bitflags", - "cfg-if", + "cfg-if 0.1.10", "ryu", "static_assertions", ] @@ -772,7 +830,7 @@ version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", ] [[package]] @@ -840,7 +898,7 @@ checksum = "3b2e0b4f3320ed72aaedb9a5ac838690a8047c7b275da22711fddff4f8a14229" dependencies = [ "bitflags", "cc", - "cfg-if", + "cfg-if 0.1.10", "libc", "void", ] @@ -909,9 +967,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.4.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "orbclient" @@ -967,7 +1025,7 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "cloudabi", "libc", "redox_syscall", @@ -1039,6 +1097,26 @@ dependencies = [ "unicode-xid 0.2.1", ] +[[package]] +name = "ptr_meta" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" +dependencies = [ + "ptr_meta_derive", +] + +[[package]] +name = "ptr_meta_derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" +dependencies = [ + "proc-macro2 1.0.20", + "quote 1.0.7", + "syn 1.0.40", +] + [[package]] name = "quote" version = "0.6.13" @@ -1082,7 +1160,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom", + "getrandom 0.1.14", "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", @@ -1130,7 +1208,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.14", ] [[package]] @@ -1307,6 +1385,40 @@ dependencies = [ "winapi", ] +[[package]] +name = "rend" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1033f6fe7ce48c8333e5412891b933e85d6a3a09728c4883240edf64e7a6f11a" +dependencies = [ + "bytecheck", +] + +[[package]] +name = "rkyv" +version = "0.7.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66bf572c17c77322f4d858c214def56b13a3c32b8d833cd6d28a92de8325ac5f" +dependencies = [ + "bytecheck", + "hashbrown 0.11.2", + "ptr_meta", + "rend", + "rkyv_derive", + "seahash", +] + +[[package]] +name = "rkyv_derive" +version = "0.7.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3eca50f172b8e59e2080810fb41b65f047960c197149564d4bd0680af1888e" +dependencies = [ + "proc-macro2 1.0.20", + "quote 1.0.7", + "syn 1.0.40", +] + [[package]] name = "rustc_version" version = "0.2.3" @@ -1398,10 +1510,16 @@ version = "0.32.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34e71125077d297d57e4c1acfe8981b5bdfbf5a20e7b589abfdcb33bf1127f86" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", ] +[[package]] +name = "seahash" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" + [[package]] name = "semver" version = "0.9.0" @@ -1579,7 +1697,7 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "rand 0.7.3", "redox_syscall", @@ -1883,7 +2001,7 @@ name = "wasmer-emscripten" version = "0.15.0" dependencies = [ "byteorder", - "getrandom", + "getrandom 0.1.14", "lazy_static", "libc", "log", @@ -2021,6 +2139,7 @@ dependencies = [ "nix", "page_size", "parking_lot", + "rkyv", "rustc_version", "serde", "serde-bench", @@ -2081,7 +2200,7 @@ dependencies = [ "bincode", "byteorder", "generational-arena", - "getrandom", + "getrandom 0.1.14", "libc", "log", "serde", diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index f7278a1cdadc..ff2a10530a74 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -22,6 +22,7 @@ smallvec = "0.6" bincode = "1.1" wasm-debug = { optional = true, version = "0.1.0" } target-lexicon = "0.9" +rkyv = "0.7.26" [dependencies.indexmap] version = "1.2" diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index 0e74ee4dc51d..e174ca6bd094 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -3,6 +3,7 @@ //! and loaded to allow skipping compilation and fast startup. use crate::{module::ModuleInfo, sys::Memory}; +use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; use std::{io, mem, slice}; /// Indicates the invalid type of invalid cache file @@ -152,8 +153,8 @@ impl ArtifactHeader { } -#[derive(Serialize, Deserialize)] -struct ArtifactInner { +#[derive(Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] +pub struct ArtifactInner { info: Box, #[serde(with = "serde_bytes")] backend_metadata: Box<[u8]>, @@ -162,6 +163,7 @@ struct ArtifactInner { /// Artifact are produced by caching, are serialized/deserialized to binaries, and contain /// module info, backend metadata, and compiled code. +#[derive(Archive, RkyvSerialize, RkyvDeserialize)] pub struct Artifact { inner: ArtifactInner, } diff --git a/lib/runtime-core/src/lib.rs b/lib/runtime-core/src/lib.rs index daf63ef74193..68d29a099bf5 100644 --- a/lib/runtime-core/src/lib.rs +++ b/lib/runtime-core/src/lib.rs @@ -25,6 +25,7 @@ #![cfg_attr(nightly, feature(unwind_attributes))] #![doc(html_favicon_url = "https://wasmer.io/static/icons/favicon.ico")] #![doc(html_logo_url = "https://avatars3.githubusercontent.com/u/44205449?s=200&v=4")] +#![feature(trivial_bounds)] #[macro_use] extern crate serde_derive; @@ -60,6 +61,7 @@ pub mod typed_func; pub mod types; pub mod units; pub mod vm; +pub mod wrapped_index_map; #[doc(hidden)] pub mod vmcalls; #[cfg(all(unix, target_arch = "x86_64"))] diff --git a/lib/runtime-core/src/module.rs b/lib/runtime-core/src/module.rs index 47a38ae8babf..27b7e7b51268 100644 --- a/lib/runtime-core/src/module.rs +++ b/lib/runtime-core/src/module.rs @@ -18,10 +18,12 @@ use crate::{ use crate::backend::CacheGen; #[cfg(feature = "generate-debug-information")] use crate::jit_debug; -use indexmap::IndexMap; +use crate::wrapped_index_map::WrappedIndexMap; use std::collections::HashMap; use std::sync::Arc; +use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; + /// This is used to instantiate a new WebAssembly module. #[doc(hidden)] pub struct ModuleInner { @@ -31,7 +33,7 @@ pub struct ModuleInner { } /// Container for module data including memories, globals, tables, imports, and exports. -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] pub struct ModuleInfo { /// Map of memory index to memory descriptors. // This are strictly local and the typesystem ensures that. @@ -52,7 +54,7 @@ pub struct ModuleInfo { pub imported_globals: Map, /// Map of string to export index. - pub exports: IndexMap, + pub exports: WrappedIndexMap, /// Vector of data initializers. pub data_initializers: Vec, @@ -217,7 +219,7 @@ pub struct DataInitializer { } /// A WebAssembly table initializer. -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone, Archive, RkyvSerialize, RkyvDeserialize)] pub struct TableInitializer { /// The index of a table to initialize. pub table_index: TableIndex, @@ -228,8 +230,9 @@ pub struct TableInitializer { } /// String table builder. +#[derive(Archive, RkyvSerialize, RkyvDeserialize)] pub struct StringTableBuilder { - map: IndexMap, + map: WrappedIndexMap, buffer: String, count: u32, } @@ -238,7 +241,7 @@ impl StringTableBuilder { /// Creates a new [`StringTableBuilder`]. pub fn new() -> Self { Self { - map: IndexMap::new(), + map: WrappedIndexMap::new(), buffer: String::new(), count: 0, } diff --git a/lib/runtime-core/src/structures/map.rs b/lib/runtime-core/src/structures/map.rs index 0ea4beb4ff92..9e41fd75a4e0 100644 --- a/lib/runtime-core/src/structures/map.rs +++ b/lib/runtime-core/src/structures/map.rs @@ -7,8 +7,10 @@ use std::{ slice, vec, }; +use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; + /// Dense item map -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone, Archive, RkyvSerialize, RkyvDeserialize)] pub struct Map where K: TypedIndex, diff --git a/lib/runtime-core/src/sys/unix/memory.rs b/lib/runtime-core/src/sys/unix/memory.rs index 45a58a3e860e..40aebbc39e65 100644 --- a/lib/runtime-core/src/sys/unix/memory.rs +++ b/lib/runtime-core/src/sys/unix/memory.rs @@ -6,12 +6,13 @@ use nix::libc; use page_size; use std::ops::{Bound, RangeBounds}; use std::{fs::File, os::unix::io::IntoRawFd, path::Path, ptr, slice, sync::Arc}; +use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; unsafe impl Send for Memory {} unsafe impl Sync for Memory {} /// Data for a sized and protected region of memory. -#[derive(Debug)] +#[derive(Debug, Archive, RkyvSerialize, RkyvDeserialize)] pub struct Memory { ptr: *mut u8, size: usize, @@ -295,7 +296,7 @@ impl Protect { } #[derive(Debug)] -struct RawFd(i32); +pub struct RawFd(i32); impl RawFd { fn from_file(f: File) -> Self { diff --git a/lib/runtime-core/src/types.rs b/lib/runtime-core/src/types.rs index 122aa544a8b8..2ea06f26f55a 100644 --- a/lib/runtime-core/src/types.rs +++ b/lib/runtime-core/src/types.rs @@ -3,6 +3,7 @@ use crate::{memory::MemoryType, module::ModuleInfo, structures::TypedIndex, units::Pages}; use std::{borrow::Cow, convert::TryFrom}; +use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; /// Represents a WebAssembly type. #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -423,7 +424,7 @@ pub trait LocalImport { macro_rules! define_map_index { ($ty:ident) => { /// Typed Index - #[derive(Serialize, Deserialize)] + #[derive(Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct $ty (u32); impl TypedIndex for $ty { diff --git a/lib/runtime-core/src/wrapped_index_map.rs b/lib/runtime-core/src/wrapped_index_map.rs new file mode 100644 index 000000000000..72238af584e3 --- /dev/null +++ b/lib/runtime-core/src/wrapped_index_map.rs @@ -0,0 +1,116 @@ +use ::core::hash::Hash; +use indexmap::{IndexMap, Equivalent}; +use indexmap::map::Iter; +use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; +use ::core::fmt; +use serde::ser::{Serialize, Serializer}; +use serde::de::{ Deserialize, Deserializer}; +use ::core::ops::Index; + +#[derive(Archive, RkyvSerialize, RkyvDeserialize)] +pub struct WrappedIndexMap(IndexMap); + +impl WrappedIndexMap +where + K: Hash + Eq, +{ + pub fn new() -> Self { + WrappedIndexMap(IndexMap::new()) + } + + pub fn get(&self, key: &Q) -> Option<&V> + where + Q: Hash + Equivalent, + { + self.0.get(&key) + } + + pub fn iter(&self) -> Iter<'_, K, V> { + self.0.iter() + } + + pub fn contains_key(&self, key: &Q) -> bool + where + Q: Hash + Equivalent, + { + self.0.contains_key(&key) + } + + pub fn insert(&mut self, key: K, value: V) -> Option { + self.0.insert(key, value) + } + + pub fn values(&self) -> Values<'_, K, V> { + self.0.values() + } +} + +impl Clone for WrappedIndexMap +where + K: Clone, + V: Clone, +{ + fn clone(&self) -> Self { + self.0.clone() + } + + fn clone_from(&mut self, other: &Self) { + self.0.clone_from(&other); + } +} + +impl fmt::Debug for WrappedIndexMap +where + K: fmt::Debug, + V: fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(&f) + } +} + +impl Serialize for WrappedIndexMap +where + K: Serialize + Hash + Eq, + V: Serialize, +{ + fn serialize(&self, serializer: T) -> Result + where + T: Serializer, + { + self.0.serialize(serializer) + } +} + +impl<'de, K, V> Deserialize<'de> for WrappedIndexMap +where + K: Deserialize<'de> + Eq + Hash, + V: Deserialize<'de>, +{ + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + IndexMap::deserialize(deserializer) + } +} + +impl Index<&Q> for WrappedIndexMap +where + Q: Hash + Equivalent, + K: Hash + Eq, +{ + type Output = V; + + fn index(&self, key: &Q) -> &V { + self.0.index(&key) + } +} + +impl Default for IndexMap +where + S: Default, +{ + /// Return an empty `IndexMap` + fn default() -> Self { + } From c44860cfb6156c557cfb04ee00d2026e53ee1ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Sun, 12 Dec 2021 19:56:08 +0200 Subject: [PATCH 106/129] More references to WrappedIndexMap --- lib/runtime-core/src/cache.rs | 1 + lib/runtime-core/src/memory/mod.rs | 4 ++- lib/runtime-core/src/module.rs | 16 ++++----- lib/runtime-core/src/sys/unix/memory.rs | 4 +-- lib/runtime-core/src/types.rs | 18 +++++----- lib/runtime-core/src/units.rs | 4 ++- lib/runtime-core/src/vm.rs | 4 +-- lib/runtime-core/src/wrapped_index_map.rs | 44 +++++++++++++++-------- 8 files changed, 58 insertions(+), 37 deletions(-) diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index e174ca6bd094..fbce632d2a79 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -153,6 +153,7 @@ impl ArtifactHeader { } +/// Inner information of an Artifact. #[derive(Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] pub struct ArtifactInner { info: Box, diff --git a/lib/runtime-core/src/memory/mod.rs b/lib/runtime-core/src/memory/mod.rs index 46818f7c3b35..83797d65266b 100644 --- a/lib/runtime-core/src/memory/mod.rs +++ b/lib/runtime-core/src/memory/mod.rs @@ -14,6 +14,8 @@ use std::{cell::Cell, fmt, mem, sync::Arc}; use std::sync::Mutex as StdMutex; +use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; + pub use self::dynamic::DynamicMemory; pub use self::static_::StaticMemory; pub use self::view::{Atomically, MemoryView}; @@ -173,7 +175,7 @@ impl fmt::Debug for Memory { } /// A kind a memory. -#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash, Archive, RkyvSerialize, RkyvDeserialize)] pub enum MemoryType { /// A dynamic memory. Dynamic, diff --git a/lib/runtime-core/src/module.rs b/lib/runtime-core/src/module.rs index 27b7e7b51268..11e6cbddedae 100644 --- a/lib/runtime-core/src/module.rs +++ b/lib/runtime-core/src/module.rs @@ -15,6 +15,8 @@ use crate::{ Instance, }; +use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; + use crate::backend::CacheGen; #[cfg(feature = "generate-debug-information")] use crate::jit_debug; @@ -22,8 +24,6 @@ use crate::wrapped_index_map::WrappedIndexMap; use std::collections::HashMap; use std::sync::Arc; -use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; - /// This is used to instantiate a new WebAssembly module. #[doc(hidden)] pub struct ModuleInner { @@ -178,7 +178,7 @@ impl Clone for Module { impl ModuleInner {} #[doc(hidden)] -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone, Archive, RkyvSerialize, RkyvDeserialize)] pub struct ImportName { pub namespace_index: NamespaceIndex, pub name_index: NameIndex, @@ -190,7 +190,7 @@ pub struct ImportName { /// Used in [`ModuleInfo`] to access function signatures ([`SigIndex`]s, /// [`FuncSig`]), [`GlobalInit`]s, [`MemoryDescriptor`]s, and /// [`TableDescriptor`]s. -#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Archive, RkyvSerialize, RkyvDeserialize)] pub enum ExportIndex { /// Function export index. [`FuncIndex`] is a type-safe handle referring to /// a Wasm function. @@ -207,7 +207,7 @@ pub enum ExportIndex { } /// A data initializer for linear memory. -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone, Archive, RkyvSerialize, RkyvDeserialize)] pub struct DataInitializer { /// The index of the memory to initialize. pub memory_index: MemoryIndex, @@ -286,7 +286,7 @@ impl StringTableBuilder { } /// A map of index to string. -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone, Archive, RkyvSerialize, RkyvDeserialize)] pub struct StringTable { table: Map, buffer: String, @@ -321,7 +321,7 @@ impl StringTable { } /// A type-safe handle referring to a module namespace. -#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Hash, Archive, RkyvSerialize, RkyvDeserialize)] pub struct NamespaceIndex(u32); impl TypedIndex for NamespaceIndex { @@ -337,7 +337,7 @@ impl TypedIndex for NamespaceIndex { } /// A type-safe handle referring to a name in a module namespace. -#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Hash, Archive, RkyvSerialize, RkyvDeserialize)] pub struct NameIndex(u32); impl TypedIndex for NameIndex { diff --git a/lib/runtime-core/src/sys/unix/memory.rs b/lib/runtime-core/src/sys/unix/memory.rs index 40aebbc39e65..26cc4ff8228e 100644 --- a/lib/runtime-core/src/sys/unix/memory.rs +++ b/lib/runtime-core/src/sys/unix/memory.rs @@ -252,7 +252,7 @@ impl Clone for Memory { } /// Kinds of memory protection. -#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Archive, RkyvSerialize, RkyvDeserialize)] #[allow(dead_code)] pub enum Protect { /// Read/write/exec allowed. @@ -295,7 +295,7 @@ impl Protect { } } -#[derive(Debug)] +#[derive(Debug, Archive, RkyvSerialize, RkyvDeserialize)] pub struct RawFd(i32); impl RawFd { diff --git a/lib/runtime-core/src/types.rs b/lib/runtime-core/src/types.rs index 2ea06f26f55a..76cdb1ad3f4b 100644 --- a/lib/runtime-core/src/types.rs +++ b/lib/runtime-core/src/types.rs @@ -30,7 +30,7 @@ impl std::fmt::Display for Type { /// /// As the number of types in WebAssembly expand, /// this structure will expand as well. -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Archive, RkyvSerialize, RkyvDeserialize)] pub enum Value { /// The `i32` type. I32(i32), @@ -247,7 +247,7 @@ macro_rules! convert_value_impl { convert_value_impl!(u8, i8, u16, i16, u32, i32, u64, i64, f32, f64); /// Kinds of element types. -#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Archive, RkyvSerialize, RkyvDeserialize)] pub enum ElementType { /// Any wasm function. Anyfunc, @@ -255,7 +255,7 @@ pub enum ElementType { /// Describes the properties of a table including the element types, minimum and optional maximum, /// number of elements in the table. -#[derive(Serialize, Deserialize, Debug, Clone, Copy)] +#[derive(Serialize, Deserialize, Debug, Clone, Copy, Archive, RkyvSerialize, RkyvDeserialize)] pub struct TableDescriptor { /// Type of data stored in this table. pub element: ElementType, @@ -279,7 +279,7 @@ impl TableDescriptor { /// A const value initializer. /// Over time, this will be able to represent more and more /// complex expressions. -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Archive, RkyvSerialize, RkyvDeserialize)] pub enum Initializer { /// Corresponds to a `const.*` instruction. Const(Value), @@ -288,7 +288,7 @@ pub enum Initializer { } /// Describes the mutability and type of a Global -#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Archive, RkyvSerialize, RkyvDeserialize)] pub struct GlobalDescriptor { /// Mutable flag. pub mutable: bool, @@ -297,7 +297,7 @@ pub struct GlobalDescriptor { } /// A wasm global. -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone, Archive, RkyvSerialize, RkyvDeserialize)] pub struct GlobalInit { /// Global descriptor. pub desc: GlobalDescriptor, @@ -306,7 +306,7 @@ pub struct GlobalInit { } /// A wasm memory descriptor. -#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Archive, RkyvSerialize, RkyvDeserialize)] pub struct MemoryDescriptor { /// The minimum number of allowed pages. pub minimum: Pages, @@ -354,7 +354,7 @@ impl MemoryDescriptor { /// The signature of a function that is either implemented /// in a wasm module or exposed to wasm by the host. -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash, Archive, RkyvSerialize, RkyvDeserialize)] pub struct FuncSig { params: Cow<'static, [Type]>, returns: Cow<'static, [Type]>, @@ -504,7 +504,7 @@ define_local_or_import![ ]; /// Index for signature. -#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Hash, Archive, RkyvSerialize, RkyvDeserialize)] pub struct SigIndex(u32); impl TypedIndex for SigIndex { #[doc(hidden)] diff --git a/lib/runtime-core/src/units.rs b/lib/runtime-core/src/units.rs index 780ceb034dda..0df5bdec2c07 100644 --- a/lib/runtime-core/src/units.rs +++ b/lib/runtime-core/src/units.rs @@ -6,6 +6,8 @@ use std::{ ops::{Add, Sub}, }; +use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; + /// The page size in bytes of a wasm page. pub const WASM_PAGE_SIZE: usize = 65_536; /// The max number of wasm pages allowed. @@ -15,7 +17,7 @@ pub const WASM_MAX_PAGES: usize = 65_536; pub const WASM_MIN_PAGES: usize = 256; /// Units of WebAssembly pages (as specified to be 65,536 bytes). -#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Archive, RkyvSerialize, RkyvDeserialize)] pub struct Pages(pub u32); impl Pages { diff --git a/lib/runtime-core/src/vm.rs b/lib/runtime-core/src/vm.rs index 73b9b2e61131..5a3a5c61490e 100644 --- a/lib/runtime-core/src/vm.rs +++ b/lib/runtime-core/src/vm.rs @@ -1072,7 +1072,7 @@ mod vm_ctx_tests { use crate::cache::Error as CacheError; use crate::typed_func::Wasm; use crate::types::{LocalFuncIndex, SigIndex}; - use indexmap::IndexMap; + use crate::WrappedIndexMap; use std::any::Any; use std::collections::HashMap; use std::ptr::NonNull; @@ -1113,7 +1113,7 @@ mod vm_ctx_tests { imported_tables: Map::new(), imported_globals: Map::new(), - exports: IndexMap::new(), + exports: WrappedIndexMap::new(), data_initializers: Vec::new(), elem_initializers: Vec::new(), diff --git a/lib/runtime-core/src/wrapped_index_map.rs b/lib/runtime-core/src/wrapped_index_map.rs index 72238af584e3..558ca945fa44 100644 --- a/lib/runtime-core/src/wrapped_index_map.rs +++ b/lib/runtime-core/src/wrapped_index_map.rs @@ -1,12 +1,16 @@ +//! Provides WrappedIndexMap, a newtype built on indexmap::IndexMap in order to implement +//! the rkyv::Archive trait. + use ::core::hash::Hash; use indexmap::{IndexMap, Equivalent}; -use indexmap::map::Iter; +use indexmap::map::{Iter, Values}; use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; use ::core::fmt; use serde::ser::{Serialize, Serializer}; use serde::de::{ Deserialize, Deserializer}; use ::core::ops::Index; +/// A newtype that wraps indexmap::IndexMap. #[derive(Archive, RkyvSerialize, RkyvDeserialize)] pub struct WrappedIndexMap(IndexMap); @@ -14,32 +18,38 @@ impl WrappedIndexMap where K: Hash + Eq, { + /// Passthrough method. pub fn new() -> Self { WrappedIndexMap(IndexMap::new()) } + /// Passthrough method. pub fn get(&self, key: &Q) -> Option<&V> where - Q: Hash + Equivalent, + Q: Hash + Eq + Equivalent, { - self.0.get(&key) + self.0.get(key) } + /// Passthrough method. pub fn iter(&self) -> Iter<'_, K, V> { self.0.iter() } + /// Passthrough method. pub fn contains_key(&self, key: &Q) -> bool where - Q: Hash + Equivalent, + Q: Hash + Eq + Equivalent, { - self.0.contains_key(&key) + self.0.contains_key(key) } + /// Passthrough method. pub fn insert(&mut self, key: K, value: V) -> Option { self.0.insert(key, value) } + /// Passthrough method. pub fn values(&self) -> Values<'_, K, V> { self.0.values() } @@ -50,12 +60,14 @@ where K: Clone, V: Clone, { + /// Passthrough method. fn clone(&self) -> Self { - self.0.clone() + WrappedIndexMap(self.0.clone()) } + /// Passthrough method. fn clone_from(&mut self, other: &Self) { - self.0.clone_from(&other); + self.0.clone_from(&other.0); } } @@ -64,8 +76,9 @@ where K: fmt::Debug, V: fmt::Debug, { + /// Passthrough method. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.0.fmt(&f) + self.0.fmt(f) } } @@ -74,6 +87,7 @@ where K: Serialize + Hash + Eq, V: Serialize, { + /// Passthrough method. fn serialize(&self, serializer: T) -> Result where T: Serializer, @@ -87,11 +101,12 @@ where K: Deserialize<'de> + Eq + Hash, V: Deserialize<'de>, { + /// Passthrough method. fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, { - IndexMap::deserialize(deserializer) + serde::Deserialize::deserialize(deserializer) } } @@ -102,15 +117,16 @@ where { type Output = V; + /// Passthrough method. fn index(&self, key: &Q) -> &V { - self.0.index(&key) + self.0.index(key) } } -impl Default for IndexMap -where - S: Default, +impl Default for WrappedIndexMap { - /// Return an empty `IndexMap` + /// Passthrough method. fn default() -> Self { + WrappedIndexMap(IndexMap::default()) } +} From 3b70e7d53b4b04aadfe5db337528789d5e943a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 14 Dec 2021 15:43:43 +0200 Subject: [PATCH 107/129] Enable the indexmap feature of rkyv --- Cargo.lock | 15 +++++---------- lib/runtime-core/Cargo.toml | 7 +++++-- lib/runtime-core/src/module.rs | 9 +++++---- lib/runtime-core/src/types.rs | 2 +- lib/runtime-core/src/vm.rs | 4 ++-- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 54076ce3aa81..d3b5fe270036 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -656,12 +656,6 @@ dependencies = [ "scroll 0.10.1", ] -[[package]] -name = "hashbrown" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00d63df3d41950fb462ed38308eea019113ad1508da725bbedcd0fa5a85ef5f7" - [[package]] name = "hashbrown" version = "0.11.2" @@ -697,12 +691,12 @@ checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" [[package]] name = "indexmap" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" dependencies = [ "autocfg 1.0.1", - "hashbrown 0.9.0", + "hashbrown", "serde", ] @@ -1401,7 +1395,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "66bf572c17c77322f4d858c214def56b13a3c32b8d833cd6d28a92de8325ac5f" dependencies = [ "bytecheck", - "hashbrown 0.11.2", + "hashbrown", + "indexmap", "ptr_meta", "rend", "rkyv_derive", diff --git a/lib/runtime-core/Cargo.toml b/lib/runtime-core/Cargo.toml index ff2a10530a74..6bb6477eb122 100644 --- a/lib/runtime-core/Cargo.toml +++ b/lib/runtime-core/Cargo.toml @@ -22,10 +22,13 @@ smallvec = "0.6" bincode = "1.1" wasm-debug = { optional = true, version = "0.1.0" } target-lexicon = "0.9" -rkyv = "0.7.26" + +[dependencies.rkyv] +version = "0.7.26" +features = ["indexmap"] [dependencies.indexmap] -version = "1.2" +version = "1.7" features = ["serde-1"] # Dependencies for caching. diff --git a/lib/runtime-core/src/module.rs b/lib/runtime-core/src/module.rs index 11e6cbddedae..41c280d99477 100644 --- a/lib/runtime-core/src/module.rs +++ b/lib/runtime-core/src/module.rs @@ -15,12 +15,13 @@ use crate::{ Instance, }; +use indexmap::IndexMap; + use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; use crate::backend::CacheGen; #[cfg(feature = "generate-debug-information")] use crate::jit_debug; -use crate::wrapped_index_map::WrappedIndexMap; use std::collections::HashMap; use std::sync::Arc; @@ -54,7 +55,7 @@ pub struct ModuleInfo { pub imported_globals: Map, /// Map of string to export index. - pub exports: WrappedIndexMap, + pub exports: IndexMap, /// Vector of data initializers. pub data_initializers: Vec, @@ -232,7 +233,7 @@ pub struct TableInitializer { /// String table builder. #[derive(Archive, RkyvSerialize, RkyvDeserialize)] pub struct StringTableBuilder { - map: WrappedIndexMap, + map: IndexMap, buffer: String, count: u32, } @@ -241,7 +242,7 @@ impl StringTableBuilder { /// Creates a new [`StringTableBuilder`]. pub fn new() -> Self { Self { - map: WrappedIndexMap::new(), + map: IndexMap::new(), buffer: String::new(), count: 0, } diff --git a/lib/runtime-core/src/types.rs b/lib/runtime-core/src/types.rs index 76cdb1ad3f4b..e6e5f6c4c4db 100644 --- a/lib/runtime-core/src/types.rs +++ b/lib/runtime-core/src/types.rs @@ -6,7 +6,7 @@ use std::{borrow::Cow, convert::TryFrom}; use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; /// Represents a WebAssembly type. -#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash, Archive, RkyvSerialize, RkyvDeserialize)] pub enum Type { /// The `i32` type. I32, diff --git a/lib/runtime-core/src/vm.rs b/lib/runtime-core/src/vm.rs index 5a3a5c61490e..73b9b2e61131 100644 --- a/lib/runtime-core/src/vm.rs +++ b/lib/runtime-core/src/vm.rs @@ -1072,7 +1072,7 @@ mod vm_ctx_tests { use crate::cache::Error as CacheError; use crate::typed_func::Wasm; use crate::types::{LocalFuncIndex, SigIndex}; - use crate::WrappedIndexMap; + use indexmap::IndexMap; use std::any::Any; use std::collections::HashMap; use std::ptr::NonNull; @@ -1113,7 +1113,7 @@ mod vm_ctx_tests { imported_tables: Map::new(), imported_globals: Map::new(), - exports: WrappedIndexMap::new(), + exports: IndexMap::new(), data_initializers: Vec::new(), elem_initializers: Vec::new(), From 9a0986fa1b1d4c7caec3946f63b1d88e46a2c176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 15 Dec 2021 18:42:57 +0200 Subject: [PATCH 108/129] Begin implementation of WrappedCow --- lib/runtime-core/src/lib.rs | 1 + lib/runtime-core/src/types.rs | 11 +++--- lib/runtime-core/src/wrapped_cow.rs | 58 +++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 lib/runtime-core/src/wrapped_cow.rs diff --git a/lib/runtime-core/src/lib.rs b/lib/runtime-core/src/lib.rs index 68d29a099bf5..81e6eba6eb9f 100644 --- a/lib/runtime-core/src/lib.rs +++ b/lib/runtime-core/src/lib.rs @@ -61,6 +61,7 @@ pub mod typed_func; pub mod types; pub mod units; pub mod vm; +pub mod wrapped_cow; pub mod wrapped_index_map; #[doc(hidden)] pub mod vmcalls; diff --git a/lib/runtime-core/src/types.rs b/lib/runtime-core/src/types.rs index e6e5f6c4c4db..46df35aa9dc0 100644 --- a/lib/runtime-core/src/types.rs +++ b/lib/runtime-core/src/types.rs @@ -2,8 +2,9 @@ //! convert to other represenations. use crate::{memory::MemoryType, module::ModuleInfo, structures::TypedIndex, units::Pages}; -use std::{borrow::Cow, convert::TryFrom}; +use std::convert::TryFrom; use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; +use crate::wrapped_cow::WrappedCow; /// Represents a WebAssembly type. #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash, Archive, RkyvSerialize, RkyvDeserialize)] @@ -356,16 +357,16 @@ impl MemoryDescriptor { /// in a wasm module or exposed to wasm by the host. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash, Archive, RkyvSerialize, RkyvDeserialize)] pub struct FuncSig { - params: Cow<'static, [Type]>, - returns: Cow<'static, [Type]>, + params: WrappedCow<'static, [Type]>, + returns: WrappedCow<'static, [Type]>, } impl FuncSig { /// Creates a new function signatures with the given parameter and return types. pub fn new(params: Params, returns: Returns) -> Self where - Params: Into>, - Returns: Into>, + Params: Into>, + Returns: Into>, { Self { params: params.into(), diff --git a/lib/runtime-core/src/wrapped_cow.rs b/lib/runtime-core/src/wrapped_cow.rs new file mode 100644 index 000000000000..b2c5338bb47a --- /dev/null +++ b/lib/runtime-core/src/wrapped_cow.rs @@ -0,0 +1,58 @@ +//! Provides WrappedCow, a newtype built on std::borrow:Cow in order to implement +//! the rkyv::Archive trait. + +use std::borrow::Cow; +use core::ops::Deref; + +use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; + +/// A newtype that wraps borrow::Cow. +#[derive(Archive, RkyvSerialize, RkyvDeserialize)] +pub struct WrappedCow<'a, B: ?Sized + ToOwned + 'a>(Cow<'a, B>); + +impl Clone for WrappedCow<'_, B> { + /// Passthrough method. + fn clone(&self) -> Self { + WrappedCow(self.0.clone()) + } + + /// Passthrough method. + fn clone_from(&mut self, source: &Self) { + self.0.clone_from(&source.0); + } +} + +impl WrappedCow<'_, B> { + /// Passthrough method. + pub fn to_mut(&mut self) -> &mut ::Owned { + self.0.to_mut() + } + + /// Passthrough method. + pub fn into_owned(self) -> ::Owned { + self.0.into_owned() + } +} + +impl Deref for WrappedCow<'_, B> { + type Target = B; + + /// Passthrough method. + fn deref(&self) -> &B { + self.0.deref() + } +} + +impl<'a, T: Clone> From> for Cow<'a, [T]> { + /// Newtype requirement. + fn from(v: Vec) -> Cow<'a, [T]> { + Cow::Owned(v) + } +} + +impl<'a, T: Clone> From<&'a Vec> for Cow<'a, [T]> { + /// Newtype requirement. + fn from(v: &'a Vec) -> Cow<'a, [T]> { + Cow::Borrowed(v.as_slice()) + } +} From d1ee9e7881fc8218c1f0b4baf3469e17e85220ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 15 Dec 2021 22:29:06 +0200 Subject: [PATCH 109/129] More type matching for WrappedCow --- Cargo.lock | 6 +-- lib/runtime-core/src/wrapped_cow.rs | 59 +++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3b5fe270036..7e75a7e925f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2250,13 +2250,13 @@ checksum = "c702914acda5feeeffbc29e4d953e5b9ce79d8b98da4dbf18a77086e116c5470" [[package]] name = "wasmparser" version = "0.51.4" -source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" [[package]] name = "wasmparser" version = "0.51.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" +source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" [[package]] name = "wast" diff --git a/lib/runtime-core/src/wrapped_cow.rs b/lib/runtime-core/src/wrapped_cow.rs index b2c5338bb47a..06341ff88bdf 100644 --- a/lib/runtime-core/src/wrapped_cow.rs +++ b/lib/runtime-core/src/wrapped_cow.rs @@ -2,13 +2,39 @@ //! the rkyv::Archive trait. use std::borrow::Cow; +use core::borrow::Borrow; use core::ops::Deref; +use std::hash::Hash; +use std::cmp::PartialEq; use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; /// A newtype that wraps borrow::Cow. -#[derive(Archive, RkyvSerialize, RkyvDeserialize)] -pub struct WrappedCow<'a, B: ?Sized + ToOwned + 'a>(Cow<'a, B>); +#[derive(Hash, Archive, RkyvSerialize, RkyvDeserialize, Serialize, Deserialize)] +pub struct WrappedCow<'a, B: ?Sized + ToOwned + 'a>(Cow<'a, B>); + +impl<'a, B: ?Sized> Borrow for WrappedCow<'a, B> +where + B: ToOwned + Clone, + ::Owned: 'a, +{ + fn borrow(&self) -> &B { + self.0.borrow() + } +} + +impl Eq for WrappedCow<'_, B> where B: Eq + ToOwned {} + +impl<'a, 'b, B: ?Sized, C: ?Sized> PartialEq> for WrappedCow<'a, B> +where + B: PartialEq + ToOwned + Clone, + C: ToOwned + Clone, +{ + #[inline] + fn eq(&self, other: &WrappedCow<'b, C>) -> bool { + self.0.eq(&other.0) + } +} impl Clone for WrappedCow<'_, B> { /// Passthrough method. @@ -43,16 +69,33 @@ impl Deref for WrappedCow<'_, B> { } } -impl<'a, T: Clone> From> for Cow<'a, [T]> { +impl AsRef for WrappedCow<'_, B> { + /// Passthrough method. + fn as_ref(&self) -> &B { + self.0.as_ref() + } +} + +impl<'a, B: Clone> From> for WrappedCow<'a, [B]> { /// Newtype requirement. - fn from(v: Vec) -> Cow<'a, [T]> { - Cow::Owned(v) + fn from(v: Vec) -> WrappedCow<'a, [B]> { + WrappedCow(Cow::Owned(v)) } } -impl<'a, T: Clone> From<&'a Vec> for Cow<'a, [T]> { +impl<'a, B: Clone> From<&'a Vec> for WrappedCow<'a, [B]> { /// Newtype requirement. - fn from(v: &'a Vec) -> Cow<'a, [T]> { - Cow::Borrowed(v.as_slice()) + fn from(v: &'a Vec) -> WrappedCow<'a, [B]> { + WrappedCow(Cow::Borrowed(v.as_slice())) + } +} + +impl<'a, B> From<&'a [B]> for WrappedCow<'a, [B]> +where + [B]: ToOwned +{ + /// Newtype requirement + fn from(s: &'a [B]) -> WrappedCow<'a, [B]> { + WrappedCow(Cow::Borrowed(s)) } } From ddb436110467f650155fa5cd4fc26b334c6a1cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Thu, 16 Dec 2021 15:44:26 +0200 Subject: [PATCH 110/129] More type alignment --- lib/runtime-core/src/types.rs | 4 +-- lib/runtime-core/src/wrapped_cow.rs | 43 +++++++++++++++-------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/lib/runtime-core/src/types.rs b/lib/runtime-core/src/types.rs index 46df35aa9dc0..dcf3d4122a48 100644 --- a/lib/runtime-core/src/types.rs +++ b/lib/runtime-core/src/types.rs @@ -376,12 +376,12 @@ impl FuncSig { /// Parameter types. pub fn params(&self) -> &[Type] { - &self.params + &self.params.0 } /// Return types. pub fn returns(&self) -> &[Type] { - &self.returns + &self.returns.0 } /// Returns true if parameter types match the function signature. diff --git a/lib/runtime-core/src/wrapped_cow.rs b/lib/runtime-core/src/wrapped_cow.rs index 06341ff88bdf..cb93b32637c4 100644 --- a/lib/runtime-core/src/wrapped_cow.rs +++ b/lib/runtime-core/src/wrapped_cow.rs @@ -6,14 +6,15 @@ use core::borrow::Borrow; use core::ops::Deref; use std::hash::Hash; use std::cmp::PartialEq; +use serde; use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; /// A newtype that wraps borrow::Cow. -#[derive(Hash, Archive, RkyvSerialize, RkyvDeserialize, Serialize, Deserialize)] -pub struct WrappedCow<'a, B: ?Sized + ToOwned + 'a>(Cow<'a, B>); +#[derive(PartialEq, Debug, Hash, Archive, RkyvSerialize, RkyvDeserialize, Serialize, Deserialize)] +pub struct WrappedCow<'a, B: ?Sized + ToOwned + serde::Serialize + serde::Deserialize<'a> + 'a>(pub Cow<'a, B>); -impl<'a, B: ?Sized> Borrow for WrappedCow<'a, B> +impl<'a, B: ?Sized + serde::Serialize + serde::Deserialize<'a>> Borrow for WrappedCow<'a, B> where B: ToOwned + Clone, ::Owned: 'a, @@ -23,20 +24,20 @@ where } } -impl Eq for WrappedCow<'_, B> where B: Eq + ToOwned {} +// impl Eq for WrappedCow<'_, B> where B: Eq + ToOwned {} -impl<'a, 'b, B: ?Sized, C: ?Sized> PartialEq> for WrappedCow<'a, B> -where - B: PartialEq + ToOwned + Clone, - C: ToOwned + Clone, -{ - #[inline] - fn eq(&self, other: &WrappedCow<'b, C>) -> bool { - self.0.eq(&other.0) - } -} +// impl<'a, 'b, B: ?Sized, C: ?Sized> PartialEq> for WrappedCow<'a, B> +// where +// B: PartialEq + ToOwned + Clone, +// C: ToOwned + Clone, +// { +// #[inline] +// fn eq(&self, other: &WrappedCow<'b, C>) -> bool { +// self.0.eq(&other.0) +// } +// } -impl Clone for WrappedCow<'_, B> { +impl<'a, B: ?Sized + ToOwned + Clone + serde::Serialize + serde::Deserialize<'a>> Clone for WrappedCow<'a, B> { /// Passthrough method. fn clone(&self) -> Self { WrappedCow(self.0.clone()) @@ -48,7 +49,7 @@ impl Clone for WrappedCow<'_, B> { } } -impl WrappedCow<'_, B> { +impl<'a, B: ?Sized + ToOwned + Clone + serde::Serialize + serde::Deserialize<'a>> WrappedCow<'a, B> { /// Passthrough method. pub fn to_mut(&mut self) -> &mut ::Owned { self.0.to_mut() @@ -60,7 +61,7 @@ impl WrappedCow<'_, B> { } } -impl Deref for WrappedCow<'_, B> { +impl<'a, B: ?Sized + ToOwned + Clone + serde::Serialize + serde::Deserialize<'a>> Deref for WrappedCow<'a, B> { type Target = B; /// Passthrough method. @@ -69,28 +70,28 @@ impl Deref for WrappedCow<'_, B> { } } -impl AsRef for WrappedCow<'_, B> { +impl<'a, B: ?Sized + ToOwned + Clone + serde::Serialize + serde::Deserialize<'a>> AsRef for WrappedCow<'a, B> { /// Passthrough method. fn as_ref(&self) -> &B { self.0.as_ref() } } -impl<'a, B: Clone> From> for WrappedCow<'a, [B]> { +impl<'a, B: Clone + serde::Serialize + serde::Deserialize<'a>> From> for WrappedCow<'a, [B]> { /// Newtype requirement. fn from(v: Vec) -> WrappedCow<'a, [B]> { WrappedCow(Cow::Owned(v)) } } -impl<'a, B: Clone> From<&'a Vec> for WrappedCow<'a, [B]> { +impl<'a, B: Clone + serde::Serialize + serde::Deserialize<'a>> From<&'a Vec> for WrappedCow<'a, [B]> { /// Newtype requirement. fn from(v: &'a Vec) -> WrappedCow<'a, [B]> { WrappedCow(Cow::Borrowed(v.as_slice())) } } -impl<'a, B> From<&'a [B]> for WrappedCow<'a, [B]> +impl<'a, B: serde::Serialize + serde::Deserialize<'a>> From<&'a [B]> for WrappedCow<'a, [B]> where [B]: ToOwned { From 27de7f36dd8105cd234a11d34597528c308e8344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 17 Dec 2021 12:20:11 +0200 Subject: [PATCH 111/129] More attempts --- Cargo.lock | 6 +-- lib/runtime-core/src/wrapped_cow.rs | 72 ++++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7e75a7e925f2..d3b5fe270036 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2250,13 +2250,13 @@ checksum = "c702914acda5feeeffbc29e4d953e5b9ce79d8b98da4dbf18a77086e116c5470" [[package]] name = "wasmparser" version = "0.51.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" +source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" [[package]] name = "wasmparser" version = "0.51.4" -source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" [[package]] name = "wast" diff --git a/lib/runtime-core/src/wrapped_cow.rs b/lib/runtime-core/src/wrapped_cow.rs index cb93b32637c4..5e037994d5be 100644 --- a/lib/runtime-core/src/wrapped_cow.rs +++ b/lib/runtime-core/src/wrapped_cow.rs @@ -6,15 +6,16 @@ use core::borrow::Borrow; use core::ops::Deref; use std::hash::Hash; use std::cmp::PartialEq; -use serde; +use serde::{Serialize, Deserialize}; +use crate::types; use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; /// A newtype that wraps borrow::Cow. -#[derive(PartialEq, Debug, Hash, Archive, RkyvSerialize, RkyvDeserialize, Serialize, Deserialize)] -pub struct WrappedCow<'a, B: ?Sized + ToOwned + serde::Serialize + serde::Deserialize<'a> + 'a>(pub Cow<'a, B>); +#[derive(PartialEq, Debug, Hash, Archive, RkyvSerialize, RkyvDeserialize)] +pub struct WrappedCow<'a, B: ?Sized + ToOwned + 'a>(pub Cow<'a, B>); -impl<'a, B: ?Sized + serde::Serialize + serde::Deserialize<'a>> Borrow for WrappedCow<'a, B> +impl<'a, B: ?Sized> Borrow for WrappedCow<'a, B> where B: ToOwned + Clone, ::Owned: 'a, @@ -24,6 +25,49 @@ where } } +impl <'a, B: ?Sized + Clone> serde::Serialize for WrappedCow<'a, B> { + #[inline] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + (**self).serialize(serializer) + } +} + +// impl<'de, 'a, B: ?Sized + ToOwned + serde::Serialize + serde::Deserialize<'de>> serde::Deserialize<'de> for WrappedCow<'a, B> +// where +// B: ToOwned, +// B::Owned: serde::Deserialize<'de>, +// 'a: 'de, +// { +// #[inline] +// fn deserialize(deserializer: D) -> Result +// where +// D: serde::Deserializer<'de>, +// { +// match B::Owned::deserialize(deserializer) { +// Ok(b) => WrappedCow(Cow::Owned(b)), +// Err(e) => Err(e) +// } +// } +// } + +impl serde::Deserialize<'static> for WrappedCow<'static, [types::Type]> +where +{ + #[inline] + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'static>, + { + match Vec::<[types::Type]>::deserialize(deserializer) { + Ok(b) => WrappedCow(Cow::Owned(b)), + Err(e) => Err(e) + } + } +} + // impl Eq for WrappedCow<'_, B> where B: Eq + ToOwned {} // impl<'a, 'b, B: ?Sized, C: ?Sized> PartialEq> for WrappedCow<'a, B> @@ -37,7 +81,7 @@ where // } // } -impl<'a, B: ?Sized + ToOwned + Clone + serde::Serialize + serde::Deserialize<'a>> Clone for WrappedCow<'a, B> { +impl<'a, B: ?Sized + ToOwned + Clone> Clone for WrappedCow<'a, B> { /// Passthrough method. fn clone(&self) -> Self { WrappedCow(self.0.clone()) @@ -49,7 +93,7 @@ impl<'a, B: ?Sized + ToOwned + Clone + serde::Serialize + serde::Deserialize<'a> } } -impl<'a, B: ?Sized + ToOwned + Clone + serde::Serialize + serde::Deserialize<'a>> WrappedCow<'a, B> { +impl<'a, B: ?Sized + ToOwned + Clone> WrappedCow<'a, B> { /// Passthrough method. pub fn to_mut(&mut self) -> &mut ::Owned { self.0.to_mut() @@ -61,7 +105,7 @@ impl<'a, B: ?Sized + ToOwned + Clone + serde::Serialize + serde::Deserialize<'a> } } -impl<'a, B: ?Sized + ToOwned + Clone + serde::Serialize + serde::Deserialize<'a>> Deref for WrappedCow<'a, B> { +impl<'a, B: ?Sized + ToOwned + Clone> Deref for WrappedCow<'a, B> { type Target = B; /// Passthrough method. @@ -70,28 +114,34 @@ impl<'a, B: ?Sized + ToOwned + Clone + serde::Serialize + serde::Deserialize<'a> } } -impl<'a, B: ?Sized + ToOwned + Clone + serde::Serialize + serde::Deserialize<'a>> AsRef for WrappedCow<'a, B> { +impl<'a, B: ?Sized + ToOwned + Clone> AsRef for WrappedCow<'a, B> { /// Passthrough method. fn as_ref(&self) -> &B { self.0.as_ref() } } -impl<'a, B: Clone + serde::Serialize + serde::Deserialize<'a>> From> for WrappedCow<'a, [B]> { +impl<'a, B: Clone> From> for WrappedCow<'a, [B]> +where + [B]: ToOwned +{ /// Newtype requirement. fn from(v: Vec) -> WrappedCow<'a, [B]> { WrappedCow(Cow::Owned(v)) } } -impl<'a, B: Clone + serde::Serialize + serde::Deserialize<'a>> From<&'a Vec> for WrappedCow<'a, [B]> { +impl<'a, B: Clone> From<&'a Vec> for WrappedCow<'a, [B]> +where + [B]: ToOwned +{ /// Newtype requirement. fn from(v: &'a Vec) -> WrappedCow<'a, [B]> { WrappedCow(Cow::Borrowed(v.as_slice())) } } -impl<'a, B: serde::Serialize + serde::Deserialize<'a>> From<&'a [B]> for WrappedCow<'a, [B]> +impl<'a, B> From<&'a [B]> for WrappedCow<'a, [B]> where [B]: ToOwned { From c430a2ecf3b8e1053e9a58c9378e6f5fed95359d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Mon, 20 Dec 2021 16:06:21 +0200 Subject: [PATCH 112/129] Remove WrappedCow and WrappedIndexMap --- lib/runtime-core/src/lib.rs | 2 - lib/runtime-core/src/types.rs | 19 +-- lib/runtime-core/src/wrapped_cow.rs | 152 ---------------------- lib/runtime-core/src/wrapped_index_map.rs | 132 ------------------- 4 files changed, 10 insertions(+), 295 deletions(-) delete mode 100644 lib/runtime-core/src/wrapped_cow.rs delete mode 100644 lib/runtime-core/src/wrapped_index_map.rs diff --git a/lib/runtime-core/src/lib.rs b/lib/runtime-core/src/lib.rs index 81e6eba6eb9f..15e7e0ed27e8 100644 --- a/lib/runtime-core/src/lib.rs +++ b/lib/runtime-core/src/lib.rs @@ -61,8 +61,6 @@ pub mod typed_func; pub mod types; pub mod units; pub mod vm; -pub mod wrapped_cow; -pub mod wrapped_index_map; #[doc(hidden)] pub mod vmcalls; #[cfg(all(unix, target_arch = "x86_64"))] diff --git a/lib/runtime-core/src/types.rs b/lib/runtime-core/src/types.rs index dcf3d4122a48..712806112cec 100644 --- a/lib/runtime-core/src/types.rs +++ b/lib/runtime-core/src/types.rs @@ -2,9 +2,8 @@ //! convert to other represenations. use crate::{memory::MemoryType, module::ModuleInfo, structures::TypedIndex, units::Pages}; -use std::convert::TryFrom; -use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; -use crate::wrapped_cow::WrappedCow; +use std::{borrow::Cow, convert::TryFrom}; +use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize, with::AsOwned}; /// Represents a WebAssembly type. #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash, Archive, RkyvSerialize, RkyvDeserialize)] @@ -357,16 +356,18 @@ impl MemoryDescriptor { /// in a wasm module or exposed to wasm by the host. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash, Archive, RkyvSerialize, RkyvDeserialize)] pub struct FuncSig { - params: WrappedCow<'static, [Type]>, - returns: WrappedCow<'static, [Type]>, + #[with(AsOwned)] + params: Cow<'static, [Type]>, + #[with(AsOwned)] + returns: Cow<'static, [Type]>, } impl FuncSig { /// Creates a new function signatures with the given parameter and return types. pub fn new(params: Params, returns: Returns) -> Self where - Params: Into>, - Returns: Into>, + Params: Into>, + Returns: Into>, { Self { params: params.into(), @@ -376,12 +377,12 @@ impl FuncSig { /// Parameter types. pub fn params(&self) -> &[Type] { - &self.params.0 + &self.params } /// Return types. pub fn returns(&self) -> &[Type] { - &self.returns.0 + &self.returns } /// Returns true if parameter types match the function signature. diff --git a/lib/runtime-core/src/wrapped_cow.rs b/lib/runtime-core/src/wrapped_cow.rs deleted file mode 100644 index 5e037994d5be..000000000000 --- a/lib/runtime-core/src/wrapped_cow.rs +++ /dev/null @@ -1,152 +0,0 @@ -//! Provides WrappedCow, a newtype built on std::borrow:Cow in order to implement -//! the rkyv::Archive trait. - -use std::borrow::Cow; -use core::borrow::Borrow; -use core::ops::Deref; -use std::hash::Hash; -use std::cmp::PartialEq; -use serde::{Serialize, Deserialize}; -use crate::types; - -use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; - -/// A newtype that wraps borrow::Cow. -#[derive(PartialEq, Debug, Hash, Archive, RkyvSerialize, RkyvDeserialize)] -pub struct WrappedCow<'a, B: ?Sized + ToOwned + 'a>(pub Cow<'a, B>); - -impl<'a, B: ?Sized> Borrow for WrappedCow<'a, B> -where - B: ToOwned + Clone, - ::Owned: 'a, -{ - fn borrow(&self) -> &B { - self.0.borrow() - } -} - -impl <'a, B: ?Sized + Clone> serde::Serialize for WrappedCow<'a, B> { - #[inline] - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - (**self).serialize(serializer) - } -} - -// impl<'de, 'a, B: ?Sized + ToOwned + serde::Serialize + serde::Deserialize<'de>> serde::Deserialize<'de> for WrappedCow<'a, B> -// where -// B: ToOwned, -// B::Owned: serde::Deserialize<'de>, -// 'a: 'de, -// { -// #[inline] -// fn deserialize(deserializer: D) -> Result -// where -// D: serde::Deserializer<'de>, -// { -// match B::Owned::deserialize(deserializer) { -// Ok(b) => WrappedCow(Cow::Owned(b)), -// Err(e) => Err(e) -// } -// } -// } - -impl serde::Deserialize<'static> for WrappedCow<'static, [types::Type]> -where -{ - #[inline] - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'static>, - { - match Vec::<[types::Type]>::deserialize(deserializer) { - Ok(b) => WrappedCow(Cow::Owned(b)), - Err(e) => Err(e) - } - } -} - -// impl Eq for WrappedCow<'_, B> where B: Eq + ToOwned {} - -// impl<'a, 'b, B: ?Sized, C: ?Sized> PartialEq> for WrappedCow<'a, B> -// where -// B: PartialEq + ToOwned + Clone, -// C: ToOwned + Clone, -// { -// #[inline] -// fn eq(&self, other: &WrappedCow<'b, C>) -> bool { -// self.0.eq(&other.0) -// } -// } - -impl<'a, B: ?Sized + ToOwned + Clone> Clone for WrappedCow<'a, B> { - /// Passthrough method. - fn clone(&self) -> Self { - WrappedCow(self.0.clone()) - } - - /// Passthrough method. - fn clone_from(&mut self, source: &Self) { - self.0.clone_from(&source.0); - } -} - -impl<'a, B: ?Sized + ToOwned + Clone> WrappedCow<'a, B> { - /// Passthrough method. - pub fn to_mut(&mut self) -> &mut ::Owned { - self.0.to_mut() - } - - /// Passthrough method. - pub fn into_owned(self) -> ::Owned { - self.0.into_owned() - } -} - -impl<'a, B: ?Sized + ToOwned + Clone> Deref for WrappedCow<'a, B> { - type Target = B; - - /// Passthrough method. - fn deref(&self) -> &B { - self.0.deref() - } -} - -impl<'a, B: ?Sized + ToOwned + Clone> AsRef for WrappedCow<'a, B> { - /// Passthrough method. - fn as_ref(&self) -> &B { - self.0.as_ref() - } -} - -impl<'a, B: Clone> From> for WrappedCow<'a, [B]> -where - [B]: ToOwned -{ - /// Newtype requirement. - fn from(v: Vec) -> WrappedCow<'a, [B]> { - WrappedCow(Cow::Owned(v)) - } -} - -impl<'a, B: Clone> From<&'a Vec> for WrappedCow<'a, [B]> -where - [B]: ToOwned -{ - /// Newtype requirement. - fn from(v: &'a Vec) -> WrappedCow<'a, [B]> { - WrappedCow(Cow::Borrowed(v.as_slice())) - } -} - -impl<'a, B> From<&'a [B]> for WrappedCow<'a, [B]> -where - [B]: ToOwned -{ - /// Newtype requirement - fn from(s: &'a [B]) -> WrappedCow<'a, [B]> { - WrappedCow(Cow::Borrowed(s)) - } -} diff --git a/lib/runtime-core/src/wrapped_index_map.rs b/lib/runtime-core/src/wrapped_index_map.rs deleted file mode 100644 index 558ca945fa44..000000000000 --- a/lib/runtime-core/src/wrapped_index_map.rs +++ /dev/null @@ -1,132 +0,0 @@ -//! Provides WrappedIndexMap, a newtype built on indexmap::IndexMap in order to implement -//! the rkyv::Archive trait. - -use ::core::hash::Hash; -use indexmap::{IndexMap, Equivalent}; -use indexmap::map::{Iter, Values}; -use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; -use ::core::fmt; -use serde::ser::{Serialize, Serializer}; -use serde::de::{ Deserialize, Deserializer}; -use ::core::ops::Index; - -/// A newtype that wraps indexmap::IndexMap. -#[derive(Archive, RkyvSerialize, RkyvDeserialize)] -pub struct WrappedIndexMap(IndexMap); - -impl WrappedIndexMap -where - K: Hash + Eq, -{ - /// Passthrough method. - pub fn new() -> Self { - WrappedIndexMap(IndexMap::new()) - } - - /// Passthrough method. - pub fn get(&self, key: &Q) -> Option<&V> - where - Q: Hash + Eq + Equivalent, - { - self.0.get(key) - } - - /// Passthrough method. - pub fn iter(&self) -> Iter<'_, K, V> { - self.0.iter() - } - - /// Passthrough method. - pub fn contains_key(&self, key: &Q) -> bool - where - Q: Hash + Eq + Equivalent, - { - self.0.contains_key(key) - } - - /// Passthrough method. - pub fn insert(&mut self, key: K, value: V) -> Option { - self.0.insert(key, value) - } - - /// Passthrough method. - pub fn values(&self) -> Values<'_, K, V> { - self.0.values() - } -} - -impl Clone for WrappedIndexMap -where - K: Clone, - V: Clone, -{ - /// Passthrough method. - fn clone(&self) -> Self { - WrappedIndexMap(self.0.clone()) - } - - /// Passthrough method. - fn clone_from(&mut self, other: &Self) { - self.0.clone_from(&other.0); - } -} - -impl fmt::Debug for WrappedIndexMap -where - K: fmt::Debug, - V: fmt::Debug, -{ - /// Passthrough method. - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.0.fmt(f) - } -} - -impl Serialize for WrappedIndexMap -where - K: Serialize + Hash + Eq, - V: Serialize, -{ - /// Passthrough method. - fn serialize(&self, serializer: T) -> Result - where - T: Serializer, - { - self.0.serialize(serializer) - } -} - -impl<'de, K, V> Deserialize<'de> for WrappedIndexMap -where - K: Deserialize<'de> + Eq + Hash, - V: Deserialize<'de>, -{ - /// Passthrough method. - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - serde::Deserialize::deserialize(deserializer) - } -} - -impl Index<&Q> for WrappedIndexMap -where - Q: Hash + Equivalent, - K: Hash + Eq, -{ - type Output = V; - - /// Passthrough method. - fn index(&self, key: &Q) -> &V { - self.0.index(key) - } -} - -impl Default for WrappedIndexMap -{ - /// Passthrough method. - fn default() -> Self { - WrappedIndexMap(IndexMap::default()) - } -} From c6e0e84484c522bfde95069c7b206123acff44c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 11 Jan 2022 20:50:29 +0200 Subject: [PATCH 113/129] Implement wrapper for serializing Memory --- .ycm_extra_conf.py | 10 ++- lib/runtime-core/src/cache.rs | 4 +- lib/runtime-core/src/sys/memory_rkyv.rs | 100 ++++++++++++++++++++++++ lib/runtime-core/src/sys/mod.rs | 4 + lib/runtime-core/src/sys/unix/memory.rs | 2 +- 5 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 lib/runtime-core/src/sys/memory_rkyv.rs diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py index 57a3cb275edf..60b5b509f975 100644 --- a/.ycm_extra_conf.py +++ b/.ycm_extra_conf.py @@ -1,5 +1,13 @@ def Settings(**kwargs): if kwargs['language'] == 'rust': return { - 'diagnostics_disabled': ['unresolved-proc-macro', 'inactive-code'] + 'ls': { + 'diagnostics': { + 'disabled': ['unresolved-proc-macro', 'inactive-code'] + }, + 'checkOnSave': { + 'enable': True, + 'extraArgs': ['--target-dir', 'target/check'] + }, + } } diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index fbce632d2a79..bf52d3d5bd9e 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -2,7 +2,7 @@ //! serializing compiled wasm code to a binary format. The binary format can be persisted, //! and loaded to allow skipping compilation and fast startup. -use crate::{module::ModuleInfo, sys::Memory}; +use crate::{module::ModuleInfo, sys::Memory, sys::ArchivableMemory}; use rkyv::{Archive, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize}; use std::{io, mem, slice}; @@ -159,6 +159,8 @@ pub struct ArtifactInner { info: Box, #[serde(with = "serde_bytes")] backend_metadata: Box<[u8]>, + + #[with(ArchivableMemory)] compiled_code: Memory, } diff --git a/lib/runtime-core/src/sys/memory_rkyv.rs b/lib/runtime-core/src/sys/memory_rkyv.rs new file mode 100644 index 000000000000..0343211ead6d --- /dev/null +++ b/lib/runtime-core/src/sys/memory_rkyv.rs @@ -0,0 +1,100 @@ +#[cfg(unix)] +use crate::sys::unix::{Memory, Protect}; + +#[cfg(windows)] +use crate::sys::windows::{Memory, Protect}; + +use rkyv::{ + Archive, + Fallible, + Serialize as RkyvSerialize, + Deserialize as RkyvDeserialize, + ser::{Serializer, ScratchSpace}, + with::{ArchiveWith, SerializeWith, DeserializeWith}, +}; + +/// A serializable wrapper for Memory. +pub struct ArchivableMemory; + +/// The archived contents of a wrapped Memory. +#[cfg(unix)] +#[derive(Debug, Archive, RkyvSerialize, RkyvDeserialize)] +pub struct ArchivedMemory { + contents: Vec, + protection: Protect, +} + +impl ArchivedMemory { + /// Construct an ArchivedMemory from a Memory. + pub unsafe fn from_memory(memory: &Memory) -> Self { + ArchivedMemory { + contents: memory.as_slice().to_vec(), + protection: memory.protection(), + } + } +} + +impl ArchiveWith for ArchivableMemory { + type Archived = ::Archived; + type Resolver = ::Resolver; + + unsafe fn resolve_with(memory: &Memory, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { + let archived_memory = ArchivedMemory::from_memory(memory); + archived_memory.resolve(pos, resolver, out); + } +} + +impl SerializeWith for ArchivableMemory +where + Memory: RkyvSerialize, + S: Serializer + ScratchSpace +{ + fn serialize_with(memory: &Memory, serializer: &mut S) -> Result { + unsafe { + let archived_memory = ArchivedMemory::from_memory(memory); + archived_memory.serialize(serializer) + } + } +} + +impl DeserializeWith for ArchivableMemory +where + ArchivedMemory: RkyvDeserialize, +{ + fn deserialize_with(archived_memory: &ArchivedMemory, _: &mut D) -> Result { + let original_protection = archived_memory.protection; + let bytes = archived_memory.contents.as_slice(); + + let mut memory = Memory::with_size_protect(bytes.len(), Protect::ReadWrite) + .expect("Could not create a memory"); + + unsafe { + memory.as_slice_mut().copy_from_slice(&*bytes); + + if memory.protection() != original_protection { + memory + .protect(.., original_protection) + .expect("Could not protect memory as its original protection"); + } + } + + Ok(memory) + } +} + +#[cfg(test)] +mod tests { + use crate::sys::unix::*; + + #[test] + fn test_new_memory() { + let bytes = b"abcdefghijkl"; + let mut memory = Memory::with_size_protect(1000, Protect::ReadWrite) + .expect("Could not create memory"); + + unsafe { + memory.as_slice_mut().copy_from_slice(&bytes[..]); + assert_eq!(memory.as_slice(), &bytes[..]); + } + } +} diff --git a/lib/runtime-core/src/sys/mod.rs b/lib/runtime-core/src/sys/mod.rs index 02b4fd25669b..19a041f5ee26 100644 --- a/lib/runtime-core/src/sys/mod.rs +++ b/lib/runtime-core/src/sys/mod.rs @@ -1,3 +1,5 @@ +mod memory_rkyv; + #[cfg(unix)] mod unix; @@ -10,6 +12,8 @@ pub use self::unix::*; #[cfg(windows)] pub use self::windows::*; +pub use self::memory_rkyv::*; + use serde::{ de::{self, SeqAccess, Visitor}, ser::SerializeStruct, diff --git a/lib/runtime-core/src/sys/unix/memory.rs b/lib/runtime-core/src/sys/unix/memory.rs index 26cc4ff8228e..c9c8a0d3f83c 100644 --- a/lib/runtime-core/src/sys/unix/memory.rs +++ b/lib/runtime-core/src/sys/unix/memory.rs @@ -12,7 +12,7 @@ unsafe impl Send for Memory {} unsafe impl Sync for Memory {} /// Data for a sized and protected region of memory. -#[derive(Debug, Archive, RkyvSerialize, RkyvDeserialize)] +#[derive(Debug)] pub struct Memory { ptr: *mut u8, size: usize, From 932622d316ff555895c7c80ec3c557d671ab7b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 14 Jan 2022 13:09:19 +0200 Subject: [PATCH 114/129] Attempt rkyv test for Artifact --- Cargo.lock | 1 + lib/runtime-c-api/Cargo.toml | 4 ++ lib/runtime-c-api/src/instance_cache.rs | 93 ++++++++++++++++++++---- lib/runtime-c-api/wasmer.h | 4 ++ lib/runtime-c-api/wasmer.hh | 4 ++ lib/runtime-core/src/cache.rs | 94 +++++++++++++++++++++++++ lib/runtime-core/src/sys/memory_rkyv.rs | 94 ++++++++++++++++++++----- lib/runtime-core/src/sys/unix/memory.rs | 3 + src/webassembly.rs | 1 - 9 files changed, 264 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3b5fe270036..6f501ea8fdea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2108,6 +2108,7 @@ version = "0.15.0" dependencies = [ "cbindgen", "libc", + "rkyv", "wasmer-clif-backend", "wasmer-emscripten", "wasmer-llvm-backend", diff --git a/lib/runtime-c-api/Cargo.toml b/lib/runtime-c-api/Cargo.toml index 4596912c69de..efce4f34e0aa 100644 --- a/lib/runtime-c-api/Cargo.toml +++ b/lib/runtime-c-api/Cargo.toml @@ -17,6 +17,10 @@ crate-type = ["cdylib", "rlib", "staticlib"] [dependencies] libc = "0.2.60" +[dependencies.rkyv] +version = "0.7.26" +features = ["indexmap"] + [dependencies.wasmer-runtime] default-features = false path = "../runtime" diff --git a/lib/runtime-c-api/src/instance_cache.rs b/lib/runtime-c-api/src/instance_cache.rs index 18952fc18174..0584fe731710 100644 --- a/lib/runtime-c-api/src/instance_cache.rs +++ b/lib/runtime-c-api/src/instance_cache.rs @@ -3,6 +3,13 @@ use crate::{ instance::{wasmer_instance_t, wasmer_compilation_options_t, CompilationOptions, prepare_middleware_chain_generator, get_compiler}, wasmer_result_t, }; + +use rkyv::{ + Deserialize as RkyvDeserialize, + ser::Serializer, + ser::serializers::AllocSerializer, +}; + use wasmer_runtime_core::{cache::Artifact, import::ImportObject}; use std::slice; use crate::import::GLOBAL_IMPORT_OBJECT; @@ -56,6 +63,43 @@ pub unsafe extern "C" fn wasmer_instance_cache( wasmer_result_t::WASMER_OK } +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_instance_cache_rkyv( + instance: *mut wasmer_instance_t, + cache_bytes: *mut *const u8, + cache_len: *mut u32, +) -> wasmer_result_t { + if instance.is_null() { + update_last_error(CApiError { + msg: "null instance".to_string(), + }); + return wasmer_result_t::WASMER_ERROR; + } + + let instance = &mut *(instance as *mut wasmer_runtime::Instance); + let module = instance.module(); + match module.cache() { + Err(error) => { + update_last_error(CApiError { + msg: format!("{:?}", error), + }); + return wasmer_result_t::WASMER_ERROR; + } + Ok(artifact) => { + let serialized = serialize_artifact_to_rkyv(artifact); + if !serialized.is_empty() { + let buf = serialized.into_boxed_slice(); + *cache_bytes = buf.as_ptr(); + *cache_len = buf.len() as u32; + std::mem::forget(buf); + } + } + }; + + wasmer_result_t::WASMER_OK +} + #[allow(clippy::cast_ptr_alignment)] #[no_mangle] pub unsafe extern "C" fn wasmer_instance_from_cache( @@ -75,22 +119,25 @@ pub unsafe extern "C" fn wasmer_instance_from_cache( let options: &CompilationOptions = &*(options as *const CompilationOptions); let compiler_chain_generator = prepare_middleware_chain_generator(&options); let compiler = get_compiler(compiler_chain_generator); - let new_module = match Artifact::deserialize(bytes) { - Ok(serialized_cache) => match wasmer_runtime_core::load_cache_with(serialized_cache, &compiler) { - Ok(deserialized_module) => { - deserialized_module - } - Err(_) => { - update_last_error(CApiError { - msg: "Failed to compile the serialized module".to_string(), - }); - return wasmer_result_t::WASMER_ERROR; - } - }, - Err(err) => { - println!("{:?}", err); + + let artifact = match Artifact::deserialize(bytes) { + Ok(deserialized_artifact) => deserialized_artifact, + Err(_) => { update_last_error(CApiError { - msg: "Failed to deserialize the module".to_string(), + msg: "Failed to compile the serialized module".to_string(), + }); + return wasmer_result_t::WASMER_ERROR; + } + }; + + + let new_module = match wasmer_runtime_core::load_cache_with(artifact, &compiler) { + Ok(deserialized_module) => { + deserialized_module + } + Err(_) => { + update_last_error(CApiError { + msg: "Failed to compile the serialized module".to_string(), }); return wasmer_result_t::WASMER_ERROR; } @@ -109,3 +156,19 @@ pub unsafe extern "C" fn wasmer_instance_from_cache( *instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t; wasmer_result_t::WASMER_OK } + +fn serialize_artifact_to_rkyv(artifact: Artifact) -> Vec { + let mut serializer = AllocSerializer::<4096>::default(); + serializer.serialize_value(&artifact).unwrap(); + let serialized = serializer.into_serializer().into_inner().to_vec(); + assert!(serialized.len() > 0); + + serialized +} + +fn deserialize_artifact_from_rkyv(bytes: &[u8]) -> Artifact { + let archived = unsafe { rkyv::archived_root::(&bytes[..]) }; + let artifact: Artifact = archived.deserialize(&mut rkyv::Infallible).unwrap().into_inner(); + artifact +} + diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 455dbaaa58aa..72fffc83c6cf 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -861,6 +861,10 @@ wasmer_result_t wasmer_instance_cache(wasmer_instance_t *instance, const uint8_t **cache_bytes, uint32_t *cache_len); +wasmer_result_t wasmer_instance_cache_rkyv(wasmer_instance_t *instance, + const uint8_t **cache_bytes, + uint32_t *cache_len); + /** * Calls an exported function of a WebAssembly instance by `name` * with the provided parameters. The exported function results are diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 888cb07b3a25..1f35663054f9 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -676,6 +676,10 @@ wasmer_result_t wasmer_instance_cache(wasmer_instance_t *instance, const uint8_t **cache_bytes, uint32_t *cache_len); +wasmer_result_t wasmer_instance_cache_rkyv(wasmer_instance_t *instance, + const uint8_t **cache_bytes, + uint32_t *cache_len); + /// Calls an exported function of a WebAssembly instance by `name` /// with the provided parameters. The exported function results are /// stored on the provided `results` pointer. diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index bf52d3d5bd9e..84791b216788 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -234,3 +234,97 @@ impl Artifact { /// A unique ID generated from the version of Wasmer for use with cache versioning pub const WASMER_VERSION_HASH: &'static str = include_str!(concat!(env!("OUT_DIR"), "/wasmer_version_hash.txt")); + +#[cfg(test)] +mod tests { + use super::*; + use std::collections::HashMap; + use crate::structures::Map; + use crate::module::StringTable; + use rkyv::ser::serializers::AllocSerializer; + use rkyv::ser::Serializer as RkyvSerializer; + use rkyv::with::With; + use crate::sys::{ArchivableMemory, CompactMemory}; + + #[test] + fn test_rkyv_artifact() { + let bytes = make_test_bytes(); + let memory = make_test_memory(&bytes); + + let module_info = make_empty_module_info(); + let artifact = Artifact::from_parts( + Box::new(module_info), + b"test_backend".to_vec().into_boxed_slice(), + memory, + ); + + let mut serializer = AllocSerializer::<4096>::default(); + serializer.serialize_value(&artifact).unwrap(); + let serialized = serializer.into_serializer().into_inner(); + assert!(serialized.len() > 0); + print!("{:?}", serialized); + + let archived: &::Archived + = unsafe { rkyv::archived_root::(&serialized[..]) }; + + let deser_result: Result + = archived.deserialize(&mut rkyv::Infallible); + + // let wrapped_artifact = deser_result.unwrap(); + // let deserialized_artifact: Artifact = wrapped_artifact.into_inner(); + // let deserialized_compiled_code = unsafe { deserialized_artifact.inner.compiled_code.as_slice() }; + // assert_eq!(deserialized_compiled_code, bytes); + } + + fn make_empty_module_info() -> ModuleInfo { + ModuleInfo { + memories: Map::new(), + globals: Map::new(), + tables: Map::new(), + + imported_functions: Map::new(), + imported_memories: Map::new(), + imported_tables: Map::new(), + imported_globals: Map::new(), + + exports: Default::default(), + + data_initializers: Vec::new(), + elem_initializers: Vec::new(), + + start_func: None, + + func_assoc: Map::new(), + signatures: Map::new(), + backend: "test".to_string(), + + namespace_table: StringTable::new(), + name_table: StringTable::new(), + + em_symbol_map: None, + + custom_sections: HashMap::new(), + + generate_debug_info: false, + #[cfg(feature = "generate-debug-information")] + debug_info_manager: crate::jit_debug::JitCodeDebugInfoManager::new(), + } + } + + fn make_test_memory(bytes: &Vec) -> Memory { + let mut memory = Memory::with_size_protect(1000, crate::sys::Protect::ReadWrite) + .expect("Could not create memory"); + unsafe { + memory.as_slice_mut().copy_from_slice(&bytes[..]); + } + memory + } + + fn make_test_bytes() -> Vec { + let page_size = page_size::get(); + let mut bytes = b"abcdefghijkl".to_vec(); + let padding_zeros = [0 as u8; 1].repeat(page_size - bytes.len()); + bytes.extend(padding_zeros); + bytes + } +} diff --git a/lib/runtime-core/src/sys/memory_rkyv.rs b/lib/runtime-core/src/sys/memory_rkyv.rs index 0343211ead6d..c23c0c568917 100644 --- a/lib/runtime-core/src/sys/memory_rkyv.rs +++ b/lib/runtime-core/src/sys/memory_rkyv.rs @@ -17,51 +17,68 @@ use rkyv::{ pub struct ArchivableMemory; /// The archived contents of a wrapped Memory. -#[cfg(unix)] -#[derive(Debug, Archive, RkyvSerialize, RkyvDeserialize)] -pub struct ArchivedMemory { +#[derive(Archive, RkyvSerialize, RkyvDeserialize, Debug, PartialEq)] +#[archive(compare(PartialEq))] +#[archive_attr(derive(Debug))] +#[archive_attr(derive(PartialEq))] +pub struct CompactMemory { contents: Vec, protection: Protect, } -impl ArchivedMemory { - /// Construct an ArchivedMemory from a Memory. +impl CompactMemory { + /// Construct a CompactMemory from a Memory. pub unsafe fn from_memory(memory: &Memory) -> Self { - ArchivedMemory { + CompactMemory { contents: memory.as_slice().to_vec(), protection: memory.protection(), } } + + /// Construct a Memory from a CompactMemory. + pub unsafe fn into_memory(&self) -> Memory { + let bytes = self.contents.as_slice(); + + let mut memory = Memory::with_size_protect(bytes.len(), Protect::ReadWrite) + .expect("Could not create a memory"); + + memory.as_slice_mut().copy_from_slice(&*bytes); + + if memory.protection() != self.protection { + memory + .protect(.., self.protection) + .expect("Could not protect memory as its original protection"); + } + + memory + } } impl ArchiveWith for ArchivableMemory { - type Archived = ::Archived; - type Resolver = ::Resolver; + type Archived = ::Archived; + type Resolver = ::Resolver; unsafe fn resolve_with(memory: &Memory, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) { - let archived_memory = ArchivedMemory::from_memory(memory); + let archived_memory = CompactMemory::from_memory(memory); archived_memory.resolve(pos, resolver, out); } } impl SerializeWith for ArchivableMemory where - Memory: RkyvSerialize, S: Serializer + ScratchSpace { fn serialize_with(memory: &Memory, serializer: &mut S) -> Result { unsafe { - let archived_memory = ArchivedMemory::from_memory(memory); + let archived_memory = CompactMemory::from_memory(memory); archived_memory.serialize(serializer) } } } -impl DeserializeWith for ArchivableMemory -where - ArchivedMemory: RkyvDeserialize, +impl DeserializeWith for ArchivableMemory { - fn deserialize_with(archived_memory: &ArchivedMemory, _: &mut D) -> Result { + fn deserialize_with(archived_memory: &CompactMemory, _: &mut D) -> Result { let original_protection = archived_memory.protection; let bytes = archived_memory.contents.as_slice(); @@ -84,17 +101,58 @@ where #[cfg(test)] mod tests { + use super::*; + use rkyv::ser::serializers::AllocSerializer; use crate::sys::unix::*; #[test] fn test_new_memory() { - let bytes = b"abcdefghijkl"; + let bytes = make_test_bytes(); + let memory = make_test_memory(&bytes); + unsafe { + assert_eq!(memory.as_slice(), bytes); + } + } + + #[test] + fn test_rkyv_memory() { + let bytes = make_test_bytes(); + let memory = make_test_memory(&bytes); + + let compact_memory = unsafe { CompactMemory::from_memory(&memory) }; + + let mut serializer = AllocSerializer::<4096>::default(); + serializer.serialize_value(&compact_memory).unwrap(); + let serialized = serializer.into_serializer().into_inner(); + assert!(serialized.len() > 0); + + let archived = unsafe { rkyv::archived_root::(&serialized[..]) }; + assert_eq!(archived, &compact_memory); + + let deserialized: CompactMemory = archived.deserialize(&mut rkyv::Infallible).unwrap(); + assert_eq!(deserialized, compact_memory); + + let deserialized_memory = unsafe { deserialized.into_memory() }; + assert_eq!(deserialized_memory.protection(), memory.protection()); + unsafe { + assert_eq!(deserialized_memory.as_slice(), memory.as_slice()); + }; + } + + fn make_test_memory(bytes: &Vec) -> Memory { let mut memory = Memory::with_size_protect(1000, Protect::ReadWrite) .expect("Could not create memory"); - unsafe { memory.as_slice_mut().copy_from_slice(&bytes[..]); - assert_eq!(memory.as_slice(), &bytes[..]); } + memory + } + + fn make_test_bytes() -> Vec { + let page_size = page_size::get(); + let mut bytes = b"abcdefghijkl".to_vec(); + let padding_zeros = [0 as u8; 1].repeat(page_size - bytes.len()); + bytes.extend(padding_zeros); + bytes } } diff --git a/lib/runtime-core/src/sys/unix/memory.rs b/lib/runtime-core/src/sys/unix/memory.rs index c9c8a0d3f83c..c515636cd54c 100644 --- a/lib/runtime-core/src/sys/unix/memory.rs +++ b/lib/runtime-core/src/sys/unix/memory.rs @@ -254,6 +254,9 @@ impl Clone for Memory { /// Kinds of memory protection. #[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Archive, RkyvSerialize, RkyvDeserialize)] #[allow(dead_code)] +#[archive(compare(PartialEq))] +#[archive_attr(derive(Debug))] +#[archive_attr(derive(PartialEq))] pub enum Protect { /// Read/write/exec allowed. None, diff --git a/src/webassembly.rs b/src/webassembly.rs index 0df8b59e8b18..0fd75b20ab41 100644 --- a/src/webassembly.rs +++ b/src/webassembly.rs @@ -1,4 +1,3 @@ -use std::panic; pub use wasmer_runtime::compile_with_config_with; use wasmer_runtime::{self as runtime, error::Result, ImportObject, Instance, Module}; From 8d46a26ca6816c89669c9a8efd0fdc0e04f6a65d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 19 Jan 2022 13:48:01 +0200 Subject: [PATCH 115/129] Update Cargo.lock --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f501ea8fdea..c96e7081d50b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2251,13 +2251,13 @@ checksum = "c702914acda5feeeffbc29e4d953e5b9ce79d8b98da4dbf18a77086e116c5470" [[package]] name = "wasmparser" version = "0.51.4" -source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" [[package]] name = "wasmparser" version = "0.51.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" +source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" [[package]] name = "wast" From f3a57c64267c1b4a267972310b1f0294a6d7c664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 25 Jan 2022 17:48:15 +0200 Subject: [PATCH 116/129] Extra test --- lib/runtime-core/src/cache.rs | 33 ++++++++++++++++++++++--- lib/runtime-core/src/sys/memory_rkyv.rs | 2 +- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index 84791b216788..da12d18b50aa 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -244,7 +244,8 @@ mod tests { use rkyv::ser::serializers::AllocSerializer; use rkyv::ser::Serializer as RkyvSerializer; use rkyv::with::With; - use crate::sys::{ArchivableMemory, CompactMemory}; + use rkyv::Archived; + // use crate::sys::{ArchivableMemory, CompactMemory}; #[test] fn test_rkyv_artifact() { @@ -264,11 +265,11 @@ mod tests { assert!(serialized.len() > 0); print!("{:?}", serialized); - let archived: &::Archived + let _: &::Archived = unsafe { rkyv::archived_root::(&serialized[..]) }; - let deser_result: Result - = archived.deserialize(&mut rkyv::Infallible); + // let deser_result: Result, std::convert::Infallible> + // = archived.deserialize(&mut rkyv::Infallible); // let wrapped_artifact = deser_result.unwrap(); // let deserialized_artifact: Artifact = wrapped_artifact.into_inner(); @@ -276,6 +277,30 @@ mod tests { // assert_eq!(deserialized_compiled_code, bytes); } + #[test] + fn test_rkyv_artifact_inner() { + let bytes = make_test_bytes(); + let memory = make_test_memory(&bytes); + + let module_info = make_empty_module_info(); + let artifact_inner = ArtifactInner { + info: Box::new(module_info), + backend_metadata: b"test_backend".to_vec().into_boxed_slice(), + compiled_code: memory, + }; + + let mut serializer = AllocSerializer::<4096>::default(); + serializer.serialize_value(&artifact_inner).unwrap(); + let serialized = serializer.into_serializer().into_inner(); + assert!(serialized.len() > 0); + print!("{:?}", serialized); + + let archived: &Archived + = unsafe { rkyv::archived_root::(&serialized[..]) }; + + let deser_result: ArtifactInner = archived.deserialize(&mut rkyv::Infallible).unwrap(); + } + fn make_empty_module_info() -> ModuleInfo { ModuleInfo { memories: Map::new(), diff --git a/lib/runtime-core/src/sys/memory_rkyv.rs b/lib/runtime-core/src/sys/memory_rkyv.rs index c23c0c568917..3b4f77f40505 100644 --- a/lib/runtime-core/src/sys/memory_rkyv.rs +++ b/lib/runtime-core/src/sys/memory_rkyv.rs @@ -115,7 +115,7 @@ mod tests { } #[test] - fn test_rkyv_memory() { + fn test_rkyv_compact_memory() { let bytes = make_test_bytes(); let memory = make_test_memory(&bytes); From 2beeb339b2ab7b7027a4e11caa6f2f307fcfcc7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 25 Jan 2022 18:49:31 +0200 Subject: [PATCH 117/129] Fix ArchivableMemory deserialization --- lib/runtime-core/src/cache.rs | 12 +++++++++--- lib/runtime-core/src/sys/memory_rkyv.rs | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index da12d18b50aa..8d9ec928beab 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -237,13 +237,17 @@ pub const WASMER_VERSION_HASH: &'static str = #[cfg(test)] mod tests { - use super::*; + use super::Artifact; + use super::ArtifactInner; + use super::Memory; + use super::ModuleInfo; use std::collections::HashMap; use crate::structures::Map; use crate::module::StringTable; use rkyv::ser::serializers::AllocSerializer; use rkyv::ser::Serializer as RkyvSerializer; - use rkyv::with::With; + use rkyv::Archive; + use rkyv::Deserialize; use rkyv::Archived; // use crate::sys::{ArchivableMemory, CompactMemory}; @@ -298,7 +302,9 @@ mod tests { let archived: &Archived = unsafe { rkyv::archived_root::(&serialized[..]) }; - let deser_result: ArtifactInner = archived.deserialize(&mut rkyv::Infallible).unwrap(); + let deserialized_artifact = Deserialize::::deserialize(archived, &mut rkyv::Infallible).unwrap(); + unsafe { assert_eq!(deserialized_artifact.compiled_code.as_slice(), artifact_inner.compiled_code.as_slice()) }; + assert_eq!(deserialized_artifact.compiled_code.protection(), artifact_inner.compiled_code.protection()); } fn make_empty_module_info() -> ModuleInfo { diff --git a/lib/runtime-core/src/sys/memory_rkyv.rs b/lib/runtime-core/src/sys/memory_rkyv.rs index 3b4f77f40505..b058442fd11a 100644 --- a/lib/runtime-core/src/sys/memory_rkyv.rs +++ b/lib/runtime-core/src/sys/memory_rkyv.rs @@ -76,10 +76,10 @@ where } } -impl DeserializeWith for ArchivableMemory +impl DeserializeWith for ArchivableMemory { - fn deserialize_with(archived_memory: &CompactMemory, _: &mut D) -> Result { - let original_protection = archived_memory.protection; + fn deserialize_with(archived_memory: &ArchivedCompactMemory, deserializer: &mut D) -> Result { + let original_protection = archived_memory.protection.deserialize(deserializer)?; let bytes = archived_memory.contents.as_slice(); let mut memory = Memory::with_size_protect(bytes.len(), Protect::ReadWrite) From 5994d9cc47ef7fda602e2d21d8912e18c832f9a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 26 Jan 2022 12:48:53 +0200 Subject: [PATCH 118/129] Minor type rewrite for DeserializeWith; clean tests --- Cargo.lock | 6 +++--- lib/runtime-core/src/cache.rs | 17 +++++++---------- lib/runtime-core/src/sys/memory_rkyv.rs | 5 +++-- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c96e7081d50b..6f501ea8fdea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2251,13 +2251,13 @@ checksum = "c702914acda5feeeffbc29e4d953e5b9ce79d8b98da4dbf18a77086e116c5470" [[package]] name = "wasmparser" version = "0.51.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" +source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" [[package]] name = "wasmparser" version = "0.51.4" -source = "git+https://github.com/ElrondNetwork/wasmparser.rs#f776d0ae8c349463b25d023ab6c8b1a80a761fd7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" [[package]] name = "wast" diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index 8d9ec928beab..e82d7ab6a343 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -246,10 +246,8 @@ mod tests { use crate::module::StringTable; use rkyv::ser::serializers::AllocSerializer; use rkyv::ser::Serializer as RkyvSerializer; - use rkyv::Archive; use rkyv::Deserialize; use rkyv::Archived; - // use crate::sys::{ArchivableMemory, CompactMemory}; #[test] fn test_rkyv_artifact() { @@ -269,14 +267,13 @@ mod tests { assert!(serialized.len() > 0); print!("{:?}", serialized); - let _: &::Archived + let archived: &Archived = unsafe { rkyv::archived_root::(&serialized[..]) }; - // let deser_result: Result, std::convert::Infallible> - // = archived.deserialize(&mut rkyv::Infallible); + let deserialized_artifact = Deserialize::::deserialize(archived, &mut rkyv::Infallible).unwrap(); + unsafe { assert_eq!(deserialized_artifact.inner.compiled_code.as_slice(), artifact.inner.compiled_code.as_slice()) }; + assert_eq!(deserialized_artifact.inner.compiled_code.protection(), artifact.inner.compiled_code.protection()); - // let wrapped_artifact = deser_result.unwrap(); - // let deserialized_artifact: Artifact = wrapped_artifact.into_inner(); // let deserialized_compiled_code = unsafe { deserialized_artifact.inner.compiled_code.as_slice() }; // assert_eq!(deserialized_compiled_code, bytes); } @@ -302,9 +299,9 @@ mod tests { let archived: &Archived = unsafe { rkyv::archived_root::(&serialized[..]) }; - let deserialized_artifact = Deserialize::::deserialize(archived, &mut rkyv::Infallible).unwrap(); - unsafe { assert_eq!(deserialized_artifact.compiled_code.as_slice(), artifact_inner.compiled_code.as_slice()) }; - assert_eq!(deserialized_artifact.compiled_code.protection(), artifact_inner.compiled_code.protection()); + let deserialized_artifact_inner = Deserialize::::deserialize(archived, &mut rkyv::Infallible).unwrap(); + unsafe { assert_eq!(deserialized_artifact_inner.compiled_code.as_slice(), artifact_inner.compiled_code.as_slice()) }; + assert_eq!(deserialized_artifact_inner.compiled_code.protection(), artifact_inner.compiled_code.protection()); } fn make_empty_module_info() -> ModuleInfo { diff --git a/lib/runtime-core/src/sys/memory_rkyv.rs b/lib/runtime-core/src/sys/memory_rkyv.rs index b058442fd11a..a10d5ee36abe 100644 --- a/lib/runtime-core/src/sys/memory_rkyv.rs +++ b/lib/runtime-core/src/sys/memory_rkyv.rs @@ -6,6 +6,7 @@ use crate::sys::windows::{Memory, Protect}; use rkyv::{ Archive, + Archived, Fallible, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize, @@ -76,9 +77,9 @@ where } } -impl DeserializeWith for ArchivableMemory +impl DeserializeWith, Memory, D> for ArchivableMemory { - fn deserialize_with(archived_memory: &ArchivedCompactMemory, deserializer: &mut D) -> Result { + fn deserialize_with(archived_memory: &Archived, deserializer: &mut D) -> Result { let original_protection = archived_memory.protection.deserialize(deserializer)?; let bytes = archived_memory.contents.as_slice(); From c1a2aac9ab19ea653ac2147c4090b4296851bff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 26 Jan 2022 13:01:38 +0200 Subject: [PATCH 119/129] Implement C API wasmer_instance_cache_rkyv() and wasmer_instance_from_cache_rkyv() --- lib/runtime-c-api/src/instance_cache.rs | 61 ++++++++++++++++++++++--- lib/runtime-c-api/wasmer.h | 5 ++ lib/runtime-c-api/wasmer.hh | 5 ++ lib/runtime-core/src/cache.rs | 3 -- 4 files changed, 64 insertions(+), 10 deletions(-) diff --git a/lib/runtime-c-api/src/instance_cache.rs b/lib/runtime-c-api/src/instance_cache.rs index 0584fe731710..a98a9a421814 100644 --- a/lib/runtime-c-api/src/instance_cache.rs +++ b/lib/runtime-c-api/src/instance_cache.rs @@ -89,10 +89,9 @@ pub unsafe extern "C" fn wasmer_instance_cache_rkyv( Ok(artifact) => { let serialized = serialize_artifact_to_rkyv(artifact); if !serialized.is_empty() { - let buf = serialized.into_boxed_slice(); - *cache_bytes = buf.as_ptr(); - *cache_len = buf.len() as u32; - std::mem::forget(buf); + *cache_bytes = serialized.as_ptr(); + *cache_len = serialized.len() as u32; + std::mem::forget(serialized); } } }; @@ -157,10 +156,58 @@ pub unsafe extern "C" fn wasmer_instance_from_cache( wasmer_result_t::WASMER_OK } -fn serialize_artifact_to_rkyv(artifact: Artifact) -> Vec { +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_instance_from_cache_rkyv( + instance: *mut *mut wasmer_instance_t, + cache_bytes: *mut u8, + cache_len: u32, + options: *const wasmer_compilation_options_t, +) -> wasmer_result_t { + if cache_bytes.is_null() { + update_last_error(CApiError { + msg: "cache bytes ptr is null".to_string(), + }); + return wasmer_result_t::WASMER_ERROR; + } + + let bytes: &[u8] = slice::from_raw_parts(cache_bytes, cache_len as usize); + let options: &CompilationOptions = &*(options as *const CompilationOptions); + let compiler_chain_generator = prepare_middleware_chain_generator(&options); + let compiler = get_compiler(compiler_chain_generator); + + let artifact = deserialize_artifact_from_rkyv(bytes); + + let new_module = match wasmer_runtime_core::load_cache_with(artifact, &compiler) { + Ok(deserialized_module) => { + deserialized_module + } + Err(_) => { + update_last_error(CApiError { + msg: "Failed to compile the serialized module".to_string(), + }); + return wasmer_result_t::WASMER_ERROR; + } + }; + + let import_object: &mut ImportObject = &mut *(GLOBAL_IMPORT_OBJECT as *mut ImportObject); + let result_instantiation = new_module.instantiate(&import_object); + let mut new_instance = match result_instantiation { + Ok(instance) => instance, + Err(error) => { + update_last_error(error); + return wasmer_result_t::WASMER_ERROR; + } + }; + metering::set_points_limit(&mut new_instance, options.gas_limit); + *instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t; + wasmer_result_t::WASMER_OK +} + +fn serialize_artifact_to_rkyv(artifact: Artifact) -> Box<[u8]> { let mut serializer = AllocSerializer::<4096>::default(); serializer.serialize_value(&artifact).unwrap(); - let serialized = serializer.into_serializer().into_inner().to_vec(); + let serialized = serializer.into_serializer().into_inner().into_boxed_slice(); assert!(serialized.len() > 0); serialized @@ -168,7 +215,7 @@ fn serialize_artifact_to_rkyv(artifact: Artifact) -> Vec { fn deserialize_artifact_from_rkyv(bytes: &[u8]) -> Artifact { let archived = unsafe { rkyv::archived_root::(&bytes[..]) }; - let artifact: Artifact = archived.deserialize(&mut rkyv::Infallible).unwrap().into_inner(); + let artifact: Artifact = RkyvDeserialize::::deserialize(archived, &mut rkyv::Infallible).unwrap(); artifact } diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index 72fffc83c6cf..fad305dd91e3 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -1083,6 +1083,11 @@ wasmer_result_t wasmer_instance_from_cache(wasmer_instance_t **instance, uint32_t cache_len, const wasmer_compilation_options_t *options); +wasmer_result_t wasmer_instance_from_cache_rkyv(wasmer_instance_t **instance, + uint8_t *cache_bytes, + uint32_t cache_len, + const wasmer_compilation_options_t *options); + uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); uint64_t wasmer_instance_get_runtime_breakpoint_value(wasmer_instance_t *instance); diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 1f35663054f9..adeb62ce209b 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -884,6 +884,11 @@ wasmer_result_t wasmer_instance_from_cache(wasmer_instance_t **instance, uint32_t cache_len, const wasmer_compilation_options_t *options); +wasmer_result_t wasmer_instance_from_cache_rkyv(wasmer_instance_t **instance, + uint8_t *cache_bytes, + uint32_t cache_len, + const wasmer_compilation_options_t *options); + uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); uint64_t wasmer_instance_get_runtime_breakpoint_value(wasmer_instance_t *instance); diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index e82d7ab6a343..a651f8b0747b 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -273,9 +273,6 @@ mod tests { let deserialized_artifact = Deserialize::::deserialize(archived, &mut rkyv::Infallible).unwrap(); unsafe { assert_eq!(deserialized_artifact.inner.compiled_code.as_slice(), artifact.inner.compiled_code.as_slice()) }; assert_eq!(deserialized_artifact.inner.compiled_code.protection(), artifact.inner.compiled_code.protection()); - - // let deserialized_compiled_code = unsafe { deserialized_artifact.inner.compiled_code.as_slice() }; - // assert_eq!(deserialized_compiled_code, bytes); } #[test] From a9dfb5b7eb117628ec50c1c09533d6fb612dc264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Fri, 28 Jan 2022 17:45:59 +0200 Subject: [PATCH 120/129] Add type MachineSubvalue to break recursivity of MachineValue --- Cargo.lock | 1 + lib/llvm-backend/src/stackmap.rs | 4 +- lib/runtime-core/src/state.rs | 81 +++++++++++++++-------- lib/singlepass-backend/Cargo.toml | 3 + lib/singlepass-backend/src/codegen_x64.rs | 11 ++- 5 files changed, 71 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f501ea8fdea..95225f5d180e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2170,6 +2170,7 @@ dependencies = [ "lazy_static", "libc", "nix", + "rkyv", "serde", "serde_derive", "smallvec 0.6.13", diff --git a/lib/llvm-backend/src/stackmap.rs b/lib/llvm-backend/src/stackmap.rs index d2f1eef89111..50b7fbd07ba0 100644 --- a/lib/llvm-backend/src/stackmap.rs +++ b/lib/llvm-backend/src/stackmap.rs @@ -253,8 +253,8 @@ impl StackmapEntry { machine_stack_layout.push(major.clone()); } else { machine_stack_layout.push(MachineValue::TwoHalves(Box::new(( - major.clone(), - minor.clone(), + major.clone().into(), + minor.clone().into(), )))); } } diff --git a/lib/runtime-core/src/state.rs b/lib/runtime-core/src/state.rs index 1dfcae8135e3..a3d9d95b4e60 100644 --- a/lib/runtime-core/src/state.rs +++ b/lib/runtime-core/src/state.rs @@ -7,8 +7,14 @@ use std::collections::BTreeMap; use std::ops::Bound::{Included, Unbounded}; use std::sync::Arc; +use rkyv::{ + Archive, + Serialize as RkyvSerialize, + Deserialize as RkyvDeserialize, +}; + /// An index to a register -#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] pub struct RegisterIndex(pub usize); /// A kind of wasm or constant value @@ -21,7 +27,7 @@ pub enum WasmAbstractValue { } /// A container for the state of a running wasm instance. -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] pub struct MachineState { /// Stack values. pub stack_values: Vec, @@ -64,7 +70,7 @@ pub struct MachineStateDiff { } /// A kind of machine value. -#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] +#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] pub enum MachineValue { /// Undefined. Undefined, @@ -83,11 +89,38 @@ pub enum MachineValue { /// Wasm Local. WasmLocal(usize), /// Two Halves. - TwoHalves(Box<(MachineValue, MachineValue)>), // 32-bit values. TODO: optimize: add another type for inner "half" value to avoid boxing? + TwoHalves(Box<(MachineSubvalue, MachineSubvalue)>), // 32-bit values. TODO: optimize: add another type for inner "half" value to avoid boxing? +} + +/// A kind of machine value used in MachineValue::TwoHalves. Created so that MachineValue does not +/// reference two more MachineValues as part of TwoHalves. +#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] +pub enum MachineSubvalue { + /// Undefined. + Undefined, + /// Vmctx Deref. + VmctxDeref(Vec), + /// Wasm Stack. + WasmStack(usize), + /// Wasm Local. + WasmLocal(usize), +} + +impl From for MachineSubvalue { + #[inline] + fn from(subvalue: MachineValue) -> MachineSubvalue { + match subvalue { + MachineValue::Undefined => MachineSubvalue::Undefined, + MachineValue::VmctxDeref(v) => MachineSubvalue::VmctxDeref(v), + MachineValue::WasmStack(i) => MachineSubvalue::WasmStack(i), + MachineValue::WasmLocal(i) => MachineSubvalue::WasmLocal(i), + _ => unimplemented!("invalid kind of MachineValue to convert to MachineSubvalue"), + } + } } /// A map of function states. -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] pub struct FunctionStateMap { /// Initial. pub initial: MachineState, @@ -134,7 +167,7 @@ pub struct OffsetInfo { } /// A map of module state. -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] pub struct ModuleStateMap { /// Local functions. pub local_functions: BTreeMap, @@ -753,7 +786,7 @@ pub mod x64 { stack_offset -= 1; // TODO: Cleanup match inner.0 { - MachineValue::WasmStack(x) => match state.wasm_stack[x] { + MachineSubvalue::WasmStack(x) => match state.wasm_stack[x] { WasmAbstractValue::Const(x) => { assert!(x <= std::u32::MAX as u64); stack[stack_offset] |= x; @@ -764,7 +797,7 @@ pub mod x64 { stack[stack_offset] |= v; } }, - MachineValue::WasmLocal(x) => match fsm.locals[x] { + MachineSubvalue::WasmLocal(x) => match fsm.locals[x] { WasmAbstractValue::Const(x) => { assert!(x <= std::u32::MAX as u64); stack[stack_offset] |= x; @@ -775,16 +808,15 @@ pub mod x64 { stack[stack_offset] |= v; } }, - MachineValue::VmctxDeref(ref seq) => { + MachineSubvalue::VmctxDeref(ref seq) => { stack[stack_offset] |= compute_vmctx_deref(vmctx as *const Ctx, seq) & (std::u32::MAX as u64); } - MachineValue::Undefined => {} - _ => unimplemented!("TwoHalves.0"), + MachineSubvalue::Undefined => {} } match inner.1 { - MachineValue::WasmStack(x) => match state.wasm_stack[x] { + MachineSubvalue::WasmStack(x) => match state.wasm_stack[x] { WasmAbstractValue::Const(x) => { assert!(x <= std::u32::MAX as u64); stack[stack_offset] |= x << 32; @@ -795,7 +827,7 @@ pub mod x64 { stack[stack_offset] |= v << 32; } }, - MachineValue::WasmLocal(x) => match fsm.locals[x] { + MachineSubvalue::WasmLocal(x) => match fsm.locals[x] { WasmAbstractValue::Const(x) => { assert!(x <= std::u32::MAX as u64); stack[stack_offset] |= x << 32; @@ -806,14 +838,13 @@ pub mod x64 { stack[stack_offset] |= v << 32; } }, - MachineValue::VmctxDeref(ref seq) => { + MachineSubvalue::VmctxDeref(ref seq) => { stack[stack_offset] |= (compute_vmctx_deref(vmctx as *const Ctx, seq) & (std::u32::MAX as u64)) << 32; } - MachineValue::Undefined => {} - _ => unimplemented!("TwoHalves.1"), + MachineSubvalue::Undefined => {} } } } @@ -1198,26 +1229,24 @@ pub mod x64 { let v = *stack; stack = stack.offset(1); match inner.0 { - MachineValue::WasmStack(idx) => { + MachineSubvalue::WasmStack(idx) => { wasm_stack[idx] = Some(v & 0xffffffffu64); } - MachineValue::WasmLocal(idx) => { + MachineSubvalue::WasmLocal(idx) => { wasm_locals[idx] = Some(v & 0xffffffffu64); } - MachineValue::VmctxDeref(_) => {} - MachineValue::Undefined => {} - _ => unimplemented!("TwoHalves.0 (read)"), + MachineSubvalue::VmctxDeref(_) => {} + MachineSubvalue::Undefined => {} } match inner.1 { - MachineValue::WasmStack(idx) => { + MachineSubvalue::WasmStack(idx) => { wasm_stack[idx] = Some(v >> 32); } - MachineValue::WasmLocal(idx) => { + MachineSubvalue::WasmLocal(idx) => { wasm_locals[idx] = Some(v >> 32); } - MachineValue::VmctxDeref(_) => {} - MachineValue::Undefined => {} - _ => unimplemented!("TwoHalves.1 (read)"), + MachineSubvalue::VmctxDeref(_) => {} + MachineSubvalue::Undefined => {} } } } diff --git a/lib/singlepass-backend/Cargo.toml b/lib/singlepass-backend/Cargo.toml index 0478b5ba7e53..dc5ee96aecb2 100644 --- a/lib/singlepass-backend/Cargo.toml +++ b/lib/singlepass-backend/Cargo.toml @@ -24,6 +24,9 @@ bincode = "1.2" serde = "1.0" serde_derive = "1.0" +[dependencies.rkyv] +version = "0.7.26" + [features] default = ["deterministic-execution"] deterministic-execution = ["wasmparser/deterministic", "wasmer-runtime-core/deterministic-execution"] diff --git a/lib/singlepass-backend/src/codegen_x64.rs b/lib/singlepass-backend/src/codegen_x64.rs index ec44ddb1efa3..6a58d3a12c64 100644 --- a/lib/singlepass-backend/src/codegen_x64.rs +++ b/lib/singlepass-backend/src/codegen_x64.rs @@ -20,6 +20,12 @@ use std::{ usize, }; +use rkyv::{ + Archive, + Serialize as RkyvSerialize, + Deserialize as RkyvDeserialize, +}; + use bincode; use wasmer_runtime_core::{ @@ -253,7 +259,10 @@ pub struct X64ExecutionContext { /// On-disk cache format. /// Offsets are relative to the start of the executable image. -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] +#[archive(compare(PartialEq))] +#[archive_attr(derive(Debug))] +#[archive_attr(derive(PartialEq))] pub struct CacheImage { /// The executable image. code: Vec, From 42275645643adaba425f671f4b2efa30b5df0453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Mon, 31 Jan 2022 20:02:57 +0200 Subject: [PATCH 121/129] Fixes for compilation --- lib/runtime-core/src/backend.rs | 10 ++++++++-- lib/runtime-core/src/state.rs | 10 +++++----- lib/singlepass-backend/src/codegen_x64.rs | 5 +---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/runtime-core/src/backend.rs b/lib/runtime-core/src/backend.rs index 4aca2d2a71c2..173c0ae36d01 100644 --- a/lib/runtime-core/src/backend.rs +++ b/lib/runtime-core/src/backend.rs @@ -18,6 +18,12 @@ use std::{any::Any, ptr::NonNull}; use std::collections::HashMap; +use rkyv::{ + Archive, + Serialize as RkyvSerialize, + Deserialize as RkyvDeserialize, +}; + pub mod sys { pub use crate::sys::*; } @@ -154,7 +160,7 @@ impl CompilerConfig { } /// An exception table for a `RunnableModule`. -#[derive(Clone, Debug, Default, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] pub struct ExceptionTable { /// Mappings from offsets in generated machine code to the corresponding exception code. pub offset_to_code: HashMap, @@ -167,7 +173,7 @@ impl ExceptionTable { } /// The code of an exception. -#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] pub enum ExceptionCode { /// An `unreachable` opcode was executed. Unreachable = 0, diff --git a/lib/runtime-core/src/state.rs b/lib/runtime-core/src/state.rs index a3d9d95b4e60..0041eb91983f 100644 --- a/lib/runtime-core/src/state.rs +++ b/lib/runtime-core/src/state.rs @@ -18,7 +18,7 @@ use rkyv::{ pub struct RegisterIndex(pub usize); /// A kind of wasm or constant value -#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] pub enum WasmAbstractValue { /// A wasm runtime value Runtime, @@ -44,7 +44,7 @@ pub struct MachineState { } /// A diff of two `MachineState`s. -#[derive(Clone, Debug, Default, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] pub struct MachineStateDiff { /// Last. pub last: Option, @@ -114,7 +114,7 @@ impl From for MachineSubvalue { MachineValue::VmctxDeref(v) => MachineSubvalue::VmctxDeref(v), MachineValue::WasmStack(i) => MachineSubvalue::WasmStack(i), MachineValue::WasmLocal(i) => MachineSubvalue::WasmLocal(i), - _ => unimplemented!("invalid kind of MachineValue to convert to MachineSubvalue"), + _ => unreachable!("invalid kind of MachineValue to convert to MachineSubvalue"), } } } @@ -145,7 +145,7 @@ pub struct FunctionStateMap { } /// A kind of suspend offset. -#[derive(Clone, Copy, Debug, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] pub enum SuspendOffset { /// A loop. Loop(usize), @@ -156,7 +156,7 @@ pub enum SuspendOffset { } /// Info for an offset. -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] pub struct OffsetInfo { /// End offset. pub end_offset: usize, // excluded bound diff --git a/lib/singlepass-backend/src/codegen_x64.rs b/lib/singlepass-backend/src/codegen_x64.rs index 6a58d3a12c64..b404c0f0bf74 100644 --- a/lib/singlepass-backend/src/codegen_x64.rs +++ b/lib/singlepass-backend/src/codegen_x64.rs @@ -259,10 +259,7 @@ pub struct X64ExecutionContext { /// On-disk cache format. /// Offsets are relative to the start of the executable image. -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] -#[archive(compare(PartialEq))] -#[archive_attr(derive(Debug))] -#[archive_attr(derive(PartialEq))] +#[derive(Clone, Debug, Serialize, Deserialize, Archive, RkyvSerialize, RkyvDeserialize)] pub struct CacheImage { /// The executable image. code: Vec, From 29addef588d80ca7630b6f8f89d55b0600c6d641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 9 Feb 2022 20:17:52 +0200 Subject: [PATCH 122/129] Ensure correct size of the serialized data --- lib/runtime-c-api/src/instance_cache.rs | 217 ++++++++++++---------- lib/runtime-c-api/wasmer.h | 13 +- lib/runtime-c-api/wasmer.hh | 13 +- lib/runtime-core/src/sys/memory_rkyv.rs | 22 +-- lib/runtime-core/src/sys/unix/memory.rs | 31 ++++ lib/singlepass-backend/src/codegen_x64.rs | 33 +++- lib/singlepass-backend/src/lib.rs | 2 + 7 files changed, 192 insertions(+), 139 deletions(-) diff --git a/lib/runtime-c-api/src/instance_cache.rs b/lib/runtime-c-api/src/instance_cache.rs index a98a9a421814..8d836e6c5966 100644 --- a/lib/runtime-c-api/src/instance_cache.rs +++ b/lib/runtime-c-api/src/instance_cache.rs @@ -10,13 +10,41 @@ use rkyv::{ ser::serializers::AllocSerializer, }; -use wasmer_runtime_core::{cache::Artifact, import::ImportObject}; +use wasmer_runtime_core::{ + cache::{Artifact, Error as CacheError}, + import::ImportObject, +}; use std::slice; use crate::import::GLOBAL_IMPORT_OBJECT; #[cfg(not(feature = "cranelift-backend"))] use wasmer_middleware_common::metering; +#[cfg(feature = "singlepass-backend")] +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_instance_enable_rkyv() { + wasmer_singlepass_backend::USE_RKYV_SERIALIZATION = true; +} + +#[cfg(feature = "singlepass-backend")] +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_instance_disable_rkyv() { + wasmer_singlepass_backend::USE_RKYV_SERIALIZATION = false; +} + +#[cfg(feature = "singlepass-backend")] +pub unsafe fn is_rkyv_enabled() -> bool { + wasmer_singlepass_backend::USE_RKYV_SERIALIZATION +} + +#[cfg(not(feature = "singlepass-backend"))] +pub unsafe fn is_rkyv_enabled() -> bool { + false +} + + #[allow(clippy::cast_ptr_alignment)] #[no_mangle] pub unsafe extern "C" fn wasmer_instance_cache( @@ -33,28 +61,26 @@ pub unsafe extern "C" fn wasmer_instance_cache( let instance = &mut *(instance as *mut wasmer_runtime::Instance); let module = instance.module(); + match module.cache() { Err(error) => { update_last_error(CApiError { - msg: format!("{:?}", error), + msg: format!("wasmer_instance_cache: artifact creation failed: {:?}", error), }); return wasmer_result_t::WASMER_ERROR; } Ok(artifact) => { - match artifact.serialize() { + match serialize_artifact(artifact) { Err(error) => { update_last_error(CApiError { - msg: format!("{:?}", error), + msg: format!("wasmer_instance_cache: artifact serialization failed: {:?}", error), }); return wasmer_result_t::WASMER_ERROR; } - Ok(bytes_vec) => { - if !bytes_vec.is_empty() { - let buf = bytes_vec.into_boxed_slice(); - *cache_bytes = buf.as_ptr(); - *cache_len = buf.len() as u32; - std::mem::forget(buf); - } + Ok(bytes) => { + *cache_bytes = bytes.as_ptr(); + *cache_len = bytes.len() as u32; + std::mem::forget(bytes); } } } @@ -63,42 +89,6 @@ pub unsafe extern "C" fn wasmer_instance_cache( wasmer_result_t::WASMER_OK } -#[allow(clippy::cast_ptr_alignment)] -#[no_mangle] -pub unsafe extern "C" fn wasmer_instance_cache_rkyv( - instance: *mut wasmer_instance_t, - cache_bytes: *mut *const u8, - cache_len: *mut u32, -) -> wasmer_result_t { - if instance.is_null() { - update_last_error(CApiError { - msg: "null instance".to_string(), - }); - return wasmer_result_t::WASMER_ERROR; - } - - let instance = &mut *(instance as *mut wasmer_runtime::Instance); - let module = instance.module(); - match module.cache() { - Err(error) => { - update_last_error(CApiError { - msg: format!("{:?}", error), - }); - return wasmer_result_t::WASMER_ERROR; - } - Ok(artifact) => { - let serialized = serialize_artifact_to_rkyv(artifact); - if !serialized.is_empty() { - *cache_bytes = serialized.as_ptr(); - *cache_len = serialized.len() as u32; - std::mem::forget(serialized); - } - } - }; - - wasmer_result_t::WASMER_OK -} - #[allow(clippy::cast_ptr_alignment)] #[no_mangle] pub unsafe extern "C" fn wasmer_instance_from_cache( @@ -119,24 +109,23 @@ pub unsafe extern "C" fn wasmer_instance_from_cache( let compiler_chain_generator = prepare_middleware_chain_generator(&options); let compiler = get_compiler(compiler_chain_generator); - let artifact = match Artifact::deserialize(bytes) { + let artifact = match deserialize_artifact(bytes) { Ok(deserialized_artifact) => deserialized_artifact, Err(_) => { update_last_error(CApiError { - msg: "Failed to compile the serialized module".to_string(), + msg: "wasmer_instance_from_cache: artifact deserialization failed".to_string(), }); return wasmer_result_t::WASMER_ERROR; } }; - let new_module = match wasmer_runtime_core::load_cache_with(artifact, &compiler) { Ok(deserialized_module) => { deserialized_module } Err(_) => { update_last_error(CApiError { - msg: "Failed to compile the serialized module".to_string(), + msg: "wasmer_instance_from_cache: artifact instantiation into module failed".to_string(), }); return wasmer_result_t::WASMER_ERROR; } @@ -156,66 +145,94 @@ pub unsafe extern "C" fn wasmer_instance_from_cache( wasmer_result_t::WASMER_OK } -#[allow(clippy::cast_ptr_alignment)] -#[no_mangle] -pub unsafe extern "C" fn wasmer_instance_from_cache_rkyv( - instance: *mut *mut wasmer_instance_t, - cache_bytes: *mut u8, - cache_len: u32, - options: *const wasmer_compilation_options_t, -) -> wasmer_result_t { - if cache_bytes.is_null() { - update_last_error(CApiError { - msg: "cache bytes ptr is null".to_string(), - }); - return wasmer_result_t::WASMER_ERROR; - } - - let bytes: &[u8] = slice::from_raw_parts(cache_bytes, cache_len as usize); - let options: &CompilationOptions = &*(options as *const CompilationOptions); - let compiler_chain_generator = prepare_middleware_chain_generator(&options); - let compiler = get_compiler(compiler_chain_generator); - - let artifact = deserialize_artifact_from_rkyv(bytes); - - let new_module = match wasmer_runtime_core::load_cache_with(artifact, &compiler) { - Ok(deserialized_module) => { - deserialized_module - } - Err(_) => { - update_last_error(CApiError { - msg: "Failed to compile the serialized module".to_string(), - }); - return wasmer_result_t::WASMER_ERROR; - } +#[cfg(feature = "singlepass-backend")] +fn serialize_artifact(artifact: Artifact) -> Result, CacheError> { + let serializer = match unsafe { is_rkyv_enabled() } { + true => serialize_artifact_with_rkyv, + false => serialize_artifact_with_serde, }; - let import_object: &mut ImportObject = &mut *(GLOBAL_IMPORT_OBJECT as *mut ImportObject); - let result_instantiation = new_module.instantiate(&import_object); - let mut new_instance = match result_instantiation { - Ok(instance) => instance, - Err(error) => { - update_last_error(error); - return wasmer_result_t::WASMER_ERROR; - } - }; - metering::set_points_limit(&mut new_instance, options.gas_limit); - *instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t; - wasmer_result_t::WASMER_OK + serializer(artifact).into() +} + +#[cfg(not(feature = "singlepass-backend"))] +fn serialize_artifact(artifact: Artifact) -> Result, CacheError> { + serialize_artifact_with_serde(artifact).into() } -fn serialize_artifact_to_rkyv(artifact: Artifact) -> Box<[u8]> { +#[cfg(feature = "singlepass-backend")] +fn serialize_artifact_with_rkyv(artifact: Artifact) -> Result, CacheError> { let mut serializer = AllocSerializer::<4096>::default(); serializer.serialize_value(&artifact).unwrap(); let serialized = serializer.into_serializer().into_inner().into_boxed_slice(); - assert!(serialized.len() > 0); + if serialized.is_empty() { + return Err(CacheError::SerializeError("rkyv serialization failed".to_string())); + } + + Ok(serialized) +} - serialized +fn serialize_artifact_with_serde(artifact: Artifact) -> Result, CacheError> { + match artifact.serialize() { + Ok(serialized) => Ok(serialized.into_boxed_slice()), + Err(error) => Err(error), + } +} + +#[cfg(feature = "singlepass-backend")] +fn deserialize_artifact(bytes: &[u8]) -> Result { + let deserializer = match unsafe { is_rkyv_enabled() } { + true => deserialize_artifact_with_rkyv, + false => deserialize_artifact_with_serde, + }; + + deserializer(bytes) +} + +#[cfg(not(feature = "singlepass-backend"))] +fn deserialize_artifact(bytes: &[u8]) -> Result { + deserialize_artifact_with_serde(bytes) } -fn deserialize_artifact_from_rkyv(bytes: &[u8]) -> Artifact { +#[cfg(feature = "singlepass-backend")] +fn deserialize_artifact_with_rkyv(bytes: &[u8]) -> Result { let archived = unsafe { rkyv::archived_root::(&bytes[..]) }; let artifact: Artifact = RkyvDeserialize::::deserialize(archived, &mut rkyv::Infallible).unwrap(); - artifact + Ok(artifact) } +fn deserialize_artifact_with_serde(bytes: &[u8]) -> Result { + Artifact::deserialize(bytes) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_simple_instantiation() { + let bytecode = get_wasm(); + + let options = CompilationOptions { + gas_limit: 1000, + unmetered_locals: 100, + max_memory_grow: 10, + max_memory_grow_delta: 10, + opcode_trace: false, + metering: true, + runtime_breakpoints: true + }; + + let compiler_chain_generator = unsafe { prepare_middleware_chain_generator(&options) }; + let compiler = unsafe { get_compiler(compiler_chain_generator) }; + let module = wasmer_runtime_core::compile_with(bytecode.as_slice(), &compiler).unwrap(); + let import_object = &mut ImportObject::new(); + let mut instance = module.instantiate(&import_object).unwrap(); + metering::set_points_limit(&mut instance, options.gas_limit); + } + + fn get_wasm() -> Vec { + let filename = "../../examples/erc20.wasm"; + std::fs::read(filename).expect("could not read bytecode from file") + } +} diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index fad305dd91e3..cccdcb148516 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -861,10 +861,6 @@ wasmer_result_t wasmer_instance_cache(wasmer_instance_t *instance, const uint8_t **cache_bytes, uint32_t *cache_len); -wasmer_result_t wasmer_instance_cache_rkyv(wasmer_instance_t *instance, - const uint8_t **cache_bytes, - uint32_t *cache_len); - /** * Calls an exported function of a WebAssembly instance by `name` * with the provided parameters. The exported function results are @@ -1033,6 +1029,10 @@ const wasmer_memory_t *wasmer_instance_context_memory(const wasmer_instance_cont */ void wasmer_instance_destroy(wasmer_instance_t *instance); +void wasmer_instance_disable_rkyv(void); + +void wasmer_instance_enable_rkyv(void); + /** * Gets all the exports of the given WebAssembly instance. * @@ -1083,11 +1083,6 @@ wasmer_result_t wasmer_instance_from_cache(wasmer_instance_t **instance, uint32_t cache_len, const wasmer_compilation_options_t *options); -wasmer_result_t wasmer_instance_from_cache_rkyv(wasmer_instance_t **instance, - uint8_t *cache_bytes, - uint32_t cache_len, - const wasmer_compilation_options_t *options); - uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); uint64_t wasmer_instance_get_runtime_breakpoint_value(wasmer_instance_t *instance); diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index adeb62ce209b..98426f852e71 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -676,10 +676,6 @@ wasmer_result_t wasmer_instance_cache(wasmer_instance_t *instance, const uint8_t **cache_bytes, uint32_t *cache_len); -wasmer_result_t wasmer_instance_cache_rkyv(wasmer_instance_t *instance, - const uint8_t **cache_bytes, - uint32_t *cache_len); - /// Calls an exported function of a WebAssembly instance by `name` /// with the provided parameters. The exported function results are /// stored on the provided `results` pointer. @@ -836,6 +832,10 @@ const wasmer_memory_t *wasmer_instance_context_memory(const wasmer_instance_cont /// ``` void wasmer_instance_destroy(wasmer_instance_t *instance); +void wasmer_instance_disable_rkyv(); + +void wasmer_instance_enable_rkyv(); + /// Gets all the exports of the given WebAssembly instance. /// /// This function stores a Rust vector of exports into `exports` as an @@ -884,11 +884,6 @@ wasmer_result_t wasmer_instance_from_cache(wasmer_instance_t **instance, uint32_t cache_len, const wasmer_compilation_options_t *options); -wasmer_result_t wasmer_instance_from_cache_rkyv(wasmer_instance_t **instance, - uint8_t *cache_bytes, - uint32_t cache_len, - const wasmer_compilation_options_t *options); - uint64_t wasmer_instance_get_points_used(wasmer_instance_t *instance); uint64_t wasmer_instance_get_runtime_breakpoint_value(wasmer_instance_t *instance); diff --git a/lib/runtime-core/src/sys/memory_rkyv.rs b/lib/runtime-core/src/sys/memory_rkyv.rs index a10d5ee36abe..b729447323bb 100644 --- a/lib/runtime-core/src/sys/memory_rkyv.rs +++ b/lib/runtime-core/src/sys/memory_rkyv.rs @@ -24,6 +24,7 @@ pub struct ArchivableMemory; #[archive_attr(derive(PartialEq))] pub struct CompactMemory { contents: Vec, + content_size: usize, protection: Protect, } @@ -32,6 +33,7 @@ impl CompactMemory { pub unsafe fn from_memory(memory: &Memory) -> Self { CompactMemory { contents: memory.as_slice().to_vec(), + content_size: memory.content_size(), protection: memory.protection(), } } @@ -51,6 +53,8 @@ impl CompactMemory { .expect("Could not protect memory as its original protection"); } + memory.set_content_size(self.content_size); + memory } } @@ -80,21 +84,8 @@ where impl DeserializeWith, Memory, D> for ArchivableMemory { fn deserialize_with(archived_memory: &Archived, deserializer: &mut D) -> Result { - let original_protection = archived_memory.protection.deserialize(deserializer)?; - let bytes = archived_memory.contents.as_slice(); - - let mut memory = Memory::with_size_protect(bytes.len(), Protect::ReadWrite) - .expect("Could not create a memory"); - - unsafe { - memory.as_slice_mut().copy_from_slice(&*bytes); - - if memory.protection() != original_protection { - memory - .protect(.., original_protection) - .expect("Could not protect memory as its original protection"); - } - } + let compact_memory: CompactMemory = archived_memory.deserialize(deserializer)?; + let memory = unsafe { compact_memory.into_memory() }; Ok(memory) } @@ -128,7 +119,6 @@ mod tests { assert!(serialized.len() > 0); let archived = unsafe { rkyv::archived_root::(&serialized[..]) }; - assert_eq!(archived, &compact_memory); let deserialized: CompactMemory = archived.deserialize(&mut rkyv::Infallible).unwrap(); assert_eq!(deserialized, compact_memory); diff --git a/lib/runtime-core/src/sys/unix/memory.rs b/lib/runtime-core/src/sys/unix/memory.rs index c515636cd54c..b3c121fadf79 100644 --- a/lib/runtime-core/src/sys/unix/memory.rs +++ b/lib/runtime-core/src/sys/unix/memory.rs @@ -18,6 +18,7 @@ pub struct Memory { size: usize, protection: Protect, fd: Option>, + content_size: usize, } impl Memory { @@ -54,6 +55,7 @@ impl Memory { size: file_len as usize, protection, fd: Some(Arc::new(raw_fd)), + content_size: 0, }) } } @@ -66,6 +68,7 @@ impl Memory { size: 0, protection, fd: None, + content_size: 0, }); } @@ -90,10 +93,19 @@ impl Memory { size, protection, fd: None, + content_size: 0, }) } } + /// Create a new memory with the given contents size and protection. + /// Used when the size of the contents must be tracked (e.g. for rkyv deserialization). + pub fn with_content_size_protect(content_size: usize, protection: Protect) -> Result { + let mut memory = Self::with_size_protect(content_size, protection)?; + memory.set_content_size(content_size); + Ok(memory) + } + /// Create a new memory with the given size. pub fn with_size(size: usize) -> Result { if size == 0 { @@ -102,6 +114,7 @@ impl Memory { size: 0, protection: Protect::None, fd: None, + content_size: 0, }); } @@ -129,6 +142,7 @@ impl Memory { size, protection: Protect::None, fd: None, + content_size: 0, }) } } @@ -173,6 +187,12 @@ impl Memory { } } + /// Set the content size of this memory. Must be set manually, as this is different in each + /// case. + pub fn set_content_size(&mut self, size: usize) { + self.content_size = size; + } + /// Split this memory into multiple memories by the given offset. pub fn split_at(mut self, offset: usize) -> (Memory, Memory) { let page_size = page_size::get(); @@ -187,6 +207,7 @@ impl Memory { size: second_size, protection: self.protection, fd: self.fd.clone(), + content_size: 0, }; (self, second) @@ -200,11 +221,21 @@ impl Memory { self.size } + /// Gets the size of the actual contents of this memory. + pub fn content_size(&self) -> usize { + self.content_size + } + /// Gets a slice for this memory. pub unsafe fn as_slice(&self) -> &[u8] { slice::from_raw_parts(self.ptr, self.size) } + /// Gets a slice for this memory, bounded by content_size. + pub unsafe fn as_slice_contents(&self) -> &[u8] { + slice::from_raw_parts(self.ptr, self.content_size) + } + /// Gets a mutable slice for this memory. pub unsafe fn as_slice_mut(&mut self) -> &mut [u8] { slice::from_raw_parts_mut(self.ptr, self.size) diff --git a/lib/singlepass-backend/src/codegen_x64.rs b/lib/singlepass-backend/src/codegen_x64.rs index b404c0f0bf74..196971d2206a 100644 --- a/lib/singlepass-backend/src/codegen_x64.rs +++ b/lib/singlepass-backend/src/codegen_x64.rs @@ -22,8 +22,11 @@ use std::{ use rkyv::{ Archive, + Archived, Serialize as RkyvSerialize, Deserialize as RkyvDeserialize, + ser::Serializer, + ser::serializers::AllocSerializer, }; use bincode; @@ -67,6 +70,8 @@ pub const INLINE_BREAKPOINT_SIZE_X86_SINGLEPASS: usize = 7; /// Inline breakpoint size for aarch64. pub const INLINE_BREAKPOINT_SIZE_AARCH64_SINGLEPASS: usize = 12; +pub static mut USE_RKYV_SERIALIZATION: bool = false; + static BACKEND_ID: &str = "singlepass"; #[cfg(target_arch = "x86_64")] @@ -306,7 +311,7 @@ pub struct SinglepassCache { impl CacheGen for SinglepassCache { fn generate_cache(&self) -> Result<(Box<[u8]>, Memory), CacheError> { - let mut memory = Memory::with_size_protect(self.buffer.len(), Protect::ReadWrite) + let mut memory = Memory::with_content_size_protect(self.buffer.len(), Protect::ReadWrite) .map_err(CacheError::SerializeError)?; let buffer = &*self.buffer; @@ -848,8 +853,19 @@ impl ModuleCodeGenerator exception_table: exception_table.clone(), }; - let cache = SinglepassCache { - buffer: Arc::from(bincode::serialize(&cache_image).unwrap().into_boxed_slice()), + let cache = if unsafe { USE_RKYV_SERIALIZATION } { + let mut serializer = AllocSerializer::<4096>::default(); + serializer.serialize_value(&cache_image).unwrap(); + let archived_cache_image = serializer.into_serializer().into_inner(); + + SinglepassCache { + buffer: Arc::from(archived_cache_image.as_slice()), + } + } else { + let serialized_cache_image = bincode::serialize(&cache_image).unwrap().into_boxed_slice(); + SinglepassCache { + buffer: Arc::from(serialized_cache_image), + } }; Ok(( @@ -940,8 +956,15 @@ impl ModuleCodeGenerator unsafe fn from_cache(artifact: Artifact, _: Token) -> Result { let (info, _, memory) = artifact.consume(); - let cache_image: CacheImage = bincode::deserialize(memory.as_slice()) - .map_err(|x| CacheError::DeserializeError(format!("{:?}", x)))?; + let cache_image: CacheImage = if USE_RKYV_SERIALIZATION { + let memory_contents = memory.as_slice_contents(); + let archived_cache_image: &Archived + = rkyv::archived_root::(memory_contents); + RkyvDeserialize::::deserialize(archived_cache_image, &mut rkyv::Infallible).unwrap() + } else { + bincode::deserialize(memory.as_slice()) + .map_err(|x| CacheError::DeserializeError(format!("{:?}", x)))? + }; let mut code_mem = CodeMemory::new(cache_image.code.len()); code_mem[0..cache_image.code.len()].copy_from_slice(&cache_image.code); diff --git a/lib/singlepass-backend/src/lib.rs b/lib/singlepass-backend/src/lib.rs index 0704cd8eba60..701c4c47e835 100644 --- a/lib/singlepass-backend/src/lib.rs +++ b/lib/singlepass-backend/src/lib.rs @@ -41,6 +41,8 @@ mod machine; #[cfg(target_arch = "aarch64")] mod translator_aarch64; +pub use codegen_x64::USE_RKYV_SERIALIZATION; + pub use codegen_x64::X64FunctionCode as FunctionCodeGenerator; pub use codegen_x64::X64ModuleCodeGenerator as ModuleCodeGenerator; From f8fb1df0e5289529fe0e47d4c43f90d92e7f931b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 9 Feb 2022 20:26:01 +0200 Subject: [PATCH 123/129] Update comment --- lib/runtime-core/src/sys/memory_rkyv.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime-core/src/sys/memory_rkyv.rs b/lib/runtime-core/src/sys/memory_rkyv.rs index b729447323bb..b9c5066696cd 100644 --- a/lib/runtime-core/src/sys/memory_rkyv.rs +++ b/lib/runtime-core/src/sys/memory_rkyv.rs @@ -17,7 +17,7 @@ use rkyv::{ /// A serializable wrapper for Memory. pub struct ArchivableMemory; -/// The archived contents of a wrapped Memory. +/// The archived contents of a Memory. #[derive(Archive, RkyvSerialize, RkyvDeserialize, Debug, PartialEq)] #[archive(compare(PartialEq))] #[archive_attr(derive(Debug))] From 037321df7149d037461c101a7f19be619c64f1e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 9 Feb 2022 20:34:36 +0200 Subject: [PATCH 124/129] Remove unneeded config file --- .gitignore | 1 + .ycm_extra_conf.py | 13 ------------- 2 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 .ycm_extra_conf.py diff --git a/.gitignore b/.gitignore index 3768a739734f..8861fc3b5949 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ capi/ api-docs/ api-docs-repo/ tags +.ycm* diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py deleted file mode 100644 index 60b5b509f975..000000000000 --- a/.ycm_extra_conf.py +++ /dev/null @@ -1,13 +0,0 @@ -def Settings(**kwargs): - if kwargs['language'] == 'rust': - return { - 'ls': { - 'diagnostics': { - 'disabled': ['unresolved-proc-macro', 'inactive-code'] - }, - 'checkOnSave': { - 'enable': True, - 'extraArgs': ['--target-dir', 'target/check'] - }, - } - } From e17fd73446b225647693826cf6b5e964a4e49ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 9 Feb 2022 20:36:12 +0200 Subject: [PATCH 125/129] Delete irrelevant test --- lib/runtime-c-api/src/instance_cache.rs | 32 ------------------------- 1 file changed, 32 deletions(-) diff --git a/lib/runtime-c-api/src/instance_cache.rs b/lib/runtime-c-api/src/instance_cache.rs index 8d836e6c5966..58f1e074dd59 100644 --- a/lib/runtime-c-api/src/instance_cache.rs +++ b/lib/runtime-c-api/src/instance_cache.rs @@ -204,35 +204,3 @@ fn deserialize_artifact_with_rkyv(bytes: &[u8]) -> Result fn deserialize_artifact_with_serde(bytes: &[u8]) -> Result { Artifact::deserialize(bytes) } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_simple_instantiation() { - let bytecode = get_wasm(); - - let options = CompilationOptions { - gas_limit: 1000, - unmetered_locals: 100, - max_memory_grow: 10, - max_memory_grow_delta: 10, - opcode_trace: false, - metering: true, - runtime_breakpoints: true - }; - - let compiler_chain_generator = unsafe { prepare_middleware_chain_generator(&options) }; - let compiler = unsafe { get_compiler(compiler_chain_generator) }; - let module = wasmer_runtime_core::compile_with(bytecode.as_slice(), &compiler).unwrap(); - let import_object = &mut ImportObject::new(); - let mut instance = module.instantiate(&import_object).unwrap(); - metering::set_points_limit(&mut instance, options.gas_limit); - } - - fn get_wasm() -> Vec { - let filename = "../../examples/erc20.wasm"; - std::fs::read(filename).expect("could not read bytecode from file") - } -} From 68f13582ba9185e6c8813ef134708991cbaff63a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 9 Feb 2022 21:03:05 +0200 Subject: [PATCH 126/129] Minor fixes --- lib/runtime-core/src/cache.rs | 9 --------- lib/runtime-core/src/lib.rs | 1 - lib/runtime-core/src/sys/memory_rkyv.rs | 2 +- lib/runtime-core/src/sys/unix/memory.rs | 12 ++++++------ lib/singlepass-backend/src/codegen_x64.rs | 4 +++- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/lib/runtime-core/src/cache.rs b/lib/runtime-core/src/cache.rs index a651f8b0747b..3f8820788341 100644 --- a/lib/runtime-core/src/cache.rs +++ b/lib/runtime-core/src/cache.rs @@ -306,30 +306,21 @@ mod tests { memories: Map::new(), globals: Map::new(), tables: Map::new(), - imported_functions: Map::new(), imported_memories: Map::new(), imported_tables: Map::new(), imported_globals: Map::new(), - exports: Default::default(), - data_initializers: Vec::new(), elem_initializers: Vec::new(), - start_func: None, - func_assoc: Map::new(), signatures: Map::new(), backend: "test".to_string(), - namespace_table: StringTable::new(), name_table: StringTable::new(), - em_symbol_map: None, - custom_sections: HashMap::new(), - generate_debug_info: false, #[cfg(feature = "generate-debug-information")] debug_info_manager: crate::jit_debug::JitCodeDebugInfoManager::new(), diff --git a/lib/runtime-core/src/lib.rs b/lib/runtime-core/src/lib.rs index 15e7e0ed27e8..daf63ef74193 100644 --- a/lib/runtime-core/src/lib.rs +++ b/lib/runtime-core/src/lib.rs @@ -25,7 +25,6 @@ #![cfg_attr(nightly, feature(unwind_attributes))] #![doc(html_favicon_url = "https://wasmer.io/static/icons/favicon.ico")] #![doc(html_logo_url = "https://avatars3.githubusercontent.com/u/44205449?s=200&v=4")] -#![feature(trivial_bounds)] #[macro_use] extern crate serde_derive; diff --git a/lib/runtime-core/src/sys/memory_rkyv.rs b/lib/runtime-core/src/sys/memory_rkyv.rs index b9c5066696cd..c7954eb77358 100644 --- a/lib/runtime-core/src/sys/memory_rkyv.rs +++ b/lib/runtime-core/src/sys/memory_rkyv.rs @@ -24,7 +24,7 @@ pub struct ArchivableMemory; #[archive_attr(derive(PartialEq))] pub struct CompactMemory { contents: Vec, - content_size: usize, + content_size: u32, protection: Protect, } diff --git a/lib/runtime-core/src/sys/unix/memory.rs b/lib/runtime-core/src/sys/unix/memory.rs index b3c121fadf79..8b56ac6b78eb 100644 --- a/lib/runtime-core/src/sys/unix/memory.rs +++ b/lib/runtime-core/src/sys/unix/memory.rs @@ -18,7 +18,7 @@ pub struct Memory { size: usize, protection: Protect, fd: Option>, - content_size: usize, + content_size: u32, } impl Memory { @@ -100,8 +100,8 @@ impl Memory { /// Create a new memory with the given contents size and protection. /// Used when the size of the contents must be tracked (e.g. for rkyv deserialization). - pub fn with_content_size_protect(content_size: usize, protection: Protect) -> Result { - let mut memory = Self::with_size_protect(content_size, protection)?; + pub fn with_content_size_protect(content_size: u32, protection: Protect) -> Result { + let mut memory = Self::with_size_protect(content_size as usize, protection)?; memory.set_content_size(content_size); Ok(memory) } @@ -189,7 +189,7 @@ impl Memory { /// Set the content size of this memory. Must be set manually, as this is different in each /// case. - pub fn set_content_size(&mut self, size: usize) { + pub fn set_content_size(&mut self, size: u32) { self.content_size = size; } @@ -222,7 +222,7 @@ impl Memory { } /// Gets the size of the actual contents of this memory. - pub fn content_size(&self) -> usize { + pub fn content_size(&self) -> u32 { self.content_size } @@ -233,7 +233,7 @@ impl Memory { /// Gets a slice for this memory, bounded by content_size. pub unsafe fn as_slice_contents(&self) -> &[u8] { - slice::from_raw_parts(self.ptr, self.content_size) + slice::from_raw_parts(self.ptr, self.content_size as usize) } /// Gets a mutable slice for this memory. diff --git a/lib/singlepass-backend/src/codegen_x64.rs b/lib/singlepass-backend/src/codegen_x64.rs index 196971d2206a..116e0deb0ee1 100644 --- a/lib/singlepass-backend/src/codegen_x64.rs +++ b/lib/singlepass-backend/src/codegen_x64.rs @@ -18,6 +18,7 @@ use std::{ slice, sync::{Arc, RwLock}, usize, + convert::TryInto, }; use rkyv::{ @@ -311,7 +312,8 @@ pub struct SinglepassCache { impl CacheGen for SinglepassCache { fn generate_cache(&self) -> Result<(Box<[u8]>, Memory), CacheError> { - let mut memory = Memory::with_content_size_protect(self.buffer.len(), Protect::ReadWrite) + let content_size: u32 = self.buffer.len().try_into().unwrap(); + let mut memory = Memory::with_content_size_protect(content_size, Protect::ReadWrite) .map_err(CacheError::SerializeError)?; let buffer = &*self.buffer; From 8e99e506dde3b413e678aea3b905b57a7fef528d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Mon, 21 Feb 2022 12:35:05 +0200 Subject: [PATCH 127/129] Create separate sighandler install function for dylib --- lib/runtime-core/src/fault.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/runtime-core/src/fault.rs b/lib/runtime-core/src/fault.rs index c1ab4cdf7008..609d2d4cb167 100644 --- a/lib/runtime-core/src/fault.rs +++ b/lib/runtime-core/src/fault.rs @@ -445,12 +445,13 @@ extern "C" fn sigint_handler( /// Ensure the signal handler is installed. pub fn ensure_sighandler() { INSTALL_SIGHANDLER.call_once(|| unsafe { - install_sighandler(); + install_sighandler_as_dylib(); }); } static INSTALL_SIGHANDLER: Once = Once::new(); +#[allow(dead_code)] unsafe fn install_sighandler() { let sa_trap = SigAction::new( SigHandler::SigAction(signal_trap_handler), @@ -471,6 +472,18 @@ unsafe fn install_sighandler() { sigaction(SIGINT, &sa_interrupt).unwrap(); } +unsafe fn install_sighandler_as_dylib() { + let sa_trap = SigAction::new( + SigHandler::SigAction(signal_trap_handler), + SaFlags::SA_ONSTACK, + SigSet::empty(), + ); + sigaction(SIGFPE, &sa_trap).unwrap(); + sigaction(SIGILL, &sa_trap).unwrap(); + sigaction(SIGBUS, &sa_trap).unwrap(); + sigaction(SIGTRAP, &sa_trap).unwrap(); +} + #[derive(Debug, Clone)] /// Info about the fault pub struct FaultInfo { From 46daf7dee19dc3d033cdc1dce956fd09560ffafb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Tue, 22 Feb 2022 17:04:03 +0200 Subject: [PATCH 128/129] Change OpcodeControl to set BREAKPOINT_VALUE_MEMORY_LIMIT for memory.grow faults --- lib/middleware-common/src/opcode_control.rs | 9 ++++++--- lib/middleware-common/src/runtime_breakpoints.rs | 5 +---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/middleware-common/src/opcode_control.rs b/lib/middleware-common/src/opcode_control.rs index b97051b542d6..8c85aec1a535 100644 --- a/lib/middleware-common/src/opcode_control.rs +++ b/lib/middleware-common/src/opcode_control.rs @@ -5,7 +5,10 @@ use wasmer_runtime_core::{ module::ModuleInfo, }; -use crate::runtime_breakpoints::{push_runtime_breakpoint, BREAKPOINT_VALUE_EXECUTION_FAILED}; +use crate::runtime_breakpoints::{ + push_runtime_breakpoint, + BREAKPOINT_VALUE_MEMORY_LIMIT, +}; static FIELD_MEMORY_GROW_COUNT: InternalField = InternalField::allocate(); @@ -35,7 +38,7 @@ impl OpcodeControl { sink.push(Event::WasmOwned(Operator::If { ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), })); - push_runtime_breakpoint(sink, BREAKPOINT_VALUE_EXECUTION_FAILED); + push_runtime_breakpoint(sink, BREAKPOINT_VALUE_MEMORY_LIMIT); sink.push(Event::WasmOwned(Operator::End)); } @@ -63,7 +66,7 @@ impl OpcodeControl { sink.push(Event::WasmOwned(Operator::If { ty: WpTypeOrFuncType::Type(WpType::EmptyBlockType), })); - push_runtime_breakpoint(sink, BREAKPOINT_VALUE_EXECUTION_FAILED); + push_runtime_breakpoint(sink, BREAKPOINT_VALUE_MEMORY_LIMIT); sink.push(Event::WasmOwned(Operator::End)); } } diff --git a/lib/middleware-common/src/runtime_breakpoints.rs b/lib/middleware-common/src/runtime_breakpoints.rs index 6d0252b61efb..773d91594477 100644 --- a/lib/middleware-common/src/runtime_breakpoints.rs +++ b/lib/middleware-common/src/runtime_breakpoints.rs @@ -11,10 +11,7 @@ pub static FIELD_RUNTIME_BREAKPOINT_VALUE: InternalField = InternalField::alloca pub const BREAKPOINT_VALUE_NO_BREAKPOINT: u64 = 0; pub const BREAKPOINT_VALUE_EXECUTION_FAILED: u64 = 1; pub const BREAKPOINT_VALUE_OUT_OF_GAS: u64 = 4; - - -#[derive(Copy, Clone, Debug)] -pub struct RuntimeBreakpointReachedError; +pub const BREAKPOINT_VALUE_MEMORY_LIMIT: u64 = 5; pub struct RuntimeBreakpointHandler {} From 82d260d36859caea3648b75916b6431b07666f5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camil=20B=C4=83ncioiu?= Date: Wed, 9 Mar 2022 16:28:34 +0200 Subject: [PATCH 129/129] Create AtomicBool which controls SIGSEGV handler registration --- lib/runtime-c-api/src/lib.rs | 2 +- lib/runtime-c-api/src/signals.rs | 8 ++++++++ lib/runtime-c-api/wasmer.h | 2 ++ lib/runtime-c-api/wasmer.hh | 2 ++ lib/runtime-core/src/fault.rs | 9 +++++++++ 5 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 lib/runtime-c-api/src/signals.rs diff --git a/lib/runtime-c-api/src/lib.rs b/lib/runtime-c-api/src/lib.rs index 50410b7795f8..62690d66cbfd 100644 --- a/lib/runtime-c-api/src/lib.rs +++ b/lib/runtime-c-api/src/lib.rs @@ -104,8 +104,8 @@ pub mod memory; pub mod metering; pub mod instance_cache; - pub mod runtime_breakpoints; +pub mod signals; pub mod module; pub mod table; diff --git a/lib/runtime-c-api/src/signals.rs b/lib/runtime-c-api/src/signals.rs new file mode 100644 index 000000000000..9feba9f9dcde --- /dev/null +++ b/lib/runtime-c-api/src/signals.rs @@ -0,0 +1,8 @@ +use wasmer_runtime_core::fault::SIGSEGV_PASSTHROUGH; +use std::sync::atomic::Ordering; + +#[allow(clippy::cast_ptr_alignment)] +#[no_mangle] +pub unsafe extern "C" fn wasmer_set_sigsegv_passthrough() { + SIGSEGV_PASSTHROUGH.swap(true, Ordering::SeqCst); +} diff --git a/lib/runtime-c-api/wasmer.h b/lib/runtime-c-api/wasmer.h index cccdcb148516..cbcf4b60ce77 100644 --- a/lib/runtime-c-api/wasmer.h +++ b/lib/runtime-c-api/wasmer.h @@ -1409,6 +1409,8 @@ wasmer_result_t wasmer_serialized_module_from_bytes(wasmer_serialized_module_t * void wasmer_set_opcode_costs(const uint32_t *opcode_costs_pointer); +void wasmer_set_sigsegv_passthrough(void); + /** * Frees memory for the given Table */ diff --git a/lib/runtime-c-api/wasmer.hh b/lib/runtime-c-api/wasmer.hh index 98426f852e71..22725ec7dd7d 100644 --- a/lib/runtime-c-api/wasmer.hh +++ b/lib/runtime-c-api/wasmer.hh @@ -1174,6 +1174,8 @@ wasmer_result_t wasmer_serialized_module_from_bytes(wasmer_serialized_module_t * void wasmer_set_opcode_costs(const uint32_t *opcode_costs_pointer); +void wasmer_set_sigsegv_passthrough(); + /// Frees memory for the given Table void wasmer_table_destroy(wasmer_table_t *table); diff --git a/lib/runtime-core/src/fault.rs b/lib/runtime-core/src/fault.rs index 609d2d4cb167..5bfd6e7b63cb 100644 --- a/lib/runtime-core/src/fault.rs +++ b/lib/runtime-core/src/fault.rs @@ -118,8 +118,12 @@ lazy_static! { InterruptSignalMem(ptr as _) }; } + static INTERRUPT_SIGNAL_DELIVERED: AtomicBool = AtomicBool::new(false); +/// Controls whether SIGSEGV is handled by Wasmer or not. +pub static SIGSEGV_PASSTHROUGH: AtomicBool = AtomicBool::new(false); + /// Returns a boolean indicating if SIGINT triggered the fault. pub fn was_sigint_triggered_fault() -> bool { WAS_SIGINT_TRIGGERED.with(|x| x.get()) @@ -482,6 +486,11 @@ unsafe fn install_sighandler_as_dylib() { sigaction(SIGILL, &sa_trap).unwrap(); sigaction(SIGBUS, &sa_trap).unwrap(); sigaction(SIGTRAP, &sa_trap).unwrap(); + + let capture_sigsegv = !SIGSEGV_PASSTHROUGH.load(Ordering::SeqCst); + if capture_sigsegv { + sigaction(SIGSEGV, &sa_trap).unwrap(); + } } #[derive(Debug, Clone)]