-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add an unsafe API to unload process trap handlers #9022
Add an unsafe API to unload process trap handlers #9022
Conversation
This commit adds a new unsafe API `Engine::unload_process_handlers` which can be used to de-initialize trap-handling state in a process. In general this is an unsafe operation that we have no means of making safe, hence the `unsafe`. There are particular situations where this can be done safely though and this is provided for such situations. The safety conditions rely on invariants that Wasmtime itself cannot maintain so the burden is on callers to ensure that this is invoked in a safe manner. This is inspired by discussion [on Zulip][zulip] where Wasmtime's trap handling infrastructure prevented unloading a DLL with Wasmtime in it. There's possibly other reasons that unloading DLLs are unsafe in Rust but it feels appropriate to at least provide this knob to embedders to be able to turn if they like. [zulip]: https://bytecodealliance.zulipchat.com/#narrow/stream/206238-general/topic/How.20to.20safely.20drop.20wasmtime.3F/near/453366905
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given how specialized this is, consider all the functional comments just questions.
/// * All existing threads which have used this DLL or copy of Wasmtime may | ||
/// no longer use this copy of Wasmtime. Per-thread state is not iterated | ||
/// and destroyed. Only future threads may use future instances of this | ||
/// Wasmtime itself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to explicitly poison this copy of wasmtime with a global or is that already effectively happening?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hesitant to go out of our way to do that as it might slow down other parts for this niche unsafe part, so I'd lean towards making this part of the unsafe contract rather than trying to add more guard rails.
Good suggestions/questions! I've tried to wordsmith and update a bit. |
Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
This commit adds a new unsafe API
Engine::unload_process_handlers
which can be used to de-initialize trap-handling state in a process. In general this is an unsafe operation that we have no means of making safe, hence theunsafe
. There are particular situations where this can be done safely though and this is provided for such situations. The safety conditions rely on invariants that Wasmtime itself cannot maintain so the burden is on callers to ensure that this is invoked in a safe manner.This is inspired by discussion on Zulip where Wasmtime's trap handling infrastructure prevented unloading a DLL with Wasmtime in it. There's possibly other reasons that unloading DLLs are unsafe in Rust but it feels appropriate to at least provide this knob to embedders to be able to turn if they like.