1 /* SPDX-License-Identifier: (GPL-2.0-only OR LGPL-2.1-only)
5 * Wrapper around kallsyms. Using kprobes to get its address when available.
7 * Can we mainline LTTng already so we don't have to waste our time doing this
10 * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 #include <linux/kprobes.h>
14 #include <linux/module.h>
15 #include <wrapper/kallsyms.h>
17 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0))
19 #ifndef CONFIG_KPROBES
20 # error "LTTng-modules requires CONFIG_KPROBES on kernels >= 5.7.0"
24 unsigned long (*kallsyms_lookup_name_sym
)(const char *name
);
27 int dummy_kprobe_handler(struct kprobe
*p
, struct pt_regs
*regs
)
33 unsigned long do_get_kallsyms(void)
39 memset(&probe
, 0, sizeof(probe
));
40 probe
.pre_handler
= dummy_kprobe_handler
;
41 probe
.symbol_name
= "kallsyms_lookup_name";
42 ret
= register_kprobe(&probe
);
45 addr
= (unsigned long)probe
.addr
;
47 #ifdef CONFIG_THUMB2_KERNEL
49 addr
|= 1; /* set bit 0 in address for thumb mode */
52 unregister_kprobe(&probe
);
56 unsigned long wrapper_kallsyms_lookup_name(const char *name
)
58 if (!kallsyms_lookup_name_sym
) {
59 kallsyms_lookup_name_sym
= (void *)do_get_kallsyms();
61 if (kallsyms_lookup_name_sym
)
62 return kallsyms_lookup_name_sym(name
);
64 printk_once(KERN_WARNING
"LTTng requires kallsyms_lookup_name\n");
68 EXPORT_SYMBOL_GPL(wrapper_kallsyms_lookup_name
);