Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1810: Adding a way to get an unlocked `WasiState` mutex r=MarkMcCaskey a=TheLostLambda # Description I'm currently developing a WASM-based [plugin system for Mosaic](https://github.com/mosaic-org/wasm-module-experiments), but I've encountered a number of rough edges throughout my time working with the 1.0 alphas (as is to be expected 🙂 ). I hope to eventually upstream a number of tweaks, but this first one is quite simple. Unfortunately, it's also something I needed a fork of the library to pull off. I have a host-function (that can be called from the WASM module) that needs access to the stdout of the WASM VM, but I was struggling to pass the VM state to the host-function using `Function::new_native_with_env()`. Conveniently, `state` in `WasiEnv` [is stored as an `Arc<Mutex<WasiState>>`](https://github.com/wasmerio/wasmer/blob/e9b280b4ddf290c1b27a27fa1e78114708c5fdaa/lib/wasi/src/lib.rs#L53) – exactly what I needed to pass a thread-safe copy of the state into [my `host_open_file()` function](https://github.com/mosaic-org/wasm-module-experiments/blob/e2da74fb1db5692aeb0b3a19f633b3ad3410a96c/loader/src/main.rs#L133) Tragically, that `state` field is private, and there is no way (so far as I can see) to get a copy of that unlocked Mutex. Just making the field public (as in this PR) might not be ideal if it's likely to change though, so I'm also open to writing a getter-function instead. As a side note, I think that I managed to hit a deadlock when I called a WASM function in the same scope as a `WasiEnv::state()` call. This, for example, totally deadlocks the program: ![image](https://user-images.githubusercontent.com/6251883/98750168-26169900-23b5-11eb-85bf-122882b37f88.png) This isn't really a massive issue, but would be clearer if `WasiEnv::state()` returned the actual Mutex that the user needs to lock. At the moment, this seems like an easy trap to fall into. # Review - [x] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Brooks J Rady <[email protected]> Co-authored-by: Brooks Rady <[email protected]>
- Loading branch information