wasmedge-rust-sdk icon indicating copy to clipboard operation
wasmedge-rust-sdk copied to clipboard

bug: Host function call through `VmDock::run_func` triggers segfault.

Open michael-0acf4 opened this issue 2 years ago • 1 comments

Summary

[1]    20267 segmentation fault (core dumped)  cargo run

Out of scope ImportObject<T> value segfaults the host program.

test-project.zip

Current State

In my wasm binary I have a function add_bindgen_host that calls a host function add_host which I then call using VmDock::run_func in WasmEdge. The issue arises when the referenced value goes out of scope, any subsequent call triggers a segmentation fault. I did not have this issue on wasmedge 0.8.1 as the variable ownership was directly transfered (vs borrowed in the current API),

Expected State

Run bindgen -- say: 3

Reproduction steps

  1. (guest) Create an extern function host_add to be defined in (host)
  2. (guest) Create a function add_bindgen_host with wasmedge_bindgen macro, that calls the host function host_add
  3. (host) define host_add
  4. (host) define init_vm function that returns a Vm, host_add import happens inside that function
  5. (host) in main, create a VmDock, and run add_bindgen_host, the program should segfault with exit code 11

Screenshots

No response

Any logs you want to share for showing the specific issue

No response

Components

Rust SDK

WasmEdge Version or Commit you used

0.13.5

Operating system information

Pop!_OS 22.04

Hardware Architecture

x86_x64

Compiler flags and options

No response

michael-0acf4 avatar Dec 09 '23 17:12 michael-0acf4

Hi @apepkuss Please check this issue.

hydai avatar Dec 09 '23 17:12 hydai