kernel/stacktrace.c
Source file repositories/reference/linux-study-clean/kernel/stacktrace.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/stacktrace.c- Extension
.c- Size
- 10696 bytes
- Lines
- 405
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/sched/task_stack.hlinux/sched/debug.hlinux/sched.hlinux/kernel.hlinux/export.hlinux/kallsyms.hlinux/stacktrace.hlinux/interrupt.h
Detected Declarations
struct stacktrace_cookiefunction Copyrightfunction stack_trace_snprintfunction stack_trace_consume_entryfunction stack_trace_consume_entry_noschedfunction stack_trace_savefunction stack_trace_save_tskfunction stack_trace_save_regsfunction stack_trace_save_tsk_reliablefunction stack_trace_save_userfunction save_stack_trace_tskfunction save_stack_trace_regsfunction stack_trace_savefunction stack_trace_save_tskfunction stack_trace_save_regsfunction stack_trace_save_tsk_reliablefunction stack_trace_save_userfunction in_irqentry_textfunction filter_irq_stacksexport stack_trace_printexport stack_trace_snprintexport stack_trace_saveexport stack_trace_save_tskexport stack_trace_saveexport stack_trace_save_tskexport filter_irq_stacks
Annotated Snippet
struct stacktrace_cookie {
unsigned long *store;
unsigned int size;
unsigned int skip;
unsigned int len;
};
static bool stack_trace_consume_entry(void *cookie, unsigned long addr)
{
struct stacktrace_cookie *c = cookie;
if (c->len >= c->size)
return false;
if (c->skip > 0) {
c->skip--;
return true;
}
c->store[c->len++] = addr;
return c->len < c->size;
}
static bool stack_trace_consume_entry_nosched(void *cookie, unsigned long addr)
{
if (in_sched_functions(addr))
return true;
return stack_trace_consume_entry(cookie, addr);
}
/**
* stack_trace_save - Save a stack trace into a storage array
* @store: Pointer to storage array
* @size: Size of the storage array
* @skipnr: Number of entries to skip at the start of the stack trace
*
* Return: Number of trace entries stored.
*/
unsigned int stack_trace_save(unsigned long *store, unsigned int size,
unsigned int skipnr)
{
stack_trace_consume_fn consume_entry = stack_trace_consume_entry;
struct stacktrace_cookie c = {
.store = store,
.size = size,
.skip = skipnr + 1,
};
arch_stack_walk(consume_entry, &c, current, NULL);
return c.len;
}
EXPORT_SYMBOL_GPL(stack_trace_save);
/**
* stack_trace_save_tsk - Save a task stack trace into a storage array
* @tsk: The task to examine
* @store: Pointer to storage array
* @size: Size of the storage array
* @skipnr: Number of entries to skip at the start of the stack trace
*
* Return: Number of trace entries stored.
*/
unsigned int stack_trace_save_tsk(struct task_struct *tsk, unsigned long *store,
unsigned int size, unsigned int skipnr)
{
stack_trace_consume_fn consume_entry = stack_trace_consume_entry_nosched;
struct stacktrace_cookie c = {
.store = store,
.size = size,
/* skip this function if they are tracing us */
.skip = skipnr + (current == tsk),
};
if (!try_get_task_stack(tsk))
return 0;
arch_stack_walk(consume_entry, &c, tsk, NULL);
put_task_stack(tsk);
return c.len;
}
EXPORT_SYMBOL_GPL(stack_trace_save_tsk);
/**
* stack_trace_save_regs - Save a stack trace based on pt_regs into a storage array
* @regs: Pointer to pt_regs to examine
* @store: Pointer to storage array
* @size: Size of the storage array
* @skipnr: Number of entries to skip at the start of the stack trace
*
* Return: Number of trace entries stored.
*/
Annotation
- Immediate include surface: `linux/sched/task_stack.h`, `linux/sched/debug.h`, `linux/sched.h`, `linux/kernel.h`, `linux/export.h`, `linux/kallsyms.h`, `linux/stacktrace.h`, `linux/interrupt.h`.
- Detected declarations: `struct stacktrace_cookie`, `function Copyright`, `function stack_trace_snprint`, `function stack_trace_consume_entry`, `function stack_trace_consume_entry_nosched`, `function stack_trace_save`, `function stack_trace_save_tsk`, `function stack_trace_save_regs`, `function stack_trace_save_tsk_reliable`, `function stack_trace_save_user`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration 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.