Commit Graph

6452 Commits

Author SHA1 Message Date
Jakub Konka
694cf117bb Add proptests for structs with mixed members (copy/noncopy) 2020-02-26 18:23:46 +01:00
Jakub Konka
7a4c881409 Fix read/write for GuestTypeCopy members of non-copy structs
This commit fixes stubs for struct members that are `GuestTypeCopy`
but are not `GuestTypeClone`. In this case, we cannot rely on methods
`T::read_from_guest` or `T::write_to_guest` since these are only
available if `T: GuestTypeClone`. In those cases, we can and should
dereference the location pointer to `T` and copy the result in/out
respectively.
2020-02-26 18:23:46 +01:00
Dan Gohman
d55a9967b1 Remove some obsolete re-exports in wasmtime-jit. (#992)
These were from when wasmtime-jit was trying to present a different API;
now they're not needed.
2020-02-26 05:13:28 -08:00
Dan Gohman
e41cae7db9 Fix the WASI-tutorial to handle short writes properly. (#991)
If write doesn't write the full buffer, start the next write at the
point where the write left off.

Also, usize `ssize_t` for the return types of `read` and `write`.
2020-02-25 23:12:43 -06:00
bjorn3
0a1bb3ba6c Add TLS support for ELF and MachO (#1174)
* Add TLS support
* Add binemit and legalize tests
* Spill all caller-saved registers when necessary
2020-02-25 17:50:04 -08:00
Alex Crichton
4b2c56e655 Retry the entire release process, not just uploading one asset (#989)
Another attempt to mitigate #978
2020-02-25 19:46:41 -06:00
Alex Crichton
ab213780cd Fix a syntax error in deployment (#987)
I have no idea how to test this code other than run it live :(
2020-02-25 18:33:11 -06:00
Peter Huene
78b32e2527 Merge pull request #977 from peterhuene/wasi-c-api
Implement a WASI instantiation C API.
2020-02-25 16:25:09 -08:00
Marcin Mielniczuk
150a3e588b Fix a possible overflow due to use of fionread in poll_oneoff on Unix. (#881)
Closes #578.
2020-02-25 16:04:46 -08:00
Peter Huene
c92bf4d863 Rename wasi_config_set_std[in|out|err].
This commit renames `wasi_config_set_std[in|out|err]` to
`wasi_config_set_std[in|out|err]_file` so we can reserve the former for
when the C API supports a stream abstraction.
2020-02-25 15:41:21 -08:00
Peter Huene
fa65a14dba Make WasiCtxBuilder by-ref.
This commit makes `WasiCtxBuilder` take `&mut Self` and return `&mut
Self` for its methods.  This is needed to allow for the same
(unmoved) `WasiCtxBuilder` to be used when building a WASI context.

Also fixes up the C API to remove the unnecessary `Box::from_raw` and
`forget` calls which were previously needed for the moving version of
`WasiCtxBuilder`.
2020-02-25 15:41:18 -08:00
Alex Crichton
5bed47631a Retry uploading release assets if they fail (#982)
This is an attempt to mitigate #978. I'm not really sure if it'll work,
but seems like it's worth trying!
2020-02-25 17:14:36 -06:00
Peter Huene
07066835db Implement PartialEq on FuncType. 2020-02-25 13:41:16 -08:00
Nick Fitzgerald
7341e2fb14 Merge pull request #980 from alexcrichton/mdbook-test
Test book documentation on CI
2020-02-25 13:25:18 -08:00
Peter Huene
104919eb79 Remove Drop impl for wasi_instance_t. 2020-02-25 12:58:38 -08:00
Alex Crichton
345db5b194 Install submodules as well 2020-02-25 09:28:28 -08:00
Alex Crichton
c7fb135452 Test book documentation on CI
Make sure the embedding API follows what's currently implemented!
2020-02-25 08:52:43 -08:00
Gustav Eiman
09a091802b Update rust embed example (#967) (#968)
* Update rust embed example (#967)

Ensures that the example works with the current API.
Drops mention of HostRef as the example is complete without it.

* Cleanup
2020-02-25 09:45:21 -06:00
Peter Huene
4e1d2a2fc1 Favor using non-braced using statement. 2020-02-24 18:44:37 -08:00
Peter Huene
a6ec8f85a6 Loop the array of strings only once.
Remove unnecessary loop when marshaling lists of strings as pointers to UTF-8
bytes.
2020-02-24 18:26:26 -08:00
Peter Huene
78ee043524 Ensure marshaled UTF-8 string arrays are null terminated. 2020-02-24 18:20:27 -08:00
Peter Huene
8dff0fc121 Fix unit tests on Windows.
Close the file descriptors before attempting to reopen the files.
2020-02-24 17:56:55 -08:00
Peter Huene
11dec4d788 Add WASI unit tests for the C# API. 2020-02-24 17:42:49 -08:00
Peter Huene
ae0b4090ce Implement WASI C API.
This commit implements an initial WASI C API that can be used to instantiate
and configure a WASI instance from C.

This also implements a `WasiBuilder` for the C# API enabling .NET hosts to bind
to Wasmtime's WASI implementation.
2020-02-24 17:42:44 -08:00
Nick Fitzgerald
f8abe1169c Merge pull request #975 from fitzgen/update-cranelift-to-0.59.0
Update cranelift to 0.59.0
2020-02-24 15:52:37 -08:00
Nick Fitzgerald
de4ad31cbd Update cranelift to 0.59.0 2020-02-24 15:21:27 -08:00
Dan Gohman
0a11736fbf Bump version to 0.59.0 (#1406) 2020-02-24 15:10:08 -08:00
Nick Fitzgerald
be553aef78 Merge pull request #970 from alexcrichton/document-release
Document and codify the release process
2020-02-24 14:41:09 -08:00
Alex Crichton
d4fcd32cdc Optimize generated code via the CLI by default (#973)
* Optimize generated code via the CLI by default

This commit updates the behavior of the CLI and adds a new flag. It
first enables the `--optimize` flag by default, ensuring that usage of
the `wasmtime` CLI will enable cranelift optimizations by default. Next
it also adds a `--opt-level` flag which is similar to Rust's
`-Copt-level` where it takes a string argument of how to optimize. This
is updates to support 0/1/2/s, where 1 is currently the same as 2 but
added for consistency with other compilers. The default setting is
`--opt-level=2`.

When the `-O` flag is not passed the `--opt-level` flag is used,
otherwise `-O` takes precedent in the sense that it implies
`--opt-level=2` which is the highest optimization level. The thinking is
that these flags will in general select the highest optimization level
specified as the final optimization level.

* Add inline docs

* fix a test
2020-02-24 15:18:08 -06:00
Jakub Konka
678065011e Implement fmt::Display for enums, flags, and ints (#18)
* Implement fmt::Display for enums

`wasi_common` relies on `strerror` to nicely format error messages.
`strerror` is autoimplemented in `wig`. I thought it might be useful
to provide a Rust-idiomatic alternative which boils down to autoimplementing
`fmt::Display` for all enums.

* Implement fmt::Display for flags

* Implement fmt::Display for ints
2020-02-24 21:11:08 +01:00
Alex Crichton
13523e6312 Attempt to fix publication to Pypi (#971)
This commit is an attempt to fix the issue pointed out at
https://github.com/bytecodealliance/wasmtime/issues/312#issuecomment-576429580
where our publication to pypi is failing (and causes our binary release
process to also fail). By updating the dependency here we should pull in
the necessary support to support the `packages_dir` option.
2020-02-24 13:20:38 -06:00
Alex Crichton
12cff023b6 Document and codify the release process
The `wasmtime` release procees seems like it's been a bit ad-hoc up to
this point, so I figured it'd be good to try to document what we do
today and codify what should be done as well as a form of release
checklist.

I've noticed that we have a number of releases (like v0.11.0) but the
`Cargo.toml` files in the repository don't reflect the current version
of `wasmtime`. Additionally I've noticed that the [most recent release]
ended up having failed tests because `Cargo.toml` was modified but
`Cargo.lock` wasn't updated. I'm hoping that by having a checklist we
can avoid these sorts of accidental issues in the future!

[release]: https://github.com/bytecodealliance/wasmtime/runs/434690272
2020-02-24 10:46:50 -08:00
Andrew Brown
78bf63c76d Translate Wasm SIMD's avgr_u to Cranelift's new avg_round instruction 2020-02-24 09:48:38 -08:00
Andrew Brown
032e81fd6f Add x86 SIMD average rounding 2020-02-24 09:48:38 -08:00
Jakub Konka
4fe397ea43 Refactor and combine all FileType structs in yanix
This commit does a bit of everything: refactors bits here and there,
fixes a bug discovered in another #701, and combines all structs that
we used in `yanix` and `wasi-common` crates to represent file types
on *nix into one struct, `yanix::file::FileType`.

Up until now, in `yanix`, we've had two separate structs used to
represent file types on the host: `yanix::dir::FileType` and
`yanix::file::SFlags` (well, not quite, but that was its main use).
They both were used in different context (the former when parsing
`dirent` struct, and the latter when parsing `stat` struct), they
were C-compatible (as far as their representation goes), and as it
turns out, they shared possible enumeration values. This commit
combines them both into an idiomatic Rust enum with the caveat that
it is now *not* C-compatible, however, I couldn't find a single use
where that would actually matter, and even if it does in the future,
we can simply add appropriate impl methods.

The combine `yanix::file::FileType` struct can be constructed in two
ways: 1) either from `stat.st_mode` value (and while we're here,
now it's done correctly according to POSIX which fixes the bug mentioned
in VFS impl PR #701), or 2) from `dirent.d_type` value. Also, since we now
have one struct for representing both contexts, this cleans up nicely
a lot of duplicated code in `host` module.
2020-02-24 15:18:26 +01:00
nalmt
830bdd5127 Add maximum threshold for number of blocks per function #951
To fix this case that may take forever to compile:

function %a(){
ebb477777777:
}

We decide to define a maximum threshold for the number of blocks in functions.

Based on a large WASM program (https://github.com/mozilla/perf-automation/blob/master/benchmarks/wasm-misc/AngryBots.wasm),
its IR functions does not exceed 1414 blocks. A number 100 times greater (100,000 blocks) seems (currently) enough to define our maximum threshold.

To make this quick benchmark the cranelift-wasm/src/func_translator.rs file has been modified like this:

static mut MAX: usize = 0;

pub fn translate_from_reader<FE: FuncEnvironment + ?Sized>(...) {

    [...]

    builder.finalize();

    // the compiler is single threaded
    unsafe {
        if func.dfg.num_ebbs() > MAX {
            MAX = func.dfg.num_ebbs();
            println!("MAX {}", MAX);
        }
    }

    Ok(())
}
2020-02-24 10:10:38 +01:00
Josh Triplett
5e05aa1b03 Update to wasmparser 0.51
wasmparser::BinaryReaderError now encapsulates its fields, so call the
accessors rather than destructuring to get the fields.
2020-02-22 21:26:27 -08:00
Josh Triplett
aa78d491b0 Make Func::getN return a Result rather than an Option (#966)
This allows getN to return a detailed explanation of any type signature
mismatch, and makes it easy to just use `?` on the result of getN rather
than constructing a (necessarily vaguer) error message in the caller.
2020-02-22 17:56:23 -06:00
Josh Triplett
48202e0c31 Update dependencies to current versions, reducing duplicate versions (#963)
* Cargo.lock: Update, to no longer use multiple versions of autocfg

* Update wasmtime-debug and wasmtime-profiling to current gimli 0.20.0

This also eliminates duplicate versions of gimli and arrayvec, and
eliminates the nodrop dependency entirely.

* Update wasmtime-profiling to goblin 0.1.3 and object 0.17.0

This also eliminates two duplicate versions of goblin, and duplicate
versions of proc-macro2, quote, syn, scroll_derive, and unicode-xid.

* Update wasmtime-profiling to current scroll 0.10.1

This eliminates duplicate versions of scroll.

* Update wasmtime-profiling to current target-lexicon 0.10.0

This eliminates duplicate versions of target-lexicon.

* Update wasmtime-interface-types to current walrus and wasm-webidl-bindings

This also eliminates the oldest of the three duplicate versions of
wasmparser.

* Update wasmtime-wast to current wast 8.0.0

This eliminates one of the duplicate versions of wast.
2020-02-22 17:10:44 -06:00
Josh Triplett
8be80cbd0d Extend Func::getN up to get10, allowing up to 10-argument functions (#965)
* Func: Number type arguments rather than using successive letters

This simplifies future extension, and avoids potential conflicts with
other type argument names.

* Extend Func::getN up to get10, allowing up to 10-argument functions
2020-02-22 17:09:06 -06:00
Pat Hickey
b7cd003b93 finish factoring tests (#17)
* atoms in one test unit

* factor out pointers test

* factor structs into separate test unit

* factor out arrays, flags

* finally, separate into strings and ints
2020-02-22 10:17:27 +01:00
Nathan Froyd
09c6c5db44 add a "raw" function definition interface to cranelift-module (#1400)
* move trap site definitions into cranelift-module

`cranelift-faerie` and `cranelift-object` already have identical
definitions of structures to represent trap sites.  We might as well
merge them ahead of work to define functions via a raw slice of bytes
with associated traps, which will need some kind of common structure for
representing traps anyway.

* cranelift-module: add `define_function_bytes` interface

This interface is useful when the client needs to precisely specify the
ordering of bytes in a particular function.

* add comment about saving files for `perf`
2020-02-21 15:14:37 -08:00
Pat Hickey
3be9d48bc6 Merge pull request #16 from kubkon/pch/factor_tests
Start factoring tests
2020-02-21 15:04:50 -08:00
Pat Hickey
f77000ad8f move ctx into wiggle-tests crate 2020-02-21 13:58:28 -08:00
Pat Hickey
2feab2ee2b fixes 2020-02-21 13:55:49 -08:00
Pat Hickey
8a110e4b13 first pass at splitting out a test, making ctx/errno reusable 2020-02-21 13:54:03 -08:00
Pat Hickey
0909cf2660 tests: factor common HostMemory / MemArea code into a separate crate 2020-02-21 13:54:03 -08:00
Jakub Konka
f48474b247 Draft out IntDatatype in wiggle-generate (#15)
* Draft out IntDatatype in wiggle-generate

This commit drafts out basic layout for `IntDatatype` structure in
`wiggle`. As it currently stands, an `Int` type is represented as
a one-element tuple struct much like `FlagDatatype`, however, with
this difference that we do not perform any checks on the input
underlying representation since any value for the prescribed type
is legal.

* Finish drafting IntDatatype support in wiggle

This commit adds necessary marshal stubs to properly pass `IntDatatype`
in and out of interface functions. It also adds a basic proptest.
2020-02-21 22:53:10 +01:00
Jakub Konka
6ab3ff71d2 Add basic GuestString support to wiggle (#13)
* Add basic GuestString support to wiggle

This commit adds basic `GuestString` support to `wiggle`. `GuestString`
is a wrapper around `GuestArray<'_, u8>` array type which itself can
be made into either an owned (cloned) Rust `String` or borrowed as
a reference `&str`. In both cases, `GuestString` ensures that the
underlying bytes are valid Unicode code units, throwing a `InvalidUtf8`
error if not.

This commit adds support *only* for passing in strings as arguments
in WASI. Marshalling of the return arg has not yet been implemented.
I'm not even sure it's possible without multi-value return args
feature of Wasm. It's not a major setback especially since the WASI
spec (and this includes even the `ephemeral` snapshot) doesn't
return strings anywhere. They are only ever passed in as arguments
to interface functions.

It should be noted that error returned in case of invalid UTF-8
requires a lot more love as it doesn't include anything besides
flagging an event that the string contained an invalid Unicode code unit.

* Borrow all of string's memory including nul-byte

Borrow all of string's underlying memory including the nul-byte.
This perhaps might not have a tremendous impact on anything, but
since the nul-byte is technically part of the WASI string, we should
include it in the borrow as well.

* Fill in wiggle-generate blanks for strings

* Print to screen passed string in proptest

* Strings are PointerLengthPairs!

* Fix generation of strings in compound types

* Update test with simple string strategy

* Generate better test strings

* Finalise proptest for strings

* Fix formatting

* Update crates/runtime/src/memory/string.rs

Removes unnecessary comment in code

* Apply Pat's suggestion to wrap Utf8Error as error
2020-02-21 22:37:22 +01:00
Sergei Shulepov
c5d6805284 Revert "Temporarily disable fuzzing until #1216 is resolved (#1224)"
This reverts commit 589fa95a05b3bc6dfe4076ed29fa02d6f0d3d349.
2020-02-21 10:54:35 -08:00