Skip to content

Commit c53d251

Browse files
committed
some refactor and add regression test case
1 parent ad73fb1 commit c53d251

File tree

5 files changed

+106
-80
lines changed

5 files changed

+106
-80
lines changed

core/iwasm/common/wasm_runtime_common.c

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -86,84 +86,6 @@ static bh_list registered_module_list_head;
8686
static bh_list *const registered_module_list = &registered_module_list_head;
8787
static korp_mutex registered_module_list_lock;
8888

89-
void
90-
wasm_runtime_propagate_exception_from_import(
91-
WASMModuleInstanceCommon *parent, WASMModuleInstanceCommon *sub_module)
92-
{
93-
static const uint32 exception_prefix_len = sizeof("Exception: ") - 1;
94-
static const char memory_oob_exception[] = "out of bounds memory access";
95-
char exception_buf[EXCEPTION_BUF_LEN] = { 0 };
96-
const char *message = NULL;
97-
bool has_exception = false;
98-
99-
if (!parent || !sub_module)
100-
return;
101-
102-
switch (sub_module->module_type) {
103-
#if WASM_ENABLE_INTERP != 0
104-
case Wasm_Module_Bytecode:
105-
has_exception = wasm_copy_exception(
106-
(WASMModuleInstance *)sub_module, exception_buf);
107-
break;
108-
#endif
109-
#if WASM_ENABLE_AOT != 0
110-
case Wasm_Module_AoT:
111-
has_exception = aot_copy_exception((AOTModuleInstance *)sub_module,
112-
exception_buf);
113-
break;
114-
#endif
115-
default:
116-
return;
117-
}
118-
119-
if (has_exception) {
120-
message = exception_buf;
121-
if (strlen(message) >= exception_prefix_len) {
122-
message += exception_prefix_len;
123-
}
124-
else {
125-
LOG_WARNING("sub-module exception format unexpected: %s", message);
126-
return;
127-
}
128-
129-
if (strcmp(message, memory_oob_exception) != 0) {
130-
LOG_WARNING("skip propagating non-memory-OOB exception: %s",
131-
message);
132-
return;
133-
}
134-
135-
switch (parent->module_type) {
136-
#if WASM_ENABLE_INTERP != 0
137-
case Wasm_Module_Bytecode:
138-
wasm_set_exception((WASMModuleInstance *)parent, message);
139-
break;
140-
#endif
141-
#if WASM_ENABLE_AOT != 0
142-
case Wasm_Module_AoT:
143-
aot_set_exception((AOTModuleInstance *)parent, message);
144-
break;
145-
#endif
146-
default:
147-
break;
148-
}
149-
150-
switch (sub_module->module_type) {
151-
#if WASM_ENABLE_INTERP != 0
152-
case Wasm_Module_Bytecode:
153-
wasm_set_exception((WASMModuleInstance *)sub_module, NULL);
154-
break;
155-
#endif
156-
#if WASM_ENABLE_AOT != 0
157-
case Wasm_Module_AoT:
158-
aot_set_exception((AOTModuleInstance *)sub_module, NULL);
159-
break;
160-
#endif
161-
default:
162-
break;
163-
}
164-
}
165-
}
166-
16789
static void
16890
wasm_runtime_destroy_registered_module_list(void);
16991
#endif /* WASM_ENABLE_MULTI_MODULE */
@@ -1449,6 +1371,84 @@ wasm_runtime_destroy_loading_module_list()
14491371

