traps.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <linux/bug.h>
  2. #include <linux/io.h>
  3. #include <linux/types.h>
  4. #include <linux/kdebug.h>
  5. #include <asm/system.h>
  6. #ifdef CONFIG_BUG
  7. static void handle_BUG(struct pt_regs *regs)
  8. {
  9. enum bug_trap_type tt;
  10. tt = report_bug(regs->pc, regs);
  11. if (tt == BUG_TRAP_TYPE_WARN) {
  12. regs->pc += instruction_size(regs->pc);
  13. return;
  14. }
  15. die("Kernel BUG", regs, TRAPA_BUG_OPCODE & 0xff);
  16. }
  17. int is_valid_bugaddr(unsigned long addr)
  18. {
  19. return addr >= PAGE_OFFSET;
  20. }
  21. #endif
  22. /*
  23. * Generic trap handler.
  24. */
  25. BUILD_TRAP_HANDLER(debug)
  26. {
  27. TRAP_HANDLER_DECL;
  28. /* Rewind */
  29. regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
  30. if (notify_die(DIE_TRAP, "debug trap", regs, 0, vec & 0xff,
  31. SIGTRAP) == NOTIFY_STOP)
  32. return;
  33. force_sig(SIGTRAP, current);
  34. }
  35. /*
  36. * Special handler for BUG() traps.
  37. */
  38. BUILD_TRAP_HANDLER(bug)
  39. {
  40. TRAP_HANDLER_DECL;
  41. /* Rewind */
  42. regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
  43. if (notify_die(DIE_TRAP, "bug trap", regs, 0, TRAPA_BUG_OPCODE & 0xff,
  44. SIGTRAP) == NOTIFY_STOP)
  45. return;
  46. #ifdef CONFIG_BUG
  47. if (__kernel_text_address(instruction_pointer(regs))) {
  48. opcode_t insn = *(opcode_t *)instruction_pointer(regs);
  49. if (insn == TRAPA_BUG_OPCODE)
  50. handle_BUG(regs);
  51. }
  52. #endif
  53. force_sig(SIGTRAP, current);
  54. }