mem_manager.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2019 Actions Semi Co., Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief mem manager.
  9. */
  10. #include <mem_manager.h>
  11. #include "mem_inner.h"
  12. #ifdef CONFIG_ACTIONS_PRINTK_DMA
  13. #include <sys/printk.h>
  14. #endif
  15. #ifdef CONFIG_SYS_MEMORY_DEBUG
  16. #include "mem_guard.h"
  17. static struct mem_guard_head mem_guard;
  18. #endif
  19. void *mem_malloc_debug(size_t size,const char *func)
  20. {
  21. #ifdef CONFIG_SYS_MEMORY_DEBUG
  22. return mem_guard_malloc(&mem_guard, mem_pool_malloc, size, func);
  23. #else
  24. return mem_pool_malloc(size);
  25. #endif
  26. }
  27. void mem_free(void *ptr)
  28. {
  29. if (ptr == NULL)
  30. return;
  31. #ifdef CONFIG_SYS_MEMORY_DEBUG
  32. mem_guard_free(&mem_guard, mem_pool_free, ptr);
  33. #else
  34. mem_pool_free(ptr);
  35. #endif
  36. }
  37. void mem_manager_dump(void)
  38. {
  39. #ifdef CONFIG_ACTIONS_PRINTK_DMA
  40. printk_dma_switch(0);
  41. #endif /* CONFIG_ACTIONS_PRINTK_DMA */
  42. #ifdef CONFIG_SYS_MEMORY_DEBUG
  43. mem_guard_dump(&mem_guard);
  44. #else
  45. mem_pool_dump();
  46. #endif
  47. #ifdef CONFIG_ACTIONS_PRINTK_DMA
  48. printk_dma_switch(1);
  49. #endif /* CONFIG_ACTIONS_PRINTK_DMA */
  50. }
  51. void mem_manager_dump_ext(int dump_detail, const char* match_value)
  52. {
  53. }
  54. int mem_manager_check_overwrite(void)
  55. {
  56. #ifdef CONFIG_SYS_MEMORY_DEBUG
  57. mem_guard_check_overwrite(&mem_guard);
  58. #endif
  59. return 0;
  60. }
  61. int mem_manager_init(void)
  62. {
  63. mem_pool_init();
  64. #ifdef CONFIG_SYS_MEMORY_DEBUG
  65. mem_guard_init(&mem_guard, CONFIG_RAM_POOL_PAGE_NUM * 2048);
  66. #endif
  67. return 0;
  68. }
  69. static int current_user_info = -1;
  70. void mem_manager_set_user_info(int user_info) {
  71. current_user_info = user_info;
  72. }
  73. int mem_manager_get_user_info(void) {
  74. return current_user_info;
  75. }