Using Zig with WebAssembly

This is part of Wasm’s tool conventions. You can’t just have a bunch of WASM libraries interact with each other, share memory, and so on without any way to coordinate things like where the stack and heap are. This is separate from the stack of the Wasm runtime itself, and is instead part of Wasm’s linear memory.

Looking in the convention on dynamic linking:

  • env.__stack_pointer - A mutable i32 global representing the explicit stack pointer as an offset into the above memory.

This should (?) make it safer (?) for two separate Wasm modules to share memory.

AFAIK, C/++, Rust, and others follow these conventions to some extent, tho I assume most of it comes from having LLVM as a backend.

4 Likes