]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
arm64: ptrace: Add function argument access API
authorMasami Hiramatsu <mhiramat@kernel.org>
Fri, 12 Apr 2019 14:22:01 +0000 (23:22 +0900)
committerWill Deacon <will.deacon@arm.com>
Fri, 12 Apr 2019 16:04:27 +0000 (17:04 +0100)
Add regs_get_argument() which returns N th argument of the function
call. On arm64, it supports up to 8th argument.
Note that this chooses most probably assignment, in some case
it can be incorrect (e.g. passing data structure or floating
point etc.)

This enables ftrace kprobe events to access kernel function
arguments via $argN syntax.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
[will: tidied up the comment a bit]
Signed-off-by: Will Deacon <will.deacon@arm.com>
arch/arm64/Kconfig
arch/arm64/include/asm/ptrace.h

index 555af50355920da5af0c5a1c9653ab110bb1f33c..c383625ec02c95bf71288409d9c618c270ecfb99 100644 (file)
@@ -148,6 +148,7 @@ config ARM64
        select HAVE_PERF_REGS
        select HAVE_PERF_USER_STACK_DUMP
        select HAVE_REGS_AND_STACK_ACCESS_API
+       select HAVE_FUNCTION_ARG_ACCESS_API
        select HAVE_RCU_TABLE_FREE
        select HAVE_RCU_TABLE_INVALIDATE
        select HAVE_RSEQ
index ec60174c8c18417354fa9bac578b8dde5284f7bd..b2de32939ada8454b9af594c251a2d85f029ef36 100644 (file)
@@ -305,6 +305,28 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
        return regs->regs[0];
 }
 
+/**
+ * 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 that this chooses the most likely register mapping. In very rare
+ * cases this may not return correct data, for example, if one of the
+ * function parameters is 16 bytes or bigger. In such cases, we cannot
+ * get access the parameter correctly and the register assignment of
+ * subsequent parameters will be shifted.
+ */
+static inline unsigned long regs_get_kernel_argument(struct pt_regs *regs,
+                                                    unsigned int n)
+{
+#define NR_REG_ARGUMENTS 8
+       if (n < NR_REG_ARGUMENTS)
+               return pt_regs_read_reg(regs, n);
+       return 0;
+}
+
 /* We must avoid circular header include via sched.h */
 struct task_struct;
 int valid_user_regs(struct user_pt_regs *regs, struct task_struct *task);