Add wasm_export.h APIs to expose memory type (#3496)
Support to get `wasm_memory_type_t memory_type` from API `wasm_runtime_get_import_type` and `wasm_runtime_get_export_type`, and then get shared flag, initial page cout, maximum page count from the memory_type: ```C bool wasm_memory_type_get_shared(const wasm_memory_type_t memory_type); uint32_t wasm_memory_type_get_init_page_count(const wasm_memory_type_t memory_type); uint32_t wasm_memory_type_get_max_page_count(const wasm_memory_type_t memory_type); ```
This commit is contained in:
@ -558,28 +558,24 @@ aot_create_comp_data(WASMModule *module, const char *target_arch,
|
||||
/* Set memory page count */
|
||||
for (i = 0; i < module->import_memory_count + module->memory_count; i++) {
|
||||
if (i < module->import_memory_count) {
|
||||
comp_data->memories[i].memory_flags =
|
||||
module->import_memories[i].u.memory.flags;
|
||||
comp_data->memories[i].flags =
|
||||
module->import_memories[i].u.memory.mem_type.flags;
|
||||
comp_data->memories[i].num_bytes_per_page =
|
||||
module->import_memories[i].u.memory.num_bytes_per_page;
|
||||
comp_data->memories[i].mem_init_page_count =
|
||||
module->import_memories[i].u.memory.init_page_count;
|
||||
comp_data->memories[i].mem_max_page_count =
|
||||
module->import_memories[i].u.memory.max_page_count;
|
||||
comp_data->memories[i].num_bytes_per_page =
|
||||
module->import_memories[i].u.memory.num_bytes_per_page;
|
||||
module->import_memories[i].u.memory.mem_type.num_bytes_per_page;
|
||||
comp_data->memories[i].init_page_count =
|
||||
module->import_memories[i].u.memory.mem_type.init_page_count;
|
||||
comp_data->memories[i].max_page_count =
|
||||
module->import_memories[i].u.memory.mem_type.max_page_count;
|
||||
}
|
||||
else {
|
||||
j = i - module->import_memory_count;
|
||||
comp_data->memories[i].memory_flags = module->memories[j].flags;
|
||||
comp_data->memories[i].flags = module->memories[j].flags;
|
||||
comp_data->memories[i].num_bytes_per_page =
|
||||
module->memories[j].num_bytes_per_page;
|
||||
comp_data->memories[i].mem_init_page_count =
|
||||
comp_data->memories[i].init_page_count =
|
||||
module->memories[j].init_page_count;
|
||||
comp_data->memories[i].mem_max_page_count =
|
||||
comp_data->memories[i].max_page_count =
|
||||
module->memories[j].max_page_count;
|
||||
comp_data->memories[i].num_bytes_per_page =
|
||||
module->memories[j].num_bytes_per_page;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -46,6 +46,8 @@ typedef WASMStructType AOTStructType;
|
||||
typedef WASMArrayType AOTArrayType;
|
||||
#endif
|
||||
typedef WASMExport AOTExport;
|
||||
typedef WASMMemory AOTMemory;
|
||||
typedef WASMMemoryType AOTMemoryType;
|
||||
|
||||
#if WASM_ENABLE_DEBUG_AOT != 0
|
||||
typedef void *dwarf_extractor_handle_t;
|
||||
@ -81,23 +83,9 @@ typedef enum AOTFloatCond {
|
||||
typedef struct AOTImportMemory {
|
||||
char *module_name;
|
||||
char *memory_name;
|
||||
uint32 memory_flags;
|
||||
uint32 num_bytes_per_page;
|
||||
uint32 mem_init_page_count;
|
||||
uint32 mem_max_page_count;
|
||||
AOTMemoryType mem_type;
|
||||
} AOTImportMemory;
|
||||
|
||||
/**
|
||||
* Memory information
|
||||
*/
|
||||
typedef struct AOTMemory {
|
||||
/* memory info */
|
||||
uint32 memory_flags;
|
||||
uint32 num_bytes_per_page;
|
||||
uint32 mem_init_page_count;
|
||||
uint32 mem_max_page_count;
|
||||
} AOTMemory;
|
||||
|
||||
/**
|
||||
* A segment of memory init data
|
||||
*/
|
||||
|
||||
@ -520,8 +520,7 @@ set_local_gc_ref(AOTCompFrame *frame, int n, LLVMValueRef value, uint8 ref_type)
|
||||
} while (0)
|
||||
|
||||
#if WASM_ENABLE_MEMORY64 != 0
|
||||
#define IS_MEMORY64 \
|
||||
(comp_ctx->comp_data->memories[0].memory_flags & MEMORY64_FLAG)
|
||||
#define IS_MEMORY64 (comp_ctx->comp_data->memories[0].flags & MEMORY64_FLAG)
|
||||
#define MEMORY64_COND_VALUE(VAL_IF_ENABLED, VAL_IF_DISABLED) \
|
||||
(IS_MEMORY64 ? VAL_IF_ENABLED : VAL_IF_DISABLED)
|
||||
#else
|
||||
|
||||
@ -189,7 +189,7 @@ get_import_memory_size(AOTCompData *comp_data)
|
||||
static uint32
|
||||
get_memory_size(AOTCompData *comp_data)
|
||||
{
|
||||
/* memory_count + count * (memory_flags + num_bytes_per_page +
|
||||
/* memory_count + count * (flags + num_bytes_per_page +
|
||||
init_page_count + max_page_count) */
|
||||
return (uint32)(sizeof(uint32)
|
||||
+ comp_data->memory_count * sizeof(uint32) * 4);
|
||||
@ -1762,10 +1762,10 @@ aot_emit_mem_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
|
||||
EMIT_U32(comp_data->memory_count);
|
||||
/* Emit memory items */
|
||||
for (i = 0; i < comp_data->memory_count; i++) {
|
||||
EMIT_U32(comp_data->memories[i].memory_flags);
|
||||
EMIT_U32(comp_data->memories[i].flags);
|
||||
EMIT_U32(comp_data->memories[i].num_bytes_per_page);
|
||||
EMIT_U32(comp_data->memories[i].mem_init_page_count);
|
||||
EMIT_U32(comp_data->memories[i].mem_max_page_count);
|
||||
EMIT_U32(comp_data->memories[i].init_page_count);
|
||||
EMIT_U32(comp_data->memories[i].max_page_count);
|
||||
}
|
||||
|
||||
/* Emit mem init data count */
|
||||
|
||||
@ -853,7 +853,7 @@ check_suspend_flags(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
LLVMBasicBlockRef terminate_block, non_terminate_block;
|
||||
AOTFuncType *aot_func_type = func_ctx->aot_func->func_type;
|
||||
bool is_shared_memory =
|
||||
comp_ctx->comp_data->memories[0].memory_flags & 0x02 ? true : false;
|
||||
comp_ctx->comp_data->memories[0].flags & 0x02 ? true : false;
|
||||
|
||||
/* Only need to check the suspend flags when memory is shared since
|
||||
shared memory must be enabled for multi-threading */
|
||||
|
||||
@ -109,7 +109,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
bool is_target_64bit, is_local_of_aot_value = false;
|
||||
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||
bool is_shared_memory =
|
||||
comp_ctx->comp_data->memories[0].memory_flags & SHARED_MEMORY_FLAG;
|
||||
comp_ctx->comp_data->memories[0].flags & SHARED_MEMORY_FLAG;
|
||||
#endif
|
||||
|
||||
is_target_64bit = (comp_ctx->pointer_size == sizeof(uint64)) ? true : false;
|
||||
@ -177,7 +177,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
uint32 num_bytes_per_page =
|
||||
comp_ctx->comp_data->memories[0].num_bytes_per_page;
|
||||
uint32 init_page_count =
|
||||
comp_ctx->comp_data->memories[0].mem_init_page_count;
|
||||
comp_ctx->comp_data->memories[0].init_page_count;
|
||||
uint64 mem_data_size = (uint64)num_bytes_per_page * init_page_count;
|
||||
|
||||
if (mem_offset + bytes <= mem_data_size) {
|
||||
@ -224,7 +224,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
&& aot_checked_addr_list_find(func_ctx, local_idx_of_aot_value,
|
||||
offset, bytes))) {
|
||||
uint32 init_page_count =
|
||||
comp_ctx->comp_data->memories[0].mem_init_page_count;
|
||||
comp_ctx->comp_data->memories[0].init_page_count;
|
||||
if (init_page_count == 0) {
|
||||
LLVMValueRef mem_size;
|
||||
|
||||
@ -932,8 +932,7 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
|
||||
/* Get memory base address and memory data size */
|
||||
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||
bool is_shared_memory =
|
||||
comp_ctx->comp_data->memories[0].memory_flags & 0x02;
|
||||
bool is_shared_memory = comp_ctx->comp_data->memories[0].flags & 0x02;
|
||||
|
||||
if (func_ctx->mem_space_unchanged || is_shared_memory) {
|
||||
#else
|
||||
@ -961,7 +960,7 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
uint32 num_bytes_per_page =
|
||||
comp_ctx->comp_data->memories[0].num_bytes_per_page;
|
||||
uint32 init_page_count =
|
||||
comp_ctx->comp_data->memories[0].mem_init_page_count;
|
||||
comp_ctx->comp_data->memories[0].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 */
|
||||
|
||||
@ -1219,7 +1219,7 @@ create_memory_info(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||
/* Load memory base address */
|
||||
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||
is_shared_memory =
|
||||
comp_ctx->comp_data->memories[0].memory_flags & 0x02 ? true : false;
|
||||
comp_ctx->comp_data->memories[0].flags & 0x02 ? true : false;
|
||||
if (is_shared_memory) {
|
||||
LLVMValueRef shared_mem_addr;
|
||||
offset = I32_CONST(offsetof(AOTModuleInstance, memories));
|
||||
|
||||
Reference in New Issue
Block a user