@@ -57,6 +57,9 @@ bh_static_assert(sizeof(AOTMemoryInstance) == 120);
5757bh_static_assert (offsetof(AOTTableInstance , elems ) == 24 );
5858
5959bh_static_assert (offsetof(AOTModuleInstanceExtra , stack_sizes ) == 0 );
60+ bh_static_assert (offsetof(AOTModuleInstanceExtra , shared_heap_base_addr_adj )
61+ == 8 );
62+ bh_static_assert (offsetof(AOTModuleInstanceExtra , shared_heap_start_off ) == 16 );
6063
6164bh_static_assert (sizeof (CApiFuncImport ) == sizeof (uintptr_t ) * 3 );
6265
@@ -1895,6 +1898,24 @@ aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
18951898 extra -> stack_sizes =
18961899 aot_get_data_section_addr (module , AOT_STACK_SIZES_SECTION_NAME , NULL );
18971900
1901+ /*
1902+ * The AOT code checks whether the n bytes to access are in shared heap
1903+ * by checking whether the beginning address meets:
1904+ * addr >= start_off && addr <= end_off - n-bytes + 1
1905+ * where n is 1/2/4/8/16 and `end_off - n-bytes + 1` is constant, e.g.,
1906+ * UINT32_MAX, UINT32_MAX-1, UINT32_MAX-3 for n = 1, 2 or 4 in 32-bit
1907+ * target. To simplify the check, when shared heap is disabled, we set
1908+ * the start off to UINT64_MAX in 64-bit target and UINT32_MAX in 32-bit
1909+ * target, so in the checking, the above formula will be false, we don't
1910+ * need to check whether the shared heap is enabled or not in the AOT
1911+ * code.
1912+ */
1913+ #if UINTPTR_MAX == UINT64_MAX
1914+ extra -> shared_heap_start_off .u64 = UINT64_MAX ;
1915+ #else
1916+ extra -> shared_heap_start_off .u32 [0 ] = UINT32_MAX ;
1917+ #endif
1918+
18981919#if WASM_ENABLE_PERF_PROFILING != 0
18991920 total_size = sizeof (AOTFuncPerfProfInfo )
19001921 * ((uint64 )module -> import_func_count + module -> func_count );
0 commit comments