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:
@ -2580,8 +2580,8 @@ wasm_module_imports(const wasm_module_t *module, own wasm_importtype_vec_t *out)
|
||||
+ (i - import_func_count - import_global_count);
|
||||
module_name_rt = import->u.names.module_name;
|
||||
field_name_rt = import->u.names.field_name;
|
||||
min_page = import->u.memory.init_page_count;
|
||||
max_page = import->u.memory.max_page_count;
|
||||
min_page = import->u.memory.mem_type.init_page_count;
|
||||
max_page = import->u.memory.mem_type.max_page_count;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -2592,8 +2592,8 @@ wasm_module_imports(const wasm_module_t *module, own wasm_importtype_vec_t *out)
|
||||
+ (i - import_func_count - import_global_count);
|
||||
module_name_rt = import->module_name;
|
||||
field_name_rt = import->memory_name;
|
||||
min_page = import->mem_init_page_count;
|
||||
max_page = import->mem_max_page_count;
|
||||
min_page = import->mem_type.init_page_count;
|
||||
max_page = import->mem_type.max_page_count;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -4308,12 +4308,12 @@ wasm_memory_new_internal(wasm_store_t *store, uint16 memory_idx_rt,
|
||||
AOTModule *module_aot = (AOTModule *)inst_aot->module;
|
||||
|
||||
if (memory_idx_rt < module_aot->import_memory_count) {
|
||||
min_pages = module_aot->import_memories->mem_init_page_count;
|
||||
max_pages = module_aot->import_memories->mem_max_page_count;
|
||||
min_pages = module_aot->import_memories->mem_type.init_page_count;
|
||||
max_pages = module_aot->import_memories->mem_type.max_page_count;
|
||||
}
|
||||
else {
|
||||
min_pages = module_aot->memories->mem_init_page_count;
|
||||
max_pages = module_aot->memories->mem_max_page_count;
|
||||
min_pages = module_aot->memories->init_page_count;
|
||||
max_pages = module_aot->memories->max_page_count;
|
||||
}
|
||||
init_flag = true;
|
||||
}
|
||||
|
||||
@ -3873,7 +3873,8 @@ wasm_runtime_get_import_type(WASMModuleCommon *const module, int32 import_index,
|
||||
import_type->kind = WASM_IMPORT_EXPORT_KIND_FUNC;
|
||||
import_type->linked =
|
||||
aot_import_func->func_ptr_linked ? true : false;
|
||||
import_type->u.func_type = aot_import_func->func_type;
|
||||
import_type->u.func_type =
|
||||
(WASMFuncType *)aot_import_func->func_type;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -3909,6 +3910,8 @@ wasm_runtime_get_import_type(WASMModuleCommon *const module, int32 import_index,
|
||||
import_type->name = aot_import_memory->memory_name;
|
||||
import_type->kind = WASM_IMPORT_EXPORT_KIND_MEMORY;
|
||||
import_type->linked = false;
|
||||
import_type->u.memory_type =
|
||||
(WASMMemoryType *)&aot_import_memory->mem_type;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -3933,7 +3936,8 @@ wasm_runtime_get_import_type(WASMModuleCommon *const module, int32 import_index,
|
||||
switch (import_type->kind) {
|
||||
case WASM_IMPORT_EXPORT_KIND_FUNC:
|
||||
import_type->linked = wasm_import->u.function.func_ptr_linked;
|
||||
import_type->u.func_type = wasm_import->u.function.func_type;
|
||||
import_type->u.func_type =
|
||||
(WASMFuncType *)wasm_import->u.function.func_type;
|
||||
break;
|
||||
case WASM_IMPORT_EXPORT_KIND_GLOBAL:
|
||||
import_type->linked = wasm_import->u.global.is_linked;
|
||||
@ -3941,12 +3945,12 @@ wasm_runtime_get_import_type(WASMModuleCommon *const module, int32 import_index,
|
||||
(WASMGlobalType *)&wasm_import->u.global.type;
|
||||
break;
|
||||
case WASM_IMPORT_EXPORT_KIND_TABLE:
|
||||
/* not supported */
|
||||
import_type->linked = false;
|
||||
import_type->linked = false; /* not supported */
|
||||
break;
|
||||
case WASM_IMPORT_EXPORT_KIND_MEMORY:
|
||||
/* not supported */
|
||||
import_type->linked = false;
|
||||
import_type->linked = false; /* not supported */
|
||||
import_type->u.memory_type =
|
||||
(WASMMemoryType *)&wasm_import->u.memory.mem_type;
|
||||
break;
|
||||
default:
|
||||
bh_assert(0);
|
||||
@ -4026,12 +4030,11 @@ wasm_runtime_get_export_type(WASMModuleCommon *const module, int32 export_index,
|
||||
.type;
|
||||
break;
|
||||
case WASM_IMPORT_EXPORT_KIND_TABLE:
|
||||
/* not supported */
|
||||
// export_type->linked = false;
|
||||
break;
|
||||
case WASM_IMPORT_EXPORT_KIND_MEMORY:
|
||||
/* not supported */
|
||||
// export_type->linked = false;
|
||||
export_type->u.memory_type =
|
||||
&aot_module->memories[aot_export->index
|
||||
- aot_module->import_memory_count];
|
||||
break;
|
||||
default:
|
||||
bh_assert(0);
|
||||
@ -4068,13 +4071,13 @@ wasm_runtime_get_export_type(WASMModuleCommon *const module, int32 export_index,
|
||||
.type;
|
||||
break;
|
||||
case WASM_IMPORT_EXPORT_KIND_TABLE:
|
||||
/* not supported */
|
||||
// export_type->linked = false;
|
||||
break;
|
||||
case WASM_IMPORT_EXPORT_KIND_MEMORY:
|
||||
/* not supported */
|
||||
// export_type->linked = false;
|
||||
export_type->u.memory_type =
|
||||
&wasm_module->memories[wasm_export->index
|
||||
- wasm_module->import_memory_count];
|
||||
break;
|
||||
default:
|
||||
bh_assert(0);
|
||||
break;
|
||||
}
|
||||
@ -4185,6 +4188,30 @@ wasm_global_type_get_mutable(WASMGlobalType *const global_type)
|
||||
return global_type->is_mutable;
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_memory_type_get_shared(WASMMemoryType *const memory_type)
|
||||
{
|
||||
bh_assert(memory_type);
|
||||
|
||||
return (memory_type->flags & SHARED_MEMORY_FLAG) ? true : false;
|
||||
}
|
||||
|
||||
uint32
|
||||
wasm_memory_type_get_init_page_count(WASMMemoryType *const memory_type)
|
||||
{
|
||||
bh_assert(memory_type);
|
||||
|
||||
return memory_type->init_page_count;
|
||||
}
|
||||
|
||||
uint32
|
||||
wasm_memory_type_get_max_page_count(WASMMemoryType *const memory_type)
|
||||
{
|
||||
bh_assert(memory_type);
|
||||
|
||||
return memory_type->max_page_count;
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_runtime_register_natives(const char *module_name,
|
||||
NativeSymbol *native_symbols,
|
||||
@ -6519,8 +6546,8 @@ wasm_runtime_get_export_memory_type(const WASMModuleCommon *module_comm,
|
||||
if (export->index < module->import_memory_count) {
|
||||
WASMMemoryImport *import_memory =
|
||||
&((module->import_memories + export->index)->u.memory);
|
||||
*out_min_page = import_memory->init_page_count;
|
||||
*out_max_page = import_memory->max_page_count;
|
||||
*out_min_page = import_memory->mem_type.init_page_count;
|
||||
*out_max_page = import_memory->mem_type.max_page_count;
|
||||
}
|
||||
else {
|
||||
WASMMemory *memory =
|
||||
@ -6540,14 +6567,14 @@ wasm_runtime_get_export_memory_type(const WASMModuleCommon *module_comm,
|
||||
if (export->index < module->import_memory_count) {
|
||||
AOTImportMemory *import_memory =
|
||||
module->import_memories + export->index;
|
||||
*out_min_page = import_memory->mem_init_page_count;
|
||||
*out_max_page = import_memory->mem_max_page_count;
|
||||
*out_min_page = import_memory->mem_type.init_page_count;
|
||||
*out_max_page = import_memory->mem_type.max_page_count;
|
||||
}
|
||||
else {
|
||||
AOTMemory *memory = module->memories
|
||||
+ (export->index - module->import_memory_count);
|
||||
*out_min_page = memory->mem_init_page_count;
|
||||
*out_max_page = memory->mem_max_page_count;
|
||||
*out_min_page = memory->init_page_count;
|
||||
*out_max_page = memory->max_page_count;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user