Skip to content

Commit b57e280

Browse files
committed
cr suggestions: 1. check potiential underflow 2. refactor and use separate function for bulk memory and normal memroy 3. static assert 4. add more comments 5. remove unused code
1 parent d21c236 commit b57e280

File tree

6 files changed

+296
-152
lines changed

6 files changed

+296
-152
lines changed

core/iwasm/aot/aot_runtime.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ bh_static_assert(offsetof(AOTModuleInstanceExtra, shared_heap_start_off) == 16);
6363
bh_static_assert(offsetof(AOTModuleInstanceExtra, shared_heap_end_off) == 24);
6464
bh_static_assert(offsetof(AOTModuleInstanceExtra, shared_heap) == 32);
6565

66+
bh_static_assert(offsetof(WASMSharedHeap, next) == 0);
6667
bh_static_assert(offsetof(WASMSharedHeap, chain_next) == 8);
68+
bh_static_assert(offsetof(WASMSharedHeap, heap_handle) == 16);
6769
bh_static_assert(offsetof(WASMSharedHeap, base_addr) == 24);
6870
bh_static_assert(offsetof(WASMSharedHeap, size) == 32);
6971
bh_static_assert(offsetof(WASMSharedHeap, start_off_mem64) == 40);

core/iwasm/common/wasm_memory.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,8 @@ is_app_addr_in_shared_heap(WASMModuleInstanceCommon *module_inst,
615615
(uint64)get_last_used_shared_heap_start_offset(module_inst);
616616
shared_heap_end = (uint64)get_last_used_shared_heap_end_offset(module_inst);
617617
if (app_offset >= shared_heap_start
618-
&& app_offset <= shared_heap_end - bytes + 1) {
618+
&& app_offset <= shared_heap_end - bytes + 1
619+
&& bytes - 1 <= shared_heap_end) {
619620
return true;
620621
}
621622

@@ -624,7 +625,8 @@ is_app_addr_in_shared_heap(WASMModuleInstanceCommon *module_inst,
624625
is_memory64 ? heap->start_off_mem64 : heap->start_off_mem32;
625626
shared_heap_end = is_memory64 ? UINT64_MAX : UINT32_MAX;
626627
if (app_offset < shared_heap_start
627-
|| app_offset > shared_heap_end - bytes + 1) {
628+
|| app_offset > shared_heap_end - bytes + 1
629+
|| bytes - 1 > shared_heap_end) {
628630
goto fail;
629631
}
630632

@@ -635,7 +637,8 @@ is_app_addr_in_shared_heap(WASMModuleInstanceCommon *module_inst,
635637
is_memory64 ? cur->start_off_mem64 : cur->start_off_mem32;
636638
shared_heap_end = shared_heap_start - 1 + cur->size;
637639
if (app_offset >= shared_heap_start
638-
&& app_offset <= shared_heap_end - bytes + 1) {
640+
&& app_offset <= shared_heap_end - bytes + 1
641+
&& bytes - 1 <= shared_heap_end) {
639642
update_last_used_shared_heap(module_inst, cur, is_memory64);
640643
return true;
641644
}

core/iwasm/common/wasm_runtime_common.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7851,7 +7851,8 @@ wasm_runtime_update_last_used_shared_heap(WASMModuleInstanceCommon *module_inst,
78517851
is_memory64 ? cur->start_off_mem64 : cur->start_off_mem32;
78527852
shared_heap_end = shared_heap_start - 1 + cur->size;
78537853
if (app_offset >= shared_heap_start
7854-
&& app_offset <= shared_heap_end - bytes + 1) {
7854+
&& app_offset <= shared_heap_end - bytes + 1
7855+
&& bytes - 1 <= shared_heap_end) {
78557856
*shared_heap_start_off_p = (uintptr_t)shared_heap_start;
78567857
*shared_heap_end_off_p = (uintptr_t)shared_heap_end;
78577858
*shared_heap_base_addr_adj_p =

0 commit comments

Comments
 (0)