mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-25 14:22:27 +03:00
1d17206e23
* add tlsf as submodule * libs: tlsf * Furi: tlsf as allocator * Furi: heap walker * shmal fixshesh * f18: tlsf * PVS: ignore tlsf * I like to moving * merge upcoming changes * memmgr: alloc aligned, realloc * Furi: distinct name for auxiliary memory pool * Furi: put idle and timer thread to mem2 * Furi: fix smal things in allocator * Furi: remove aligned_free. Use free instead. * aligned_malloc -> aligned_alloc * aligned_alloc, parameters order * aligned_alloc: check that alignment is correct * unit test: malloc * unit tests: realloc and test with memory fragmentation * unit tests: aligned_alloc * update api * updater: properly read large update file Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
90 lines
2.0 KiB
C
90 lines
2.0 KiB
C
#include "memmgr.h"
|
|
#include "common_defines.h"
|
|
#include <string.h>
|
|
#include <furi_hal_memory.h>
|
|
|
|
extern void* pvPortMalloc(size_t xSize);
|
|
extern void* pvPortAllocAligned(size_t xSize, size_t xAlignment);
|
|
extern void* pvPortRealloc(void* pv, size_t xSize);
|
|
extern void vPortFree(void* pv);
|
|
extern size_t xPortGetFreeHeapSize(void);
|
|
extern size_t xPortGetTotalHeapSize(void);
|
|
extern size_t xPortGetMinimumEverFreeHeapSize(void);
|
|
|
|
void* malloc(size_t size) {
|
|
return pvPortMalloc(size);
|
|
}
|
|
|
|
void free(void* ptr) {
|
|
vPortFree(ptr);
|
|
}
|
|
|
|
void* realloc(void* ptr, size_t size) {
|
|
return pvPortRealloc(ptr, size);
|
|
}
|
|
|
|
void* calloc(size_t count, size_t size) {
|
|
return pvPortMalloc(count * size);
|
|
}
|
|
|
|
char* strdup(const char* s) {
|
|
// arg s marked as non-null, so we need hack to check for NULL
|
|
furi_check(((uint32_t)s << 2) != 0);
|
|
|
|
size_t siz = strlen(s) + 1;
|
|
char* y = pvPortMalloc(siz);
|
|
memcpy(y, s, siz);
|
|
|
|
return y;
|
|
}
|
|
|
|
void* aligned_alloc(size_t alignment, size_t size) {
|
|
return pvPortAllocAligned(size, alignment);
|
|
}
|
|
|
|
size_t memmgr_get_free_heap(void) {
|
|
return xPortGetFreeHeapSize();
|
|
}
|
|
|
|
size_t memmgr_get_total_heap(void) {
|
|
return xPortGetTotalHeapSize();
|
|
}
|
|
|
|
size_t memmgr_get_minimum_free_heap(void) {
|
|
return xPortGetMinimumEverFreeHeapSize();
|
|
}
|
|
|
|
void* __wrap__malloc_r(struct _reent* r, size_t size) {
|
|
UNUSED(r);
|
|
return pvPortMalloc(size);
|
|
}
|
|
|
|
void __wrap__free_r(struct _reent* r, void* ptr) {
|
|
UNUSED(r);
|
|
vPortFree(ptr);
|
|
}
|
|
|
|
void* __wrap__calloc_r(struct _reent* r, size_t count, size_t size) {
|
|
UNUSED(r);
|
|
return calloc(count, size);
|
|
}
|
|
|
|
void* __wrap__realloc_r(struct _reent* r, void* ptr, size_t size) {
|
|
UNUSED(r);
|
|
return realloc(ptr, size);
|
|
}
|
|
|
|
void* memmgr_aux_pool_alloc(size_t size) {
|
|
void* p = furi_hal_memory_alloc(size);
|
|
if(p == NULL) p = malloc(size);
|
|
|
|
return p;
|
|
}
|
|
|
|
size_t memmgr_aux_pool_get_free(void) {
|
|
return furi_hal_memory_get_free();
|
|
}
|
|
|
|
size_t memmgr_pool_get_max_block(void) {
|
|
return furi_hal_memory_max_pool_block();
|
|
} |