MIPS: kprobe: Add support.
[firefly-linux-kernel-4.4.55.git] / arch / mips / kernel / traps.c
index 852780868fb4914e4711107e96c388e1ad8ab38d..4c6079f24958a478d86a8bf2e48fef23cf9cb9db 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/ptrace.h>
 #include <linux/kgdb.h>
 #include <linux/kdebug.h>
+#include <linux/kprobes.h>
 #include <linux/notifier.h>
 #include <linux/kdb.h>
 
@@ -334,7 +335,7 @@ void show_regs(struct pt_regs *regs)
        __show_regs((struct pt_regs *)regs);
 }
 
-void show_registers(const struct pt_regs *regs)
+void show_registers(struct pt_regs *regs)
 {
        const int field = 2 * sizeof(unsigned long);
 
@@ -783,6 +784,25 @@ asmlinkage void do_bp(struct pt_regs *regs)
        if (bcode >= (1 << 10))
                bcode >>= 10;
 
+       /*
+        * notify the kprobe handlers, if instruction is likely to
+        * pertain to them.
+        */
+       switch (bcode) {
+       case BRK_KPROBE_BP:
+               if (notify_die(DIE_BREAK, "debug", regs, bcode, 0, 0) == NOTIFY_STOP)
+                       return;
+               else
+                       break;
+       case BRK_KPROBE_SSTEPBP:
+               if (notify_die(DIE_SSTEPBP, "single_step", regs, bcode, 0, 0) == NOTIFY_STOP)
+                       return;
+               else
+                       break;
+       default:
+               break;
+       }
+
        do_trap_or_bp(regs, bcode, "Break");
        return;
 
@@ -907,11 +927,6 @@ static int default_cu2_call(struct notifier_block *nfb, unsigned long action,
        return NOTIFY_OK;
 }
 
-static struct notifier_block default_cu2_notifier = {
-       .notifier_call  = default_cu2_call,
-       .priority       = 0x80000000,           /* Run last  */
-};
-
 asmlinkage void do_cpu(struct pt_regs *regs)
 {
        unsigned int __user *epc;
@@ -1734,5 +1749,5 @@ void __init trap_init(void)
 
        sort_extable(__start___dbe_table, __stop___dbe_table);
 
-       register_cu2_notifier(&default_cu2_notifier);
+       cu2_notifier(default_cu2_call, 0x80000000);     /* Run last  */
 }