Commit Graph

44 Commits

Author SHA1 Message Date
adam-rhebo 7fe6ef4e35 Add ARMv7 as CI test target (#186)
* Add ARMv7 as CI test target

* Avoid UB in conversions from floating point

When truncating floating point values to integer values, we need to
avoid undefined behavior if the argument does not fit into the target
type which is currently impossible using casts of primitive types.

Hence, this reimplements those conversions using arbitrary precision
integers and rationals from the num crate.
2019-06-18 15:06:16 +02:00
adam-rhebo 8dac328ea7 Remove hashbrown and use BTree{Map,Set} from the alloc crate (#187)
* Remove hashbrown and use BTree{Map,Set} from the alloc crate

wasmi-validation must handle untrusted input and hence we switch from
Hash{Set,Map} (whether std's or hashbrown's) to BTree{Set,Map} to avoid
algorithmic complexity attacks while retaining no_std support.

Closes #183

* Improve memory locality of checking for duplicate exports

Using a sorted slice gives us the same O(N log N) worst case execution
time as using a BTreeMap, but using a single allocation as with HashMap,
so that we should see better memory locality and hence better constant
factors when checking for duplicate exports.
2019-06-12 11:30:10 +02:00
adam-rhebo 284c907b29 Recycle value stacks to avoid allocation costs (#184) 2019-06-12 10:51:04 +02:00
Sergei Pepyakin a3aad8a549
Extract validation into a separate crate (#176)
* Add some docs.

* return_type isn't failable

* Add comment about safety of top_label

* Attempt number 10

* Rework.

Now we will a compiler which wraps and uses info from a evaluation simulator.

* Get rid of outcome

* Introduce StartedWith

* Actually use started_with.

* Mirror label_stack.

* Avoid using frame_type.

* Finally get rid from frame_type.

* Extract compilation

* Refactoring cleaning

* Validation separated from compilation.

* Move sink to FunctionReader

* Rename to compiler.

* fmt

* Move push_label under validation context.

* Add Validation traits

* Express the compiler using validation trait

* Move code under prepare

* Comments.

* WIP

* The great move of validation

* Make validation compile

* Make it compile.

* Format it.

* Fix warnings.

* Clean.

* Make it work under no_std

* Move deny_floating_point to wasmi

* Rename validate_module2 → validate_module

* Make validation tests work

* Make wasmi compilation tests work

* Renamings.

* Get rid of memory_units dependency in validation

* Rename.

* Clean.

* Estimate capacity.

* fmt.

* Clean and detail End opcode.

* Add comment about top_label safety

* Remove another TODO

* Comment access to require_target

* Remove redundant PartialEq

* Print value that can't be coerced to u32

* s/with_instruction_capacity/with_capacity

* fmt.

* fmt

* Proofs

* Add better proof

* Get rid of unreachable in StackValueType

* Propagate error if frame stack overflown on create

* use checked sub instead of -

* Keep::count
2019-04-19 16:05:09 +02:00
Elichai Turkel e88d5d32e5 Removed Byteorder now that rust supports it natively (#171)
* Removed byteorder now that from_le_bytes is stabilized

* Rust fmt
2019-02-26 11:37:14 +01:00
Elichai Turkel 23b054c0e5 Replaced hashmap_core with hashbrown (#161) 2019-01-20 17:59:26 +01:00
Jef 899cc32e45 rustfmt (#151) 2018-12-11 12:54:06 +01:00
Jef c7f9196df6 Export LittleEndianConvert (#148) 2018-11-28 14:01:51 +01:00
Eric Findlay 7b4c648acb Minor edits to documentation. (#140) 2018-11-09 15:39:40 +01:00
Julius Rakow 20154c5e24 Add no_std support (#122)
* add default-enabled std feature

* use parity-wasm/std feature only if std is enabled

* drop dependency on std::io

* use hashmap_core instead of std::collections::HashMap

* disable std::error in no_std

* core and alloc all the things

* mention no_std in readme

* add no_std feature and use hashmap_core only on no_std

* rename the no_std feature to core

* drop dependency on byteorder/std

* simplify float impl macro

* remove some trailing whitespace

* use libm for float math in no_std

* add note about no_std panics of libm to readme

* Embed nan-preserving-float crate.

* Add no_std check to the Travis CI config

* add missing dev-dependency
2018-10-29 11:16:55 +01:00
Tobias Bucher 167e4845ef Proofread the library-level docs (#123)
* Proofread the library-level docs

* Fix extra word, remove mention of linear memory "space"
2018-08-27 11:10:45 +03:00
Guanqun Lu 43b8d52bca typo fixes in lib.rs (#113) 2018-07-30 15:16:17 +03:00
Wei Tang a605175abe Resumable function invocation (#110)
* Move call_stack to Interpreter struct

* Accept func and args when creating the Interpreter

* Create a RunState to indicate whether the current interpreter is recoverable

* Add functionality to resume execution in Interpreter level

* Implement resumable execution in func

* Expose FuncInvocation and ResumableError

* Fix missing docs for FuncInvocation

* Add test for resumable invoke and move external parameter passing to start/resume_invocation

* Add comments why assert is always true

* Add note why value stack is always empty after execution

* Use as_func

* Document `resume_execution` on conditions for `is_resumable` and `resumable_value_type`

* Document conditions where NotResumable and AlreadyStarted error is returned

* Warn user that invoke_resumable is experimental
2018-07-09 19:06:44 +03:00
Sergey Pepyakin dc5052aadb
Export nan_preserving_float (#109) 2018-07-04 12:13:57 +03:00
Sergey Pepyakin f6657bace4
Flat Stack (#98)
* Define Instruction Set.

* WIP

* WIP 2

* Tests

* Working

* Bunch of other tests.

* WIP

* WIP

* Use Vec instead of VecDeque.

* Calibrate the limits.

* Clean

* Clean

* Another round of cleaning.

* Ignore traces.

* Optimize value stack

* Optimize a bit more.

* Cache memory index.

* Inline always instruction dispatch function.

* Comments.

* Clean

* Clean

* Use vector to keep unresolved references.

* Estimate resulting size.

* do refactoring

* Validate the locals count in the begging

* Introduce Keep and DropKeep structs in isa

* Rename/Split Validator into Reader

* Document stack layout

* Remove println!

* Fix typo.

* Use .last / .last_mut in stack

* Update docs for BrTable.

* Review fixes.

* Merge.

* Add an assert that stack is empty after the exec
2018-07-04 10:08:45 +03:00
Jef 3890dd379f Preserve signalling bit in NaNs (#87)
* Preserve signalling bit in NaNs

* Fix warnings
2018-04-25 10:18:14 +03:00
Sergey Pepyakin 730c918a80
Don't expand locals. (#86) 2018-04-20 17:55:07 +03:00
Jef 22b260a3b9 Optionally deny floating point operations (#83)
* Optionally deny floating point operations

* Deny floating-point parameters and fix docs/indentation

* Test denial of floating-point parameters
2018-04-18 15:09:09 +03:00
Pierre Krieger 4c2995ca98 Fix the name of the 32bits feature (#82)
So that it matches the Cargo.toml
2018-04-04 18:14:43 +03:00
Sergey Pepyakin 6253dd6fdf Args refactor (#71)
* Refactor TryInto → FromRuntimeValue.

Replace `TryInto<T, E>` with `FromRuntimeValue`.

The main difference is that `FromRuntimeValue` is implemented for the concrete type of the value we create, rather than on `RuntimeValue`. This makes more sense to me and seems more clear.

The `try_into` method is now implemented on `RuntimeValue` itself.

And finally, `FromRuntimeValue` has been made public.

* Impl AsRef<[RuntimeValue]> for RuntimeArgs

This impl can be used as an escape hatch if the user wants to use the inner slice.

* Little doc fixes for RuntimeArgs.
2018-03-14 01:23:12 +03:00
Sergey Pepyakin 0c277abacb
Implement Error for Trap (#73) 2018-03-12 12:37:12 +01:00
Sergey Pepyakin 6cf6a31970
Merge signature mismatch traps (#57) 2018-02-14 18:27:22 +03:00
Sergey Pepyakin e5056e7871 Add newline in compile_error!
This doesn't change the actual message.
2018-02-13 18:17:38 +03:00
Sergey Pepyakin 483736b1bd
Memory units (#42)
* Initial implementation

* Not use grow as it is makes debug builds very slow

* Use Pages::BYTE_SIZE for LINEAR_MEMORY_PAGE_SIZE

* Tidy docs.

* Use memory_units from git.
2018-02-09 16:45:21 +03:00
Sergey Pepyakin 6e4bbb7490 Opt in for 32bit platforms (#44) 2018-02-09 11:20:21 +03:00
Sergey Pepyakin 367f17989b Refine errors (#36)
* Get rid of Stack error

* Add UnexpectedSignature error and remove Value err

* Publish FuncInstance::invoke

* Rename Trap to TrapKind

* Replace Trap with struct. Enum is now TrapKind

* Fixes

* Update value.rs

* Avoid reversing parameter types iter.

* Add impl From<TrapKind> for Trap

* Remove redundant clone in prepare_function_args.

* Use .into() to convert TrapKind into Trap
2018-02-06 14:14:57 +03:00
Sergey Pepyakin fa82dee676 Add docs (#32) 2018-02-01 19:46:33 +03:00
Sergey Pepyakin c96735d6d6 Wasm function can only trap (#29)
* Introduce Trap struct.

* get_local can't fail.

* Add MemoryOutOfBounds trap.

* from_little_endian use slice instead of vec.

* MemoryAccessOutOfBounds for mem get and set.

* from_little_endian conversion can't fail.

* call_indirect traps.

* DivisionByZero and InvalidConversionToInt

* Use traps in value to convey an error

* select: int condition on stack top

* if: int condition on stack top

* Assert pops.

* Another protions of assert pops

* Introduce ValueStack

Also, hide FunctionContext and remove some stale code

* Traps in execution

* Make it compile.

* Check args before invoke.

* Document RuntimeArgs.

* Update host.rs

* Add rustdoc for Trap.
2018-02-01 14:59:21 +03:00
Sergey Pepyakin 1d87fb09dc
Publish LINEAR_MEMORY_PAGE_SIZE constant (#31) 2018-02-01 14:46:49 +03:00
Sergey Pepyakin 551c992730
4th iteration on documentation (#22)
* Rename LoadedModule to Module

* Hide TryInto

* Fix rustdoc tests.

* Rename from_parity_wasm_module and doc it.

* Document `Module::from_buffer`

* Tidy Module docs

* Some rustdoc headers.

* Document FuncInstance::{alloc_host, signature}

* Document descriptors.

* Doc NotStartedModuleRef

* Fix cargo-deadlinks
2018-01-26 19:24:40 +03:00
Sergey Pepyakin cc24d8a77a Fix idents 2018-01-25 19:56:52 +03:00
Sergey Pepyakin bc89a20b96 Third iteration on documenation. 2018-01-25 18:17:25 +03:00
NikVolf 4eb8608c1e rewire everything 2018-01-23 14:26:45 +03:00
Sergey Pepyakin 791292cd19 TODO about docs 2018-01-22 20:22:22 +03:00
Sergey Pepyakin bf2b2acbc5 Reintroduce FuncInstance; Hide internals 2018-01-22 20:07:30 +03:00
Sergey Pepyakin 44f61251c1 Hide FuncInstance 2018-01-22 19:38:57 +03:00
Sergey Pepyakin e26ddb6d12 Hide MemoryType. 2018-01-22 16:34:32 +03:00
Sergey Pepyakin 973d58a643 Hide TableType. 2018-01-22 16:30:13 +03:00
Sergey Pepyakin b323d004fe Hide GlobalType 2018-01-22 16:23:07 +03:00
Sergey Pepyakin aae9a3c129 Hide validation stuff. 2018-01-22 16:11:20 +03:00
Sergey Pepyakin ca6299ba53 Hide ValueType. 2018-01-18 17:13:56 +03:00
Sergey Pepyakin 1bf3702440 Move Signature into types module. 2018-01-18 15:54:31 +03:00
Sergey Pepyakin e9470373f7 Migrate on Signature type. 2018-01-18 15:48:43 +03:00
Sergey Pepyakin 49347a63ee Initial commit 2018-01-17 19:54:06 +03:00