Commit Graph

7963 Commits

Author SHA1 Message Date
Ivan Enderlin
012f37e3a9 doc(cranelift) Fix a typo
Hello Cranelfit :-).
2021-03-01 10:06:14 -08:00
Dan Gohman
10dbee0c17 Add a minimal README.md for wasmtime-wasi. 2021-03-01 09:58:57 -08:00
Dan Gohman
0824a934bf Add a minimal README.md for cap-std-sync. 2021-03-01 09:58:57 -08:00
Dan Gohman
a7dbba0b1e Add a mention of the WasiCtxBuilder move in the RELEASES.md document.
As suggested in #2691, mention that the path to `WasiCtxBuilder` changed
in the 0.23.0 release.
2021-03-01 09:03:03 -08:00
Chris Fallin
cdb60ec5a9 Merge pull request #2682 from cfallin/shift-bugs
Fix some `i128` shift-related bugs in x64 backend.
2021-02-26 15:13:08 -08:00
Alex Crichton
7795a230f2 Implement support for async functions in Wasmtime (#2434)
* Implement support for `async` functions in Wasmtime

This is an implementation of [RFC 2] in Wasmtime which is to support
`async`-defined host functions. At a high level support is added by
executing WebAssembly code that might invoke an asynchronous host
function on a separate native stack. When the host function's future is
not ready we switch back to the main native stack to continue execution.

There's a whole bunch of details in this commit, and it's a bit much to
go over them all here in this commit message. The most important changes
here are:

* A new `wasmtime-fiber` crate has been written to manage the low-level
  details of stack-switching. Unixes use `mmap` to allocate a stack and
  Windows uses the native fibers implementation. We'll surely want to
  refactor this to move stack allocation elsewhere in the future. Fibers
  are intended to be relatively general with a lot of type paremters to
  fling values back and forth across suspension points. The whole crate
  is a giant wad of `unsafe` unfortunately and involves handwritten
  assembly with custom dwarf CFI directives to boot. Definitely deserves
  a close eye in review!

* The `Store` type has two new methods -- `block_on` and `on_fiber`
  which bridge between the async and non-async worlds. Lots of unsafe
  fiddly bits here as we're trying to communicate context pointers
  between disparate portions of the code. Extra eyes and care in review
  is greatly appreciated.

* The APIs for binding `async` functions are unfortunately pretty ugly
  in `Func`. This is mostly due to language limitations and compiler
  bugs (I believe) in Rust. Instead of `Func::wrap` we have a
  `Func::wrapN_async` family of methods, and we've also got a whole
  bunch of `Func::getN_async` methods now too. It may be worth
  rethinking the API of `Func` to try to make the documentation page
  actually grok'able.

This isn't super heavily tested but the various test should suffice for
engaging hopefully nearly all the infrastructure in one form or another.
This is just the start though!

[RFC 2]: https://github.com/bytecodealliance/rfcs/pull/2

* Add wasmtime-fiber to publish script

* Save vector/float registers on ARM too.

* Fix a typo

* Update lock file

* Implement periodically yielding with fuel consumption

This commit implements APIs on `Store` to periodically yield execution
of futures through the consumption of fuel. When fuel runs out a
future's execution is yielded back to the caller, and then upon
resumption fuel is re-injected. The goal of this is to allow cooperative
multi-tasking with futures.

* Fix compile without async

* Save/restore the frame pointer in fiber switching

Turns out this is another caller-saved register!

* Simplify x86_64 fiber asm

Take a leaf out of aarch64's playbook and don't have extra memory to
load/store these arguments, instead leverage how `wasmtime_fiber_switch`
already loads a bunch of data into registers which we can then
immediately start using on a fiber's start without any extra memory
accesses.

* Add x86 support to wasmtime-fiber

* Add ARM32 support to fiber crate

* Make fiber build file probing more flexible

* Use CreateFiberEx on Windows

* Remove a stray no-longer-used trait declaration

* Don't reach into `Caller` internals

* Tweak async fuel to eventually run out.

With fuel it's probably best to not provide any way to inject infinite
fuel.

* Fix some typos

* Cleanup asm a bit

* Use a shared header file to deduplicate some directives
* Guarantee hidden visibility for functions
* Enable gc-sections on macOS x86_64
* Add `.type` annotations for ARM

* Update lock file

* Fix compile error

* Review comments
2021-02-26 16:19:56 -06:00
Arjun P
2b3eff8582 README: remove extra full stop (#2687) 2021-02-26 09:30:40 -06:00
Nick Fitzgerald
824ce7bf89 deps: Update Arbitrary to 1.0; libfuzzer-sys to 0.4.0; wasm-smith to 0.4.0 2021-02-25 15:34:02 -08:00
Chris Fallin
6dcb31abb7 Fix 128-bit left shift: null out tmp3, not tmp2, on zero-shift case.
Add a bunch of test vectors that actually expose this (previously the
shift-by-zero test had equal lower and upper halves and hid the bug),
including the most basic of all, 1 << 0 == 1 (thanks @bjorn3 for finding
this).
2021-02-25 09:46:57 -08:00
Chris Fallin
ebbe626e79 Merge pull request #2685 from cfallin/fix-multi-trap-metadata
Fix incomplete trap metadata due to multiple traps at one address.
2021-02-24 16:38:09 -08:00
Chris Fallin
40db4de44a Fix incomplete trap metadata due to multiple traps at one address.
If an instruction has more than one trap record associated with it (for
example: a divide instruction that has participated in load-op fusion,
so we have both a heap-out-of-bounds trap record due to its load and a
divide-by-zero trap record due to its divide op), the current MachBuffer
code would emit only one of the trap records to the sink.

Separately, divide instructions probably shouldn't merge loads, because
the two separate possible traps at one location might be confusing for
some embedders (certainly in Lucet). Divide seems to be the only case in
our current codegen where such merging might occur. This PR changes the
lowering to always force the divisor into a register.

Finally, while working out why trap records were not appearing, I had
noticed that `isa::x64::emit_std_enc_mem()` was only emitting heap-OOB
trap metadata for loads/stores when it had a srcloc. This PR ensures
that the metadata is emitted even when the srcloc is empty.

Note that none of the above presents a security or correctness problem;
trap metadata only affects the status that we return to the embedder
when a Wasm program terminates with a trap.
2021-02-24 15:13:45 -08:00
Chris Fallin
0cc4a3d445 Merge pull request #2683 from cfallin/br-table-unreachable
Fix bad jumptable block ref when DCE removes a block.
2021-02-23 16:31:19 -08:00
Chris Fallin
48d542d67c Fix bad jumptable block ref when DCE removes a block.
When a block is unreachable, the `unreachable_code` pass will remove it,
which is perfectly sensible. Jump tables factor into unreachability in
an expected way: even if a block is listed in a jump table, the block
might be unreachable if the jump table itself is unused (or used in an
unreachable block). Unfortunately, the verifier still expects all
block refs in all jump tables to be valid, even after DCE, which will
not always be the case.

This makes a simple change to the pass: after removing blocks, it scans
jump tables. Any jump table that refers to an unreachable block must
itself be unused, and so we just clear its entries. We do not bother
removing it (and renumbering all later jumptables), and we do not bother
computing full unused-ness of all jumptables, as that would be more
expensive; it's sufficient to clear out the ones that refer to
unreachable blocks, which are a subset of all unused jumptables.

Fixes #2670.
2021-02-23 15:01:01 -08:00
Chris Fallin
0f3e00b25e Fix some i128 shift-related bugs in x64 backend.
This fixes #2672 and #2679, and also fixes an incorrect instruction
emission (`test` with small immediate) that we had missed earlier.

The shift-related fixes have to do with (i) shifts by 0 bits, as a
special case that must be handled; and (ii) shifts by a 128-bit amount,
which we can handle by just dropping the upper half (we only use 3--7
bits of shift amount).

This adjusts the lowerings appropriately, and also adds run-tests to
ensure that the lowerings actually execute correctly (previously we only
had compile-tests with golden lowerings; I'd like to correct this for
more ops eventually, adding run-tests beyond what the Wasm spec and
frontend covers).
2021-02-23 14:22:04 -08:00
Chris Fallin
778afaf953 Merge pull request #2680 from bytecodealliance/pch/update_tracing_subscriber
latest tracing-{subscriber,log} fixes performance problem reported in #2662
2021-02-23 10:57:23 -08:00
Alex Crichton
707f83d413 Fix preservation of the sigaltstack on macOS (#2676)
* Fix preservation of the sigaltstack on macOS

This commit fixes an issue discovered in the wasmtime-go bindings when
the Go runtime was crashing on macOS only when running wasm code that
trapped. It turns out that our switch to `siglongjmp` from `longjmp`
actually broke macOS! This breakage happens because all subsequent
signals after the first signal are all delivered on the main stack, not
the sigaltstack, even if the sigaltstack is configured. This causes the
Go runtime to crash since it expects to run on the sigaltstack.

The fix in this commit is to actually return from the signal handler to
trigger the kernel's updating of the sigaltstack no longer being in use.
Before we return, however, we configure the register context to return
to to call some custom code which immediately does the unwind we would
otherwise have done. This works around the issue on macOS hopefully
without adding too many portability problems. Ideally this will all go
away as well with #2632 as well.

* Fix compile warning
2021-02-23 12:42:20 -06:00
Pat Hickey
ee1ddfb6f9 Merge pull request #2674 from bjorn3/module_improvements
Make Module object safe
2021-02-23 09:20:26 -08:00
Pat Hickey
4559537f24 latest tracing-subscriber fixes performance problem reported in #2662 2021-02-23 09:10:38 -08:00
Andrew Brown
96556ed700 Optionally compile wasmtime-bench-api with wasi-nn and wasi-crypto (#2677)
This adds the ability to add feature flags (e.g. `--features wasi-nn`) when compiling `wasmtime-bench-api` to allow benchmarking Wasmtime with WASI proposals included. Note that due to https://github.com/rust-lang/cargo/issues/5364, these features are only available:
 - in the `crates/bench-api` directory, e.g. `pushd crates/bench-api; cargo build --features wasi-crypto`
 - or from the top-level project directory using `-Zpackage-features`, e.g. `OPENVINO_INSTALL_DIR=/opt/intel/openvino cargo +nightly build -p wasmtime-bench-api -Zpackage-features --features wasi-nn`
2021-02-23 09:18:37 -06:00
Alex Crichton
98d3e6823f Update wasmparser/wat dependencies (#2675)
* Update wasmparser/wat dependencies

Bring in new opcodes and new instructions for SIMD

* Update module linking syntax
2021-02-22 11:56:34 -06:00
bjorn3
a710fc4425 Make Module object safe 2021-02-22 16:00:37 +01:00
Nick Fitzgerald
584d6fbf0e Merge pull request #2671 from fitzgen/issue-templates
Clean up our github issue templates
2021-02-19 13:05:04 -08:00
Nick Fitzgerald
a4a841cb6c Ensure all issue templates use Title Case 2021-02-19 10:30:28 -08:00
Nick Fitzgerald
25a9c73901 Clean up our github issue templates
* Don't use HTML comments, as they are noisy, which makes the templates more
  intimidating.

* Use "TODO" to clearly demarcate everywhere the issue reporter should fill in
  some information.

* Use headers and white space abundantly, which makes it easier to visually
  process the template and its sections at a glance, and less of an intimidating
  wall of text.

Fixes #2661
2021-02-19 09:44:19 -08:00
Pat Hickey
d60e158548 Merge pull request #2668 from bytecodealliance/pch/rename_some_wiggle_tests
rename some wiggle tests to reflect new witx ast names
2021-02-18 16:11:58 -08:00
Pat Hickey
1fe97ea31e rename some wiggle tests to reflect new witx ast names
arrays are now lists
structs are now records
unions are now variants

this ruins some of my union puns, oh well
2021-02-18 15:06:16 -08:00
Alex Crichton
cc6bde522a Update wasi-nn submodule 2021-02-18 14:45:20 -08:00
Alex Crichton
d095f63cfd Update submodules 2021-02-18 14:45:20 -08:00
Alex Crichton
136755ade2 Fix wiggle trace example 2021-02-18 14:45:20 -08:00
Alex Crichton
26e9ea433e Fix a bug in wasi 2021-02-18 14:45:20 -08:00
Alex Crichton
9ab5fa26cf Update the wasi-crypto spec 2021-02-18 14:45:20 -08:00
Alex Crichton
250f11c572 Fix build of wasi-nn 2021-02-18 14:45:20 -08:00
Alex Crichton
fa98f0bc91 Fix wiggle tests 2021-02-18 14:45:20 -08:00
Alex Crichton
df9c725fa0 Update to the next version of the witx crate
This commit updates to the 0.9 version of the witx crate implemented in
WebAssembly/wasi#395. This new version drastically changes code
generation and how we interface with the crate. The intention is to
abstract the code generation aspects and allow code generators to
implement much more low-level instructions to enable more flexible APIs
in the future. Additionally a bunch of `*.witx` files were updated in
the WASI repository.

It's worth pointing out, however, that `wasi-common` does not change as
a result of this change. The shape of the APIs that we need to implement
are effectively the same and the only difference is that the shim
functions generated by wiggle are a bit different.
2021-02-18 14:45:20 -08:00
Alex Crichton
aed6de32d4 Automatically add wasmtime-publish team while publishing (#2663)
This updates the publication script we have for crates to ensure that
the `wasmtime-publish` GitHub team is added to all crates published.
This will fail for most publications because the team is already listed,
but the hope is that whomever is publishing can see the logs and catch
anything that looks awry.
2021-02-18 12:34:48 -06:00
Max de Danschutter
445e539ae0 Disable wasmtime default-features in wasi crate (#2664) 2021-02-18 11:29:52 -06:00
Chris Fallin
c07ec4c525 Merge pull request #2653 from bjorn3/more_atomic_ops
More atomic ops
2021-02-18 08:34:58 -08:00
Chris Fallin
79bb1fc6a4 Merge pull request #2527 from bjorn3/serialize_ir
Add serde serialization support for the full clif ir
2021-02-18 08:33:50 -08:00
bjorn3
ff22842da5 More atomic ops 2021-02-18 14:16:15 +01:00
bjorn3
08f72d7084 Fix ensure_deterministic_build.sh 2021-02-18 13:53:21 +01:00
bjorn3
0693b7dade Include git rev in the version number 2021-02-18 13:01:01 +01:00
bjorn3
720da20588 Describe serialization format 2021-02-18 11:27:51 +01:00
bjorn3
a0c2276ee7 Add a version marker
This prevents deserializing a function with a different Cranelift version
2021-02-18 11:27:51 +01:00
bjorn3
71e468a954 Remove most of cranelift-serde 2021-02-18 11:27:49 +01:00
bjorn3
2fc964ea35 Add serde serialization support for the full clif ir 2021-02-18 11:27:02 +01:00
Chris Fallin
7b4652bb82 Merge pull request #2654 from kaseyc/rex
Add methods to construct RexFlags from OperandSizes.
2021-02-17 19:27:18 -08:00
Kasey Carrothers
9c3edee9d0 Add methods to construct RexFlags from OperandSizes.
This unifies the logic around Rex prefix emission and hopefully makes REX prefix errors less likely.
There are still several instructions that use other sources to determine the flags, so set_w and clear_w are left as is.

Additional cleanups:
  * Change always_emit_if_8bit_needed to take a Reg instead of a u8 for type safety.
  * Deduplicated emission code in MovRM.
2021-02-17 18:48:05 -08:00
Dan Gohman
8d90ea0390 Bump version to 0.23.0
I used a specially modified version of the publish script to avoid
bumping the `witx` version.
2021-02-17 15:35:43 -08:00
Pat Hickey
38b63f525e Merge pull request #2658 from Daniel-Liu-c0deb0t/anytrue-type
Specified type for V128AnyTrue
2021-02-16 17:30:37 -08:00
c0deb0t
fdd6bcae2e Specified type for V128AnyTrue 2021-02-16 15:13:23 -08:00