Skip to content

Commit 8f49f86

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 3288983 commit 8f49f86

6 files changed

Lines changed: 296 additions & 152 deletions

File tree

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
@@ -7907,7 +7907,8 @@ wasm_runtime_update_last_used_shared_heap(WASMModuleInstanceCommon *module_inst,
79077907
is_memory64 ? cur->start_off_mem64 : cur->start_off_mem32;
79087908
shared_heap_end = shared_heap_start - 1 + cur->size;
79097909
if (app_offset >= shared_heap_start
7910-
&& app_offset <= shared_heap_end - bytes + 1) {
7910+
&& app_offset <= shared_heap_end - bytes + 1
7911+
&& bytes - 1 <= shared_heap_end) {
79117912
*shared_heap_start_off_p = (uintptr_t)shared_heap_start;
79127913
*shared_heap_end_off_p = (uintptr_t)shared_heap_end;
79137914
*shared_heap_base_addr_adj_p =

0 commit comments

Comments
 (0)