-
Notifications
You must be signed in to change notification settings - Fork 271
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
Pause/Stop wasm execution #421
Comments
Will take some time to think through this. For starters, you can invoke an unexported function for the setup, if it is in wasm as the "start function" https://www.w3.org/TR/wasm-core-1/#start-function%E2%91%A4 other modules won't be able to call an unexported function directly |
Thank you. I'll check the I don't understand the internals of wasm, so I'm not sure how hard is to pause the execution of the wasm. I guess it have their on stack and so on, and it should recover from that point once |
the longer thinking will be around that wasm isn't necessarily executed from the same goroutine, though to pause it would imply it is forked somehow. An interceptor could pause anything, though even without that a host function can. pausing in the middle of wasm of a binary is likely expensive to implement unless the break points are well defined. If you are routinely routing through host functions, that's probably the cheapest pause area. |
You give me one idea, but I'm not sure if will work. In my case that might work, but not in general case. I would like to support many languages as possible (like Zig, Rust, Go, and may others). My goal is to use wazero similar to an "VM", running some arbitrary code (the compilation will be performed on my end, but the source-code might not be trusted). That is why I'm interested to set some limitation. I need to test it little bit more, but in general, that is the idea:
Expose one
I test the wasm, using TinyGo, with:
Compiling with |
ps I plan to revisit this topic after tomorrow as have some things to chase up. if you have other ideas and context meanwhile, please dump. This could even include links to other runtimes if they have some sort of stop-the-world feature. |
ps wires crossed as I was typing my response when you sent yours :D |
Note: we have multiple things that end up needing some sort of interceptor. If the pause feature can be loose to "the next call to an external function" interceptor would work. This same interceptor could implement tracing for each boundary cross (as demarcated by an external (import or export)) function call. |
PS I am going to focus time next week on the interceptor thing and we can see if it helps enough or not. I have to implement it anyway as debugging arbitrary wasm is too hard (takes too long) without some sort of interceptor, and if I don't I won't have enough time to do other things :D It is possible an interceptor won't be the right hook, but anyway we can find out and go another route if it doesn't. |
From the go docs, it's not immediately clear if canceling the passed |
Going to give some updates ps @sam-at-luther I answered you on a different issue as this one is on pause/resume which will be different than close (via cancel) #509 @inkeliz so @anuraaga added the first go of listener which has function hooks. This is internal which means to try it requires a fork of wazero. That's intentional because it isn't stable, yet and notably will need to change more as we finish the other two value types in WebAssembly 2.0 https://github.com/tetratelabs/wazero/blob/main/internal/experimental/api/listener.go I've also progressed some other things more direct to your question I think, though it isn't integrated in a way you can use it, yet. For example, your earlier question was about freezing the memory state. |
some of the use cases described here have now been addressed by #1108 |
Hi! I have a use case that involves "save states" of a text adventure game, so I was looking for a mechanism for doing that, something like wasmerio/wasmer#489 but for wazero. If I'm understanding this correctly, is it the case that I could pause execution and get a full dump of memory but perhaps not yet of the stack pointer and whatnot? EDIT: Oh, #1808 seems like what I'm looking for, never mind! |
I have the following code:
The idea is:
Any arbitrary module/wasm should create one array of 2048bytes. I omit the error handling. My program will call
SetupCommand
when the wasm initialize, so I can read the information in the future. I will callUpdate
multiple times (say, every 32ms), and the module/wasm should populate the command buffer with some content. Then, my program (which is using wazero) will read the given command (based on the pointer given onSetupCommand
).The issue is:
Currently, I need to
copy
the information, and I'm not sure how safe it's, since the module/wasm can change the memory at anytime, including while I'm copying it.Also, nothing prevents the wasm to continue to run, in the background, which may consume CPU. For instance, one "malicious wasm" could perform any task outside of the
Update
function. To make clear, one "malicious" code could usego func(){for {}}
, so it will keep running in the background. Or even worse, it could use somego func(){for{rand.Read(commandBuf)}}()
, so the wasm is changing thecommand
(which my program is reading).I would like to do something like:
The
Continue
andStop
will pause the execution of the module/wasm, preventing it from manipulate the memory and from perform any other task. In order words: the module/wasm will ONLY work whileUpdate
doesn't return (and I can implement some "timeout" to kill the wasm if it takes too long, that is not the point here). After callingStop()
, the module/wasm must not be able to perform any task anymore. The module/wasm can continue do whatever it's doing onceContinue
is called, including change the memory information and read it, it can also reply the nextUpdate
call. The honest code should never be affected, since it's design to only perform tasks insideUpdate
.I'm not sure if that can be done already, the only option seems to use
.Close()
, but I'm not sure how it would affect the performance, and if that will keep the information from the module (keep the memory).The text was updated successfully, but these errors were encountered: