Add memory instance support apis (#3786)
Now that WAMR supports multiple memory instances, this PR adds some APIs to access them in a standard way. This involves moving some existing utility functions out from the `WASM_ENABLE_MULTI_MODULE` blocks they were nested in, but multi-memory and multi-module seem independent as far as I can tell so I assume that's okay. APIs added: ```C wasm_runtime_lookup_memory wasm_runtime_get_default_memory wasm_runtime_get_memory wasm_memory_get_cur_page_count wasm_memory_get_max_page_count wasm_memory_get_bytes_per_page wasm_memory_get_shared wasm_memory_get_base_address wasm_memory_enlarge ```
This commit is contained in:
@ -1058,7 +1058,24 @@ fail1:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static AOTMemoryInstance *
|
||||
AOTMemoryInstance *
|
||||
aot_lookup_memory(AOTModuleInstance *module_inst, char const *name)
|
||||
{
|
||||
#if WASM_ENABLE_MULTI_MEMORY != 0
|
||||
uint32 i;
|
||||
for (i = 0; i < module_inst->export_memory_count; i++)
|
||||
if (!strcmp(module_inst->export_memories[i].name, name))
|
||||
return module_inst->export_memories[i].memory;
|
||||
return NULL;
|
||||
#else
|
||||
(void)module_inst->export_memories;
|
||||
if (!module_inst->memories)
|
||||
return NULL;
|
||||
return module_inst->memories[0];
|
||||
#endif
|
||||
}
|
||||
|
||||
AOTMemoryInstance *
|
||||
aot_get_default_memory(AOTModuleInstance *module_inst)
|
||||
{
|
||||
if (module_inst->memories)
|
||||
@ -1067,6 +1084,14 @@ aot_get_default_memory(AOTModuleInstance *module_inst)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
AOTMemoryInstance *
|
||||
aot_get_memory_with_index(AOTModuleInstance *module_inst, uint32 index)
|
||||
{
|
||||
if ((index >= module_inst->memory_count) || !module_inst->memories)
|
||||
return NULL;
|
||||
return module_inst->memories[index];
|
||||
}
|
||||
|
||||
static bool
|
||||
memories_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
|
||||
AOTModule *module, uint32 heap_size,
|
||||
|
||||
Reference in New Issue
Block a user