wm_mem2.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "wm_osal.h"
  2. #include "wm_mem.h"
  3. #include "list.h"
  4. #include <string.h>
  5. #include "FreeRTOS.h"
  6. #include "task.h"
  7. #include "stdio.h"
  8. #include "luat_conf_bsp.h"
  9. #if 0
  10. #ifdef LUAT_USE_PROFILER_XXX
  11. void * mem_alloc_debug(u32 size) {
  12. void* ptr = malloc(size);
  13. printf("mem_alloc_debug %p %d\n", ptr, size);
  14. return ptr;
  15. }
  16. void mem_free_debug(void *ptr) {
  17. printf("mem_free_debug %p\n", ptr);
  18. free(ptr);
  19. }
  20. void * mem_realloc_debug(void *mem_address, u32 size) {
  21. void* ptr = realloc(mem_address, size);
  22. printf("mem_realloc_debug %p %d %p\n", mem_address, size, ptr);
  23. return ptr;
  24. }
  25. void *mem_calloc_debug(u32 length, u32 size) {
  26. void* ptr = calloc(length, size);
  27. printf("mem_calloc_debug %p %d\n", ptr, size * length);
  28. return ptr;
  29. }
  30. #else
  31. TaskStatus_t stat;
  32. void * mem_alloc_debug(u32 size) {
  33. if (size == 16) {
  34. printf("mem_alloc_debug %d\n", size);
  35. TaskHandle_t t = xTaskGetCurrentTaskHandle();
  36. if (t != NULL) {
  37. vTaskGetInfo(t, &stat, pdFALSE, eInvalid);
  38. printf("task %s %d\n", stat.pcTaskName, stat.xTaskNumber);
  39. }
  40. }
  41. return malloc(size);
  42. }
  43. void mem_free_debug(void *p) {
  44. // printf("free %p\n", p);
  45. free(p);
  46. }
  47. void * mem_realloc_debug(void *mem_address, u32 size) {
  48. return realloc(mem_address, size);
  49. }
  50. void *mem_calloc_debug(u32 length, u32 size) {
  51. return calloc(length, size);
  52. }
  53. #endif
  54. #endif