11da177e4SLinus Torvalds #ifndef _LINUX_KPROBES_H 21da177e4SLinus Torvalds #define _LINUX_KPROBES_H 31da177e4SLinus Torvalds /* 41da177e4SLinus Torvalds * Kernel Probes (KProbes) 51da177e4SLinus Torvalds * include/linux/kprobes.h 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 81da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 91da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 101da177e4SLinus Torvalds * (at your option) any later version. 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, 131da177e4SLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 141da177e4SLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 151da177e4SLinus Torvalds * GNU General Public License for more details. 161da177e4SLinus Torvalds * 171da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 181da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 191da177e4SLinus Torvalds * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 201da177e4SLinus Torvalds * 211da177e4SLinus Torvalds * Copyright (C) IBM Corporation, 2002, 2004 221da177e4SLinus Torvalds * 231da177e4SLinus Torvalds * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel 241da177e4SLinus Torvalds * Probes initial implementation ( includes suggestions from 251da177e4SLinus Torvalds * Rusty Russell). 261da177e4SLinus Torvalds * 2004-July Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes 271da177e4SLinus Torvalds * interface to access function arguments. 28b94cce92SHien Nguyen * 2005-May Hien Nguyen <hien@us.ibm.com> and Jim Keniston 29b94cce92SHien Nguyen * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi 30b94cce92SHien Nguyen * <prasanna@in.ibm.com> added function-return probes. 311da177e4SLinus Torvalds */ 3236dcd67aSIngo Molnar #include <linux/linkage.h> 331da177e4SLinus Torvalds #include <linux/list.h> 341da177e4SLinus Torvalds #include <linux/notifier.h> 351da177e4SLinus Torvalds #include <linux/smp.h> 36187f1882SPaul Gortmaker #include <linux/bug.h> 37e6584523SAnanth N Mavinakayanahalli #include <linux/percpu.h> 383516a460SAnanth N Mavinakayanahalli #include <linux/spinlock.h> 393516a460SAnanth N Mavinakayanahalli #include <linux/rcupdate.h> 407a7d1cf9SIngo Molnar #include <linux/mutex.h> 41*ae6aa16fSMasami Hiramatsu #include <linux/ftrace.h> 42b94cce92SHien Nguyen 4300d7c05aSKeshavamurthy Anil S #ifdef CONFIG_KPROBES 441da177e4SLinus Torvalds #include <asm/kprobes.h> 451da177e4SLinus Torvalds 46ea32c65cSPrasanna S Panchamukhi /* kprobe_status settings */ 47ea32c65cSPrasanna S Panchamukhi #define KPROBE_HIT_ACTIVE 0x00000001 48ea32c65cSPrasanna S Panchamukhi #define KPROBE_HIT_SS 0x00000002 49ea32c65cSPrasanna S Panchamukhi #define KPROBE_REENTER 0x00000004 50ea32c65cSPrasanna S Panchamukhi #define KPROBE_HIT_SSDONE 0x00000008 51ea32c65cSPrasanna S Panchamukhi 52*ae6aa16fSMasami Hiramatsu /* 53*ae6aa16fSMasami Hiramatsu * If function tracer is enabled and the arch supports full 54*ae6aa16fSMasami Hiramatsu * passing of pt_regs to function tracing, then kprobes can 55*ae6aa16fSMasami Hiramatsu * optimize on top of function tracing. 56*ae6aa16fSMasami Hiramatsu */ 57*ae6aa16fSMasami Hiramatsu #if defined(CONFIG_FUNCTION_TRACER) && defined(ARCH_SUPPORTS_FTRACE_SAVE_REGS) \ 58*ae6aa16fSMasami Hiramatsu && defined(ARCH_SUPPORTS_KPROBES_ON_FTRACE) 59*ae6aa16fSMasami Hiramatsu # define KPROBES_CAN_USE_FTRACE 60*ae6aa16fSMasami Hiramatsu #endif 61*ae6aa16fSMasami Hiramatsu 62d0aaff97SPrasanna S Panchamukhi /* Attach to insert probes on any functions which should be ignored*/ 63fe832a3aSSteven Rostedt #define __kprobes __attribute__((__section__(".kprobes.text"))) 64*ae6aa16fSMasami Hiramatsu 65dc19835dSMasami Hiramatsu #else /* CONFIG_KPROBES */ 66dc19835dSMasami Hiramatsu typedef int kprobe_opcode_t; 67dc19835dSMasami Hiramatsu struct arch_specific_insn { 68dc19835dSMasami Hiramatsu int dummy; 69dc19835dSMasami Hiramatsu }; 70fe832a3aSSteven Rostedt #define __kprobes 71*ae6aa16fSMasami Hiramatsu 72dc19835dSMasami Hiramatsu #endif /* CONFIG_KPROBES */ 73d0aaff97SPrasanna S Panchamukhi 741da177e4SLinus Torvalds struct kprobe; 751da177e4SLinus Torvalds struct pt_regs; 76b94cce92SHien Nguyen struct kretprobe; 77b94cce92SHien Nguyen struct kretprobe_instance; 781da177e4SLinus Torvalds typedef int (*kprobe_pre_handler_t) (struct kprobe *, struct pt_regs *); 791da177e4SLinus Torvalds typedef int (*kprobe_break_handler_t) (struct kprobe *, struct pt_regs *); 801da177e4SLinus Torvalds typedef void (*kprobe_post_handler_t) (struct kprobe *, struct pt_regs *, 811da177e4SLinus Torvalds unsigned long flags); 821da177e4SLinus Torvalds typedef int (*kprobe_fault_handler_t) (struct kprobe *, struct pt_regs *, 831da177e4SLinus Torvalds int trapnr); 84b94cce92SHien Nguyen typedef int (*kretprobe_handler_t) (struct kretprobe_instance *, 85b94cce92SHien Nguyen struct pt_regs *); 86b94cce92SHien Nguyen 871da177e4SLinus Torvalds struct kprobe { 881da177e4SLinus Torvalds struct hlist_node hlist; 891da177e4SLinus Torvalds 9064f562c6SAnanth N Mavinakayanahalli /* list of kprobes for multi-handler support */ 9164f562c6SAnanth N Mavinakayanahalli struct list_head list; 9264f562c6SAnanth N Mavinakayanahalli 93ea32c65cSPrasanna S Panchamukhi /*count the number of times this probe was temporarily disarmed */ 94ea32c65cSPrasanna S Panchamukhi unsigned long nmissed; 95ea32c65cSPrasanna S Panchamukhi 961da177e4SLinus Torvalds /* location of the probe point */ 971da177e4SLinus Torvalds kprobe_opcode_t *addr; 981da177e4SLinus Torvalds 993a872d89SAnanth N Mavinakayanahalli /* Allow user to indicate symbol name of the probe point */ 1009b3af29bSAnanth N Mavinakayanahalli const char *symbol_name; 1013a872d89SAnanth N Mavinakayanahalli 1023a872d89SAnanth N Mavinakayanahalli /* Offset into the symbol */ 1033a872d89SAnanth N Mavinakayanahalli unsigned int offset; 1043a872d89SAnanth N Mavinakayanahalli 1051da177e4SLinus Torvalds /* Called before addr is executed. */ 1061da177e4SLinus Torvalds kprobe_pre_handler_t pre_handler; 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds /* Called after addr is executed, unless... */ 1091da177e4SLinus Torvalds kprobe_post_handler_t post_handler; 1101da177e4SLinus Torvalds 111cc00e9cfSMasami Hiramatsu /* 112cc00e9cfSMasami Hiramatsu * ... called if executing addr causes a fault (eg. page fault). 113cc00e9cfSMasami Hiramatsu * Return 1 if it handled fault, otherwise kernel will see it. 114cc00e9cfSMasami Hiramatsu */ 1151da177e4SLinus Torvalds kprobe_fault_handler_t fault_handler; 1161da177e4SLinus Torvalds 117cc00e9cfSMasami Hiramatsu /* 118cc00e9cfSMasami Hiramatsu * ... called if breakpoint trap occurs in probe handler. 119cc00e9cfSMasami Hiramatsu * Return 1 if it handled break, otherwise kernel will see it. 120cc00e9cfSMasami Hiramatsu */ 1211da177e4SLinus Torvalds kprobe_break_handler_t break_handler; 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvalds /* Saved opcode (which has been replaced with breakpoint) */ 1241da177e4SLinus Torvalds kprobe_opcode_t opcode; 1251da177e4SLinus Torvalds 1261da177e4SLinus Torvalds /* copy of the original instruction */ 1271da177e4SLinus Torvalds struct arch_specific_insn ainsn; 128e8386a0cSMasami Hiramatsu 129de5bd88dSMasami Hiramatsu /* 130de5bd88dSMasami Hiramatsu * Indicates various status flags. 131de5bd88dSMasami Hiramatsu * Protected by kprobe_mutex after this kprobe is registered. 132de5bd88dSMasami Hiramatsu */ 133e8386a0cSMasami Hiramatsu u32 flags; 1341da177e4SLinus Torvalds }; 1351da177e4SLinus Torvalds 136e8386a0cSMasami Hiramatsu /* Kprobe status flags */ 137e8386a0cSMasami Hiramatsu #define KPROBE_FLAG_GONE 1 /* breakpoint has already gone */ 138de5bd88dSMasami Hiramatsu #define KPROBE_FLAG_DISABLED 2 /* probe is temporarily disabled */ 139afd66255SMasami Hiramatsu #define KPROBE_FLAG_OPTIMIZED 4 /* 140afd66255SMasami Hiramatsu * probe is really optimized. 141afd66255SMasami Hiramatsu * NOTE: 142afd66255SMasami Hiramatsu * this flag is only for optimized_kprobe. 143afd66255SMasami Hiramatsu */ 144*ae6aa16fSMasami Hiramatsu #define KPROBE_FLAG_FTRACE 8 /* probe is using ftrace */ 145e8386a0cSMasami Hiramatsu 146de5bd88dSMasami Hiramatsu /* Has this kprobe gone ? */ 147e8386a0cSMasami Hiramatsu static inline int kprobe_gone(struct kprobe *p) 148e8386a0cSMasami Hiramatsu { 149e8386a0cSMasami Hiramatsu return p->flags & KPROBE_FLAG_GONE; 150e8386a0cSMasami Hiramatsu } 151e8386a0cSMasami Hiramatsu 152de5bd88dSMasami Hiramatsu /* Is this kprobe disabled ? */ 153de5bd88dSMasami Hiramatsu static inline int kprobe_disabled(struct kprobe *p) 154de5bd88dSMasami Hiramatsu { 155de5bd88dSMasami Hiramatsu return p->flags & (KPROBE_FLAG_DISABLED | KPROBE_FLAG_GONE); 156de5bd88dSMasami Hiramatsu } 157afd66255SMasami Hiramatsu 158afd66255SMasami Hiramatsu /* Is this kprobe really running optimized path ? */ 159afd66255SMasami Hiramatsu static inline int kprobe_optimized(struct kprobe *p) 160afd66255SMasami Hiramatsu { 161afd66255SMasami Hiramatsu return p->flags & KPROBE_FLAG_OPTIMIZED; 162afd66255SMasami Hiramatsu } 163*ae6aa16fSMasami Hiramatsu 164*ae6aa16fSMasami Hiramatsu /* Is this kprobe uses ftrace ? */ 165*ae6aa16fSMasami Hiramatsu static inline int kprobe_ftrace(struct kprobe *p) 166*ae6aa16fSMasami Hiramatsu { 167*ae6aa16fSMasami Hiramatsu return p->flags & KPROBE_FLAG_FTRACE; 168*ae6aa16fSMasami Hiramatsu } 169*ae6aa16fSMasami Hiramatsu 1701da177e4SLinus Torvalds /* 1711da177e4SLinus Torvalds * Special probe type that uses setjmp-longjmp type tricks to resume 1721da177e4SLinus Torvalds * execution at a specified entry with a matching prototype corresponding 1731da177e4SLinus Torvalds * to the probed function - a trick to enable arguments to become 1741da177e4SLinus Torvalds * accessible seamlessly by probe handling logic. 1751da177e4SLinus Torvalds * Note: 1761da177e4SLinus Torvalds * Because of the way compilers allocate stack space for local variables 1771da177e4SLinus Torvalds * etc upfront, regardless of sub-scopes within a function, this mirroring 1781da177e4SLinus Torvalds * principle currently works only for probes placed on function entry points. 1791da177e4SLinus Torvalds */ 1801da177e4SLinus Torvalds struct jprobe { 1811da177e4SLinus Torvalds struct kprobe kp; 18281eae375SMichael Ellerman void *entry; /* probe handling code to jump to */ 1831da177e4SLinus Torvalds }; 1841da177e4SLinus Torvalds 1859e367d85SMichael Ellerman /* For backward compatibility with old code using JPROBE_ENTRY() */ 1869e367d85SMichael Ellerman #define JPROBE_ENTRY(handler) (handler) 1879e367d85SMichael Ellerman 188b94cce92SHien Nguyen /* 189b94cce92SHien Nguyen * Function-return probe - 190b94cce92SHien Nguyen * Note: 191b94cce92SHien Nguyen * User needs to provide a handler function, and initialize maxactive. 192b94cce92SHien Nguyen * maxactive - The maximum number of instances of the probed function that 193b94cce92SHien Nguyen * can be active concurrently. 194b94cce92SHien Nguyen * nmissed - tracks the number of times the probed function's return was 195b94cce92SHien Nguyen * ignored, due to maxactive being too low. 196b94cce92SHien Nguyen * 197b94cce92SHien Nguyen */ 198b94cce92SHien Nguyen struct kretprobe { 199b94cce92SHien Nguyen struct kprobe kp; 200b94cce92SHien Nguyen kretprobe_handler_t handler; 201f47cd9b5SAbhishek Sagar kretprobe_handler_t entry_handler; 202b94cce92SHien Nguyen int maxactive; 203b94cce92SHien Nguyen int nmissed; 204f47cd9b5SAbhishek Sagar size_t data_size; 205b94cce92SHien Nguyen struct hlist_head free_instances; 206ec484608SThomas Gleixner raw_spinlock_t lock; 207b94cce92SHien Nguyen }; 208b94cce92SHien Nguyen 209b94cce92SHien Nguyen struct kretprobe_instance { 210b94cce92SHien Nguyen struct hlist_node hlist; 211b94cce92SHien Nguyen struct kretprobe *rp; 212802eae7cSRusty Lynch kprobe_opcode_t *ret_addr; 213802eae7cSRusty Lynch struct task_struct *task; 214f47cd9b5SAbhishek Sagar char data[0]; 215b94cce92SHien Nguyen }; 216b94cce92SHien Nguyen 217f438d914SMasami Hiramatsu struct kretprobe_blackpoint { 218f438d914SMasami Hiramatsu const char *name; 219f438d914SMasami Hiramatsu void *addr; 220f438d914SMasami Hiramatsu }; 2213d8d996eSSrinivasa Ds 2223d8d996eSSrinivasa Ds struct kprobe_blackpoint { 2233d8d996eSSrinivasa Ds const char *name; 2243d8d996eSSrinivasa Ds unsigned long start_addr; 2253d8d996eSSrinivasa Ds unsigned long range; 2263d8d996eSSrinivasa Ds }; 2273d8d996eSSrinivasa Ds 228dc19835dSMasami Hiramatsu #ifdef CONFIG_KPROBES 229dc19835dSMasami Hiramatsu DECLARE_PER_CPU(struct kprobe *, current_kprobe); 230dc19835dSMasami Hiramatsu DECLARE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk); 231dc19835dSMasami Hiramatsu 232b1801812SIngo Molnar /* 233b1801812SIngo Molnar * For #ifdef avoidance: 234b1801812SIngo Molnar */ 235b1801812SIngo Molnar static inline int kprobes_built_in(void) 236b1801812SIngo Molnar { 237b1801812SIngo Molnar return 1; 238b1801812SIngo Molnar } 239b1801812SIngo Molnar 240dc19835dSMasami Hiramatsu #ifdef CONFIG_KRETPROBES 241dc19835dSMasami Hiramatsu extern void arch_prepare_kretprobe(struct kretprobe_instance *ri, 242dc19835dSMasami Hiramatsu struct pt_regs *regs); 243dc19835dSMasami Hiramatsu extern int arch_trampoline_kprobe(struct kprobe *p); 244dc19835dSMasami Hiramatsu #else /* CONFIG_KRETPROBES */ 245dc19835dSMasami Hiramatsu static inline void arch_prepare_kretprobe(struct kretprobe *rp, 246dc19835dSMasami Hiramatsu struct pt_regs *regs) 247dc19835dSMasami Hiramatsu { 248dc19835dSMasami Hiramatsu } 249dc19835dSMasami Hiramatsu static inline int arch_trampoline_kprobe(struct kprobe *p) 250dc19835dSMasami Hiramatsu { 251dc19835dSMasami Hiramatsu return 0; 252dc19835dSMasami Hiramatsu } 253dc19835dSMasami Hiramatsu #endif /* CONFIG_KRETPROBES */ 254dc19835dSMasami Hiramatsu 255f438d914SMasami Hiramatsu extern struct kretprobe_blackpoint kretprobe_blacklist[]; 256f438d914SMasami Hiramatsu 2570f95b7fcSAnanth N Mavinakayanahalli static inline void kretprobe_assert(struct kretprobe_instance *ri, 2580f95b7fcSAnanth N Mavinakayanahalli unsigned long orig_ret_address, unsigned long trampoline_address) 2590f95b7fcSAnanth N Mavinakayanahalli { 2600f95b7fcSAnanth N Mavinakayanahalli if (!orig_ret_address || (orig_ret_address == trampoline_address)) { 2610f95b7fcSAnanth N Mavinakayanahalli printk("kretprobe BUG!: Processing kretprobe %p @ %p\n", 2620f95b7fcSAnanth N Mavinakayanahalli ri->rp, ri->rp->kp.addr); 2630f95b7fcSAnanth N Mavinakayanahalli BUG(); 2640f95b7fcSAnanth N Mavinakayanahalli } 2650f95b7fcSAnanth N Mavinakayanahalli } 2660f95b7fcSAnanth N Mavinakayanahalli 2678c1c9356SAnanth N Mavinakayanahalli #ifdef CONFIG_KPROBES_SANITY_TEST 2688c1c9356SAnanth N Mavinakayanahalli extern int init_test_probes(void); 2698c1c9356SAnanth N Mavinakayanahalli #else 2708c1c9356SAnanth N Mavinakayanahalli static inline int init_test_probes(void) 2718c1c9356SAnanth N Mavinakayanahalli { 2728c1c9356SAnanth N Mavinakayanahalli return 0; 2738c1c9356SAnanth N Mavinakayanahalli } 2748c1c9356SAnanth N Mavinakayanahalli #endif /* CONFIG_KPROBES_SANITY_TEST */ 2758c1c9356SAnanth N Mavinakayanahalli 2761da177e4SLinus Torvalds extern int arch_prepare_kprobe(struct kprobe *p); 2777e1048b1SRusty Lynch extern void arch_arm_kprobe(struct kprobe *p); 2787e1048b1SRusty Lynch extern void arch_disarm_kprobe(struct kprobe *p); 2796772926bSRusty Lynch extern int arch_init_kprobes(void); 2801da177e4SLinus Torvalds extern void show_registers(struct pt_regs *regs); 2819ec4b1f3SAnanth N Mavinakayanahalli extern kprobe_opcode_t *get_insn_slot(void); 282b4c6c34aSMasami Hiramatsu extern void free_insn_slot(kprobe_opcode_t *slot, int dirty); 283bf8d5c52SKeshavamurthy Anil S extern void kprobes_inc_nmissed_count(struct kprobe *p); 2841da177e4SLinus Torvalds 285afd66255SMasami Hiramatsu #ifdef CONFIG_OPTPROBES 286afd66255SMasami Hiramatsu /* 287afd66255SMasami Hiramatsu * Internal structure for direct jump optimized probe 288afd66255SMasami Hiramatsu */ 289afd66255SMasami Hiramatsu struct optimized_kprobe { 290afd66255SMasami Hiramatsu struct kprobe kp; 291afd66255SMasami Hiramatsu struct list_head list; /* list for optimizing queue */ 292afd66255SMasami Hiramatsu struct arch_optimized_insn optinsn; 293afd66255SMasami Hiramatsu }; 294afd66255SMasami Hiramatsu 295afd66255SMasami Hiramatsu /* Architecture dependent functions for direct jump optimization */ 296afd66255SMasami Hiramatsu extern int arch_prepared_optinsn(struct arch_optimized_insn *optinsn); 297afd66255SMasami Hiramatsu extern int arch_check_optimized_kprobe(struct optimized_kprobe *op); 298afd66255SMasami Hiramatsu extern int arch_prepare_optimized_kprobe(struct optimized_kprobe *op); 299afd66255SMasami Hiramatsu extern void arch_remove_optimized_kprobe(struct optimized_kprobe *op); 300cd7ebe22SMasami Hiramatsu extern void arch_optimize_kprobes(struct list_head *oplist); 301f984ba4eSMasami Hiramatsu extern void arch_unoptimize_kprobes(struct list_head *oplist, 302f984ba4eSMasami Hiramatsu struct list_head *done_list); 303afd66255SMasami Hiramatsu extern void arch_unoptimize_kprobe(struct optimized_kprobe *op); 304afd66255SMasami Hiramatsu extern kprobe_opcode_t *get_optinsn_slot(void); 305afd66255SMasami Hiramatsu extern void free_optinsn_slot(kprobe_opcode_t *slot, int dirty); 306afd66255SMasami Hiramatsu extern int arch_within_optimized_kprobe(struct optimized_kprobe *op, 307afd66255SMasami Hiramatsu unsigned long addr); 308afd66255SMasami Hiramatsu 309afd66255SMasami Hiramatsu extern void opt_pre_handler(struct kprobe *p, struct pt_regs *regs); 310b2be84dfSMasami Hiramatsu 311b2be84dfSMasami Hiramatsu #ifdef CONFIG_SYSCTL 312b2be84dfSMasami Hiramatsu extern int sysctl_kprobes_optimization; 313b2be84dfSMasami Hiramatsu extern int proc_kprobes_optimization_handler(struct ctl_table *table, 314b2be84dfSMasami Hiramatsu int write, void __user *buffer, 315b2be84dfSMasami Hiramatsu size_t *length, loff_t *ppos); 316b2be84dfSMasami Hiramatsu #endif 317b2be84dfSMasami Hiramatsu 318afd66255SMasami Hiramatsu #endif /* CONFIG_OPTPROBES */ 319*ae6aa16fSMasami Hiramatsu #ifdef KPROBES_CAN_USE_FTRACE 320*ae6aa16fSMasami Hiramatsu extern void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, 321*ae6aa16fSMasami Hiramatsu struct pt_regs *regs); 322*ae6aa16fSMasami Hiramatsu extern int arch_prepare_kprobe_ftrace(struct kprobe *p); 323*ae6aa16fSMasami Hiramatsu #endif 324*ae6aa16fSMasami Hiramatsu 325afd66255SMasami Hiramatsu 326d217d545SAnanth N Mavinakayanahalli /* Get the kprobe at this addr (if any) - called with preemption disabled */ 3271da177e4SLinus Torvalds struct kprobe *get_kprobe(void *addr); 328ef53d9c5SSrinivasa D S void kretprobe_hash_lock(struct task_struct *tsk, 329ef53d9c5SSrinivasa D S struct hlist_head **head, unsigned long *flags); 330ef53d9c5SSrinivasa D S void kretprobe_hash_unlock(struct task_struct *tsk, unsigned long *flags); 331b94cce92SHien Nguyen struct hlist_head * kretprobe_inst_table_head(struct task_struct *tsk); 3321da177e4SLinus Torvalds 333e6584523SAnanth N Mavinakayanahalli /* kprobe_running() will just return the current_kprobe on this CPU */ 334e6584523SAnanth N Mavinakayanahalli static inline struct kprobe *kprobe_running(void) 335e6584523SAnanth N Mavinakayanahalli { 336b76834bcSChristoph Lameter return (__this_cpu_read(current_kprobe)); 337e6584523SAnanth N Mavinakayanahalli } 338e6584523SAnanth N Mavinakayanahalli 339e6584523SAnanth N Mavinakayanahalli static inline void reset_current_kprobe(void) 340e6584523SAnanth N Mavinakayanahalli { 341b76834bcSChristoph Lameter __this_cpu_write(current_kprobe, NULL); 342e6584523SAnanth N Mavinakayanahalli } 343e6584523SAnanth N Mavinakayanahalli 344e6584523SAnanth N Mavinakayanahalli static inline struct kprobe_ctlblk *get_kprobe_ctlblk(void) 345e6584523SAnanth N Mavinakayanahalli { 346e6584523SAnanth N Mavinakayanahalli return (&__get_cpu_var(kprobe_ctlblk)); 347e6584523SAnanth N Mavinakayanahalli } 348e6584523SAnanth N Mavinakayanahalli 3491da177e4SLinus Torvalds int register_kprobe(struct kprobe *p); 3501da177e4SLinus Torvalds void unregister_kprobe(struct kprobe *p); 3519861668fSMasami Hiramatsu int register_kprobes(struct kprobe **kps, int num); 3529861668fSMasami Hiramatsu void unregister_kprobes(struct kprobe **kps, int num); 3531da177e4SLinus Torvalds int setjmp_pre_handler(struct kprobe *, struct pt_regs *); 3541da177e4SLinus Torvalds int longjmp_break_handler(struct kprobe *, struct pt_regs *); 3551da177e4SLinus Torvalds int register_jprobe(struct jprobe *p); 3561da177e4SLinus Torvalds void unregister_jprobe(struct jprobe *p); 35726b31c19SMasami Hiramatsu int register_jprobes(struct jprobe **jps, int num); 35826b31c19SMasami Hiramatsu void unregister_jprobes(struct jprobe **jps, int num); 3591da177e4SLinus Torvalds void jprobe_return(void); 3603d7e3382SMichael Ellerman unsigned long arch_deref_entry_point(void *); 3611da177e4SLinus Torvalds 362b94cce92SHien Nguyen int register_kretprobe(struct kretprobe *rp); 363b94cce92SHien Nguyen void unregister_kretprobe(struct kretprobe *rp); 3644a296e07SMasami Hiramatsu int register_kretprobes(struct kretprobe **rps, int num); 3654a296e07SMasami Hiramatsu void unregister_kretprobes(struct kretprobe **rps, int num); 366b94cce92SHien Nguyen 367b94cce92SHien Nguyen void kprobe_flush_task(struct task_struct *tk); 36899219a3fSbibo,mao void recycle_rp_inst(struct kretprobe_instance *ri, struct hlist_head *head); 3698c1c9356SAnanth N Mavinakayanahalli 370de5bd88dSMasami Hiramatsu int disable_kprobe(struct kprobe *kp); 371de5bd88dSMasami Hiramatsu int enable_kprobe(struct kprobe *kp); 372de5bd88dSMasami Hiramatsu 37324851d24SFrederic Weisbecker void dump_kprobe(struct kprobe *kp); 37424851d24SFrederic Weisbecker 375b1801812SIngo Molnar #else /* !CONFIG_KPROBES: */ 37600d7c05aSKeshavamurthy Anil S 377b1801812SIngo Molnar static inline int kprobes_built_in(void) 378b1801812SIngo Molnar { 379b1801812SIngo Molnar return 0; 380b1801812SIngo Molnar } 381b1801812SIngo Molnar static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr) 382b1801812SIngo Molnar { 383b1801812SIngo Molnar return 0; 384b1801812SIngo Molnar } 385785656a4SAbhishek Sagar static inline struct kprobe *get_kprobe(void *addr) 386785656a4SAbhishek Sagar { 387785656a4SAbhishek Sagar return NULL; 388785656a4SAbhishek Sagar } 389e6584523SAnanth N Mavinakayanahalli static inline struct kprobe *kprobe_running(void) 3901da177e4SLinus Torvalds { 391e6584523SAnanth N Mavinakayanahalli return NULL; 3921da177e4SLinus Torvalds } 3931da177e4SLinus Torvalds static inline int register_kprobe(struct kprobe *p) 3941da177e4SLinus Torvalds { 3951da177e4SLinus Torvalds return -ENOSYS; 3961da177e4SLinus Torvalds } 3979861668fSMasami Hiramatsu static inline int register_kprobes(struct kprobe **kps, int num) 3989861668fSMasami Hiramatsu { 3999861668fSMasami Hiramatsu return -ENOSYS; 4009861668fSMasami Hiramatsu } 4011da177e4SLinus Torvalds static inline void unregister_kprobe(struct kprobe *p) 4021da177e4SLinus Torvalds { 4031da177e4SLinus Torvalds } 4049861668fSMasami Hiramatsu static inline void unregister_kprobes(struct kprobe **kps, int num) 4059861668fSMasami Hiramatsu { 4069861668fSMasami Hiramatsu } 4071da177e4SLinus Torvalds static inline int register_jprobe(struct jprobe *p) 4081da177e4SLinus Torvalds { 4091da177e4SLinus Torvalds return -ENOSYS; 4101da177e4SLinus Torvalds } 41126b31c19SMasami Hiramatsu static inline int register_jprobes(struct jprobe **jps, int num) 41226b31c19SMasami Hiramatsu { 41326b31c19SMasami Hiramatsu return -ENOSYS; 41426b31c19SMasami Hiramatsu } 4151da177e4SLinus Torvalds static inline void unregister_jprobe(struct jprobe *p) 4161da177e4SLinus Torvalds { 4171da177e4SLinus Torvalds } 41826b31c19SMasami Hiramatsu static inline void unregister_jprobes(struct jprobe **jps, int num) 41926b31c19SMasami Hiramatsu { 42026b31c19SMasami Hiramatsu } 4211da177e4SLinus Torvalds static inline void jprobe_return(void) 4221da177e4SLinus Torvalds { 4231da177e4SLinus Torvalds } 424b94cce92SHien Nguyen static inline int register_kretprobe(struct kretprobe *rp) 425b94cce92SHien Nguyen { 426b94cce92SHien Nguyen return -ENOSYS; 427b94cce92SHien Nguyen } 4284a296e07SMasami Hiramatsu static inline int register_kretprobes(struct kretprobe **rps, int num) 4294a296e07SMasami Hiramatsu { 4304a296e07SMasami Hiramatsu return -ENOSYS; 4314a296e07SMasami Hiramatsu } 432b94cce92SHien Nguyen static inline void unregister_kretprobe(struct kretprobe *rp) 433b94cce92SHien Nguyen { 434b94cce92SHien Nguyen } 4354a296e07SMasami Hiramatsu static inline void unregister_kretprobes(struct kretprobe **rps, int num) 4364a296e07SMasami Hiramatsu { 4374a296e07SMasami Hiramatsu } 438b94cce92SHien Nguyen static inline void kprobe_flush_task(struct task_struct *tk) 439b94cce92SHien Nguyen { 440b94cce92SHien Nguyen } 441de5bd88dSMasami Hiramatsu static inline int disable_kprobe(struct kprobe *kp) 442de5bd88dSMasami Hiramatsu { 443de5bd88dSMasami Hiramatsu return -ENOSYS; 444de5bd88dSMasami Hiramatsu } 445de5bd88dSMasami Hiramatsu static inline int enable_kprobe(struct kprobe *kp) 446de5bd88dSMasami Hiramatsu { 447de5bd88dSMasami Hiramatsu return -ENOSYS; 448de5bd88dSMasami Hiramatsu } 449b94cce92SHien Nguyen #endif /* CONFIG_KPROBES */ 4508f9b1528SMasami Hiramatsu static inline int disable_kretprobe(struct kretprobe *rp) 4518f9b1528SMasami Hiramatsu { 4528f9b1528SMasami Hiramatsu return disable_kprobe(&rp->kp); 4538f9b1528SMasami Hiramatsu } 4548f9b1528SMasami Hiramatsu static inline int enable_kretprobe(struct kretprobe *rp) 4558f9b1528SMasami Hiramatsu { 4568f9b1528SMasami Hiramatsu return enable_kprobe(&rp->kp); 4578f9b1528SMasami Hiramatsu } 4588f9b1528SMasami Hiramatsu static inline int disable_jprobe(struct jprobe *jp) 4598f9b1528SMasami Hiramatsu { 4608f9b1528SMasami Hiramatsu return disable_kprobe(&jp->kp); 4618f9b1528SMasami Hiramatsu } 4628f9b1528SMasami Hiramatsu static inline int enable_jprobe(struct jprobe *jp) 4638f9b1528SMasami Hiramatsu { 4648f9b1528SMasami Hiramatsu return enable_kprobe(&jp->kp); 4658f9b1528SMasami Hiramatsu } 4668f9b1528SMasami Hiramatsu 4671da177e4SLinus Torvalds #endif /* _LINUX_KPROBES_H */ 468