git: 053b8cb7602c - stable/15 - dtrace: Use a size_t to represent a buffer size in the printm action

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 30 Sep 2025 15:23:51 UTC
The branch stable/15 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=053b8cb7602cf1246f6c37b8db8dfdffd331af48

commit 053b8cb7602cf1246f6c37b8db8dfdffd331af48
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-09-10 14:33:58 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-09-30 09:43:08 +0000

    dtrace: Use a size_t to represent a buffer size in the printm action
    
    printm is specific to the FreeBSD dtrace port.  I believe it's
    effectively the same as tracemem(), though printm apparently predates
    it.  It stores the size of the buffer of traced data inline.  Currently
    it represents that size using a uintptr_t, which isn't really right and
    poses challenges when porting to CHERI because
    `DTRACE_STORE(uintptr_t, ...`  requires the destination to be suitably
    aligned, but this isn't necessary since we're just storing a size.
    
    Convert to using a size_t.  This should be a no-op since
    sizeof(uintptr_t) == sizeof(size_t) on non-CHERI platforms (and besides
    that I don't see a reason to use printm() when tracemem() is available
    and is simpler to use.)
    
    Reviewed by:    Domagoj Stolfa, avg
    MFC after:      2 weeks
    Sponsored by:   Innovate UK
    Differential Revision:  https://reviews.freebsd.org/D52055
    
    (cherry picked from commit 3877025f52ee205fe99ad4ff68229933d57e4bcb)
---
 cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c |  9 ++++-----
 sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c    | 11 ++++++-----
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c
index 385c9d78bdfc..b311b5425587 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c
@@ -2242,11 +2242,10 @@ dt_format_bytes_get(dtrace_hdl_t *dtp, caddr_t addr, size_t nbytes)
 static int
 dt_format_memory(dtrace_hdl_t *dtp, caddr_t addr)
 {
-
-	size_t nbytes = *((uintptr_t *) addr);
+	size_t nbytes = *((size_t *) addr);
 	char *s;
 
-	s = dt_format_bytes_get(dtp, addr + sizeof(uintptr_t), nbytes);
+	s = dt_format_bytes_get(dtp, addr + sizeof(size_t), nbytes);
 	if (s == NULL)
 		return (-1);
 
@@ -2260,9 +2259,9 @@ static int
 dt_print_memory(dtrace_hdl_t *dtp, FILE *fp, caddr_t addr)
 {
 	int quiet = (dtp->dt_options[DTRACEOPT_QUIET] != DTRACEOPT_UNSET);
-	size_t nbytes = *((uintptr_t *) addr);
+	size_t nbytes = *((size_t *) addr);
 
-	return (dt_print_bytes(dtp, fp, addr + sizeof(uintptr_t),
+	return (dt_print_bytes(dtp, fp, addr + sizeof(size_t),
 	    nbytes, 50, quiet, 1));
 }
 
diff --git a/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c b/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c
index 7192df200ae2..8078f3f6d4b1 100644
--- a/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c
+++ b/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c
@@ -7761,7 +7761,8 @@ dtrace_probe(dtrace_id_t id, uintptr_t arg0, uintptr_t arg1,
 				uintptr_t *memref = (uintptr_t *)(uintptr_t) val;
 
 				if (!DTRACE_INSCRATCHPTR(&mstate,
-				    (uintptr_t)memref, 2 * sizeof(uintptr_t))) {
+				    (uintptr_t) memref,
+				    sizeof (uintptr_t) + sizeof (size_t))) {
 					*flags |= CPU_DTRACE_BADADDR;
 					continue;
 				}
@@ -7773,21 +7774,21 @@ dtrace_probe(dtrace_id_t id, uintptr_t arg0, uintptr_t arg1,
 				 * Check if the size exceeds the allocated
 				 * buffer size.
 				 */
-				if (size + sizeof(uintptr_t) > dp->dtdo_rtype.dtdt_size) {
+				if (size + sizeof (size_t) >
+				    dp->dtdo_rtype.dtdt_size) {
 					/* Flag a drop! */
 					*flags |= CPU_DTRACE_DROP;
 					continue;
 				}
 
 				/* Store the size in the buffer first. */
-				DTRACE_STORE(uintptr_t, tomax,
-				    valoffs, size);
+				DTRACE_STORE(size_t, tomax, valoffs, size);
 
 				/*
 				 * Offset the buffer address to the start
 				 * of the data.
 				 */
-				valoffs += sizeof(uintptr_t);
+				valoffs += sizeof(size_t);
 
 				/*
 				 * Reset to the memory address rather than