Fix windows AOT hw bound check (#2475)

When AOT out of bound linear memory access or stack overflow occurs, the call stack of
AOT functions cannot be unwound currently, so from the exception handler, runtime
cannot jump back into the place that calls the AOT function.
We temporarily skip the current instruction and let AOT code continue to run and return
to caller as soon as possible. And use the zydis library the decode the current instruction
to get its size.

And remove using RtlAddFunctionTable to register the AOT functions since it doesn't work
currently.
This commit is contained in:
Wenyong Huang
2023-08-18 10:16:03 +08:00
committed by GitHub
parent 6716c23dd1
commit 2cb701f7f3
6 changed files with 159 additions and 134 deletions

View File

@ -18,6 +18,17 @@
} \
} while (0)
static bool
is_win_platform(AOTCompContext *comp_ctx)
{
char *triple = LLVMGetTargetMachineTriple(comp_ctx->target_machine);
bh_assert(trip);
if (strstr(triple, "win32") || strstr(triple, "win"))
return true;
return false;
}
static bool
create_func_return_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
{
@ -458,7 +469,7 @@ check_app_addr_and_convert(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
}
/* Check whether exception was thrown when executing the function */
if (comp_ctx->enable_bound_check
if ((comp_ctx->enable_bound_check || is_win_platform(comp_ctx))
&& !check_call_return(comp_ctx, func_ctx, res)) {
return false;
}
@ -696,7 +707,7 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
goto fail;
/* Check whether there was exception thrown when executing
the function */
if (comp_ctx->enable_bound_check
if ((comp_ctx->enable_bound_check || is_win_platform(comp_ctx))
&& !check_call_return(comp_ctx, func_ctx, res))
goto fail;
}
@ -849,7 +860,8 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
/* Check whether there was exception thrown when executing
the function */
if (!tail_call && comp_ctx->enable_bound_check
if (!tail_call
&& (comp_ctx->enable_bound_check || is_win_platform(comp_ctx))
&& !check_exception_thrown(comp_ctx, func_ctx))
goto fail;
}
@ -1431,7 +1443,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
goto fail;
/* Check whether exception was thrown when executing the function */
if (comp_ctx->enable_bound_check
if ((comp_ctx->enable_bound_check || is_win_platform(comp_ctx))
&& !check_call_return(comp_ctx, func_ctx, res))
goto fail;
@ -1483,7 +1495,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
}
/* Check whether exception was thrown when executing the function */
if (comp_ctx->enable_bound_check
if ((comp_ctx->enable_bound_check || is_win_platform(comp_ctx))
&& !check_exception_thrown(comp_ctx, func_ctx))
goto fail;