ANDROID: debug_symbols: Add android_debug_for_each_module

Allow vendors to obtain a list of modules loaded at given time. Vendor
modules are able to register on part of notifier chain
(register_module_notifer), but a vendor module would never see modules
which are loaded before the one which registers on the notifier chain.
The kernel doesn't offer load order control, so a hook is necessary to
iterate through currently loaded kernel modules.

Bug: 193552324
Change-Id: I3b01cc1b90f8c0c7c21a37992cc7d607316efc7b
Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
This commit is contained in:
Elliot Berman
2021-07-13 14:26:23 -07:00
committed by Todd Kjos
parent a0429aa1d0
commit 0bb433e014
2 changed files with 23 additions and 0 deletions

View File

@@ -50,6 +50,9 @@ enum android_debug_per_cpu_symbol {
void *android_debug_symbol(enum android_debug_symbol symbol);
void *android_debug_per_cpu_symbol(enum android_debug_per_cpu_symbol symbol);
void android_debug_for_each_module(int (*fn)(const char *mod_name, void *mod_addr, void *data),
void *data);
#else /* !CONFIG_ANDROID_DEBUG_SYMBOLS */
static inline void *android_debug_symbol(enum android_debug_symbol symbol)
@@ -60,6 +63,9 @@ static inline void *android_debug_per_cpu_symbol(enum android_debug_per_cpu_symb
{
return NULL;
}
static inline void android_debug_for_each_module(int (*fn)(const char *mod_name, void *mod_addr,
void *data), void *data) {}
#endif /* CONFIG_ANDROID_DEBUG_SYMBOLS */
#endif /* _ANDROID_DEBUG_SYMBOLS_H */

View File

@@ -4788,6 +4788,23 @@ void print_modules(void)
pr_cont("\n");
}
#ifdef CONFIG_ANDROID_DEBUG_SYMBOLS
void android_debug_for_each_module(int (*fn)(const char *mod_name, void *mod_addr, void *data),
void *data)
{
struct module *module;
preempt_disable();
list_for_each_entry_rcu(module, &modules, list) {
if (fn(module->name, module->core_layout.base, data))
goto out;
}
out:
preempt_enable();
}
EXPORT_SYMBOL_GPL(android_debug_for_each_module);
#endif
#ifdef CONFIG_MODVERSIONS
/* Generate the signature for all relevant module structures here.
* If these change, we don't want to try to parse the module. */