block: disable sysfs parts of the disk command filter
[safe/jmp/linux-2.6] / include / linux / kprobes.h
index f20c163..0be7795 100644 (file)
  *             Rusty Russell).
  * 2004-July   Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes
  *             interface to access function arguments.
+ * 2005-May    Hien Nguyen <hien@us.ibm.com> and Jim Keniston
+ *             <jkenisto@us.ibm.com>  and Prasanna S Panchamukhi
+ *             <prasanna@in.ibm.com> added function-return probes.
  */
-#include <linux/config.h>
 #include <linux/list.h>
 #include <linux/notifier.h>
 #include <linux/smp.h>
+#include <linux/percpu.h>
+#include <linux/spinlock.h>
+#include <linux/rcupdate.h>
+#include <linux/mutex.h>
+
+#ifdef CONFIG_KPROBES
 #include <asm/kprobes.h>
 
+/* kprobe_status settings */
+#define KPROBE_HIT_ACTIVE      0x00000001
+#define KPROBE_HIT_SS          0x00000002
+#define KPROBE_REENTER         0x00000004
+#define KPROBE_HIT_SSDONE      0x00000008
+
+/* Attach to insert probes on any functions which should be ignored*/
+#define __kprobes      __attribute__((__section__(".kprobes.text")))
+
 struct kprobe;
 struct pt_regs;
+struct kretprobe;
+struct kretprobe_instance;
 typedef int (*kprobe_pre_handler_t) (struct kprobe *, struct pt_regs *);
 typedef int (*kprobe_break_handler_t) (struct kprobe *, struct pt_regs *);
 typedef void (*kprobe_post_handler_t) (struct kprobe *, struct pt_regs *,
                                       unsigned long flags);
 typedef int (*kprobe_fault_handler_t) (struct kprobe *, struct pt_regs *,
                                       int trapnr);
