Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to solve cyclic ref in WasmerEnv #2312

Closed
wants to merge 2 commits into from

Conversation

MarkMcCaskey
Copy link
Contributor

Trying to fix #2304

I'm not sure we want to go with the strategy in this PR, it's very low level and unsafe. The idea is to decrement the strong count of InstanceRef for each export in the Env because in the context of host functions, anything coming from the same instance is guaranteed to be alive. We must preserve the property that cloning these types then increments the InstanceRef count though, so we can't get rid of it entirely. Additionally we have to handle the case of something being re-exported, so we can't assume that if something is exported from an Instance that it's owned by that Instance.

The PR currently gets stuck in an infinite loop during instantiation.

Review

  • Add a short description of the change to the CHANGELOG.md file

@MarkMcCaskey MarkMcCaskey mentioned this pull request May 19, 2021
1 task
@MarkMcCaskey
Copy link
Contributor Author

Closing this in favor of #2327 as #2327 is essentially an iteration on this that's more complete and simpler

@MarkMcCaskey MarkMcCaskey deleted the fix/cyclic-ref-in-wasmerenv branch May 26, 2021 14:09
bors bot added a commit that referenced this pull request May 28, 2021
2327: Fix cyclic ref in WasmerEnv r=syrusakbary a=MarkMcCaskey

This is an alternative to #2312 to fix #2304 

The core idea is to have a `WeakInstanceRef` too. The main concern is that `Memory` (from a `WasmerEnv`) should behave like it has a strong instance ref if it's cloned. Currently we always convert weak `VMMemory`s into strong ones and if we can't, we panic.

1 other edge case not handled yet: we need to make sure that when the `InstanceRef` is weak that everything still works as expected (for example when the `Instance` it points to is gone). Or maybe we don't. `WasmerEnv`s are always passed by `&` and `Clone`ing forces them to upgrade into `Strong` or panic. So there's no real case where this can happen except for when you're calling into a host function from Wasm while the Instance is freed. Doing that means that you're already executing uninitialized memory as code so it shouldn't be possible / if it is, the concern is not with`WasmerEnv`.

# Review

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


Co-authored-by: Mark McCaskey <[email protected]>
Co-authored-by: Syrus Akbary <[email protected]>
Co-authored-by: Mark McCaskey <[email protected]>
bors bot added a commit that referenced this pull request May 28, 2021
2327: Fix cyclic ref in WasmerEnv r=MarkMcCaskey a=MarkMcCaskey

This is an alternative to #2312 to fix #2304 

The core idea is to have a `WeakInstanceRef` too. The main concern is that `Memory` (from a `WasmerEnv`) should behave like it has a strong instance ref if it's cloned. Currently we always convert weak `VMMemory`s into strong ones and if we can't, we panic.

1 other edge case not handled yet: we need to make sure that when the `InstanceRef` is weak that everything still works as expected (for example when the `Instance` it points to is gone). Or maybe we don't. `WasmerEnv`s are always passed by `&` and `Clone`ing forces them to upgrade into `Strong` or panic. So there's no real case where this can happen except for when you're calling into a host function from Wasm while the Instance is freed. Doing that means that you're already executing uninitialized memory as code so it shouldn't be possible / if it is, the concern is not with`WasmerEnv`.

# Review

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


Co-authored-by: Mark McCaskey <[email protected]>
Co-authored-by: Syrus Akbary <[email protected]>
Co-authored-by: Mark McCaskey <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LazyInit<Memory> does not call munmap
1 participant