Commit Graph

1738 Commits

Author SHA1 Message Date
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
Benjamin Bouvier
b0ce0c8f5d Upgrade Tokio to 1.8.1
This contains a fix for a vulnerability reported as RUSTSEC-2021-0072.
2021-07-08 12:13:53 +02:00
Peter Huene
89ed663058 Merge pull request #3068 from fitzgen/error-msg-off-by-one
Fix error messages reporting number of expected vs actual params
2021-07-07 17:50:13 -07:00
Andrew Brown
43b9337162 Fix typo
Also, the IDE auto-formatted the length of several other comments.
2021-07-07 12:07:04 -07:00
Nick Fitzgerald
be60fec6ba Fix error messages reporting number of expected vs actual params
We previously had some off-by-one errors in our error messages and this led to
very confusing messages like "expected 0 types, found 0" that were quite
annoying to debug as an API consumer.
2021-07-07 11:32:40 -07:00
Benjamin Bouvier
91c65d739f Remove unused code in machinst 2021-07-02 18:09:33 +02:00
Alex Crichton
aa5d837428 Start a high-level architecture document for Wasmtime (#3019)
* Start a high-level architecture document for Wasmtime

This commit cleands up some existing documentation by removing a number
of "noop README files" and starting a high-level overview of the
architecture of Wasmtime. I've placed this documentation under the
contributing section of the book since it seems most useful for possible
contributors.

I've surely left some things out in this pass, and am happy to add more!

* Review comments

* More rewording

* typos
2021-07-02 09:02:26 -05:00
Alex Crichton
b9985fe2e5 Change the injection count of fuel in a store from u32 to u64 (#3048)
* Change the injection count of fuel in a store from u32 to u64

This commit updates the type of the amount of times to inject fuel in
the `out_of_fuel_async_yield` to `u64` instead of `u32`. This should
allow effectively infinite fuel to get injected, even if a small amount
of fuel is injected per iteration.

Closes #2927
Closes #3046

* Fix tokio example
2021-07-01 10:46:21 -05:00
Benjamin Bouvier
a603fc5bd5 Add a way to display only the trap's reason (without the backtrace) (#3033) 2021-06-30 09:34:47 -05:00
Alex Crichton
c5609bc364 Update documentation of enter/exit hooks (#3041)
Clarify that they're executed not only around imports but also around
function calls. Additionally spell out the semantics around traps a bit
more clearly too.
2021-06-29 12:57:39 -05:00
Alex Crichton
7e31a0bbce Update documentation in Config about Send futures
Futures are indeed `Send` now!
2021-06-25 07:38:47 -07:00
Alex Crichton
1047c4e156 Fix fuzzers requesting 4gb memories (#3029)
Wasmtime was updated to reject creation of memories exactly 4gb in size
in #3013, but the fuzzers still had the assumption that any request to
create a host object for a particular wasm type would succeed.
Unfortunately now, though, a request to create a 4gb memory fails. This
is an expected failure, though, so the fix here was to catch the error
and allow it.
2021-06-24 14:53:18 -05:00
katelyn martin
ab536126dd update WASI submodule (#3025)
* wasi-common: update wasi submodule

This updates the WASI submodule, pulling in changes to the witx crate,
now that there is a 0.9.1 version including some bug fixes. See
WebAssembly/WASI#434 for more information.

* wiggle: update witx dependencies

* publish: verify and vendor witx-cli

* adjust root workspace members

This commit removes some items from the root manifest's workspace
members array, and adds `witx-cli` to the root `workspace.exclude`
array.

The motivation for this stems from a cargo bug described in
rust-lang/cargo#6745: `workspace.exclude` does not work if it is nested
under a `workspace.members` path.

See WebAssembly/WASI#438 for the underlying change to the WASI submodule
which reorganized the `witx-cli` crate, and WebAssembly/WASI#398 for the
original PR introducing `witx-cli`.

See [this
comment](https://github.com/bytecodealliance/wasmtime/pull/3025#issuecomment-867741175)
for more details about the compilation errors, and failed alternative
approaches that necessitated this change.

N.B. This is not a functional change, these crates are still implicitly
workspace members as transitive dependencies, but this will allow us to
side-step the aforementioned cargo bug.

Co-Authored-By: Alex Crichton <alex@alexcrichton.com>

Co-authored-by: Alex Crichton <alex@alexcrichton.com>
2021-06-24 14:21:48 -05:00
Chris Fallin
8172620763 Merge pull request #3024 from uweigand/poll-timeout
Increase timeout for poll_oneoff tests
2021-06-23 11:42:21 -07:00
Ulrich Weigand
c881c01cde Increase timeout for poll_oneoff tests
This increases the timeout from 50ms to 200ms, which makes the
tests reliably pass on my machine using the CI scripts againt
the s390x-linux-user qemu target.
2021-06-23 20:04:31 +02:00
Alex Crichton
a273add815 Simplify the list of builtin intrinsics Wasmtime needs
This commit slims down the list of builtin intrinsics. It removes the
duplicated intrinsics for imported and locally defined items, instead
always using one intrinsic for both. This was previously inconsistently
applied where some intrinsics got two copies (one for imported one for
local) and other intrinsics got only one copy. This does add an extra
branch in intrinsics since they need to determine whether something is
local or not, but that's generally much lower cost than the intrinsics
themselves.

This also removes the `memory32_size` intrinsic, instead inlining the
codegen directly into the clif IR. This matches what the `table.size`
instruction does and removes the need for a few functions on a
`wasmtime_runtime::Instance`.
2021-06-23 10:30:31 -07:00
Alex Crichton
324d80729a Refactor some internal accessors of Instance (#3021)
This commit removes some one-use methods to inline them at their use
site, and otherwise adds bounds checks to other functions like
`imported_function` where previously the `FuncIndex` may have been
accidentally out of bounds, which would cause memory unsafety. There's
no actual bug this was fixing, just trying to improve the safety of the
code internally a little.
2021-06-23 12:12:38 -05:00
Ulrich Weigand
83007b79e3 Fix access to VMMemoryDefinition::current_length on big-endian (#3013)
The current_length member is defined as "usize" in Rust code,
but generated wasm code refers to it as if it were "u32".
While this happens to mostly work on little-endian machines
(as long as the length is < 4GB), it will always fail on
big-endian machines.

Fixed by making current_length "u32" in Rust as well, and
ensuring the actual memory size is always less than 4GB.
2021-06-23 11:45:32 -05:00
Ulrich Weigand
1a865fb0f5 Fix WASI fd_readdir on big-endian (#3016)
This code assumes that the Dirent structure has the same memory
layout on the host (Rust code) as in wasm code.  This is not true
if the host is big-endian, as wasm is always little-endian.

Fixed by always byte-swapping Dirent fields to little-endian
before passing them on to wasm code.
2021-06-22 10:39:38 -05:00
Alex Crichton
8760bccc8e Fix running enter/exit hooks on start functions (#3001)
This commit fixes running the store's enter/exit hooks into wasm which
accidentally weren't run for an instance's `start` function. The fix
here was mostly to just sink the enter/exit hook much lower in the code
to `invoke_wasm_and_catch_traps`, which is the common entry point for
all wasm calls.

This did involve propagating the `StoreContext<T>` generic rather than
using `StoreOpaque` unfortunately, but it is overally not too too much
code and we generally wanted most of it inlined anyway.
2021-06-21 16:31:10 -05:00
Anton Kirilov
cb93726250 Enable more tests on AArch64 (#2994)
Copyright (c) 2021, Arm Limited.
2021-06-21 12:26:44 -05:00
Alex Crichton
724beaf0f3 Connect helper C symbols to their static library
This commit adds a `#[link]` annotation to the block defining symbols
coming from a native static library that we build and link. This is
required by rustc to get symbols to get exported correctly when linking
wasmtime into a Rust dynamic library instead of always as an rlib.

While I was at it I went ahead and renamed the symbols now that they're
no longer in C++ and they're doing setjmp/longjmp and not much else.

Closes #3006
2021-06-21 07:27:22 -07:00
Alex Crichton
7ce46043dc Add guard pages to the front of linear memories (#2977)
* Add guard pages to the front of linear memories

This commit implements a safety feature for Wasmtime to place guard
pages before the allocation of all linear memories. Guard pages placed
after linear memories are typically present for performance (at least)
because it can help elide bounds checks. Guard pages before a linear
memory, however, are never strictly needed for performance or features.
The intention of a preceding guard page is to help insulate against bugs
in Cranelift or other code generators, such as CVE-2021-32629.

This commit adds a `Config::guard_before_linear_memory` configuration
option, defaulting to `true`, which indicates whether guard pages should
be present both before linear memories as well as afterwards. Guard
regions continue to be controlled by
`{static,dynamic}_memory_guard_size` methods.

The implementation here affects both on-demand allocated memories as
well as the pooling allocator for memories. For on-demand memories this
adjusts the size of the allocation as well as adjusts the calculations
for the base pointer of the wasm memory. For the pooling allocator this
will place a singular extra guard region at the very start of the
allocation for memories. Since linear memories in the pooling allocator
are contiguous every memory already had a preceding guard region in
memory, it was just the previous memory's guard region afterwards. Only
the first memory needed this extra guard.

I've attempted to write some tests to help test all this, but this is
all somewhat tricky to test because the settings are pretty far away
from the actual behavior. I think, though, that the tests added here
should help cover various use cases and help us have confidence in
tweaking the various `Config` settings beyond their defaults.

Note that this also contains a semantic change where
`InstanceLimits::memory_reservation_size` has been removed. Instead this
field is now inferred from the `static_memory_maximum_size` and guard
size settings. This should hopefully remove some duplication in these
settings, canonicalizing on the guard-size/static-size settings as the
way to control memory sizes and virtual reservations.

* Update config docs

* Fix a typo

* Fix benchmark

* Fix wasmtime-runtime tests

* Fix some more tests

* Try to fix uffd failing test

* Review items

* Tweak 32-bit defaults

Makes the pooling allocator a bit more reasonable by default on 32-bit
with these settings.
2021-06-18 09:57:08 -05:00
Alex Crichton
d8d4bf81b2 Reimplement how instance exports are stored/loaded (#2984)
* Reimplement how instance exports are stored/loaded

This commit internally refactors how instance exports are handled and
fixes two issues. One issue is that when we instantiate an instance we
no longer forcibly load all items from the instance immediately,
deferring insertion of each item into the store data tables to happen
later as necessary. The next issue is that repeated calls to
`Caller::get_export` would continuously insert items into the store data
tables. While working as intended this was undesirable because it would
continuously push onto a vector that only got deallocated once the
entire store was deallocate. Now it's routed to `Instance::get_export`
which doesn't have this behavior.

Closes #2916
Closes #2983

* Just define our own `Either`
2021-06-17 14:27:48 -05:00
Alex Crichton
fb07ff5740 Implement Clone for Linker (#2993)
There's no real reason to not do this, and it can help with some
usability use cases!
2021-06-16 16:06:24 -05:00
Alex Crichton
5140fd251a Update wasm-tools crates (#2989)
* Update wasm-tools crates

This brings in recent updates, notably including more improvements to
wasm-smith which will hopefully help exercise non-trapping wasm more.

* Fix some wat
2021-06-15 22:56:10 -05:00
Olivier Lemasle
a7dad4e38f Include READMEs in crates (#2987) 2021-06-15 06:40:45 -07:00
Olivier Lemasle
b506bc30b1 wasmtime-cache: Update zstd (#2969)
Also update exceptions in deny.toml bans
2021-06-10 12:47:45 -05:00
Alex Crichton
e8b8947956 Bump to 0.28.0 (#2972) 2021-06-09 14:00:13 -05:00
Alex Crichton
884a6500e9 Add a safe method for accessing memory and T (#2971)
This is currently a very common operation in host bindings where if wasm
gives a host function a relative pointer you'll want to simulataneously
work with the host state and the wasm memory. These two regions are
distinct and safe to borrow mutably simulataneously but it's not obvious
in the Rust type system that this is so, so add a helper method here to
assist in doing so.
2021-06-08 09:37:31 -05:00
Pat Hickey
8b4bdf92e2 make ResourceLimiter operate on Store data; add hooks for entering and exiting native code (#2952)
* wasmtime_runtime: move ResourceLimiter defaults into this crate

In preparation of changing wasmtime::ResourceLimiter to be a re-export
of this definition, because translating between two traits was causing
problems elsewhere.

* wasmtime: make ResourceLimiter a re-export of wasmtime_runtime::ResourceLimiter

* refactor Store internals to support ResourceLimiter as part of store's data

* add hooks for entering and exiting native code to Store

* wasmtime-wast, fuzz: changes to adapt ResourceLimiter API

* fix tests

* wrap calls into wasm with entering/exiting exit hooks as well

* the most trivial test found a bug, lets write some more

* store: mark some methods as #[inline] on Store, StoreInner, StoreInnerMost

Co-authored-By: Alex Crichton <alex@alexcrichton.com>

* improve tests for the entering/exiting native hooks

Co-authored-by: Alex Crichton <alex@alexcrichton.com>
2021-06-08 09:37:00 -05:00
Pat Hickey
38ab7a03dd Merge pull request #2946 from bytecodealliance/pch/eager_per_thread_init
expose eager thread-local resource initialization on Engine
2021-06-04 15:42:08 -07:00
Alex Crichton
e516f0339a Update wasm-smith to generate more wasm (#2967)
This brings in bytecodealliance/wasm-tools#277 which should improve the
wasm programs that wasm-smith generates.
2021-06-04 17:11:19 -05:00
Pat Hickey
613309b76c missing docs 2021-06-04 14:22:08 -07:00
Pat Hickey
895ee2b85f make Module::deserialize's version check optional via Config (#2945)
* make Module::deserialize's version check optional via Config

A SerializedModule contains the CARGO_PKG_VERSION string, which is
checked for equality when loading. This is a great guard-rail but
some users may want to disable this check (e.g. so they can implement
their own versioning scheme)

* rename config to deserialize_check_wasmtime_version

* add test

* fix doc links

* fix

* thank you rustdoc
2021-06-04 14:18:02 -05:00