arch/arm64/kernel/stacktrace.c
Source file repositories/reference/linux-study-clean/arch/arm64/kernel/stacktrace.c
File Facts
- System
- Linux kernel
- Corpus path
arch/arm64/kernel/stacktrace.c- Extension
.c- Size
- 15203 bytes
- Lines
- 622
- Domain
- Architecture Layer
- Bucket
- arch/arm64
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/efi.hlinux/export.hlinux/filter.hlinux/ftrace.hlinux/kprobes.hlinux/sched.hlinux/sched/debug.hlinux/sched/task_stack.hlinux/stacktrace.hasm/efi.hasm/irq.hasm/stack_pointer.hasm/stacktrace.h
Detected Declarations
struct kunwind_statestruct kunwind_consume_entry_datastruct bpf_unwind_consume_entry_datastruct frame_tailstruct compat_frame_tailenum kunwind_sourcefunction kunwind_initfunction kunwind_init_from_regsfunction kunwind_init_from_callerfunction PCfunction kunwind_recover_return_addressfunction kunwind_next_regs_pcfunction kunwind_next_frame_record_metafunction kunwind_next_frame_recordfunction recordfunction do_kunwindfunction kunwind_stack_walkfunction arch_kunwind_consume_entryfunction arch_stack_walkfunction arch_reliable_kunwind_consume_entryfunction arch_stack_walk_reliablefunction arch_bpf_unwind_consume_entryfunction arch_bpf_stack_walkfunction dump_backtrace_entryfunction dump_backtracefunction show_stackfunction unwind_user_framefunction unwind_compat_user_framefunction arch_stack_walk_user
Annotated Snippet
struct kunwind_state {
struct unwind_state common;
struct task_struct *task;
int graph_idx;
#ifdef CONFIG_KRETPROBES
struct llist_node *kr_cur;
#endif
enum kunwind_source source;
union unwind_flags flags;
struct pt_regs *regs;
};
static __always_inline void
kunwind_init(struct kunwind_state *state,
struct task_struct *task)
{
unwind_init_common(&state->common);
state->task = task;
state->source = KUNWIND_SOURCE_UNKNOWN;
state->flags.all = 0;
state->regs = NULL;
}
/*
* Start an unwind from a pt_regs.
*
* The unwind will begin at the PC within the regs.
*
* The regs must be on a stack currently owned by the calling task.
*/
static __always_inline void
kunwind_init_from_regs(struct kunwind_state *state,
struct pt_regs *regs)
{
kunwind_init(state, current);
state->regs = regs;
state->common.fp = regs->regs[29];
state->common.pc = regs->pc;
state->source = KUNWIND_SOURCE_REGS_PC;
}
/*
* Start an unwind from a caller.
*
* The unwind will begin at the caller of whichever function this is inlined
* into.
*
* The function which invokes this must be noinline.
*/
static __always_inline void
kunwind_init_from_caller(struct kunwind_state *state)
{
kunwind_init(state, current);
state->common.fp = (unsigned long)__builtin_frame_address(1);
state->common.pc = (unsigned long)__builtin_return_address(0);
state->source = KUNWIND_SOURCE_CALLER;
}
/*
* Start an unwind from a blocked task.
*
* The unwind will begin at the blocked tasks saved PC (i.e. the caller of
* cpu_switch_to()).
*
* The caller should ensure the task is blocked in cpu_switch_to() for the
* duration of the unwind, or the unwind will be bogus. It is never valid to
* call this for the current task.
*/
static __always_inline void
kunwind_init_from_task(struct kunwind_state *state,
struct task_struct *task)
{
kunwind_init(state, task);
state->common.fp = thread_saved_fp(task);
state->common.pc = thread_saved_pc(task);
state->source = KUNWIND_SOURCE_TASK;
}
static __always_inline int
kunwind_recover_return_address(struct kunwind_state *state)
{
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
if (state->task->ret_stack &&
(state->common.pc == (unsigned long)return_to_handler)) {
unsigned long orig_pc;
orig_pc = ftrace_graph_ret_addr(state->task, &state->graph_idx,
state->common.pc,
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/efi.h`, `linux/export.h`, `linux/filter.h`, `linux/ftrace.h`, `linux/kprobes.h`, `linux/sched.h`, `linux/sched/debug.h`.
- Detected declarations: `struct kunwind_state`, `struct kunwind_consume_entry_data`, `struct bpf_unwind_consume_entry_data`, `struct frame_tail`, `struct compat_frame_tail`, `enum kunwind_source`, `function kunwind_init`, `function kunwind_init_from_regs`, `function kunwind_init_from_caller`, `function PC`.
- Atlas domain: Architecture Layer / arch/arm64.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.