mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-08 20:56:13 +00:00
fix exec_env not checked issue, export __heap_base and __data_end in sample to decrease memory usage (#371)
This commit is contained in:
parent
c8df3f6eed
commit
2e0cef3ef1
|
@ -84,16 +84,17 @@ WASMExecEnv *
|
||||||
wasm_exec_env_create(struct WASMModuleInstanceCommon *module_inst,
|
wasm_exec_env_create(struct WASMModuleInstanceCommon *module_inst,
|
||||||
uint32 stack_size)
|
uint32 stack_size)
|
||||||
{
|
{
|
||||||
WASMExecEnv *exec_env = wasm_exec_env_create_internal(module_inst,
|
WASMExecEnv *exec_env =
|
||||||
stack_size);
|
wasm_exec_env_create_internal(module_inst, stack_size);
|
||||||
|
|
||||||
|
if (!exec_env)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
/* Set the aux_stack_boundary to 0 */
|
/* Set the aux_stack_boundary to 0 */
|
||||||
exec_env->aux_stack_boundary = 0;
|
exec_env->aux_stack_boundary = 0;
|
||||||
#if WASM_ENABLE_THREAD_MGR != 0
|
#if WASM_ENABLE_THREAD_MGR != 0
|
||||||
WASMCluster *cluster;
|
WASMCluster *cluster;
|
||||||
|
|
||||||
if (!exec_env)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
/* Create a new cluster for this exec_env */
|
/* Create a new cluster for this exec_env */
|
||||||
cluster = wasm_cluster_create(exec_env);
|
cluster = wasm_cluster_create(exec_env);
|
||||||
if (!cluster) {
|
if (!cluster) {
|
||||||
|
|
|
@ -335,14 +335,14 @@ wasm_native_init()
|
||||||
#if WASM_ENABLE_LIBC_BUILTIN != 0
|
#if WASM_ENABLE_LIBC_BUILTIN != 0
|
||||||
n_native_symbols = get_libc_builtin_export_apis(&native_symbols);
|
n_native_symbols = get_libc_builtin_export_apis(&native_symbols);
|
||||||
if (!wasm_native_register_natives("env",
|
if (!wasm_native_register_natives("env",
|
||||||
native_symbols, n_native_symbols))
|
native_symbols, n_native_symbols))
|
||||||
return false;
|
return false;
|
||||||
#endif /* WASM_ENABLE_LIBC_BUILTIN */
|
#endif /* WASM_ENABLE_LIBC_BUILTIN */
|
||||||
|
|
||||||
#if WASM_ENABLE_SPEC_TEST
|
#if WASM_ENABLE_SPEC_TEST
|
||||||
n_native_symbols = get_spectest_export_apis(&native_symbols);
|
n_native_symbols = get_spectest_export_apis(&native_symbols);
|
||||||
if (!wasm_native_register_natives("spectest",
|
if (!wasm_native_register_natives("spectest",
|
||||||
native_symbols, n_native_symbols))
|
native_symbols, n_native_symbols))
|
||||||
return false;
|
return false;
|
||||||
#endif /* WASM_ENABLE_SPEC_TEST */
|
#endif /* WASM_ENABLE_SPEC_TEST */
|
||||||
|
|
||||||
|
|
|
@ -1365,14 +1365,6 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
wasi_ctx->curfds_offset = offset_curfds;
|
|
||||||
wasi_ctx->prestats_offset = offset_prestats;
|
|
||||||
wasi_ctx->argv_environ_offset = offset_argv_environ;
|
|
||||||
wasi_ctx->argv_buf_offset = offset_argv_buf;
|
|
||||||
wasi_ctx->argv_offsets_offset = offset_argv_offsets;
|
|
||||||
wasi_ctx->env_buf_offset = offset_env_buf;
|
|
||||||
wasi_ctx->env_offsets_offset = offset_env_offsets;
|
|
||||||
|
|
||||||
if (!fd_table_init(curfds)) {
|
if (!fd_table_init(curfds)) {
|
||||||
set_error_buf(error_buf, error_buf_size,
|
set_error_buf(error_buf, error_buf_size,
|
||||||
"Init wasi environment failed: "
|
"Init wasi environment failed: "
|
||||||
|
@ -1434,6 +1426,14 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||||
fd_prestats_insert(prestats, dir_list[i], wasm_fd);
|
fd_prestats_insert(prestats, dir_list[i], wasm_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wasi_ctx->curfds_offset = offset_curfds;
|
||||||
|
wasi_ctx->prestats_offset = offset_prestats;
|
||||||
|
wasi_ctx->argv_environ_offset = offset_argv_environ;
|
||||||
|
wasi_ctx->argv_buf_offset = offset_argv_buf;
|
||||||
|
wasi_ctx->argv_offsets_offset = offset_argv_offsets;
|
||||||
|
wasi_ctx->env_buf_offset = offset_env_buf;
|
||||||
|
wasi_ctx->env_offsets_offset = offset_env_offsets;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
|
|
@ -153,6 +153,7 @@ OUT_FILE=${i%.*}.wasm
|
||||||
-Wl,--export=on_request -Wl,--export=on_response \
|
-Wl,--export=on_request -Wl,--export=on_response \
|
||||||
-Wl,--export=on_sensor_event -Wl,--export=on_timer_callback \
|
-Wl,--export=on_sensor_event -Wl,--export=on_timer_callback \
|
||||||
-Wl,--export=on_connection_data \
|
-Wl,--export=on_connection_data \
|
||||||
|
-Wl,--export=__heap_base -Wl,--export=__data_end \
|
||||||
-o ${OUT_DIR}/wasm-apps/${OUT_FILE} ${APP_SRC}
|
-o ${OUT_DIR}/wasm-apps/${OUT_FILE} ${APP_SRC}
|
||||||
if [ -f ${OUT_DIR}/wasm-apps/${OUT_FILE} ]; then
|
if [ -f ${OUT_DIR}/wasm-apps/${OUT_FILE} ]; then
|
||||||
echo "build ${OUT_FILE} success"
|
echo "build ${OUT_FILE} success"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user