arch/x86/kernel/stacktrace.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/stacktrace.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/stacktrace.c- Extension
.c- Size
- 2924 bytes
- Lines
- 131
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/sched.hlinux/sched/debug.hlinux/sched/task_stack.hlinux/stacktrace.hlinux/export.hlinux/uaccess.hasm/stacktrace.hasm/unwind.h
Detected Declarations
struct stack_frame_userfunction Copyrightfunction unwind_next_framefunction arch_stack_walk_reliablefunction unwind_next_framefunction copy_stack_framefunction arch_stack_walk_user
Annotated Snippet
struct stack_frame_user {
const void __user *next_fp;
unsigned long ret_addr;
};
static int
copy_stack_frame(const struct stack_frame_user __user *fp,
struct stack_frame_user *frame)
{
int ret;
if (!__access_ok(fp, sizeof(*frame)))
return 0;
ret = 1;
pagefault_disable();
if (__get_user(frame->next_fp, &fp->next_fp) ||
__get_user(frame->ret_addr, &fp->ret_addr))
ret = 0;
pagefault_enable();
return ret;
}
void arch_stack_walk_user(stack_trace_consume_fn consume_entry, void *cookie,
const struct pt_regs *regs)
{
const void __user *fp = (const void __user *)regs->bp;
if (!consume_entry(cookie, regs->ip))
return;
while (1) {
struct stack_frame_user frame;
frame.next_fp = NULL;
frame.ret_addr = 0;
if (!copy_stack_frame(fp, &frame))
break;
if ((unsigned long)fp < regs->sp)
break;
if (!frame.ret_addr)
break;
if (!consume_entry(cookie, frame.ret_addr))
break;
fp = frame.next_fp;
}
}
Annotation
- Immediate include surface: `linux/sched.h`, `linux/sched/debug.h`, `linux/sched/task_stack.h`, `linux/stacktrace.h`, `linux/export.h`, `linux/uaccess.h`, `asm/stacktrace.h`, `asm/unwind.h`.
- Detected declarations: `struct stack_frame_user`, `function Copyright`, `function unwind_next_frame`, `function arch_stack_walk_reliable`, `function unwind_next_frame`, `function copy_stack_frame`, `function arch_stack_walk_user`.
- 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.
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.