Detect missing symbols used with kallsyms_lookup at compile time
[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 #ifndef HAVE_KABI_2635_TRACEPOINT
18
19 #define kabi_2635_tracepoint_probe_register tracepoint_probe_register
20 #define kabi_2635_tracepoint_probe_unregister tracepoint_probe_unregister
21
22 #endif /* HAVE_KABI_2635_TRACEPOINT */
23
24 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0))
25
26 #include <lttng-tracepoint.h>
27
28 #define lttng_wrapper_tracepoint_probe_register lttng_tracepoint_probe_register
29 #define lttng_wrapper_tracepoint_probe_unregister lttng_tracepoint_probe_unregister
30
31 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0)) */
32
33 #define lttng_wrapper_tracepoint_probe_register kabi_2635_tracepoint_probe_register
34 #define lttng_wrapper_tracepoint_probe_unregister kabi_2635_tracepoint_probe_unregister
35
36 static inline
37 int lttng_tracepoint_init(void)
38 {
39 return 0;
40 }
41
42 static inline
43 void lttng_tracepoint_exit(void)
44 {
45 }
46
47 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0)) */
48
49 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0) && defined(CONFIG_MODULE_SIG))
50
51 #include <linux/kallsyms.h>
52 #include <wrapper/kallsyms.h>
53
54 static inline
55 int wrapper_tracepoint_module_notify(struct notifier_block *nb,
56 unsigned long val, struct module *mod)
57 {
58 int (*tracepoint_module_notify_sym)(struct notifier_block *nb,
59 unsigned long val, struct module *mod);
60
61 tracepoint_module_notify_sym =
62 (void *) kallsyms_lookup_funcptr("tracepoint_module_notify");
63 if (tracepoint_module_notify_sym) {
64 return tracepoint_module_notify_sym(nb, val, mod);
65 } else {
66 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");
67 return -ENOSYS;
68 }
69 }
70
71 /*
72 * No canary for 'tracepoint_module_notify()', it's only defined in 'kernel/tracepoint.c'.
73 *
74 * static inline
75 * int __canary__tracepoint_module_notify(struct notifier_block *nb,
76 * unsigned long val, struct module *mod)
77 * {
78 * return tracepoint_module_notify(nb, val, mod);
79 * }
80 */
81
82 #endif /* #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0) && defined(CONFIG_MODULE_SIG)) */
83
84 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0) && defined(CONFIG_MODULE_SIG) && defined(MODULE))
85
86 static inline
87 int wrapper_lttng_fixup_sig(struct module *mod)
88 {
89 int ret = 0;
90
91 /*
92 * This is for module.c confusing force loaded modules with
93 * unsigned modules.
94 */
95 if (!THIS_MODULE->sig_ok &&
96 THIS_MODULE->taints & (1U << TAINT_FORCED_MODULE)) {
97 THIS_MODULE->taints &= ~(1U << TAINT_FORCED_MODULE);
98 ret = wrapper_tracepoint_module_notify(NULL,
99 MODULE_STATE_COMING, mod);
100 THIS_MODULE->taints |= (1U << TAINT_FORCED_MODULE);
101 }
102 return ret;
103 }
104
105 #else /* #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0) && defined(CONFIG_MODULE_SIG) && defined(MODULE)) */
106
107 static inline
108 int wrapper_lttng_fixup_sig(struct module *mod)
109 {
110 return 0;
111 }
112
113 #endif /* #else #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0) && defined(CONFIG_MODULE_SIG) && defined(MODULE)) */
114
115 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0))
116 static inline struct tracepoint *lttng_tracepoint_ptr_deref(tracepoint_ptr_t *p)
117 {
118 return tracepoint_ptr_deref(p);
119 }
120 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0)) */
121 static inline struct tracepoint *lttng_tracepoint_ptr_deref(struct tracepoint * const *p)
122 {
123 return *p;
124 }
125 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0)) */
126
127 #endif /* _LTTNG_WRAPPER_TRACEPOINT_H */
This page took 0.031144 seconds and 4 git commands to generate.