syscall_mem.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2015-01-28 Bernard first version
  9. * 2021-11-13 Meco Man implement no-heap warning
  10. */
  11. #include <rtthread.h>
  12. #include <stddef.h>
  13. #ifndef RT_USING_HEAP
  14. #define DBG_TAG "dlib.syscall_mem"
  15. #define DBG_LVL DBG_INFO
  16. #include <rtdbg.h>
  17. #define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\
  18. RT_ASSERT(0);\
  19. }while(0)
  20. #endif /* RT_USING_HEAP */
  21. void *malloc(size_t n)
  22. {
  23. #ifdef RT_USING_HEAP
  24. return rt_malloc(n);
  25. #else
  26. _NO_HEAP_ERROR();
  27. return RT_NULL;
  28. #endif
  29. }
  30. void *realloc(void *rmem, size_t newsize)
  31. {
  32. #ifdef RT_USING_HEAP
  33. return rt_realloc(rmem, newsize);
  34. #else
  35. _NO_HEAP_ERROR();
  36. return RT_NULL;
  37. #endif
  38. }
  39. void *calloc(size_t nelem, size_t elsize)
  40. {
  41. #ifdef RT_USING_HEAP
  42. return rt_calloc(nelem, elsize);
  43. #else
  44. _NO_HEAP_ERROR();
  45. return RT_NULL;
  46. #endif
  47. }
  48. void free(void *rmem)
  49. {
  50. #ifdef RT_USING_HEAP
  51. rt_free(rmem);
  52. #else
  53. _NO_HEAP_ERROR();
  54. #endif
  55. }