Skip to content

Commit 3877025

Browse files
committed
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
1 parent 0b68e3c commit 3877025

File tree

2 files changed

+10
-10
lines changed
  • cddl/contrib/opensolaris/lib/libdtrace/common
  • sys/cddl/contrib/opensolaris/uts/common/dtrace

2 files changed

+10
-10
lines changed

cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,11 +2242,10 @@ dt_format_bytes_get(dtrace_hdl_t *dtp, caddr_t addr, size_t nbytes)
22422242
static int
22432243
dt_format_memory(dtrace_hdl_t *dtp, caddr_t addr)
22442244
{
2245-
2246-
size_t nbytes = *((uintptr_t *) addr);
2245+
size_t nbytes = *((size_t *) addr);
22472246
char *s;
22482247

2249-
s = dt_format_bytes_get(dtp, addr + sizeof(uintptr_t), nbytes);
2248+
s = dt_format_bytes_get(dtp, addr + sizeof(size_t), nbytes);
22502249
if (s == NULL)
22512250
return (-1);
22522251

@@ -2260,9 +2259,9 @@ static int
22602259
dt_print_memory(dtrace_hdl_t *dtp, FILE *fp, caddr_t addr)
22612260
{
22622261
int quiet = (dtp->dt_options[DTRACEOPT_QUIET] != DTRACEOPT_UNSET);
2263-
size_t nbytes = *((uintptr_t *) addr);
2262+
size_t nbytes = *((size_t *) addr);
22642263

2265-
return (dt_print_bytes(dtp, fp, addr + sizeof(uintptr_t),
2264+
return (dt_print_bytes(dtp, fp, addr + sizeof(size_t),
22662265
nbytes, 50, quiet, 1));
22672266
}
22682267

sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7761,7 +7761,8 @@ dtrace_probe(dtrace_id_t id, uintptr_t arg0, uintptr_t arg1,
77617761
uintptr_t *memref = (uintptr_t *)(uintptr_t) val;
77627762

77637763
if (!DTRACE_INSCRATCHPTR(&mstate,
7764-
(uintptr_t)memref, 2 * sizeof(uintptr_t))) {
7764+
(uintptr_t) memref,
7765+
sizeof (uintptr_t) + sizeof (size_t))) {
77657766
*flags |= CPU_DTRACE_BADADDR;
77667767
continue;
77677768
}
@@ -7773,21 +7774,21 @@ dtrace_probe(dtrace_id_t id, uintptr_t arg0, uintptr_t arg1,
77737774
* Check if the size exceeds the allocated
77747775
* buffer size.
77757776
*/
7776-
if (size + sizeof(uintptr_t) > dp->dtdo_rtype.dtdt_size) {
7777+
if (size + sizeof (size_t) >
7778+
dp->dtdo_rtype.dtdt_size) {
77777779
/* Flag a drop! */
77787780
*flags |= CPU_DTRACE_DROP;
77797781
continue;
77807782
}
77817783

77827784
/* Store the size in the buffer first. */
7783-
DTRACE_STORE(uintptr_t, tomax,
7784-
valoffs, size);
7785+
DTRACE_STORE(size_t, tomax, valoffs, size);
77857786

77867787
/*
77877788
* Offset the buffer address to the start
77887789
* of the data.
77897790
*/
7790-
valoffs += sizeof(uintptr_t);
7791+
valoffs += sizeof(size_t);
77917792

77927793
/*
77937794
* Reset to the memory address rather than

0 commit comments

Comments
 (0)