Skip to content

Commit ce5ff45

Browse files
authored
[Wasm] Instantiate error detection (#128167)
Better failure mode when trying to load an R2R module using a release build of corerun.js.
1 parent 47759f1 commit ce5ff45

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/coreclr/hosts/corerun/wasm/libCorerun.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ function libCoreRunFactory() {
220220
if (_posix_memalign(ptrPtr, 16, payloadSize)) {
221221
throw new Error("posix_memalign failed for Webcil payload");
222222
}
223+
if (typeof (wasmExports.__stack_pointer) === "undefined") {
224+
throw new Error("__stack_pointer was not preserved by the linker or optimizer");
225+
}
223226
payloadPtr = HEAPU32[ptrPtr >>> 2 >>> 0];
224227
wasmInstance = new WebAssembly.Instance(wasmModule, {
225228
webcil: {
@@ -229,6 +232,10 @@ function libCoreRunFactory() {
229232
tableBase: new WebAssembly.Global({ value: "i32", mutable: false }, tableStartIndex),
230233
imageBase: new WebAssembly.Global({ value: "i32", mutable: false }, payloadPtr)
231234
}});
235+
} catch (e) {
236+
const errorMessage = e instanceof Error ? e.message : String(e);
237+
console.error("Failed to construct WebAssembly instance for Webcil image:", {wasmPath, errorMessage});
238+
return false;
232239
} finally {
233240
stackRestore(sp);
234241
}

0 commit comments

Comments
 (0)