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:
@ -97,7 +97,7 @@ execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[])
|
||||
uint32 argc1 = 0, argv1[2] = { 0 };
|
||||
uint32 total_argv_size = 0;
|
||||
uint64 total_size;
|
||||
uint32 argv_buf_offset = 0;
|
||||
uint64 argv_buf_offset = 0;
|
||||
int32 i;
|
||||
char *argv_buf, *p, *p_end;
|
||||
uint32 *argv_offsets, module_type;
|
||||
@ -202,7 +202,7 @@ execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[])
|
||||
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(argv_buf_offset = wasm_runtime_module_malloc(
|
||||
module_inst, (uint32)total_size, (void **)&argv_buf))) {
|
||||
module_inst, total_size, (void **)&argv_buf))) {
|
||||
wasm_runtime_set_exception(module_inst, "allocate memory failed");
|
||||
return false;
|
||||
}
|
||||
@ -214,12 +214,13 @@ execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[])
|
||||
for (i = 0; i < argc; i++) {
|
||||
bh_memcpy_s(p, (uint32)(p_end - p), argv[i],
|
||||
(uint32)(strlen(argv[i]) + 1));
|
||||
argv_offsets[i] = argv_buf_offset + (uint32)(p - argv_buf);
|
||||
argv_offsets[i] = (uint32)argv_buf_offset + (uint32)(p - argv_buf);
|
||||
p += strlen(argv[i]) + 1;
|
||||
}
|
||||
|
||||
argc1 = 2;
|
||||
argv1[0] = (uint32)argc;
|
||||
/* TODO: memory64 uint64 when the memory idx is i64 */
|
||||
argv1[1] =
|
||||
(uint32)wasm_runtime_addr_native_to_app(module_inst, argv_offsets);
|
||||
}
|
||||
|
||||
@ -149,9 +149,9 @@ 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;
|
||||
exec_env->aux_stack_bottom.bottom = module->aux_stack_bottom;
|
||||
exec_env->aux_stack_boundary.boundary =
|
||||
module->aux_stack_bottom - module->aux_stack_size;
|
||||
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;
|
||||
#if WASM_ENABLE_GC != 0
|
||||
gc_heap_handle =
|
||||
((WASMModuleInstance *)module_inst)->e->common.gc_heap_pool;
|
||||
@ -163,9 +163,9 @@ wasm_exec_env_create(struct WASMModuleInstanceCommon *module_inst,
|
||||
if (module_inst->module_type == Wasm_Module_AoT) {
|
||||
AOTModule *module =
|
||||
(AOTModule *)((AOTModuleInstance *)module_inst)->module;
|
||||
exec_env->aux_stack_bottom.bottom = module->aux_stack_bottom;
|
||||
exec_env->aux_stack_boundary.boundary =
|
||||
module->aux_stack_bottom - module->aux_stack_size;
|
||||
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;
|
||||
#if WASM_ENABLE_GC != 0
|
||||
gc_heap_handle =
|
||||
((AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst)->e)
|
||||
|
||||
@ -62,16 +62,10 @@ typedef struct WASMExecEnv {
|
||||
WASMSuspendFlags suspend_flags;
|
||||
|
||||
/* Auxiliary stack boundary */
|
||||
union {
|
||||
uint32 boundary;
|
||||
uintptr_t __padding__;
|
||||
} aux_stack_boundary;
|
||||
uintptr_t aux_stack_boundary;
|
||||
|
||||
/* Auxiliary stack bottom */
|
||||
union {
|
||||
uint32 bottom;
|
||||
uintptr_t __padding__;
|
||||
} aux_stack_bottom;
|
||||
uintptr_t aux_stack_bottom;
|
||||
|
||||
#if WASM_ENABLE_AOT != 0
|
||||
/* Native symbol list, reserved */
|
||||
@ -195,8 +189,7 @@ wasm_exec_env_destroy(WASMExecEnv *exec_env);
|
||||
static inline bool
|
||||
wasm_exec_env_is_aux_stack_managed_by_runtime(WASMExecEnv *exec_env)
|
||||
{
|
||||
return exec_env->aux_stack_boundary.boundary != 0
|
||||
|| exec_env->aux_stack_bottom.bottom != 0;
|
||||
return exec_env->aux_stack_boundary != 0 || exec_env->aux_stack_bottom != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -282,7 +282,7 @@ wasm_runtime_get_mem_alloc_info(mem_alloc_info_t *mem_alloc_info)
|
||||
|
||||
bool
|
||||
wasm_runtime_validate_app_addr(WASMModuleInstanceCommon *module_inst_comm,
|
||||
uint32 app_offset, uint32 size)
|
||||
uint64 app_offset, uint64 size)
|
||||
{
|
||||
WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm;
|
||||
WASMMemoryInstance *memory_inst;
|
||||
@ -299,8 +299,9 @@ wasm_runtime_validate_app_addr(WASMModuleInstanceCommon *module_inst_comm,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* integer overflow check */
|
||||
if (app_offset > UINT32_MAX - size) {
|
||||
/* boundary overflow check */
|
||||
if (size > MAX_LINEAR_MEMORY_SIZE
|
||||
|| app_offset > MAX_LINEAR_MEMORY_SIZE - size) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -320,10 +321,10 @@ fail:
|
||||
|
||||
bool
|
||||
wasm_runtime_validate_app_str_addr(WASMModuleInstanceCommon *module_inst_comm,
|
||||
uint32 app_str_offset)
|
||||
uint64 app_str_offset)
|
||||
{
|
||||
WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm;
|
||||
uint32 app_end_offset;
|
||||
uint64 app_end_offset;
|
||||
char *str, *str_end;
|
||||
|
||||
bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode
|
||||
@ -337,6 +338,12 @@ wasm_runtime_validate_app_str_addr(WASMModuleInstanceCommon *module_inst_comm,
|
||||
&app_end_offset))
|
||||
goto fail;
|
||||
|
||||
/* boundary overflow check, max start offset can only be size - 1, while end
|
||||
* offset can be size */
|
||||
if (app_str_offset >= MAX_LINEAR_MEMORY_SIZE
|
||||
|| app_end_offset > MAX_LINEAR_MEMORY_SIZE)
|
||||
goto fail;
|
||||
|
||||
str = wasm_runtime_addr_app_to_native(module_inst_comm, app_str_offset);
|
||||
str_end = str + (app_end_offset - app_str_offset);
|
||||
while (str < str_end && *str != '\0')
|
||||
@ -352,7 +359,7 @@ fail:
|
||||
|
||||
bool
|
||||
wasm_runtime_validate_native_addr(WASMModuleInstanceCommon *module_inst_comm,
|
||||
void *native_ptr, uint32 size)
|
||||
void *native_ptr, uint64 size)
|
||||
{
|
||||
WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm;
|
||||
WASMMemoryInstance *memory_inst;
|
||||
@ -370,8 +377,8 @@ wasm_runtime_validate_native_addr(WASMModuleInstanceCommon *module_inst_comm,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* integer overflow check */
|
||||
if ((uintptr_t)addr > UINTPTR_MAX - size) {
|
||||
/* boundary overflow check */
|
||||
if (size > MAX_LINEAR_MEMORY_SIZE || (uintptr_t)addr > UINTPTR_MAX - size) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -392,7 +399,7 @@ fail:
|
||||
|
||||
void *
|
||||
wasm_runtime_addr_app_to_native(WASMModuleInstanceCommon *module_inst_comm,
|
||||
uint32 app_offset)
|
||||
uint64 app_offset)
|
||||
{
|
||||
WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm;
|
||||
WASMMemoryInstance *memory_inst;
|
||||
@ -411,7 +418,7 @@ wasm_runtime_addr_app_to_native(WASMModuleInstanceCommon *module_inst_comm,
|
||||
|
||||
SHARED_MEMORY_LOCK(memory_inst);
|
||||
|
||||
addr = memory_inst->memory_data + app_offset;
|
||||
addr = memory_inst->memory_data + (uintptr_t)app_offset;
|
||||
|
||||
if (bounds_checks) {
|
||||
if (memory_inst->memory_data <= addr
|
||||
@ -430,7 +437,7 @@ wasm_runtime_addr_app_to_native(WASMModuleInstanceCommon *module_inst_comm,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32
|
||||
uint64
|
||||
wasm_runtime_addr_native_to_app(WASMModuleInstanceCommon *module_inst_comm,
|
||||
void *native_ptr)
|
||||
{
|
||||
@ -438,7 +445,7 @@ wasm_runtime_addr_native_to_app(WASMModuleInstanceCommon *module_inst_comm,
|
||||
WASMMemoryInstance *memory_inst;
|
||||
uint8 *addr = (uint8 *)native_ptr;
|
||||
bool bounds_checks;
|
||||
uint32 ret;
|
||||
uint64 ret;
|
||||
|
||||
bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode
|
||||
|| module_inst_comm->module_type == Wasm_Module_AoT);
|
||||
@ -455,14 +462,14 @@ wasm_runtime_addr_native_to_app(WASMModuleInstanceCommon *module_inst_comm,
|
||||
if (bounds_checks) {
|
||||
if (memory_inst->memory_data <= addr
|
||||
&& addr < memory_inst->memory_data_end) {
|
||||
ret = (uint32)(addr - memory_inst->memory_data);
|
||||
ret = (uint64)(addr - memory_inst->memory_data);
|
||||
SHARED_MEMORY_UNLOCK(memory_inst);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
/* If bounds checks is disabled, return the offset directly */
|
||||
else if (addr != NULL) {
|
||||
ret = (uint32)(addr - memory_inst->memory_data);
|
||||
ret = (uint64)(addr - memory_inst->memory_data);
|
||||
SHARED_MEMORY_UNLOCK(memory_inst);
|
||||
return ret;
|
||||
}
|
||||
@ -473,12 +480,12 @@ wasm_runtime_addr_native_to_app(WASMModuleInstanceCommon *module_inst_comm,
|
||||
|
||||
bool
|
||||
wasm_runtime_get_app_addr_range(WASMModuleInstanceCommon *module_inst_comm,
|
||||
uint32 app_offset, uint32 *p_app_start_offset,
|
||||
uint32 *p_app_end_offset)
|
||||
uint64 app_offset, uint64 *p_app_start_offset,
|
||||
uint64 *p_app_end_offset)
|
||||
{
|
||||
WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm;
|
||||
WASMMemoryInstance *memory_inst;
|
||||
uint32 memory_data_size;
|
||||
uint64 memory_data_size;
|
||||
|
||||
bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode
|
||||
|| module_inst_comm->module_type == Wasm_Module_AoT);
|
||||
@ -541,19 +548,21 @@ wasm_runtime_get_native_addr_range(WASMModuleInstanceCommon *module_inst_comm,
|
||||
|
||||
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 *memory_inst = wasm_get_default_memory(module_inst);
|
||||
uint8 *native_addr;
|
||||
bool bounds_checks;
|
||||
|
||||
bh_assert(app_buf_addr <= UINTPTR_MAX && app_buf_size <= UINTPTR_MAX);
|
||||
|
||||
if (!memory_inst) {
|
||||
wasm_set_exception(module_inst, "out of bounds memory access");
|
||||
return false;
|
||||
}
|
||||
|
||||
native_addr = memory_inst->memory_data + app_buf_addr;
|
||||
native_addr = memory_inst->memory_data + (uintptr_t)app_buf_addr;
|
||||
|
||||
bounds_checks = is_bounds_checks_enabled((wasm_module_inst_t)module_inst);
|
||||
|
||||
@ -695,9 +704,9 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
|
||||
{
|
||||
WASMMemoryInstance *memory = wasm_get_default_memory(module);
|
||||
uint8 *memory_data_old, *memory_data_new, *heap_data_old;
|
||||
uint32 num_bytes_per_page, heap_size, total_size_old = 0;
|
||||
uint32 num_bytes_per_page, heap_size;
|
||||
uint32 cur_page_count, max_page_count, total_page_count;
|
||||
uint64 total_size_new;
|
||||
uint64 total_size_old = 0, total_size_new;
|
||||
bool ret = true, full_size_mmaped;
|
||||
enlarge_memory_error_reason_t failure_reason = INTERNAL_ERROR;
|
||||
|
||||
@ -741,18 +750,12 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
|
||||
goto return_func;
|
||||
}
|
||||
|
||||
bh_assert(total_size_new <= 4 * (uint64)BH_GB);
|
||||
if (total_size_new > UINT32_MAX) {
|
||||
/* Resize to 1 page with size 4G-1 */
|
||||
num_bytes_per_page = UINT32_MAX;
|
||||
total_page_count = max_page_count = 1;
|
||||
total_size_new = UINT32_MAX;
|
||||
}
|
||||
bh_assert(total_size_new <= MAX_LINEAR_MEMORY_SIZE);
|
||||
|
||||
if (full_size_mmaped) {
|
||||
#ifdef BH_PLATFORM_WINDOWS
|
||||
if (!os_mem_commit(memory->memory_data_end,
|
||||
(uint32)total_size_new - total_size_old,
|
||||
(uint32)(total_size_new - total_size_old),
|
||||
MMAP_PROT_READ | MMAP_PROT_WRITE)) {
|
||||
ret = false;
|
||||
goto return_func;
|
||||
@ -760,12 +763,12 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
|
||||
#endif
|
||||
|
||||
if (os_mprotect(memory->memory_data_end,
|
||||
(uint32)total_size_new - total_size_old,
|
||||
(uint32)(total_size_new - total_size_old),
|
||||
MMAP_PROT_READ | MMAP_PROT_WRITE)
|
||||
!= 0) {
|
||||
#ifdef BH_PLATFORM_WINDOWS
|
||||
os_mem_decommit(memory->memory_data_end,
|
||||
(uint32)total_size_new - total_size_old);
|
||||
(uint32)(total_size_new - total_size_old));
|
||||
#endif
|
||||
ret = false;
|
||||
goto return_func;
|
||||
@ -780,9 +783,9 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
|
||||
}
|
||||
}
|
||||
|
||||
if (!(memory_data_new = wasm_mremap_linear_memory(
|
||||
memory_data_old, total_size_old, (uint32)total_size_new,
|
||||
(uint32)total_size_new))) {
|
||||
if (!(memory_data_new =
|
||||
wasm_mremap_linear_memory(memory_data_old, total_size_old,
|
||||
total_size_new, total_size_new))) {
|
||||
ret = false;
|
||||
goto return_func;
|
||||
}
|
||||
@ -811,8 +814,8 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count)
|
||||
memory->num_bytes_per_page = num_bytes_per_page;
|
||||
memory->cur_page_count = total_page_count;
|
||||
memory->max_page_count = max_page_count;
|
||||
SET_LINEAR_MEMORY_SIZE(memory, (uint32)total_size_new);
|
||||
memory->memory_data_end = memory->memory_data + (uint32)total_size_new;
|
||||
SET_LINEAR_MEMORY_SIZE(memory, total_size_new);
|
||||
memory->memory_data_end = memory->memory_data + total_size_new;
|
||||
|
||||
wasm_runtime_set_mem_bound_check_bytes(memory, total_size_new);
|
||||
|
||||
@ -926,7 +929,7 @@ wasm_allocate_linear_memory(uint8 **data, bool is_shared_memory,
|
||||
|
||||
page_size = os_getpagesize();
|
||||
*memory_data_size = init_page_count * num_bytes_per_page;
|
||||
bh_assert(*memory_data_size <= UINT32_MAX);
|
||||
bh_assert(*memory_data_size <= MAX_LINEAR_MEMORY_SIZE);
|
||||
align_as_and_cast(*memory_data_size, page_size);
|
||||
|
||||
if (map_size > 0) {
|
||||
|
||||
@ -9,16 +9,33 @@
|
||||
#include "bh_common.h"
|
||||
#include "../include/wasm_export.h"
|
||||
#include "../interpreter/wasm_runtime.h"
|
||||
#include "../common/wasm_shared_memory.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||
#if WASM_ENABLE_SHARED_MEMORY != 0 && BH_ATOMIC_64_IS_ATOMIC != 0
|
||||
#define GET_LINEAR_MEMORY_SIZE(memory) \
|
||||
BH_ATOMIC_32_LOAD(memory->memory_data_size)
|
||||
BH_ATOMIC_64_LOAD(memory->memory_data_size)
|
||||
#define SET_LINEAR_MEMORY_SIZE(memory, size) \
|
||||
BH_ATOMIC_32_STORE(memory->memory_data_size, size)
|
||||
BH_ATOMIC_64_STORE(memory->memory_data_size, size)
|
||||
#elif WASM_ENABLE_SHARED_MEMORY != 0
|
||||
static inline uint64
|
||||
GET_LINEAR_MEMORY_SIZE(const WASMMemoryInstance *memory)
|
||||
{
|
||||
SHARED_MEMORY_LOCK(memory);
|
||||
uint64 memory_data_size = BH_ATOMIC_64_LOAD(memory->memory_data_size);
|
||||
SHARED_MEMORY_UNLOCK(memory);
|
||||
return memory_data_size;
|
||||
}
|
||||
static inline void
|
||||
SET_LINEAR_MEMORY_SIZE(WASMMemoryInstance *memory, uint64 size)
|
||||
{
|
||||
SHARED_MEMORY_LOCK(memory);
|
||||
BH_ATOMIC_64_STORE(memory->memory_data_size, size);
|
||||
SHARED_MEMORY_UNLOCK(memory);
|
||||
}
|
||||
#else
|
||||
#define GET_LINEAR_MEMORY_SIZE(memory) memory->memory_data_size
|
||||
#define SET_LINEAR_MEMORY_SIZE(memory, size) memory->memory_data_size = size
|
||||
|
||||
@ -1190,7 +1190,7 @@ wasm_runtime_is_built_in_module(const char *module_name)
|
||||
|
||||
#if WASM_ENABLE_THREAD_MGR != 0
|
||||
bool
|
||||
wasm_exec_env_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset,
|
||||
wasm_exec_env_set_aux_stack(WASMExecEnv *exec_env, uint64 start_offset,
|
||||
uint32 size)
|
||||
{
|
||||
WASMModuleInstanceCommon *module_inst =
|
||||
@ -1209,7 +1209,7 @@ wasm_exec_env_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset,
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_exec_env_get_aux_stack(WASMExecEnv *exec_env, uint32 *start_offset,
|
||||
wasm_exec_env_get_aux_stack(WASMExecEnv *exec_env, uint64 *start_offset,
|
||||
uint32 *size)
|
||||
{
|
||||
WASMModuleInstanceCommon *module_inst =
|
||||
@ -1611,11 +1611,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);
|
||||
@ -1650,8 +1650,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
|
||||
@ -2772,9 +2773,9 @@ wasm_runtime_is_bounds_checks_enabled(WASMModuleInstanceCommon *module_inst)
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32
|
||||
uint64
|
||||
wasm_runtime_module_malloc_internal(WASMModuleInstanceCommon *module_inst,
|
||||
WASMExecEnv *exec_env, uint32 size,
|
||||
WASMExecEnv *exec_env, uint64 size,
|
||||
void **p_native_addr)
|
||||
{
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
@ -2790,10 +2791,10 @@ wasm_runtime_module_malloc_internal(WASMModuleInstanceCommon *module_inst,
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32
|
||||
uint64
|
||||
wasm_runtime_module_realloc_internal(WASMModuleInstanceCommon *module_inst,
|
||||
WASMExecEnv *exec_env, uint32 ptr,
|
||||
uint32 size, void **p_native_addr)
|
||||
WASMExecEnv *exec_env, uint64 ptr,
|
||||
uint64 size, void **p_native_addr)
|
||||
{
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
if (module_inst->module_type == Wasm_Module_Bytecode)
|
||||
@ -2810,7 +2811,7 @@ wasm_runtime_module_realloc_internal(WASMModuleInstanceCommon *module_inst,
|
||||
|
||||
void
|
||||
wasm_runtime_module_free_internal(WASMModuleInstanceCommon *module_inst,
|
||||
WASMExecEnv *exec_env, uint32 ptr)
|
||||
WASMExecEnv *exec_env, uint64 ptr)
|
||||
{
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
if (module_inst->module_type == Wasm_Module_Bytecode) {
|
||||
@ -2828,8 +2829,8 @@ wasm_runtime_module_free_internal(WASMModuleInstanceCommon *module_inst,
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32
|
||||
wasm_runtime_module_malloc(WASMModuleInstanceCommon *module_inst, uint32 size,
|
||||
uint64
|
||||
wasm_runtime_module_malloc(WASMModuleInstanceCommon *module_inst, uint64 size,
|
||||
void **p_native_addr)
|
||||
{
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
@ -2845,9 +2846,9 @@ wasm_runtime_module_malloc(WASMModuleInstanceCommon *module_inst, uint32 size,
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32
|
||||
wasm_runtime_module_realloc(WASMModuleInstanceCommon *module_inst, uint32 ptr,
|
||||
uint32 size, void **p_native_addr)
|
||||
uint64
|
||||
wasm_runtime_module_realloc(WASMModuleInstanceCommon *module_inst, uint64 ptr,
|
||||
uint64 size, void **p_native_addr)
|
||||
{
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
if (module_inst->module_type == Wasm_Module_Bytecode)
|
||||
@ -2863,7 +2864,7 @@ wasm_runtime_module_realloc(WASMModuleInstanceCommon *module_inst, uint32 ptr,
|
||||
}
|
||||
|
||||
void
|
||||
wasm_runtime_module_free(WASMModuleInstanceCommon *module_inst, uint32 ptr)
|
||||
wasm_runtime_module_free(WASMModuleInstanceCommon *module_inst, uint64 ptr)
|
||||
{
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
if (module_inst->module_type == Wasm_Module_Bytecode) {
|
||||
@ -2879,9 +2880,9 @@ wasm_runtime_module_free(WASMModuleInstanceCommon *module_inst, uint32 ptr)
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32
|
||||
uint64
|
||||
wasm_runtime_module_dup_data(WASMModuleInstanceCommon *module_inst,
|
||||
const char *src, uint32 size)
|
||||
const char *src, uint64 size)
|
||||
{
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
if (module_inst->module_type == Wasm_Module_Bytecode) {
|
||||
@ -3691,6 +3692,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] == '*') {
|
||||
@ -3702,23 +3705,23 @@ wasm_runtime_invoke_native_raw(WASMExecEnv *exec_env, void *func_ptr,
|
||||
/* pointer without length followed */
|
||||
ptr_len = 1;
|
||||
|
||||
if (!wasm_runtime_validate_app_addr(module, arg_i32,
|
||||
ptr_len))
|
||||
if (!wasm_runtime_validate_app_addr(
|
||||
module, (uint64)arg_i32, (uint64)ptr_len))
|
||||
goto fail;
|
||||
|
||||
*(uintptr_t *)argv_dst =
|
||||
(uintptr_t)wasm_runtime_addr_app_to_native(module,
|
||||
arg_i32);
|
||||
(uintptr_t)wasm_runtime_addr_app_to_native(
|
||||
module, (uint64)arg_i32);
|
||||
}
|
||||
else if (signature[i + 1] == '$') {
|
||||
/* param is a string */
|
||||
if (!wasm_runtime_validate_app_str_addr(module,
|
||||
arg_i32))
|
||||
if (!wasm_runtime_validate_app_str_addr(
|
||||
module, (uint64)arg_i32))
|
||||
goto fail;
|
||||
|
||||
*(uintptr_t *)argv_dst =
|
||||
(uintptr_t)wasm_runtime_addr_app_to_native(module,
|
||||
arg_i32);
|
||||
(uintptr_t)wasm_runtime_addr_app_to_native(
|
||||
module, (uint64)arg_i32);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -4114,6 +4117,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 */
|
||||
@ -4124,21 +4129,21 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
|
||||
/* pointer without length followed */
|
||||
ptr_len = 1;
|
||||
|
||||
if (!wasm_runtime_validate_app_addr(module, arg_i32,
|
||||
ptr_len))
|
||||
if (!wasm_runtime_validate_app_addr(
|
||||
module, (uint64)arg_i32, (uint64)ptr_len))
|
||||
goto fail;
|
||||
|
||||
arg_i32 = (uintptr_t)wasm_runtime_addr_app_to_native(
|
||||
module, arg_i32);
|
||||
module, (uint64)arg_i32);
|
||||
}
|
||||
else if (signature[i + 1] == '$') {
|
||||
/* param is a string */
|
||||
if (!wasm_runtime_validate_app_str_addr(module,
|
||||
arg_i32))
|
||||
if (!wasm_runtime_validate_app_str_addr(
|
||||
module, (uint64)arg_i32))
|
||||
goto fail;
|
||||
|
||||
arg_i32 = (uintptr_t)wasm_runtime_addr_app_to_native(
|
||||
module, arg_i32);
|
||||
module, (uint64)arg_i32);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4489,6 +4494,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 */
|
||||
@ -4499,21 +4506,21 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
|
||||
/* pointer without length followed */
|
||||
ptr_len = 1;
|
||||
|
||||
if (!wasm_runtime_validate_app_addr(module, arg_i32,
|
||||
ptr_len))
|
||||
if (!wasm_runtime_validate_app_addr(
|
||||
module, (uint64)arg_i32, (uint64)ptr_len))
|
||||
goto fail;
|
||||
|
||||
arg_i32 = (uintptr_t)wasm_runtime_addr_app_to_native(
|
||||
module, arg_i32);
|
||||
module, (uint64)arg_i32);
|
||||
}
|
||||
else if (signature[i + 1] == '$') {
|
||||
/* param is a string */
|
||||
if (!wasm_runtime_validate_app_str_addr(module,
|
||||
arg_i32))
|
||||
if (!wasm_runtime_validate_app_str_addr(
|
||||
module, (uint64)arg_i32))
|
||||
goto fail;
|
||||
|
||||
arg_i32 = (uintptr_t)wasm_runtime_addr_app_to_native(
|
||||
module, arg_i32);
|
||||
module, (uint64)arg_i32);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4804,6 +4811,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 */
|
||||
@ -4814,21 +4823,21 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
|
||||
/* pointer without length followed */
|
||||
ptr_len = 1;
|
||||
|
||||
if (!wasm_runtime_validate_app_addr(module, arg_i32,
|
||||
ptr_len))
|
||||
if (!wasm_runtime_validate_app_addr(
|
||||
module, (uint64)arg_i32, (uint64)ptr_len))
|
||||
goto fail;
|
||||
|
||||
arg_i64 = (uintptr_t)wasm_runtime_addr_app_to_native(
|
||||
module, arg_i32);
|
||||
module, (uint64)arg_i32);
|
||||
}
|
||||
else if (signature[i + 1] == '$') {
|
||||
/* param is a string */
|
||||
if (!wasm_runtime_validate_app_str_addr(module,
|
||||
arg_i32))
|
||||
if (!wasm_runtime_validate_app_str_addr(
|
||||
module, (uint64)arg_i32))
|
||||
goto fail;
|
||||
|
||||
arg_i64 = (uintptr_t)wasm_runtime_addr_app_to_native(
|
||||
module, arg_i32);
|
||||
module, (uint64)arg_i32);
|
||||
}
|
||||
}
|
||||
if (n_ints < MAX_REG_INTS)
|
||||
|
||||
@ -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;
|
||||
@ -770,66 +770,66 @@ WASM_RUNTIME_API_EXTERN void *
|
||||
wasm_runtime_get_custom_data(WASMModuleInstanceCommon *module_inst);
|
||||
|
||||
/* Internal API */
|
||||
uint32
|
||||
uint64
|
||||
wasm_runtime_module_malloc_internal(WASMModuleInstanceCommon *module_inst,
|
||||
WASMExecEnv *exec_env, uint32 size,
|
||||
WASMExecEnv *exec_env, uint64 size,
|
||||
void **p_native_addr);
|
||||
|
||||
/* Internal API */
|
||||
uint32
|
||||
uint64
|
||||
wasm_runtime_module_realloc_internal(WASMModuleInstanceCommon *module_inst,
|
||||
WASMExecEnv *exec_env, uint32 ptr,
|
||||
uint32 size, void **p_native_addr);
|
||||
WASMExecEnv *exec_env, uint64 ptr,
|
||||
uint64 size, void **p_native_addr);
|
||||
|
||||
/* Internal API */
|
||||
void
|
||||
wasm_runtime_module_free_internal(WASMModuleInstanceCommon *module_inst,
|
||||
WASMExecEnv *exec_env, uint32 ptr);
|
||||
WASMExecEnv *exec_env, uint64 ptr);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN uint32
|
||||
wasm_runtime_module_malloc(WASMModuleInstanceCommon *module_inst, uint32 size,
|
||||
WASM_RUNTIME_API_EXTERN uint64
|
||||
wasm_runtime_module_malloc(WASMModuleInstanceCommon *module_inst, uint64 size,
|
||||
void **p_native_addr);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN void
|
||||
wasm_runtime_module_free(WASMModuleInstanceCommon *module_inst, uint32 ptr);
|
||||
wasm_runtime_module_free(WASMModuleInstanceCommon *module_inst, uint64 ptr);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN uint32
|
||||
WASM_RUNTIME_API_EXTERN uint64
|
||||
wasm_runtime_module_dup_data(WASMModuleInstanceCommon *module_inst,
|
||||
const char *src, uint32 size);
|
||||
const char *src, uint64 size);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
wasm_runtime_validate_app_addr(WASMModuleInstanceCommon *module_inst,
|
||||
uint32 app_offset, uint32 size);
|
||||
uint64 app_offset, uint64 size);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
wasm_runtime_validate_app_str_addr(WASMModuleInstanceCommon *module_inst,
|
||||
uint32 app_str_offset);
|
||||
uint64 app_str_offset);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
wasm_runtime_validate_native_addr(WASMModuleInstanceCommon *module_inst,
|
||||
void *native_ptr, uint32 size);
|
||||
void *native_ptr, uint64 size);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN void *
|
||||
wasm_runtime_addr_app_to_native(WASMModuleInstanceCommon *module_inst,
|
||||
uint32 app_offset);
|
||||
uint64 app_offset);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN uint32
|
||||
WASM_RUNTIME_API_EXTERN uint64
|
||||
wasm_runtime_addr_native_to_app(WASMModuleInstanceCommon *module_inst,
|
||||
void *native_ptr);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
wasm_runtime_get_app_addr_range(WASMModuleInstanceCommon *module_inst,
|
||||
uint32 app_offset, uint32 *p_app_start_offset,
|
||||
uint32 *p_app_end_offset);
|
||||
uint64 app_offset, uint64 *p_app_start_offset,
|
||||
uint64 *p_app_end_offset);
|
||||
|
||||
/* See wasm_export.h for description */
|
||||
WASM_RUNTIME_API_EXTERN bool
|
||||
@ -916,11 +916,11 @@ wasm_runtime_is_built_in_module(const char *module_name);
|
||||
|
||||
#if WASM_ENABLE_THREAD_MGR != 0
|
||||
bool
|
||||
wasm_exec_env_get_aux_stack(WASMExecEnv *exec_env, uint32 *start_offset,
|
||||
wasm_exec_env_get_aux_stack(WASMExecEnv *exec_env, uint64 *start_offset,
|
||||
uint32 *size);
|
||||
|
||||
bool
|
||||
wasm_exec_env_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset,
|
||||
wasm_exec_env_set_aux_stack(WASMExecEnv *exec_env, uint64 start_offset,
|
||||
uint32 size);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user