git: 9ab7f84be600 - stable/14 - dtrace: Add a partial implementation of dtrace_getarg() on arm64

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Sun, 14 Jul 2024 16:43:17 UTC
The branch stable/14 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=9ab7f84be600572534bf77b54cb566d92e6ce197

commit 9ab7f84be600572534bf77b54cb566d92e6ce197
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-06-20 16:41:01 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-07-14 16:16:01 +0000

    dtrace: Add a partial implementation of dtrace_getarg() on arm64
    
    For invop providers (i.e., fbt and kinst) we can simply reach into the
    invop trapframe to fetch argument registers for arguments 0-7; for
    argument 8 and beyond we have to read the value off of the stack.
    
    Reviewed by:    Domagoj Stolfa, avg
    MFC after:      2 weeks
    Sponsored by:   Innovate UK
    Differential Revision:  https://reviews.freebsd.org/D45649
    
    (cherry picked from commit bae00433f013c1c960ab13b9d81edef5a9dbf84d)
---
 sys/cddl/dev/dtrace/aarch64/dtrace_isa.c | 33 +++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/sys/cddl/dev/dtrace/aarch64/dtrace_isa.c b/sys/cddl/dev/dtrace/aarch64/dtrace_isa.c
index 34e225f32e81..72944e8a5ae2 100644
--- a/sys/cddl/dev/dtrace/aarch64/dtrace_isa.c
+++ b/sys/cddl/dev/dtrace/aarch64/dtrace_isa.c
@@ -238,14 +238,37 @@ dtrace_getufpstack(uint64_t *pcstack, uint64_t *fpstack, int pcstack_limit)
 	printf("IMPLEMENT ME: %s\n", __func__);
 }
 
-/*ARGSUSED*/
 uint64_t
-dtrace_getarg(int arg, int aframes)
+dtrace_getarg(int arg, int aframes __unused)
 {
+	struct trapframe *tf;
 
-	printf("IMPLEMENT ME: %s\n", __func__);
-
-	return (0);
+	/*
+	 * We only handle invop providers here.
+	 */
+	if ((tf = curthread->t_dtrace_trapframe) == NULL) {
+		DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
+		return (0);
+	} else if (arg < 8) {
+		return (tf->tf_x[arg]);
+	} else {
+		uintptr_t p;
+		uint64_t val;
+
+		p = (tf->tf_sp + (arg - 8) * sizeof(uint64_t));
+		if ((p & 7) != 0) {
+			DTRACE_CPUFLAG_SET(CPU_DTRACE_BADALIGN);
+			cpu_core[curcpu].cpuc_dtrace_illval = p;
+			return (0);
+		}
+		if (!kstack_contains(curthread, p, sizeof(uint64_t))) {
+			DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR);
+			cpu_core[curcpu].cpuc_dtrace_illval = p;
+			return (0);
+		}
+		memcpy(&val, (void *)p, sizeof(uint64_t));
+		return (val);
+	}
 }
 
 int