Fix potential recursive lock in pthread_create_wrapper (#2980)

Potential recursive lock occurs in:
```
pthread_create_wrapper   (acquire exec_env->wait_lock)
  => wasm_cluster_create_thread
    => allocate_aux_stack
      => wasm_runtime_module_malloc_internal
        => wasm_call_function
          => wasm_exec_env_set_thread_info (acquire exec_env->wait_lock again)
```
Allocate aux stack before calling wasm_cluster_create_thread to resolve it.

Reported in https://github.com/bytecodealliance/wasm-micro-runtime/pull/2977.
This commit is contained in:
Wenyong Huang
2024-01-08 09:43:31 +08:00
committed by GitHub
parent 4a1ad9a160
commit c39214e8a5
4 changed files with 64 additions and 22 deletions

View File

@ -81,7 +81,9 @@ wasm_cluster_dup_c_api_imports(WASMModuleInstanceCommon *module_inst_dst,
int32
wasm_cluster_create_thread(WASMExecEnv *exec_env,
wasm_module_inst_t module_inst, bool alloc_aux_stack,
wasm_module_inst_t module_inst,
bool is_aux_stack_allocated, uint32 aux_stack_start,
uint32 aux_stack_size,
void *(*thread_routine)(void *), void *arg);
int32
@ -221,6 +223,13 @@ wasm_cluster_traverse_lock(WASMExecEnv *exec_env);
void
wasm_cluster_traverse_unlock(WASMExecEnv *exec_env);
bool
wasm_cluster_allocate_aux_stack(WASMExecEnv *exec_env, uint32 *p_start,
uint32 *p_size);
bool
wasm_cluster_free_aux_stack(WASMExecEnv *exec_env, uint32 start);
#ifdef __cplusplus
}
#endif