diff options
author | Jeff Xie <chongguiguzi@gmail.com> | 2021-06-20 20:01:51 +0800 |
---|---|---|
committer | Palmer Dabbelt <palmerdabbelt@google.com> | 2021-07-05 20:53:09 -0700 |
commit | 70eee556b678d1e4cd4ea6742a577b596963fa25 (patch) | |
tree | 0fcf027fb9694803f3054ee7906bcd4456f9109d /arch/riscv/include/asm/ptrace.h | |
parent | 9eb4fcff220790f4afadf59160f2c696e99f0a84 (diff) | |
download | linux-70eee556b678d1e4cd4ea6742a577b596963fa25.tar.bz2 |
riscv: ptrace: add argn syntax
This enables ftrace kprobe events to access kernel function
arguments via $argN syntax.
Signed-off-by: Jeff Xie <huan.xie@suse.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
Diffstat (limited to 'arch/riscv/include/asm/ptrace.h')
-rw-r--r-- | arch/riscv/include/asm/ptrace.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/arch/riscv/include/asm/ptrace.h b/arch/riscv/include/asm/ptrace.h index 09ad4e923510..6ecd461129d2 100644 --- a/arch/riscv/include/asm/ptrace.h +++ b/arch/riscv/include/asm/ptrace.h @@ -141,6 +141,37 @@ static inline unsigned long regs_get_register(struct pt_regs *regs, return *(unsigned long *)((unsigned long)regs + offset); } + +/** + * regs_get_kernel_argument() - get Nth function argument in kernel + * @regs: pt_regs of that context + * @n: function argument number (start from 0) + * + * regs_get_argument() returns @n th argument of the function call. + * + * Note you can get the parameter correctly if the function has no + * more than eight arguments. + */ +static inline unsigned long regs_get_kernel_argument(struct pt_regs *regs, + unsigned int n) +{ + static const int nr_reg_arguments = 8; + static const unsigned int argument_offs[] = { + offsetof(struct pt_regs, a0), + offsetof(struct pt_regs, a1), + offsetof(struct pt_regs, a2), + offsetof(struct pt_regs, a3), + offsetof(struct pt_regs, a4), + offsetof(struct pt_regs, a5), + offsetof(struct pt_regs, a6), + offsetof(struct pt_regs, a7), + }; + + if (n < nr_reg_arguments) + return regs_get_register(regs, argument_offs[n]); + return 0; +} + #endif /* __ASSEMBLY__ */ #endif /* _ASM_RISCV_PTRACE_H */ |