Skip to content

Validation error: Trying to access parent frame stack values. #199

Closed
@DarrenTsung

Description

@DarrenTsung

Hi, I'm getting a super strange error with wasm-bindgen that I wasn't seeing in the past few days.

Basically when I'm pushing a boxed trait object to some storage (a Vec<Box<_>>), wasm-bindgen fails with:

error: failed to create wasmi module
	caused by: Validation: Function #165 validation error: Trying to access parent frame stack values.

It looks like it's running the output wasm file through an interpreter to figure out the signature of the exposed functions(?).

Here's the minimal lib.rs I'm managed to compile this down to:

#![feature(proc_macro, wasm_custom_section, wasm_import_module)]

use std::boxed::Box;
use std::cell::RefCell;
use std::rc::Rc;

extern crate wasm_bindgen;

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn greet(mut holder: TestTraitHolder) {
    let test_struct = TestStruct::new();
    let boxed = Box::new(test_struct);

    // If you comment this out, no errors from wasm-bindgen.
    holder.hold.push(boxed);
}

#[wasm_bindgen]
pub struct TestTraitHolder {
    hold: Vec<Box<TestTrait>>,
}

#[wasm_bindgen]
pub struct TestStruct {
    a: Rc<RefCell<u32>>,
    f: Rc<RefCell<ButtonState>>,
}

#[wasm_bindgen]
impl TestStruct {
    pub fn new() -> TestStruct {
        TestStruct {
            a: Rc::new(RefCell::new(0)),
            f: Rc::new(RefCell::new(ButtonState { hovered: true, clicked_in: false, clicked: true, })),
        }
    }
}

#[derive(Clone)]
struct ButtonState {
    pub hovered: bool,
    pub clicked_in: bool,
    // If you remove one of these fields, no errors from wasm-bindgen.
    pub clicked: bool,
}

pub trait TestTrait {
    fn hello(&self);
}

impl TestTrait for TestStruct {
    fn hello(&self) {
        // If you comment this out OR change `self.f` to `self.a`, no errors from wasm-bindgen
        let _hi = self.f.borrow().clone();
    }
}

The way I tested this was to create a new hello-world project from the README and sub in this lib.rs and run:
cargo build --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/debug/wasm_validation_64.wasm --out-dir .

There's also a lot of weird ways to make this go through wasm-bindgen without complaining, see the comments. Does anyone know why this might be happening?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions