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

wasm_func_call uses the wrong exec_env when multithreaded, gives "invalid exec env" #2172

Closed
cpetig opened this issue May 3, 2023 · 2 comments

Comments

@cpetig
Copy link
Contributor

cpetig commented May 3, 2023

If you call wasm_func_call from a callback which executes on a separate thread you get "invalid exec env" exception.

The check in wasm_runtime.c:2398 fails.

cpetig added a commit to cpetig/wasm-micro-runtime that referenced this issue May 3, 2023
cpetig added a commit to cpetig/wasm-micro-runtime that referenced this issue May 3, 2023
@cpetig
Copy link
Contributor Author

cpetig commented May 3, 2023

Testcase (adapted from samples/wasm-c-api-imports)
wamr_test_2172.zip

wenyongh pushed a commit that referenced this issue May 5, 2023
Fix issue reported in #2172: wasm-c-api `wasm_func_call` may use a wrong exec_env
when multi-threading is enabled, with error "invalid exec env" reported

Fix issue reported in #2149: main instance's `c_api_func_imports` are not passed to
the counterpart of new thread's instance in wasi-threads mode

Fix issue of invalid size calculated to copy `c_api_func_imports` in pthread mode

And refactor the code to use `wasm_cluster_dup_c_api_imports` to copy the
`c_api_func_imports` to new thread for wasi-threads mode and pthread mode.
@cpetig
Copy link
Contributor Author

cpetig commented May 8, 2023

Fixed by above MR. I found that the C API is unsuitable for multi-threaded host implementations, and much less ergonomic than the native API.

@cpetig cpetig closed this as completed May 8, 2023
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this issue May 27, 2024
…ance#2173)

Fix issue reported in bytecodealliance#2172: wasm-c-api `wasm_func_call` may use a wrong exec_env
when multi-threading is enabled, with error "invalid exec env" reported

Fix issue reported in bytecodealliance#2149: main instance's `c_api_func_imports` are not passed to
the counterpart of new thread's instance in wasi-threads mode

Fix issue of invalid size calculated to copy `c_api_func_imports` in pthread mode

And refactor the code to use `wasm_cluster_dup_c_api_imports` to copy the
`c_api_func_imports` to new thread for wasi-threads mode and pthread mode.
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

1 participant