Commit Graph

542 Commits

Author SHA1 Message Date
Syrus Akbary
28c8b877fd Merge branch 'master' into compilerconfig-owned 2020-12-04 13:53:37 -08:00
Syrus
8481161cf9 Updated metering with remaining points implementation 2020-12-04 17:06:29 +01:00
Syrus
13e6f29c29 Set compiler config to be owned (following wasm-c-api) 2020-12-04 02:39:19 -08:00
Simon Warta
31cfa4941d Add missing re-exports CompileError, WasmError and ParseCpuFeatureError 2020-12-04 10:50:40 +01:00
Syrus Akbary
2fac4356a8 Added Cranelift x64 experimental feature flag 2020-12-02 23:02:24 -08:00
Mark McCaskey
5cd76521d5 Add #[track_caller] to panic helper function
This will make the line reported in the panic point to a useful
location instead of the helper function.
2020-12-02 14:03:47 -08:00
Mark McCaskey
e928a832a8 Update mentions of alpha to beta 2020-12-02 11:01:54 -08:00
Mark McCaskey
947e7d394f Prepare for 1.0.0-beta1 release 2020-12-01 17:15:46 -08:00
Syrus Akbary
11bf406a2b Merge pull request #1857 from wasmerio/fix/dynamic-fn-env-wasmer-env
Fix dynamic function envs not working with `WasmerEnv`
2020-12-01 17:06:05 -08:00
Mark McCaskey
46567a4bf8 Fix dynamic function envs not working with WasmerEnv 2020-12-01 15:59:14 -08:00
bors[bot]
5371543f4e Merge #1839
1839: Metering middleware. r=syrusakbary a=nlewycky

Based on https://github.com/wasmerio/wasmer-reborn/pull/129 . Original description:

- [x] Necessary APIs for modifying module info.
- [x] Global transformation.
- [x] Per-function transformation.
- [x] Testing and examples.


Co-authored-by: losfair <zhy20000919@hotmail.com>
Co-authored-by: Syrus <me@syrusakbary.com>
Co-authored-by: Nick Lewycky <nick@wasmer.io>
Co-authored-by: nlewycky <nick@wasmer.io>
Co-authored-by: Syrus Akbary <me@syrusakbary.com>
2020-12-01 19:48:44 +00:00
Ivan Enderlin
7973a965fb Merge branch 'master' into fix-vm-leak 2020-12-01 10:08:21 +01:00
Syrus Akbary
097bfeb479 Merge branch 'master' into feature/middleware 2020-11-30 21:31:56 -05:00
Mark McCaskey
4ef3286f2e Merge branch 'master' into feature/host-env-prototype 2020-11-30 16:52:34 -08:00
Mark McCaskey
d0c44c6491 Merge pull request #1842 from wasmerio/host-env-prototype-export-change 2020-11-30 15:41:50 -08:00
nlewycky
f110c4d308 Merge branch 'master' into feature/middleware 2020-11-30 15:12:02 -08:00
Mark McCaskey
03410c15a1 Rename EngineExport to Export 2020-11-30 12:32:53 -08:00
Mark McCaskey
9e0cfcebbb Rename vm::Export to vm::VMExport 2020-11-30 11:38:14 -08:00
Ivan Enderlin
7621991a9a test(api) Test that exports work after the instance has been freed. 2020-11-27 10:25:50 +01:00
Ivan Enderlin
8e17a4ce41 fixup 2020-11-26 14:23:31 +01:00
Ivan Enderlin
081d3e3edc fix(vm) Remove debugging statements. 2020-11-26 13:48:30 +01:00
Ivan Enderlin
cae4bc699f fix(api) Fix new_native_with_unsafe_mutable_env. 2020-11-26 13:20:59 +01:00
Mark McCaskey
8669e92ed4 Move EngineExport to engine 2020-11-25 16:44:21 -08:00
Mark McCaskey
40eec3fbd6 Address feedback: misc clean ups 2020-11-25 14:19:29 -08:00
Mark McCaskey
7013163829 WIP attempt to make an Export wrapper type
I can't figure out how we can ever use the non-wrapped type though
2020-11-25 10:59:04 -08:00
Mark McCaskey
82fc0080ba Allow closures with non-native host functions 2020-11-24 13:15:38 -08:00
Mark McCaskey
29d50a55ca Disable closures as host functions for now + docs + tests 2020-11-24 12:44:13 -08:00
Ivan Enderlin
d5c7b628be Merge branch 'master' into fix-vm-leak 2020-11-23 17:37:21 +01:00
Ivan Enderlin
d7bcc211c2 big patch: add some traces. 2020-11-23 17:33:22 +01:00
Ivan Enderlin
e77afea383 big patch: Start injecting InstanceAllocator everywhere. 2020-11-23 17:25:09 +01:00
Mark McCaskey
de6cb9c4c4 Merge branch 'master' into feature/host-env-prototype 2020-11-20 15:54:35 -08:00
Mark McCaskey
77c12e9ff1 Merge branch 'master' into feature/make-env-immutable 2020-11-20 14:40:20 -08:00
losfair
e7dd725c6d Add module info transformation method to ModuleMiddleware. 2020-11-20 14:34:46 -08:00
Mark McCaskey
eeed1b9124 Rename LegacyEnv to UnsafeMutableEnv 2020-11-20 14:21:54 -08:00
Mark McCaskey
c5aec5dd9a Clean up typos in comments 2020-11-20 14:02:32 -08:00
Mark McCaskey
a95c44583c Add hack to get deprecated API to work 2020-11-19 17:43:33 -08:00
bors[bot]
875ac93355 Merge #1826
1826: feat(api) Faster `Exports::from_iter` r=Hywan a=Hywan

# Description

Instead of creating a new `Exports` with `Exports::new` and inserting
all pair `(String, Extern)` one after the other with
`Exports::insert`, this patch updates the code to create an `Exports`
directly with its `map` field built with `IndexMap::from_iter`, so
that we avoid calling `Arc::get_mut(…).unwrap().insert(…)` for every
pair.

# Review

- ~[ ] Add a short description of the the change to the CHANGELOG.md file~ (not sure it's necessary)


Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2020-11-19 23:13:37 +00:00
bors[bot]
43b3d4b0cd Merge #1822
1822: fix(vm) Fix memory leak of `InstanceHandle` r=syrusakbary a=Hywan

# Description

In `wasmer_engine::Artifact::instantiate`, the engine artifact
allocates a new instance by calling
`wasmer_vm::InstanceHandle::allocate_instance`. To make it short, this
function calculates the [`Layout`] of an `wasmer_vm::Instance`, and
allocates space for it by calling [`alloc`]. This last part is
important because it means we are responsible to deallocate it with
[`dealloc`].

The pointer to this `wasmer_vm::Instance` is stored in the
`wasmer_vm::InstanceHandle` structure. That's the handle that is
returned by the engine artifact `Artifact::instantiate` method.

This instance handle is then stored in `wasmer::Instance` (through the
intervention of `wasmer::Module`).

How is it freed? It wasn't. That's the leak. [`dealloc`] was never
called.

How to free it? We must call [`dealloc`]. There is even a
`wasmer_vm::InstanceHandle::deallocate` helper to do that
properly. Neat!

When to free it? That's the tricky part. A `wasmer::Instance` can be
clonable. To do so, `wasmer_vm::InstanceHandle` must be clonable
too. There was a `Clone` implementation, that was constructing a new
`wasmer_vm:InstanceHandle` by using the same pointer to
`wasmer_vm::Instance`. That's annoying because it's the best way to
get many pointers that point to the same `wasmer_vm::Instance` in the
nature, and it's difficult to track them.

This patch changes the paradigm. There is only one and unique
`wasmer_vm::InstanceHandle` per `wasmer::Instance`, including its
clones. The handle is now stored inside a
`Arc<Mutex<wasmer_vm::InstanceHandle>>`. Consequently, when a
`wasmer::Instance` is cloned, it uses the same
`wasmer_vm::InstanceHandle`, not a clone of it.

Bonus: `wasmer::Instance` continues to be `Send` + `Sync`.

So. Let's back to our question. When to free
`wasmer_vm::InstanceHandle`? Response: When `wasmer::Instance` is
dropped. Right? There is a unique path from `wasmer::Instance`, to
`wasmer_vm::InstanceHandle`, to `wasmer_vm::Instance` now. So we just
need to call `wasmer_vm::InstanceHandle::dealloc` in a specific `Drop`
implementation for `wasmer_vm::InstanceHandle`, and the Rust borrow
checker does the rest.

Yes. … No. There is another use case: It is possible to create a
`wasmer_vm::InstanceHandle` with `InstanceHandle::from_vmctx`. Indeed,
a `wasmer_vm::VMContext` also stores a pointer to
`wasmer_vm::Instance`. In this, we consider `wasmer_vm::VMContext`
owns the instance pointer, somehow, and is responsible to free it
properly.

Consequently, we need another flag inside `wasmer_vm::InstanceHandle`
to know whether this structure owns the pointer to
`wasmer_vm::Instance` or not.

So. Let's back to our question. When to free
`wasmer_vm::InstanceHandle`? Response: Inside the `Drop`
implementation of `wasmer_vm::InstanceHandle` with its `Self::dealloc`
method if and only if the handle owns the pointer to
`wasmer_vm::Instance`.

Testing with Valgrind shows that the leak has been removed.

[`Layout`]: https://doc.rust-lang.org/std/alloc/struct.Layout.html
[`alloc`]: https://doc.rust-lang.org/std/alloc/fn.alloc.html
[`dealloc`]: https://doc.rust-lang.org/std/alloc/fn.dealloc.html

# Review

- [ ] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2020-11-19 18:14:04 +00:00
Ivan Enderlin
297eb952ab feat(api) Faster Exports::from_iter.
Instead of creating a new `Exports` with `Exports::new` and inserting
all pair `(String, Extern)` one after the other with
`Exports::insert`, this patch updates the code to create an `Exports`
directly with its `map` field built with `IndexMap::from_iter`, so
that we avoid calling `Arc::get_mut(…).unwrap().insert(…)` for every
pair.
2020-11-19 11:41:19 +01:00
Ivan Enderlin
ca89bd5d75 feat(api) Rename Extern::from_export to …::from_vm_export.
I hope this little change will clarify a little bit that the `Export`
passed to `Extern::from_vm_export` is not a `wasmer::Export` but a
`wasmer_vm::Export`.
2020-11-19 11:06:18 +01:00
Mark McCaskey
84370c7930 Merge branch 'master' into feature/make-env-immutable 2020-11-18 15:40:11 -08:00
Mark McCaskey
0e03544163 Merge branch 'feature/host-env-prototype' of github.com:wasmerio/wasmer into feature/host-env-prototype 2020-11-18 14:24:26 -08:00
Mark McCaskey
85169f6996 Add misc clean ups and corrections 2020-11-18 14:23:40 -08:00
Mark McCaskey
2065556c41 Merge branch 'master' into feature/host-env-prototype 2020-11-18 13:49:38 -08:00
Mark McCaskey
15e88a1195 Clean up error message in proc macro, improve docs on WasmerEnv 2020-11-18 12:12:24 -08:00
Mark McCaskey
7131caa8d9 Implement WasmerEnv for dyn Any 2020-11-18 11:31:57 -08:00
Mark McCaskey
3580f165e8 Rename WasmerEnv::finish to WasmerEnv::init_with_instance 2020-11-17 17:14:11 -08:00
Mark McCaskey
6aab77e503 Add default impl for WasmerEnv::finish remove macro 2020-11-17 16:25:07 -08:00
Mark McCaskey
2b0464a4b2 Port wasmer-emscripten to use WasmerEnv 2020-11-17 16:19:00 -08:00
Mark McCaskey
38b296e36f Move WasmerEnv into its own mod, implement it for stdlib types 2020-11-17 15:30:21 -08:00