android_debug_symbols.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023, Unisoc (Shanghai) Technologies Co., Ltd
  5. */
  6. #include <linux/types.h>
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/android_debug_symbols.h>
  10. #include <asm/sections.h>
  11. #include <asm/stacktrace.h>
  12. #include <linux/cma.h>
  13. #include <linux/mm.h>
  14. #include "../../mm/slab.h"
  15. #include <linux/security.h>
  16. struct ads_entry {
  17. char *name;
  18. void *addr;
  19. };
  20. #define _ADS_ENTRY(index, symbol) \
  21. [index] = { .name = #symbol, .addr = (void *)symbol }
  22. #define ADS_ENTRY(index, symbol) _ADS_ENTRY(index, symbol)
  23. #define _ADS_PER_CPU_ENTRY(index, symbol) \
  24. [index] = { .name = #symbol, .addr = (void *)&symbol }
  25. #define ADS_PER_CPU_ENTRY(index, symbol) _ADS_PER_CPU_ENTRY(index, symbol)
  26. /*
  27. * This module maintains static array of symbol and address information.
  28. * Add all required core kernel symbols and their addresses into ads_entries[] array,
  29. * so that vendor modules can query and to find address of non-exported symbol.
  30. */
  31. static const struct ads_entry ads_entries[ADS_END] = {
  32. ADS_ENTRY(ADS_SDATA, _sdata),
  33. ADS_ENTRY(ADS_BSS_END, __bss_stop),
  34. ADS_ENTRY(ADS_PER_CPU_START, __per_cpu_start),
  35. ADS_ENTRY(ADS_PER_CPU_END, __per_cpu_end),
  36. ADS_ENTRY(ADS_TEXT, _text),
  37. ADS_ENTRY(ADS_SEND, _end),
  38. ADS_ENTRY(ADS_LINUX_BANNER, linux_banner),
  39. ADS_ENTRY(ADS_TOTAL_CMA, &totalcma_pages),
  40. ADS_ENTRY(ADS_SLAB_CACHES, &slab_caches),
  41. ADS_ENTRY(ADS_SLAB_MUTEX, &slab_mutex),
  42. };
  43. /*
  44. * ads_per_cpu_entries array contains all the per_cpu variable address information.
  45. */
  46. static const struct ads_entry ads_per_cpu_entries[ADS_DEBUG_PER_CPU_END] = {
  47. #ifdef CONFIG_ARM64
  48. ADS_PER_CPU_ENTRY(ADS_IRQ_STACK_PTR, irq_stack_ptr),
  49. #endif
  50. #ifdef CONFIG_X86
  51. ADS_PER_CPU_ENTRY(ADS_IRQ_STACK_PTR, hardirq_stack_ptr),
  52. #endif
  53. };
  54. /*
  55. * android_debug_symbol - Provide address inforamtion of debug symbol.
  56. * @symbol: Index of debug symbol array.
  57. *
  58. * Return address of core kernel symbol on success and a negative errno will be
  59. * returned in error cases.
  60. *
  61. */
  62. void *android_debug_symbol(enum android_debug_symbol symbol)
  63. {
  64. if (symbol >= ADS_END)
  65. return ERR_PTR(-EINVAL);
  66. return ads_entries[symbol].addr;
  67. }
  68. EXPORT_SYMBOL_NS_GPL(android_debug_symbol, MINIDUMP);
  69. /*
  70. * android_debug_per_cpu_symbol - Provide address inforamtion of per cpu debug symbol.
  71. * @symbol: Index of per cpu debug symbol array.
  72. *
  73. * Return address of core kernel symbol on success and a negative errno will be
  74. * returned in error cases.
  75. *
  76. */
  77. void *android_debug_per_cpu_symbol(enum android_debug_per_cpu_symbol symbol)
  78. {
  79. if (symbol >= ADS_DEBUG_PER_CPU_END)
  80. return ERR_PTR(-EINVAL);
  81. return ads_per_cpu_entries[symbol].addr;
  82. }
  83. EXPORT_SYMBOL_NS_GPL(android_debug_per_cpu_symbol, MINIDUMP);