From 74dbafc6995a1a4700fcd713ffcdf850b05181fb Mon Sep 17 00:00:00 2001 From: Benbuck Nason Date: Tue, 25 Jun 2024 20:07:16 -0700 Subject: [PATCH] Export API wasm_runtime_enlarge_memory (#3569) Export API wasm_runtime_enlarge_memory to support memory growth. --- core/iwasm/common/wasm_memory.c | 20 ++++++++++++++++++++ core/iwasm/include/wasm_export.h | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/core/iwasm/common/wasm_memory.c b/core/iwasm/common/wasm_memory.c index d86ea4a8..cde2de4d 100644 --- a/core/iwasm/common/wasm_memory.c +++ b/core/iwasm/common/wasm_memory.c @@ -919,6 +919,26 @@ return_func: return ret; } +bool +wasm_runtime_enlarge_memory(WASMModuleInstanceCommon *module_inst, + uint32_t inc_page_count) +{ +#if WASM_ENABLE_AOT != 0 + if (module_inst->module_type == Wasm_Module_AoT) { + return aot_enlarge_memory((AOTModuleInstance *)module_inst, + inc_page_count); + } +#endif +#if WASM_ENABLE_INTERP != 0 + if (module_inst->module_type == Wasm_Module_Bytecode) { + return wasm_enlarge_memory((WASMModuleInstance *)module_inst, + inc_page_count); + } +#endif + + return false; +} + void wasm_runtime_set_enlarge_mem_error_callback( const enlarge_memory_error_callback_t callback, void *user_data) diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index 051408a1..0d5f9572 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -1842,6 +1842,10 @@ WASM_RUNTIME_API_EXTERN bool wasm_runtime_is_import_global_linked(const char *module_name, const char *global_name); +WASM_RUNTIME_API_EXTERN bool +wasm_runtime_enlarge_memory(wasm_module_inst_t module_inst, + uint32_t inc_page_count); + typedef enum { INTERNAL_ERROR, MAX_SIZE_REACHED,