Commit Graph

787 Commits

Author SHA1 Message Date
Adam C. Foltzer
fddd94d23f address review comments 2020-07-01 09:46:38 -07:00
Adam C. Foltzer
5a96b0deaa 🕳 Add virtual pipes to wasi-common
This introduces `Handle` implementations for readable and writable pipes, backed by arbitrary `Read`
and `Write` types, respectively. In particular, this allows for easily providing, capturing, or
redirecting WASI stdio without having to resort to OS-provided file descriptors.

The implementation is based heavily on `wasi_common::virtfs::InMemoryFile`, but without inapplicable
operations like `seek` or `allocate`.

Note that these types are not 1:1 replacements for real pipes, because they do not support `poll_oneoff`.
2020-06-30 10:44:42 -07:00
Pat Hickey
cd7fcf480b Merge pull request #1910 from bytecodealliance/pch/separate_wasmtime_wiggle_crate
Factor Wiggle's wasmtime integration into a standalone crate
2020-06-25 09:34:34 -07:00
Benjamin Bouvier
c9a3f05afd machinst x64: implement calls and int cmp/store/loads;
This makes it possible to run a simple recursive fibonacci function in
wasmtime.
2020-06-25 16:20:33 +02:00
Pat Hickey
82c4132700 simpler name, add rustdocs 2020-06-24 14:34:35 -07:00
Pat Hickey
6b62b16c7d rewrite shim func generator with witx CoreType 2020-06-24 12:47:28 -07:00
Nick Fitzgerald
1ea2f47d9c Merge pull request #1901 from fitzgen/ref-func
Support for `funcref`s, `ref.func`, and `table.grow` with `funcref`s
2020-06-24 10:53:19 -07:00
Nick Fitzgerald
58bb5dd953 wasmtime: Add support for func.ref and table.grow with funcrefs
`funcref`s are implemented as `NonNull<VMCallerCheckedAnyfunc>`.

This should be more efficient than using a `VMExternRef` that points at a
`VMCallerCheckedAnyfunc` because it gets rid of an indirection, dynamic
allocation, and some reference counting.

Note that the null function reference is *NOT* a null pointer; it is a
`VMCallerCheckedAnyfunc` that has a null `func_ptr` member.

Part of #929
2020-06-24 10:08:13 -07:00
Pat Hickey
91980b29f7 Merge pull request #1909 from siyopao/guestptr-conversion
wiggle: GuestPtr<[u8]> => GuestPtr<str> conversions
2020-06-23 21:08:44 -07:00
Pat Hickey
c6e599219a Update crates/wiggle/src/lib.rs 2020-06-23 21:08:05 -07:00
Pat Hickey
67f6aad415 Update crates/wiggle/src/lib.rs 2020-06-23 21:08:00 -07:00
Pat Hickey
564b0709dd wip 2020-06-23 18:11:38 -07:00
Pat Hickey
f66c1fbde9 reorganize configuration into modules 2020-06-23 17:42:12 -07:00
Craig Pastro
ea3c2325a5 wiggle: add as_byte_ptr: str -> [u8] method 2020-06-24 09:12:30 +09:00
Craig Pastro
7699c4d6e3 wiggle: fix lifetime in as_str_ptr 2020-06-24 09:10:59 +09:00
Nick Fitzgerald
ddc2ce8080 cranelift-wasm: Make FuncEnvironment::translate_ref_func take a FuncIndex
It was previously taking a raw `u32`. This change makes it more clear what index
space that index points into.
2020-06-23 16:36:10 -07:00
Nick Fitzgerald
c6f32f666d cranelift-wasm: Retain both the Wasm and Cranelift types of tables 2020-06-23 16:36:10 -07:00
Nick Fitzgerald
28fccaedc4 cranelift-wasm: Pass ir::Tables into all the translate_table_* methods
This serves two purposes:

1. It ensures that we call `get_or_create_table` to ensure that the embedder
already had a chance to create the given table (although this is mostly
redundant due to validation).

