Compare commits
7 Commits
Author | SHA1 | Date |
---|---|---|
Cadey Ratio | 0b6dd64219 | |
adam-rhebo | d2ea44e37c | |
Sergei Pepyakin | f19e1c27fc | |
Sergei Pepyakin | 59ab1c8d78 | |
Sergei Pepyakin | e6bdaf76f6 | |
Pierre Krieger | 390f4b2c4a | |
Sergei Pepyakin | 08c09adbf2 |
12
.travis.yml
12
.travis.yml
|
@ -40,7 +40,17 @@ after_success: |
|
||||||
ghp-import -n target/doc &&
|
ghp-import -n target/doc &&
|
||||||
git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
|
git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
|
||||||
|
|
||||||
cache: cargo
|
cache:
|
||||||
|
# Don't use `cache: cargo` since it adds the `target` directory and that can be huge.
|
||||||
|
# Saving and loading this directory dwarfes actual compilation and test times. But what is more
|
||||||
|
# important, is that travis timeouts the build since the job doesn't produce any output for more
|
||||||
|
# than 10 minutes.
|
||||||
|
#
|
||||||
|
# So we just cache ~/.cargo directory
|
||||||
|
directories:
|
||||||
|
- /home/travis/.cargo
|
||||||
before_cache:
|
before_cache:
|
||||||
# Travis can't cache files that are not readable by "others"
|
# Travis can't cache files that are not readable by "others"
|
||||||
- chmod -R a+r $HOME/.cargo
|
- chmod -R a+r $HOME/.cargo
|
||||||
|
# According to the Travis CI docs for building Rust project this is done by,
|
||||||
|
- rm -rf /home/travis/.cargo/registry
|
||||||
|
|
10
Cargo.toml
10
Cargo.toml
|
@ -11,18 +11,17 @@ keywords = ["wasm", "webassembly", "bytecode", "interpreter"]
|
||||||
exclude = [ "/res/*", "/tests/*", "/fuzz/*", "/benches/*" ]
|
exclude = [ "/res/*", "/tests/*", "/fuzz/*", "/benches/*" ]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmi-validation = { version = "0.1", path = "validation", default-features = false }
|
wasmi-validation = { version = "0.2", path = "validation", default-features = false }
|
||||||
parity-wasm = { version = "0.40.1", default-features = false }
|
parity-wasm = { version = "0.40.1", default-features = false }
|
||||||
memory_units = "0.3.0"
|
memory_units = "0.3.0"
|
||||||
libm = { version = "0.1.2", optional = true }
|
libm = { version = "0.1.2", optional = true }
|
||||||
num-rational = "0.2.2"
|
num-rational = { version = "0.2.2", default-features = false }
|
||||||
num-traits = "0.2.8"
|
num-traits = { version = "0.2.8", default-features = false }
|
||||||
libc = "0.2.58"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_matches = "1.1"
|
assert_matches = "1.1"
|
||||||
rand = "0.4.2"
|
rand = "0.4.2"
|
||||||
wabt = "0.6"
|
wabt = "0.9"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
|
@ -31,6 +30,7 @@ std = [
|
||||||
"parity-wasm/std",
|
"parity-wasm/std",
|
||||||
"wasmi-validation/std",
|
"wasmi-validation/std",
|
||||||
"num-rational/std",
|
"num-rational/std",
|
||||||
|
"num-rational/bigint-std",
|
||||||
"num-traits/std"
|
"num-traits/std"
|
||||||
]
|
]
|
||||||
# Enable for no_std support
|
# Enable for no_std support
|
||||||
|
|
|
@ -6,7 +6,7 @@ authors = ["Sergey Pepyakin <s.pepyakin@gmail.com>"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmi = { path = ".." }
|
wasmi = { path = ".." }
|
||||||
assert_matches = "1.2"
|
assert_matches = "1.2"
|
||||||
wabt = "0.6"
|
wabt = "0.9"
|
||||||
|
|
||||||
[profile.bench]
|
[profile.bench]
|
||||||
debug = true
|
debug = true
|
||||||
|
|
|
@ -33,7 +33,7 @@ pub extern "C" fn prepare_tiny_keccak() -> *const TinyKeccakTestData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn bench_tiny_keccak(test_data: *const TinyKeccakTestData) {
|
pub extern "C" fn bench_tiny_keccak(test_data: *mut TinyKeccakTestData) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut keccak = Keccak::new_keccak256();
|
let mut keccak = Keccak::new_keccak256();
|
||||||
keccak.update((*test_data).data);
|
keccak.update((*test_data).data);
|
||||||
|
|
|
@ -10,7 +10,7 @@ cargo-fuzz = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
wasmi = { path = ".." }
|
wasmi = { path = ".." }
|
||||||
wabt = "0.6.0"
|
wabt = "0.9"
|
||||||
wasmparser = "0.14.1"
|
wasmparser = "0.14.1"
|
||||||
tempdir = "0.3.6"
|
tempdir = "0.3.6"
|
||||||
|
|
||||||
|
|
|
@ -7,4 +7,4 @@ authors = ["Sergey Pepyakin <s.pepyakin@gmail.com>"]
|
||||||
honggfuzz = "=0.5.9" # Strict equal since hfuzz requires dep and cmd versions to match.
|
honggfuzz = "=0.5.9" # Strict equal since hfuzz requires dep and cmd versions to match.
|
||||||
wasmi = { path = ".." }
|
wasmi = { path = ".." }
|
||||||
tempdir = "0.3.6"
|
tempdir = "0.3.6"
|
||||||
wabt = "0.6.0"
|
wabt = "0.9"
|
||||||
|
|
10
src/func.rs
10
src/func.rs
|
@ -1,4 +1,5 @@
|
||||||
use alloc::{
|
use alloc::{
|
||||||
|
borrow::Cow,
|
||||||
rc::{Rc, Weak},
|
rc::{Rc, Weak},
|
||||||
vec::Vec,
|
vec::Vec,
|
||||||
};
|
};
|
||||||
|
@ -195,12 +196,13 @@ impl FuncInstance {
|
||||||
/// [`resume_execution`]: struct.FuncInvocation.html#method.resume_execution
|
/// [`resume_execution`]: struct.FuncInvocation.html#method.resume_execution
|
||||||
pub fn invoke_resumable<'args>(
|
pub fn invoke_resumable<'args>(
|
||||||
func: &FuncRef,
|
func: &FuncRef,
|
||||||
args: &'args [RuntimeValue],
|
args: impl Into<Cow<'args, [RuntimeValue]>>,
|
||||||
) -> Result<FuncInvocation<'args>, Trap> {
|
) -> Result<FuncInvocation<'args>, Trap> {
|
||||||
|
let args = args.into();
|
||||||
check_function_args(func.signature(), &args)?;
|
check_function_args(func.signature(), &args)?;
|
||||||
match *func.as_internal() {
|
match *func.as_internal() {
|
||||||
FuncInstanceInternal::Internal { .. } => {
|
FuncInstanceInternal::Internal { .. } => {
|
||||||
let interpreter = Interpreter::new(func, args, None)?;
|
let interpreter = Interpreter::new(func, &*args, None)?;
|
||||||
Ok(FuncInvocation {
|
Ok(FuncInvocation {
|
||||||
kind: FuncInvocationKind::Internal(interpreter),
|
kind: FuncInvocationKind::Internal(interpreter),
|
||||||
})
|
})
|
||||||
|
@ -257,7 +259,7 @@ pub struct FuncInvocation<'args> {
|
||||||
enum FuncInvocationKind<'args> {
|
enum FuncInvocationKind<'args> {
|
||||||
Internal(Interpreter),
|
Internal(Interpreter),
|
||||||
Host {
|
Host {
|
||||||
args: &'args [RuntimeValue],
|
args: Cow<'args, [RuntimeValue]>,
|
||||||
host_func_index: usize,
|
host_func_index: usize,
|
||||||
finished: bool,
|
finished: bool,
|
||||||
},
|
},
|
||||||
|
@ -304,7 +306,7 @@ impl<'args> FuncInvocation<'args> {
|
||||||
return Err(ResumableError::AlreadyStarted);
|
return Err(ResumableError::AlreadyStarted);
|
||||||
}
|
}
|
||||||
*finished = true;
|
*finished = true;
|
||||||
Ok(externals.invoke_index(*host_func_index, args.clone().into())?)
|
Ok(externals.invoke_index(*host_func_index, args.as_ref().into())?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
use libm::{F32Ext, F64Ext};
|
||||||
|
|
||||||
use core::cmp::{Ordering, PartialEq, PartialOrd};
|
use core::cmp::{Ordering, PartialEq, PartialOrd};
|
||||||
use core::ops::{Add, Div, Mul, Neg, Rem, Sub};
|
use core::ops::{Add, Div, Mul, Neg, Rem, Sub};
|
||||||
|
|
||||||
|
|
|
@ -1289,14 +1289,8 @@ impl FunctionContext {
|
||||||
debug_assert!(!self.is_initialized);
|
debug_assert!(!self.is_initialized);
|
||||||
|
|
||||||
let num_locals = locals.iter().map(|l| l.count() as usize).sum();
|
let num_locals = locals.iter().map(|l| l.count() as usize).sum();
|
||||||
let locals = vec![Default::default(); num_locals];
|
|
||||||
|
|
||||||
// TODO: Replace with extend.
|
value_stack.extend(num_locals)?;
|
||||||
for local in locals {
|
|
||||||
value_stack
|
|
||||||
.push(local)
|
|
||||||
.map_err(|_| TrapKind::StackOverflow)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.is_initialized = true;
|
self.is_initialized = true;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1442,6 +1436,18 @@ impl ValueStack {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn extend(&mut self, len: usize) -> Result<(), TrapKind> {
|
||||||
|
let cells = self
|
||||||
|
.buf
|
||||||
|
.get_mut(self.sp..self.sp + len)
|
||||||
|
.ok_or_else(|| TrapKind::StackOverflow)?;
|
||||||
|
for cell in cells {
|
||||||
|
*cell = Default::default();
|
||||||
|
}
|
||||||
|
self.sp += len;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn len(&self) -> usize {
|
fn len(&self) -> usize {
|
||||||
self.sp
|
self.sp
|
||||||
|
|
|
@ -285,7 +285,7 @@ fn resume_call_host_func() {
|
||||||
let export = instance.export_by_name("test").unwrap();
|
let export = instance.export_by_name("test").unwrap();
|
||||||
let func_instance = export.as_func().unwrap();
|
let func_instance = export.as_func().unwrap();
|
||||||
|
|
||||||
let mut invocation = FuncInstance::invoke_resumable(&func_instance, &[]).unwrap();
|
let mut invocation = FuncInstance::invoke_resumable(&func_instance, &[][..]).unwrap();
|
||||||
let result = invocation.start_execution(&mut env);
|
let result = invocation.start_execution(&mut env);
|
||||||
match result {
|
match result {
|
||||||
Err(ResumableError::Trap(_)) => {}
|
Err(ResumableError::Trap(_)) => {}
|
||||||
|
@ -330,7 +330,7 @@ fn resume_call_host_func_type_mismatch() {
|
||||||
let export = instance.export_by_name("test").unwrap();
|
let export = instance.export_by_name("test").unwrap();
|
||||||
let func_instance = export.as_func().unwrap();
|
let func_instance = export.as_func().unwrap();
|
||||||
|
|
||||||
let mut invocation = FuncInstance::invoke_resumable(&func_instance, &[]).unwrap();
|
let mut invocation = FuncInstance::invoke_resumable(&func_instance, &[][..]).unwrap();
|
||||||
let result = invocation.start_execution(&mut env);
|
let result = invocation.start_execution(&mut env);
|
||||||
match result {
|
match result {
|
||||||
Err(ResumableError::Trap(_)) => {}
|
Err(ResumableError::Trap(_)) => {}
|
||||||
|
|
27
src/value.rs
27
src/value.rs
|
@ -368,6 +368,7 @@ impl WrapInto<F32> for F64 {
|
||||||
macro_rules! impl_try_truncate_into {
|
macro_rules! impl_try_truncate_into {
|
||||||
(@primitive $from: ident, $into: ident, $to_primitive:path) => {
|
(@primitive $from: ident, $into: ident, $to_primitive:path) => {
|
||||||
impl TryTruncateInto<$into, TrapKind> for $from {
|
impl TryTruncateInto<$into, TrapKind> for $from {
|
||||||
|
#[cfg(feature = "std")]
|
||||||
fn try_truncate_into(self) -> Result<$into, TrapKind> {
|
fn try_truncate_into(self) -> Result<$into, TrapKind> {
|
||||||
// Casting from a float to an integer will round the float towards zero
|
// Casting from a float to an integer will round the float towards zero
|
||||||
num_rational::BigRational::from_float(self)
|
num_rational::BigRational::from_float(self)
|
||||||
|
@ -375,6 +376,23 @@ macro_rules! impl_try_truncate_into {
|
||||||
.and_then(|val| $to_primitive(&val))
|
.and_then(|val| $to_primitive(&val))
|
||||||
.ok_or(TrapKind::InvalidConversionToInt)
|
.ok_or(TrapKind::InvalidConversionToInt)
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
fn try_truncate_into(self) -> Result<$into, TrapKind> {
|
||||||
|
// Casting from a float to an integer will round the float towards zero
|
||||||
|
// NOTE: currently this will cause Undefined Behavior if the rounded value cannot be represented by the
|
||||||
|
// target integer type. This includes Inf and NaN. This is a bug and will be fixed.
|
||||||
|
if self.is_nan() || self.is_infinite() {
|
||||||
|
return Err(TrapKind::InvalidConversionToInt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// range check
|
||||||
|
let result = self as $into;
|
||||||
|
if result as $from != self.trunc() {
|
||||||
|
return Err(TrapKind::InvalidConversionToInt);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(self as $into)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(@wrapped $from:ident, $intermediate:ident, $into:ident) => {
|
(@wrapped $from:ident, $intermediate:ident, $into:ident) => {
|
||||||
|
@ -819,15 +837,6 @@ impl_integer!(u32);
|
||||||
impl_integer!(i64);
|
impl_integer!(i64);
|
||||||
impl_integer!(u64);
|
impl_integer!(u64);
|
||||||
|
|
||||||
// Use std float functions in std environment.
|
|
||||||
// And libm's implementation in no_std
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
macro_rules! call_math {
|
|
||||||
($op:ident, $e:expr, $fXX:ident, $FXXExt:ident) => {
|
|
||||||
$fXX::$op($e)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#[cfg(not(feature = "std"))]
|
|
||||||
macro_rules! call_math {
|
macro_rules! call_math {
|
||||||
($op:ident, $e:expr, $fXX:ident, $FXXExt:ident) => {
|
($op:ident, $e:expr, $fXX:ident, $FXXExt:ident) => {
|
||||||
::libm::$FXXExt::$op($e)
|
::libm::$FXXExt::$op($e)
|
||||||
|
|
|
@ -18,6 +18,7 @@ fn spec_to_runtime_value(val: Value<u32, u64>) -> RuntimeValue {
|
||||||
Value::I64(v) => RuntimeValue::I64(v),
|
Value::I64(v) => RuntimeValue::I64(v),
|
||||||
Value::F32(v) => RuntimeValue::F32(v.into()),
|
Value::F32(v) => RuntimeValue::F32(v.into()),
|
||||||
Value::F64(v) => RuntimeValue::F64(v.into()),
|
Value::F64(v) => RuntimeValue::F64(v.into()),
|
||||||
|
Value::V128(_) => panic!("v128 is not supported"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "wasmi-validation"
|
name = "wasmi-validation"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
authors = ["Parity Technologies <admin@parity.io>"]
|
authors = ["Parity Technologies <admin@parity.io>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
|
|
Loading…
Reference in New Issue