kernel/module/kallsyms.c
Source file repositories/reference/linux-study-clean/kernel/module/kallsyms.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/module/kallsyms.c- Extension
.c- Size
- 13433 bytes
- Lines
- 497
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/module_symbol.hlinux/kallsyms.hlinux/buildid.hlinux/bsearch.hinternal.h
Detected Declarations
function Copyrightfunction is_exportedfunction elf_typefunction is_core_symbolfunction layout_symtabfunction add_kallsymsfunction init_build_idfunction init_build_idfunction dereference_module_function_descriptorfunction module_address_lookupfunction lookup_module_symbol_namefunction module_get_kallsymfunction __find_kallsyms_symbol_valuefunction __module_kallsyms_lookup_namefunction list_for_each_entry_rcufunction module_kallsyms_lookup_namefunction find_kallsyms_symbol_valuefunction module_kallsyms_on_each_symbol
Annotated Snippet
if (thisval <= addr && thisval > bestval) {
best = i;
bestval = thisval;
}
if (thisval > addr && thisval < nextval)
nextval = thisval;
}
if (!best)
return NULL;
if (size)
*size = nextval - bestval;
if (offset)
*offset = addr - bestval;
return kallsyms_symbol_name(kallsyms, best);
}
void * __weak dereference_module_function_descriptor(struct module *mod,
void *ptr)
{
return ptr;
}
/*
* For kallsyms to ask for address resolution. NULL means not found. Careful
* not to lock to avoid deadlock on oopses, RCU is enough.
*/
int module_address_lookup(unsigned long addr,
unsigned long *size,
unsigned long *offset,
char **modname,
const unsigned char **modbuildid,
char *namebuf)
{
const char *sym;
int ret = 0;
struct module *mod;
guard(rcu)();
mod = __module_address(addr);
if (mod) {
if (modname)
*modname = mod->name;
if (modbuildid)
*modbuildid = module_buildid(mod);
sym = find_kallsyms_symbol(mod, addr, size, offset);
if (sym)
ret = strscpy(namebuf, sym, KSYM_NAME_LEN);
}
return ret;
}
int lookup_module_symbol_name(unsigned long addr, char *symname)
{
struct module *mod;
guard(rcu)();
list_for_each_entry_rcu(mod, &modules, list) {
if (mod->state == MODULE_STATE_UNFORMED)
continue;
if (within_module(addr, mod)) {
const char *sym;
sym = find_kallsyms_symbol(mod, addr, NULL, NULL);
if (!sym)
goto out;
strscpy(symname, sym, KSYM_NAME_LEN);
return 0;
}
}
out:
return -ERANGE;
}
int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
char *name, char *module_name, int *exported)
{
struct module *mod;
guard(rcu)();
list_for_each_entry_rcu(mod, &modules, list) {
struct mod_kallsyms *kallsyms;
if (mod->state == MODULE_STATE_UNFORMED)
continue;
Annotation
- Immediate include surface: `linux/module.h`, `linux/module_symbol.h`, `linux/kallsyms.h`, `linux/buildid.h`, `linux/bsearch.h`, `internal.h`.
- Detected declarations: `function Copyright`, `function is_exported`, `function elf_type`, `function is_core_symbol`, `function layout_symtab`, `function add_kallsyms`, `function init_build_id`, `function init_build_id`, `function dereference_module_function_descriptor`, `function module_address_lookup`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.