mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-11-27 10:00:59 +00:00
some refactor and add regression test case
This commit is contained in:
parent
9492cabfa3
commit
b8463822eb
|
|
@ -86,84 +86,6 @@ static bh_list registered_module_list_head;
|
||||||
static bh_list *const registered_module_list = ®istered_module_list_head;
|
static bh_list *const registered_module_list = ®istered_module_list_head;
|
||||||
static korp_mutex registered_module_list_lock;
|
static korp_mutex registered_module_list_lock;
|
||||||
|
|
||||||
void
|
|
||||||
wasm_runtime_propagate_exception_from_import(
|
|
||||||
WASMModuleInstanceCommon *parent, WASMModuleInstanceCommon *sub_module)
|
|
||||||
{
|
|
||||||
static const uint32 exception_prefix_len = sizeof("Exception: ") - 1;
|
|
||||||
static const char memory_oob_exception[] = "out of bounds memory access";
|
|
||||||
char exception_buf[EXCEPTION_BUF_LEN] = { 0 };
|
|
||||||
const char *message = NULL;
|
|
||||||
bool has_exception = false;
|
|
||||||
|
|
||||||
if (!parent || !sub_module)
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (sub_module->module_type) {
|
|
||||||
#if WASM_ENABLE_INTERP != 0
|
|
||||||
case Wasm_Module_Bytecode:
|
|
||||||
has_exception = wasm_copy_exception(
|
|
||||||
(WASMModuleInstance *)sub_module, exception_buf);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#if WASM_ENABLE_AOT != 0
|
|
||||||
case Wasm_Module_AoT:
|
|
||||||
has_exception = aot_copy_exception((AOTModuleInstance *)sub_module,
|
|
||||||
exception_buf);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (has_exception) {
|
|
||||||
message = exception_buf;
|
|
||||||
if (strlen(message) >= exception_prefix_len) {
|
|
||||||
message += exception_prefix_len;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
LOG_WARNING("sub-module exception format unexpected: %s", message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(message, memory_oob_exception) != 0) {
|
|
||||||
LOG_WARNING("skip propagating non-memory-OOB exception: %s",
|
|
||||||
message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (parent->module_type) {
|
|
||||||
#if WASM_ENABLE_INTERP != 0
|
|
||||||
case Wasm_Module_Bytecode:
|
|
||||||
wasm_set_exception((WASMModuleInstance *)parent, message);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#if WASM_ENABLE_AOT != 0
|
|
||||||
case Wasm_Module_AoT:
|
|
||||||
aot_set_exception((AOTModuleInstance *)parent, message);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (sub_module->module_type) {
|
|
||||||
#if WASM_ENABLE_INTERP != 0
|
|
||||||
case Wasm_Module_Bytecode:
|
|
||||||
wasm_set_exception((WASMModuleInstance *)sub_module, NULL);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#if WASM_ENABLE_AOT != 0
|
|
||||||
case Wasm_Module_AoT:
|
|
||||||
aot_set_exception((AOTModuleInstance *)sub_module, NULL);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wasm_runtime_destroy_registered_module_list(void);
|
wasm_runtime_destroy_registered_module_list(void);
|
||||||
#endif /* WASM_ENABLE_MULTI_MODULE */
|
#endif /* WASM_ENABLE_MULTI_MODULE */
|
||||||
|
|
@ -1449,6 +1371,84 @@ wasm_runtime_destroy_loading_module_list()
|
||||||
|
|
||||||
os_mutex_unlock(&loading_module_list_lock);
|
os_mutex_unlock(&loading_module_list_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wasm_runtime_propagate_exception_from_import(
|
||||||
|
WASMModuleInstanceCommon *parent, WASMModuleInstanceCommon *sub_module)
|
||||||
|
{
|
||||||
|
static const uint32 exception_prefix_len = sizeof("Exception: ") - 1;
|
||||||
|
static const char memory_oob_exception[] = "out of bounds memory access";
|
||||||
|
char exception_buf[EXCEPTION_BUF_LEN] = { 0 };
|
||||||
|
const char *message = NULL;
|
||||||
|
bool has_exception = false;
|
||||||
|
|
||||||
|
if (!parent || !sub_module)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (sub_module->module_type) {
|
||||||
|
#if WASM_ENABLE_INTERP != 0
|
||||||
|
case Wasm_Module_Bytecode:
|
||||||
|
has_exception = wasm_copy_exception(
|
||||||
|
(WASMModuleInstance *)sub_module, exception_buf);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#if WASM_ENABLE_AOT != 0
|
||||||
|
case Wasm_Module_AoT:
|
||||||
|
has_exception = aot_copy_exception((AOTModuleInstance *)sub_module,
|
||||||
|
exception_buf);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (has_exception) {
|
||||||
|
message = exception_buf;
|
||||||
|
if (strlen(message) >= exception_prefix_len) {
|
||||||
|
message += exception_prefix_len;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LOG_WARNING("sub-module exception format unexpected: %s", message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(message, memory_oob_exception) != 0) {
|
||||||
|
LOG_WARNING("skip propagating non-memory-OOB exception: %s",
|
||||||
|
message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (parent->module_type) {
|
||||||
|
#if WASM_ENABLE_INTERP != 0
|
||||||
|
case Wasm_Module_Bytecode:
|
||||||
|
wasm_set_exception((WASMModuleInstance *)parent, message);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#if WASM_ENABLE_AOT != 0
|
||||||
|
case Wasm_Module_AoT:
|
||||||
|
aot_set_exception((AOTModuleInstance *)parent, message);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (sub_module->module_type) {
|
||||||
|
#if WASM_ENABLE_INTERP != 0
|
||||||
|
case Wasm_Module_Bytecode:
|
||||||
|
wasm_set_exception((WASMModuleInstance *)sub_module, NULL);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#if WASM_ENABLE_AOT != 0
|
||||||
|
case Wasm_Module_AoT:
|
||||||
|
aot_set_exception((AOTModuleInstance *)sub_module, NULL);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif /* WASM_ENABLE_MULTI_MODULE */
|
#endif /* WASM_ENABLE_MULTI_MODULE */
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,15 @@ function build_iwasm() {
|
||||||
cd ${WORK_DIR}/build &&
|
cd ${WORK_DIR}/build &&
|
||||||
if [ -d build-iwasm-$2 ]; then rm -rf build-iwasm-$2; else mkdir build-iwasm-$2; fi &&
|
if [ -d build-iwasm-$2 ]; then rm -rf build-iwasm-$2; else mkdir build-iwasm-$2; fi &&
|
||||||
cd build-iwasm-$2 &&
|
cd build-iwasm-$2 &&
|
||||||
|
|
||||||
|
# default: enable asan, when pass false, disable asan
|
||||||
|
SANITIZER_FLAG="-DWAMR_BUILD_SANITIZER=asan"
|
||||||
|
if [ "$3" = "false" ]; then
|
||||||
|
SANITIZER_FLAG=""
|
||||||
|
fi
|
||||||
|
|
||||||
cmake ${WAMR_DIR}/product-mini/platforms/${PLATFORM} $1 \
|
cmake ${WAMR_DIR}/product-mini/platforms/${PLATFORM} $1 \
|
||||||
-DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_SANITIZER=asan &&
|
-DCMAKE_BUILD_TYPE=Debug ${SANITIZER_FLAG} &&
|
||||||
make -j 4
|
make -j 4
|
||||||
if [ "$?" != 0 ]; then
|
if [ "$?" != 0 ]; then
|
||||||
echo -e "build iwasm failed"
|
echo -e "build iwasm failed"
|
||||||
|
|
@ -60,4 +67,7 @@ build_iwasm "-DWAMR_BUILD_REF_TYPES=1 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LIBC_WASI=
|
||||||
# build multi-tier-jit iwasm for testing classic-interp, fast-jit, llvm-jit and multi-tier-jit with libc-wasi disabled
|
# build multi-tier-jit iwasm for testing classic-interp, fast-jit, llvm-jit and multi-tier-jit with libc-wasi disabled
|
||||||
build_iwasm "-DWAMR_BUILD_REF_TYPES=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LIBC_WASI=0" "multi-tier-jit-wasi-disabled"
|
build_iwasm "-DWAMR_BUILD_REF_TYPES=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LIBC_WASI=0" "multi-tier-jit-wasi-disabled"
|
||||||
|
|
||||||
|
# build default iwasm for testing multi-module
|
||||||
|
build_iwasm "-DWAMR_BUILD_MULTI_MODULE=1 -DWAMR_BUILD_MULTI_MEMORY=1 -DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=0" "multi-memory-multi-module" "false"
|
||||||
|
|
||||||
# TODO: add more version of iwasm, for example, sgx version
|
# TODO: add more version of iwasm, for example, sgx version
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -1818,6 +1818,22 @@
|
||||||
"stdout content": "Exception: unsupported opcode",
|
"stdout content": "Exception: unsupported opcode",
|
||||||
"description": "classic-interp will exit gracefully when meeting simd opcodes"
|
"description": "classic-interp will exit gracefully when meeting simd opcodes"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"deprecated": false,
|
||||||
|
"ids": [
|
||||||
|
4703
|
||||||
|
],
|
||||||
|
"runtime": "iwasm-multi-memory-multi-module",
|
||||||
|
"file": "single_page_memory.wasm",
|
||||||
|
"mode": "classic-interp",
|
||||||
|
"options": "--module-path=./issues/issue-4703",
|
||||||
|
"argument": "",
|
||||||
|
"expected return": {
|
||||||
|
"ret code": 1,
|
||||||
|
"stdout content": "Exception: out of bounds memory access",
|
||||||
|
"description": "when encounter memory OOB in sub-module when hardware bondary check is enabled, report exception correctly instead of silent exit"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user