Master the fundamental concepts of webassembly internals through this focused micro-challenge.
Wasm exposes one or more growable byte arrays called memories. \`memory.grow\` adds 64 KiB pages; loads and stores use \`i32\` addresses into index 0 by default in MVP modules.
Properties:
Hosts map the same linear memory for JS \`WebAssembly.Memory\` views or WASI \`mmap\` equivalents.
For example, \`memory.grow(1)\` on a 1-page memory yields 2 pages (128 KiB). An \`i32.store\` at offset 70000 traps on a single-page memory.
\`data\` segments copy initializer bytes into linear memory at compile time or instantiation.
Hosts may share one linear memory with multiple views (i8, i32). Alignment rules still apply; unaligned atomics have their own rules in threaded proposals you may see in newer specs.
This exercise asks you to document linear memory layout and \`memory.grow\` semantics. You will explain page growth and why every access must be bounds-checked for sandbox safety.
You will use the same mental model here when reading production interpreter source later in the track. Sketch one concrete input on paper, predict the outcome, then confirm with code. That discipline catches logic errors early and makes debugging far faster when you extend the implementation in follow-on tasks.
Write a C program that documents and simulates Wasm linear memory operations.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github