WebAssembly / WebAssembly/spec

[js-api] Monitoring the execution of Wasm

Open
#1,957 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
3.5k
Forks
539
Avg merge
2d 1h
Merged PRs (30d)
13

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.

Image

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?

Image

Fig.2: JS API algorithm which is performed "immediately after a WebAssembly memory.grow instruction executes"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the embedding section's func_invoke definition and the JS API algorithm that runs after memory.grow, following the linked specification steps and the two figures. Determine whether the algorithm can preserve the embedding abstraction, and document a resolved specification direction or reformulation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, wasm
Domain
api, compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.