arch/x86/kernel/dumpstack.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/dumpstack.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/dumpstack.c- Extension
.c- Size
- 13866 bytes
- Lines
- 491
- Domain
- Architecture Layer
- Bucket
- arch/x86
- 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.
- 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/kallsyms.hlinux/kprobes.hlinux/uaccess.hlinux/utsname.hlinux/hardirq.hlinux/kdebug.hlinux/module.hlinux/ptrace.hlinux/sched/debug.hlinux/sched/task_stack.hlinux/ftrace.hlinux/kexec.hlinux/bug.hlinux/nmi.hlinux/sysfs.hlinux/kasan.hasm/cpu_entry_area.hasm/stacktrace.hasm/unwind.h
Detected Declarations
function in_task_stackfunction in_entry_stackfunction printk_stack_addressfunction copy_codefunction show_opcodesfunction show_ipfunction show_iret_regsfunction show_regs_if_on_stackfunction __show_trace_log_lvlfunction show_trace_log_lvlfunction show_stackfunction show_stack_regsfunction oops_beginfunction oops_endfunction __die_headerfunction __die_bodyfunction __diefunction diefunction die_addrfunction show_regs
Annotated Snippet
if (get_stack_info(stack, task, &stack_info, &visit_mask)) {
/*
* We weren't on a valid stack. It's possible that
* we overflowed a valid stack into a guard page.
* See if the next page up is valid so that we can
* generate some kind of backtrace if this happens.
*/
stack = (unsigned long *)PAGE_ALIGN((unsigned long)stack);
if (get_stack_info(stack, task, &stack_info, &visit_mask))
break;
}
stack_name = stack_type_name(stack_info.type);
if (stack_name)
printk("%s <%s>\n", log_lvl, stack_name);
if (regs)
show_regs_if_on_stack(&stack_info, regs, partial, log_lvl);
/*
* Scan the stack, printing any text addresses we find. At the
* same time, follow proper stack frames with the unwinder.
*
* Addresses found during the scan which are not reported by
* the unwinder are considered to be additional clues which are
* sometimes useful for debugging and are prefixed with '?'.
* This also serves as a failsafe option in case the unwinder
* goes off in the weeds.
*/
for (; stack < stack_info.end; stack++) {
unsigned long real_addr;
int reliable = 0;
unsigned long addr = READ_ONCE_NOCHECK(*stack);
unsigned long *ret_addr_p =
unwind_get_return_address_ptr(&state);
if (!__kernel_text_address(addr))
continue;
/*
* Don't print regs->ip again if it was already printed
* by show_regs_if_on_stack().
*/
if (regs && stack == ®s->ip)
goto next;
if (stack == ret_addr_p)
reliable = 1;
/*
* When function graph tracing is enabled for a
* function, its return address on the stack is
* replaced with the address of an ftrace handler
* (return_to_handler). In that case, before printing
* the "real" address, we want to print the handler
* address as an "unreliable" hint that function graph
* tracing was involved.
*/
real_addr = ftrace_graph_ret_addr(task, &graph_idx,
addr, stack);
if (real_addr != addr)
printk_stack_address(addr, 0, log_lvl);
printk_stack_address(real_addr, reliable, log_lvl);
if (!reliable)
continue;
next:
/*
* Get the next frame from the unwinder. No need to
* check for an error: if anything goes wrong, the rest
* of the addresses will just be printed as unreliable.
*/
unwind_next_frame(&state);
/* if the frame has entry regs, print them */
regs = unwind_get_entry_regs(&state, &partial);
if (regs)
show_regs_if_on_stack(&stack_info, regs, partial, log_lvl);
}
if (stack_name)
printk("%s </%s>\n", log_lvl, stack_name);
}
}
static void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
unsigned long *stack, const char *log_lvl)
{
/*
Annotation
- Immediate include surface: `linux/kallsyms.h`, `linux/kprobes.h`, `linux/uaccess.h`, `linux/utsname.h`, `linux/hardirq.h`, `linux/kdebug.h`, `linux/module.h`, `linux/ptrace.h`.
- Detected declarations: `function in_task_stack`, `function in_entry_stack`, `function printk_stack_address`, `function copy_code`, `function show_opcodes`, `function show_ip`, `function show_iret_regs`, `function show_regs_if_on_stack`, `function __show_trace_log_lvl`, `function show_trace_log_lvl`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.