@@ -1500,7 +1500,11 @@ aot_set_exception(AOTModuleInstance *module_inst, const char *exception)
15001500void
15011501aot_set_exception_with_id (AOTModuleInstance * module_inst , uint32 id )
15021502{
1503- wasm_set_exception_with_id (module_inst , id );
1503+ if (id != EXCE_ALREADY_THROWN )
1504+ wasm_set_exception_with_id (module_inst , id );
1505+ #ifdef OS_ENABLE_HW_BOUND_CHECK
1506+ wasm_runtime_access_exce_check_guard_page ();
1507+ #endif
15041508}
15051509
15061510const char *
@@ -1755,6 +1759,7 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
17551759 const char * signature ;
17561760 void * attachment ;
17571761 char buf [96 ];
1762+ bool ret = false;
17581763
17591764 bh_assert (func_idx < aot_module -> import_func_count );
17601765
@@ -1764,27 +1769,34 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
17641769 "failed to call unlinked import function (%s, %s)" ,
17651770 import_func -> module_name , import_func -> func_name );
17661771 aot_set_exception (module_inst , buf );
1767- return false ;
1772+ goto fail ;
17681773 }
17691774
17701775 attachment = import_func -> attachment ;
17711776 if (import_func -> call_conv_wasm_c_api ) {
1772- return wasm_runtime_invoke_c_api_native (
1777+ ret = wasm_runtime_invoke_c_api_native (
17731778 (WASMModuleInstanceCommon * )module_inst , func_ptr , func_type , argc ,
17741779 argv , import_func -> wasm_c_api_with_env , attachment );
17751780 }
17761781 else if (!import_func -> call_conv_raw ) {
17771782 signature = import_func -> signature ;
1778- return wasm_runtime_invoke_native ( exec_env , func_ptr , func_type ,
1779- signature , attachment , argv , argc ,
1780- argv );
1783+ ret =
1784+ wasm_runtime_invoke_native ( exec_env , func_ptr , func_type , signature ,
1785+ attachment , argv , argc , argv );
17811786 }
17821787 else {
17831788 signature = import_func -> signature ;
1784- return wasm_runtime_invoke_native_raw (exec_env , func_ptr , func_type ,
1785- signature , attachment , argv , argc ,
1786- argv );
1789+ ret = wasm_runtime_invoke_native_raw (exec_env , func_ptr , func_type ,
1790+ signature , attachment , argv , argc ,
1791+ argv );
17871792 }
1793+
1794+ fail :
1795+ #ifdef OS_ENABLE_HW_BOUND_CHECK
1796+ if (!ret )
1797+ wasm_runtime_access_exce_check_guard_page ();
1798+ #endif
1799+ return ret ;
17881800}
17891801
17901802bool
@@ -1811,21 +1823,21 @@ aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
18111823
18121824 if ((uint8 * )& module_inst < exec_env -> native_stack_boundary ) {
18131825 aot_set_exception_with_id (module_inst , EXCE_NATIVE_STACK_OVERFLOW );
1814- return false ;
1826+ goto fail ;
18151827 }
18161828
18171829 tbl_inst = module_inst -> tables [tbl_idx ];
18181830 bh_assert (tbl_inst );
18191831
18201832 if (table_elem_idx >= tbl_inst -> cur_size ) {
18211833 aot_set_exception_with_id (module_inst , EXCE_UNDEFINED_ELEMENT );
1822- return false ;
1834+ goto fail ;
18231835 }
18241836
18251837 func_idx = tbl_inst -> elems [table_elem_idx ];
18261838 if (func_idx == NULL_REF ) {
18271839 aot_set_exception_with_id (module_inst , EXCE_UNINITIALIZED_ELEMENT );
1828- return false ;
1840+ goto fail ;
18291841 }
18301842
18311843 func_type_idx = func_type_indexes [func_idx ];
@@ -1843,7 +1855,7 @@ aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
18431855 "failed to call unlinked import function (%s, %s)" ,
18441856 import_func -> module_name , import_func -> func_name );
18451857 aot_set_exception (module_inst , buf );
1846- return false ;
1858+ goto fail ;
18471859 }
18481860
18491861 if (func_idx < aot_module -> import_func_count ) {
@@ -1852,9 +1864,13 @@ aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
18521864 signature = import_func -> signature ;
18531865 if (import_func -> call_conv_raw ) {
18541866 attachment = import_func -> attachment ;
1855- return wasm_runtime_invoke_native_raw (exec_env , func_ptr , func_type ,
1856- signature , attachment , argv ,
1857- argc , argv );
1867+ ret = wasm_runtime_invoke_native_raw (exec_env , func_ptr , func_type ,
1868+ signature , attachment , argv ,
1869+ argc , argv );
1870+ if (!ret )
1871+ goto fail ;
1872+
1873+ return true;
18581874 }
18591875 }
18601876
@@ -1878,7 +1894,7 @@ aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
18781894 && !(argv1 = runtime_malloc (size , module_inst -> cur_exception ,
18791895 sizeof (module_inst -> cur_exception )))) {
18801896 aot_set_exception_with_id (module_inst , EXCE_OUT_OF_MEMORY );
1881- return false ;
1897+ goto fail ;
18821898 }
18831899
18841900 /* Copy original arguments */
@@ -1897,12 +1913,10 @@ aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
18971913
18981914 ret = invoke_native_internal (exec_env , func_ptr , func_type , signature ,
18991915 attachment , argv1 , argc , argv );
1900- if (!ret || aot_get_exception ( module_inst ) ) {
1916+ if (!ret ) {
19011917 if (argv1 != argv1_buf )
19021918 wasm_runtime_free (argv1 );
1903- if (clear_wasi_proc_exit_exception (module_inst ))
1904- return true;
1905- return false;
1919+ goto fail ;
19061920 }
19071921
19081922 /* Get extra result values */
@@ -1941,19 +1955,38 @@ aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
19411955 else {
19421956 ret = invoke_native_internal (exec_env , func_ptr , func_type , signature ,
19431957 attachment , argv , argc , argv );
1944- if (clear_wasi_proc_exit_exception (module_inst ))
1945- return true;
1946- return ret ;
1958+ if (!ret )
1959+ goto fail ;
1960+
1961+ return true;
19471962 }
1963+
1964+ fail :
1965+ if (clear_wasi_proc_exit_exception (module_inst ))
1966+ return true;
1967+
1968+ #ifdef OS_ENABLE_HW_BOUND_CHECK
1969+ wasm_runtime_access_exce_check_guard_page ();
1970+ #endif
1971+ return false;
19481972}
19491973
19501974bool
19511975aot_check_app_addr_and_convert (AOTModuleInstance * module_inst , bool is_str ,
19521976 uint32 app_buf_addr , uint32 app_buf_size ,
19531977 void * * p_native_addr )
19541978{
1955- return wasm_check_app_addr_and_convert (module_inst , is_str , app_buf_addr ,
1956- app_buf_size , p_native_addr );
1979+ bool ret ;
1980+
1981+ ret = wasm_check_app_addr_and_convert (module_inst , is_str , app_buf_addr ,
1982+ app_buf_size , p_native_addr );
1983+
1984+ #ifdef OS_ENABLE_HW_BOUND_CHECK
1985+ if (!ret )
1986+ wasm_runtime_access_exce_check_guard_page ();
1987+ #endif
1988+
1989+ return ret ;
19571990}
19581991
19591992void *
0 commit comments