Fix pointer unchecked issue in thread-mgr.c (#960)

And refine the code format of thread_manager.h
This commit is contained in:
Xu Jun 2022-01-14 17:57:59 +08:00 committed by GitHub
parent 9eb3ed6b15
commit ee97e30a1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 64 deletions

View File

@ -344,13 +344,13 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
{ {
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env); WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
wasm_module_inst_t module_inst = get_module_inst(exec_env); wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasm_module_t module = wasm_exec_env_get_module(exec_env); wasm_module_t module;
wasm_module_inst_t new_module_inst; wasm_module_inst_t new_module_inst;
WASMExecEnv *new_exec_env; WASMExecEnv *new_exec_env;
uint32 aux_stack_start, aux_stack_size; uint32 aux_stack_start, aux_stack_size;
uint32 stack_size = 8192; uint32 stack_size = 8192;
if (!module) { if (!module_inst || !(module = wasm_exec_env_get_module(exec_env))) {
return NULL; return NULL;
} }
@ -373,11 +373,9 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
return NULL; return NULL;
} }
if (module_inst) { /* Set custom_data to new module instance */
/* Set custom_data to new module instance */ wasm_runtime_set_custom_data_internal(
wasm_runtime_set_custom_data_internal( new_module_inst, wasm_runtime_get_custom_data(module_inst));
new_module_inst, wasm_runtime_get_custom_data(module_inst));
}
new_exec_env = wasm_exec_env_create_internal(new_module_inst, new_exec_env = wasm_exec_env_create_internal(new_module_inst,
exec_env->wasm_stack_size); exec_env->wasm_stack_size);

View File

@ -15,65 +15,9 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#if WASM_ENABLE_DEBUG_INTERP != 0 #if WASM_ENABLE_DEBUG_INTERP != 0
#define WAMR_SIG_TRAP (5)
#define WAMR_SIG_STOP (19)
#define WAMR_SIG_TERM (15)
#define WAMR_SIG_SINGSTEP (0x1ff)
#define STATUS_RUNNING (0)
#define STATUS_STOP (1)
#define STATUS_EXIT (2)
#define STATUS_STEP (3)
#define IS_WAMR_TERM_SIG(signo) ((signo) == WAMR_SIG_TERM)
#define IS_WAMR_STOP_SIG(signo) \
((signo) == WAMR_SIG_STOP || (signo) == WAMR_SIG_TRAP)
typedef struct WASMCurrentEnvStatus {
uint64 signal_flag : 32;
uint64 step_count : 16;
uint64 running_status : 16;
korp_mutex wait_lock;
korp_cond wait_cond;
} WASMCurrentEnvStatus;
typedef struct WASMDebugInstance WASMDebugInstance; typedef struct WASMDebugInstance WASMDebugInstance;
WASMCurrentEnvStatus *
wasm_cluster_create_exenv_status();
void
wasm_cluster_destroy_exenv_status(WASMCurrentEnvStatus *status);
void
wasm_cluster_send_signal_all(WASMCluster *cluster, uint32 signo);
void
wasm_cluster_thread_stopped(WASMExecEnv *exec_env);
void
wasm_cluster_thread_waiting_run(WASMExecEnv *exec_env);
void
wasm_cluster_wait_thread_status(WASMExecEnv *exec_env, uint32 *status);
void
wasm_cluster_thread_exited(WASMExecEnv *exec_env);
void
wasm_cluster_thread_continue(WASMExecEnv *exec_env);
void
wasm_cluster_thread_send_signal(WASMExecEnv *exec_env, uint32 signo);
void
wasm_cluster_thread_step(WASMExecEnv *exec_env);
void
wasm_cluster_set_debug_inst(WASMCluster *cluster, WASMDebugInstance *inst);
#endif #endif
typedef struct WASMCluster { typedef struct WASMCluster {
struct WASMCluster *next; struct WASMCluster *next;
@ -183,6 +127,65 @@ void
wasm_cluster_spread_custom_data(WASMModuleInstanceCommon *module_inst, wasm_cluster_spread_custom_data(WASMModuleInstanceCommon *module_inst,
void *custom_data); void *custom_data);
#if WASM_ENABLE_DEBUG_INTERP != 0
#define WAMR_SIG_TRAP (5)
#define WAMR_SIG_STOP (19)
#define WAMR_SIG_TERM (15)
#define WAMR_SIG_SINGSTEP (0x1ff)
#define STATUS_RUNNING (0)
#define STATUS_STOP (1)
#define STATUS_EXIT (2)
#define STATUS_STEP (3)
#define IS_WAMR_TERM_SIG(signo) ((signo) == WAMR_SIG_TERM)
#define IS_WAMR_STOP_SIG(signo) \
((signo) == WAMR_SIG_STOP || (signo) == WAMR_SIG_TRAP)
typedef struct WASMCurrentEnvStatus {
uint64 signal_flag : 32;
uint64 step_count : 16;
uint64 running_status : 16;
korp_mutex wait_lock;
korp_cond wait_cond;
} WASMCurrentEnvStatus;
WASMCurrentEnvStatus *
wasm_cluster_create_exenv_status();
void
wasm_cluster_destroy_exenv_status(WASMCurrentEnvStatus *status);
void
wasm_cluster_send_signal_all(WASMCluster *cluster, uint32 signo);
void
wasm_cluster_thread_stopped(WASMExecEnv *exec_env);
void
wasm_cluster_thread_waiting_run(WASMExecEnv *exec_env);
void
wasm_cluster_wait_thread_status(WASMExecEnv *exec_env, uint32 *status);
void
wasm_cluster_thread_exited(WASMExecEnv *exec_env);
void
wasm_cluster_thread_continue(WASMExecEnv *exec_env);
void
wasm_cluster_thread_send_signal(WASMExecEnv *exec_env, uint32 signo);
void
wasm_cluster_thread_step(WASMExecEnv *exec_env);
void
wasm_cluster_set_debug_inst(WASMCluster *cluster, WASMDebugInstance *inst);
#endif /* end of WASM_ENABLE_DEBUG_INTERP != 0 */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif