-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wasmer/js raises cannot read property 'buffer'
when try to access memory via Env
#2816
Comments
Thanks for creating the issue! We have identified an issue in wasmer-js raleted to this that basically frees the imports after instantiating (this doesn't happen when you use a js-only approach, but it happens in Rust). This will be fixed in the next releases. To verify this assumption, could you try storing the fn load_plugin() -> Result<(Instance, ImportObject, Arc<Mutex<Vec<u8>>>), Error> {
let wasmer_store = Store::default();
let module = Module::new(&wasmer_store, &WASM_BINARY);
return match module {
Ok(module) => {
let transform_result: Arc<Mutex<Vec<u8>>> = Arc::new(Mutex::new(vec![]));
let set_transform_result_fn_decl = Function::new_native_with_env(
&wasmer_store,
HostEnvironment {
memory: LazyInit::default(),
transform_result: transform_result.clone(),
},
set_transform_result,
);
let imports = imports! {
"env" => {
"__set_transform_result" => set_transform_result_fn_decl,
}
};
let instance = Instance::new(&module, &imports).unwrap();
Ok((instance, imports, transform_result))
},
Err(err) => panic!("should not be here"),
}
}
fn run() {
let (instance, imports, transform_result) = load_plugin().unwrap();
let input_ptr = write_bytes_into_guest(&instance, &input_serialized);
let transform_fn = instance
.exports
.get_native_function::<(i32, i32), i32>("__guest_transform")
.unwrap();
transform_fn.call(input_ptr.0, input_ptr.1).unwrap();
} |
Oh wow, I spent nearly week to find out isolated case cause I never expected creating a fn might cause unexpectedly drop imports. I tried suggested verification and it looks like correctly preserving imports. Guess I can wait for next release. Thanks! |
This issue is solved will be fully resolved on the next major Wasmer release 3.0: |
Describe the bug
Note: I'm filing this as a bug since I was not able to figure out why one passes and the other is not, but it is totally possible I made a mistakes in my code. Please change category if needed. 🙏
I'm trying to make existing wasm execution logic to be compatible on
wasmer/js
features as well, to allow run wasm binary from its executor / runner compiled into wasm itself. I made poc work, however in certain case wasmer raisesTypeError: Cannot read property 'buffer' of undefined
when it try to access memory from imported fn's env and I am not able to figure out what exactly triggers this.Passing poc
Failing POC
Codes are exactly same, the only difference is failing cases have separate fn to load / instantiate module then return created instance (with cloned env properties).
load_plugin
maybe?Thanks!
Steps to reproduce
Expected behavior
Actual behavior
The text was updated successfully, but these errors were encountered: