Steven Rostedt (VMware) | b06457c | 2019-11-08 13:12:33 -0500 | [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 | void my_direct_func(struct task_struct *p) |
| 8 | { |
Colin Ian King | 760f8bc | 2019-11-15 08:59:38 +0000 | [diff] [blame] | 9 | trace_printk("waking up %s-%d\n", p->comm, p->pid); |
Steven Rostedt (VMware) | b06457c | 2019-11-08 13:12:33 -0500 | [diff] [blame] | 10 | } |
| 11 | |
| 12 | extern void my_tramp(void *); |
| 13 | |
| 14 | asm ( |
| 15 | " .pushsection .text, \"ax\", @progbits\n" |
Josh Poimboeuf | 9d907f1 | 2020-04-24 15:40:43 -0500 | [diff] [blame^] | 16 | " .type my_tramp, @function\n" |
Steven Rostedt (VMware) | b06457c | 2019-11-08 13:12:33 -0500 | [diff] [blame] | 17 | " my_tramp:" |
| 18 | " pushq %rbp\n" |
| 19 | " movq %rsp, %rbp\n" |
| 20 | " pushq %rdi\n" |
| 21 | " call my_direct_func\n" |
| 22 | " popq %rdi\n" |
| 23 | " leave\n" |
| 24 | " ret\n" |
Josh Poimboeuf | 9d907f1 | 2020-04-24 15:40:43 -0500 | [diff] [blame^] | 25 | " .size my_tramp, .-my_tramp\n" |
Steven Rostedt (VMware) | b06457c | 2019-11-08 13:12:33 -0500 | [diff] [blame] | 26 | " .popsection\n" |
| 27 | ); |
| 28 | |
| 29 | |
| 30 | static int __init ftrace_direct_init(void) |
| 31 | { |
| 32 | return register_ftrace_direct((unsigned long)wake_up_process, |
| 33 | (unsigned long)my_tramp); |
| 34 | } |
| 35 | |
| 36 | static void __exit ftrace_direct_exit(void) |
| 37 | { |
| 38 | unregister_ftrace_direct((unsigned long)wake_up_process, |
| 39 | (unsigned long)my_tramp); |
| 40 | } |
| 41 | |
| 42 | module_init(ftrace_direct_init); |
| 43 | module_exit(ftrace_direct_exit); |
| 44 | |
| 45 | MODULE_AUTHOR("Steven Rostedt"); |
| 46 | MODULE_DESCRIPTION("Example use case of using register_ftrace_direct()"); |
| 47 | MODULE_LICENSE("GPL"); |