wasmer: Wasmer can't run Doom
I understand that this is a somewhat nebulous, perhaps frivolous issue. Here it is anyway.
Wasmer fails to run a Doom Wasm port. This article by Cornelius Diekmann documents the process of porting Doom to WebAssembly and results in this demo. In my own explorations of the subject, I found that the Doom Wasm module runs as expected in the browser (tested on Chrome, Safari, Firefox) and Wasmtime, but fails using Wasmer.
The only clue as to what is going on is the following trap message on invocation of the main export function.
out of bounds memory access
Wasmer version: 4.2.0
Steps to reproduce
Descriptions for recreating the issue can be found in my write up. Alternatively, the module can be initialized with relatively few imports. I’ve attached the Wasm module in question.
Expected behaviour
Invocation of the main export function should result in the following expected logs.
Hello, World, from JS Console! Answer=42 (101010 in binary) Hello, world from rust! 🦀🦀🦀 (println! working) Starting D_DoomMain Triggering a printf Doom’s screen is 320x200 mallocing 12 bytes at 7078176
Actual behavior
Invocation of the main export function results in the following logs before the function invocation fails.
Hello, World, from JS Console! Answer=42 (101010 in binary) Hello, world from rust! 🦀🦀🦀 (println! working)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (17 by maintainers)
Here’s a minimal rust repro:
The underlying issue is in
Function::new, which is also used from C as typed functions aren’t possible via the WASM C API. Functions created throughFunction::newdon’t get afunc_ptrwhich, at runtime, causes acallinstruction to the zero address, hence the error. Under the LLVM backend, this turns into anIndirectCallToNulltrap because the LLVM backend checks thefunc_ptr. The cranelift and singlepass backends don’t, and instead get a sigsegv which is translated into an out of bounds memory access by the VM layer.I’m still investigating how this can be fixed, since I have little familiarity with the compiler backends; I took this issue out of my love for computer games 😄
@ashtonmeuser Thanks for reporting this! This may in fact help us with something we’re working on right now, so I’ll investigate the issue.