diff --git a/core/iwasm/common/wasm_memory.c b/core/iwasm/common/wasm_memory.c index 4f58bbc3..fac6f4af 100644 --- a/core/iwasm/common/wasm_memory.c +++ b/core/iwasm/common/wasm_memory.c @@ -167,3 +167,12 @@ wasm_runtime_free(void *ptr) { wasm_runtime_free_internal(ptr); } + +bool +wasm_runtime_get_mem_alloc_info(mem_alloc_info_t *mem_alloc_info) +{ + if (memory_mode == MEMORY_MODE_POOL) { + return mem_allocator_get_alloc_info(pool_allocator, mem_alloc_info); + } + return false; +} diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index 4beb4d55..f5970ea8 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -121,6 +121,13 @@ typedef union MemAllocOption { } MemAllocOption; #endif +/* Memory pool info */ +typedef struct mem_alloc_info_t { + uint32_t total_size; + uint32_t total_free_size; + uint32_t highmark_size; +} mem_alloc_info_t; + /* WASM runtime initialize arguments */ typedef struct RuntimeInitArgs { mem_alloc_type_t mem_alloc_type; @@ -229,6 +236,12 @@ wasm_runtime_realloc(void *ptr, unsigned int size); WASM_RUNTIME_API_EXTERN void wasm_runtime_free(void *ptr); +/* + * Get memory info, only pool mode is supported now. + */ +WASM_RUNTIME_API_EXTERN bool +wasm_runtime_get_mem_alloc_info(mem_alloc_info_t *mem_alloc_info); + /** * Get the package type of a buffer. * diff --git a/core/shared/mem-alloc/mem_alloc.c b/core/shared/mem-alloc/mem_alloc.c index 16652965..3a3748c4 100644 --- a/core/shared/mem-alloc/mem_alloc.c +++ b/core/shared/mem-alloc/mem_alloc.c @@ -69,6 +69,13 @@ mem_allocator_is_heap_corrupted(mem_allocator_t allocator) return gc_is_heap_corrupted((gc_handle_t)allocator); } +bool +mem_allocator_get_alloc_info(mem_allocator_t allocator, void *mem_alloc_info) +{ + gc_heap_stats((gc_handle_t)allocator, mem_alloc_info, 3); + return true; +} + #else /* else of DEFAULT_MEM_ALLOCATOR */ #include "tlsf/tlsf.h" diff --git a/core/shared/mem-alloc/mem_alloc.h b/core/shared/mem-alloc/mem_alloc.h index d5dc66f1..224eb736 100644 --- a/core/shared/mem-alloc/mem_alloc.h +++ b/core/shared/mem-alloc/mem_alloc.h @@ -45,6 +45,9 @@ mem_allocator_migrate(mem_allocator_t allocator, char *pool_buf_new, bool mem_allocator_is_heap_corrupted(mem_allocator_t allocator); +bool +mem_allocator_get_alloc_info(mem_allocator_t allocator, void *mem_alloc_info); + #ifdef __cplusplus } #endif