Commit Graph

8232 Commits

Author SHA1 Message Date
Pat Hickey
9d6f64b33d cargo deny: ignore RUSTSEC-2021-0064
Transient dependencies depend on two different versions of `cpuid-bool`.

This advisory does not appear to be urgent. We should review this ignore
after a few weeks to see if our deps have switched over.

text of the advisory:

Issued
May 6, 2021
Package
cpuid-bool (crates.io)
Type
Unmaintained
Details
https://github.com/RustCrypto/utils/pull/381
Patched
no patched versions
Description
Please use the `cpufeatures`` crate going forward:

https://github.com/RustCrypto/utils/tree/master/cpufeatures

There will be no further releases of cpuid-bool.
2021-05-06 17:08:05 -07:00
Chris Fallin
6a1a169c62 Merge pull request #2865 from eggyal/expose_get_got_address
Expose new `JITModule::read_got_entry` function
2021-05-04 11:30:52 -07:00
Pat Hickey
fe76c59159 Merge pull request #2730 from bjorn3/less_thiserror
Remove some dependencies
2021-05-04 09:28:34 -07:00
Ryan Brewster
2145855954 Add example of execution limits using fuel consumption (#2869)
* Add example of execution limits using fuel consumption

* run rustfmt

* Use a more naive WAT implementation

* Catch error and return cleanly

* Add a C example to demonstrate fuel consumption

* Add error handling for add_fuel
2021-05-04 10:39:01 -05:00
bjorn3
82f3ad4f1a Add comment why thiserror is not used 2021-05-04 13:51:28 +02:00
bjorn3
84c79982e7 Remove unnecessary dependencies
Found using cargo-udeps
2021-05-04 13:51:26 +02:00
bjorn3
03fdbadfb4 Remove thiserror dependency from cranelift_codegen 2021-05-04 13:45:20 +02:00
bjorn3
147cda3b99 Remove thiserror dependency from cranelift_module 2021-05-04 13:42:48 +02:00
Benjamin Bouvier
8811246a9f debug: Avoid underflow when scanning for landing pad bytes (#2866) 2021-05-03 11:58:40 -05:00
Ulrich Weigand
dfb1bc4d02 Trap handler changes to support s390x (#2871)
On s390x, SIGILL and SIGFPE are delivered with the PSW address
pointing *after* the faulting instruction, while SIGSEGV and
SIGBUS are delivered with the PSW address pointing *to* the
faulting instruction.  In order to support this, the common
code trap handler has to distinguish between those cases.

Also, enable SIGFPE on s390x (just like on x86).
2021-05-03 11:56:18 -05:00
Ulrich Weigand
e1cc1a67d5 Object file support for s390x (#2872)
Add support for s390x binary format object files.  In particular,
add support for s390x ELF relocation types (currently only
S390xPCRel32Dbl).
2021-05-03 11:50:00 -05:00
Ulrich Weigand
7a3791f9e9 Fiber support for s390x (#2870)
Add fiber support for the s390x architecture.
2021-05-03 11:01:10 -05:00
Andrew Brown
92e0b6b9e8 wasi-nn: turn it on by default (#2859)
* wasi-nn: turn it on by default

This change makes the wasi-nn Cargo feature a default feature. Previously, a wasi-nn user would have to build a separate Wasmtime binary (e.g. `cargo build --features wasi-nn ...`) to use wasi-nn and the resulting binary would require OpenVINO shared libraries to be present in the environment in order to run (otherwise it would fail immediately with linking errors). With recent changes to the `openvino` crate, the wasi-nn implementation can defer the loading of the OpenVINO shared libraries until runtime (i.e., when the user Wasm program calls `wasi_ephemeral_nn::load`) and display a user-level error if anything goes wrong (e.g., the OpenVINO libraries are not present on the system). This runtime-linking addition allows the wasi-nn feature to be turned on by default and shipped with upcoming releases of Wasmtime. This change should be transparent for users who do not use wasi-nn: the `openvino` crate is small and the newly-available wasi-nn imports only affect programs in which they are used.

For those interested in reviewing the runtime linking approach added to the `openvino` crate, see https://github.com/intel/openvino-rs/pull/19.

* wasi-nn spec path: don't use canonicalize

* Allow dependencies using the ISC license

The ISC license should be [just as permissive](https://choosealicense.com/licenses/isc) as MIT, e.g., with no additional limitations.

* Add a `--wasi-modules` flag

This flag controls which WASI modules are made available to the Wasm program. This initial commit enables `wasi-common` by default (equivalent to `--wasi-modules=all`) and allows `wasi-nn` and `wasi-crypto` to be added in either individually (e.g., `--wasi-modules=wasi-nn`) or as a group (e.g., `--wasi-modules=all-experimental`).

* wasi-crypto: fix unused dependency

Co-authored-by: Pat Hickey <pat@moreproductive.org>
2021-04-29 15:03:28 -05:00
Alan Egerton
e4f9eebe3a Expose new JITModule::read_got_entry function 2021-04-29 09:28:29 +01:00
Chris Fallin
ff2529c339 Merge pull request #2746 from bjorn3/emit_small_mem_custom_memflags
Allow passing arbitrary MemFlags to emit_small_mem{cpy,move}
2021-04-28 11:26:48 -07:00
Alex Crichton
7ec073cef1 Bring back per-thread lazy initialization (#2863)
* Bring back per-thread lazy initialization

Platforms Wasmtime supports may have per-thread initialization that
needs to run before WebAssembly. For example Unix needs to setup a
sigaltstack and macOS needs to set up mach ports. In #2757 this
per-thread setup was moved out of the invocation of a wasm function,
relying on the lack of Send for Store to initialize the thread at Store
creation time and never worry about it later.

This conflicted with [wasmtime's desired multithreading
story](https://github.com/bytecodealliance/wasmtime/pull/2812) so a new
[`Store::notify_switched_thread` was
added](https://github.com/bytecodealliance/wasmtime/pull/2822) to
explicitly indicate a Store has moved to another thread (if it unsafely
did so).

It turns out though that it's not always easy to determine when a
`Store` moves to a new thread. For example the Go bindings for Wasmtime
are generally unaware when a goroutine switches OS threads. This led to
https://github.com/bytecodealliance/wasmtime-go/issues/74 where a SIGILL
was left uncaught, making it appear that traps aren't working properly.

This commit revisits the decision in #2757 and moves per-thread
initialization back into the path of calling into WebAssembly. This is
differently from before, though, where there's still only one TLS access
on the path of calling into WebAssembly, unlike before where it was a
separate access. This allows us to get the speed benefits of #2757 as
well as the flexibility benefits of not having to explicitly move a
store between threads.

With this new ability this commit deletes the recently added
`Store::notify_switched_thread` method since it's no longer necessary.

* Fix a test compiling
2021-04-28 12:08:27 -05:00
Chris Fallin
207da989ac Merge pull request #2862 from akirilov-arm/simd_boolean
Enable the simd_boolean test for AArch64
2021-04-27 21:29:18 -07:00
Anton Kirilov
480670e17f Enable the simd_boolean test for AArch64
Also, enable the simd_i64x2_arith2 test because it doesn't need
any code changes.

Copyright (c) 2021, Arm Limited.
2021-04-27 20:19:51 +01:00
Chris Fallin
b89c959e4a Merge pull request #2854 from uweigand/debug-endian
debug: Support big-endian architectures
2021-04-27 10:27:22 -07:00
Alex Crichton
8384f3a347 Bring back Module::deserialize (#2858)
* Bring back `Module::deserialize`

I thought I was being clever suggesting that `Module::deserialize` was
removed from #2791 by funneling all module constructors into
`Module::new`. As our studious fuzzers have found, though, this means
that `Module::new` is not safe currently to pass arbitrary user-defined
input into. Now one might pretty reasonable expect to be able to do
that, however, being a WebAssembly engine and all. This PR as a result
separates the `deserialize` part of `Module::new` back into
`Module::deserialize`.

This means that binary blobs created with `Module::serialize` and
`Engine::precompile_module` will need to be passed to
`Module::deserialize` to "rehydrate" them back into a `Module`. This
restores the property that it should be safe to pass arbitrary input to
`Module::new` since it's always expected to be a wasm module. This also
means that fuzzing will no longer attempt to fuzz `Module::deserialize`
which isn't something we want to do anyway.

* Fix an example

* Mark `Module::deserialize` as `unsafe`
2021-04-27 10:55:12 -05:00
Peter Huene
4a830b1159 Merge pull request #2857 from workingjubilee/byte-less
Factor out byteorder in cranelift
2021-04-23 13:42:39 -07:00
Jubilee Young
a8c956ede1 Factor out byteorder in cranelift
This removes an existing dependency on the byteorder crate in favor of
using std equivalents directly.

While not an issue for wasmtime per se, cranelift is now part of the
critical path of building and testing Rust, and minimizing dependencies,
even small ones, can help reduce the time and bandwidth required.
2021-04-23 12:05:18 -07:00
StackDoubleFlow
9637bc5a09 Fix cranelift Module and ObjectModule docs links (#2852) 2021-04-21 06:29:02 -07:00
Ulrich Weigand
801358333d debug: Support big-endian architectures
This fixes some hard-coded assumptions in the debug crate that
the native ELF files being accessed are little-endian; specifically
in create_gdbjit_image as well as in emit_dwarf.

In addition, data in WebAssembly memory always uses little-endian
byte order.  Therefore, if the native architecture is big-endian,
all references to base types need to be marked as little-endian
using the DW_AT_endianity attribute, so that the debugger will
be able to correctly access them.
2021-04-21 14:14:59 +02:00
Alex Crichton
196bcec6cf Process declared element segments for "possibly exported funcs" (#2851)
Now that we're using "possibly exported" as an impactful decision for
codegen (which trampolines to generate and which ABI a function has)
it's important that we calculate this property of a wasm function
correctly! Previously Wasmtime forgot to processed "declared" elements
in apart from active/passive element segments, but this updates Wasmtime
to ensure that these entries are processed and all the functions
contained within are flagged as "possibly exported".

Closes #2850
2021-04-20 16:52:51 -05:00
Alex Crichton
200d7f1df6 Delete signature for no-longer-present function (#2849)
Accidental omission from #2736
2021-04-19 20:49:33 -05:00
Alex Crichton
193551a8d6 Optimize table.init instruction and instantiation (#2847)
* Optimize `table.init` instruction and instantiation

This commit optimizes table initialization as part of instance
instantiation and also applies the same optimization to the `table.init`
instruction. One part of this commit is to remove some preexisting
duplication between instance instantiation and the `table.init`
instruction itself, after this the actual implementation of `table.init`
is optimized to effectively have fewer bounds checks in fewer places and
have a much tighter loop for instantiation.

A big fallout from this change is that memory/table initializer offsets
are now stored as `u32` instead of `usize` to remove a few casts in a
few places. This ended up requiring moving some overflow checks that
happened in parsing to later in code itself because otherwise the wrong
spec test errors are emitted during testing. I've tried to trace where
these can possibly overflow but I think that I managed to get
everything.

In a local synthetic test where an empty module with a single 80,000
element initializer this improves total instantiation time by 4x (562us
=> 141us)

* Review comments
2021-04-19 18:44:48 -05:00
Nick Fitzgerald
2864bb4a0f Merge pull request #2848 from fitzgen/map-or-in-table-element-into-raw
Use `map_or` instead of `map` and `unwrap_or` in `TableElement::into_raw`
2021-04-19 15:45:12 -07:00
Nick Fitzgerald
8507eb7708 Use map_or instead of map and unwrap_or in TableElement::into_raw 2021-04-19 14:18:55 -07:00
Peter Huene
f12b4c467c Add resource limiting to the Wasmtime API. (#2736)
* Add resource limiting to the Wasmtime API.

This commit adds a `ResourceLimiter` trait to the Wasmtime API.

When used in conjunction with `Store::new_with_limiter`, this can be used to
monitor and prevent WebAssembly code from growing linear memories and tables.

This is particularly useful when hosts need to take into account host resource
usage to determine if WebAssembly code can consume more resources.

A simple `StaticResourceLimiter` is also included with these changes that will
simply limit the size of linear memories or tables for all instances created in
the store based on static values.

* Code review feedback.

* Implemented `StoreLimits` and `StoreLimitsBuilder`.
* Moved `max_instances`, `max_memories`, `max_tables` out of `Config` and into
  `StoreLimits`.
* Moved storage of the limiter in the runtime into `Memory` and `Table`.
* Made `InstanceAllocationRequest` use a reference to the limiter.
* Updated docs.
* Made `ResourceLimiterProxy` generic to remove a level of indirection.
* Fixed the limiter not being used for `wasmtime::Memory` and
  `wasmtime::Table`.

* Code review feedback and bug fix.

* `Memory::new` now returns `Result<Self>` so that an error can be returned if
  the initial requested memory exceeds any limits placed on the store.

* Changed an `Arc` to `Rc` as the `Arc` wasn't necessary.

* Removed `Store` from the `ResourceLimiter` callbacks. Custom resource limiter
  implementations are free to capture any context they want, so no need to
  unnecessarily store a weak reference to `Store` from the proxy type.

* Fixed a bug in the pooling instance allocator where an instance would be
  leaked from the pool. Previously, this would only have happened if the OS was
  unable to make the necessary linear memory available for the instance. With
  these changes, however, the instance might not be created due to limits
  placed on the store. We now properly deallocate the instance on error.

* Added more tests, including one that covers the fix mentioned above.

* Code review feedback.

* Add another memory to `test_pooling_allocator_initial_limits_exceeded` to
  ensure a partially created instance is successfully deallocated.
* Update some doc comments for better documentation of `Store` and
  `ResourceLimiter`.
2021-04-19 09:19:20 -05:00
Taiki Endo
52b1166918 Update iter-enum to 1 (#2846) 2021-04-19 09:08:15 -05:00
Peter Huene
6b6a6463a2 Merge pull request #2842 from peterhuene/engine-sig-registry
Additional performance improvements for module instantiation.
2021-04-16 13:59:01 -07:00
Peter Huene
ef2ad6375d Consolidate module construction.
This commit adds `Module::from_parts` as an internal constructor that shared
the implementation between `Module::from_binary` and module deserialization.
2021-04-16 12:34:38 -07:00
Peter Huene
dfab471ce5 Remove unused file.
This file hasn't been used for a while and was mistakenly not deleted.
2021-04-16 12:30:14 -07:00
Peter Huene
b775b68cfb Make module information lookup from runtime safe.
This commit uses a two-phase lookup of stack map information from modules
rather than giving back raw pointers to stack maps.

First the runtime looks up information about a module from a pc value, which
returns an `Arc` it keeps a reference on while completing the stack map lookup.

Second it then queries the module information for the stack map from a pc
value, getting a reference to the stack map (which is now safe because of the
`Arc` held by the runtime).
2021-04-16 12:30:10 -07:00
Peter Huene
6ac1321162 Minor corrections with latest changes. 2021-04-16 11:08:22 -07:00
Peter Huene
726a936474 Remove ArcModuleCode as it is no longer used. 2021-04-16 11:08:22 -07:00
Peter Huene
510fc71728 Code review feedback.
* Make `FunctionInfo` public and `CompiledModule::func_info` return it.
* Make the `StackMapLookup` trait unsafe.
* Add comments for the purpose of `EngineHostFuncs`.
* Rework ownership model of shared signatures: `SignatureCollection` in
  conjunction with `SignatureRegistry` is now used so that the `Engine`,
  `Store`, and `Module` don't need to worry about unregistering shared
  signatures.
* Implement `Func::param_arity` and `Func::result_arity` in terms of
  `Func::ty`.
* Make looking up a trampoline with the module registry more efficient by doing
  a binary search on the function's starting PC value for the owning module and
  then looking up the trampoline with only that module.
* Remove reference to the shared signatures from `GlobalRegisteredModule`.
2021-04-16 11:08:21 -07:00
Peter Huene
ea72c621f0 Remove the stack map registry.
This commit removes the stack map registry and instead uses the existing
information from the store's module registry to lookup stack maps.

A trait is now used to pass the lookup context to the runtime, implemented by
`Store` to do the lookup.

With this change, module registration in `Store` is now entirely limited to
inserting the module into the module registry.
2021-04-16 11:08:21 -07:00
Peter Huene
a2466b3c23 Move the signature registry into Engine.
This commit moves the shared signature registry out of `Store` and into
`Engine`.

This helps eliminate work that was performed whenever a `Module` was
instantiated into a `Store`.

Now a `Module` is registered with the shared signature registry upon creation,
storing the mapping from the module's signature index space to the shared index
space.

This also refactors the "frame info" registry into a general purpose "module
registry" that is used to look up trap information, signature information, and
(soon) stack map information.
2021-04-16 11:06:44 -07:00
Benjamin Bouvier
f26449f03d Merge pull request #2845 from bnjbvr/fix-unwind-win64-old-backend
Generate unwind information on Win64 with the old backend
2021-04-16 18:59:19 +02:00
Benjamin Bouvier
ba73b458b8 Introduce a new API that allows notifying that a Store has moved to a new thread (#2822)
* Introduce a new API that allows notifying that a Store has moved to a new thread

* Add backlink to documentation, and mention the new API in the multithreading doc;
2021-04-16 11:15:35 -05:00
Benjamin Bouvier
8ab3511b3b Generate unwind information on Win64 with the old backend
Following the new ABI introduced for efficient support of multiple return values, the old-backend test for generating unwind information was incomplete, resulting in no unwind information being generated and traps not being correctly caught by the runtime.
2021-04-16 18:05:49 +02:00
Benjamin Bouvier
82f6556bc2 Merge pull request #2758 from bnjbvr/revert-log
cranelift: Use a deferred display mechanism instead of `log_enabled!`
2021-04-16 11:49:44 +02:00
Benjamin Bouvier
50aa645769 cranelift: use a deferred display wrapper for logging the vcode's IR 2021-04-16 10:27:19 +02:00
Chris Fallin
03077e0de9 Merge pull request #2843 from uweigand/spillslot-fix
cranelift: Fix spillslot regression on big-endian platforms
2021-04-15 13:28:33 -07:00
Ulrich Weigand
10efe8e780 cranelift: Fix spillslot regression on big-endian platforms
PR 2840 changed the store_spillslot routine to always store
integer registers in full word size to a spill slot.  However,
the load_spillslot routine was not updated, which may causes
the contents to be reloaded in a different type.  On big-endian
systems this will fetch wrong data.

Fixed by using the same type override in load_spillslot.
2021-04-15 21:39:14 +02:00
Andrew Brown
0acc1451ea x64: lower iabs.i64x2 using a single AVX512 instruction when possible (#2819)
* x64: add EVEX encoding mechanism

Also, includes an empty stub module for the VEX encoding.

* x64: lower abs.i64x2 to VPABSQ when available

* x64: refactor EVEX encodings to use `EvexInstruction`

This change replaces the `encode_evex` function with a builder-style struct, `EvexInstruction`. This approach clarifies the code, adds documentation, and results in slight speedups when benchmarked.

* x64: rename encoding CodeSink to ByteSink
2021-04-15 11:53:58 -07:00
Ulrich Weigand
1243cea455 Update cap-std dependency to 0.13.9
This fixes a build failure on s390x.
2021-04-14 14:11:46 -07:00
Chris Fallin
36c667d58d Merge pull request #2837 from uweigand/outgoing-args
Add back support for accumulating outgoing arguments
2021-04-14 12:54:06 -07:00