From c949f3d2aabdd5af0af756e2c1f1bce41f5d19f8 Mon Sep 17 00:00:00 2001 From: mkolchurin <33422855+mkolchurin@users.noreply.github.com> Date: Wed, 28 Feb 2024 06:18:23 +0300 Subject: [PATCH] zephyr: Implement Alloc_With_System_Allocator (#3179) Add zephyr libc malloc/realloc/free which were introduced since version 1.13.0. --- core/shared/platform/zephyr/zephyr_platform.c | 8 +++++--- product-mini/platforms/zephyr/simple/src/main.c | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/core/shared/platform/zephyr/zephyr_platform.c b/core/shared/platform/zephyr/zephyr_platform.c index e91a4230..156ce537 100644 --- a/core/shared/platform/zephyr/zephyr_platform.c +++ b/core/shared/platform/zephyr/zephyr_platform.c @@ -72,18 +72,20 @@ bh_platform_destroy() void * os_malloc(unsigned size) { - return NULL; + return malloc(size); } void * os_realloc(void *ptr, unsigned size) { - return NULL; + return realloc(ptr, size); } void os_free(void *ptr) -{} +{ + free(ptr); +} int os_dumps_proc_mem_info(char *out, unsigned int size) diff --git a/product-mini/platforms/zephyr/simple/src/main.c b/product-mini/platforms/zephyr/simple/src/main.c index 5d209a86..e70bb5ca 100644 --- a/product-mini/platforms/zephyr/simple/src/main.c +++ b/product-mini/platforms/zephyr/simple/src/main.c @@ -129,8 +129,12 @@ iwasm_main(void *arg1, void *arg2, void *arg3) init_args.mem_alloc_type = Alloc_With_Pool; init_args.mem_alloc_option.pool.heap_buf = global_heap_buf; init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf); +#elif (defined(CONFIG_COMMON_LIBC_MALLOC) \ + && CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE != 0) \ + || defined(CONFIG_NEWLIB_LIBC) + init_args.mem_alloc_type = Alloc_With_System_Allocator; #else -#error Another memory allocation scheme than global heap pool is not implemented yet for Zephyr. +#error "memory allocation scheme is not defined." #endif /* initialize runtime environment */