Commit Graph

500 Commits

Author SHA1 Message Date
Alex Crichton
84bcbd4650 Fix some tests 2020-03-04 10:37:10 -08:00
Alex Crichton
8cee547519 Run rustfmt 2020-03-04 10:36:26 -08:00
Alex Crichton
ca9f33b6d9 Rewrite for recursive safety
This commit rewrites the runtime crate to provide safety in the face
of recursive calls to the guest. The basic principle is that
`GuestMemory` is now a trait which dynamically returns the
pointer/length pair. This also has an implicit contract (hence the
`unsafe` trait) that the pointer/length pair point to a valid list of
bytes in host memory "until something is reentrant".

After this changes the various suite of `Guest*` types were rewritten.
`GuestRef` and `GuestRefMut` were both removed since they cannot safely
exist. The `GuestPtrMut` type was removed for simplicity, and the final
`GuestPtr` type subsumes `GuestString` and `GuestArray`. This means
that there's only one guest pointer type, `GuestPtr<'a, T>`, where `'a`
is the borrow into host memory, basically borrowing the `GuestMemory`
trait object itself.

Some core utilities are exposed on `GuestPtr`, but they're all 100%
safe. Unsafety is now entirely contained within a few small locations:

* Implementations of the `GuestType` for primitive types (e.g. `i8`,
  `u8`, etc) use `unsafe` to read/write memory. The `unsafe` trait of
  `GuestMemory` though should prove that they're safe.

* `GuestPtr<'_, str>` has a method which validates utf-8 contents, and
  this requires `unsafe` internally to read all the bytes. This is
  guaranteed to be safe however given the contract of `GuestMemory`.

And that's it! Everything else is a bunch of safe combinators all built
up on the various utilities provided by `GuestPtr`. The general idioms
are roughly the same as before, with various tweaks here and there. A
summary of expected idioms are:

* For small values you'd `.read()` or `.write()` very quickly. You'd
  pass around the type itself.

* For strings, you'd pass `GuestPtr<'_, str>` down to the point where
  it's actually consumed. At that moment you'd either decide to copy it
  out (a safe operation) or you'd get a raw view to the string (an
  unsafe operation) and assert that you won't call back into wasm while
  you're holding that pointer.

* Arrays are similar to strings, passing around `GuestPtr<'_, [T]>`.
  Arrays also have a `iter()` method which yields an iterator of
  `GuestPtr<'_, T>` for convenience.

Overall there's still a lot of missing documentation on the runtime
crate specifically around the safety of the `GuestMemory` trait as well
as how the utilities/methods are expected to be used. Additionally
there's utilities which aren't currently implemented which would be easy
to implement. For example there's no method to copy out a string or a
slice, although that would be pretty easy to add.

