Commit Graph

8435 Commits

Author SHA1 Message Date
Pat Hickey
27464c85f4 cargo.lock 2021-04-19 16:00:56 -07:00
Pat Hickey
3d3a2acc1b wasi-tokio: WIP need to port the sync scheduler into a spawn_blocking 2021-04-19 16:00:38 -07:00
Pat Hickey
8667d8c244 test-programs: test wasi-tokio 2021-04-19 16:00:27 -07: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
Pat Hickey
675b579361 use AsyncSeek 2021-04-19 14:35:46 -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
Pat Hickey
d2a98ced53 use some better traits 2021-04-15 16:00:11 -07:00
Pat Hickey
9880d09f1f do some programming 2021-04-15 14:50:17 -07: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
Pat Hickey
33dbd4388c use tokio's File with a cap-std Dir 2021-04-15 11:39:11 -07:00
Pat Hickey
2ddf4c1da9 tokio example requires enabling a cargo feature
and also a dummy C example
2021-04-14 16:54:52 -07:00
Pat Hickey
7202494e9d fix windows sched 2021-04-14 16:17:21 -07:00
Pat Hickey
b883bda022 fix test-programs for sync wasi 2021-04-14 16:06:50 -07:00
Pat Hickey
2f0c7e59e7 wasmtime-wasi: all funcs are async now 2021-04-14 16:04:41 -07:00
Pat Hickey
c0e89b8da8 wasi-cap-std-sync: WasiFile and WasiDir converted to async_traits 2021-04-14 15:43:19 -07:00
Pat Hickey
564e43d1b3 WasiDir: make all operations async 2021-04-14 15:22:25 -07:00
Pat Hickey
00e58567d9 WasiFile: all operations are now async
only fn as_any(&self) -> &dyn Any doesnt get to be async.
2021-04-14 15:17:31 -07:00
Pat Hickey
025a1ecff4 wasi-common: snapshots 0 and 1 traits are all async now 2021-04-14 15:05:38 -07:00
Pat Hickey
228096c840 wiggle: convenient syntax for marking all funcs async 2021-04-14 14:51:24 -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
Pat Hickey
0127676621 wasi-cap-std-async is better named wasi-tokio 2021-04-14 14:06:36 -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
Chris Fallin
fd4bfbe5a7 Merge pull request #2836 from uweigand/framesizefix
Fix frame size after unwind rework
2021-04-14 12:19:38 -07:00
Chris Fallin
1f21b32e99 Merge pull request #2838 from uweigand/optionalfp
Allow unwind support to work without a frame pointer
2021-04-14 10:58:51 -07:00
Chris Fallin
337cc47d2f Merge pull request #2840 from bnjbvr/fix-2839
cranelift: always spill i32 with i64 stores
2021-04-14 10:11:47 -07:00
Pat Hickey
c691d1864e fix 2021-04-14 09:54:27 -07:00
Benjamin Bouvier
e7bced9512 cranelift: always spill i32 with i64 stores;
Fixes #2839. See also the issue description and comments in this commits for
details of what the fix is about here.
2021-04-14 18:08:52 +02:00
Pat Hickey
247795c7ca fix 2021-04-14 08:37:53 -07:00
Ulrich Weigand
5904c09682 Allow unwind support to work without a frame pointer
The patch extends the unwinder to support targets that do not need
to use a dedicated frame pointer register.  Specifically, the
changes include:

- Change the "fp" routine in the RegisterMapper to return an
  *optional* frame pointer regsiter via Option<Register>.

- On targets that choose to not define a FP register via the above
  routine, the UnwindInst::DefineNewFrame operation no longer switches
  the CFA to be defined in terms of the FP.  (The operation still can
  be used to define the location of the clobber area.)

- In addition, on targets that choose not to define a FP register, the
  UnwindInst::PushFrameRegs operation is not supported.

- There is a new operation UnwindInst::StackAlloc that needs to be
  called on targets without FP whenever the stack pointer is updated.
  This caused the CFA offset to be adjusted accordingly.  (On
  targets with FP this operation is a no-op.)
2021-04-14 15:32:31 +02:00
Ulrich Weigand
336c6369b4 Add back support for accumulating outgoing arguments
The unwind rework (commit 2d5db92a) removed support for the
feature to allow a target to allocate the space for outgoing
function arguments right in the prologue (originally added
via commit 80c2d70d).   This patch adds it back.
2021-04-14 13:51:16 +02:00
Ulrich Weigand
e3bb36ba77 Fix frame size after unwind rework
After the unwind rework (commit 2d5db92a) the space used to save
clobbered registers now lies between the nominal SP and the FP.
Therefore, the size of that space should now be included in the
frame size as reported by frame_size(), since this value is used
to compute the nominal_sp_to_fp offset.
2021-04-14 13:46:08 +02:00
Pat Hickey
759019811e add tokio example
Co-authored-by: Alex Crichton <alex@alexcrichton.com>
2021-04-13 17:52:52 -07:00