Commit Graph

1772 Commits

Author SHA1 Message Date
Andrew Brown
651a321f1a fuzz: add differential_spec fuzzing target
This new target compares the outputs of executing the first exported
function of a Wasm module in Wasmtime and in the official Wasm spec
interpreter (using the `wasm-spec-interpreter` crate). This is an
initial step towards more fully-featured fuzzing (e.g. compare memories,
add `v128`, add references, add other proposals, etc.)
2021-08-10 11:56:07 -07:00
Andrew Brown
f3955fa62a refactor: rename DifferentialWasmiModuleConfig to SingleFunctionModuleConfig
Since we plan to reuse this configuration, we rename it and ensure it
has at least 1 type (this resulted in invalid modules).
2021-08-10 11:56:07 -07:00
Andrew Brown
a7f592a026 Add a crate to interface with the WebAssembly spec interpreter
The WebAssembly spec interpreter is written in OCaml and the new crate
uses `ocaml-interop` along with a small OCaml wrapper to interpret Wasm
modules in-process. The build process for this crate is currently
Linux-specific: it requires several OCaml packages (e.g. `apt install -y
ocaml-nox ocamlbuild`) as well as `make`, `cp`, and `ar`.
2021-08-10 11:56:07 -07:00
Andrew Brown
2e95d4e7c6 wasi-nn: refactor wasi-nn context to use multiple backends 2021-08-10 10:05:52 -07:00
Andrew Brown
f0147f23e8 wiggle: emit From<#ident> for #tag_type for variants 2021-08-10 10:05:52 -07:00
Andrew Brown
c3bbdead7c wasi-nn: add backend abstraction 2021-08-10 10:05:52 -07:00
Alex Crichton
480dff21e8 fuzz: Disable more features for spectests fuzzer (#3159)
The previous commit to eanble multi-memory and simd leaked into the
spectest fuzzer, but to pass the spec tests we can't enable these features.
2021-08-06 16:27:42 -05:00
Alex Crichton
33c3d00f10 Remove rss prediction from api_calls fuzzer (#3156)
This functionality is now subsumed by the limiter built-in to all
fuzzing stores, so there's no longer any need for it. It was also
triggering arithmetic overflows in fuzzing, so instead of fixing I'm
removing it!
2021-08-06 12:43:22 -05:00
Nick Fitzgerald
e5ef1455a3 Merge pull request #3157 from alexcrichton/centralize-error-handling
fuzz: Centralize handling instantiation errors
2021-08-06 10:38:48 -07:00
Alex Crichton
45896e0533 Decrease memory limit in fuzzing to 1gb (#3155)
This should keep us under the default 2gb limit when fuzzing
2021-08-06 12:28:49 -05:00
Alex Crichton
3bdf6c7a48 fuzz: Centralize handling instantiation errors
At the same time remove some string matching in favor of checking for
oom explicitly.
2021-08-06 07:47:28 -07:00
Alex Crichton
bb85366a3b Enable simd fuzzing on oss-fuzz (#3152)
* Enable simd fuzzing on oss-fuzz

This commit generally enables the simd feature while fuzzing, which
should affect almost all fuzzers. For fuzzers that just throw random
data at the wall and see what sticks, this means that they'll now be
able to throw simd-shaped data at the wall and have it stick. For
wasm-smith-based fuzzers this commit also updates wasm-smith to 0.6.0
which allows further configuring the `SwarmConfig` after generation,
notably allowing `instantiate-swarm` to generate modules using simd
using `wasm-smith`. This should much more reliably feed simd-related
things into the fuzzers.

Finally, this commit updates wasmtime to avoid usage of the general
`wasm_smith::Module` generator to instead use a Wasmtime-specific custom
default configuration which enables various features we have
implemented.

* Allow dummy table creation to fail

Tables might creation for imports may exceed the memory limit on the
store, which we'll want to gracefully recover from and not fail the
fuzzers.
2021-08-05 16:24:42 -05:00
Alex Crichton
214c5f862d fuzz: Implement finer memory limits per-store (#3149)
* fuzz: Implement finer memory limits per-store

This commit implements a custom resource limiter for fuzzing. Locally I
was seeing a lot of ooms while fuzzing and I believe it was generally
caused from not actually having any runtime limits for wasm modules. I'm
actually surprised that this hasn't come up more on oss-fuzz more in
reality, but with a custom store limiter I think this'll get the job
done where we have an easier knob to turn for controlling the memory
usage of fuzz-generated modules.

For now I figure a 2gb limit should be good enough for limiting fuzzer
execution. Additionally the "out of resources" check if instantiation
fails now looks for the `oom` flag to be set instead of pattern matching
on some error messages about resources.

* Fix tests
2021-08-05 15:07:33 -05:00
Alex Crichton
d8c4ac2c25 Improve output of expectation failures of the wast commands (#3150)
This commit updates the output of failed expectations in the `wast`
crate to fold in the check-is-the-value-the-same with the
generate-a-nice-message. Additionally this tries to make sure that
everything is aligned in the output to make it a bit more easily
readable. Vectors should notably be improved where lane differences can
be compared vertically in the case of integers and printed out
specifically in the case of floats.
2021-08-05 14:31:55 -05:00
Alex Crichton
9e142f8792 Fix some warnings on nightly Rust (#3148)
Looks like these trailing-semicolons-in-macros are likely to become a
hard error in the future, so this updates to remove them as necessary.
2021-08-05 13:02:44 -05:00
Alex Crichton
4cfa031c5f Implement API support for v128-globals (#3147)
Found via fuzzing, and looks like these were accidentally left out along
the way SIMD was taking shape.
2021-08-05 13:02:34 -05:00
Alex Crichton
85f16f488d Consolidate address calculations for atomics (#3143)
* Consolidate address calculations for atomics

This commit consolidates all calcuations of guest addresses into one
`prepare_addr` function. This notably remove the atomics-specifics paths
as well as the `prepare_load` function (now renamed to `prepare_addr`
and folded into `get_heap_addr`).

The goal of this commit is to simplify how addresses are managed in the
code generator for atomics to use all the shared infrastrucutre of other
loads/stores as well. This additionally fixes #3132 via the use of
`heap_addr` in clif for all operations.

I also added a number of tests for loads/stores with varying alignments.
Originally I was going to allow loads/stores to not be aligned since
that's what the current formal specification says, but the overview of
the threads proposal disagrees with the formal specification, so I
figured I'd leave it as-is but adding tests probably doesn't hurt.

Closes #3132

* Fix old backend

* Guarantee misalignment checks happen before out-of-bounds
2021-08-04 15:57:56 -05:00
Alex Crichton
a33caec9be Bump the wasm-tools crates (#3139)
* Bump the wasm-tools crates

Pulls in some updates here and there, mostly for updating crates to the
latest version to prepare for later memory64 work.

* Update lightbeam
2021-08-04 09:53:47 -05:00
Chris Fallin
a13a777230 Bump to Wasmtime v0.29.0 and Cranelift 0.76.0. 2021-08-02 11:24:09 -07:00
Alex Crichton
63a3bbbf5a Change VMMemoryDefinition::current_length to usize (#3134)
* Change VMMemoryDefinition::current_length to `usize`

This commit changes the definition of
`VMMemoryDefinition::current_length` to `usize` from its previous
definition of `u32`. This is a pretty impactful change because it also
changes the cranelift semantics of "dynamic" heaps where the bound
global value specifier must now match the pointer type for the platform
rather than the index type for the heap.

The motivation for this change is that the `current_length` field (or
bound for the heap) is intended to reflect the current size of the heap.
This is bound by `usize` on the host platform rather than `u32` or`
u64`. The previous choice of `u32` couldn't represent a 4GB memory
because we couldn't put a number representing 4GB into the
`current_length` field. By using `usize`, which reflects the host's
memory allocation, this should better reflect the size of the heap and
allows Wasmtime to support a full 4GB heap for a wasm program (instead
of 4GB minus one page).

This commit also updates the legalization of the `heap_addr` clif
instruction to appropriately cast the address to the platform's pointer
type, handling bounds checks along the way. The practical impact for
today's targets is that a `uextend` is happening sooner than it happened
before, but otherwise there is no intended impact of this change. In the
future when 64-bit memories are supported there will likely need to be
fancier logic which handles offsets a bit differently (especially in the
case of a 64-bit memory on a 32-bit host).

The clif `filetest` changes should show the differences in codegen, and
the Wasmtime changes are largely removing casts here and there.

Closes #3022

* Add tests for memory.size at maximum memory size

* Add a dfg helper method
2021-08-02 13:09:40 -05:00
Shamil
072d5dc978 Fix typo in doc (#3127) 2021-07-29 08:59:41 -05:00
Andrew Brown
e3c56efd3e Fix unused borrow warning
`#[warn(unused_must_use)]` is on, prompting a compiler warning like:
"unused borrow that must be used".
2021-07-28 15:39:45 -07:00
Alex Crichton
65378422bf Add a wasmtime_linker_define_func C API function (#3122)
This exposes the functionality of the `Linker` type where a
store-independent function can be created and inserted, allowing a
linker's functions to be used across many stores (instead of requiring
one linker-per-store).

Closes #3110
2021-07-27 18:56:52 -05:00
Alex Crichton
9b088756b3 Implement Linker::module_async (#3121)
This implements and adds the async counterpart of the `Linker::module`
method.

Closes #3077
2021-07-27 16:17:45 -05:00
Alex Crichton
b5f7b2f86a Remove thread local for mach port (#3119)
This was needed a long time ago in the original implementation when the
function being called here was hotter than it was before, but nowadays
this function isn't hot as it's protected elsewhere from being
repeatedly called, so the caching thread local is no longer necessary.
2021-07-27 11:07:15 -05:00
Dan Gohman
784a380e5f Add comments about vmctx pointers in various datastructures. (#2925)
This forward-ports the relevant parts of #1396.
2021-07-27 09:33:27 -05:00
Nick Fitzgerald
10eead18c8 Update object to 0.26.0 2021-07-26 12:10:41 -07:00
Nick Fitzgerald
514bbb20b4 Update backtrace to 0.3.61 2021-07-26 12:05:44 -07:00
Nick Fitzgerald
3d76cbdf34 Update gimli to 0.25; addr2line to 0.16 2021-07-26 11:04:53 -07:00
Peter Huene
ad054c6bce Add more documentation to ModuleLimits and InstanceLimits.
This commit adds some clarifying documentation to both the `ModuleLimits` and
`InstanceLimits` types in the Wasmtime API.

It clarifies how each setting relates to the memory allocated by the pooling
instance allocator.

Closes #3080.
2021-07-23 14:26:48 -07:00
Nick Fitzgerald
f136f73033 Reword get_export mutable context docs to be more user-facing 2021-07-21 11:25:49 -07:00
Nick Fitzgerald
943d027757 Document reborrowing issues for AsContextMut and workarounds 2021-07-21 09:28:36 -07:00
Nick Fitzgerald
4c9f90e89d Document why get_export requires a mutable context 2021-07-21 09:10:09 -07:00
Qiu Wenbo
f628d06118 Upgrade capstone to v0.9 2021-07-19 17:14:28 +08:00
Alex Crichton
ff1ae6e10c Flag another error as ok to hit when fuzzing (#3092)
We've got a lot of fuzz failures right now of modules instantiating
memories of 65536 pages, which we specifically disallow since the
representation of limits within Wasmtime don't support full 4GB
memories. This is ok, however, and it's not a fuzz failure that we're
interested in, so this commit allows strings of that error to pass
through the fuzzer.
2021-07-16 14:37:27 -05:00
Pat Hickey
83f7872ace Merge pull request #3090 from bytecodealliance/pch/wiggle_dummy_executor_crashes
wiggle: dummy executor traps instead of panics, improve testing
2021-07-16 11:34:56 -07:00
Pat Hickey
906182a304 fix wasi-tokio 2021-07-16 10:28:09 -07:00
Pat Hickey
4fa4a72328 wiggle: expand test suite
sync test: show the dummy executor will trap (rather than panic) when a
future inside it pends.

async test: show that the executor is hooked up to a future that pends
for a trivial amount of time.

this adds tokio to the dev-dependencies of wiggle, it shouldn't end up
increasing the build burden for the project as a whole since its already
a dev-dependency.
2021-07-16 09:32:43 -07:00
Alex Crichton
3da677796b Reword env var hint for dwarf debug info (#3081)
* Reword env var hint for dwarf debug info

Try not to declare that more information will indeed be displayed,
instead suggest that the output may improve if the env var is set since
dwarf debug info wasn't parsed.

cc bytecodealliance/wasmtime-go#90

* Fix test assertion
2021-07-15 16:33:47 -05:00
Pat Hickey
6f07c76c84 wiggle: make the dummy executor return a trap rather than panic
when configured improperly
2021-07-15 11:44:58 -07:00
Stephan Renatus
f3b80ece5f c-api: add wasmtime_trap_code (#3086)
Eventually this should be added to the wasmtime-go binding, addressing
https://github.com/bytecodealliance/wasmtime-go/issues/63.

Added a snippet to examples/interrupt.c to verify that this works as
expected in manual testing.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2021-07-15 10:31:03 -05:00
Dan Gohman
6a5a295019 Port wasi-common from unsafe-io to io-lifetimes (#3049)
* Port wasi-common to io-lifetimes.

This ports wasi-common from unsafe-io to io-lifetimes.

Ambient authority is now indicated via calls to `ambient_authority()`
from the ambient-authority crate, rather than using `unsafe` blocks.

The `GetSetFdFlags::set_fd_flags` function is now split into two phases,
to simplify lifetimes in implementations which need to close and re-open
the underlying file.

* Use posish for errno values instead of libc.

This eliminates one of the few remaining direct libc dependencies.

* Port to posish::io::poll.

Use posish::io::poll instead of calling libc directly. This factors out
more code from Wasmtime, and eliminates the need to manipulate raw file
descriptors directly.

And, this eliminates the last remaining direct dependency on libc in
wasi-common.

* Port wasi-c-api to io-lifetimes.

* Update to posish 0.16.0.

* Embeded NULs in filenames now get `EINVAL` instead of `EILSEQ`.

* Accept either `EILSEQ` or `EINVAL` for embedded NULs.

* Bump the nightly toolchain to 2021-07-12.

This fixes build errors on the semver crate, which as of this writing
builds with latest nightly and stable but not 2021-04-11, the old pinned
version.

* Have cap-std-sync re-export ambient_authority so that users get the same version.
2021-07-14 15:39:09 -07:00
Alex Crichton
13d317a0a8 Fix stack checks of recursive async function calls (#3088)
* Fix stack checks of recursive async function calls

Previously the stack pointer limit wasn't adjusted, even in the face of
stack switching. This commit updates the logic around the stack limit
calculation to configure it on all async function calls, even if they're
recursive. Synchronous function calls, however, continue to only
configure the stack limit at the start, not for recursive calls.

* Update crates/wasmtime/src/func.rs

Co-authored-by: Peter Huene <peter@huene.dev>

Co-authored-by: Peter Huene <peter@huene.dev>
2021-07-14 16:32:30 -05:00
Alex Crichton
73fd702bb7 Don't assume all custom sections are dwarf info (#3083)
This incorrectly assumed that we had unparsed dwarf information,
regardless of custom section name. This commit updates the logic to
calculate that by first checking the section name before we set the flag
indicating that there's unparsed debuginfo.
2021-07-13 15:53:17 -05:00
Alex Crichton
992d85ae8b Add a type parameter to VMOffsets for pointer size (#3020)
* Add a type parameter to `VMOffsets` for pointer size

This commit adds a type parameter to `VMOffsets` representing the
pointer size to improve computations in `wasmtime-runtime` which always
use a constant value of the host's pointer size. The type parameter is
`u8` for `wasmtime-cranelift`'s use case where cross-compilation may be
involved.

* fix lightbeam
2021-07-13 09:52:27 -05:00
Peter Huene
75e5219792 Merge pull request #3034 from alexcrichton/update-config
Update documentation in Config about Send futures
2021-07-12 18:39:04 -07:00
Benoît CORTIER
cfeaa95b54 wasmtime: fix typo in Store doc 2021-07-12 21:28:15 -04:00
Ulan Degenbaev
f08491eeca Restore POSIX signal handling on MacOS behind a feature flag (#3063)
* Restore POSIX signal handling on MacOS behind a feature flag

As described in Issue #3052, the switch to Mach Exception handling
removed `unix::StoreExt` from the public API of crate on MacOS.
That is a breaking change and makes it difficult for some
application to upgrade to the current stable Wasmtime.

As a workaround this PR introduces a feature flag called
`posix-signals-on-macos` that restores the old behaviour on MacOS.
The flag is disabled by default.

* Fix test guard

* Fix formatting in the test
2021-07-12 16:25:44 -05:00
Alphyr
808582826b Enable nightly doc features on docs.rs (#3076) 2021-07-12 09:24:55 -05:00
Peter Huene
08575a8b5e Add setter for enabling multi-memory to the C API.
This commit adds `wasmtime_config_wasm_multi_memory_set` to the C API.

Fixes #3066.
2021-07-08 11:05:51 -07:00