In any case I'm curious to get feedback on this approach and see what
y'all think!
2020-03-04 10:26:47 -08:00
Maciej Woś
8acfdbdd8a add more wrappers and getters (#1222) 2020-03-03 22:58:11 -06:00
Jakub Konka
3764204250 Put context object behind a ref rather than mut ref
This commit puts context object, i.e., the implementor of the
WASI snapshot, behind a reference `&self` rather than a mutable
reference `&mut self`. As suggested by @alexcrichton, this gives
the implementor the possibility to determine how it handles its
interior mutability.
2020-03-03 17:50:32 +01:00
Alex Crichton
77e17d8f71 Add a wasmtime-specific wasmtime_wat2wasm C API (#1206)
* Add a wasmtime-specific `wasmtime_wat2wasm` C API

This commit implements a wasmtime-specific C API for converting the text
format to the binary format. An upstream spec issue exists for adding
this to the C API, but in the meantime we can experiment with our own
version of this API and use it in the C# extension, for example!

Closes #1000

* Reorder arguments

* Use wasm_byte_vec_t for input `*.wat`

* Mark wat input as const

* Return an error message and use `fixed`

* Actually include the error message

* Use `fixed` in `Module.cs` as well
2020-03-03 10:29:20 -06:00
Jakub Konka
ea4d2d0535 Return *mut u8 in GuestPtrMut::as_raw
Currently, we create an immutable `GuestPtr` from `self` and call
`as_raw` on it which correctly returns `*const u8`. However, since
we're dealing with `GuestPtrMut` I thought it might make more sense
to return `*mut u8` directly instead. This will be needed (and will
save us from silly casts `*const _ as *mut _`) in plugging in
`Iovec<'_>` into `std::io::IoSliceMut` in `fd_read` and `fd_pread` calls.
2020-03-03 10:19:50 +01:00
Jakub Konka
db8fec354d Add current snapshot1 WASI spec as test + fixes (#31)
* Add WASI spec (minus unions)

* Fill in all WASI shims

* Clean up derives and fix noncopy struct write method

This commit does three things:
* it uses the full, current snapshot1 WASI spec as a compilation test
* it fixes noncopy struct write method (which was incorrectly resolved
  in certain cases to the inherent method of the `GuestPtrMut` rather
  than the interface method `GuestType::write`
* it cleans up derives for structs and unions which should not auto-derive
  `PartialEq`, `Eq`, or `Hash` since their members are not guaranteed to
  be compatible
2020-03-02 23:28:13 +01:00
Alex Crichton
fe9debfed3 Update WASI submodule to update transitive wast crate (#1207)
One less version to build!
2020-03-02 11:34:04 -06:00
Alex Crichton
8597930eed rename PassiveElemIndex to ElemIndex and same for PassiveDataIndex (#1188)
* rename PassiveElemIndex to ElemIndex and same for PassiveDataIndex (#1411)

* rename PassiveDataIndex to DataIndex

* rename PassiveElemIndex to ElemIndex

* Apply renamings to wasmtime as well

* Run rustfmt

Co-authored-by: csmoe <csmoe@msn.com>
2020-03-02 08:55:25 -06:00
Nick Fitzgerald
4866fa0e6a Limit rayon to one thread during fuzzing
This should enable more deterministic execution.
2020-02-28 18:35:09 -08:00
Nick Fitzgerald
6e2bb9ebdd Limit the number of exported function calls we make in the API calls fuzzer
This should fix some fuzzing timeouts like
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20847
2020-02-28 15:48:24 -08:00
Nick Fitzgerald
f2fef600c6 Implement Arbitrary::size_hint for WasmOptTtf 2020-02-28 15:48:24 -08:00
Nick Fitzgerald
5ed9796ef3 Implement Arbitrary::size_hint for ApiCalls 2020-02-28 15:48:24 -08:00
Nick Fitzgerald
506a83d8ef Update to arbitrary@0.4.0 and libfuzzer-sys@0.3.1 2020-02-28 15:48:24 -08:00
Alex Crichton
86ff6d7aef Merge pull request #1019 from alexcrichton/cranelift-merge-for-realz
Merge the Cranelift repository into Wasmtime
2020-02-28 17:13:14 -06:00
Jakub Konka
9cc9dacc08 Escape reserved keywords in generate
This commit escapes certain (hopefully all keywords present in
snapshot1!) reserved keywords in Rust that are autogenerated by
wiggle.
2020-02-28 21:58:43 +01:00
Jakub Konka
16fe947e65 Make generated modules public
While public might be an overkill, until we successfully merge
`wiggle` with `wasi-common` (and others), I suggest we just make
the modules fully public and work from there.
2020-02-28 21:49:08 +01:00
Jakub Konka
5db335b7c7 Add EMPTY_FLAGS to flags generator
This seems like a useful primitive to have especially when dealing
with `Rights` flags in `wasi-common` (and WASI in general).
2020-02-28 21:41:17 +01:00
Pat Hickey
974f5617e0 depend on witx 0.8.3, rather than a path dependency. (#27)
and delete the submodule that was providing the path dep
2020-02-28 21:12:58 +01:00
Pat Hickey
bb6995ceaf make wiggle-generate ordinary lib, and wiggle the proc-macro lib
this allows us to reuse the code in wiggle-generate elsewhere, because
a proc-macro=true lib can only export a #[proc_macro] and not ordinary
functions.

In lucet, I will depend on wiggle-generate to define a proc macro that
glues wiggle to the specifics of the runtime.
2020-02-28 11:43:43 -08:00
Alex Crichton
0dbfad3aa7 Fix broken API doc links (#1020)
Also enable the lint to guarantee they stay un-broken.
2020-02-28 12:44:27 -06:00
Alex Crichton
5f1cba0b7f Hook up all crates via path dependencies 2020-02-28 09:16:05 -08:00
Peter Huene
121bbd3656 Merge pull request #1014 from peterhuene/c-api-module-new
Change `wasm_module_new` to use `Module::from_binary`.
2020-02-27 21:39:20 -08:00
Johnnie Birch
3e4509fd6a Update usage of target_lexicon to be consistent with v0.10 (#1003)
Jitdump was using an api consisent v0.04 for target_lexicon instead
of the version v0.10. This updates calls to target_lexicon to be
consistent with v0.10.
2020-02-27 20:43:20 -08:00
Peter Huene
b942bdbfe9 Be explicit when marshalling bool. 2020-02-27 14:12:15 -08:00
Peter Huene
7dfb6ebdb6 Change wasm_module_new to use Module::from_binary.
This commit changes the C API function `wasm_module_new` to use the Rust API
`Module::from_binary` which performs verification of the module, as per the C
API spec.

This also introduces a `EngineBuilder` type to the C# API that can be used to
construct an `Engine` with the various Wasmtime configuration options.  This
is required to get the C# tests passing since they use reference types and
multi-value.

Fixes #859.
2020-02-27 13:38:08 -08:00
Jakub Konka
0fe3f11194 Split wiggle-generate type generation into modules
This commit splits `generate/src/types.rs` into submodules, each
responsible for specifying a (compound) type. `generate/src/types.rs`
grew in size a lot, and IMHO this should yield readability and maintenance.
2020-02-27 22:21:41 +01:00
Jakub Konka
ec75f874ee Unify GuestType and GuestTypeClone, rename GuestTypeCopy to GuestTypeTransparent
This commit refactors trait system for guest types. Namely, as
discussed offline on zulip, `GuestType` now includes `GuestTypeClone`,
whereas `GuestTypeCopy` has been renamed to `GuestTypeTransparent`.
2020-02-27 21:53:52 +01:00
Jakub Konka
ed1d5180ef Add TryFromIntError to GuestError and fix error handling
While working on the full WASI spec, it turned out that we need two
tweaks to `GuestError`:
1. we need to support conversion from `TryFromIntError`, and
2. we need to invoke `e.into()` when unwrapping the result of `try_into()`
   in auto-implementation of raw interface functions.

Both problems seem to originate for "transparent" builtin types since
for those we don't really provide a `TryFrom` implementation like for
compound types, e.g., enums, flags, etc.
2020-02-27 21:46:04 +01:00
Peter Huene
1b28bade16 Merge pull request #1006 from peterhuene/update-dotnet-package-ver
Bump .NET NuGet package version to 0.12.0
2020-02-27 09:02:31 -08:00
Pat Hickey
90182bc5da Handles (#22)
* test coverage: make sure aliases to builtins get tested

* trivial support for handles

* add tests for handles
2020-02-27 11:57:36 +01:00
Pat Hickey
10dcaeeab4 factor lifetime determination into its own module 2020-02-27 11:21:40 +01:00
Pat Hickey
515b751333 latest witx 0.8.3 2020-02-27 11:21:40 +01:00
Pat Hickey
8ecbceb5de handle union result types (simplify logic) 2020-02-27 11:21:40 +01:00
Pat Hickey
126d7b6825 argument marshaling for unions 2020-02-27 11:21:40 +01:00
Pat Hickey
f6a732b6cf squash all tagged union work into one commit 2020-02-27 11:21:40 +01:00
Peter Huene
709fe0af6b Bump .NET NuGet package version to 0.12.0 2020-02-27 00:19:38 -08:00
Dan Gohman
588cdd47f9 Add dependency versions and a README.md (#1004)
* Add a version to a path dependeency for publishing on crates.io.

* Add a README.md for wasmtime-profiling.

* Add versions to the wasmtime-profiling dependencies.
2020-02-26 18:13:50 -06:00
Nick Fitzgerald
66634cc796 Do not allow partial segment initialization for tables and memories 2020-02-26 14:38:56 -08:00
Nick Fitzgerald
235833ab97 Ignore a doc test 2020-02-26 14:37:28 -08:00
Nick Fitzgerald
ef0cabf8b4 Address review feedback 2020-02-26 14:37:28 -08:00
Nick Fitzgerald
39307b2b36 Fix comments about bulk memory that incorrectly referenced "multi-value" 2020-02-26 14:35:09 -08:00
Nick Fitzgerald
81227892da Implement bulk memory's partial failure instantiation semantics
Essentially, table and memory out of bounds errors are no longer link errors,
but traps after linking. This means that the partail writes / inits are visible.
2020-02-26 14:35:09 -08:00
Nick Fitzgerald
44c28612fb Implement the memory.fill instruction from the bulk memory proposal 2020-02-26 14:35:09 -08:00
Nick Fitzgerald
98ecef1700 Implement the memory.copy instruction from the bulk memory proposal 2020-02-26 14:35:09 -08:00
Nick Fitzgerald
cb97e4ec8e Implement table.init and elem.drop from the bulk memory proposal 2020-02-26 14:35:09 -08:00
Nick Fitzgerald
33b4a37bcb Add support for table.copy
This adds support for the `table.copy` instruction from the bulk memory
proposal. It also supports multiple tables, which were introduced by the
reference types proposal.

Part of #928
2020-02-26 14:30:43 -08:00
Nick Fitzgerald
6d01fd4103 deps: Update wat to 1.0.9 2020-02-26 14:23:33 -08:00
Alex Crichton
33a39ff4f0 Bump to 0.12.0 (#997)
* Bump to 0.12.0

* Another lockfile update
2020-02-26 16:19:12 -06:00