Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_X86_FTRACE_H
0003 #define _ASM_X86_FTRACE_H
0004 
0005 #ifdef CONFIG_FUNCTION_TRACER
0006 #ifndef CC_USING_FENTRY
0007 # error Compiler does not support fentry?
0008 #endif
0009 # define MCOUNT_ADDR        ((unsigned long)(__fentry__))
0010 #define MCOUNT_INSN_SIZE    5 /* sizeof mcount call */
0011 
0012 /* Ignore unused weak functions which will have non zero offsets */
0013 #ifdef CONFIG_HAVE_FENTRY
0014 # include <asm/ibt.h>
0015 /* Add offset for endbr64 if IBT enabled */
0016 # define FTRACE_MCOUNT_MAX_OFFSET   ENDBR_INSN_SIZE
0017 #endif
0018 
0019 #ifdef CONFIG_DYNAMIC_FTRACE
0020 #define ARCH_SUPPORTS_FTRACE_OPS 1
0021 #endif
0022 
0023 #define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
0024 
0025 #ifndef __ASSEMBLY__
0026 extern atomic_t modifying_ftrace_code;
0027 extern void __fentry__(void);
0028 
0029 static inline unsigned long ftrace_call_adjust(unsigned long addr)
0030 {
0031     /*
0032      * addr is the address of the mcount call instruction.
0033      * recordmcount does the necessary offset calculation.
0034      */
0035     return addr;
0036 }
0037 
0038 /*
0039  * When a ftrace registered caller is tracing a function that is
0040  * also set by a register_ftrace_direct() call, it needs to be
0041  * differentiated in the ftrace_caller trampoline. To do this, we
0042  * place the direct caller in the ORIG_AX part of pt_regs. This
0043  * tells the ftrace_caller that there's a direct caller.
0044  */
0045 static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr)
0046 {
0047     /* Emulate a call */
0048     regs->orig_ax = addr;
0049 }
0050 
0051 #ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
0052 struct ftrace_regs {
0053     struct pt_regs      regs;
0054 };
0055 
0056 static __always_inline struct pt_regs *
0057 arch_ftrace_get_regs(struct ftrace_regs *fregs)
0058 {
0059     /* Only when FL_SAVE_REGS is set, cs will be non zero */
0060     if (!fregs->regs.cs)
0061         return NULL;
0062     return &fregs->regs;
0063 }
0064 
0065 #define ftrace_instruction_pointer_set(fregs, _ip)  \
0066     do { (fregs)->regs.ip = (_ip); } while (0)
0067 
0068 struct ftrace_ops;
0069 #define ftrace_graph_func ftrace_graph_func
0070 void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
0071                struct ftrace_ops *op, struct ftrace_regs *fregs);
0072 #else
0073 #define FTRACE_GRAPH_TRAMP_ADDR FTRACE_GRAPH_ADDR
0074 #endif
0075 
0076 #ifdef CONFIG_DYNAMIC_FTRACE
0077 
0078 struct dyn_arch_ftrace {
0079     /* No extra data needed for x86 */
0080 };
0081 
0082 #endif /*  CONFIG_DYNAMIC_FTRACE */
0083 #endif /* __ASSEMBLY__ */
0084 #endif /* CONFIG_FUNCTION_TRACER */
0085 
0086 
0087 #ifndef __ASSEMBLY__
0088 
0089 #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
0090 extern void set_ftrace_ops_ro(void);
0091 #else
0092 static inline void set_ftrace_ops_ro(void) { }
0093 #endif
0094 
0095 #define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
0096 static inline bool arch_syscall_match_sym_name(const char *sym, const char *name)
0097 {
0098     /*
0099      * Compare the symbol name with the system call name. Skip the
0100      * "__x64_sys", "__ia32_sys", "__do_sys" or simple "sys" prefix.
0101      */
0102     return !strcmp(sym + 3, name + 3) ||
0103         (!strncmp(sym, "__x64_", 6) && !strcmp(sym + 9, name + 3)) ||
0104         (!strncmp(sym, "__ia32_", 7) && !strcmp(sym + 10, name + 3)) ||
0105         (!strncmp(sym, "__do_sys", 8) && !strcmp(sym + 8, name + 3));
0106 }
0107 
0108 #ifndef COMPILE_OFFSETS
0109 
0110 #if defined(CONFIG_FTRACE_SYSCALLS) && defined(CONFIG_IA32_EMULATION)
0111 #include <linux/compat.h>
0112 
0113 /*
0114  * Because ia32 syscalls do not map to x86_64 syscall numbers
0115  * this screws up the trace output when tracing a ia32 task.
0116  * Instead of reporting bogus syscalls, just do not trace them.
0117  *
0118  * If the user really wants these, then they should use the
0119  * raw syscall tracepoints with filtering.
0120  */
0121 #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS 1
0122 static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
0123 {
0124     return in_32bit_syscall();
0125 }
0126 #endif /* CONFIG_FTRACE_SYSCALLS && CONFIG_IA32_EMULATION */
0127 #endif /* !COMPILE_OFFSETS */
0128 #endif /* !__ASSEMBLY__ */
0129 
0130 #endif /* _ASM_X86_FTRACE_H */