wasm3 / wasm3-rs

Rust wrapper for Wasm3, the fastest WebAssembly interpreter
MIT License
160 stars 44 forks source link

fix: Calculates the offset by sizeof #11

Closed douchuan closed 4 years ago

Veykril commented 4 years ago

What exactly does this fix? ptr::add work in units of T, so this change offsets the pointer by size_of::<u32/u64> * size_of::<ParamterType> which is very much wrong to my knowledge.

douchuan commented 4 years ago

My mistake, just ignore it.

The exact bug is: can't get the second arg's val .

I declare extensions like this:

mod env {
    extern "C" {
        pub fn add_u32(a: u32, b: u32) -> u32;
    }
}

and, used it like this:

wasm3::make_func_wrapper!(add_u32_wrap: add_u32(a: u32, b: u32) -> u32);
fn add_u32(a: u32, b: u32) -> u32 {
    a + b
}

the 'b''s value isn't right.

I check wasm3 code, found:

m3_compile.c, CompileCallArgsAndReturn, say:


   u32 slotsPerArg = sizeof (u64) / sizeof (m3slot_t);
    // args are 64-bit aligned
    u16 argTop = topSlot + numArgs * slotsPerArg;

so, the value SIZE_IN_SLOT_COUNT of u32/i32/f32, should be '2'

Veykril commented 4 years ago

Ah yes, I also noticed this probably earlier today, https://github.com/Veykril/wasm3-rs/issues/12. Can you try with default features off and see if the problem persists?

[dependencies.wasm3]
git = "https://github.com/Veykril/wasm3-rs"
default-features = false
douchuan commented 4 years ago

it's ok with 'default-features = false'

Veykril commented 4 years ago

56858c8 should've fixed this, please let me know if it did for you.

douchuan commented 4 years ago

Thanks, it worked for me, great work.

Veykril commented 4 years ago

Aight, thanks for confirming 😄