| 1 | #ifndef _LTTNG_WRAPPER_UPROBES_H |
| 2 | #define _LTTNG_WRAPPER_UPROBES_H |
| 3 | |
| 4 | /* |
| 5 | * wrapper/uprobes.h |
| 6 | * |
| 7 | * wrapper around uprobes. Using KALLSYMS to get its address when |
| 8 | * available, else we need to have a kernel that exports this function to GPL |
| 9 | * modules. |
| 10 | * |
| 11 | * Copyright (C) 2013 Yannick Brosseau <yannick.brosseau@gmail.com> |
| 12 | * Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com> |
| 13 | * |
| 14 | * This library is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU Lesser General Public |
| 16 | * License as published by the Free Software Foundation; only |
| 17 | * version 2.1 of the License. |
| 18 | * |
| 19 | * This library is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | * Lesser General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU Lesser General Public |
| 25 | * License along with this library; if not, write to the Free Software |
| 26 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 27 | */ |
| 28 | |
| 29 | #include <linux/version.h> |
| 30 | |
| 31 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)) |
| 32 | #include <linux/uprobes.h> |
| 33 | |
| 34 | /* Use kallsym lookup for version before 3.9. */ |
| 35 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0)) |
| 36 | |
| 37 | static inline |
| 38 | int wrapper_uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc) |
| 39 | { |
| 40 | return uprobe_register(inode, offset, uc); |
| 41 | } |
| 42 | |
| 43 | static inline |
| 44 | void wrapper_uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc) |
| 45 | { |
| 46 | uprobe_unregister(inode, offset, uc); |
| 47 | } |
| 48 | |
| 49 | #else /* Version < 3.9, use kallsym lookup. */ |
| 50 | #include "kallsyms.h" |
| 51 | |
| 52 | static inline |
| 53 | int wrapper_uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc) |
| 54 | { |
| 55 | int (*uprobe_register_sym)(struct inode *inode, loff_t offset, struct uprobe_consumer *uc); |
| 56 | |
| 57 | uprobe_register_sym = (void *) kallsyms_lookup_funcptr("uprobe_register"); |
| 58 | |
| 59 | if (uprobe_register_sym) { |
| 60 | return uprobe_register_sym(inode, offset, uc); |
| 61 | } else { |
| 62 | printk(KERN_WARNING "LTTng: uprobe_register symbol lookup failed.\n"); |
| 63 | return -EINVAL; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | static inline |
| 68 | void wrapper_uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc) |
| 69 | { |
| 70 | int (*uprobe_unregister_sym)(struct inode *inode, loff_t offset, struct uprobe_consumer *uc); |
| 71 | |
| 72 | uprobe_unregister_sym = (void *) kallsyms_lookup_funcptr("uprobe_unregister"); |
| 73 | |
| 74 | if (uprobe_unregister_sym) { |
| 75 | uprobe_unregister_sym(inode, offset, uc); |
| 76 | } else { |
| 77 | printk(KERN_WARNING "LTTng: uprobe_unregister symbol lookup failed.\n"); |
| 78 | WARN_ON(1); |
| 79 | } |
| 80 | } |
| 81 | #endif |
| 82 | #else |
| 83 | /* Version < 3.5, before uprobe was added. */ |
| 84 | struct uprobe_consumer {}; |
| 85 | |
| 86 | #endif |
| 87 | #endif |