Refactor APIs and data structures as preliminary work for Memory64 (#3209)
# Change the data type representing linear memory address from u32 to u64
## APIs signature changes
- (Export)wasm_runtime_module_malloc
- wasm_module_malloc
- wasm_module_malloc_internal
- aot_module_malloc
- aot_module_malloc_internal
- wasm_runtime_module_realloc
- wasm_module_realloc
- wasm_module_realloc_internal
- aot_module_realloc
- aot_module_realloc_internal
- (Export)wasm_runtime_module_free
- wasm_module_free
- wasm_module_free_internal
- aot_module_malloc
- aot_module_free_internal
- (Export)wasm_runtime_module_dup_data
- wasm_module_dup_data
- aot_module_dup_data
- (Export)wasm_runtime_validate_app_addr
- (Export)wasm_runtime_validate_app_str_addr
- (Export)wasm_runtime_validate_native_addr
- (Export)wasm_runtime_addr_app_to_native
- (Export)wasm_runtime_addr_native_to_app
- (Export)wasm_runtime_get_app_addr_range
- aot_set_aux_stack
- aot_get_aux_stack
- wasm_set_aux_stack
- wasm_get_aux_stack
- aot_check_app_addr_and_convert, wasm_check_app_addr_and_convert
and jit_check_app_addr_and_convert
- wasm_exec_env_set_aux_stack
- wasm_exec_env_get_aux_stack
- wasm_cluster_create_thread
- wasm_cluster_allocate_aux_stack
- wasm_cluster_free_aux_stack
## Data structure changes
- WASMModule and AOTModule
- field aux_data_end, aux_heap_base and aux_stack_bottom
- WASMExecEnv
- field aux_stack_boundary and aux_stack_bottom
- AOTCompData
- field aux_data_end, aux_heap_base and aux_stack_bottom
- WASMMemoryInstance(AOTMemoryInstance)
- field memory_data_size and change __padding to is_memory64
- WASMModuleInstMemConsumption
- field total_size and memories_size
- WASMDebugExecutionMemory
- field start_offset and current_pos
- WASMCluster
- field stack_tops
## Components that are affected by the APIs and data structure changes
- libc-builtin
- libc-emcc
- libc-uvwasi
- libc-wasi
- Python and Go Language Embedding
- Interpreter Debug engine
- Multi-thread: lib-pthread, wasi-threads and thread manager
This commit is contained in:
@ -316,11 +316,11 @@ typedef struct AOTCompData {
|
||||
uint32 retain_func_index;
|
||||
|
||||
uint32 aux_data_end_global_index;
|
||||
uint32 aux_data_end;
|
||||
uint64 aux_data_end;
|
||||
uint32 aux_heap_base_global_index;
|
||||
uint32 aux_heap_base;
|
||||
uint64 aux_heap_base;
|
||||
uint32 aux_stack_top_global_index;
|
||||
uint32 aux_stack_bottom;
|
||||
uint64 aux_stack_bottom;
|
||||
uint32 aux_stack_size;
|
||||
|
||||
#if WASM_ENABLE_STRINGREF != 0
|
||||
|
||||
@ -850,7 +850,7 @@ get_init_data_section_size(AOTCompContext *comp_ctx, AOTCompData *comp_data,
|
||||
size += (uint32)sizeof(uint32) * 2;
|
||||
|
||||
/* aux data/heap/stack data */
|
||||
size += sizeof(uint32) * 7;
|
||||
size += sizeof(uint32) * 10;
|
||||
|
||||
size += get_object_data_section_info_size(comp_ctx, obj_data);
|
||||
return size;
|
||||
@ -2428,11 +2428,11 @@ aot_emit_init_data_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
|
||||
EMIT_U32(comp_data->start_func_index);
|
||||
|
||||
EMIT_U32(comp_data->aux_data_end_global_index);
|
||||
EMIT_U32(comp_data->aux_data_end);
|
||||
EMIT_U64(comp_data->aux_data_end);
|
||||
EMIT_U32(comp_data->aux_heap_base_global_index);
|
||||
EMIT_U32(comp_data->aux_heap_base);
|
||||
EMIT_U64(comp_data->aux_heap_base);
|
||||
EMIT_U32(comp_data->aux_stack_top_global_index);
|
||||
EMIT_U32(comp_data->aux_stack_bottom);
|
||||
EMIT_U64(comp_data->aux_stack_bottom);
|
||||
EMIT_U32(comp_data->aux_stack_size);
|
||||
|
||||
if (!aot_emit_object_data_section_info(buf, buf_end, &offset, comp_ctx,
|
||||
|
||||
@ -1167,8 +1167,8 @@ check_app_addr_and_convert(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
/* prepare function type of aot_check_app_addr_and_convert */
|
||||
func_param_types[0] = comp_ctx->aot_inst_type; /* module_inst */
|
||||
func_param_types[1] = INT8_TYPE; /* is_str_arg */
|
||||
func_param_types[2] = I32_TYPE; /* app_offset */
|
||||
func_param_types[3] = I32_TYPE; /* buf_size */
|
||||
func_param_types[2] = I64_TYPE; /* app_offset */
|
||||
func_param_types[3] = I64_TYPE; /* buf_size */
|
||||
func_param_types[4] =
|
||||
comp_ctx->basic_types.int8_pptr_type; /* p_native_addr */
|
||||
if (!(func_type =
|
||||
@ -1555,7 +1555,19 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
if (signature[i + 2] == '~')
|
||||
native_addr_size = param_values[i + 2];
|
||||
else
|
||||
native_addr_size = I32_ONE;
|
||||
native_addr_size = I64_CONST(1);
|
||||
if (!(native_addr_size = LLVMBuildZExtOrBitCast(
|
||||
comp_ctx->builder, native_addr_size, I64_TYPE,
|
||||
"native_addr_size_i64"))) {
|
||||
aot_set_last_error("llvm build zextOrBitCast failed.");
|
||||
goto fail;
|
||||
}
|
||||
if (!(param_values[j] = LLVMBuildZExtOrBitCast(
|
||||
comp_ctx->builder, param_values[j], I64_TYPE,
|
||||
"native_addr_i64"))) {
|
||||
aot_set_last_error("llvm build zextOrBitCast failed.");
|
||||
goto fail;
|
||||
}
|
||||
if (!check_app_addr_and_convert(
|
||||
comp_ctx, func_ctx, false, param_values[j],
|
||||
native_addr_size, &native_addr)) {
|
||||
@ -1564,7 +1576,13 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
param_values[j] = native_addr;
|
||||
}
|
||||
else if (signature[i + 1] == '$') {
|
||||
native_addr_size = I32_ZERO;
|
||||
native_addr_size = I64_ZERO;
|
||||
if (!(param_values[j] = LLVMBuildZExtOrBitCast(
|
||||
comp_ctx->builder, param_values[j], I64_TYPE,
|
||||
"native_addr_i64"))) {
|
||||
aot_set_last_error("llvm build zextOrBitCast failed.");
|
||||
goto fail;
|
||||
}
|
||||
if (!check_app_addr_and_convert(
|
||||
comp_ctx, func_ctx, true, param_values[j],
|
||||
native_addr_size, &native_addr)) {
|
||||
|
||||
@ -919,7 +919,7 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
comp_ctx->comp_data->memories[0].num_bytes_per_page;
|
||||
uint32 init_page_count =
|
||||
comp_ctx->comp_data->memories[0].mem_init_page_count;
|
||||
uint32 mem_data_size = num_bytes_per_page * init_page_count;
|
||||
uint64 mem_data_size = (uint64)num_bytes_per_page * init_page_count;
|
||||
if (mem_data_size > 0 && mem_offset + mem_len <= mem_data_size) {
|
||||
/* inside memory space */
|
||||
/* maddr = mem_base_addr + moffset */
|
||||
@ -938,7 +938,7 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
}
|
||||
else {
|
||||
if (!(mem_size = LLVMBuildLoad2(
|
||||
comp_ctx->builder, I32_TYPE,
|
||||
comp_ctx->builder, I64_TYPE,
|
||||
func_ctx->mem_info[0].mem_data_size_addr, "mem_size"))) {
|
||||
aot_set_last_error("llvm build load failed.");
|
||||
goto fail;
|
||||
@ -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");
|
||||
|
||||
@ -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;
|
||||
LLVMValueRef cmp, global_i64;
|
||||
|
||||
/* Add basic blocks */
|
||||
if (!(check_overflow_succ = LLVMAppendBasicBlockInContext(
|
||||
@ -270,8 +270,14 @@ compile_global(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
}
|
||||
LLVMMoveBasicBlockAfter(check_underflow_succ, check_overflow_succ);
|
||||
|
||||
if (!(global_i64 = LLVMBuildZExt(comp_ctx->builder, global,
|
||||
I64_TYPE, "global_i64"))) {
|
||||
aot_set_last_error("llvm build zext failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check aux stack overflow */
|
||||
if (!(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntULE, global,
|
||||
if (!(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntULE, global_i64,
|
||||
func_ctx->aux_stack_bound, "cmp"))) {
|
||||
aot_set_last_error("llvm build icmp failed.");
|
||||
return false;
|
||||
@ -283,7 +289,7 @@ compile_global(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
|
||||
/* Check aux stack underflow */
|
||||
LLVMPositionBuilderAtEnd(comp_ctx->builder, check_overflow_succ);
|
||||
if (!(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntUGT, global,
|
||||
if (!(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntUGT, global_i64,
|
||||
func_ctx->aux_stack_bottom, "cmp"))) {
|
||||
aot_set_last_error("llvm build icmp failed.");
|
||||
return false;
|
||||
|
||||
@ -1004,17 +1004,23 @@ create_aux_stack_info(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||
|
||||
if (!(aux_stack_bound_addr =
|
||||
LLVMBuildBitCast(comp_ctx->builder, aux_stack_bound_addr,
|
||||
INT32_PTR_TYPE, "aux_stack_bound_ptr"))) {
|
||||
INTPTR_T_PTR_TYPE, "aux_stack_bound_ptr"))) {
|
||||
aot_set_last_error("llvm build bit cast failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(func_ctx->aux_stack_bound =
|
||||
LLVMBuildLoad2(comp_ctx->builder, I32_TYPE, aux_stack_bound_addr,
|
||||
"aux_stack_bound"))) {
|
||||
LLVMBuildLoad2(comp_ctx->builder, INTPTR_T_TYPE,
|
||||
aux_stack_bound_addr, "aux_stack_bound_intptr"))) {
|
||||
aot_set_last_error("llvm build load failed");
|
||||
return false;
|
||||
}
|
||||
if (!(func_ctx->aux_stack_bound =
|
||||
LLVMBuildZExt(comp_ctx->builder, func_ctx->aux_stack_bound,
|
||||
I64_TYPE, "aux_stack_bound_i64"))) {
|
||||
aot_set_last_error("llvm build truncOrBitCast failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Get aux stack bottom address */
|
||||
if (!(aux_stack_bottom_addr = LLVMBuildInBoundsGEP2(
|
||||
@ -1026,16 +1032,23 @@ create_aux_stack_info(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||
|
||||
if (!(aux_stack_bottom_addr =
|
||||
LLVMBuildBitCast(comp_ctx->builder, aux_stack_bottom_addr,
|
||||
INT32_PTR_TYPE, "aux_stack_bottom_ptr"))) {
|
||||
INTPTR_T_PTR_TYPE, "aux_stack_bottom_ptr"))) {
|
||||
aot_set_last_error("llvm build bit cast failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(func_ctx->aux_stack_bottom =
|
||||
LLVMBuildLoad2(comp_ctx->builder, I32_TYPE, aux_stack_bottom_addr,
|
||||
"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;
|
||||
}
|
||||
if (!(func_ctx->aux_stack_bottom =
|
||||
LLVMBuildZExt(comp_ctx->builder, func_ctx->aux_stack_bottom,
|
||||
I64_TYPE, "aux_stack_bottom_i64"))) {
|
||||
aot_set_last_error("llvm build truncOrBitCast failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1365,7 +1378,7 @@ create_memory_info(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
}
|
||||
if (!(func_ctx->mem_info[0].mem_data_size_addr = LLVMBuildBitCast(
|
||||
comp_ctx->builder, func_ctx->mem_info[0].mem_data_size_addr,
|
||||
INT32_PTR_TYPE, "mem_data_size_ptr"))) {
|
||||
INT64_PTR_TYPE, "mem_data_size_ptr"))) {
|
||||
aot_set_last_error("llvm build bit cast failed");
|
||||
return false;
|
||||
}
|
||||
@ -1384,7 +1397,7 @@ create_memory_info(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
return false;
|
||||
}
|
||||
if (!(func_ctx->mem_info[0].mem_data_size_addr = LLVMBuildLoad2(
|
||||
comp_ctx->builder, I32_TYPE,
|
||||
comp_ctx->builder, I64_TYPE,
|
||||
func_ctx->mem_info[0].mem_data_size_addr, "mem_data_size"))) {
|
||||
aot_set_last_error("llvm build load failed");
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user