1
0

syscall_mem.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. * 2014-08-03 bernard Add file header
  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 "armlibc.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. #ifdef __CC_ARM
  22. /* avoid the heap and heap-using library functions supplied by arm */
  23. #pragma import(__use_no_heap)
  24. #endif /* __CC_ARM */
  25. void *malloc(size_t n)
  26. {
  27. #ifdef RT_USING_HEAP
  28. return rt_malloc(n);
  29. #else
  30. _NO_HEAP_ERROR();
  31. return RT_NULL;
  32. #endif
  33. }
  34. RTM_EXPORT(malloc);
  35. void *realloc(void *rmem, size_t newsize)
  36. {
  37. #ifdef RT_USING_HEAP
  38. return rt_realloc(rmem, newsize);
  39. #else
  40. _NO_HEAP_ERROR();
  41. return RT_NULL;
  42. #endif
  43. }
  44. RTM_EXPORT(realloc);
  45. void *calloc(size_t nelem, size_t elsize)
  46. {
  47. #ifdef RT_USING_HEAP
  48. return rt_calloc(nelem, elsize);
  49. #else
  50. _NO_HEAP_ERROR();
  51. return RT_NULL;
  52. #endif
  53. }
  54. RTM_EXPORT(calloc);
  55. void free(void *rmem)
  56. {
  57. #ifdef RT_USING_HEAP
  58. rt_free(rmem);
  59. #else
  60. _NO_HEAP_ERROR();
  61. #endif
  62. }
  63. RTM_EXPORT(free);