Skip to content

Commit 2e0cef3

Browse files
fix exec_env not checked issue, export __heap_base and __data_end in sample to decrease memory usage (#371)
1 parent c8df3f6 commit 2e0cef3

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

core/iwasm/common/wasm_exec_env.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,17 @@ WASMExecEnv *
8484
wasm_exec_env_create(struct WASMModuleInstanceCommon *module_inst,
8585
uint32 stack_size)
8686
{
87-
WASMExecEnv *exec_env = wasm_exec_env_create_internal(module_inst,
88-
stack_size);
87+
WASMExecEnv *exec_env =
88+
wasm_exec_env_create_internal(module_inst, stack_size);
89+
90+
if (!exec_env)
91+
return NULL;
92+
8993
/* Set the aux_stack_boundary to 0 */
9094
exec_env->aux_stack_boundary = 0;
9195
#if WASM_ENABLE_THREAD_MGR != 0
9296
WASMCluster *cluster;
9397

94-
if (!exec_env)
95-
return NULL;
96-
9798
/* Create a new cluster for this exec_env */
9899
cluster = wasm_cluster_create(exec_env);
99100
if (!cluster) {

core/iwasm/common/wasm_native.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,14 @@ wasm_native_init()
335335
#if WASM_ENABLE_LIBC_BUILTIN != 0
336336
n_native_symbols = get_libc_builtin_export_apis(&native_symbols);
337337
if (!wasm_native_register_natives("env",
338-
native_symbols, n_native_symbols))
338+
native_symbols, n_native_symbols))
339339
return false;
340340
#endif /* WASM_ENABLE_LIBC_BUILTIN */
341341

342342
#if WASM_ENABLE_SPEC_TEST
343343
n_native_symbols = get_spectest_export_apis(&native_symbols);
344344
if (!wasm_native_register_natives("spectest",
345-
native_symbols, n_native_symbols))
345+
native_symbols, n_native_symbols))
346346
return false;
347347
#endif /* WASM_ENABLE_SPEC_TEST */
348348

core/iwasm/common/wasm_runtime_common.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,14 +1365,6 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
13651365
goto fail;
13661366
}
13671367

1368-
wasi_ctx->curfds_offset = offset_curfds;
1369-
wasi_ctx->prestats_offset = offset_prestats;
1370-
wasi_ctx->argv_environ_offset = offset_argv_environ;
1371-
wasi_ctx->argv_buf_offset = offset_argv_buf;
1372-
wasi_ctx->argv_offsets_offset = offset_argv_offsets;
1373-
wasi_ctx->env_buf_offset = offset_env_buf;
1374-
wasi_ctx->env_offsets_offset = offset_env_offsets;
1375-
13761368
if (!fd_table_init(curfds)) {
13771369
set_error_buf(error_buf, error_buf_size,
13781370
"Init wasi environment failed: "
@@ -1434,6 +1426,14 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
14341426
fd_prestats_insert(prestats, dir_list[i], wasm_fd);
14351427
}
14361428

1429+
wasi_ctx->curfds_offset = offset_curfds;
1430+
wasi_ctx->prestats_offset = offset_prestats;
1431+
wasi_ctx->argv_environ_offset = offset_argv_environ;
1432+
wasi_ctx->argv_buf_offset = offset_argv_buf;
1433+
wasi_ctx->argv_offsets_offset = offset_argv_offsets;
1434+
wasi_ctx->env_buf_offset = offset_env_buf;
1435+
wasi_ctx->env_offsets_offset = offset_env_offsets;
1436+
14371437
return true;
14381438

14391439
fail:

samples/simple/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ OUT_FILE=${i%.*}.wasm
153153
-Wl,--export=on_request -Wl,--export=on_response \
154154
-Wl,--export=on_sensor_event -Wl,--export=on_timer_callback \
155155
-Wl,--export=on_connection_data \
156+
-Wl,--export=__heap_base -Wl,--export=__data_end \
156157
-o ${OUT_DIR}/wasm-apps/${OUT_FILE} ${APP_SRC}
157158
if [ -f ${OUT_DIR}/wasm-apps/${OUT_FILE} ]; then
158159
echo "build ${OUT_FILE} success"

0 commit comments

Comments
 (0)