wasm-posix-host
    Preparing search index...

    Function patchWasmForThread

    • Patch a Wasm binary for use in a thread instance (shared memory).

      In LLVM's shared-memory Wasm model:

      • The Start function (section id=8) is __wasm_init_memory — it initializes passive data segments with an atomic guard. Threads must NOT re-run this.
      • A separate constructor function (__wasm_call_ctors) runs C++ global constructors. LLVM inserts a call to this function at the beginning of every exported function. Threads must NOT re-run constructors either, as they would clobber shared global state (e.g. resetting LOGGER::file_log_handler to NULL in MariaDB).

      This function:

      1. Removes the Start section so __wasm_init_memory doesn't auto-run.
      2. Finds the constructor function by scanning the known LLVM helper exports for their common call target and replaces that function body with a no-op.

      Parameters

      • bytes: ArrayBuffer

      Returns ArrayBuffer