Skip to content
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

Invoke other wasm function in native api: "Exception: invalid exec env" #3988

Open
Jiax-cn opened this issue Dec 26, 2024 · 2 comments
Open

Comments

@Jiax-cn
Copy link

Jiax-cn commented Dec 26, 2024

I'm trying to invoke a wasm function (of another instance) in my native api, but failed with "Exception: invalid exec env". Is it impossible to achieve this without setting WAMR_DISABLE_HW_BOUND_CHECK? Any guidance would be appreciated.

@lum1n0us
Copy link
Collaborator

It's advisable not to use WAMR_DISABLE_HW_BOUND_CHECK to switch to software bounds checking unless the platform has poor support for signals and jmp.

For reference, please look at the examples in samples/basic or samples/spawn-thread, depending on your specific use case.

If that's acceptable, please share your embedded code for discussion.

@Jiax-cn
Copy link
Author

Jiax-cn commented Dec 26, 2024

Thanks for your response. Here is a simplified version of the code I’m working with:

hello.wasm

(import "my_module" "world" (func $world_func))
(func $_start 
  ;; printf("hello ")
  call $world_func
)

world.wasm

(func $_start 
  ;; printf("world!\n")
)

host_app

int main() {
    ...
    hello_module = wasm_runtime_load(hello_wasm ...);
    hello_module_inst = wasm_runtime_instantiate(hello_module, ...);
    hello_func = wasm_runtime_lookup_function(hello_module_inst, "_start");
    hello_exec_env = wasm_runtime_create_exec_env(hello_module_inst, ...);

    world_module = wasm_runtime_load(world_wasm ...);
    world_module_inst = wasm_runtime_instantiate(world_module, ...);
    world_func = wasm_runtime_lookup_function(world_module_inst, "_start");
    world_exec_env = wasm_runtime_create_exec_env(world_module_inst, ...);

    wasm_runtime_call_wasm(hello_exec_env, hello_func, ...);

    ...
}

native api wrapper

static void my_module_world_wrapper(...) {
    if (!wasm_runtime_call_wasm(world_exec_env, world_func, ...)) {
        // Exception: invalid exec env
        os_printf("%s\n", wasm_runtime_get_exception(world_module_inst));
    }
}

expected result:

hello world!

but result:

hello

#00: 0x0000 - _start

Exception: invalid exec env

@Jiax-cn Jiax-cn closed this as completed Dec 26, 2024
@Jiax-cn Jiax-cn reopened this Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants