SkylerLipthay / mini-v8

A minimal embedded V8 JavaScript engine wrapper for Rust
MIT License
104 stars 11 forks source link

Segmentation fault when running WASM #2

Closed hoangpq closed 4 years ago

hoangpq commented 4 years ago

I created simple code follow the v8 example hello_world.cc to run WASM

fn main() {
    let mv8 = MiniV8::new();
    let value: Value = mv8
        .eval(
            r#"
              let bytes = new Uint8Array([
                0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01,
                0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07,
                0x07, 0x01, 0x03, 0x61, 0x64, 0x64, 0x00, 0x00, 0x0a, 0x09, 0x01,
                0x07, 0x00, 0x20, 0x00, 0x20, 0x01, 0x6a, 0x0b
              ]);

              let module = new WebAssembly.Module(bytes);
              let instance = new WebAssembly.Instance(module);
              instance.exports.add(3, 4)
            "#,
        )
        .unwrap();

    dbg!(value);
}

The messages are as follows:

[examples/simple.rs:35] value = 7
Segmentation fault: 11

@SkylerLipthay Can you help me to point out the issue.

SkylerLipthay commented 4 years ago

Thanks for the report! I finally got around to fixing this. Previous releases of MiniV8 had a major memory management flaw in the FFI. This has been fixed, a regression test has been added, and a new MiniV8 release will be published very soon.