14501372
os_mutex_unlock(&loading_module_list_lock);
14511373
}
1374+
1375+
void
1376+
wasm_runtime_propagate_exception_from_import(
1377+
WASMModuleInstanceCommon *parent, WASMModuleInstanceCommon *sub_module)
1378+
{
1379+
static const uint32 exception_prefix_len = sizeof("Exception: ") - 1;
1380+
static const char memory_oob_exception[] = "out of bounds memory access";
1381+
char exception_buf[EXCEPTION_BUF_LEN] = { 0 };
1382+
const char *message = NULL;
1383+
bool has_exception = false;
1384+
1385+
if (!parent || !sub_module)
1386+
return;
1387+
1388+
switch (sub_module->module_type) {
1389+
#if WASM_ENABLE_INTERP != 0
1390+
case Wasm_Module_Bytecode:
1391+
has_exception = wasm_copy_exception(
1392+
(WASMModuleInstance *)sub_module, exception_buf);
1393+
break;
1394+
#endif
1395+
#if WASM_ENABLE_AOT != 0
1396+
case Wasm_Module_AoT:
1397+
has_exception = aot_copy_exception((AOTModuleInstance *)sub_module,
1398+
exception_buf);
1399+
break;
1400+
#endif
1401+
default:
1402+
return;
1403+
}
1404+
1405+
if (has_exception) {
1406+
message = exception_buf;
1407+
if (strlen(message) >= exception_prefix_len) {
1408+
message += exception_prefix_len;
1409+
}
1410+
else {
1411+
LOG_WARNING("sub-module exception format unexpected: %s", message);
1412+
return;
1413+
}
1414+
1415+
if (strcmp(message, memory_oob_exception) != 0) {
1416+
LOG_WARNING("skip propagating non-memory-OOB exception: %s",
1417+
message);
1418+
return;
1419+
}
1420+
1421+
switch (parent->module_type) {
1422+
#if WASM_ENABLE_INTERP != 0
1423+
case Wasm_Module_Bytecode:
1424+
wasm_set_exception((WASMModuleInstance *)parent, message);
1425+
break;
1426+
#endif
1427+
#if WASM_ENABLE_AOT != 0
1428+
case Wasm_Module_AoT:
1429+
aot_set_exception((AOTModuleInstance *)parent, message);
1430+
break;
1431+
#endif
1432+
default:
1433+
break;
1434+
}
1435+
1436+
switch (sub_module->module_type) {
1437+
#if WASM_ENABLE_INTERP != 0
1438+
case Wasm_Module_Bytecode:
1439+
wasm_set_exception((WASMModuleInstance *)sub_module, NULL);
1440+
break;
1441+
#endif
1442+
#if WASM_ENABLE_AOT != 0
1443+
case Wasm_Module_AoT:
1444+
aot_set_exception((AOTModuleInstance *)sub_module, NULL);
1445+
break;
1446+
#endif
1447+
default:
1448+
break;
1449+
}
1450+
}
1451+
}
14521452
#endif /* WASM_ENABLE_MULTI_MODULE */
14531453

14541454
bool

tests/regression/ba-issues/build_wamr.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ function build_iwasm() {
2525
cd ${WORK_DIR}/build &&
2626
if [ -d build-iwasm-$2 ]; then rm -rf build-iwasm-$2; else mkdir build-iwasm-$2; fi &&
2727
cd build-iwasm-$2 &&
28+
29+
# default: enable asan, when pass false, disable asan
30+
SANITIZER_FLAG="-DWAMR_BUILD_SANITIZER=asan"
31+
if [ "$3" = "false" ]; then
32+
SANITIZER_FLAG=""
33+
fi
34+
2835
cmake ${WAMR_DIR}/product-mini/platforms/${PLATFORM} $1 \
29-
-DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_SANITIZER=asan &&
36+
-DCMAKE_BUILD_TYPE=Debug ${SANITIZER_FLAG} &&
3037
make -j 4
3138
if [ "$?" != 0 ]; then
3239
echo -e "build iwasm failed"
@@ -60,4 +67,7 @@ build_iwasm "-DWAMR_BUILD_REF_TYPES=1 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LIBC_WASI=
6067
# build multi-tier-jit iwasm for testing classic-interp, fast-jit, llvm-jit and multi-tier-jit with libc-wasi disabled
6168
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"
6269

70+
# build default iwasm for testing multi-module
71+
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"
72+
6373
# TODO: add more version of iwasm, for example, sgx version
Binary file not shown.
Binary file not shown.

tests/regression/ba-issues/running_config.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,22 @@
18181818
"stdout content": "Exception: unsupported opcode",
18191819
"description": "classic-interp will exit gracefully when meeting simd opcodes"
18201820
}
1821+
},
1822+
{
1823+
"deprecated": false,
1824+
"ids": [
1825+
4703
1826+
],
1827+
"runtime": "iwasm-multi-memory-multi-module",
1828+
"file": "single_page_memory.wasm",
1829+
"mode": "classic-interp",
1830+
"options": "--module-path=./issues/issue-4703",
1831+
"argument": "",
1832+
"expected return": {
1833+
"ret code": 1,
1834+
"stdout content": "Exception: out of bounds memory access",
1835+
"description": "when encounter memory OOB in sub-module when hardware bondary check is enabled, report exception correctly instead of silent exit"
1836+
}
18211837
}
18221838
]
1823-
}
1839+
}

0 commit comments

Comments
 (0)