Implement aux stack overflow/underflow check for AOT/interp (#601)

This commit is contained in:
Wenyong Huang
2021-04-07 16:15:59 +08:00
committed by GitHub
parent fe76c89c25
commit 77c3ddf7d0
18 changed files with 242 additions and 45 deletions

View File

@ -5,6 +5,12 @@
#include "wasm_exec_env.h"
#include "wasm_runtime_common.h"
#if WASM_ENABLE_INTERP != 0
#include "../interpreter/wasm_runtime.h"
#endif
#if WASM_ENABLE_AOT != 0
#include "../aot/aot_runtime.h"
#endif
#if WASM_ENABLE_THREAD_MGR != 0
#include "../libraries/thread-mgr/thread_manager.h"
@ -88,20 +94,37 @@ WASMExecEnv *
wasm_exec_env_create(struct WASMModuleInstanceCommon *module_inst,
uint32 stack_size)
{
#if WASM_ENABLE_THREAD_MGR != 0
WASMCluster *cluster;
#endif
WASMExecEnv *exec_env =
wasm_exec_env_create_internal(module_inst, stack_size);
if (!exec_env)
return NULL;
/* Set the aux_stack_boundary to 0 */
exec_env->aux_stack_boundary = 0;
#if WASM_ENABLE_THREAD_MGR != 0
WASMCluster *cluster;
/* Set the aux_stack_boundary and aux_stack_bottom */
#if WASM_ENABLE_INTERP != 0
if (module_inst->module_type == Wasm_Module_Bytecode) {
WASMModule *module = ((WASMModuleInstance *)module_inst)->module;
exec_env->aux_stack_bottom.bottom = module->aux_stack_bottom;
exec_env->aux_stack_boundary.boundary = module->aux_stack_bottom
- module->aux_stack_size;
}
#endif
#if WASM_ENABLE_AOT != 0
if (module_inst->module_type == Wasm_Module_AoT) {
AOTModule *module =
(AOTModule *)(((AOTModuleInstance *)module_inst)->aot_module.ptr);
exec_env->aux_stack_bottom.bottom = module->aux_stack_bottom;
exec_env->aux_stack_boundary.boundary = module->aux_stack_bottom
- module->aux_stack_size;
}
#endif
#if WASM_ENABLE_THREAD_MGR != 0
/* Create a new cluster for this exec_env */
cluster = wasm_cluster_create(exec_env);
if (!cluster) {
if (!(cluster = wasm_cluster_create(exec_env))) {
wasm_exec_env_destroy_internal(exec_env);
return NULL;
}

View File

@ -37,8 +37,10 @@ typedef struct WASMExecEnv {
/* Previous thread's exec env of a WASM module instance. */
struct WASMExecEnv *prev;
/* Note: field module_inst, argv_buf and native_stack_boundary
are used by AOTed code, don't change the places of them */
/* Note: field module_inst, argv_buf, native_stack_boundary,
suspend_flags, aux_stack_boundary, aux_stack_bottom, and
native_symbol are used by AOTed code, don't change the
places of them */
/* The WASM module instance of current thread */
struct WASMModuleInstanceCommon *module_inst;
@ -52,10 +54,9 @@ typedef struct WASMExecEnv {
exception. */
uint8 *native_stack_boundary;
#if WASM_ENABLE_THREAD_MGR != 0
/* Used to terminate or suspend the interpreter
bit 0: need terminate
bit 1: need suspend
/* Used to terminate or suspend current thread
bit 0: need to terminate
bit 1: need to suspend
bit 2: need to go into breakpoint
bit 3: return from pthread_exit */
union {
@ -63,6 +64,24 @@ typedef struct WASMExecEnv {
uintptr_t __padding__;
} suspend_flags;
/* Auxiliary stack boundary */
union {
uint32 boundary;
uintptr_t __padding__;
} aux_stack_boundary;
/* Auxiliary stack bottom */
union {
uint32 bottom;
uintptr_t __padding__;
} aux_stack_bottom;
#if WASM_ENABLE_AOT != 0
/* Native symbol list, reserved */
void **native_symbol;
#endif
#if WASM_ENABLE_THREAD_MGR != 0
/* thread return value */
void *thread_ret_value;
@ -78,9 +97,6 @@ typedef struct WASMExecEnv {
korp_cond wait_cond;
#endif
/* Aux stack boundary */
uint32 aux_stack_boundary;
/* attachment for native function */
void *attachment;