]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/i386/kernel/kprobes.c
Pull osi-now into release branch
[linux-2.6-omap-h63xx.git] / arch / i386 / kernel / kprobes.c
index d98e44b16fe20fa1edbda6d0246bc95b3a49cede..dde828a333c3e8355e49d0a3ed8d562b3071d4f9 100644 (file)
@@ -31,8 +31,8 @@
 #include <linux/kprobes.h>
 #include <linux/ptrace.h>
 #include <linux/preempt.h>
+#include <linux/kdebug.h>
 #include <asm/cacheflush.h>
-#include <asm/kdebug.h>
 #include <asm/desc.h>
 #include <asm/uaccess.h>
 
@@ -184,7 +184,7 @@ void __kprobes arch_disarm_kprobe(struct kprobe *p)
 void __kprobes arch_remove_kprobe(struct kprobe *p)
 {
        mutex_lock(&kprobe_mutex);
-       free_insn_slot(p->ainsn.insn);
+       free_insn_slot(p->ainsn.insn, (p->ainsn.boostable == 1));
        mutex_unlock(&kprobe_mutex);
 }
 
@@ -226,24 +226,15 @@ static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
 }
 
 /* Called with kretprobe_lock held */
-void __kprobes arch_prepare_kretprobe(struct kretprobe *rp,
+void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
                                      struct pt_regs *regs)
 {
        unsigned long *sara = (unsigned long *)&regs->esp;
 
-       struct kretprobe_instance *ri;
+       ri->ret_addr = (kprobe_opcode_t *) *sara;
 
-       if ((ri = get_free_rp_inst(rp)) != NULL) {
-               ri->rp = rp;
-               ri->task = current;
-               ri->ret_addr = (kprobe_opcode_t *) *sara;
-
-               /* Replace the return addr with trampoline addr */
-               *sara = (unsigned long) &kretprobe_trampoline;
-               add_rp_inst(ri);
-       } else {
-               rp->nmissed++;
-       }
+       /* Replace the return addr with trampoline addr */
+       *sara = (unsigned long) &kretprobe_trampoline;
 }
 
 /*
@@ -333,7 +324,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
                return 1;
 
 ss_probe:
-#ifndef CONFIG_PREEMPT
+#if !defined(CONFIG_PREEMPT) || defined(CONFIG_PM)
        if (p->ainsn.boostable == 1 && !p->post_handler){
                /* Boost up -- we can execute copied instructions directly */
                reset_current_kprobe();
@@ -361,8 +352,11 @@ no_kprobe:
        asm volatile ( ".global kretprobe_trampoline\n"
                        "kretprobe_trampoline: \n"
                        "       pushf\n"
-                       /* skip cs, eip, orig_eax, es, ds */
-                       "       subl $20, %esp\n"
+                       /* skip cs, eip, orig_eax */
+                       "       subl $12, %esp\n"
+                       "       pushl %fs\n"
+                       "       pushl %ds\n"
+                       "       pushl %es\n"
                        "       pushl %eax\n"
                        "       pushl %ebp\n"
                        "       pushl %edi\n"
@@ -373,10 +367,10 @@ no_kprobe:
                        "       movl %esp, %eax\n"
                        "       call trampoline_handler\n"
                        /* move eflags to cs */
-                       "       movl 48(%esp), %edx\n"
-                       "       movl %edx, 44(%esp)\n"
+                       "       movl 52(%esp), %edx\n"
+                       "       movl %edx, 48(%esp)\n"
                        /* save true return address on eflags */
-                       "       movl %eax, 48(%esp)\n"
+                       "       movl %eax, 52(%esp)\n"
                        "       popl %ebx\n"
                        "       popl %ecx\n"
                        "       popl %edx\n"
@@ -384,8 +378,8 @@ no_kprobe:
                        "       popl %edi\n"
                        "       popl %ebp\n"
                        "       popl %eax\n"
-                       /* skip eip, orig_eax, es, ds */
-                       "       addl $16, %esp\n"
+                       /* skip eip, orig_eax, es, ds, fs */
+                       "       addl $20, %esp\n"
                        "       popf\n"
                        "       ret\n");
 }
@@ -404,6 +398,10 @@ fastcall void *__kprobes trampoline_handler(struct pt_regs *regs)
        INIT_HLIST_HEAD(&empty_rp);
        spin_lock_irqsave(&kretprobe_lock, flags);
        head = kretprobe_inst_table_head(current);
+       /* fixup registers */
+       regs->xcs = __KERNEL_CS | get_kernel_rpl();
+       regs->eip = trampoline_address;
+       regs->orig_eax = 0xffffffff;
 
        /*
         * It is possible to have multiple instances associated with a given
@@ -425,6 +423,7 @@ fastcall void *__kprobes trampoline_handler(struct pt_regs *regs)
 
                if (ri->rp && ri->rp->handler){
                        __get_cpu_var(current_kprobe) = &ri->rp->kp;
+                       get_kprobe_ctlblk()->kprobe_status = KPROBE_HIT_ACTIVE;
                        ri->rp->handler(ri, regs);
                        __get_cpu_var(current_kprobe) = NULL;
                }
@@ -441,8 +440,7 @@ fastcall void *__kprobes trampoline_handler(struct pt_regs *regs)
                        break;
        }
 
-       BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address));
-
+       kretprobe_assert(ri, orig_ret_address, trampoline_address);
        spin_unlock_irqrestore(&kretprobe_lock, flags);
 
        hlist_for_each_entry_safe(ri, node, tmp, &empty_rp, hlist) {
@@ -745,6 +743,11 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
        return 0;
 }
 
+int __kprobes arch_trampoline_kprobe(struct kprobe *p)
+{
+       return 0;
+}
+
 int __init arch_init_kprobes(void)
 {
        return 0;