2. It allows the embedder to easily get the `ir::TableData` associated with this
table, and more easily emit whatever inline JIT code to translate the table
instruction (rather than falling back to VM calls).
2020-06-23 16:36:10 -07:00
Pat Hickey
69f81397a8 add func overrides, to get rid of proc exit special case 2020-06-23 16:29:11 -07:00
Pat Hickey
49c62ee828 make the missing memory error value configurable 2020-06-23 15:28:01 -07:00
Pat Hickey
62237de7ce remove logging: wiggle now provides this functionality 2020-06-23 14:49:17 -07:00
Pat Hickey
bb339aaba0 rename macro. add comments to invocation. 2020-06-23 14:16:53 -07:00
Pat Hickey
abc3982234 add target to config 2020-06-23 14:13:27 -07:00
Thibault Charbonnier
8082aeaa5f C API: expose wasmtime_linker_get_one_by_name() (#1897)
* C API: expose wasmtime_linker_get_one_by_name()

* C API: remove unnecessary 'unsafe' qualifiers

* C API: avoid unnecessary mutable borrows of the Linker
2020-06-23 14:23:49 -05:00
Alex Crichton
6f6296816b Bind Trap::i32_exit_status in C API (#1912)
This allows embedders to take a different action when a WASI program
exits depending on whether it exited with an exit status or exited with
a trap.

cc bytecodealliance/wasmtime-py#30
2020-06-23 11:40:51 -05:00
Pat Hickey
cde32070fc factor the docs out as well 2020-06-22 19:27:31 -07:00
Pat Hickey
6adbae3007 paramaterize the instance type name as well 2020-06-22 19:01:29 -07:00
Pat Hickey
09971bc090 replace more custom idents with Names 2020-06-22 18:54:07 -07:00
Pat Hickey
1050c6d99c wasmtime-wiggle-macro: re-use Names functionality
rather than try to duplicate it in utils
2020-06-22 18:47:59 -07:00
Pat Hickey
185701df1b wasmtime-wiggle-macro: adopt config system from wiggle-generate 2020-06-22 18:39:33 -07:00
Pat Hickey
7d3d16aef0 wig: delete wiggle integration functionality 2020-06-22 17:24:53 -07:00
Pat Hickey
303f7172a1 wasi: switch to use wasmtime-wiggle for wiggle integration 2020-06-22 17:23:11 -07:00
Pat Hickey
712990191a create wasmtime-wiggle crate, by copying implementation of wig 2020-06-22 17:23:06 -07:00
Craig Pastro
cf8cf9a948 wiggle: fix a couple of typos in lib.rs docs 2020-06-23 08:47:13 +09:00
Craig Pastro
f9ef734698 wiggle: GuestPtr<[u8]> => GuestPtr<str> conversions 2020-06-23 08:46:40 +09:00
Alexandru Ene
38f4ed084d Don't reuse the command between c/c++ 2020-06-19 00:14:29 +01:00
Alexandru Ene
9213717917 Run cc tests if any are found in the examples folder 2020-06-19 00:09:33 +01:00
Alexandru Ene
50ef890ae0 Fix compilation error due to redefinition. 2020-06-18 16:56:03 +01:00
Nick Fitzgerald
bbd99c5bfa reference types: Implement the table.size and table.grow instructions (#1894)
Part of #929
2020-06-18 08:57:18 -05:00
Benjamin Bouvier
c2692ecb8a Wasmtime: allow using the experimental Cranelift x64 backend in cli;
This introduces two changes:

- first, a Cargo feature is added to make it possible to use the
Cranelift x64 backend directly from wasmtime's CLI.
- second, when passing a `cranelift-flags` parameter, and the given
parameter's name doesn't exist at the target-independent flag level, try
to set it as a target-dependent setting.

These two changes make it possible to try out the new x64 backend with:

    cargo run --features experimental_x64 -- run --cranelift-flags use_new_backend=true -- /path/to/a.wasm

Right now, this will fail because most opcodes required by the
trampolines are actually not implemented yet.
2020-06-17 17:18:46 +02:00
Nick Fitzgerald
647d2b4231 Merge pull request #1832 from fitzgen/externref-stack-maps
externref: implement stack map-based garbage collection
2020-06-15 18:26:24 -07:00
Nick Fitzgerald
7e167cae10 externref: Address review feedback 2020-06-15 15:39:26 -07:00
Nick Fitzgerald
8d671c21e2 wasmtime-runtime: Allow tables to internally hold externrefs (#1882)
This commit enables `wasmtime_runtime::Table` to internally hold elements of
either `funcref` (all that is currently supported) or `externref` (newly
introduced in this commit).

This commit updates `Table`'s API, but does NOT generally propagate those
changes outwards all the way through the Wasmtime embedding API. It only does
enough to get everything compiling and the current test suite passing. It is
expected that as we implement more of the reference types spec, we will bubble
these changes out and expose them to the embedding API.
2020-06-15 16:55:23 -05:00
Nick Fitzgerald
618c278e41 externref: implement a canary for GC stack walking
This allows us to detect when stack walking has failed to walk the whole stack,
and we are potentially missing on-stack roots, and therefore it would be unsafe
to do a GC because we could free objects too early, leading to use-after-free.
When we detect this scenario, we skip the GC.
2020-06-15 09:39:37 -07:00
Nick Fitzgerald
f30ce1fe97 externref: implement stack map-based garbage collection
For host VM code, we use plain reference counting, where cloning increments
the reference count, and dropping decrements it. We can avoid many of the
on-stack increment/decrement operations that typically plague the
performance of reference counting via Rust's ownership and borrowing system.
Moving a `VMExternRef` avoids mutating its reference count, and borrowing it
either avoids the reference count increment or delays it until if/when the
`VMExternRef` is cloned.

When passing a `VMExternRef` into compiled Wasm code, we don't want to do
reference count mutations for every compiled `local.{get,set}`, nor for
every function call. Therefore, we use a variation of **deferred reference
counting**, where we only mutate reference counts when storing
`VMExternRef`s somewhere that outlives the activation: into a global or
table. Simultaneously, we over-approximate the set of `VMExternRef`s that
are inside Wasm function activations. Periodically, we walk the stack at GC
safe points, and use stack map information to precisely identify the set of
`VMExternRef`s inside Wasm activations. Then we take the difference between
this precise set and our over-approximation, and decrement the reference
count for each of the `VMExternRef`s that are in our over-approximation but
not in the precise set. Finally, the over-approximation is replaced with the
precise set.

The `VMExternRefActivationsTable` implements the over-approximized set of
`VMExternRef`s referenced by Wasm activations. Calling a Wasm function and
passing it a `VMExternRef` moves the `VMExternRef` into the table, and the
compiled Wasm function logically "borrows" the `VMExternRef` from the
table. Similarly, `global.get` and `table.get` operations clone the gotten
`VMExternRef` into the `VMExternRefActivationsTable` and then "borrow" the
reference out of the table.

When a `VMExternRef` is returned to host code from a Wasm function, the host
increments the reference count (because the reference is logically
"borrowed" from the `VMExternRefActivationsTable` and the reference count
from the table will be dropped at the next GC).

For more general information on deferred reference counting, see *An
Examination of Deferred Reference Counting and Cycle Detection* by Quinane:
https://openresearch-repository.anu.edu.au/bitstream/1885/42030/2/hon-thesis.pdf

cc #929

Fixes #1804
2020-06-15 09:39:37 -07:00
SlightlyOutOfPhase
0303834082 Fix lightbeam compilation by updating staticvec dependency to version 0.10 (#1878)
* Update StaticVec dependency from 0.9 to 0.10

* Update lockfile also
2020-06-15 09:05:26 -05:00
Jakub Konka
60d55a3483 Remove a runaway explicit drop 2020-06-13 15:55:01 +02:00
bjorn3
9788b02dd5 Bump object to 0.19.0 (#1767)
* Bump object to 0.19.0
2020-06-12 15:37:04 -05:00
Dan Gohman
caa87048ab Wasmtime 0.18.0 and Cranelift 0.65.0. 2020-06-11 17:49:56 -07:00
Yury Delendik
70424037c3 Refactor debug library to use object:🧝:* (#1860)
* Add GDB test

* rm stray test resource

* use object:🧝:* structures

* install gdb on CI
2020-06-11 13:53:38 -05:00