Is there a way to forcefully terminate a running wasm function call.
Currently when a module with an infinite loop is run there seems to be no way to interrupt the function call. What would be the best way to guard against this kind of code? Would it make sense to preprocess the wasm module and inject a maybe_halt function call?
(module
(func $run
(loop
(br 0)
))
(export "run" (func $run))
)
Not yet.
An instrumentation framework supporting this kind of code injection is on the roadmap.
As Iosfair said, we don't support this yet. There are a couple of approaches we could take here.
We can inject a signal into the thread running the wasm, but there may be undefined behavior and whatnot if we interrupt a host function.
We could also inject an access to a specific, preknown memory page into the trailing edges of loops and function calls that will normally get passed through the cpu pipeline without much ado, but we can then unmap that page and trigger a signal on that thread.
@fd @losfair @lachlansneff Have a look at https://github.com/ewasm/wasm-metering - which injects calls to metering functions before each block.
Most helpful comment
Not yet.
An instrumentation framework supporting this kind of code injection is on the roadmap.