Commit Graph

847 Commits

Author SHA1 Message Date
Nick Fitzgerald
ec331a088c run-examples: Provide more error context for debugging
Use `anyhow` for nice errors and provide error context on commands that we run.
2020-07-10 13:51:58 -07:00
Nick Fitzgerald
89603bc6b3 wasmtime-c-api: Make wasm_table_set *not* take ownership of its reference
Same for `wasm_table_grow` and `wasm_table_new` and their `init` values.
2020-07-10 13:09:08 -07:00
Nick Fitzgerald
d07fdca73a wasmtime-c-api: Use a safe helper for initializing MaybeUninit out pointers 2020-07-10 13:09:08 -07:00
Nick Fitzgerald
377b213fd5 wasmtime-c-api: Remove unused HostInfoState struct 2020-07-10 13:09:08 -07:00
Nick Fitzgerald
b73b2e0d5a wasmtime-c-api: Make wasmtime_externref_new write to an out pointer
The C API prefers not to return structs by value.

Same for `wasmtime_externref_new_with_finalizer`.
2020-07-10 13:09:08 -07:00
Nick Fitzgerald
b9bb095e0f wasmtime-c-api: Remove nested options from wasm_ref_t representation 2020-07-10 13:09:08 -07:00
Nick Fitzgerald
742f8ee1fc wasmtime-c-api: Make wasmtime_externref_new proxy to wasmtime_externref_new_with_finalizer 2020-07-10 13:09:08 -07:00
Nick Fitzgerald
5ed8a9ba0e wasmtime-c-api: Add an externrefs example for the C API 2020-07-10 13:09:08 -07:00
Nick Fitzgerald
267bf16683 wasmtime-c-api: Add Wasmtime-specific APIs for externrefs
This commit adds APIs to create new `externref` values (with and without
finalizers) and to get an `externref`'s wrapped data.
2020-07-10 13:09:08 -07:00
Nick Fitzgerald
4c01ffd087 wasmtime-c-api: Document new reference types support 2020-07-10 13:09:08 -07:00
Nick Fitzgerald
aaf4c941b8 wasmtime-c-api: Add support for funcref values 2020-07-10 13:09:08 -07:00
Nick Fitzgerald
4cdf8b7cfd wasmtime-c-api: Add support for externref values
This required that `wasm_val_t` have a `Drop` implementation, an explicit
`Clone` implementation, and no longer be `Copy`, which rippled out through the
crate a bit.

Additionally, `wasm_func_call` and friends were creating references to
uninitialized data for its out pointers and assigning to them. As soon as
`wasm_val_t` gained a `Drop` impl and tried to drop the old value of the
assignment (which is uninitialized data), then things blew up. The fix is to
properly represent the out pointers with `MaybeUninit`, and use `ptr::write` to
initialize them without dropping the old data.

