-
Notifications
You must be signed in to change notification settings - Fork 494
Description
Functions defined in embedding section provide abstraction of Wasm's mechanics to embedders. However, I found a case in JS API specification that breaks this abstraction: monitoring the execution of Wasm. I'm curious whether these are inevitable or intentional.
Abstraction over the mechanics of Wasm execution is achieved by the embedding function func_invoke. As shown in Fig. 1, it takes a function address, invokes the corresponding function, and returns the result. By using this function, the embedder does not need to understand how execution of Wasm is performed.
Fig. 1: Embedding function func_invoke
However, there is an algorithm that must run immediately after a WebAssembly memory.grow instruction executes, which requires monitoring the Wasm execution context. Not only that, this algorithm inspects the value at the top of the stack (line 1) and accesses the current frame (line 1.1-1.3). These steps even require knowledge of the composition of the Wasm state and direct access to its internal structures.
These requirements significantly breaks the abstraction layer established by func_invoke. Could the algorithm be reformulated in a way that preserves this abstraction?
Fig.2: JS API algorithm which is performed "immediately after a WebAssembly memory.grow instruction executes"