WebAssembly Runtime - WebGHC/wasm-cross GitHub Wiki

WebAssembly Runtime

Refer https://developer.mozilla.org/en-US/docs/WebAssembly for WebAssembly overview.

Execution environment

Memory

The memory allocated to a WebAssembly executable is a linear array (with index starting from 0), which is accessible from both JavaScript and WebAssembly code.

The memory is just a plain continuous block of byte array, which has to be used by the runtime as either Heap or stack.

The memory block only grows, there is no concept of freeing the memory.

The pointer values are simply the indices of the array.

Accessing memory from JavaScript

// Example C
myfun (int n, int* iPtr, int** iSPtr) {
  int i = 0;
  for (; i < n; i++) {
    int j = iPtr[i];
    iSPtr[i][j] = i * j;
  }
}

// JS
myfun (n, iPtr_, iSPtr_) {
  var iPtr = iPtr_ / 4;
  var iSPtr = iSPtr_ / 4;
  for (var i = 0; i < n; i++) {
    var j = heap_uint32[iPtr + i];
    var ptr_ = heap_uint32[iSPtr + i];
    var ptr = ptr_ / 4;
    heap_uint32[ptr + j] = i * j;
  }
}

Kernel

Overview of kernel Sys calls http://man7.org/linux/man-pages/dir_section_2.html

Input / Output

FileSystem

Concurrency

This looks promising https://github.com/lars-t-hansen/parlib-simple

https://github.com/kripken/emscripten/blob/incoming/src/pthread-main.js

Timer/Interrupts