arch/arm64/kernel/traps.c
Source file repositories/reference/linux-study-clean/arch/arm64/kernel/traps.c
File Facts
- System
- Linux kernel
- Corpus path
arch/arm64/kernel/traps.c- Extension
.c- Size
- 27777 bytes
- Lines
- 1104
- Domain
- Architecture Layer
- Bucket
- arch/arm64
- 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/bug.hlinux/context_tracking.hlinux/signal.hlinux/kallsyms.hlinux/kprobes.hlinux/spinlock.hlinux/uaccess.hlinux/hardirq.hlinux/kdebug.hlinux/module.hlinux/kexec.hlinux/delay.hlinux/efi.hlinux/init.hlinux/sched/signal.hlinux/sched/debug.hlinux/sched/task_stack.hlinux/sizes.hlinux/syscalls.hlinux/mm_types.hlinux/kasan.hlinux/ubsan.hlinux/cfi.hasm/atomic.hasm/bug.hasm/cpufeature.hasm/daifflags.hasm/debug-monitors.hasm/efi.hasm/esr.hasm/exception.hasm/extable.h
Detected Declarations
struct sys64_hookfunction Copyrightfunction __check_nefunction __check_csfunction __check_ccfunction __check_mifunction __check_plfunction __check_vsfunction __check_vcfunction __check_hifunction __check_lsfunction __check_gefunction __check_ltfunction __check_gtfunction __check_lefunction __check_alfunction dump_kernel_instrfunction __diefunction diefunction arm64_show_signalfunction arm64_force_sig_faultfunction arm64_force_sig_fault_pkeyfunction arm64_force_sig_mceerrfunction arm64_force_sig_ptrace_errno_trapfunction arm64_notify_diefunction compat_get_it_statefunction compat_set_it_statefunction advance_itstatefunction advance_itstatefunction user_insn_readfunction force_signal_injectfunction siginfo_layoutfunction arm64_notify_segfaultfunction do_el0_undeffunction do_el1_undeffunction do_el0_btifunction do_el1_btifunction do_el0_gcsfunction do_el1_gcsfunction do_el0_fpacfunction do_el1_fpacfunction do_el0_mopsfunction do_el1_mopsfunction user_cache_maint_handlerfunction ctr_read_handlerfunction cntvct_read_handlerfunction cntfrq_read_handlerfunction mrs_handler
Annotated Snippet
struct sys64_hook {
unsigned long esr_mask;
unsigned long esr_val;
void (*handler)(unsigned long esr, struct pt_regs *regs);
};
static const struct sys64_hook sys64_hooks[] = {
{
.esr_mask = ESR_ELx_SYS64_ISS_EL0_CACHE_OP_MASK,
.esr_val = ESR_ELx_SYS64_ISS_EL0_CACHE_OP_VAL,
.handler = user_cache_maint_handler,
},
{
/* Trap read access to CTR_EL0 */
.esr_mask = ESR_ELx_SYS64_ISS_SYS_OP_MASK,
.esr_val = ESR_ELx_SYS64_ISS_SYS_CTR_READ,
.handler = ctr_read_handler,
},
{
/* Trap read access to CNTVCT_EL0 */
.esr_mask = ESR_ELx_SYS64_ISS_SYS_OP_MASK,
.esr_val = ESR_ELx_SYS64_ISS_SYS_CNTVCT,
.handler = cntvct_read_handler,
},
{
/* Trap read access to CNTVCTSS_EL0 */
.esr_mask = ESR_ELx_SYS64_ISS_SYS_OP_MASK,
.esr_val = ESR_ELx_SYS64_ISS_SYS_CNTVCTSS,
.handler = cntvct_read_handler,
},
{
/* Trap read access to CNTFRQ_EL0 */
.esr_mask = ESR_ELx_SYS64_ISS_SYS_OP_MASK,
.esr_val = ESR_ELx_SYS64_ISS_SYS_CNTFRQ,
.handler = cntfrq_read_handler,
},
{
/* Trap read access to CPUID registers */
.esr_mask = ESR_ELx_SYS64_ISS_SYS_MRS_OP_MASK,
.esr_val = ESR_ELx_SYS64_ISS_SYS_MRS_OP_VAL,
.handler = mrs_handler,
},
{
/* Trap WFI instructions executed in userspace */
.esr_mask = ESR_ELx_WFx_MASK,
.esr_val = ESR_ELx_WFx_WFI_VAL,
.handler = wfi_handler,
},
{},
};
#ifdef CONFIG_COMPAT
static bool cp15_cond_valid(unsigned long esr, struct pt_regs *regs)
{
int cond;
/* Only a T32 instruction can trap without CV being set */
if (!(esr & ESR_ELx_CV)) {
u32 it;
it = compat_get_it_state(regs);
if (!it)
return true;
cond = it >> 4;
} else {
cond = (esr & ESR_ELx_COND_MASK) >> ESR_ELx_COND_SHIFT;
}
return aarch32_opcode_cond_checks[cond](regs->pstate);
}
static void compat_cntfrq_read_handler(unsigned long esr, struct pt_regs *regs)
{
int reg = (esr & ESR_ELx_CP15_32_ISS_RT_MASK) >> ESR_ELx_CP15_32_ISS_RT_SHIFT;
pt_regs_write_reg(regs, reg, arch_timer_get_rate());
arm64_skip_faulting_instruction(regs, 4);
}
static const struct sys64_hook cp15_32_hooks[] = {
{
.esr_mask = ESR_ELx_CP15_32_ISS_SYS_MASK,
.esr_val = ESR_ELx_CP15_32_ISS_SYS_CNTFRQ,
.handler = compat_cntfrq_read_handler,
},
{},
};
static void compat_cntvct_read_handler(unsigned long esr, struct pt_regs *regs)
Annotation
- Immediate include surface: `linux/bug.h`, `linux/context_tracking.h`, `linux/signal.h`, `linux/kallsyms.h`, `linux/kprobes.h`, `linux/spinlock.h`, `linux/uaccess.h`, `linux/hardirq.h`.
- Detected declarations: `struct sys64_hook`, `function Copyright`, `function __check_ne`, `function __check_cs`, `function __check_cc`, `function __check_mi`, `function __check_pl`, `function __check_vs`, `function __check_vc`, `function __check_hi`.
- Atlas domain: Architecture Layer / arch/arm64.
- 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.