dotnet/runtime · critical · Error
posix_memalign failed for Webcil payload
Error message
posix_memalign failed for Webcil payload
What it means
Thrown by allocWebcilPayload() (src/native/libs/Common/JavaScript/host/assets.ts:93) when _posix_memalign fails to allocate the 16-byte-aligned buffer that backs a Webcil image. This buffer holds the image payload passed as the imageBase import and must outlive the instantiate call, so it is heap-allocated rather than stack-allocated.
Source
Thrown at src/native/libs/Common/JavaScript/host/assets.ts:98
}
}
async function checkWebcilResponse(webcilPromise: Promise<Response>, virtualPath: string): Promise<Response> {
const res = await webcilPromise;
if (!res || res.ok === false) {
throw new Error(`Failed to load Webcil module '${virtualPath}'. HTTP status: ${(res as Response)?.status} ${(res as Response)?.statusText}`);
}
return res;
}
// Allocates a 16-byte-aligned buffer for the Webcil payload. The pointer is heap memory that
// outlives the stack frame, so it can be passed as the imageBase import.
function allocWebcilPayload(payloadSize: number): number {
const sp = _ems_.stackSave();
try {
const ptrPtr = _ems_.stackAlloc(sizeOfPtr);
if (_ems_._posix_memalign(ptrPtr as any, 16, payloadSize)) {
throw new Error("posix_memalign failed for Webcil payload");
}
return _ems_.HEAPU32[ptrPtr as any >>> 2];
} finally {
_ems_.stackRestore(sp);
}
}
// Builds the `webcil` import object. For R2R images (tableSize > 0) the module imports the runtime's
// stack pointer, exception tag, indirect-call table and base globals; this also grows the table.
// These import names and the webcilVersion/getWebcilPayload/fillWebcilTable handshake in
// finishWebcilInstance are the R2R Webcil-in-Wasm host ABI defined by crossgen's WasmObjectWriter
// (src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs, CreateDefaultGlobalImports/
// WriteExports). Keep in sync with the corerun host
// (src/coreclr/hosts/corerun/wasm/libCorerun.js, BrowserHost_ExternalAssemblyProbe). Unlike corerun,
// which parses data segment 0 for payloadSize/tableSize, this loader receives them from boot config.
function buildWebcilImports(memory: WebAssembly.Memory, payloadPtr: number, tableSize: number): Record<string, WebAssembly.ImportValue> {
const webcilImports: Record<string, WebAssembly.ImportValue> = { memory };
if (tableSize > 0) {View on GitHub (pinned to 60108ba66e)
Solutions
- Increase the runtime's maximum WebAssembly.Memory so the heap can hold the largest webcil image plus the rest of the working set.
- Reduce the size or number of R2R webcil assemblies loaded concurrently (lazy-load large assemblies).
- If it appears after earlier successes, look for a heap memory leak in the host.
Example fix
// before: default memory cap, large R2R assembly -> posix_memalign failed for Webcil payload
// after
{ "memory": { "initial": 1, "maximum": 4294 } } Defensive patterns
Strategy: try-catch
Validate before calling
// approximate headroom before instantiating a large webcil image
function hasRoomFor(payloadSize: number): boolean {
const max = 2 * 1024 * 1024 * 1024; // typical wasm memory ceiling
const used = (globalThis as any).Module?.HEAP8?.buffer.byteLength ?? 0;
return used + payloadSize < max;
} Try / catch
try {
await instantiateWebcilModule(webcilPromise, memory, virtualPath, tableSize, payloadSize);
} catch (err) {
if (/posix_memalign failed for Webcil payload/.test(String((err as Error).message))) {
// raise maximum memory or lazy-load the oversized R2R assembly
}
throw err;
} Prevention
- Raise the runtime maximum memory to fit the largest R2R webcil image.
- Lazy-load large R2R assemblies instead of eager-loading them all.
- Cap concurrent webcil instantiations.
When it happens
Trigger: instantiateWebcilModule computes payloadSize from the boot config and calls allocWebcilPayload(payloadSize); posix_memalign returns non-zero because the wasm heap cannot accommodate payloadSize bytes (would exceed maximum memory).
Common situations: An R2R/large webcil assembly larger than remaining memory headroom; a runtime whose maximum memory is too small; many concurrent webcil instantiations exhausting the heap.
Related errors
- posix_memalign failed
- posix_memalign failed for ICU data
- Unsupported Webcil version: ${webcilVersion}
- Failed to load ICU data
- .NET runtime has failed to start, because too much memory wa
AI-assisted analysis of dotnet/runtime@60108ba66e (2026-08-10).
Data as JSON: /api/errors/8cc9e90a9e83f831.
Report an issue: GitHub.