+typedef int (*kretprobe_handler_t) (struct kretprobe_instance *,
+                                   struct pt_regs *);
+
 struct kprobe {
        struct hlist_node hlist;
 
+       /* list of kprobes for multi-handler support */
+       struct list_head list;
+
+       /* Indicates that the corresponding module has been ref counted */
+       unsigned int mod_refcounted;
+
+       /*count the number of times this probe was temporarily disarmed */
+       unsigned long nmissed;
+
        /* location of the probe point */
        kprobe_opcode_t *addr;
 
+       /* Allow user to indicate symbol name of the probe point */
+       const char *symbol_name;
+
+       /* Offset into the symbol */
+       unsigned int offset;
+
        /* Called before addr is executed. */
        kprobe_pre_handler_t pre_handler;
 
@@ -79,58 +116,205 @@ struct kprobe {
  */
 struct jprobe {
        struct kprobe kp;
-       kprobe_opcode_t *entry; /* probe handling code to jump to */
+       void *entry;    /* probe handling code to jump to */
 };
 
-#ifdef CONFIG_KPROBES
-/* Locks kprobe: irq must be disabled */
-void lock_kprobes(void);
-void unlock_kprobes(void);
+/* For backward compatibility with old code using JPROBE_ENTRY() */
+#define JPROBE_ENTRY(handler)  (handler)
+
+DECLARE_PER_CPU(struct kprobe *, current_kprobe);
+DECLARE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
+
+#ifdef CONFIG_KRETPROBES
+extern void arch_prepare_kretprobe(struct kretprobe_instance *ri,
+                                  struct pt_regs *regs);
+extern int arch_trampoline_kprobe(struct kprobe *p);
+#else /* CONFIG_KRETPROBES */
+static inline void arch_prepare_kretprobe(struct kretprobe *rp,
+                                       struct pt_regs *regs)
+{
+}
+static inline int arch_trampoline_kprobe(struct kprobe *p)
+{
+       return 0;
+}
+#endif /* CONFIG_KRETPROBES */
+/*
+ * Function-return probe -
+ * Note:
+ * User needs to provide a handler function, and initialize maxactive.
+ * maxactive - The maximum number of instances of the probed function that
+ * can be active concurrently.
+ * nmissed - tracks the number of times the probed function's return was
+ * ignored, due to maxactive being too low.
+ *
+ */
+struct kretprobe {
+       struct kprobe kp;
+       kretprobe_handler_t handler;
+       kretprobe_handler_t entry_handler;
+       int maxactive;
+       int nmissed;
+       size_t data_size;
+       struct hlist_head free_instances;
+       spinlock_t lock;
+};
+
+struct kretprobe_instance {
+       struct hlist_node hlist;
+       struct kretprobe *rp;
+       kprobe_opcode_t *ret_addr;
+       struct task_struct *task;
+       char data[0];
+};
+
+struct kretprobe_blackpoint {
+       const char *name;
+       void *addr;
+};
 
-/* kprobe running now on this CPU? */
-static inline int kprobe_running(void)
+struct kprobe_blackpoint {
+       const char *name;
+       unsigned long start_addr;
+       unsigned long range;
+};
+
+extern struct kretprobe_blackpoint kretprobe_blacklist[];
+
+static inline void kretprobe_assert(struct kretprobe_instance *ri,
+       unsigned long orig_ret_address, unsigned long trampoline_address)
 {
-       extern unsigned int kprobe_cpu;
-       return kprobe_cpu == smp_processor_id();
+       if (!orig_ret_address || (orig_ret_address == trampoline_address)) {
+               printk("kretprobe BUG!: Processing kretprobe %p @ %p\n",
+                               ri->rp, ri->rp->kp.addr);
+               BUG();
+       }
 }
 
+#ifdef CONFIG_KPROBES_SANITY_TEST
+extern int init_test_probes(void);
+#else
+static inline int init_test_probes(void)
+{
+       return 0;
+}
+#endif /* CONFIG_KPROBES_SANITY_TEST */
+
+extern struct mutex kprobe_mutex;
 extern int arch_prepare_kprobe(struct kprobe *p);
-extern void arch_copy_kprobe(struct kprobe *p);
-extern void arch_remove_kprobe(struct kprobe *p);
+extern void arch_arm_kprobe(struct kprobe *p);
+extern void arch_disarm_kprobe(struct kprobe *p);
+extern int arch_init_kprobes(void);
 extern void show_registers(struct pt_regs *regs);
+extern kprobe_opcode_t *get_insn_slot(void);
+extern void free_insn_slot(kprobe_opcode_t *slot, int dirty);
+extern void kprobes_inc_nmissed_count(struct kprobe *p);
 
-/* Get the kprobe at this addr (if any).  Must have called lock_kprobes */
+/* Get the kprobe at this addr (if any) - called with preemption disabled */
 struct kprobe *get_kprobe(void *addr);
+void kretprobe_hash_lock(struct task_struct *tsk,
+                        struct hlist_head **head, unsigned long *flags);
+void kretprobe_hash_unlock(struct task_struct *tsk, unsigned long *flags);
+struct hlist_head * kretprobe_inst_table_head(struct task_struct *tsk);
+
+/* kprobe_running() will just return the current_kprobe on this CPU */
+static inline struct kprobe *kprobe_running(void)
+{
+       return (__get_cpu_var(current_kprobe));
+}
+
+static inline void reset_current_kprobe(void)
+{
+       __get_cpu_var(current_kprobe) = NULL;
+}
+
+static inline struct kprobe_ctlblk *get_kprobe_ctlblk(void)
+{
+       return (&__get_cpu_var(kprobe_ctlblk));
+}
 
 int register_kprobe(struct kprobe *p);
 void unregister_kprobe(struct kprobe *p);
+int register_kprobes(struct kprobe **kps, int num);
+void unregister_kprobes(struct kprobe **kps, int num);
 int setjmp_pre_handler(struct kprobe *, struct pt_regs *);
 int longjmp_break_handler(struct kprobe *, struct pt_regs *);
 int register_jprobe(struct jprobe *p);
 void unregister_jprobe(struct jprobe *p);
+int register_jprobes(struct jprobe **jps, int num);
+void unregister_jprobes(struct jprobe **jps, int num);
 void jprobe_return(void);
+unsigned long arch_deref_entry_point(void *);
 
-#else
-static inline int kprobe_running(void)
+int register_kretprobe(struct kretprobe *rp);
+void unregister_kretprobe(struct kretprobe *rp);
+int register_kretprobes(struct kretprobe **rps, int num);
+void unregister_kretprobes(struct kretprobe **rps, int num);
+
+void kprobe_flush_task(struct task_struct *tk);
+void recycle_rp_inst(struct kretprobe_instance *ri, struct hlist_head *head);
+
+#else /* CONFIG_KPROBES */
+
+#define __kprobes      /**/
+struct jprobe;
+struct kretprobe;
+
+static inline struct kprobe *get_kprobe(void *addr)
 {
-       return 0;
+       return NULL;
+}
+static inline struct kprobe *kprobe_running(void)
+{
+       return NULL;
 }
 static inline int register_kprobe(struct kprobe *p)
 {
        return -ENOSYS;
 }
+static inline int register_kprobes(struct kprobe **kps, int num)
+{
+       return -ENOSYS;
+}
 static inline void unregister_kprobe(struct kprobe *p)
 {
 }
+static inline void unregister_kprobes(struct kprobe **kps, int num)
+{
+}
 static inline int register_jprobe(struct jprobe *p)
 {
        return -ENOSYS;
 }
+static inline int register_jprobes(struct jprobe **jps, int num)
+{
+       return -ENOSYS;
+}
 static inline void unregister_jprobe(struct jprobe *p)
 {
 }
+static inline void unregister_jprobes(struct jprobe **jps, int num)
+{
+}
 static inline void jprobe_return(void)
 {
 }
-#endif
+static inline int register_kretprobe(struct kretprobe *rp)
+{
+       return -ENOSYS;
+}
+static inline int register_kretprobes(struct kretprobe **rps, int num)
+{
+       return -ENOSYS;
+}
+static inline void unregister_kretprobe(struct kretprobe *rp)
+{
+}
+static inline void unregister_kretprobes(struct kretprobe **rps, int num)
+{
+}
+static inline void kprobe_flush_task(struct task_struct *tk)
+{
+}
+#endif                         /* CONFIG_KPROBES */
 #endif                         /* _LINUX_KPROBES_H */