Part of #929
2020-07-10 13:09:08 -07:00
Nick Fitzgerald
62655cdbe7 wasmtime: Document support for {extern,func}ref in Func::wrap 2020-07-07 14:27:07 -07:00
Nick Fitzgerald
392bbadac7 wasmtime: Ensure that Func::wrap'd return values are compatible with the current store 2020-07-07 14:27:07 -07:00
Nick Fitzgerald
3e63774e99 wasmtime: Add support for Option<Func> args and returns in Func::wrap 2020-07-07 11:09:20 -07:00
Nick Fitzgerald
46ef80bf2f wasmtime: Support ExternRefs in Func::wrap'd functions
Fixes #1868
2020-07-07 11:09:20 -07:00
Nick Fitzgerald
44e6fae29c wasmtime: Modify WasmTy and WasmRet for future {extern,func}ref support 2020-07-07 11:09:20 -07:00
Yury Delendik
bef1b87be0 Write ELF image and instantiate code_memory from it (#1931)
- Create the ELF image from Compilation
- Create CodeMemory from the ELF image
- Link using ELF image
- Remove creation of GDB JIT images from crates/debug
- Move make_trampoline from compiler.rs
2020-07-07 12:51:24 -05:00
Gabor Greif
79f054f77f Correct the files' directory index when downgrading DWARF5 -> 4 (#1989)
* correct the files' directory index when downgrading DWARF5 -> 4
2020-07-07 11:20:32 -05:00
Yury Delendik
9900641674 Support reference types in the DWARF transform (#1986) 2020-07-07 09:43:03 -05:00
Nick Fitzgerald
a7c6433773 wasmtime: Support reference types in the Rust API
This is a mix of exposing new things (e.g. a `Table::fill` method) and extending
existing support to `externref`s (e.g. `Table::new`).

Part of #929
2020-07-06 14:21:32 -07:00
Dan Gohman
cf5289c553 Begin porting yanix to WASI.
This isn't complete yet, but subsequent steps will depend on Rust libstd
and libc bindings changes that are in flight.
2020-07-06 20:20:28 +02:00
Nick Fitzgerald
25397d0c15 Merge pull request #1982 from fitzgen/fuzz-reference-types
fuzzing: Enable reference types by default
2020-07-06 10:27:09 -07:00
Daiki Ueno
2ce2dd0203 wasmtime: add build-time option for parallel compilation (#1903)
When running in embedded environments, threads creation is sometimes
undesirable. This adds a feature to toggle wasmtime's internal thread
creation for parallel compilation.
2020-07-06 11:22:05 -05:00
Nick Fitzgerald
9b56203732 fuzzing: Enable reference types by default
Part of #929
2020-07-06 09:18:52 -07:00
Nick Fitzgerald
80ff22fd18 Merge pull request #1973 from fitzgen/table-fill
wasmtime: Implement `table.fill`
2020-07-06 09:03:25 -07:00
Graham Scheaffer
ef8fe18262 Updated region versions (#1978) 2020-07-06 09:26:28 -05:00
Nick Fitzgerald
3555f97906 wasmtime: Implement table.fill
Part of #929
2020-07-02 16:59:07 -07:00
Johnnie Birch
60681d7019 Add __dso_handle to exception list of deprecated export symbols
When compiling C to WASM with clang-8, __dso_handle is a global
that maybe exported but that currently is not whitelisted along
with __heap_base and _data_end to be handled as allowable depricated
exports. This PR adds the case for __dso_handle.
2020-07-02 14:58:53 -07:00
Nick Fitzgerald
bffd54c016 wasmtime: Implement global.{get,set} for externref globals (#1969)
* wasmtime: Implement `global.{get,set}` for externref globals

We use libcalls to implement these -- unlike `table.{get,set}`, for which we
create inline JIT fast paths -- because no known toolchain actually uses
externref globals.

Part of #929

* wasmtime: Enable `{extern,func}ref` globals in the API
2020-07-02 16:04:01 -05:00
Nick Fitzgerald
3fa3ff2ece Merge pull request #1968 from alexcrichton/link-c-docs
Link to C API docs and make a landing page
2020-07-02 13:28:20 -07:00
Sergei Shulepov
ce51995828 Use smallvec for avoid allocations in the trampoline (#1965) 2020-07-02 11:24:03 -05:00
Alex Crichton
920e0984d3 Link to C API docs and make a landing page
Spice up the landing page a bit for the C API documentation and then
link to it from a few places to ensure it's discoverable.
2020-07-02 08:49:27 -07:00
Alex Crichton
47a218f908 Document the rest of the C API (#1959)
This commit fills out documentation for all remaining functions in the C
API, and additionally enables "warn if undocumented" which will fail CI
since warnings are also treated as errors.
2020-07-02 09:26:10 -05:00
Pat Hickey
301277e60d Merge pull request #1961 from bytecodealliance/pch/sync_wasi_pipe
wasi-common virtfs pipe: convert to be Send and Sync; fix Clone
2020-07-01 22:54:25 -07:00
Pat Hickey
e7869c7320 virtfs pipe: implement Clone correctly
* The underlying `R`/`W` doesnt need to be Clone, since we just need to
  clone the Arc it sits behind.
* The rights actually shouldn't be behind an Arc - those get mutated
  separately in each clone.
2020-07-01 17:54:30 -07:00
Pat Hickey
cf303d91fc wasi-common virtfs pipe: convert to be Send and Sync 2020-07-01 14:51:30 -07:00
Alex Crichton
d72b330de2 Add support for documenting the C API (#1928)
This commit adds a bit of a skeleton of what it might look like to
document the C API. Today the C API has virtually zero documentation
because the upstream documentation does not exist and we haven't put a
ton of effort into documenting our own extensions. Given that this is
one of the main vectors we expect users to use Wasmtime, we should make
sure it's thoroughly documented!

I've never really done much documentation generation of C myself before,
but I did a bit of searching and Doxygen seems reasonable proficient for
doing this. This commit sets up what it might look like for Doxygen to
be used for the C API. One nice feature of DOxygen is that we can
document the items in `wasm.h` without actually modifying `wasm.h`. For
those purposes a `doc-wasm.h` file was added here which is where we can
put Wasmtime-specific documentation about `wasm.h`.

There's quite a few functions in the C API so I didn't want to get them
all done before getting consensus on this. I've started some skeletons
of documentation for global types in `wasm.h` and also confirmed that
documentation works for our own `wasmtime.h` and such header files. If
this looks good to everyone and it runs reasonable well on CI then I can
spend more time filling out the rest of the documentation.
2020-07-01 14:05:18 -05:00
Alex Crichton
f24c7e1249 Expand top-level wasmtime crate docs (#1955)
This is something I meant to do a long time ago but forgot to get around
to it! This commit updates the top-level documentation of the `wasmtime`
crate to have examples, more words, and generall be a bit more
up-to-date and complete.
2020-07-01 14:04:29 -05:00
Dan Gohman
b37adbbe31 Rename OFlag/AtFlag to OFlags/AtFlags. (#1951)
* Rename `OFlag`/`AtFlag` to `OFlags`/`AtFlags`.

This makes them consistent with `PollFlags` and common usage of
bitflags types in Rust code in general.

POSIX does tend to use names like `oflag` and `flag`, so this is in mild
disagreement with POSIX style, however I find this particular aspects of
POSIX confusing because these values hold multiple flags.

* rustfmt
2020-07-01 20:53:16 +02:00
Adam C. Foltzer
4f16f0dc32 Merge pull request #1949 from bytecodealliance/acf/virtual-pipes
🕳 Add virtual pipes to wasi-common
2020-07-01 11:26:13 -07:00
Adam C. Foltzer
fddd94d23f address review comments 2020-07-01 09:46:38 -07:00
Till Schneidereit
f80c2abffb Update various crates' object and wast dependencies (#1908)
This somewhat cuts down on duplicate dependencies. `wast` is used in a much older version (`11.0.0`) by `witx`, and can be updated without issues there as well, but this at least gets us from 3 copies to 2.
2020-07-01 09:11:38 -05:00
Pat Hickey
ec76f3207a Merge pull request #1938 from bytecodealliance/pch/factor_borrowchecker_out_of_wiggle
wiggle: factor BorrowChecker concrete implementation to live in engines
2020-06-30 13:08:29 -07:00
Nick Fitzgerald
a2f4202800 cranelift-frontend: Add the FunctionBuilder::insert_block_after method 2020-06-30 12:00:57 -07:00
Nick Fitzgerald
98e899f6b3 fuzz: Add a fuzz target for table.{get,set} operations
This new fuzz target exercises sequences of `table.get`s, `table.set`s, and
GCs.

It already found a couple bugs:

* Some leaks due to ref count cycles between stores and host-defined functions
  closing over those stores.

* If there are no live references for a PC, Cranelift can avoid emiting an
  associated stack map. This was running afoul of a debug assertion.
2020-06-30 12:00:57 -07:00
Nick Fitzgerald
8c5f59c0cf wasmtime: Implement table.get and table.set
These instructions have fast, inline JIT paths for the common cases, and only
call out to host VM functions for the slow paths. This required some changes to
`cranelift-wasm`'s `FuncEnvironment`: instead of taking a `FuncCursor` to insert
an instruction sequence within the current basic block,
`FuncEnvironment::translate_table_{get,set}` now take a `&mut FunctionBuilder`
so that they can create whole new basic blocks. This is necessary for
implementing GC read/write barriers that involve branching (e.g. checking for
null, or whether a store buffer is at capacity).

Furthermore, it required that the `load`, `load_complex`, and `store`
instructions handle loading and storing through an `r{32,64}` rather than just
`i{32,64}` addresses. This involved making `r{32,64}` types acceptable
instantiations of the `iAddr` type variable, plus a few new instruction
encodings.

Part of #929
2020-06-30 12:00:57 -07:00
Dan Gohman
959e424c81 Add O_PATH and O_CLOEXEC to yanix. (#1946)
* Add O_PATH and O_CLOEXEC to yanix.

While here, update the Wasmtime git branch name in a comment.

* Add AT_EMPTY_PATH too.
2020-06-30 11:26:59 -07:00
Pat Hickey
d5836e2c12 Merge remote-tracking branch 'origin/main' into pch/factor_borrowchecker_out_of_wiggle 2020-06-30 11:25:23 -07:00
Alex Crichton
0acd2072c2 Fix doc warnings and link failures (#1948)
Also add configuration to CI to fail doc generation if any links are
broken. Unfortunately we can't blanket deny all warnings in rustdoc
since some are unconditional warnings, but for now this is hopefully
good enough.

Closes #1947
2020-06-30 13:01:49 -05:00