123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- #include <linux/sched.h>
- #include <linux/kdebug.h>
- #include <linux/uaccess.h>
- #include <linux/ptrace.h>
- #include <linux/kprobes.h>
- #include <linux/kgdb.h>
- #include <asm/setup.h>
- #include <asm/unaligned.h>
- #include <asm/kprobes.h>
- void __init trap_init(void)
- {
- return;
- }
- void die(const char *str, struct pt_regs *regs, unsigned long address)
- {
- show_kernel_fault_diag(str, regs, address);
-
- __asm__("flag 1");
- }
- static noinline int
- unhandled_exception(const char *str, struct pt_regs *regs, siginfo_t *info)
- {
- if (user_mode(regs)) {
- struct task_struct *tsk = current;
- tsk->thread.fault_address = (__force unsigned int)info->si_addr;
- force_sig_info(info->si_signo, info, tsk);
- } else {
-
- if (fixup_exception(regs))
- return 0;
- die(str, regs, (unsigned long)info->si_addr);
- }
- return 1;
- }
- #define DO_ERROR_INFO(signr, str, name, sicode) \
- int name(unsigned long address, struct pt_regs *regs) \
- { \
- siginfo_t info = { \
- .si_signo = signr, \
- .si_errno = 0, \
- .si_code = sicode, \
- .si_addr = (void __user *)address, \
- }; \
- return unhandled_exception(str, regs, &info);\
- }
- DO_ERROR_INFO(SIGILL, "Priv Op/Disabled Extn", do_privilege_fault, ILL_PRVOPC)
- DO_ERROR_INFO(SIGILL, "Invalid Extn Insn", do_extension_fault, ILL_ILLOPC)
- DO_ERROR_INFO(SIGILL, "Illegal Insn (or Seq)", insterror_is_error, ILL_ILLOPC)
- DO_ERROR_INFO(SIGBUS, "Invalid Mem Access", do_memory_error, BUS_ADRERR)
- DO_ERROR_INFO(SIGTRAP, "Breakpoint Set", trap_is_brkpt, TRAP_BRKPT)
- DO_ERROR_INFO(SIGBUS, "Misaligned Access", do_misaligned_error, BUS_ADRALN)
- int do_misaligned_access(unsigned long address, struct pt_regs *regs,
- struct callee_regs *cregs)
- {
-
- if (misaligned_fixup(address, regs, cregs) != 0)
- return do_misaligned_error(address, regs);
- return 0;
- }
- void do_machine_check_fault(unsigned long address, struct pt_regs *regs)
- {
- die("Machine Check Exception", regs, address);
- }
- void do_non_swi_trap(unsigned long address, struct pt_regs *regs)
- {
- unsigned int param = regs->ecr_param;
- switch (param) {
- case 1:
- trap_is_brkpt(address, regs);
- break;
- case 2:
- trap_is_kprobe(address, regs);
- break;
- case 3:
- case 4:
- kgdb_trap(regs);
- break;
- default:
- break;
- }
- }
- void do_insterror_or_kprobe(unsigned long address, struct pt_regs *regs)
- {
- int rc;
-
- rc = notify_die(DIE_IERR, "kprobe_ierr", regs, address, 0, SIGILL);
- if (rc == NOTIFY_STOP)
- return;
- insterror_is_error(address, regs);
- }
|