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