Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 #include <linux/module.h>
0003 
0004 #include <linux/sched.h> /* for wake_up_process() */
0005 #include <linux/ftrace.h>
0006 #include <asm/asm-offsets.h>
0007 
0008 extern void my_direct_func(struct task_struct *p);
0009 
0010 void my_direct_func(struct task_struct *p)
0011 {
0012     trace_printk("waking up %s-%d\n", p->comm, p->pid);
0013 }
0014 
0015 extern void my_tramp(void *);
0016 
0017 #ifdef CONFIG_X86_64
0018 
0019 #include <asm/ibt.h>
0020 
0021 asm (
0022 "   .pushsection    .text, \"ax\", @progbits\n"
0023 "   .type       my_tramp, @function\n"
0024 "   .globl      my_tramp\n"
0025 "   my_tramp:"
0026     ASM_ENDBR
0027 "   pushq %rbp\n"
0028 "   movq %rsp, %rbp\n"
0029 "   pushq %rdi\n"
0030 "   call my_direct_func\n"
0031 "   popq %rdi\n"
0032 "   leave\n"
0033     ASM_RET
0034 "   .size       my_tramp, .-my_tramp\n"
0035 "   .popsection\n"
0036 );
0037 
0038 #endif /* CONFIG_X86_64 */
0039 
0040 #ifdef CONFIG_S390
0041 
0042 asm (
0043 "   .pushsection    .text, \"ax\", @progbits\n"
0044 "   .type       my_tramp, @function\n"
0045 "   .globl      my_tramp\n"
0046 "   my_tramp:"
0047 "   lgr     %r1,%r15\n"
0048 "   stmg        %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
0049 "   stg     %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
0050 "   aghi        %r15,"__stringify(-STACK_FRAME_OVERHEAD)"\n"
0051 "   stg     %r1,"__stringify(__SF_BACKCHAIN)"(%r15)\n"
0052 "   brasl       %r14,my_direct_func\n"
0053 "   aghi        %r15,"__stringify(STACK_FRAME_OVERHEAD)"\n"
0054 "   lmg     %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
0055 "   lg      %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
0056 "   lgr     %r1,%r0\n"
0057 "   br      %r1\n"
0058 "   .size       my_tramp, .-my_tramp\n"
0059 "   .popsection\n"
0060 );
0061 
0062 #endif /* CONFIG_S390 */
0063 
0064 static int __init ftrace_direct_init(void)
0065 {
0066     return register_ftrace_direct((unsigned long)wake_up_process,
0067                      (unsigned long)my_tramp);
0068 }
0069 
0070 static void __exit ftrace_direct_exit(void)
0071 {
0072     unregister_ftrace_direct((unsigned long)wake_up_process,
0073                  (unsigned long)my_tramp);
0074 }
0075 
0076 module_init(ftrace_direct_init);
0077 module_exit(ftrace_direct_exit);
0078 
0079 MODULE_AUTHOR("Steven Rostedt");
0080 MODULE_DESCRIPTION("Example use case of using register_ftrace_direct()");
0081 MODULE_LICENSE("GPL");