|
|
@@ -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
|
|
|
|
|
|
@@ -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
|
|
|
|
|
|
@@ -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;
|
|
|
}
|
|
|
}
|
|
|
}
|