arch/riscv/kernel/traps.c
Source file repositories/reference/linux-study-clean/arch/riscv/kernel/traps.c
File Facts
- System
- Linux kernel
- Corpus path
arch/riscv/kernel/traps.c- Extension
.c- Size
- 12279 bytes
- Lines
- 487
- Domain
- Architecture Layer
- Bucket
- arch/riscv
- 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/cpu.hlinux/kernel.hlinux/init.hlinux/irqflags.hlinux/randomize_kstack.hlinux/sched.hlinux/sched/debug.hlinux/sched/signal.hlinux/signal.hlinux/kdebug.hlinux/uaccess.hlinux/kprobes.hlinux/uprobes.hasm/uprobes.hlinux/mm.hlinux/module.hlinux/irq.hlinux/kexec.hlinux/entry-common.hasm/asm-prototypes.hasm/bug.hasm/cfi.hasm/csr.hasm/processor.hasm/ptrace.hasm/syscall.hasm/thread_info.hasm/vector.hasm/irq_stack.h
Detected Declarations
enum misaligned_access_typefunction copy_codefunction dump_instrfunction diefunction do_trapfunction do_trap_errorfunction namefunction do_trap_insn_illegalfunction do_trap_misalignedfunction do_trap_load_misalignedfunction do_trap_store_misalignedfunction get_break_insn_lengthfunction probe_single_step_handlerfunction probe_breakpoint_handlerfunction handle_breakfunction do_trap_breakfunction do_trap_ecall_ufunction handle_user_cfi_violationfunction do_trap_software_checkfunction do_page_faultfunction handle_riscv_irqfunction do_irqfunction is_valid_bugaddrfunction handle_bad_stack
Annotated Snippet
if (!bad) {
p += sprintf(p, i == 0 ? "(%04hx) " : "%04hx ", val);
} else {
printk("%sCode: Unable to access instruction at 0x%px.\n",
loglvl, &insns[i]);
return;
}
}
printk("%sCode: %s\n", loglvl, str);
}
void die(struct pt_regs *regs, const char *str)
{
static int die_counter;
int ret;
long cause;
unsigned long flags;
oops_enter();
raw_spin_lock_irqsave(&die_lock, flags);
console_verbose();
bust_spinlocks(1);
pr_emerg("%s [#%d]\n", str, ++die_counter);
print_modules();
if (regs) {
show_regs(regs);
dump_instr(KERN_EMERG, regs);
}
cause = regs ? regs->cause : -1;
ret = notify_die(DIE_OOPS, str, regs, 0, cause, SIGSEGV);
if (kexec_should_crash(current))
crash_kexec(regs);
bust_spinlocks(0);
add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
raw_spin_unlock_irqrestore(&die_lock, flags);
oops_exit();
if (in_interrupt())
panic("Fatal exception in interrupt");
if (panic_on_oops)
panic("Fatal exception");
if (ret != NOTIFY_STOP)
make_task_dead(SIGSEGV);
}
void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr)
{
struct task_struct *tsk = current;
if (show_unhandled_signals && unhandled_signal(tsk, signo)
&& printk_ratelimit()) {
pr_info("%s[%d]: unhandled signal %d code 0x%x at 0x" REG_FMT,
tsk->comm, task_pid_nr(tsk), signo, code, addr);
print_vma_addr(KERN_CONT " in ", instruction_pointer(regs));
pr_cont("\n");
__show_regs(regs);
dump_instr(KERN_INFO, regs);
}
force_sig_fault(signo, code, (void __user *)addr);
}
static void do_trap_error(struct pt_regs *regs, int signo, int code,
unsigned long addr, const char *str)
{
current->thread.bad_cause = regs->cause;
if (user_mode(regs)) {
do_trap(regs, signo, code, addr);
} else {
if (!fixup_exception(regs))
die(regs, str);
}
}
#define __trap_section noinstr
#define DO_ERROR_INFO(name, signo, code, str) \
asmlinkage __visible __trap_section void name(struct pt_regs *regs) \
{ \
if (user_mode(regs)) { \
irqentry_enter_from_user_mode(regs); \
local_irq_enable(); \
do_trap_error(regs, signo, code, regs->epc, "Oops - " str); \
local_irq_disable(); \
irqentry_exit_to_user_mode(regs); \
Annotation
- Immediate include surface: `linux/cpu.h`, `linux/kernel.h`, `linux/init.h`, `linux/irqflags.h`, `linux/randomize_kstack.h`, `linux/sched.h`, `linux/sched/debug.h`, `linux/sched/signal.h`.
- Detected declarations: `enum misaligned_access_type`, `function copy_code`, `function dump_instr`, `function die`, `function do_trap`, `function do_trap_error`, `function name`, `function do_trap_insn_illegal`, `function do_trap_misaligned`, `function do_trap_load_misaligned`.
- Atlas domain: Architecture Layer / arch/riscv.
- 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.