arch/x86/kernel/traps.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/traps.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/traps.c- Extension
.c- Size
- 46168 bytes
- Lines
- 1678
- 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/context_tracking.hlinux/interrupt.hlinux/kallsyms.hlinux/kmsan.hlinux/spinlock.hlinux/kprobes.hlinux/uaccess.hlinux/kdebug.hlinux/kgdb.hlinux/kernel.hlinux/export.hlinux/ptrace.hlinux/uprobes.hlinux/string.hlinux/delay.hlinux/errno.hlinux/kexec.hlinux/sched.hlinux/sched/task_stack.hlinux/static_call.hlinux/timer.hlinux/init.hlinux/bug.hlinux/nmi.hlinux/mm.hlinux/smp.hlinux/cpu.hlinux/io.hlinux/hardirq.hlinux/atomic.hlinux/iommu.hlinux/ubsan.h
Detected Declarations
enum kernel_gp_hintfunction is_valid_bugaddrfunction decode_bugfunction pt_regs_valfunction do_trap_no_signalfunction show_signalfunction do_trapfunction do_error_trapfunction SIGILLfunction handle_bugfunction handle_stack_overflowfunction always_truefunction nmi_enterfunction get_kernel_gp_addressfunction fixup_iopl_exceptionfunction try_fixup_enqcmd_gpfunction gp_try_fixup_and_notifyfunction gp_user_force_sig_segvfunction do_int3function do_int3_userfunction irqentry_enter_from_user_modefunction is_sysenter_singlestepfunction debug_read_reset_dr6function placesfunction exc_debug_kernelfunction exc_debug_userfunction math_errorfunction APICfunction ve_raise_faultfunction Exceptionsfunction trap_init
Annotated Snippet
if (v == INSN_LOCK) {
lock = true;
continue;
}
if ((v & 0xf0) == 0x40) {
rex = v;
continue;
}
break;
}
switch (v) {
case 0x70 ... 0x7f: /* Jcc.d8 */
addr += 1; /* d8 */
*len = addr - start;
WARN_ON_ONCE(!lock);
return BUG_LOCK;
case 0xd6:
*len = addr - start;
return BUG_UDB;
case OPCODE_ESCAPE:
break;
default:
return BUG_NONE;
}
v = *(u8 *)(addr++);
if (v == SECOND_BYTE_OPCODE_UD2) {
*len = addr - start;
return BUG_UD2;
}
if (v != SECOND_BYTE_OPCODE_UD1)
return BUG_NONE;
*imm = 0;
v = *(u8 *)(addr++); /* ModRM */
if (X86_MODRM_MOD(v) != 3 && X86_MODRM_RM(v) == 4)
addr++; /* SIB */
reg = X86_MODRM_REG(v) + 8*!!X86_REX_R(rex);
rm = X86_MODRM_RM(v) + 8*!!X86_REX_B(rex);
/* Decode immediate, if present */
switch (X86_MODRM_MOD(v)) {
case 0: if (X86_MODRM_RM(v) == 5)
addr += 4; /* RIP + disp32 */
if (rm == 0) /* (%eax) */
type = BUG_UD1_UBSAN;
if (rm == 2) { /* (%edx) */
*imm = reg;
type = BUG_UD1_WARN;
}
break;
case 1: *imm = *(s8 *)addr;
addr += 1;
if (rm == 0) /* (%eax) */
type = BUG_UD1_UBSAN;
break;
case 2: *imm = *(s32 *)addr;
addr += 4;
if (rm == 0) /* (%eax) */
type = BUG_UD1_UBSAN;
break;
case 3: break;
}
/* record instruction length */
*len = addr - start;
return type;
}
static inline unsigned long pt_regs_val(struct pt_regs *regs, int nr)
{
int offset = pt_regs_offset(regs, nr);
if (WARN_ON_ONCE(offset < -0))
return 0;
return *((unsigned long *)((void *)regs + offset));
Annotation
- Immediate include surface: `linux/context_tracking.h`, `linux/interrupt.h`, `linux/kallsyms.h`, `linux/kmsan.h`, `linux/spinlock.h`, `linux/kprobes.h`, `linux/uaccess.h`, `linux/kdebug.h`.
- Detected declarations: `enum kernel_gp_hint`, `function is_valid_bugaddr`, `function decode_bug`, `function pt_regs_val`, `function do_trap_no_signal`, `function show_signal`, `function do_trap`, `function do_error_trap`, `function SIGILL`, `function handle_bug`.
- 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.