arch/loongarch/kernel/unwind_prologue.c
Source file repositories/reference/linux-study-clean/arch/loongarch/kernel/unwind_prologue.c
File Facts
- System
- Linux kernel
- Corpus path
arch/loongarch/kernel/unwind_prologue.c- Extension
.c- Size
- 6209 bytes
- Lines
- 263
- Domain
- Architecture Layer
- Bucket
- arch/loongarch
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cpumask.hlinux/export.hlinux/ftrace.hlinux/kallsyms.hasm/inst.hasm/loongson.hasm/ptrace.hasm/setup.hasm/unwind.h
Detected Declarations
function scan_handlersfunction fix_exceptionfunction for_each_possible_cpufunction fix_ftracefunction unwind_state_fixupfunction unwind_by_prologuefunction next_framefunction unwind_get_return_addressfunction unwind_startfunction default_next_framefunction unwind_next_frameexport unwind_get_return_addressexport unwind_startexport unwind_next_frame
Annotated Snippet
if (is_stack_alloc_ins(ip)) {
frame_size = (1 << 12) - ip->reg2i12_format.immediate;
ip++;
break;
}
ip++;
}
/*
* Can't find stack alloc action, PC may be in a leaf function. Only the
* first being true is reasonable, otherwise indicate analysis is broken.
*/
if (!frame_size) {
if (state->first)
goto first;
return false;
}
while (ip < ip_end) {
if (is_ra_save_ins(ip)) {
frame_ra = ip->reg2i12_format.immediate;
break;
}
if (is_branch_ins(ip))
break;
ip++;
}
/* Can't find save $ra action, PC may be in a leaf function, too. */
if (frame_ra < 0) {
if (state->first) {
state->sp = state->sp + frame_size;
goto first;
}
return false;
}
state->pc = *(unsigned long *)(state->sp + frame_ra);
state->sp = state->sp + frame_size;
goto out;
first:
state->pc = state->ra;
out:
state->first = false;
return unwind_state_fixup(state) || __kernel_text_address(state->pc);
}
static bool next_frame(struct unwind_state *state)
{
unsigned long pc;
struct pt_regs *regs;
struct stack_info *info = &state->stack_info;
if (unwind_done(state))
return false;
do {
if (unwind_by_prologue(state)) {
state->pc = unwind_graph_addr(state, state->pc, state->sp);
return true;
}
if (info->type == STACK_TYPE_IRQ && info->end == state->sp) {
regs = (struct pt_regs *)info->next_sp;
pc = regs->csr_era;
if (user_mode(regs) || !__kernel_text_address(pc))
goto out;
state->first = true;
state->pc = pc;
state->ra = regs->regs[1];
state->sp = regs->regs[3];
get_stack_info(state->sp, state->task, info);
return true;
}
state->sp = info->next_sp;
} while (!get_stack_info(state->sp, state->task, info));
out:
state->stack_info.type = STACK_TYPE_UNKNOWN;
return false;
}
Annotation
- Immediate include surface: `linux/cpumask.h`, `linux/export.h`, `linux/ftrace.h`, `linux/kallsyms.h`, `asm/inst.h`, `asm/loongson.h`, `asm/ptrace.h`, `asm/setup.h`.
- Detected declarations: `function scan_handlers`, `function fix_exception`, `function for_each_possible_cpu`, `function fix_ftrace`, `function unwind_state_fixup`, `function unwind_by_prologue`, `function next_frame`, `function unwind_get_return_address`, `function unwind_start`, `function default_next_frame`.
- Atlas domain: Architecture Layer / arch/loongarch.
- 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.