Skip to content

Commit

Permalink
some update
Browse files Browse the repository at this point in the history
  • Loading branch information
TianlongLiang committed Feb 29, 2024
1 parent 40e6c95 commit 0a3ae63
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 56 deletions.
2 changes: 1 addition & 1 deletion core/app-mgr/app-manager/module_wasm_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ app_instance_queue_callback(void *queue_msg, void *arg)
(response_t *)bh_message_payload(queue_msg);
int size;
char *buffer;
int32 buffer_offset;
int64 buffer_offset;

app_manager_printf("App %s got response_t,status %d\n",
m_data->module_name, response->status);
Expand Down
5 changes: 3 additions & 2 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2430,8 +2430,9 @@ load_init_data_section(const uint8 *buf, const uint8 *buf_end,
read_uint64(p, p_end, module->aux_stack_bottom);
read_uint32(p, p_end, module->aux_stack_size);

if (module->aux_data_end > UINT32_MAX || module->aux_heap_base > UINT32_MAX
|| module->aux_stack_bottom > UINT32_MAX) {
if (module->aux_data_end >= MAX_LINEAR_MEMORY_SIZE
|| module->aux_heap_base >= MAX_LINEAR_MEMORY_SIZE
|| module->aux_stack_bottom >= MAX_LINEAR_MEMORY_SIZE) {
set_error_buf(
error_buf, error_buf_size,
"invalid range of aux_date_end/aux_heap_base/aux_stack_bottom");
Expand Down
9 changes: 5 additions & 4 deletions core/iwasm/aot/aot_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2645,16 +2645,17 @@ aot_module_dup_data(AOTModuleInstance *module_inst, const char *src,
uint64 size)
{
char *buffer;
uint64 buffer_offset =
aot_module_malloc(module_inst, size, (void **)&buffer);
uint64 buffer_offset;

/* TODO: Memory64 size check based on memory idx type */
bh_assert(size <= UINT32_MAX);

buffer_offset = aot_module_malloc(module_inst, size, (void **)&buffer);

if (buffer_offset != 0) {
buffer = wasm_runtime_addr_app_to_native(
(WASMModuleInstanceCommon *)module_inst, buffer_offset);
bh_memcpy_s(buffer, size, src, size);
bh_memcpy_s(buffer, (uint32)size, src, (uint32)size);
}
return buffer_offset;
}
Expand Down Expand Up @@ -3012,7 +3013,7 @@ aot_memory_init(AOTModuleInstance *module_inst, uint32 seg_index, uint32 offset,
(WASMModuleInstanceCommon *)module_inst, (uint64)dst);

SHARED_MEMORY_LOCK(memory_inst);
bh_memcpy_s(maddr, (uint32)memory_inst->memory_data_size - dst,
bh_memcpy_s(maddr, (uint32)(memory_inst->memory_data_size - dst),
data + offset, len);
SHARED_MEMORY_UNLOCK(memory_inst);
return true;
Expand Down
4 changes: 0 additions & 4 deletions core/iwasm/common/wasm_exec_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ wasm_exec_env_create(struct WASMModuleInstanceCommon *module_inst,
/* Set the aux_stack_boundary and aux_stack_bottom */
if (module_inst->module_type == Wasm_Module_Bytecode) {
WASMModule *module = ((WASMModuleInstance *)module_inst)->module;
/* TODO: only assert when it's not memory64 */
bh_assert(module->aux_stack_bottom < UINT32_MAX);
exec_env->aux_stack_bottom = (uintptr_t)module->aux_stack_bottom;
exec_env->aux_stack_boundary =
(uintptr_t)module->aux_stack_bottom - module->aux_stack_size;
Expand All @@ -165,8 +163,6 @@ wasm_exec_env_create(struct WASMModuleInstanceCommon *module_inst,
if (module_inst->module_type == Wasm_Module_AoT) {
AOTModule *module =
(AOTModule *)((AOTModuleInstance *)module_inst)->module;
/* TODO: only assert when it's not memory64 */
bh_assert(module->aux_stack_bottom < UINT32_MAX);
exec_env->aux_stack_bottom = (uintptr_t)module->aux_stack_bottom;
exec_env->aux_stack_boundary =
(uintptr_t)module->aux_stack_bottom - module->aux_stack_size;
Expand Down
15 changes: 12 additions & 3 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1575,11 +1575,11 @@ wasm_runtime_dump_module_inst_mem_consumption(
}
#endif

os_printf("WASM module inst memory consumption, total size: %u\n",
os_printf("WASM module inst memory consumption, total size: %lu\n",
mem_conspn.total_size);
os_printf(" module inst struct size: %u\n",
mem_conspn.module_inst_struct_size);
os_printf(" memories size: %u\n", mem_conspn.memories_size);
os_printf(" memories size: %lu\n", mem_conspn.memories_size);
os_printf(" app heap size: %u\n", mem_conspn.app_heap_size);
os_printf(" tables size: %u\n", mem_conspn.tables_size);
os_printf(" functions size: %u\n", mem_conspn.functions_size);
Expand Down Expand Up @@ -1614,8 +1614,9 @@ wasm_runtime_dump_mem_consumption(WASMExecEnv *exec_env)
WASMModuleInstanceCommon *module_inst_common;
WASMModuleCommon *module_common = NULL;
void *heap_handle = NULL;
uint32 total_size = 0, app_heap_peak_size = 0;
uint32 app_heap_peak_size = 0;
uint32 max_aux_stack_used = -1;
uint64 total_size = 0;

module_inst_common = exec_env->module_inst;
#if WASM_ENABLE_INTERP != 0
Expand Down Expand Up @@ -3655,6 +3656,8 @@ wasm_runtime_invoke_native_raw(WASMExecEnv *exec_env, void *func_ptr,
case VALUE_TYPE_FUNCREF:
#endif
{
/* TODO: memory64 the data type of ptr_len and argc depends on
* mem idx type */
*(uint32 *)argv_dst = arg_i32 = *argv_src++;
if (signature) {
if (signature[i + 1] == '*') {
Expand Down Expand Up @@ -4078,6 +4081,8 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
{
arg_i32 = *argv_src++;

/* TODO: memory64 the data type of ptr_len and argc depends on
* mem idx type */
if (signature) {
if (signature[i + 1] == '*') {
/* param is a pointer */
Expand Down Expand Up @@ -4453,6 +4458,8 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
{
arg_i32 = *argv++;

/* TODO: memory64 the data type of ptr_len and argc depends on
* mem idx type */
if (signature) {
if (signature[i + 1] == '*') {
/* param is a pointer */
Expand Down Expand Up @@ -4768,6 +4775,8 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
{
arg_i32 = *argv_src++;
arg_i64 = arg_i32;
/* TODO: memory64 the data type of ptr_len and argc depends on
* mem idx type */
if (signature) {
if (signature[i + 1] == '*') {
/* param is a pointer */
Expand Down
4 changes: 2 additions & 2 deletions core/iwasm/common/wasm_runtime_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,10 @@ typedef struct WASMModuleMemConsumption {
} WASMModuleMemConsumption;

typedef struct WASMModuleInstMemConsumption {
uint32 total_size;
uint64 total_size;
uint32 module_inst_struct_size;
uint32 memories_size;
uint32 app_heap_size;
uint64 memories_size;
uint32 tables_size;
uint32 globals_size;
uint32 functions_size;
Expand Down
2 changes: 0 additions & 2 deletions core/iwasm/compilation/aot_emit_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,6 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
offset =
LLVMBuildZExt(comp_ctx->builder, offset, I64_TYPE, "extend_offset");
bytes = LLVMBuildZExt(comp_ctx->builder, bytes, I64_TYPE, "extend_len");
mem_size =
LLVMBuildZExt(comp_ctx->builder, mem_size, I64_TYPE, "extend_size");

BUILD_OP(Add, offset, bytes, max_addr, "max_addr");
BUILD_ICMP(LLVMIntUGT, max_addr, mem_size, cmp, "cmp_max_mem_addr");
Expand Down
22 changes: 3 additions & 19 deletions core/iwasm/compilation/aot_emit_variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ compile_global(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMBasicBlockRef block_curr =
LLVMGetInsertBlock(comp_ctx->builder);
LLVMBasicBlockRef check_overflow_succ, check_underflow_succ;
LLVMValueRef cmp, aux_stack_bound, aux_stack_bottom;
LLVMValueRef cmp;

/* Add basic blocks */
if (!(check_overflow_succ = LLVMAppendBasicBlockInContext(
Expand All @@ -271,16 +271,8 @@ compile_global(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMMoveBasicBlockAfter(check_underflow_succ, check_overflow_succ);

/* Check aux stack overflow */

/* TODO: memory64 cast to mem idx type */
if (!(aux_stack_bound = LLVMBuildTruncOrBitCast(
comp_ctx->builder, func_ctx->aux_stack_bound,
TO_LLVM_TYPE(global_type), "aux_stack_bound"))) {
aot_set_last_error("llvm build truncOrBitCast failed.");
return false;
}
if (!(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntULE, global,
aux_stack_bound, "cmp"))) {
func_ctx->aux_stack_bound, "cmp"))) {
aot_set_last_error("llvm build icmp failed.");
return false;
}
Expand All @@ -291,16 +283,8 @@ compile_global(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,

/* Check aux stack underflow */
LLVMPositionBuilderAtEnd(comp_ctx->builder, check_overflow_succ);

/* TODO: memory64 cast to mem idx type */
if (!(aux_stack_bottom = LLVMBuildTruncOrBitCast(
comp_ctx->builder, func_ctx->aux_stack_bottom,
TO_LLVM_TYPE(global_type), "aux_stack_bottom"))) {
aot_set_last_error("llvm build truncOrBitCast failed.");
return false;
}
if (!(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntUGT, global,
aux_stack_bottom, "cmp"))) {
func_ctx->aux_stack_bottom, "cmp"))) {
aot_set_last_error("llvm build icmp failed.");
return false;
}
Expand Down
17 changes: 16 additions & 1 deletion core/iwasm/compilation/aot_llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1011,10 +1011,17 @@ create_aux_stack_info(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)

if (!(func_ctx->aux_stack_bound =
LLVMBuildLoad2(comp_ctx->builder, INTPTR_T_TYPE,
aux_stack_bound_addr, "aux_stack_bound"))) {
aux_stack_bound_addr, "aux_stack_bound_intptr"))) {
aot_set_last_error("llvm build load failed");
return false;
}
/* TODO: Memory64 the actual type depends on mem_idx type */
if (!(func_ctx->aux_stack_bound = LLVMBuildTruncOrBitCast(
comp_ctx->builder, func_ctx->aux_stack_bound, I32_TYPE,
"aux_stack_bound_mem_idx_type"))) {
aot_set_last_error("llvm build truncOrBitCast failed.");
return false;
}

/* Get aux stack bottom address */
if (!(aux_stack_bottom_addr = LLVMBuildInBoundsGEP2(
Expand All @@ -1030,12 +1037,20 @@ create_aux_stack_info(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
aot_set_last_error("llvm build bit cast failed");
return false;
}

if (!(func_ctx->aux_stack_bottom =
LLVMBuildLoad2(comp_ctx->builder, INTPTR_T_TYPE,
aux_stack_bottom_addr, "aux_stack_bottom"))) {
aot_set_last_error("llvm build load failed");
return false;
}
/* TODO: Memory64 the actual type depends on mem_idx type */
if (!(func_ctx->aux_stack_bottom = LLVMBuildTruncOrBitCast(
comp_ctx->builder, func_ctx->aux_stack_bottom, I32_TYPE,
"aux_stack_bottom_mem_idx_type"))) {
aot_set_last_error("llvm build truncOrBitCast failed.");
return false;
}

return true;
}
Expand Down
3 changes: 2 additions & 1 deletion core/iwasm/fast-jit/fe/jit_emit_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ jit_compile_op_call(JitCompContext *cc, uint32 func_idx, bool tail_call)
func_params[1] = NEW_CONST(I32, false); /* is_str = false */
func_params[2] = argvs[i];
if (signature[i + 2] == '~') {
/* TODO: Memory64 no need to convert if mem idx type i64 */
func_params[3] = jit_cc_new_reg_I64(cc);
/* pointer with length followed */
GEN_INSN(I32TOI64, func_params[3], argvs[i + 1]);
Expand All @@ -350,7 +351,7 @@ jit_compile_op_call(JitCompContext *cc, uint32 func_idx, bool tail_call)

if (is_pointer_arg) {
JitReg native_addr_64 = jit_cc_new_reg_I64(cc);
/* TODO: Memory64 no need to convert if mem idx type is i64 */
/* TODO: Memory64 no need to convert if mem idx type i64 */
GEN_INSN(I32TOI64, native_addr_64, func_params[2]);
func_params[2] = native_addr_64;

Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/fast-jit/fe/jit_emit_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ wasm_init_memory(WASMModuleInstance *inst, uint32 mem_idx, uint32 seg_idx,
goto out_of_bounds;

mem_addr = mem_inst->memory_data + mem_offset;
bh_memcpy_s(mem_addr, (uint32)mem_size - mem_offset, data_addr, len);
bh_memcpy_s(mem_addr, (uint32)(mem_size - mem_offset), data_addr, len);

return 0;
out_of_bounds:
Expand Down
9 changes: 0 additions & 9 deletions core/iwasm/fast-jit/jit_frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,15 @@ JitReg
get_aux_stack_bound_reg(JitFrame *frame)
{
JitCompContext *cc = frame->cc;
#if UINTPTR_MAX == UINT64_MAX
JitReg tmp = jit_cc_new_reg_I32(cc);
#endif

if (!frame->aux_stack_bound_reg) {
frame->aux_stack_bound_reg = cc->aux_stack_bound_reg;
GEN_INSN(LDPTR, frame->aux_stack_bound_reg, cc->exec_env_reg,
NEW_CONST(I32, offsetof(WASMExecEnv, aux_stack_boundary)));
#if UINTPTR_MAX == UINT64_MAX
/* TODO: Memory64 whether to convert depends on memory idx type */
GEN_INSN(I64TOI32, tmp, frame->aux_stack_bound_reg);
frame->aux_stack_bound_reg = tmp;
#endif
}
return frame->aux_stack_bound_reg;
}
Expand All @@ -215,19 +211,15 @@ JitReg
get_aux_stack_bottom_reg(JitFrame *frame)
{
JitCompContext *cc = frame->cc;
#if UINTPTR_MAX == UINT64_MAX
JitReg tmp = jit_cc_new_reg_I32(cc);
#endif

if (!frame->aux_stack_bottom_reg) {
frame->aux_stack_bottom_reg = cc->aux_stack_bottom_reg;
GEN_INSN(LDPTR, frame->aux_stack_bottom_reg, cc->exec_env_reg,
NEW_CONST(I32, offsetof(WASMExecEnv, aux_stack_bottom)));
#if UINTPTR_MAX == UINT64_MAX
/* TODO: Memory64 whether to convert depends on memory idx type */
GEN_INSN(I64TOI32, tmp, frame->aux_stack_bottom_reg);
frame->aux_stack_bottom_reg = tmp;
#endif
}
return frame->aux_stack_bottom_reg;
}
Expand Down Expand Up @@ -929,7 +921,6 @@ create_fixed_virtual_regs(JitCompContext *cc)
cc->import_func_ptrs_reg = jit_cc_new_reg_ptr(cc);
cc->fast_jit_func_ptrs_reg = jit_cc_new_reg_ptr(cc);
cc->func_type_indexes_reg = jit_cc_new_reg_ptr(cc);
// uintptr type
cc->aux_stack_bound_reg = jit_cc_new_reg_ptr(cc);
cc->aux_stack_bottom_reg = jit_cc_new_reg_ptr(cc);

Expand Down
5 changes: 3 additions & 2 deletions core/iwasm/interpreter/wasm_interp_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -4088,6 +4088,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
bh_assert(global_idx < module->e->global_count);
global = globals + global_idx;
global_addr = get_global_addr(global_data, global);
/* TODO: Memory64 the data type depends on mem idx type */
aux_stack_top = (uint64)(*(uint32 *)(frame_sp - 1));
if (aux_stack_top <= (uint64)exec_env->aux_stack_boundary) {
wasm_set_exception(module, "wasm auxiliary stack overflow");
Expand Down Expand Up @@ -5488,8 +5489,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
#endif

/* allowing the destination and source to overlap */
bh_memmove_s(mdst, (uint32)linear_mem_size - dst, msrc,
len);
bh_memmove_s(mdst, (uint32)(linear_mem_size - dst),
msrc, len);
break;
}
case WASM_OP_MEMORY_FILL:
Expand Down
1 change: 1 addition & 0 deletions core/iwasm/interpreter/wasm_interp_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -3530,6 +3530,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
bh_assert(global_idx < module->e->global_count);
global = globals + global_idx;
global_addr = get_global_addr(global_data, global);
/* TODO: Memory64 the data type depends on mem idx type */
aux_stack_top = (uint64)frame_lp[GET_OFFSET()];
if (aux_stack_top <= (uint64)exec_env->aux_stack_boundary) {
wasm_set_exception(module, "wasm auxiliary stack overflow");
Expand Down
8 changes: 5 additions & 3 deletions core/iwasm/interpreter/wasm_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -3410,12 +3410,13 @@ wasm_module_dup_data(WASMModuleInstance *module_inst, const char *src,
uint64 size)
{
char *buffer;
uint64 buffer_offset =
wasm_module_malloc(module_inst, size, (void **)&buffer);
uint64 buffer_offset;

/* TODO: Memory64 size check based on memory idx type */
bh_assert(size <= UINT32_MAX);

buffer_offset = wasm_module_malloc(module_inst, size, (void **)&buffer);

if (buffer_offset != 0) {
buffer = wasm_runtime_addr_app_to_native(
(WASMModuleInstanceCommon *)module_inst, buffer_offset);
Expand Down Expand Up @@ -3677,7 +3678,8 @@ void
wasm_get_module_inst_mem_consumption(const WASMModuleInstance *module_inst,
WASMModuleInstMemConsumption *mem_conspn)
{
uint32 i, size;
uint32 i;
uint64 size;

memset(mem_conspn, 0, sizeof(*mem_conspn));

Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/interpreter/wasm_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct WASMMemoryInstance {
/* Whether the memory is shared */
uint8 is_shared_memory;

/* TODO: Memory64 whether the memory is 64-bit memory addresses */
/* TODO: Memory64 whether the memory has 64-bit memory addresses */
uint8 is_memory64;

/* Reference count of the memory instance:
Expand Down
3 changes: 2 additions & 1 deletion core/iwasm/libraries/thread-mgr/thread_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,8 @@ wasm_cluster_destroy_spawned_exec_env(WASMExecEnv *exec_env)
}

/* Free aux stack space */
wasm_cluster_free_aux_stack(exec_env_tls, (uint64)exec_env->aux_stack_bottom);
wasm_cluster_free_aux_stack(exec_env_tls,
(uint64)exec_env->aux_stack_bottom);

os_mutex_lock(&cluster->lock);

Expand Down

0 comments on commit 0a3ae63

Please sign in to comment.