From b8c51abe691a2d0f6770f4bfef3574541f49d744 Mon Sep 17 00:00:00 2001 From: Felipe Martínez Date: Mon, 9 Dec 2024 01:10:09 +0100 Subject: Use all free RAM for FreeRTOS heap * Use all free RAM for FreeRTOS heap * Wrap newlib malloc and related functions * Implement calloc --- src/stdlib.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'src/stdlib.c') diff --git a/src/stdlib.c b/src/stdlib.c index 3ad66b37..21b506a8 100644 --- a/src/stdlib.c +++ b/src/stdlib.c @@ -1,4 +1,5 @@ #include +#include #include // Override malloc() and free() to use the memory manager from FreeRTOS. @@ -10,18 +11,41 @@ void* malloc(size_t size) { return pvPortMalloc(size); } +void* __wrap_malloc(size_t size) { + return malloc(size); +} + +void* __wrap__malloc_r(struct _reent* reent, size_t size) { + (void) reent; + return malloc(size); +} + void free(void* ptr) { vPortFree(ptr); } +void __wrap_free(void* ptr) { + free(ptr); +} + void* calloc(size_t num, size_t size) { - (void)(num); - (void)(size); - // Not supported - return NULL; + void *ptr = malloc(num * size); + if (ptr) { + memset(ptr, 0, num * size); + } + return ptr; } -void *pvPortRealloc(void *ptr, size_t xWantedSize); -void* realloc( void *ptr, size_t newSize) { +void* __wrap_calloc(size_t num, size_t size) { + return calloc(num, size); +} + +void* pvPortRealloc(void* ptr, size_t xWantedSize); + +void* realloc(void* ptr, size_t newSize) { return pvPortRealloc(ptr, newSize); } + +void* __wrap_realloc(void* ptr, size_t newSize) { + return realloc(ptr, newSize); +} -- cgit v1.2.3-70-g09d2