Commit Graph

577 Commits

Author SHA1 Message Date
Peter Huene
9de0ab302c Remove the .NET implementation. (#1477)
This commit removes the .NET implementation from Wasmtime.

It now exists at https://github.com/bytecodealliance/wasmtime-dotnet.

Also updates the Wasmtime book to include information about using Wasmtime from
.NET.
2020-04-06 20:03:49 -05:00
Alex Crichton
bd374fd6fc Add Wasmtime-specific C API functions to return errors (#1467)
* Add Wasmtime-specific C API functions to return errors

This commit adds new `wasmtime_*` symbols to the C API, many of which
mirror the existing counterparts in the `wasm.h` header. These APIs are
enhanced in a number of respects:

* Detailed error information is now available through a
  `wasmtime_error_t`. Currently this only exposes one function which is
  to extract a string version of the error.

* There is a distinction now between traps and errors during
  instantiation and function calling. Traps only happen if wasm traps,
  and errors can happen for things like runtime type errors when
  interacting with the API.

* APIs have improved safety with respect to embedders where the lengths
  of arrays are now taken as explicit parameters rather than assumed
  from other parameters.

* Handle trap updates

* Update C examples

* Fix memory.c compile on MSVC

* Update test assertions

* Refactor C slightly

* Bare-bones .NET update

* Remove bogus nul handling
2020-04-06 15:13:06 -05:00
Maciej Kot
78c548dc8f Option for host managed memory (#1400)
* Option for host managed memory

* Rename Allocator to MemoryCreator

* Create LinearMemory and MemoryCreator traits in api

* Leave only one as_ptr function in LinearMemory trait

* Memory creator test

* Update comments/docs for LinearMemory and MemoryCreator traits

* Add guard page to the custom memory example

* Remove mut from LinearMemory trait as_ptr

* Host_memory_grow test
2020-04-06 09:52:43 -05:00
Pat Hickey
c2cb4ea3ff Wiggle: tweaks to internal interfaces (#1469)
* [wiggle]: wiggle-generate internal interface for Names simplified

im using it in other libraries where I don't want to construct a
wiggle_generate::Config just to use the ctx_type out of it.

* wiggle: define_func can get trait name as argument

this flexibility needed for some customization over in lucet
2020-04-06 09:51:17 -05:00
Dan Gohman
9ca3bf532e Increase the size of the sigaltstack. (#1315)
* Increase the size of the sigaltstack.

Rust's stack overflow handler installs a sigaltstack stack with size
SIGSTKSZ, which is too small for some of the things we do in signal
handlers, and as of this writing lacks a guard page. Install bigger
sigaltstack stacks so that we have enough space, and have a guard page.
2020-04-03 16:36:17 -05:00
Dan Gohman
fde5ddf159 Fixes for 0.15 (#1449)
* Wasmtime 0.15.0 and Cranelift 0.62.0. (#1398)

* Bump more ad-hoc versions.

* Add build.rs to wasi-common's Cargo.toml.

* Update the env var name in more places.

* Remove a redundant echo.
2020-04-03 13:13:37 -07:00
Marcin Mielniczuk
f6e3ab03a2 Implement path_link for Windows. (#1199)
Implement path_link for Windows.
2020-04-03 21:24:38 +02:00
Alex Crichton
7728703ec7 Remove stray file in C API (#1464)
Forgot to delete this from a previous PR!
2020-04-03 13:53:33 -05:00
Nick Fitzgerald
244ed4191b Fix the C API crate's tests 2020-04-02 10:02:07 -07:00
Johnnie Birch
dff789c7c6 Adds JIT profiling support for VTune (#819)
This patch adds initial support for ittapi which is an open
source profiling api for instrumentation and tracing and profiling
of jitted code. Result files can be read by VTune for analysis

Build:
    cargo build --features=vtune
Profile: // Using amplxe-cl from VTune
    amplxe-cl -v -collect hostpost target/debug/wasmtime --vtune test.wasm
2020-04-02 09:04:08 -05:00
Alex Crichton
1a0325014f Remove the wasmtime Python extension from this repo (#1457)
* Remove the wasmtime Python extension from this repo

This commit removes the `crates/misc/py` folder and all associated
doo-dads like CI. This module has been rewritten to use the C API
natively and now lives at
https://github.com/bytecodealliance/wasmtime-py as discussed on #1390
2020-04-01 13:52:59 -05:00
Marcin Mielniczuk
20e71858a1 Sanitize file/directory symlinks in path_symlinks on Windows (#1359)
* Sanitize file/directory symlinks in path_symlinks on Windows

* Remove redundant error mappings
2020-04-01 08:55:51 +02:00
Yury Delendik
e64668776a Propertly simulate DWARF information when imports present (#1452)
* Ignore complex LLVM10 expressions.

* Propery function name when imports are present
2020-03-31 18:33:35 -05:00
Andrew Brown
d3df275003 Remove duplication of map_reg; fixes #1245
Both cranelift-codegen and wasmtime-debug need to map Cranelift registers to Gimli registers. Previously both crates had an almost-identical `map_reg` implementation. This change:
 - removes the wasmtime-debug implementation
 - improves the cranelift-codegen implementation with custom errors
 - exposes map_reg in `cranelift_codegen::isa::fde::map_reg` and subsequently `wasmtime_environ::isa::fde::map_reg`
2020-03-31 15:42:02 -07:00
Pat Hickey
48014e8d45 wiggle: remove versions and dont publish wiggle-test (#1446)
* wiggle: delete version deps between wiggle and wiggle-test

* scripts: dont publish wiggle-test
2020-03-31 14:13:16 -05:00
teapotd
2180e9ce16 fuzzing: Enable NaN canonicalization (#1334)
* Method to enable NaN canonicalization in Config

* Use fuzz_default_config in DifferentialConfig

* Enable NaN canonicalization for fuzzing
2020-03-31 09:22:08 -05:00
Alex Crichton
ac7cd4c46a Implement more of the wasm_frame_t type (#1438)
This fills out a few functions related to frame information in the C
API. This additionally adds some extension functions to get the module
name and function name from the C API.
2020-03-30 17:13:51 -05:00
Alex Crichton
bc5568f4b3 Symbolize start trap traces (#1437)
Make sure we've registered the frame info early enough so traps during
instantiation give frames as well.
2020-03-30 17:02:01 -05:00
Alex Crichton
968cd76163 Move back to only one WASI submodule (#1434)
* Move back to only one WASI submodule

This commit fixes the issue where we have two WASI submodules for build
reasons in this repository. The fix was to place the submodule in the
`wasi-common` crate, and then anyone using the `wig` crate has to be
sure to define a `WASI_ROOT` env var in a build script to be able to
parse witx files.

With all that in place `wasi-common` becomes the source of truth for the
witx files we're parsing, and crates like `wasmtime-wasi` use
build-scripts shenanigans to read the same witx files. This should
hopefully get us so we're compatible with publishing and still only have
one submodule!

* rustfmt
2020-03-30 14:45:23 -05:00
Jakub Konka
78772cf5e1 Generate trace logs in wiggle albeit behind a feature gate
This commit augments `wiggle` with trace log generation for the shims,
returned errno values, and returned values proper (if any, i.e.,
different than unit type `()`). What that means is that every syscall
will have auto-generated up to 3 traces, for instance,

```
 TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd_prestat_get(fd=Fd(3))
 TRACE wasi_common::wasi::wasi_snapshot_preview1 >      | result=(buf=Dir(PrestatDir { pr_name_len: 1 }))
 TRACE wasi_common::wasi::wasi_snapshot_preview1 >      | errno=No error occurred. System call completed successfully. (Errno::Success(0))
```

Putting logging behind a feature gate in this case means that the log calls
are generated by the `wiggle` crate regardless if the client requested
the feature or not, however, then their usage in the client lib is
dictated by the presence of the feature flag. So, for instance, `wasi-common`
has this feature enabled by default, while any other client lib
using `wiggle` if they don't want tracing enabled, they will just
leave the feature off. I'm not sure if this is what we wanted
but seemed easiest to implement quickly. Lemme y'all know your thoughts
about this!
2020-03-30 19:58:15 +02:00
Håvar Nøvik
98ff36bfed Fix typo in Memory.Maximum doc string. (#1432)
Co-authored-by: Håvar Nøvik <havar.novik@esmartsystems.com>
2020-03-30 10:04:40 -05:00
Alex Crichton
4ede98fe0c Make WASI and wat support optional in the C API (#1419)
Add some crate features to compile out support for these features of the
C API. Avoiding these two features if they're not necessary shaves about
2MB off the final shared object in some local tests!
2020-03-27 12:12:48 -05:00
Alex Crichton
6ef09359b0 Refactor and fill out wasmtime's C API (#1415)
* Refactor and improve safety of C API

This commit is intended to be a relatively large refactoring of the C
API which is targeted at improving the safety of our C API definitions.
Not all of the APIs have been updated yet but this is intended to be the
start.

The goal here is to make as many functions safe as we can, expressing
inputs/outputs as native Rust types rather than raw pointers wherever
possible. For example instead of `*const wasm_foo_t` we'd take
`&wasm_foo_t`. Instead of returning `*mut wasm_foo_t` we'd return
`Box<wasm_foo_t>`. No ABI/API changes are intended from this commit,
it's supposed to only change how we define all these functions
internally.

This commit also additionally implements a few more API bindings for
exposed vector types by unifying everything into one macro.

Finally, this commit moves many internal caches in the C API to the
`OnceCell` type which provides a safe interface for one-time
initialization.

* Split apart monolithic C API `lib.rs`

This commit splits the monolithic `src/lib.rs` in the C API crate into
lots of smaller files. The goal here is to make this a bit more readable
and digestable. Each module now contains only API bindings for a
particular type, roughly organized around the grouping in the wasm.h
header file already.

A few more extensions were added, such as filling out `*_as_*`
conversions with both const and non-const versions. Additionally many
APIs were made safer in the same style as the previous commit, generally
preferring Rust types rather than raw pointer types.

Overall no functional change is intended here, it should be mostly just
code movement and minor refactorings!

* Make a few wasi C bindings safer

Use safe Rust types where we can and touch up a few APIs here and there.

* Implement `wasm_*type_as_externtype*` APIs

This commit restructures `wasm_externtype_t` to be similar to
`wasm_extern_t` so type conversion between the `*_extern_*` variants to
the concrete variants are all simple casts. (checked in the case of
general to concrete, of course).

* Consistently imlpement host info functions in the API

This commit adds a small macro crate which is then used to consistently
define the various host-info-related functions in the C API. The goal
here is to try to mirror what the `wasm.h` header provides to provide a
full implementation of the header.
2020-03-27 09:50:32 -05:00
Dan Gohman
157aab50f5 More fixes for 0.14. (#1418) 2020-03-27 09:49:51 -05:00
Jakub Konka
5c51940100 Refactor use of Refs and RefMuts in wasi-common (#1412)
* Refactor use of Refs and RefMuts in wasi-common

This commit refactors the use of `Ref`s and `RefMut`s in `wasi-common`.
Now, `Entry` is stored behind an `Rc` inside the `EntryTable`. The `Entry`
itself on the other hand now stores rights behind a `RefCell` and the
descriptor as `Rc<RefCell<..>>` combo to enable easy reference tracking
and interior mutability which is required down the line in a couple of
syscalls. In essence, this implies that we no longer have need for
mutable accessor to `Entry` from `WasiCtx`, and so all related methods
go away (`get_entry_mut`, etc.).

While here, I've also simplified handling and aggregating of rights on
the `Entry` object. Instead of storing base and inheriting rights as
separate fields, they are now aggregated into one struct `EntryRights`
which features convenient constructors for each possible combination; i.e.,
when only base rights are set, or both base and inheriting are set, or
both are left as empty. Since we do need to be able to mutate those
rights down the line in `fdstat_set_rights` syscall, this object
is kept behind a `RefCell` (note no `Rc` since we don't need to pass it
around anywhere).

The descriptor field in `Entry` is now kept behind `Rc<RefCell<..>>` combo
since we not only need to mutate it down the line, but we also need to
be able to pass it around (as part of the machinery making `poll_oneoff`
work).

I've also removed `as_file` and `try_clone` methods on `Descriptor` struct
since they were adding more noise than necessary, and making them work
with `Rc` was unnecessarily complicated.

Finally, I've converted the `get_dir_from_os_handle` function into a
method attached to the `OsHandle` itself, called `dir_stream`. IMHO,
it makes more sense to have it there directly as a method than as a separate
function.

* Use Cell for types that are Copy
2020-03-27 09:34:52 +01:00
Dan Gohman
092538cc54 Test 0.14 (#1417)
* Bump Wasmtime to 0.14.0.

* Update the publish script for the wiggle crate wiggle.

* More fixes.

* Fix lightbeam depenency version.

* cargo update

* Cargo update wasi-tests too.

And add cargo update to the version-bump scripts.
2020-03-26 21:53:42 -07:00
Dan Gohman
6c0c9a46f3 Fixes for cargo publish (#1416)
* Publishing fixes.

* Make WASI a symlink.

* More fixes.

* Cargo doesn't allow dev-dependencies to have optional features.

* Remove the symlink.

* Add WASI as another git submodule.
2020-03-26 20:31:12 -07:00
Alex Crichton
a628dc315e Shuffle around the wiggle crates (#1414)
* Shuffle around the wiggle crates

This commit reorganizes the wiggle crates slightly by performing the
following transforms:

* The `crates/wiggle` crate, previously named `wiggle`, was moved to
  `crates/wiggle/crates/macro` and is renamed to `wiggle-macro`.

* The `crates/wiggle/crates/runtime` crate, previously named
  `wiggle-runtime`, was moved to `crates/wiggle` and is renamed to
  `wiggle`.

* The new `wiggle` crate depends on `wiggle-macro` and reexports the macro.

The goal here is that consumers only deal with the `wiggle` crate
itself. No more crates depend on `wiggle-runtime` and all dependencies
are entirely on just the `wiggle` crate.

* Remove the `crates/wiggle/crates` directory

Move everything into `crates/wiggle` directly, like `wasi-common`

* Add wiggle-macro to test-all script

* Fixup a test
2020-03-26 18:34:50 -05:00
Dan Gohman
6fa9be7767 Wasmtime 0.13.0 and Cranelift 0.61.0. (#1398)
This also updates the publishing scripts to work with newly added
and reorganized crates.
2020-03-26 13:19:02 -07:00
Peter Huene
cde01a47b1 Merge pull request #1411 from peterhuene/reimplement-dotnet-api
Reimplement the .NET API in terms of a linker
2020-03-26 12:35:39 -07:00
Peter Huene
fb0762bbd6 Add wasmtime_func_new_with_env.
This commit adds the `wasmtime_func_new_with_env` C API function and refactors
the implementation to share the implementation between the C API and Wasmtime
extension variants.
2020-03-26 11:48:06 -07:00
Peter Huene
382f68c620 Add Wasmtime C API function to control linker shadowing. 2020-03-26 11:26:04 -07:00
Yury Delendik
27bf044ca2 Fix debug asserts for dwarf transform (#1413)
* Fix debug asserts for dwarf transform

* feedback
2020-03-26 12:25:26 -05:00
Nick Fitzgerald
a8c5e7df95 Merge pull request #1402 from yurydelendik/enable-gdb
Enable GDB JIT debugging
2020-03-26 10:08:15 -07:00
Peter Huene
2d43d5a8fa Fix typo in exception message. 2020-03-26 01:14:51 -07:00
Peter Huene
183aa9af4c Fix typo in method call. 2020-03-26 01:10:45 -07:00
Peter Huene
cf1d9ee857 Reimplement the C# API.
This commit reimplements the C# API in terms of a Wasmtime linker.

It removes the custom binding implementation that was based on reflection in
favor of the linker's implementation.

This should make the C# API a little closer to the Rust API.

The `Engine` and `Store` types have been hidden behind the `Host` type which is
responsible for hosting WebAssembly module instances.

Documentation and tests have been updated.
2020-03-25 18:47:59 -07:00
Peter Huene
0d5d63fdb1 Support WASI snapshot0 in the C API.
This commit adds support for snapshot0 in the WASI C API.

A name parameter was added to `wasi_instance_new` to accept which WASI module
is being instantiated.

Additionally, the C# API now supports constructing a WASI instance based on the
WASI module name.

Fixes #1221.
2020-03-25 18:22:22 -07:00
Alex Crichton
e0dff02c9e Expand the C API slightly (#1404)
* Expand the C API slightly

Fill out missing `wasm_{memory,table}_type` APIs and don't panic on the
`wasm_externtype_as_*type_const` APIs and opt for returning a null
pointer instead.

* Update crates/c-api/src/lib.rs

Co-Authored-By: Yury Delendik <ydelendik@mozilla.com>

Co-authored-by: Yury Delendik <ydelendik@mozilla.com>
2020-03-25 16:12:19 -05:00
Yury Delendik
f3bfa2aa23 Ignore DWARF expressions with wasm globals (#1405) 2020-03-25 16:03:38 -05:00
Pat Hickey
bc1a11435e wiggle: emit a metadata module containing witx document (#1387)
* wiggle: emit a metadata module containing witx document

* wiggle: put metadata module behind a wiggle_metadata feature

* wasi-common: add wiggle_metadata feature and optional witx dep

* refactor according to alex's advice

* wasi-common: make snapshots pub

* wasi-common: i do need a wiggle_metadata feature to be available

* Tweak features and such

* wiggle: fix tests by passing metadata flag to wiggle-runtime

* wiggle: need to move wiggle-runtime to a non-dev dependency

so that the feature resolves for external users of the crates

Co-authored-by: Alex Crichton <alex@alexcrichton.com>
2020-03-25 14:57:44 -05:00
Yury Delendik
5c4ea5b03a Increase generated DWARF version to 4 2020-03-25 13:52:34 -05:00
Jakub Konka
1f6890e070 [wasi-common] Clean up the use of mutable Entry (#1395)
* Clean up the use of mutable Entry

Until now, several syscalls including `fd_pwrite` etc. were relying on
mutating `&mut Entry` by mutating its inner file handle. This is
unnecessary in almost all cases since all methods mutating `std::fs::File`
in Rust's libstd are also implemented for `&std::fs::File`.

While here, I've also modified `OsHandle` in BSD to include `RefCell<Option<Dir>>`
rather than `Option<Mutex<Dir>>` as was until now. While `RefCell`
could easily be replaced with `RefCell`, since going multithreading
will require a lot of (probably even) conceptual changes to `wasi-common`,
I thought it'd be best not to mix single- with multithreading contexts
and swap all places at once when it comes to it.

I've also had to make some modifications to virtual FS which mainly
swapped mutability for interior mutability in places.

* Use one-liners wherever convenient
2020-03-25 14:00:52 +01:00
Alex Crichton
c241f18b81 Use Linker in *.wast testing (#1391)
* Use `Linker` in `*.wast` testing

By default `Linker` disallows shadowing previously defined items, but it
looks like the `*.wast` test suites rely on this so this commit adds a
boolean flag to `Linker` as well indicating whether duplicates are
allowed.

* Review comments

* Add a test with a number of recursive instances

* Deny warnings in doctests

* No tabs
2020-03-24 17:37:32 -05:00
Benjamin Brittain
b214804850 Disable lowering thread priority on Fuchsia (#1394) 2020-03-24 15:53:48 -05:00
John Sullivan
222a73c150 Initial documentation for python users (#1378)
* Fix instructions for building rust modules in python examples

When I ran `rustc +nightly ...` the compiler just looked for a source file
called `+nightly`. I changed these instructions to use rustup + rustc instead.

* Initial documentation for python users

Added documentation for using the Wasmtime loader in python, and explained the
first two examples in the repo. Changed the import example to demonstrate
working with module linear memory.

* Fix include in python guide

* Wording

* Clarify memory usage

* Flow through the example better

* More word choice

* Make rustup a prereq

* Fix source code paths in python guide

* Fix rustup example in python guide

Co-Authored-By: Samrat Man Singh <samratmansingh@gmail.com>

* Replace command examples with preformat blocks

* Revert "Fix instructions for building rust modules in python examples"

This reverts commit 1738888a2df4e15aba1e26c8ef42058e7a2053bb.

* Left a block quote in a preformat example

Co-authored-by: Samrat Man Singh <samratmansingh@gmail.com>
2020-03-24 09:44:05 -05:00
Benjamin Brittain
ee4b5353f8 bump winapi version to 0.3.8 (#1388) 2020-03-24 08:47:31 -05:00
Alex Crichton
0d4bde4ab3 Add a wasmtime::Linker type (#1384)
* Add a `wasmtime::Linker` type

This commit adds a new type to the `wasmtime` crate, a `Linker`. This
linker is intended to vastly simplify calling `Instance::new` by easily
performing name resolution and incrementally defining state over time.
The goal here is to start down a path of making linking wasm modules in
`wasmtime` a first-class and ergonomic operation. This is highly likely
to evolve over time and get tweaked through releases as we iterate
towards a design well-suited for `wasmtime`, but this is intended to at
least be the initial foundation for such functionality.

This commit additionally also adds a C API for the linker and switches
the existing linking examples to using this linker in both Rust and C.

One piece of future work I'd like to tackle next is to integrate WASI
into the `wasmtime` crate in a more first-class manner. This [`Linker`]
type provides a great location to hook into the instantiation process to
easily instantiate modules with WASI imports. That's a relatively large
refactoring for now though and I figured it'd be best left for a
different time.

Closes #727
2020-03-23 21:02:31 -05:00
Yury Delendik
021ebb3748 Refactor address_transform.rs to use less memory (#1260)
The crates/debug/src/transform/address_transform.rs is unoptimized in terms of data structures. This PR refactors this file to remove creation of intermediate in-heap structures, thus improves overall performance of the DWARF transformation.

* Reduce amount of memory allocated in translate_ranges_raw
* refactor translate_ranges
* Don't transform non-unit .debug_line
* type annotation for TransformRangeXXXIter's
* Fix empty generated wasm positions
2020-03-23 16:36:29 -05:00
Dan Gohman
2fdc7f1a8e [wiggle] Don't make generated structs and unions Copy.
Some structs and unions are large enough that making them `Copy` isn't
ideal. wasi-common only needed `Copy` in a few places that were easy to
fix. `SubscriptionClock` is 32 bytes, so it's not a bad a idea to pass
it by reference anyway.
2020-03-23 18:01:25 +01:00