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
7extern void my_direct_func(struct task_struct *p);
8
9void my_direct_func(struct task_struct *p)
10{
11	trace_printk("waking up %s-%d\n", p->comm, p->pid);
12}
13
14extern void my_tramp(void *);
15
16asm (
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	ASM_RET
28"	.size		my_tramp, .-my_tramp\n"
29"	.popsection\n"
30);
31
32
33static int __init ftrace_direct_init(void)
34{
35	return register_ftrace_direct((unsigned long)wake_up_process,
36				     (unsigned long)my_tramp);
37}
38
39static void __exit ftrace_direct_exit(void)
40{
41	unregister_ftrace_direct((unsigned long)wake_up_process,
42				 (unsigned long)my_tramp);
43}
44
45module_init(ftrace_direct_init);
46module_exit(ftrace_direct_exit);
47
48MODULE_AUTHOR("Steven Rostedt");
49MODULE_DESCRIPTION("Example use case of using register_ftrace_direct()");
50MODULE_LICENSE("GPL");
51