Skip to content

Commit

Permalink
some update
Browse files Browse the repository at this point in the history
  • Loading branch information
TianlongLiang committed Mar 18, 2024
1 parent ab527f6 commit ac1f00b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
9 changes: 4 additions & 5 deletions core/iwasm/common/wasm_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
uint8 *memory_data_old, *memory_data_new, *heap_data_old;
uint32 num_bytes_per_page, heap_size;
uint32 cur_page_count, max_page_count, total_page_count;
uint64 total_size_old = 0, total_size_new, default_max_memory_size;
uint64 total_size_old = 0, total_size_new;
bool ret = true, full_size_mmaped;
enlarge_memory_error_reason_t failure_reason = INTERNAL_ERROR;

Expand Down Expand Up @@ -748,9 +748,8 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
goto return_func;
}

default_max_memory_size = memory->is_memory64 ? MAX_LINEAR_MEM64_MEMORY_SIZE
: MAX_LINEAR_MEMORY_SIZE;
bh_assert(total_size_new <= default_max_memory_size);
bh_assert(total_size_new
<= GET_MAX_LINEAR_MEMORY_SIZE(memory->is_memory64));

if (full_size_mmaped) {
#ifdef BH_PLATFORM_WINDOWS
Expand Down Expand Up @@ -837,7 +836,7 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
(WASMModuleInstanceCommon *)module, exec_env,
enlarge_memory_error_user_data);
}
(void)default_max_memory_size;

return ret;
}

Expand Down
3 changes: 3 additions & 0 deletions core/iwasm/interpreter/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ extern "C" {
/* Roughly 274 TB */
#define MAX_LINEAR_MEM64_MEMORY_SIZE \
(DEFAULT_MEM64_MAX_PAGES * 64 * (uint64)BH_KB)
/* Macro to check memory flag and return appropriate memory size */
#define GET_MAX_LINEAR_MEMORY_SIZE(is_memory64) \
(is_memory64 ? MAX_LINEAR_MEM64_MEMORY_SIZE : MAX_LINEAR_MEMORY_SIZE)

#if WASM_ENABLE_GC == 0
typedef uintptr_t table_elem_type_t;
Expand Down
13 changes: 9 additions & 4 deletions core/iwasm/interpreter/wasm_interp_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ wasm_interp_get_frame_ref(WASMInterpFrame *frame)
p += _off; \
} while (0)

#if WASM_ENABLE_MEMORY64 != 0
#define read_leb_mem_offset(p, p_end, res) \
do { \
uint8 _val = *p; \
Expand All @@ -677,6 +678,9 @@ wasm_interp_get_frame_ref(WASMInterpFrame *frame)
false); \
p += _off; \
} while (0)
#else
#define read_leb_mem_offset(p, p_end, res) read_leb_uint32(p, p_end, res)
#endif

#if WASM_ENABLE_LABELS_AS_VALUES == 0
#define RECOVER_FRAME_IP_END() frame_ip_end = wasm_get_func_code_end(cur_func)
Expand Down Expand Up @@ -1472,7 +1476,6 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
int32_t exception_tag_index;
#endif
uint8 value_type;
bool is_memory64 = false;
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
Expand All @@ -1497,6 +1500,9 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
WASMStringviewIterObjectRef stringview_iter_obj;
#endif
#endif
#if WASM_ENABLE_MEMORY64 != 0
bool is_memory64 = false;
#endif

#if WASM_ENABLE_DEBUG_INTERP != 0
uint8 *frame_ip_orig = NULL;
Expand Down Expand Up @@ -4477,7 +4483,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
else
#endif
{
PUT_I64_TO_ADDR((linear_mem_ptr_t *)maddr,
PUT_I64_TO_ADDR((uint32 *)maddr,
GET_I64_FROM_ADDR(frame_sp + 1));
}
CHECK_WRITE_WATCHPOINT(addr, offset);
Expand Down Expand Up @@ -5749,8 +5755,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
SYNC_ALL_TO_FRAME();
#endif
for (i = 0; i < n; i++) {
/* UINT32_MAX indicates that it is a null ref
*/
/* UINT32_MAX indicates that it is a null ref */
bh_assert(init_values[i].init_expr_type
== INIT_EXPR_TYPE_REFNULL_CONST
|| init_values[i].init_expr_type
Expand Down
26 changes: 14 additions & 12 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -4734,18 +4734,20 @@ load_data_segment_section(const uint8 *buf, const uint8 *buf_end,
#endif
{
#if WASM_ENABLE_MEMORY64 != 0
/* This reassigned mem_flag is from memory instead of data
* segment
*/
bool is_memory64 =
(module->import_memory_count > 0
? module->import_memories[mem_index].u.memory.flags
: module
->memories[mem_index
- module->import_memory_count]
.flags)
& MEMORY64_FLAG;
mem_offset_type = is_memory64 ? VALUE_TYPE_I64 : VALUE_TYPE_I32;
/* This memory_flag is from memory instead of data segment */
uint8 memory_flag;
if (module->import_memory_count > 0) {
memory_flag =
module->import_memories[mem_index].u.memory.flags;
}
else {
memory_flag =
module
->memories[mem_index - module->import_memory_count]
.flags;
}
mem_offset_type = memory_flag & MEMORY64_FLAG ? VALUE_TYPE_I64
: VALUE_TYPE_I32;
#else
mem_offset_type = VALUE_TYPE_I32;
#endif
Expand Down

0 comments on commit ac1f00b

Please sign in to comment.