Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use all free RAM for FreeRTOS heap #2172

Merged
merged 17 commits into from
Dec 9, 2024
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,9 @@ add_definitions(-D__HEAP_SIZE=0)
add_definitions(-DMYNEWT_VAL_BLE_LL_RFMGMT_ENABLE_TIME=1500)
add_definitions(-DLFS_CONFIG=lfs_config.h)

# _sbrk is purposefully not implemented so that builds fail when it is used
add_link_options(-Wl,-wrap=malloc -Wl,-wrap=free -Wl,-wrap=calloc -Wl,-wrap=realloc -Wl,-wrap=_malloc_r -Wl,-wrap=_sbrk)

# Note: Only use this for debugging
# Derive the low frequency clock from the main clock (SYNT)
# add_definitions(-DCLOCK_CONFIG_LF_SRC=2)
Expand Down
31 changes: 24 additions & 7 deletions src/stdlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,40 @@ 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);
(void) num;
mark9064 marked this conversation as resolved.
Show resolved Hide resolved
(void) size;
// Not supported
return NULL;
}

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* _sbrk(int size) {
(void)size;
return *(void **)0; // Force fault
void* __wrap_realloc(void* ptr, size_t newSize) {
return realloc(ptr, newSize);
}
Loading