@@ -143,9 +143,9 @@ runtime_signal_handler(void *sig_addr)
143143 WASMJmpBuf * jmpbuf_node ;
144144 uint8 * mapped_mem_start_addr = NULL ;
145145 uint8 * mapped_mem_end_addr = NULL ;
146+ uint32 page_size = os_getpagesize ();
146147#if WASM_DISABLE_STACK_HW_BOUND_CHECK == 0
147148 uint8 * stack_min_addr ;
148- uint32 page_size ;
149149 uint32 guard_page_count = STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT ;
150150#endif
151151
@@ -163,7 +163,6 @@ runtime_signal_handler(void *sig_addr)
163163
164164#if WASM_DISABLE_STACK_HW_BOUND_CHECK == 0
165165 /* Get stack info of current thread */
166- page_size = os_getpagesize ();
167166 stack_min_addr = os_thread_get_stack_boundary ();
168167#endif
169168
@@ -216,29 +215,41 @@ runtime_exception_handler(EXCEPTION_POINTERS *exce_info)
216215 mapped_mem_start_addr = memory_inst -> memory_data ;
217216 mapped_mem_end_addr =
218217 memory_inst -> memory_data + 8 * (uint64 )BH_GB ;
219- if (mapped_mem_start_addr <= (uint8 * )sig_addr
220- && (uint8 * )sig_addr < mapped_mem_end_addr ) {
221- /* The address which causes segmentation fault is inside
222- the memory instance's guard regions.
223- Set exception and let the wasm func continue to run, when
224- the wasm func returns, the caller will check whether the
225- exception is thrown and return to runtime. */
226- wasm_set_exception (module_inst ,
227- "out of bounds memory access" );
228- if (module_inst -> module_type == Wasm_Module_Bytecode ) {
229- /* Continue to search next exception handler for
230- interpreter mode as it can be caught by
231- `__try { .. } __except { .. }` sentences in
232- wasm_runtime.c */
233- return EXCEPTION_CONTINUE_SEARCH ;
234- }
235- else {
236- /* Skip current instruction and continue to run for
237- AOT mode. TODO: implement unwind support for AOT
238- code in Windows platform */
239- exce_info -> ContextRecord -> Rip ++ ;
240- return EXCEPTION_CONTINUE_EXECUTION ;
241- }
218+ }
219+
220+ if (memory_inst && mapped_mem_start_addr <= (uint8 * )sig_addr
221+ && (uint8 * )sig_addr < mapped_mem_end_addr ) {
222+ /* The address which causes segmentation fault is inside
223+ the memory instance's guard regions.
224+ Set exception and let the wasm func continue to run, when
225+ the wasm func returns, the caller will check whether the
226+ exception is thrown and return to runtime. */
227+ wasm_set_exception (module_inst , "out of bounds memory access" );
228+ if (module_inst -> module_type == Wasm_Module_Bytecode ) {
229+ /* Continue to search next exception handler for
230+ interpreter mode as it can be caught by
231+ `__try { .. } __except { .. }` sentences in
232+ wasm_runtime.c */
233+ return EXCEPTION_CONTINUE_SEARCH ;
234+ }
235+ else {
236+ /* Skip current instruction and continue to run for
237+ AOT mode. TODO: implement unwind support for AOT
238+ code in Windows platform */
239+ exce_info -> ContextRecord -> Rip ++ ;
240+ return EXCEPTION_CONTINUE_EXECUTION ;
241+ }
242+ }
243+ else if (exec_env_tls -> exce_check_guard_page <= (uint8 * )sig_addr
244+ && (uint8 * )sig_addr
245+ < exec_env_tls -> exce_check_guard_page + page_size ) {
246+ bh_assert (wasm_get_exception (module_inst ));
247+ if (module_inst -> module_type == Wasm_Module_Bytecode ) {
248+ return EXCEPTION_CONTINUE_SEARCH ;
249+ }
250+ else {
251+ exce_info -> ContextRecord -> Rip ++ ;
252+ return EXCEPTION_CONTINUE_EXECUTION ;
242253 }
243254 }
244255 }
0 commit comments