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:
Wenyong Huang
2024-03-12 11:38:50 +08:00
committed by GitHub
parent b6216a5f8a
commit 0ee5ffce85
46 changed files with 1006 additions and 754 deletions

View File

@ -93,6 +93,9 @@ extern "C" {
#define DEFAULT_NUM_BYTES_PER_PAGE 65536
#define DEFAULT_MAX_PAGES 65536
/* Max size of linear memory */
#define MAX_LINEAR_MEMORY_SIZE (4 * (uint64)BH_GB)
#if WASM_ENABLE_GC == 0
typedef uintptr_t table_elem_type_t;
#define NULL_REF (0xFFFFFFFF)
@ -870,19 +873,19 @@ struct WASMModule {
-1 means unexported */
uint32 aux_data_end_global_index;
/* auxiliary __data_end exported by wasm app */
uint32 aux_data_end;
uint64 aux_data_end;
/* the index of auxiliary __heap_base global,
-1 means unexported */
uint32 aux_heap_base_global_index;
/* auxiliary __heap_base exported by wasm app */
uint32 aux_heap_base;
uint64 aux_heap_base;
/* the index of auxiliary stack top global,
-1 means unexported */
uint32 aux_stack_top_global_index;
/* auxiliary stack bottom resolved */
uint32 aux_stack_bottom;
uint64 aux_stack_bottom;
/* auxiliary stack size resolved */
uint32 aux_stack_size;
@ -1091,6 +1094,21 @@ align_uint(unsigned v, unsigned b)
return (v + m) & ~m;
}
/**
* Align an 64 bit unsigned value on a alignment boundary.
*
* @param v the value to be aligned
* @param b the alignment boundary (2, 4, 8, ...)
*
* @return the aligned value
*/
inline static uint64
align_uint64(uint64 v, uint64 b)
{
uint64 m = b - 1;
return (v + m) & ~m;
}
/**
* Check whether a piece of data is out of range
*

View File

@ -48,28 +48,26 @@ typedef float64 CellType_F64;
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
#define CHECK_MEMORY_OVERFLOW(bytes) \
do { \
uint64 offset1 = (uint64)offset + (uint64)addr; \
if (disable_bounds_checks \
|| offset1 + bytes <= (uint64)get_linear_mem_size()) \
/* If offset1 is in valid range, maddr must also \
be in valid range, no need to check it again. */ \
maddr = memory->memory_data + offset1; \
else \
goto out_of_bounds; \
#define CHECK_MEMORY_OVERFLOW(bytes) \
do { \
uint64 offset1 = (uint64)offset + (uint64)addr; \
if (disable_bounds_checks || offset1 + bytes <= get_linear_mem_size()) \
/* If offset1 is in valid range, maddr must also \
be in valid range, no need to check it again. */ \
maddr = memory->memory_data + offset1; \
else \
goto out_of_bounds; \
} while (0)
#define CHECK_BULK_MEMORY_OVERFLOW(start, bytes, maddr) \
do { \
uint64 offset1 = (uint32)(start); \
if (disable_bounds_checks \
|| offset1 + bytes <= (uint64)get_linear_mem_size()) \
/* App heap space is not valid space for \
bulk memory operation */ \
maddr = memory->memory_data + offset1; \
else \
goto out_of_bounds; \
#define CHECK_BULK_MEMORY_OVERFLOW(start, bytes, maddr) \
do { \
uint64 offset1 = (uint32)(start); \
if (disable_bounds_checks || offset1 + bytes <= get_linear_mem_size()) \
/* App heap space is not valid space for \
bulk memory operation */ \
maddr = memory->memory_data + offset1; \
else \
goto out_of_bounds; \
} while (0)
#else
#define CHECK_MEMORY_OVERFLOW(bytes) \
@ -1211,8 +1209,8 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
uint8 *ip = prev_frame->ip;
char buf[128];
WASMExecEnv *sub_module_exec_env = NULL;
uint32 aux_stack_origin_boundary = 0;
uint32 aux_stack_origin_bottom = 0;
uintptr_t aux_stack_origin_boundary = 0;
uintptr_t aux_stack_origin_bottom = 0;
if (!sub_func_inst) {
snprintf(buf, sizeof(buf),
@ -1235,13 +1233,11 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
wasm_exec_env_set_module_inst(exec_env,
(WASMModuleInstanceCommon *)sub_module_inst);
/* - aux_stack_boundary */
aux_stack_origin_boundary = exec_env->aux_stack_boundary.boundary;
exec_env->aux_stack_boundary.boundary =
sub_module_exec_env->aux_stack_boundary.boundary;
aux_stack_origin_boundary = exec_env->aux_stack_boundary;
exec_env->aux_stack_boundary = sub_module_exec_env->aux_stack_boundary;
/* - aux_stack_bottom */
aux_stack_origin_bottom = exec_env->aux_stack_bottom.bottom;
exec_env->aux_stack_bottom.bottom =
sub_module_exec_env->aux_stack_bottom.bottom;
aux_stack_origin_bottom = exec_env->aux_stack_bottom;
exec_env->aux_stack_bottom = sub_module_exec_env->aux_stack_bottom;
/* set ip NULL to make call_func_bytecode return after executing
this function */
@ -1253,8 +1249,8 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
/* restore ip and other replaced */
prev_frame->ip = ip;
exec_env->aux_stack_boundary.boundary = aux_stack_origin_boundary;
exec_env->aux_stack_bottom.bottom = aux_stack_origin_bottom;
exec_env->aux_stack_boundary = aux_stack_origin_boundary;
exec_env->aux_stack_bottom = aux_stack_origin_bottom;
wasm_exec_env_restore_module_inst(exec_env,
(WASMModuleInstanceCommon *)module_inst);
}
@ -1374,7 +1370,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
|| WASM_ENABLE_BULK_MEMORY != 0
uint32 linear_mem_size = 0;
uint64 linear_mem_size = 0;
if (memory)
#if WASM_ENABLE_THREAD_MGR == 0
linear_mem_size = memory->memory_data_size;
@ -4086,18 +4082,19 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
HANDLE_OP(WASM_OP_SET_GLOBAL_AUX_STACK)
{
uint32 aux_stack_top;
uint64 aux_stack_top;
read_leb_uint32(frame_ip, frame_ip_end, global_idx);
bh_assert(global_idx < module->e->global_count);
global = globals + global_idx;
global_addr = get_global_addr(global_data, global);
aux_stack_top = *(uint32 *)(frame_sp - 1);
if (aux_stack_top <= exec_env->aux_stack_boundary.boundary) {
/* 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");
goto got_exception;
}
if (aux_stack_top > exec_env->aux_stack_bottom.bottom) {
if (aux_stack_top > (uint64)exec_env->aux_stack_bottom) {
wasm_set_exception(module,
"wasm auxiliary stack underflow");
goto got_exception;
@ -4106,8 +4103,9 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
frame_sp--;
#if WASM_ENABLE_MEMORY_PROFILING != 0
if (module->module->aux_stack_top_global_index != (uint32)-1) {
uint32 aux_stack_used = module->module->aux_stack_bottom
- *(uint32 *)global_addr;
uint32 aux_stack_used =
(uint32)(module->module->aux_stack_bottom
- *(uint32 *)global_addr);
if (aux_stack_used > module->e->max_aux_stack_used)
module->e->max_aux_stack_used = aux_stack_used;
}
@ -5491,7 +5489,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
#endif
/* allowing the destination and source to overlap */
bh_memmove_s(mdst, linear_mem_size - dst, msrc, len);
bh_memmove_s(mdst, (uint32)(linear_mem_size - dst),
msrc, len);
break;
}
case WASM_OP_MEMORY_FILL:
@ -5511,7 +5510,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
#ifndef OS_ENABLE_HW_BOUND_CHECK
CHECK_BULK_MEMORY_OVERFLOW(dst, len, mdst);
#else
if ((uint64)(uint32)dst + len > (uint64)linear_mem_size)
if ((uint64)(uint32)dst + len > linear_mem_size)
goto out_of_bounds;
mdst = memory->memory_data + (uint32)dst;
#endif

View File

@ -39,16 +39,15 @@ typedef float64 CellType_F64;
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0
#define CHECK_MEMORY_OVERFLOW(bytes) \
do { \
uint64 offset1 = (uint64)offset + (uint64)addr; \
if (disable_bounds_checks \
|| offset1 + bytes <= (uint64)get_linear_mem_size()) \
/* If offset1 is in valid range, maddr must also \
be in valid range, no need to check it again. */ \
maddr = memory->memory_data + offset1; \
else \
goto out_of_bounds; \
#define CHECK_MEMORY_OVERFLOW(bytes) \
do { \
uint64 offset1 = (uint64)offset + (uint64)addr; \
if (disable_bounds_checks || offset1 + bytes <= get_linear_mem_size()) \
/* If offset1 is in valid range, maddr must also \
be in valid range, no need to check it again. */ \
maddr = memory->memory_data + offset1; \
else \
goto out_of_bounds; \
} while (0)
#define CHECK_BULK_MEMORY_OVERFLOW(start, bytes, maddr) \
@ -1274,8 +1273,8 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
uint8 *ip = prev_frame->ip;
char buf[128];
WASMExecEnv *sub_module_exec_env = NULL;
uint32 aux_stack_origin_boundary = 0;
uint32 aux_stack_origin_bottom = 0;
uintptr_t aux_stack_origin_boundary = 0;
uintptr_t aux_stack_origin_bottom = 0;
if (!sub_func_inst) {
snprintf(buf, sizeof(buf),
@ -1298,13 +1297,11 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
wasm_exec_env_set_module_inst(exec_env,
(WASMModuleInstanceCommon *)sub_module_inst);
/* - aux_stack_boundary */
aux_stack_origin_boundary = exec_env->aux_stack_boundary.boundary;
exec_env->aux_stack_boundary.boundary =
sub_module_exec_env->aux_stack_boundary.boundary;
aux_stack_origin_boundary = exec_env->aux_stack_boundary;
exec_env->aux_stack_boundary = sub_module_exec_env->aux_stack_boundary;
/* - aux_stack_bottom */
aux_stack_origin_bottom = exec_env->aux_stack_bottom.bottom;
exec_env->aux_stack_bottom.bottom =
sub_module_exec_env->aux_stack_bottom.bottom;
aux_stack_origin_bottom = exec_env->aux_stack_bottom;
exec_env->aux_stack_bottom = sub_module_exec_env->aux_stack_bottom;
/* set ip NULL to make call_func_bytecode return after executing
this function */
@ -1316,8 +1313,8 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
/* restore ip and other replaced */
prev_frame->ip = ip;
exec_env->aux_stack_boundary.boundary = aux_stack_origin_boundary;
exec_env->aux_stack_bottom.bottom = aux_stack_origin_bottom;
exec_env->aux_stack_boundary = aux_stack_origin_boundary;
exec_env->aux_stack_bottom = aux_stack_origin_bottom;
wasm_exec_env_restore_module_inst(exec_env,
(WASMModuleInstanceCommon *)module_inst);
}
@ -1444,7 +1441,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
#if !defined(OS_ENABLE_HW_BOUND_CHECK) \
|| WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \
|| WASM_ENABLE_BULK_MEMORY != 0
uint32 linear_mem_size = 0;
uint64 linear_mem_size = 0;
if (memory)
#if WASM_ENABLE_THREAD_MGR == 0
linear_mem_size = memory->memory_data_size;
@ -3527,27 +3524,29 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
HANDLE_OP(WASM_OP_SET_GLOBAL_AUX_STACK)
{
uint32 aux_stack_top;
uint64 aux_stack_top;
global_idx = read_uint32(frame_ip);
bh_assert(global_idx < module->e->global_count);
global = globals + global_idx;
global_addr = get_global_addr(global_data, global);
aux_stack_top = frame_lp[GET_OFFSET()];
if (aux_stack_top <= exec_env->aux_stack_boundary.boundary) {
/* 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");
goto got_exception;
}
if (aux_stack_top > exec_env->aux_stack_bottom.bottom) {
if (aux_stack_top > (uint64)exec_env->aux_stack_bottom) {
wasm_set_exception(module,
"wasm auxiliary stack underflow");
goto got_exception;
}
*(int32 *)global_addr = aux_stack_top;
*(int32 *)global_addr = (uint32)aux_stack_top;
#if WASM_ENABLE_MEMORY_PROFILING != 0
if (module->module->aux_stack_top_global_index != (uint32)-1) {
uint32 aux_stack_used = module->module->aux_stack_bottom
- *(uint32 *)global_addr;
uint32 aux_stack_used =
(uint32)(module->module->aux_stack_bottom
- *(uint32 *)global_addr);
if (aux_stack_used > module->e->max_aux_stack_used)
module->e->max_aux_stack_used = aux_stack_used;
}
@ -4968,8 +4967,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
#ifndef OS_ENABLE_HW_BOUND_CHECK
CHECK_BULK_MEMORY_OVERFLOW(addr, bytes, maddr);
#else
if ((uint64)(uint32)addr + bytes
> (uint64)linear_mem_size)
if ((uint64)(uint32)addr + bytes > linear_mem_size)
goto out_of_bounds;
maddr = memory->memory_data + (uint32)addr;
#endif
@ -4987,7 +4985,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
if (offset + bytes > seg_len)
goto out_of_bounds;
bh_memcpy_s(maddr, linear_mem_size - addr,
bh_memcpy_s(maddr, (uint32)(linear_mem_size - addr),
data + offset, (uint32)bytes);
break;
}
@ -5017,17 +5015,18 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
CHECK_BULK_MEMORY_OVERFLOW(src, len, msrc);
CHECK_BULK_MEMORY_OVERFLOW(dst, len, mdst);
#else
if ((uint64)(uint32)src + len > (uint64)linear_mem_size)
if ((uint64)(uint32)src + len > linear_mem_size)
goto out_of_bounds;
msrc = memory->memory_data + (uint32)src;
if ((uint64)(uint32)dst + len > (uint64)linear_mem_size)
if ((uint64)(uint32)dst + len > linear_mem_size)
goto out_of_bounds;
mdst = memory->memory_data + (uint32)dst;
#endif
/* allowing the destination and source to overlap */
bh_memmove_s(mdst, linear_mem_size - dst, msrc, len);
bh_memmove_s(mdst, (uint32)(linear_mem_size - dst),
msrc, len);
break;
}
case WASM_OP_MEMORY_FILL:
@ -5046,7 +5045,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
#ifndef OS_ENABLE_HW_BOUND_CHECK
CHECK_BULK_MEMORY_OVERFLOW(dst, len, mdst);
#else
if ((uint64)(uint32)dst + len > (uint64)linear_mem_size)
if ((uint64)(uint32)dst + len > linear_mem_size)
goto out_of_bounds;
mdst = memory->memory_data + (uint32)dst;
#endif

View File

@ -5597,8 +5597,9 @@ load_from_sections(WASMModule *module, WASMSection *sections,
*buf_func = NULL, *buf_func_end = NULL;
WASMGlobal *aux_data_end_global = NULL, *aux_heap_base_global = NULL;
WASMGlobal *aux_stack_top_global = NULL, *global;
uint32 aux_data_end = (uint32)-1, aux_heap_base = (uint32)-1;
uint32 aux_stack_top = (uint32)-1, global_index, func_index, i;
uint64 aux_data_end = (uint64)-1, aux_heap_base = (uint64)-1,
aux_stack_top = (uint64)-1;
uint32 global_index, func_index, i;
uint32 aux_data_end_global_index = (uint32)-1;
uint32 aux_heap_base_global_index = (uint32)-1;
WASMFuncType *func_type;
@ -5735,7 +5736,7 @@ load_from_sections(WASMModule *module, WASMSection *sections,
&& global->init_expr.init_expr_type
== INIT_EXPR_TYPE_I32_CONST) {
aux_heap_base_global = global;
aux_heap_base = global->init_expr.u.i32;
aux_heap_base = (uint64)(uint32)global->init_expr.u.i32;
aux_heap_base_global_index = export->index;
LOG_VERBOSE("Found aux __heap_base global, value: %d",
aux_heap_base);
@ -5748,12 +5749,12 @@ load_from_sections(WASMModule *module, WASMSection *sections,
&& global->init_expr.init_expr_type
== INIT_EXPR_TYPE_I32_CONST) {
aux_data_end_global = global;
aux_data_end = global->init_expr.u.i32;
aux_data_end = (uint64)(uint32)global->init_expr.u.i32;
aux_data_end_global_index = export->index;
LOG_VERBOSE("Found aux __data_end global, value: %d",
aux_data_end);
aux_data_end = align_uint(aux_data_end, 16);
aux_data_end = align_uint64(aux_data_end, 16);
}
}
@ -5789,16 +5790,17 @@ load_from_sections(WASMModule *module, WASMSection *sections,
&& global->type == VALUE_TYPE_I32
&& global->init_expr.init_expr_type
== INIT_EXPR_TYPE_I32_CONST
&& (uint32)global->init_expr.u.i32 <= aux_heap_base) {
&& (uint64)(uint32)global->init_expr.u.i32
<= aux_heap_base) {
aux_stack_top_global = global;
aux_stack_top = (uint32)global->init_expr.u.i32;
aux_stack_top = (uint64)(uint32)global->init_expr.u.i32;
module->aux_stack_top_global_index =
module->import_global_count + global_index;
module->aux_stack_bottom = aux_stack_top;
module->aux_stack_size =
aux_stack_top > aux_data_end
? aux_stack_top - aux_data_end
: aux_stack_top;
? (uint32)(aux_stack_top - aux_data_end)
: (uint32)aux_stack_top;
LOG_VERBOSE("Found aux stack top global, value: %d, "
"global index: %d, stack size: %d",
aux_stack_top, global_index,
@ -5939,29 +5941,35 @@ load_from_sections(WASMModule *module, WASMSection *sections,
if (aux_data_end_global && aux_heap_base_global
&& aux_stack_top_global) {
uint64 init_memory_size;
uint32 shrunk_memory_size = align_uint(aux_heap_base, 8);
uint64 shrunk_memory_size = align_uint64(aux_heap_base, 8);
if (module->import_memory_count) {
memory_import = &module->import_memories[0].u.memory;
init_memory_size = (uint64)memory_import->num_bytes_per_page
* memory_import->init_page_count;
if (shrunk_memory_size <= init_memory_size) {
/* Reset memory info to decrease memory usage */
memory_import->num_bytes_per_page = shrunk_memory_size;
memory_import->init_page_count = 1;
LOG_VERBOSE("Shrink import memory size to %d",
shrunk_memory_size);
/* Only resize(shrunk) the memory size if num_bytes_per_page is in
* valid range of uint32 */
if (shrunk_memory_size <= UINT32_MAX) {
if (module->import_memory_count) {
memory_import = &module->import_memories[0].u.memory;
init_memory_size = (uint64)memory_import->num_bytes_per_page
* memory_import->init_page_count;
if (shrunk_memory_size <= init_memory_size) {
/* Reset memory info to decrease memory usage */
memory_import->num_bytes_per_page = shrunk_memory_size;
memory_import->init_page_count = 1;
LOG_VERBOSE("Shrink import memory size to %d",
shrunk_memory_size);
}
}
}
if (module->memory_count) {
memory = &module->memories[0];
init_memory_size = (uint64)memory->num_bytes_per_page
* memory->init_page_count;
if (shrunk_memory_size <= init_memory_size) {
/* Reset memory info to decrease memory usage */
memory->num_bytes_per_page = shrunk_memory_size;
memory->init_page_count = 1;
LOG_VERBOSE("Shrink memory size to %d", shrunk_memory_size);
if (module->memory_count) {
memory = &module->memories[0];
init_memory_size = (uint64)memory->num_bytes_per_page
* memory->init_page_count;
if (shrunk_memory_size <= init_memory_size) {
/* Reset memory info to decrease memory usage */
memory->num_bytes_per_page = shrunk_memory_size;
memory->init_page_count = 1;
LOG_VERBOSE("Shrink memory size to %d",
shrunk_memory_size);
}
}
}
}
@ -5969,30 +5977,31 @@ load_from_sections(WASMModule *module, WASMSection *sections,
#if WASM_ENABLE_MULTI_MODULE == 0
if (module->import_memory_count) {
memory_import = &module->import_memories[0].u.memory;
if (memory_import->init_page_count < DEFAULT_MAX_PAGES)
/* Only resize the memory to one big page if num_bytes_per_page is
* in valid range of uint32 */
if (memory_import->init_page_count < DEFAULT_MAX_PAGES) {
memory_import->num_bytes_per_page *=
memory_import->init_page_count;
else
memory_import->num_bytes_per_page = UINT32_MAX;
if (memory_import->init_page_count > 0)
memory_import->init_page_count = memory_import->max_page_count =
1;
else
memory_import->init_page_count = memory_import->max_page_count =
0;
if (memory_import->init_page_count > 0)
memory_import->init_page_count =
memory_import->max_page_count = 1;
else
memory_import->init_page_count =
memory_import->max_page_count = 0;
}
}
if (module->memory_count) {
memory = &module->memories[0];
if (memory->init_page_count < DEFAULT_MAX_PAGES)
/* Only resize(shrunk) the memory size if num_bytes_per_page is in
* valid range of uint32 */
if (memory->init_page_count < DEFAULT_MAX_PAGES) {
memory->num_bytes_per_page *= memory->init_page_count;
else
memory->num_bytes_per_page = UINT32_MAX;
if (memory->init_page_count > 0)
memory->init_page_count = memory->max_page_count = 1;
else
memory->init_page_count = memory->max_page_count = 0;
if (memory->init_page_count > 0)
memory->init_page_count = memory->max_page_count = 1;
else
memory->init_page_count = memory->max_page_count = 0;
}
}
#endif
}

View File

@ -2542,8 +2542,9 @@ load_from_sections(WASMModule *module, WASMSection *sections,
*buf_func = NULL, *buf_func_end = NULL;
WASMGlobal *aux_data_end_global = NULL, *aux_heap_base_global = NULL;
WASMGlobal *aux_stack_top_global = NULL, *global;
uint32 aux_data_end = (uint32)-1, aux_heap_base = (uint32)-1;
uint32 aux_stack_top = (uint32)-1, global_index, func_index, i;
uint64 aux_data_end = (uint64)-1, aux_heap_base = (uint64)-1,
aux_stack_top = (uint64)-1;
uint32 global_index, func_index, i;
uint32 aux_data_end_global_index = (uint32)-1;
uint32 aux_heap_base_global_index = (uint32)-1;
WASMFuncType *func_type;
@ -2661,7 +2662,7 @@ load_from_sections(WASMModule *module, WASMSection *sections,
&& global->init_expr.init_expr_type
== INIT_EXPR_TYPE_I32_CONST) {
aux_heap_base_global = global;
aux_heap_base = global->init_expr.u.i32;
aux_heap_base = (uint64)(uint32)global->init_expr.u.i32;
aux_heap_base_global_index = export->index;
LOG_VERBOSE("Found aux __heap_base global, value: %d",
aux_heap_base);
@ -2674,12 +2675,11 @@ load_from_sections(WASMModule *module, WASMSection *sections,
&& global->init_expr.init_expr_type
== INIT_EXPR_TYPE_I32_CONST) {
aux_data_end_global = global;
aux_data_end = global->init_expr.u.i32;
aux_data_end = (uint64)(uint32)global->init_expr.u.i32;
aux_data_end_global_index = export->index;
LOG_VERBOSE("Found aux __data_end global, value: %d",
aux_data_end);
aux_data_end = align_uint(aux_data_end, 16);
aux_data_end = align_uint64(aux_data_end, 16);
}
}
@ -2715,16 +2715,17 @@ load_from_sections(WASMModule *module, WASMSection *sections,
&& global->type == VALUE_TYPE_I32
&& global->init_expr.init_expr_type
== INIT_EXPR_TYPE_I32_CONST
&& (uint32)global->init_expr.u.i32 <= aux_heap_base) {
&& (uint64)(uint32)global->init_expr.u.i32
<= aux_heap_base) {
aux_stack_top_global = global;
aux_stack_top = (uint32)global->init_expr.u.i32;
aux_stack_top = (uint64)(uint32)global->init_expr.u.i32;
module->aux_stack_top_global_index =
module->import_global_count + global_index;
module->aux_stack_bottom = aux_stack_top;
module->aux_stack_size =
aux_stack_top > aux_data_end
? aux_stack_top - aux_data_end
: aux_stack_top;
? (uint32)(aux_stack_top - aux_data_end)
: (uint32)aux_stack_top;
LOG_VERBOSE("Found aux stack top global, value: %d, "
"global index: %d, stack size: %d",
aux_stack_top, global_index,
@ -2862,60 +2863,62 @@ load_from_sections(WASMModule *module, WASMSection *sections,
if (aux_data_end_global && aux_heap_base_global
&& aux_stack_top_global) {
uint64 init_memory_size;
uint32 shrunk_memory_size = align_uint(aux_heap_base, 8);
uint64 shrunk_memory_size = align_uint64(aux_heap_base, 8);
if (module->import_memory_count) {
memory_import = &module->import_memories[0].u.memory;
init_memory_size = (uint64)memory_import->num_bytes_per_page
* memory_import->init_page_count;
if (shrunk_memory_size <= init_memory_size) {
/* Reset memory info to decrease memory usage */
memory_import->num_bytes_per_page = shrunk_memory_size;
memory_import->init_page_count = 1;
LOG_VERBOSE("Shrink import memory size to %d",
shrunk_memory_size);
/* Only resize(shrunk) the memory size if num_bytes_per_page is in
* valid range of uint32 */
if (shrunk_memory_size <= UINT32_MAX) {
if (module->import_memory_count) {
memory_import = &module->import_memories[0].u.memory;
init_memory_size = (uint64)memory_import->num_bytes_per_page
* memory_import->init_page_count;
if (shrunk_memory_size <= init_memory_size) {
/* Reset memory info to decrease memory usage */
memory_import->num_bytes_per_page = shrunk_memory_size;
memory_import->init_page_count = 1;
LOG_VERBOSE("Shrink import memory size to %d",
shrunk_memory_size);
}
}
}
if (module->memory_count) {
memory = &module->memories[0];
init_memory_size = (uint64)memory->num_bytes_per_page
* memory->init_page_count;
if (shrunk_memory_size <= init_memory_size) {
/* Reset memory info to decrease memory usage */
memory->num_bytes_per_page = shrunk_memory_size;
memory->init_page_count = 1;
LOG_VERBOSE("Shrink memory size to %d", shrunk_memory_size);
if (module->memory_count) {
memory = &module->memories[0];
init_memory_size = (uint64)memory->num_bytes_per_page
* memory->init_page_count;
if (shrunk_memory_size <= init_memory_size) {
/* Reset memory info to decrease memory usage */
memory->num_bytes_per_page = shrunk_memory_size;
memory->init_page_count = 1;
LOG_VERBOSE("Shrink memory size to %d",
shrunk_memory_size);
}
}
}
}
if (module->import_memory_count) {
memory_import = &module->import_memories[0].u.memory;
if (memory_import->init_page_count < DEFAULT_MAX_PAGES)
if (memory_import->init_page_count < DEFAULT_MAX_PAGES) {
memory_import->num_bytes_per_page *=
memory_import->init_page_count;
else
memory_import->num_bytes_per_page = UINT32_MAX;
if (memory_import->init_page_count > 0)
memory_import->init_page_count = memory_import->max_page_count =
1;
else
memory_import->init_page_count = memory_import->max_page_count =
0;
if (memory_import->init_page_count > 0)
memory_import->init_page_count =
memory_import->max_page_count = 1;
else
memory_import->init_page_count =
memory_import->max_page_count = 0;
}
}
if (module->memory_count) {
memory = &module->memories[0];
if (memory->init_page_count < DEFAULT_MAX_PAGES)
if (memory->init_page_count < DEFAULT_MAX_PAGES) {
memory->num_bytes_per_page *= memory->init_page_count;
else
memory->num_bytes_per_page = UINT32_MAX;
if (memory->init_page_count > 0)
memory->init_page_count = memory->max_page_count = 1;
else
memory->init_page_count = memory->max_page_count = 0;
if (memory->init_page_count > 0)
memory->init_page_count = memory->max_page_count = 1;
else
memory->init_page_count = memory->max_page_count = 0;
}
}
}

View File

@ -162,10 +162,11 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
char *error_buf, uint32 error_buf_size)
{
WASMModule *module = module_inst->module;
uint64 memory_data_size, max_memory_data_size;
uint32 heap_offset = num_bytes_per_page * init_page_count;
uint32 inc_page_count, aux_heap_base, global_idx;
uint32 inc_page_count, global_idx;
uint32 bytes_of_last_page, bytes_to_page_end;
uint64 aux_heap_base,
heap_offset = (uint64)num_bytes_per_page * init_page_count;
uint64 memory_data_size, max_memory_data_size;
uint8 *global_addr;
bool is_shared_memory = false;
@ -192,6 +193,15 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
heap_size = 0;
}
/* If initial memory is the largest size allowed, disallowing insert host
* managed heap */
if (heap_size > 0 && heap_offset == MAX_LINEAR_MEMORY_SIZE) {
set_error_buf(error_buf, error_buf_size,
"failed to insert app heap into linear memory, "
"try using `--heap-size=0` option");
return NULL;
}
if (init_page_count == max_page_count && init_page_count == 1) {
/* If only one page and at most one page, we just append
the app heap to the end of linear memory, enlarge the
@ -215,7 +225,7 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
}
else if (module->aux_heap_base_global_index != (uint32)-1
&& module->aux_heap_base
< num_bytes_per_page * init_page_count) {
< (uint64)num_bytes_per_page * init_page_count) {
/* Insert app heap before __heap_base */
aux_heap_base = module->aux_heap_base;
bytes_of_last_page = aux_heap_base % num_bytes_per_page;
@ -243,15 +253,15 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
&& global_idx < module_inst->e->global_count);
global_addr = module_inst->global_data
+ module_inst->e->globals[global_idx].data_offset;
*(uint32 *)global_addr = aux_heap_base;
*(uint32 *)global_addr = (uint32)aux_heap_base;
LOG_VERBOSE("Reset __heap_base global to %u", aux_heap_base);
}
else {
/* Insert app heap before new page */
inc_page_count =
(heap_size + num_bytes_per_page - 1) / num_bytes_per_page;
heap_offset = num_bytes_per_page * init_page_count;
heap_size = num_bytes_per_page * inc_page_count;
heap_offset = (uint64)num_bytes_per_page * init_page_count;
heap_size = (uint64)num_bytes_per_page * inc_page_count;
if (heap_size > 0)
heap_size -= 1 * BH_KB;
}
@ -263,19 +273,9 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
"try using `--heap-size=0` option");
return NULL;
}
else if (init_page_count == DEFAULT_MAX_PAGES) {
num_bytes_per_page = UINT32_MAX;
init_page_count = max_page_count = 1;
}
if (max_page_count > DEFAULT_MAX_PAGES)
max_page_count = DEFAULT_MAX_PAGES;
}
else { /* heap_size == 0 */
if (init_page_count == DEFAULT_MAX_PAGES) {
num_bytes_per_page = UINT32_MAX;
init_page_count = max_page_count = 1;
}
}
LOG_VERBOSE("Memory instantiate:");
LOG_VERBOSE(" page bytes: %u, init pages: %u, max pages: %u",
@ -283,7 +283,7 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
LOG_VERBOSE(" heap offset: %u, heap size: %d\n", heap_offset, heap_size);
max_memory_data_size = (uint64)num_bytes_per_page * max_page_count;
bh_assert(max_memory_data_size <= 4 * (uint64)BH_GB);
bh_assert(max_memory_data_size <= MAX_LINEAR_MEMORY_SIZE);
(void)max_memory_data_size;
bh_assert(memory != NULL);
@ -301,11 +301,11 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
memory->num_bytes_per_page = num_bytes_per_page;
memory->cur_page_count = init_page_count;
memory->max_page_count = max_page_count;
memory->memory_data_size = (uint32)memory_data_size;
memory->memory_data_size = memory_data_size;
memory->heap_data = memory->memory_data + heap_offset;
memory->heap_data_end = memory->heap_data + heap_size;
memory->memory_data_end = memory->memory_data + (uint32)memory_data_size;
memory->memory_data_end = memory->memory_data + memory_data_size;
/* Initialize heap */
if (heap_size > 0) {
@ -3274,27 +3274,30 @@ wasm_get_wasm_func_exec_time(const WASMModuleInstance *inst,
}
#endif /*WASM_ENABLE_PERF_PROFILING != 0*/
uint32
uint64
wasm_module_malloc_internal(WASMModuleInstance *module_inst,
WASMExecEnv *exec_env, uint32 size,
WASMExecEnv *exec_env, uint64 size,
void **p_native_addr)
{
WASMMemoryInstance *memory = wasm_get_default_memory(module_inst);
uint8 *addr = NULL;
uint32 offset = 0;
/* TODO: Memory64 size check based on memory idx type */
bh_assert(size <= UINT32_MAX);
if (!memory) {
wasm_set_exception(module_inst, "uninitialized memory");
return 0;
}
if (memory->heap_handle) {
addr = mem_allocator_malloc(memory->heap_handle, size);
addr = mem_allocator_malloc(memory->heap_handle, (uint32)size);
}
else if (module_inst->e->malloc_function && module_inst->e->free_function) {
if (!execute_malloc_function(
module_inst, exec_env, module_inst->e->malloc_function,
module_inst->e->retain_function, size, &offset)) {
module_inst->e->retain_function, (uint32)size, &offset)) {
return 0;
}
/* If we use app's malloc function,
@ -3317,17 +3320,21 @@ wasm_module_malloc_internal(WASMModuleInstance *module_inst,
if (p_native_addr)
*p_native_addr = addr;
return (uint32)(addr - memory->memory_data);
return (uint64)(addr - memory->memory_data);
}
uint32
uint64
wasm_module_realloc_internal(WASMModuleInstance *module_inst,
WASMExecEnv *exec_env, uint32 ptr, uint32 size,
WASMExecEnv *exec_env, uint64 ptr, uint64 size,
void **p_native_addr)
{
WASMMemoryInstance *memory = wasm_get_default_memory(module_inst);
uint8 *addr = NULL;
/* TODO: Memory64 ptr and size check based on memory idx type */
bh_assert(ptr <= UINT32_MAX);
bh_assert(size <= UINT32_MAX);
if (!memory) {
wasm_set_exception(module_inst, "uninitialized memory");
return 0;
@ -3335,7 +3342,9 @@ wasm_module_realloc_internal(WASMModuleInstance *module_inst,
if (memory->heap_handle) {
addr = mem_allocator_realloc(
memory->heap_handle, ptr ? memory->memory_data + ptr : NULL, size);
memory->heap_handle,
(uint32)ptr ? memory->memory_data + (uint32)ptr : NULL,
(uint32)size);
}
/* Only support realloc in WAMR's app heap */
@ -3354,21 +3363,24 @@ wasm_module_realloc_internal(WASMModuleInstance *module_inst,
if (p_native_addr)
*p_native_addr = addr;
return (uint32)(addr - memory->memory_data);
return (uint64)(addr - memory->memory_data);
}
void
wasm_module_free_internal(WASMModuleInstance *module_inst,
WASMExecEnv *exec_env, uint32 ptr)
WASMExecEnv *exec_env, uint64 ptr)
{
WASMMemoryInstance *memory = wasm_get_default_memory(module_inst);
/* TODO: Memory64 ptr and size check based on memory idx type */
bh_assert(ptr <= UINT32_MAX);
if (!memory) {
return;
}
if (ptr) {
uint8 *addr = memory->memory_data + ptr;
uint8 *addr = memory->memory_data + (uint32)ptr;
uint8 *memory_data_end;
/* memory->memory_data_end may be changed in memory grow */
@ -3384,20 +3396,20 @@ wasm_module_free_internal(WASMModuleInstance *module_inst,
&& module_inst->e->free_function && memory->memory_data <= addr
&& addr < memory_data_end) {
execute_free_function(module_inst, exec_env,
module_inst->e->free_function, ptr);
module_inst->e->free_function, (uint32)ptr);
}
}
}
uint32
wasm_module_malloc(WASMModuleInstance *module_inst, uint32 size,
uint64
wasm_module_malloc(WASMModuleInstance *module_inst, uint64 size,
void **p_native_addr)
{
return wasm_module_malloc_internal(module_inst, NULL, size, p_native_addr);
}
uint32
wasm_module_realloc(WASMModuleInstance *module_inst, uint32 ptr, uint32 size,
uint64
wasm_module_realloc(WASMModuleInstance *module_inst, uint64 ptr, uint64 size,
void **p_native_addr)
{
return wasm_module_realloc_internal(module_inst, NULL, ptr, size,
@ -3405,22 +3417,27 @@ wasm_module_realloc(WASMModuleInstance *module_inst, uint32 ptr, uint32 size,
}
void
wasm_module_free(WASMModuleInstance *module_inst, uint32 ptr)
wasm_module_free(WASMModuleInstance *module_inst, uint64 ptr)
{
wasm_module_free_internal(module_inst, NULL, ptr);
}
uint32
uint64
wasm_module_dup_data(WASMModuleInstance *module_inst, const char *src,
uint32 size)
uint64 size)
{
char *buffer;
uint32 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);
bh_memcpy_s(buffer, size, src, size);
bh_memcpy_s(buffer, (uint32)size, src, (uint32)size);
}
return buffer_offset;
}
@ -3543,7 +3560,7 @@ wasm_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 elem_idx,
#if WASM_ENABLE_THREAD_MGR != 0
bool
wasm_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset, uint32 size)
wasm_set_aux_stack(WASMExecEnv *exec_env, uint64 start_offset, uint32 size)
{
WASMModuleInstance *module_inst =
(WASMModuleInstance *)exec_env->module_inst;
@ -3551,8 +3568,8 @@ wasm_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset, uint32 size)
#if WASM_ENABLE_HEAP_AUX_STACK_ALLOCATION == 0
/* Check the aux stack space */
uint32 data_end = module_inst->module->aux_data_end;
uint32 stack_bottom = module_inst->module->aux_stack_bottom;
uint64 data_end = module_inst->module->aux_data_end;
uint64 stack_bottom = module_inst->module->aux_stack_bottom;
bool is_stack_before_data = stack_bottom < data_end ? true : false;
if ((is_stack_before_data && (size > start_offset))
|| ((!is_stack_before_data) && (start_offset - data_end < size)))
@ -3565,11 +3582,11 @@ wasm_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset, uint32 size)
uint8 *global_addr =
module_inst->global_data
+ module_inst->e->globals[stack_top_idx].data_offset;
*(int32 *)global_addr = start_offset;
*(int32 *)global_addr = (uint32)start_offset;
/* The aux stack boundary is a constant value,
set the value to exec_env */
exec_env->aux_stack_boundary.boundary = start_offset - size;
exec_env->aux_stack_bottom.bottom = start_offset;
exec_env->aux_stack_boundary = (uintptr_t)start_offset - size;
exec_env->aux_stack_bottom = (uintptr_t)start_offset;
return true;
}
@ -3577,14 +3594,14 @@ wasm_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset, uint32 size)
}
bool
wasm_get_aux_stack(WASMExecEnv *exec_env, uint32 *start_offset, uint32 *size)
wasm_get_aux_stack(WASMExecEnv *exec_env, uint64 *start_offset, uint32 *size)
{
WASMModuleInstance *module_inst =
(WASMModuleInstance *)exec_env->module_inst;
/* The aux stack information is resolved in loader
and store in module */
uint32 stack_bottom = module_inst->module->aux_stack_bottom;
uint64 stack_bottom = module_inst->module->aux_stack_bottom;
uint32 total_aux_stack_size = module_inst->module->aux_stack_size;
if (stack_bottom != 0 && total_aux_stack_size != 0) {
@ -3678,7 +3695,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));
@ -3958,7 +3976,7 @@ jit_set_exception_with_id(WASMModuleInstance *module_inst, uint32 id)
bool
jit_check_app_addr_and_convert(WASMModuleInstance *module_inst, bool is_str,
uint32 app_buf_addr, uint32 app_buf_size,
uint64 app_buf_addr, uint64 app_buf_size,
void **p_native_addr)
{
bool ret = wasm_check_app_addr_and_convert(
@ -4104,7 +4122,7 @@ llvm_jit_memory_init(WASMModuleInstance *module_inst, uint32 seg_index,
}
if (!wasm_runtime_validate_app_addr((WASMModuleInstanceCommon *)module_inst,
dst, len))
(uint64)dst, (uint64)len))
return false;
if ((uint64)offset + (uint64)len > seg_len) {
@ -4113,10 +4131,11 @@ llvm_jit_memory_init(WASMModuleInstance *module_inst, uint32 seg_index,
}
maddr = wasm_runtime_addr_app_to_native(
(WASMModuleInstanceCommon *)module_inst, dst);
(WASMModuleInstanceCommon *)module_inst, (uint64)dst);
SHARED_MEMORY_LOCK(memory_inst);
bh_memcpy_s(maddr, memory_inst->memory_data_size - dst, data + offset, len);
bh_memcpy_s(maddr, (uint32)(memory_inst->memory_data_size - dst),
data + offset, len);
SHARED_MEMORY_UNLOCK(memory_inst);
return true;
}

View File

@ -103,13 +103,17 @@ struct WASMMemoryInstance {
/* Whether the memory is shared */
uint8 is_shared_memory;
/* One byte padding */
uint8 __padding__;
/* TODO: Memory64 whether the memory has 64-bit memory addresses */
uint8 is_memory64;
/* Reference count of the memory instance:
0: non-shared memory, > 0: shared memory */
bh_atomic_16_t ref_count;
/* Four-byte paddings to ensure the layout of WASMMemoryInstance is the same
* in both 64-bit and 32-bit */
uint8 __paddings[4];
/* Number bytes per page */
uint32 num_bytes_per_page;
/* Current page count */
@ -117,7 +121,7 @@ struct WASMMemoryInstance {
/* Maximum page count */
uint32 max_page_count;
/* Memory data size */
uint32 memory_data_size;
uint64 memory_data_size;
/**
* Memory data begin address, Note:
* the app-heap might be inserted in to the linear memory,
@ -175,7 +179,8 @@ struct WASMGlobalInstance {
uint8 type;
/* mutable or constant */
bool is_mutable;
/* data offset to base_addr of WASMMemoryInstance */
/* data offset to the address of initial_value, started from the end of
* WASMMemoryInstance(start of WASMGlobalInstance)*/
uint32 data_offset;
/* initial value */
WASMValue initial_value;
@ -577,34 +582,34 @@ wasm_get_exception(WASMModuleInstance *module);
bool
wasm_copy_exception(WASMModuleInstance *module_inst, char *exception_buf);
uint32
uint64
wasm_module_malloc_internal(WASMModuleInstance *module_inst,
WASMExecEnv *exec_env, uint32 size,
WASMExecEnv *exec_env, uint64 size,
void **p_native_addr);
uint32
uint64
wasm_module_realloc_internal(WASMModuleInstance *module_inst,
WASMExecEnv *exec_env, uint32 ptr, uint32 size,
WASMExecEnv *exec_env, uint64 ptr, uint64 size,
void **p_native_addr);
void
wasm_module_free_internal(WASMModuleInstance *module_inst,
WASMExecEnv *exec_env, uint32 ptr);
WASMExecEnv *exec_env, uint64 ptr);
uint32
wasm_module_malloc(WASMModuleInstance *module_inst, uint32 size,
uint64
wasm_module_malloc(WASMModuleInstance *module_inst, uint64 size,
void **p_native_addr);
uint32
wasm_module_realloc(WASMModuleInstance *module_inst, uint32 ptr, uint32 size,
uint64
wasm_module_realloc(WASMModuleInstance *module_inst, uint64 ptr, uint64 size,
void **p_native_addr);
void
wasm_module_free(WASMModuleInstance *module_inst, uint32 ptr);
wasm_module_free(WASMModuleInstance *module_inst, uint64 ptr);
uint32
uint64
wasm_module_dup_data(WASMModuleInstance *module_inst, const char *src,
uint32 size);
uint64 size);
/**
* Check whether the app address and the buf is inside the linear memory,
@ -612,7 +617,7 @@ wasm_module_dup_data(WASMModuleInstance *module_inst, const char *src,
*/
bool
wasm_check_app_addr_and_convert(WASMModuleInstance *module_inst, bool is_str,
uint32 app_buf_addr, uint32 app_buf_size,
uint64 app_buf_addr, uint64 app_buf_size,
void **p_native_addr);
WASMMemoryInstance *
@ -627,10 +632,10 @@ wasm_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 elem_idx,
#if WASM_ENABLE_THREAD_MGR != 0
bool
wasm_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset, uint32 size);
wasm_set_aux_stack(WASMExecEnv *exec_env, uint64 start_offset, uint32 size);
bool
wasm_get_aux_stack(WASMExecEnv *exec_env, uint32 *start_offset, uint32 *size);
wasm_get_aux_stack(WASMExecEnv *exec_env, uint64 *start_offset, uint32 *size);
#endif
void
@ -727,7 +732,7 @@ jit_set_exception_with_id(WASMModuleInstance *module_inst, uint32 id);
*/
bool
jit_check_app_addr_and_convert(WASMModuleInstance *module_inst, bool is_str,
uint32 app_buf_addr, uint32 app_buf_size,
uint64 app_buf_addr, uint64 app_buf_size,
void **p_native_addr);
#endif /* end of WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 \
|| WASM_ENABLE_WAMR_COMPILER != 0 */