^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2021, The Linux Foundation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/android_debug_symbols.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/stacktrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/cma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "../../mm/slab.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/page_owner.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct ads_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) void *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define _ADS_ENTRY(index, symbol) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) [index] = { .name = #symbol, .addr = (void *)symbol }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define ADS_ENTRY(index, symbol) _ADS_ENTRY(index, symbol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define _ADS_PER_CPU_ENTRY(index, symbol) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) [index] = { .name = #symbol, .addr = (void *)&symbol }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define ADS_PER_CPU_ENTRY(index, symbol) _ADS_PER_CPU_ENTRY(index, symbol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * This module maintains static array of symbol and address information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * Add all required core kernel symbols and their addresses into ads_entries[] array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * so that vendor modules can query and to find address of non-exported symbol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static const struct ads_entry ads_entries[ADS_END] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) ADS_ENTRY(ADS_SDATA, _sdata),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) ADS_ENTRY(ADS_BSS_END, __bss_stop),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) ADS_ENTRY(ADS_PER_CPU_START, __per_cpu_start),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ADS_ENTRY(ADS_PER_CPU_END, __per_cpu_end),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ADS_ENTRY(ADS_START_RO_AFTER_INIT, __start_ro_after_init),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) ADS_ENTRY(ADS_END_RO_AFTER_INIT, __end_ro_after_init),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) ADS_ENTRY(ADS_LINUX_BANNER, linux_banner),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #ifdef CONFIG_CMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ADS_ENTRY(ADS_TOTAL_CMA, &totalcma_pages),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ADS_ENTRY(ADS_SLAB_CACHES, &slab_caches),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) ADS_ENTRY(ADS_SLAB_MUTEX, &slab_mutex),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) ADS_ENTRY(ADS_MIN_LOW_PFN, &min_low_pfn),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ADS_ENTRY(ADS_MAX_PFN, &max_pfn),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #ifdef CONFIG_PAGE_OWNER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ADS_ENTRY(ADS_PAGE_OWNER_ENABLED, &page_owner_enabled),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #ifdef CONFIG_SLUB_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) ADS_ENTRY(ADS_SLUB_DEBUG, &slub_debug),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #ifdef CONFIG_SWAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ADS_ENTRY(ADS_NR_SWAP_PAGES, &nr_swap_pages),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #ifdef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ADS_ENTRY(ADS_MMAP_MIN_ADDR, &mmap_min_addr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) ADS_ENTRY(ADS_STACK_GUARD_GAP, &stack_guard_gap),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ADS_ENTRY(ADS_SYSCTL_LEGACY_VA_LAYOUT, &sysctl_legacy_va_layout),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * ads_per_cpu_entries array contains all the per_cpu variable address information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static const struct ads_entry ads_per_cpu_entries[ADS_DEBUG_PER_CPU_END] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #ifdef CONFIG_ARM64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) ADS_PER_CPU_ENTRY(ADS_IRQ_STACK_PTR, irq_stack_ptr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #ifdef CONFIG_X86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) ADS_PER_CPU_ENTRY(ADS_IRQ_STACK_PTR, hardirq_stack_ptr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * android_debug_symbol - Provide address inforamtion of debug symbol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * @symbol: Index of debug symbol array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * Return address of core kernel symbol on success and a negative errno will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * returned in error cases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) void *android_debug_symbol(enum android_debug_symbol symbol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (symbol >= ADS_END)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return ads_entries[symbol].addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) EXPORT_SYMBOL_GPL(android_debug_symbol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * android_debug_per_cpu_symbol - Provide address inforamtion of per cpu debug symbol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * @symbol: Index of per cpu debug symbol array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * Return address of core kernel symbol on success and a negative errno will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * returned in error cases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) void *android_debug_per_cpu_symbol(enum android_debug_per_cpu_symbol symbol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (symbol >= ADS_DEBUG_PER_CPU_END)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return ads_per_cpu_entries[symbol].addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) EXPORT_SYMBOL_GPL(android_debug_per_cpu_symbol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static int __init debug_symbol_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) module_init(debug_symbol_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static void __exit debug_symbol_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) module_exit(debug_symbol_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) MODULE_DESCRIPTION("Debug Symbol Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) MODULE_LICENSE("GPL v2");