aboutsummaryrefslogtreecommitdiffstats
path: root/src/stdlib.c
diff options
context:
space:
mode:
authorFelipe Martínez <felipe@pipe01.net>2024-12-09 01:10:09 +0100
committerGitHub <noreply@github.com>2024-12-09 00:10:09 +0000
commitb8c51abe691a2d0f6770f4bfef3574541f49d744 (patch)
tree0e501734fed33451789943e30aad9be23d8eb3c6 /src/stdlib.c
parent2105a7b63da8d4065ebfc62e0057f225358eedfc (diff)
Use all free RAM for FreeRTOS heap
* Use all free RAM for FreeRTOS heap * Wrap newlib malloc and related functions * Implement calloc
Diffstat (limited to 'src/stdlib.c')
-rw-r--r--src/stdlib.c36
1 files changed, 30 insertions, 6 deletions
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 <stdlib.h>
+#include <string.h>
#include <FreeRTOS.h>
// 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);
+}