Implement Memory64 support for AOT (#3362)
Refer to: https://github.com/bytecodealliance/wasm-micro-runtime/pull/3266 https://github.com/bytecodealliance/wasm-micro-runtime/issues/3091
This commit is contained in:
@ -1408,19 +1408,23 @@ execute_malloc_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
|
||||
#endif
|
||||
WASMExecEnv *exec_env_created = NULL;
|
||||
WASMModuleInstanceCommon *module_inst_old = NULL;
|
||||
uint32 argv[3], argc;
|
||||
union {
|
||||
uint32 u32[3];
|
||||
uint64 u64;
|
||||
} argv;
|
||||
uint32 argc;
|
||||
bool ret;
|
||||
#if WASM_ENABLE_MEMORY64 != 0
|
||||
bool is_memory64 = module_inst->memories[0]->is_memory64;
|
||||
if (is_memory64) {
|
||||
argc = 2;
|
||||
PUT_I64_TO_ADDR(&argv[0], size);
|
||||
PUT_I64_TO_ADDR(&argv.u64, size);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
argc = 1;
|
||||
argv[0] = (uint32)size;
|
||||
argv.u32[0] = (uint32)size;
|
||||
}
|
||||
|
||||
/* if __retain is exported, then this module is compiled by
|
||||
@ -1431,7 +1435,7 @@ execute_malloc_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
|
||||
/* the malloc function from assemblyscript is:
|
||||
function __new(size: usize, id: u32)
|
||||
id = 0 means this is an ArrayBuffer object */
|
||||
argv[argc] = 0;
|
||||
argv.u32[argc] = 0;
|
||||
argc++;
|
||||
}
|
||||
|
||||
@ -1472,10 +1476,10 @@ execute_malloc_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
|
||||
}
|
||||
}
|
||||
|
||||
ret = wasm_call_function(exec_env, malloc_func, argc, argv);
|
||||
ret = wasm_call_function(exec_env, malloc_func, argc, argv.u32);
|
||||
|
||||
if (retain_func && ret)
|
||||
ret = wasm_call_function(exec_env, retain_func, 1, argv);
|
||||
ret = wasm_call_function(exec_env, retain_func, 1, argv.u32);
|
||||
|
||||
if (module_inst_old)
|
||||
/* Restore the existing exec_env's module inst */
|
||||
@ -1487,11 +1491,11 @@ execute_malloc_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
|
||||
if (ret) {
|
||||
#if WASM_ENABLE_MEMORY64 != 0
|
||||
if (is_memory64)
|
||||
*p_result = GET_I64_FROM_ADDR(&argv[0]);
|
||||
*p_result = GET_I64_FROM_ADDR(&argv.u64);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
*p_result = argv[0];
|
||||
*p_result = argv.u32[0];
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -1506,18 +1510,22 @@ execute_free_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
|
||||
#endif
|
||||
WASMExecEnv *exec_env_created = NULL;
|
||||
WASMModuleInstanceCommon *module_inst_old = NULL;
|
||||
uint32 argv[2], argc;
|
||||
union {
|
||||
uint32 u32[2];
|
||||
uint64 u64;
|
||||
} argv;
|
||||
uint32 argc;
|
||||
bool ret;
|
||||
|
||||
#if WASM_ENABLE_MEMORY64 != 0
|
||||
if (module_inst->memories[0]->is_memory64) {
|
||||
PUT_I64_TO_ADDR(&argv[0], offset);
|
||||
PUT_I64_TO_ADDR(&argv.u64, offset);
|
||||
argc = 2;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
argv[0] = (uint32)offset;
|
||||
argv.u32[0] = (uint32)offset;
|
||||
argc = 1;
|
||||
}
|
||||
|
||||
@ -1558,7 +1566,7 @@ execute_free_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
|
||||
}
|
||||
}
|
||||
|
||||
ret = wasm_call_function(exec_env, free_func, argc, argv);
|
||||
ret = wasm_call_function(exec_env, free_func, argc, argv.u32);
|
||||
|
||||
if (module_inst_old)
|
||||
/* Restore the existing exec_env's module inst */
|
||||
@ -4176,7 +4184,7 @@ fail:
|
||||
#if WASM_ENABLE_BULK_MEMORY != 0
|
||||
bool
|
||||
llvm_jit_memory_init(WASMModuleInstance *module_inst, uint32 seg_index,
|
||||
uint32 offset, uint32 len, uint32 dst)
|
||||
uint32 offset, uint32 len, size_t dst)
|
||||
{
|
||||
WASMMemoryInstance *memory_inst;
|
||||
WASMModule *module;
|
||||
@ -4211,7 +4219,7 @@ llvm_jit_memory_init(WASMModuleInstance *module_inst, uint32 seg_index,
|
||||
(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, CLAMP_U64_TO_U32(memory_inst->memory_data_size - dst),
|
||||
data + offset, len);
|
||||
SHARED_MEMORY_UNLOCK(memory_inst);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user