3 #include <linux/types.h>
4 #include <linux/kdebug.h>
5 #include <linux/signal.h>
6 #include <linux/sched.h>
7 #include <linux/uaccess.h>
8 #include <asm/unwinder.h>
9 #include <asm/system.h>
12 void handle_BUG(struct pt_regs *regs)
14 const struct bug_entry *bug;
15 unsigned long bugaddr = regs->pc;
16 enum bug_trap_type tt;
18 if (!is_valid_bugaddr(bugaddr))
21 bug = find_bug(bugaddr);
23 /* Switch unwinders when unwind_stack() is called */
24 if (bug->flags & BUGFLAG_UNWINDER)
27 tt = report_bug(bugaddr, regs);
28 if (tt == BUG_TRAP_TYPE_WARN) {
29 regs->pc += instruction_size(bugaddr);
34 die("Kernel BUG", regs, TRAPA_BUG_OPCODE & 0xff);
37 int is_valid_bugaddr(unsigned long addr)
41 if (addr < PAGE_OFFSET)
43 if (probe_kernel_address((insn_size_t *)addr, opcode))
45 if (opcode == TRAPA_BUG_OPCODE)
53 * Generic trap handler.
55 BUILD_TRAP_HANDLER(debug)
60 regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
62 if (notify_die(DIE_TRAP, "debug trap", regs, 0, vec & 0xff,
63 SIGTRAP) == NOTIFY_STOP)
66 force_sig(SIGTRAP, current);
70 * Special handler for BUG() traps.
72 BUILD_TRAP_HANDLER(bug)
77 regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
79 if (notify_die(DIE_TRAP, "bug trap", regs, 0, TRAPA_BUG_OPCODE & 0xff,
80 SIGTRAP) == NOTIFY_STOP)
84 if (__kernel_text_address(instruction_pointer(regs))) {
85 insn_size_t insn = *(insn_size_t *)instruction_pointer(regs);
86 if (insn == TRAPA_BUG_OPCODE)
92 force_sig(SIGTRAP, current);