arch/xtensa/kernel/stacktrace.c
Source file repositories/reference/linux-study-clean/arch/xtensa/kernel/stacktrace.c
File Facts
- System
- Linux kernel
- Corpus path
arch/xtensa/kernel/stacktrace.c- Extension
.c- Size
- 6107 bytes
- Lines
- 274
- Domain
- Architecture Layer
- Bucket
- arch/xtensa
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/export.hlinux/sched.hlinux/stacktrace.hasm/ftrace.hasm/sections.hasm/stacktrace.hasm/traps.hlinux/uaccess.h
Detected Declarations
struct stack_trace_datastruct return_addr_datafunction xtensa_backtrace_userfunction xtensa_backtrace_kernelfunction walk_stackframefunction stack_trace_cbfunction save_stack_trace_tskfunction save_stack_tracefunction return_address_cbfunction return_addressexport xtensa_backtrace_userexport xtensa_backtrace_kernelexport save_stack_trace_tskexport save_stack_traceexport return_address
Annotated Snippet
struct stack_trace_data {
struct stack_trace *trace;
unsigned skip;
};
static int stack_trace_cb(struct stackframe *frame, void *data)
{
struct stack_trace_data *trace_data = data;
struct stack_trace *trace = trace_data->trace;
if (trace_data->skip) {
--trace_data->skip;
return 0;
}
if (!kernel_text_address(frame->pc))
return 0;
trace->entries[trace->nr_entries++] = frame->pc;
return trace->nr_entries >= trace->max_entries;
}
void save_stack_trace_tsk(struct task_struct *task, struct stack_trace *trace)
{
struct stack_trace_data trace_data = {
.trace = trace,
.skip = trace->skip,
};
walk_stackframe(stack_pointer(task), stack_trace_cb, &trace_data);
}
EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
void save_stack_trace(struct stack_trace *trace)
{
save_stack_trace_tsk(current, trace);
}
EXPORT_SYMBOL_GPL(save_stack_trace);
#endif
struct return_addr_data {
unsigned long addr;
unsigned skip;
};
static int return_address_cb(struct stackframe *frame, void *data)
{
struct return_addr_data *r = data;
if (r->skip) {
--r->skip;
return 0;
}
if (!kernel_text_address(frame->pc))
return 0;
r->addr = frame->pc;
return 1;
}
/*
* level == 0 is for the return address from the caller of this function,
* not from this function itself.
*/
unsigned long return_address(unsigned level)
{
struct return_addr_data r = {
.skip = level,
};
walk_stackframe(stack_pointer(NULL), return_address_cb, &r);
return r.addr;
}
EXPORT_SYMBOL(return_address);
Annotation
- Immediate include surface: `linux/export.h`, `linux/sched.h`, `linux/stacktrace.h`, `asm/ftrace.h`, `asm/sections.h`, `asm/stacktrace.h`, `asm/traps.h`, `linux/uaccess.h`.
- Detected declarations: `struct stack_trace_data`, `struct return_addr_data`, `function xtensa_backtrace_user`, `function xtensa_backtrace_kernel`, `function walk_stackframe`, `function stack_trace_cb`, `function save_stack_trace_tsk`, `function save_stack_trace`, `function return_address_cb`, `function return_address`.
- Atlas domain: Architecture Layer / arch/xtensa.
- Implementation status: integration 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.