Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | #include <linux/module.h> |
| 3 | |
| 4 | #include <linux/sched.h> /* for wake_up_process() */ |
| 5 | #include <linux/ftrace.h> |
| 6 | |
| 7 | extern void my_direct_func(struct task_struct *p); |
| 8 | |
| 9 | void my_direct_func(struct task_struct *p) |
| 10 | { |
| 11 | trace_printk("waking up %s-%d\n", p->comm, p->pid); |
| 12 | } |
| 13 | |
| 14 | extern void my_tramp(void *); |
| 15 | |
| 16 | asm ( |
| 17 | " .pushsection .text, \"ax\", @progbits\n" |
| 18 | " .type my_tramp, @function\n" |
| 19 | " .globl my_tramp\n" |
| 20 | " my_tramp:" |
| 21 | " pushq %rbp\n" |
| 22 | " movq %rsp, %rbp\n" |
| 23 | " pushq %rdi\n" |
| 24 | " call my_direct_func\n" |
| 25 | " popq %rdi\n" |
| 26 | " leave\n" |
| 27 | " ret\n" |
| 28 | " .size my_tramp, .-my_tramp\n" |
| 29 | " .popsection\n" |
| 30 | ); |
| 31 | |
| 32 | |
| 33 | static int __init ftrace_direct_init(void) |
| 34 | { |
| 35 | return register_ftrace_direct((unsigned long)wake_up_process, |
| 36 | (unsigned long)my_tramp); |
| 37 | } |
| 38 | |
| 39 | static void __exit ftrace_direct_exit(void) |
| 40 | { |
| 41 | unregister_ftrace_direct((unsigned long)wake_up_process, |
| 42 | (unsigned long)my_tramp); |
| 43 | } |
| 44 | |
| 45 | module_init(ftrace_direct_init); |
| 46 | module_exit(ftrace_direct_exit); |
| 47 | |
| 48 | MODULE_AUTHOR("Steven Rostedt"); |
| 49 | MODULE_DESCRIPTION("Example use case of using register_ftrace_direct()"); |
| 50 | MODULE_LICENSE("GPL"); |