Use EntryStoreContext to manage state when entering and exiting Wasm#10626
Use EntryStoreContext to manage state when entering and exiting Wasm#10626fitzgen merged 5 commits intobytecodealliance:mainfrom
Conversation
|
CC @fitzgen |
fitzgen
left a comment
There was a problem hiding this comment.
Looks great, will merge once our collective nitpicks are addressed. Thanks a ton for this clean up!
|
Initial comparison to DetailsLooks like an improvement for most things! Going to look into the regressions a little bit. |
Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
|
Okay I've got a few Details |
| // same store and `self.vm_store_context == self.prev.vm_store_context`) and we must to | ||
| // maintain the list of contiguous-Wasm-frames stack regions for | ||
| // backtracing purposes. | ||
| // FIXME(frank-emrich) Does this need to be an (Unsafe)Cell? |
There was a problem hiding this comment.
Following the reasoning about UnsafeCell elsewhere, I guess the answer is "no" here then as well
There was a problem hiding this comment.
Correct, because nothing is mutating this pointer in such a way that violates Rust's regular borrowing discipline.
There was a problem hiding this comment.
Actually, I remember now why I put this comment here: The previous old_* fields were Cells. Maybe that was just some leftover.
There was a problem hiding this comment.
Yeah, should be fine to remove.
|
Currently, there are two places that perform some updates to the runtime when entering and exiting Wasm: In
runtime::vm::catch_traps(together withCallThreadState'sdrop) and infunc.rs(using theenter_wasm/exit_wasmfunctions there). I believe @alexcrichton mentioned that this split is mostly for legacy reasons due to how to things were separated into different crates until recently.As a result, both of these places need to store different parts of the runtime state, and then restore it at the right moment.
This PR consolidates all of this into one place using a new type,
EntryStoreContext, whoseenter_wasmandexit_wasmfunctions mimic the original functions, but also subsume what previously happened inCallThreadState. The code is just moved around with minimal changes. The name of the type reflects that we are storing a subset of theStoreContextupon entry into Wasm.The motivation for this refactoring is the following (discussed here): For the implementation of the stack switching proposal, we need to save and restore even more context. Using either of the places mentioned above lead to awkward code. Thus, this PR contains the necessary preparation work, without any stack-switching specific code.