heap_wrap.c 854 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "wm_include.h"
  2. #include "FreeRTOS.h"
  3. #include "stdio.h"
  4. void* __wrap_malloc(size_t len) {
  5. return pvPortMalloc(len);
  6. }
  7. void __wrap_free(void* ptr) {
  8. if (ptr == NULL)
  9. return;
  10. u32 addr = (u32)ptr;
  11. if (addr >= 0x20000000 && addr <= 0x40000000) {
  12. // printf("free %p\n", ptr);
  13. vPortFree(ptr);
  14. }
  15. }
  16. void *pvPortRealloc( void *pv, size_t xWantedSize );
  17. void* __wrap_realloc(void*ptr, size_t len) {
  18. return pvPortRealloc(ptr, len);
  19. }
  20. void* __wrap_calloc(size_t itemCount, size_t itemSize) {
  21. void* ptr = pvPortMalloc(itemCount * itemSize);
  22. if (ptr == NULL)
  23. return NULL;
  24. memset(ptr, 0, itemCount * itemSize);
  25. return ptr;
  26. }
  27. void* __wrap_zalloc(size_t size) {
  28. void* ptr = pvPortMalloc(size);
  29. if (ptr == NULL)
  30. return NULL;
  31. memset(ptr, 0, size);
  32. return ptr;
  33. }