fix: tracepoint: Optimize using static_call() (v5.10)
[lttng-modules.git] / wrapper / tracepoint.h
1 /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
2 *
3 * wrapper/tracepoint.h
4 *
5 * wrapper around DECLARE_EVENT_CLASS.
6 *
7 * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 */
9
10 #ifndef _LTTNG_WRAPPER_TRACEPOINT_H
11 #define _LTTNG_WRAPPER_TRACEPOINT_H
12
13 #include <linux/version.h>
14 #include <linux/tracepoint.h>
15 #include <linux/module.h>
16
17 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35))
18
19 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)
20
21 #endif
22
23 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,10,0))
24 #define LTTNG_DEFINE_TRACE(name, proto, args) \
25 DEFINE_TRACE(name, PARAMS(proto), PARAMS(args))
26 #else
27 #define LTTNG_DEFINE_TRACE(name, proto, args) \
28 DEFINE_TRACE(name)
29 #endif
30
31 #ifndef HAVE_KABI_2635_TRACEPOINT
32
33 #define kabi_2635_tracepoint_probe_register tracepoint_probe_register
34 #define kabi_2635_tracepoint_probe_unregister tracepoint_probe_unregister
35
36 #endif /* HAVE_KABI_2635_TRACEPOINT */
37
38 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0))
39
40 #include <lttng-tracepoint.h>
41
42 #define lttng_wrapper_tracepoint_probe_register lttng_tracepoint_probe_register
43 #define lttng_wrapper_tracepoint_probe_unregister lttng_tracepoint_probe_unregister
44
45 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0)) */
46
47 #define lttng_wrapper_tracepoint_probe_register kabi_2635_tracepoint_probe_register
48 #define lttng_wrapper_tracepoint_probe_unregister kabi_2635_tracepoint_probe_unregister
49
50 static inline
51 int lttng_tracepoint_init(void)
52 {
53 return 0;
54 }
55
56 static inline
57 void lttng_tracepoint_exit(void)
58 {
59 }
60
61 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0)) */
62
63 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0) && defined(CONFIG_MODULE_SIG))
64
65 #include <linux/kallsyms.h>
66 #include <wrapper/kallsyms.h>
67
68 static inline
69 int wrapper_tracepoint_module_notify(struct notifier_block *nb,
70 unsigned long val, struct module *mod)
71 {
72 int (*tracepoint_module_notify_sym)(struct notifier_block *nb,
73 unsigned long val, struct module *mod);
74
75 tracepoint_module_notify_sym =
76 (void *) kallsyms_lookup_funcptr("tracepoint_module_notify");
77 if (tracepoint_module_notify_sym) {
78 return tracepoint_module_notify_sym(nb, val, mod);
79 } else {
80 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");
81 return -ENOSYS;
82 }
83 }
84
85 /*
86 * No canary for 'tracepoint_module_notify()', it's only defined in 'kernel/tracepoint.c'.
87 *
88 * static inline
89 * int __canary__tracepoint_module_notify(struct notifier_block *nb,
90 * unsigned long val, struct module *mod)
91 * {
92 * return tracepoint_module_notify(nb, val, mod);
93 * }
94 */
95
96 #endif /* #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0) && defined(CONFIG_MODULE_SIG)) */
97
98 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0) && defined(CONFIG_MODULE_SIG) && defined(MODULE))
99
100 static inline
101 int wrapper_lttng_fixup_sig(struct module *mod)
102 {
103 int ret = 0;
104
105 /*
106 * This is for module.c confusing force loaded modules with
107 * unsigned modules.
108 */
109 if (!THIS_MODULE->sig_ok &&
110 THIS_MODULE->taints & (1U << TAINT_FORCED_MODULE)) {
111 THIS_MODULE->taints &= ~(1U << TAINT_FORCED_MODULE);
112 ret = wrapper_tracepoint_module_notify(NULL,
113 MODULE_STATE_COMING, mod);
114 THIS_MODULE->taints |= (1U << TAINT_FORCED_MODULE);
115 }
116 return ret;
117 }
118
119 #else /* #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0) && defined(CONFIG_MODULE_SIG) && defined(MODULE)) */
120
121 static inline
122 int wrapper_lttng_fixup_sig(struct module *mod)
123 {
124 return 0;
125 }
126
127 #endif /* #else #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0) && defined(CONFIG_MODULE_SIG) && defined(MODULE)) */
128
129 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0))
130 static inline struct tracepoint *lttng_tracepoint_ptr_deref(tracepoint_ptr_t *p)
131 {
132 return tracepoint_ptr_deref(p);
133 }
134 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0)) */
135 static inline struct tracepoint *lttng_tracepoint_ptr_deref(struct tracepoint * const *p)
136 {
137 return *p;
138 }
139 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0)) */
140
141 #endif /* _LTTNG_WRAPPER_TRACEPOINT_H */
This page took 0.031652 seconds and 4 git commands to generate.