| 1 | #ifndef _LTTNG_WRAPPER_TRACEPOINT_H |
| 2 | #define _LTTNG_WRAPPER_TRACEPOINT_H |
| 3 | |
| 4 | /* |
| 5 | * wrapper/tracepoint.h |
| 6 | * |
| 7 | * wrapper around DECLARE_EVENT_CLASS. |
| 8 | * |
| 9 | * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 10 | * |
| 11 | * This library is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU Lesser General Public |
| 13 | * License as published by the Free Software Foundation; only |
| 14 | * version 2.1 of the License. |
| 15 | * |
| 16 | * This library is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * Lesser General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU Lesser General Public |
| 22 | * License along with this library; if not, write to the Free Software |
| 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 24 | */ |
| 25 | |
| 26 | #include <linux/version.h> |
| 27 | #include <linux/tracepoint.h> |
| 28 | #include <linux/module.h> |
| 29 | |
| 30 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)) |
| 31 | |
| 32 | #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) |
| 33 | |
| 34 | #endif |
| 35 | |
| 36 | #ifndef HAVE_KABI_2635_TRACEPOINT |
| 37 | |
| 38 | #define kabi_2635_tracepoint_probe_register tracepoint_probe_register |
| 39 | #define kabi_2635_tracepoint_probe_unregister tracepoint_probe_unregister |
| 40 | |
| 41 | #endif /* HAVE_KABI_2635_TRACEPOINT */ |
| 42 | |
| 43 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0)) |
| 44 | |
| 45 | #include <lttng-tracepoint.h> |
| 46 | |
| 47 | #define lttng_wrapper_tracepoint_probe_register lttng_tracepoint_probe_register |
| 48 | #define lttng_wrapper_tracepoint_probe_unregister lttng_tracepoint_probe_unregister |
| 49 | |
| 50 | #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0)) */ |
| 51 | |
| 52 | #define lttng_wrapper_tracepoint_probe_register kabi_2635_tracepoint_probe_register |
| 53 | #define lttng_wrapper_tracepoint_probe_unregister kabi_2635_tracepoint_probe_unregister |
| 54 | |
| 55 | static inline |
| 56 | int lttng_tracepoint_init(void) |
| 57 | { |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static inline |
| 62 | void lttng_tracepoint_exit(void) |
| 63 | { |
| 64 | } |
| 65 | |
| 66 | #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0)) */ |
| 67 | |
| 68 | #ifdef CONFIG_MODULE_SIG |
| 69 | |
| 70 | #include <linux/kallsyms.h> |
| 71 | #include <wrapper/kallsyms.h> |
| 72 | |
| 73 | static inline |
| 74 | int wrapper_tracepoint_module_notify(struct notifier_block *nb, |
| 75 | unsigned long val, struct module *mod) |
| 76 | { |
| 77 | int (*tracepoint_module_notify_sym)(struct notifier_block *nb, |
| 78 | unsigned long val, struct module *mod); |
| 79 | |
| 80 | tracepoint_module_notify_sym = |
| 81 | (void *) kallsyms_lookup_funcptr("tracepoint_module_notify"); |
| 82 | if (tracepoint_module_notify_sym) { |
| 83 | return tracepoint_module_notify_sym(nb, val, mod); |
| 84 | } else { |
| 85 | printk_once(KERN_WARNING "LTTng: tracepoint_module_notify symbol lookup failed. It probably means you kernel don't need this work-around. Please consider upgrading LTTng modules to make this warning go away.\n"); |
| 86 | return -ENOSYS; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | #endif /* CONFIG_MODULE_SIG */ |
| 91 | |
| 92 | #if defined(CONFIG_MODULE_SIG) && defined(MODULE) |
| 93 | |
| 94 | static inline |
| 95 | int wrapper_lttng_fixup_sig(struct module *mod) |
| 96 | { |
| 97 | int ret = 0; |
| 98 | |
| 99 | /* |
| 100 | * This is for module.c confusing force loaded modules with |
| 101 | * unsigned modules. |
| 102 | */ |
| 103 | if (!THIS_MODULE->sig_ok && |
| 104 | THIS_MODULE->taints & (1U << TAINT_FORCED_MODULE)) { |
| 105 | THIS_MODULE->taints &= ~(1U << TAINT_FORCED_MODULE); |
| 106 | ret = wrapper_tracepoint_module_notify(NULL, |
| 107 | MODULE_STATE_COMING, mod); |
| 108 | THIS_MODULE->taints |= (1U << TAINT_FORCED_MODULE); |
| 109 | } |
| 110 | return ret; |
| 111 | } |
| 112 | |
| 113 | #else /* #if defined(CONFIG_MODULE_SIG) && defined(MODULE) */ |
| 114 | |
| 115 | static inline |
| 116 | int wrapper_lttng_fixup_sig(struct module *mod) |
| 117 | { |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | #endif /*#else #if defined(CONFIG_MODULE_SIG) && defined(MODULE) */ |
| 122 | |
| 123 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0)) |
| 124 | static inline struct tracepoint *lttng_tracepoint_ptr_deref(tracepoint_ptr_t *p) |
| 125 | { |
| 126 | return tracepoint_ptr_deref(p); |
| 127 | } |
| 128 | #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0)) */ |
| 129 | static inline struct tracepoint *lttng_tracepoint_ptr_deref(struct tracepoint * const *p) |
| 130 | { |
| 131 | return *p; |
| 132 | } |
| 133 | #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0)) */ |
| 134 | |
| 135 | #endif /* _LTTNG_WRAPPER_TRACEPOINT_H */ |