Fix three multi-threading and wasm-c-api-imports issues (#2173)

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.
This commit is contained in:
Christof Petig
2023-05-05 04:01:58 +02:00
committed by GitHub
parent 71d43f3ca1
commit 5a23ae465c
5 changed files with 73 additions and 40 deletions

View File

@ -23,6 +23,9 @@
#if WASM_ENABLE_WASM_CACHE != 0
#include <openssl/sha.h>
#endif
#if WASM_ENABLE_THREAD_MGR != 0
#include "thread_manager.h"
#endif
/*
* Thread Model:
@ -3315,7 +3318,17 @@ wasm_func_call(const wasm_func_t *func, const wasm_val_vec_t *params,
goto failed;
}
exec_env = wasm_runtime_get_exec_env_singleton(func->inst_comm_rt);
#ifdef OS_ENABLE_HW_BOUND_CHECK
exec_env = wasm_runtime_get_exec_env_tls();
#endif
#if WASM_ENABLE_THREAD_MGR != 0
if (!exec_env) {
exec_env = wasm_clusters_search_exec_env(func->inst_comm_rt);
}
#endif
if (!exec_env) {
exec_env = wasm_runtime_get_exec_env_singleton(func->inst_comm_rt);
}
if (!exec_env) {
goto failed;
}