mem.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * ESPRESSIF MIT License
  3. *
  4. * Copyright (c) 2016 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
  5. *
  6. * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
  7. * it is free of charge, to any person obtaining a copy of this software and associated
  8. * documentation files (the "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
  11. * to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all copies or
  14. * substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. */
  24. #ifndef __MEM_H__
  25. #define __MEM_H__
  26. /* Note: check_memleak_debug_enable is a weak function inside SDK.
  27. * please copy following codes to user_main.c.
  28. #include "mem.h"
  29. bool ICACHE_FLASH_ATTR check_memleak_debug_enable(void)
  30. {
  31. return MEMLEAK_DEBUG_ENABLE;
  32. }
  33. */
  34. void *pvPortMalloc (size_t sz, const char *, unsigned);
  35. void vPortFree (void *p, const char *, unsigned);
  36. void *pvPortZalloc (size_t sz, const char *, unsigned);
  37. void *pvPortRealloc (void *p, size_t n, const char *, unsigned);
  38. #ifndef MEMLEAK_DEBUG
  39. #define MEMLEAK_DEBUG_ENABLE 0
  40. #define os_free(s) vPortFree(s, "", 0)
  41. #define os_malloc(s) pvPortMalloc(s, "", 0)
  42. #define os_calloc(s) pvPortCalloc(s, "", 0);
  43. #define os_realloc(p, s) pvPortRealloc(p, s, "", 0)
  44. #define os_zalloc(s) pvPortZalloc(s, "", 0)
  45. #else
  46. #define MEMLEAK_DEBUG_ENABLE 1
  47. #define os_free(s) \
  48. do{\
  49. static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \
  50. vPortFree(s, mem_debug_file, __LINE__);\
  51. }while(0)
  52. #define os_malloc(s) \
  53. ({ \
  54. static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \
  55. pvPortMalloc(s, mem_debug_file, __LINE__); \
  56. })
  57. #define os_calloc(s) \
  58. ({ \
  59. static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \
  60. pvPortCalloc(s, mem_debug_file, __LINE__); \
  61. })
  62. #define os_realloc(p, s) \
  63. ({ \
  64. static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \
  65. pvPortRealloc(p, s, mem_debug_file, __LINE__); \
  66. })
  67. #define os_zalloc(s) \
  68. ({ \
  69. static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; \
  70. pvPortZalloc(s, mem_debug_file, __LINE__); \
  71. })
  72. #endif
  73. #endif