Skip to content

Commit 70eee55

Browse files
Jeff Xiepalmer-dabbelt
authored andcommitted
riscv: ptrace: add argn syntax
This enables ftrace kprobe events to access kernel function arguments via $argN syntax. Signed-off-by: Jeff Xie <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 9eb4fcf commit 70eee55

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

arch/riscv/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ config RISCV
9090
select HAVE_PERF_REGS
9191
select HAVE_PERF_USER_STACK_DUMP
9292
select HAVE_REGS_AND_STACK_ACCESS_API
93+
select HAVE_FUNCTION_ARG_ACCESS_API
9394
select HAVE_STACKPROTECTOR
9495
select HAVE_SYSCALL_TRACEPOINTS
9596
select IRQ_DOMAIN

arch/riscv/include/asm/ptrace.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,37 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
141141

142142
return *(unsigned long *)((unsigned long)regs + offset);
143143
}
144+
145+
/**
146+
* regs_get_kernel_argument() - get Nth function argument in kernel
147+
* @regs: pt_regs of that context
148+
* @n: function argument number (start from 0)
149+
*
150+
* regs_get_argument() returns @n th argument of the function call.
151+
*
152+
* Note you can get the parameter correctly if the function has no
153+
* more than eight arguments.
154+
*/
155+
static inline unsigned long regs_get_kernel_argument(struct pt_regs *regs,
156+
unsigned int n)
157+
{
158+
static const int nr_reg_arguments = 8;
159+
static const unsigned int argument_offs[] = {
160+
offsetof(struct pt_regs, a0),
161+
offsetof(struct pt_regs, a1),
162+
offsetof(struct pt_regs, a2),
163+
offsetof(struct pt_regs, a3),
164+
offsetof(struct pt_regs, a4),
165+
offsetof(struct pt_regs, a5),
166+
offsetof(struct pt_regs, a6),
167+
offsetof(struct pt_regs, a7),
168+
};
169+
170+
if (n < nr_reg_arguments)
171+
return regs_get_register(regs, argument_offs[n]);
172+
return 0;
173+
}
174+
144175
#endif /* __ASSEMBLY__ */
145176

146177
#endif /* _ASM_RISCV_PTRACE_H */

0 commit comments

Comments
 (0)