kernel/kallsyms_selftest.c
Source file repositories/reference/linux-study-clean/kernel/kallsyms_selftest.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/kallsyms_selftest.c- Extension
.c- Size
- 10333 bytes
- Lines
- 447
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/init.hlinux/module.hlinux/kallsyms.hlinux/random.hlinux/sched/clock.hlinux/kthread.hlinux/vmalloc.hkallsyms_internal.hkallsyms_selftest.h
Detected Declarations
struct test_statstruct test_itemfunction kallsyms_test_func_staticfunction kallsyms_test_funcfunction kallsyms_test_func_weakfunction stat_symbol_lenfunction test_kallsyms_compression_ratiofunction lookup_namefunction test_perf_kallsyms_lookup_namefunction find_symbolfunction test_perf_kallsyms_on_each_symbolfunction match_symbolfunction test_perf_kallsyms_on_each_match_symbolfunction test_kallsyms_basic_functionfunction kallsyms_on_each_symbolfunction kallsyms_on_each_symbolfunction kallsyms_lookup_namefunction test_entryfunction kallsyms_test_init
Annotated Snippet
struct test_stat {
int min;
int max;
int save_cnt;
int real_cnt;
int perf;
u64 sum;
char *name;
unsigned long addr;
unsigned long addrs[MAX_NUM_OF_RECORDS];
};
struct test_item {
char *name;
unsigned long addr;
};
#define ITEM_FUNC(s) \
{ \
.name = #s, \
.addr = (unsigned long)s, \
}
#define ITEM_DATA(s) \
{ \
.name = #s, \
.addr = (unsigned long)&s, \
}
static int kallsyms_test_var_bss_static;
static int kallsyms_test_var_data_static = 1;
int kallsyms_test_var_bss;
int kallsyms_test_var_data = 1;
static int kallsyms_test_func_static(void)
{
kallsyms_test_var_bss_static++;
kallsyms_test_var_data_static++;
return 0;
}
int kallsyms_test_func(void)
{
return kallsyms_test_func_static();
}
__weak int kallsyms_test_func_weak(void)
{
kallsyms_test_var_bss++;
kallsyms_test_var_data++;
return 0;
}
static struct test_item test_items[] = {
ITEM_FUNC(kallsyms_test_func_static),
ITEM_FUNC(kallsyms_test_func),
ITEM_FUNC(kallsyms_test_func_weak),
ITEM_FUNC(vmalloc_noprof),
ITEM_FUNC(vfree),
#ifdef CONFIG_KALLSYMS_ALL
ITEM_DATA(kallsyms_test_var_bss_static),
ITEM_DATA(kallsyms_test_var_data_static),
ITEM_DATA(kallsyms_test_var_bss),
ITEM_DATA(kallsyms_test_var_data),
#endif
};
static char stub_name[KSYM_NAME_LEN];
static int stat_symbol_len(void *data, const char *name, unsigned long addr)
{
*(u32 *)data += strlen(name);
return 0;
}
static void test_kallsyms_compression_ratio(void)
{
u32 pos, off, len, num;
u32 ratio, total_size, total_len = 0;
kallsyms_on_each_symbol(stat_symbol_len, &total_len);
/*
* A symbol name cannot start with a number. This stub name helps us
* traverse the entire symbol table without finding a match. It's used
* for subsequent performance tests, and its length is the average
* length of all symbol names.
Annotation
- Immediate include surface: `linux/init.h`, `linux/module.h`, `linux/kallsyms.h`, `linux/random.h`, `linux/sched/clock.h`, `linux/kthread.h`, `linux/vmalloc.h`, `kallsyms_internal.h`.
- Detected declarations: `struct test_stat`, `struct test_item`, `function kallsyms_test_func_static`, `function kallsyms_test_func`, `function kallsyms_test_func_weak`, `function stat_symbol_len`, `function test_kallsyms_compression_ratio`, `function lookup_name`, `function test_perf_kallsyms_lookup_name`, `function find_symbol`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
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.