Skip to content

Commit ee97e30

Browse files
Fix pointer unchecked issue in thread-mgr.c (#960)
And refine the code format of thread_manager.h
1 parent 9eb3ed6 commit ee97e30

File tree

2 files changed

+65
-64
lines changed

2 files changed

+65
-64
lines changed

core/iwasm/libraries/thread-mgr/thread_manager.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,13 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
344344
{
345345
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
346346
wasm_module_inst_t module_inst = get_module_inst(exec_env);
347-
wasm_module_t module = wasm_exec_env_get_module(exec_env);
347+
wasm_module_t module;
348348
wasm_module_inst_t new_module_inst;
349349
WASMExecEnv *new_exec_env;
350350
uint32 aux_stack_start, aux_stack_size;
351351
uint32 stack_size = 8192;
352352

353-
if (!module) {
353+
if (!module_inst || !(module = wasm_exec_env_get_module(exec_env))) {
354354
return NULL;
355355
}
356356

@@ -373,11 +373,9 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
373373
return NULL;
374374
}
375375

376-
if (module_inst) {
377-
/* Set custom_data to new module instance */
378-
wasm_runtime_set_custom_data_internal(
379-
new_module_inst, wasm_runtime_get_custom_data(module_inst));
380-
}
376+
/* Set custom_data to new module instance */
377+
wasm_runtime_set_custom_data_internal(
378+
new_module_inst, wasm_runtime_get_custom_data(module_inst));
381379

382380
new_exec_env = wasm_exec_env_create_internal(new_module_inst,
383381
exec_env->wasm_stack_size);

core/iwasm/libraries/thread-mgr/thread_manager.h

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,65 +15,9 @@
1515
#ifdef __cplusplus
1616
extern "C" {
1717
#endif
18-
#if WASM_ENABLE_DEBUG_INTERP != 0
19-
#define WAMR_SIG_TRAP (5)
20-
#define WAMR_SIG_STOP (19)
21-
#define WAMR_SIG_TERM (15)
22-
#define WAMR_SIG_SINGSTEP (0x1ff)
23-
24-
#define STATUS_RUNNING (0)
25-
#define STATUS_STOP (1)
26-
#define STATUS_EXIT (2)
27-
#define STATUS_STEP (3)
28-
29-
#define IS_WAMR_TERM_SIG(signo) ((signo) == WAMR_SIG_TERM)
30-
31-
#define IS_WAMR_STOP_SIG(signo) \
32-
((signo) == WAMR_SIG_STOP || (signo) == WAMR_SIG_TRAP)
33-
34-
typedef struct WASMCurrentEnvStatus {
35-
uint64 signal_flag : 32;
36-
uint64 step_count : 16;
37-
uint64 running_status : 16;
38-
korp_mutex wait_lock;
39-
korp_cond wait_cond;
40-
} WASMCurrentEnvStatus;
4118

19+
#if WASM_ENABLE_DEBUG_INTERP != 0
4220
typedef struct WASMDebugInstance WASMDebugInstance;
43-
44-
WASMCurrentEnvStatus *
45-
wasm_cluster_create_exenv_status();
46-
47-
void
48-
wasm_cluster_destroy_exenv_status(WASMCurrentEnvStatus *status);
49-
50-
void
51-
wasm_cluster_send_signal_all(WASMCluster *cluster, uint32 signo);
52-
53-
void
54-
wasm_cluster_thread_stopped(WASMExecEnv *exec_env);
55-
56-
void
57-
wasm_cluster_thread_waiting_run(WASMExecEnv *exec_env);
58-
59-
void
60-
wasm_cluster_wait_thread_status(WASMExecEnv *exec_env, uint32 *status);
61-
62-
void
63-
wasm_cluster_thread_exited(WASMExecEnv *exec_env);
64-
65-
void
66-
wasm_cluster_thread_continue(WASMExecEnv *exec_env);
67-
68-
void
69-
wasm_cluster_thread_send_signal(WASMExecEnv *exec_env, uint32 signo);
70-
71-
void
72-
wasm_cluster_thread_step(WASMExecEnv *exec_env);
73-
74-
void
75-
wasm_cluster_set_debug_inst(WASMCluster *cluster, WASMDebugInstance *inst);
76-
7721
#endif
7822
typedef struct WASMCluster {
7923
struct WASMCluster *next;
@@ -183,6 +127,65 @@ void
183127
wasm_cluster_spread_custom_data(WASMModuleInstanceCommon *module_inst,
184128
void *custom_data);
185129

130+
#if WASM_ENABLE_DEBUG_INTERP != 0
131+
#define WAMR_SIG_TRAP (5)
132+
#define WAMR_SIG_STOP (19)
133+
#define WAMR_SIG_TERM (15)
134+
#define WAMR_SIG_SINGSTEP (0x1ff)
135+
136+
#define STATUS_RUNNING (0)
137+
#define STATUS_STOP (1)
138+
#define STATUS_EXIT (2)
139+
#define STATUS_STEP (3)
140+
141+
#define IS_WAMR_TERM_SIG(signo) ((signo) == WAMR_SIG_TERM)
142+
143+
#define IS_WAMR_STOP_SIG(signo) \
144+
((signo) == WAMR_SIG_STOP || (signo) == WAMR_SIG_TRAP)
145+
146+
typedef struct WASMCurrentEnvStatus {
147+
uint64 signal_flag : 32;
148+
uint64 step_count : 16;
149+
uint64 running_status : 16;
150+
korp_mutex wait_lock;
151+
korp_cond wait_cond;
152+
} WASMCurrentEnvStatus;
153+
154+
WASMCurrentEnvStatus *
155+
wasm_cluster_create_exenv_status();
156+
157+
void
158+
wasm_cluster_destroy_exenv_status(WASMCurrentEnvStatus *status);
159+
160+
void
161+
wasm_cluster_send_signal_all(WASMCluster *cluster, uint32 signo);
162+
163+
void
164+
wasm_cluster_thread_stopped(WASMExecEnv *exec_env);
165+
166+
void
167+
wasm_cluster_thread_waiting_run(WASMExecEnv *exec_env);
168+
169+
void
170+
wasm_cluster_wait_thread_status(WASMExecEnv *exec_env, uint32 *status);
171+
172+
void
173+
wasm_cluster_thread_exited(WASMExecEnv *exec_env);
174+
175+
void
176+
wasm_cluster_thread_continue(WASMExecEnv *exec_env);
177+
178+
void
179+
wasm_cluster_thread_send_signal(WASMExecEnv *exec_env, uint32 signo);
180+
181+
void
182+
wasm_cluster_thread_step(WASMExecEnv *exec_env);
183+
184+
void
185+
wasm_cluster_set_debug_inst(WASMCluster *cluster, WASMDebugInstance *inst);
186+
187+
#endif /* end of WASM_ENABLE_DEBUG_INTERP != 0 */
188+
186189
#ifdef __cplusplus
187190
}
188191
#endif

0 commit comments

Comments
 (0)