Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/iwasm/aot/arch/aot_reloc_arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ void __aeabi_idivmod();
void __aeabi_l2d();
void __aeabi_l2f();
void __aeabi_ldivmod();
void __aeabi_memcpy();
void __aeabi_memmove();
void __aeabi_memset();
void __aeabi_uidiv();
void __aeabi_uidivmod();
void __aeabi_ul2d();
Expand Down Expand Up @@ -120,6 +123,9 @@ static SymbolMap target_sym_map[] = {
REG_SYM(__aeabi_l2d),
REG_SYM(__aeabi_l2f),
REG_SYM(__aeabi_ldivmod),
REG_SYM(__aeabi_memcpy),
REG_SYM(__aeabi_memmove),
REG_SYM(__aeabi_memset),
REG_SYM(__aeabi_uidiv),
REG_SYM(__aeabi_uidivmod),
REG_SYM(__aeabi_ul2d),
Expand Down
1 change: 1 addition & 0 deletions core/iwasm/common/wasm_c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2112,6 +2112,7 @@ wasm_module_imports(const wasm_module_t *module, own wasm_importtype_vec_t *out)
memset(&module_name, 0, sizeof(wasm_val_vec_t));
memset(&name, 0, sizeof(wasm_val_vec_t));
extern_type = NULL;
import_type = NULL;

if (i < import_func_count) {
wasm_functype_t *type = NULL;
Expand Down
18 changes: 10 additions & 8 deletions core/iwasm/common/wasm_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,11 @@ wasm_native_unregister_natives(const char *module_name,
bool
wasm_native_init()
{
#if WASM_ENABLE_SPEC_TEST != 0 || WASM_ENABLE_LIBC_BUILTIN != 0 \
|| WASM_ENABLE_BASE_LIB != 0 || WASM_ENABLE_LIBC_EMCC != 0 \
|| WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \
|| WASM_ENABLE_APP_FRAMEWORK != 0
#if WASM_ENABLE_SPEC_TEST != 0 || WASM_ENABLE_LIBC_BUILTIN != 0 \
|| WASM_ENABLE_BASE_LIB != 0 || WASM_ENABLE_LIBC_EMCC != 0 \
|| WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \
|| WASM_ENABLE_APP_FRAMEWORK != 0 || WASM_ENABLE_LIBC_WASI != 0 \
|| WASM_ENABLE_LIB_PTHREAD != 0
NativeSymbol *native_symbols;
uint32 n_native_symbols;
#endif
Expand Down Expand Up @@ -461,10 +462,11 @@ wasm_native_init()
#endif

return true;
#if WASM_ENABLE_SPEC_TEST != 0 || WASM_ENABLE_LIBC_BUILTIN != 0 \
|| WASM_ENABLE_BASE_LIB != 0 || WASM_ENABLE_LIBC_EMCC != 0 \
|| WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \
|| WASM_ENABLE_APP_FRAMEWORK != 0
#if WASM_ENABLE_SPEC_TEST != 0 || WASM_ENABLE_LIBC_BUILTIN != 0 \
|| WASM_ENABLE_BASE_LIB != 0 || WASM_ENABLE_LIBC_EMCC != 0 \
|| WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \
|| WASM_ENABLE_APP_FRAMEWORK != 0 || WASM_ENABLE_LIBC_WASI != 0 \
|| WASM_ENABLE_LIB_PTHREAD != 0
fail:
wasm_native_destroy();
return false;
Expand Down
61 changes: 36 additions & 25 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ runtime_signal_handler(void *sig_addr)
WASMJmpBuf *jmpbuf_node;
uint8 *mapped_mem_start_addr = NULL;
uint8 *mapped_mem_end_addr = NULL;
uint32 page_size = os_getpagesize();
#if WASM_DISABLE_STACK_HW_BOUND_CHECK == 0
uint8 *stack_min_addr;
uint32 page_size;
uint32 guard_page_count = STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT;
#endif

Expand All @@ -163,7 +163,6 @@ runtime_signal_handler(void *sig_addr)

#if WASM_DISABLE_STACK_HW_BOUND_CHECK == 0
/* Get stack info of current thread */
page_size = os_getpagesize();
stack_min_addr = os_thread_get_stack_boundary();
#endif

Expand Down Expand Up @@ -216,29 +215,41 @@ runtime_exception_handler(EXCEPTION_POINTERS *exce_info)
mapped_mem_start_addr = memory_inst->memory_data;
mapped_mem_end_addr =
memory_inst->memory_data + 8 * (uint64)BH_GB;
if (mapped_mem_start_addr <= (uint8 *)sig_addr
&& (uint8 *)sig_addr < mapped_mem_end_addr) {
/* The address which causes segmentation fault is inside
the memory instance's guard regions.
Set exception and let the wasm func continue to run, when
the wasm func returns, the caller will check whether the
exception is thrown and return to runtime. */
wasm_set_exception(module_inst,
"out of bounds memory access");
if (module_inst->module_type == Wasm_Module_Bytecode) {
/* Continue to search next exception handler for
interpreter mode as it can be caught by
`__try { .. } __except { .. }` sentences in
wasm_runtime.c */
return EXCEPTION_CONTINUE_SEARCH;
}
else {
/* Skip current instruction and continue to run for
AOT mode. TODO: implement unwind support for AOT
code in Windows platform */
exce_info->ContextRecord->Rip++;
return EXCEPTION_CONTINUE_EXECUTION;
}
}

if (memory_inst && mapped_mem_start_addr <= (uint8 *)sig_addr
&& (uint8 *)sig_addr < mapped_mem_end_addr) {
/* The address which causes segmentation fault is inside
the memory instance's guard regions.
Set exception and let the wasm func continue to run, when
the wasm func returns, the caller will check whether the
exception is thrown and return to runtime. */
wasm_set_exception(module_inst, "out of bounds memory access");
if (module_inst->module_type == Wasm_Module_Bytecode) {
/* Continue to search next exception handler for
interpreter mode as it can be caught by
`__try { .. } __except { .. }` sentences in
wasm_runtime.c */
return EXCEPTION_CONTINUE_SEARCH;
}
else {
/* Skip current instruction and continue to run for
AOT mode. TODO: implement unwind support for AOT
code in Windows platform */
exce_info->ContextRecord->Rip++;
return EXCEPTION_CONTINUE_EXECUTION;
}
}
else if (exec_env_tls->exce_check_guard_page <= (uint8 *)sig_addr
&& (uint8 *)sig_addr
< exec_env_tls->exce_check_guard_page + page_size) {
bh_assert(wasm_get_exception(module_inst));
if (module_inst->module_type == Wasm_Module_Bytecode) {
return EXCEPTION_CONTINUE_SEARCH;
}
else {
exce_info->ContextRecord->Rip++;
return EXCEPTION_CONTINUE_EXECUTION;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions core/iwasm/compilation/aot_emit_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ aot_compile_op_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
false, NULL, NULL))) {
goto fail;
}
aot_block_destroy(block);
return aot_handle_next_reachable_block(comp_ctx, func_ctx,
p_frame_ip);
}
Expand Down
3 changes: 2 additions & 1 deletion core/iwasm/interpreter/wasm_mini_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -5125,10 +5125,11 @@ copy_params_to_dynamic_space(WASMLoaderContext *loader_ctx, bool is_if_block,

/* Free the emit data */
wasm_runtime_free(emit_data);

return true;

fail:
/* Free the emit data */
wasm_runtime_free(emit_data);
return false;
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3081,14 +3081,15 @@ wasi_ssp_sock_addr_resolve(
size_t _max_info_size;
size_t actual_info_size;

if (!ns_lookup_list_search(ns_lookup_list, host)) {
return __WASI_EACCES;
}

if (!wamr_addr_info) {
return __WASI_ENOMEM;
}

if (!ns_lookup_list_search(ns_lookup_list, host)) {
wasm_runtime_free(wamr_addr_info);
return __WASI_EACCES;
}

int ret = os_socket_addr_resolve(
host, service, hints->hints_enabled ? &hints_is_tcp : NULL,
hints->hints_enabled ? &hints_is_ipv4 : NULL, wamr_addr_info,
Expand Down
6 changes: 1 addition & 5 deletions samples/file/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ main(int argc, char *argv_main[])
wasm_module_inst_t module_inst = NULL;
wasm_exec_env_t exec_env = NULL;
uint32 buf_size, stack_size = 8092, heap_size = 8092;
uint32_t wasm_buffer = 0;

RuntimeInitArgs init_args;
memset(&init_args, 0, sizeof(RuntimeInitArgs));
Expand Down Expand Up @@ -103,11 +102,8 @@ main(int argc, char *argv_main[])
fail:
if (exec_env)
wasm_runtime_destroy_exec_env(exec_env);
if (module_inst) {
if (wasm_buffer)
wasm_runtime_module_free(module_inst, wasm_buffer);
if (module_inst)
wasm_runtime_deinstantiate(module_inst);
}
if (module)
wasm_runtime_unload(module);
if (buffer)
Expand Down
13 changes: 9 additions & 4 deletions samples/wasm-c-api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,16 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")

if(VALGRIND)
foreach(EX ${EXAMPLES})
add_custom_target(${EX}_LEAK_TEST
COMMAND ${VALGRIND} --tool=memcheck --leak-check=yes ./${EX}
add_custom_command(
OUTPUT ${EX}_leak_check.report
DEPENDS ${EX} ${EX}_WASM
VERBATIM
COMMENT "run a leak check on ${EX}"
COMMAND ${VALGRIND} --tool=memcheck --leak-check=summary -- ./${EX} > ${EX}_leak_check.report 2>&1
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_custom_target(${EX}_LEAK_TEST ALL
DEPENDS ${EX}_leak_check.report
COMMAND grep "All heap blocks were freed -- no leaks are possible" ${EX}_leak_check.report
COMMENT "Please read ${EX}_leak_check.report when meeting Error"
)
endforeach()
endif (VALGRIND)
Expand Down
8 changes: 5 additions & 3 deletions samples/wasm-c-api/src/callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,11 @@ int main(int argc, const char* argv[]) {
wasm_val_t rs[1] = { WASM_INIT_VAL };
wasm_val_vec_t args = WASM_ARRAY_VEC(as);
wasm_val_vec_t results = WASM_ARRAY_VEC(rs);
if (wasm_func_call(run_func, &args, &results)) {
printf("> Error calling function!\n");
return 1;
wasm_trap_t *trap = wasm_func_call(run_func, &args, &results);
if (trap) {
printf("> Error calling function!\n");
wasm_trap_delete(trap);
return 1;
}

wasm_extern_vec_delete(&exports);
Expand Down
8 changes: 6 additions & 2 deletions samples/wasm-c-api/src/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,13 @@ vm_function_set_byte(const wasm_vm_t *vm, uint32_t offset, uint8_t byte)
wasm_val_vec_t args = WASM_ARRAY_VEC(a_v);
wasm_val_vec_t results = WASM_EMPTY_VEC;
wasm_trap_t *trap = wasm_func_call(vm->function_list[0], &args, &results);
if (trap)
if (trap) {
printf("call wasm_set_byte failed");
wasm_trap_delete(trap);
return false;
}

return trap != NULL;
return true;
}

bool
Expand All @@ -247,6 +250,7 @@ vm_function_get_byte(const wasm_vm_t *vm, uint32_t offset, uint8_t *byte)
wasm_trap_t *trap = wasm_func_call(vm->function_list[1], &args, &results);
if (trap) {
printf("call wasm_get_byte failed");
wasm_trap_delete(trap);
return false;
}

Expand Down
14 changes: 10 additions & 4 deletions samples/wasm-c-api/src/empty_imports.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,16 @@ int main(int argc, const char* argv[]) {
wasm_val_t results[1] = { WASM_INIT_VAL };
wasm_val_vec_t results_vec = WASM_ARRAY_VEC(results);

if (wasm_func_call(add_func, &args_vec, &results_vec)
|| results_vec.data[0].of.i32 != 7) {
printf("> Error calling function!\n");
return 1;
wasm_trap_t *trap = wasm_func_call(add_func, &args_vec, &results_vec);
if (trap) {
printf("> Error calling function!\n");
wasm_trap_delete(trap);
return 1;
}

if (results_vec.data[0].of.i32 != 7) {
printf("> Error calling function!\n");
return 1;
}

wasm_extern_vec_delete(&exports);
Expand Down
40 changes: 27 additions & 13 deletions samples/wasm-c-api/src/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,22 @@ wasm_func_t* get_export_func(const wasm_extern_vec_t* exports, size_t i) {
check(val, type, expected); \
}

#define check_call(func, type, expected) \
{ \
wasm_val_t vs[1]; \
wasm_val_vec_t args = WASM_EMPTY_VEC; \
wasm_val_vec_t results = WASM_ARRAY_VEC(vs); \
wasm_func_call(func, &args, &results); \
check(vs[0], type, expected); \
}

#define check_trap(trap) \
if (trap) { \
printf("> Error calling function\n"); \
wasm_trap_delete(trap); \
exit(1); \
}

#define check_call(func, type, expected) \
{ \
wasm_val_t vs[1]; \
wasm_val_vec_t args = WASM_EMPTY_VEC; \
wasm_val_vec_t results = WASM_ARRAY_VEC(vs); \
wasm_trap_t *trap = wasm_func_call(func, &args, &results); \
check_trap(trap); \
check(vs[0], type, expected); \
}

int main(int argc, const char* argv[]) {
// Initialize.
Expand Down Expand Up @@ -225,16 +232,23 @@ int main(int argc, const char* argv[]) {
wasm_val_vec_t res = WASM_EMPTY_VEC;
wasm_val_t vs73[] = { WASM_F32_VAL(73) };
wasm_val_vec_t args73 = WASM_ARRAY_VEC(vs73);
wasm_func_call(set_var_f32_import, &args73, &res);
wasm_trap_t *trap = wasm_func_call(set_var_f32_import, &args73, &res);
check_trap(trap);

wasm_val_t vs74[] = { WASM_I64_VAL(74) };
wasm_val_vec_t args74 = WASM_ARRAY_VEC(vs74);
wasm_func_call(set_var_i64_import, &args74, &res);
trap = wasm_func_call(set_var_i64_import, &args74, &res);
check_trap(trap);

wasm_val_t vs77[] = { WASM_F32_VAL(77) };
wasm_val_vec_t args77 = WASM_ARRAY_VEC(vs77);
wasm_func_call(set_var_f32_export, &args77, &res);
trap = wasm_func_call(set_var_f32_export, &args77, &res);
check_trap(trap);

wasm_val_t vs78[] = { WASM_I64_VAL(78) };
wasm_val_vec_t args78 = WASM_ARRAY_VEC(vs78);
wasm_func_call(set_var_i64_export, &args78, &res);
trap = wasm_func_call(set_var_i64_export, &args78, &res);
check_trap(trap);

check_global(var_f32_import, f32, 73);
check_global(var_i64_import, i64, 74);
Expand Down
29 changes: 20 additions & 9 deletions samples/wasm-c-api/src/globalexportimport.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,21 @@ wasm_func_t* get_export_func(const wasm_extern_vec_t* exports, size_t i) {
check(val, type, expected); \
}

#define check_call(func, type, expected) \
{ \
wasm_val_vec_t results; \
wasm_val_vec_new_uninitialized(&results, 1); \
wasm_func_call(func, NULL, &results); \
check(results.data[0], type, expected); \
}
#define check_trap(trap) \
if (trap) { \
printf("> Error calling function\n"); \
wasm_trap_delete(trap); \
exit(1); \
}

#define check_call(func, type, expected) \
{ \
wasm_val_vec_t results; \
wasm_val_vec_new_uninitialized(&results, 1); \
wasm_trap_t *trap = wasm_func_call(func, NULL, &results); \
check_trap(trap); \
check(results.data[0], type, expected); \
}

wasm_module_t * create_module_from_file(wasm_store_t* store, const char * filename)
{
Expand Down Expand Up @@ -149,7 +157,9 @@ int main(int argc, const char* argv[]) {
printf("Modify the variable to 77.0...\n");
wasm_val_vec_t args77;
wasm_val_vec_new(&args77, 1, (wasm_val_t []){ {.kind = WASM_F32, .of = {.f32 = 77.0}} });
wasm_func_call(set_var_f32_export, &args77, NULL); //Call to module export
wasm_trap_t *trap = wasm_func_call(set_var_f32_export, &args77,
NULL); // Call to module export
check_trap(trap);
check_call(get_var_f32_export, f32, 77.0); //Call to module export
check_global(var_f32_export, f32, 77.0); //Failed here, still 37
check_call(get_var_f32_import, f32, 77.0); //Call to module import Failed here, still 37
Expand All @@ -158,7 +168,8 @@ int main(int argc, const char* argv[]) {
printf("Modify the variable to 78.0...\n");
wasm_val_vec_t args78;
wasm_val_vec_new(&args78, 1, (wasm_val_t []){ {.kind = WASM_F32, .of = {.f32 = 78.0}} });
wasm_func_call(set_var_f32_import, &args78, NULL);
trap = wasm_func_call(set_var_f32_import, &args78, NULL);
check_trap(trap);
check_global(var_f32_export, f32, 78.0);
check_call(get_var_f32_export, f32, 78.0); //Call to module export Failed here, still 77
check_call(get_var_f32_import, f32, 78.0); //Call to module import
Expand Down
Loading