[DTrace-devel] [PATCH] Make DCTX_RODATA available to BPF functions
eugene.loh at oracle.com
eugene.loh at oracle.com
Tue Nov 21 04:56:35 UTC 2023
From: Eugene Loh <eugene.loh at oracle.com>
Use DCTX_RODATA in inet_ntoa.S.
Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
bpf/inet_ntoa6.S | 12 +++---------
libdtrace/dt_bpf.h | 9 +++++----
libdtrace/dt_cc.c | 3 +++
libdtrace/dt_dlibs.c | 1 +
4 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/bpf/inet_ntoa6.S b/bpf/inet_ntoa6.S
index 37807ad6..92a7d858 100644
--- a/bpf/inet_ntoa6.S
+++ b/bpf/inet_ntoa6.S
@@ -5,14 +5,6 @@
#define BPF_FUNC_probe_read 4
-/*
- * We sadly cannot include struct declarations in assembler input files, so we
- * cannot use offsetof() to programmatically determine the offset of the rodata
- * member in the DTrace context (dt_ctx_t). If that structure changes, the
- * following define must be updated as well.
- */
-#define DCTX_RODATA 56
-
#define OUTPUT_LEN 40
#define INPUT_LEN 16
@@ -224,7 +216,9 @@ dt_inet_ntoa6:
* have the code below output the address in two parts: a 7 word
* prefix followed by a 1 word suffix.
*/
- ldxdw %r6, [%r6 + DCTX_RODATA]
+ lddw %r1, DCTX_RODATA
+ add %r1, %r6
+ ldxdw %r6, [%r1 + 0]
ldxw %r1, [%fp + -4] /* restore tbloff */
lddw %r0, RODATA_SIZE
jge %r1, %r0, .Ldone
diff --git a/libdtrace/dt_bpf.h b/libdtrace/dt_bpf.h
index 0b883936..c52110ec 100644
--- a/libdtrace/dt_bpf.h
+++ b/libdtrace/dt_bpf.h
@@ -37,10 +37,11 @@ extern "C" {
#define DT_CONST_TASK_COMM 16
#define DT_CONST_MUTEX_OWNER 17
#define DT_CONST_RWLOCK_CNTS 18
-#define DT_CONST_RODATA_OFF 19
-#define DT_CONST_RODATA_SIZE 20
-#define DT_CONST_ZERO_OFF 21
-#define DT_CONST_MEM_STACK 22
+#define DT_CONST_DCTX_RODATA 19
+#define DT_CONST_RODATA_OFF 20
+#define DT_CONST_RODATA_SIZE 21
+#define DT_CONST_ZERO_OFF 22
+#define DT_CONST_MEM_STACK 23
#define DT_BPF_LOG_SIZE_DEFAULT (UINT32_MAX >> 8)
#define DT_BPF_LOG_SIZE_SMALL 4096
diff --git a/libdtrace/dt_cc.c b/libdtrace/dt_cc.c
index b35b8821..784b528c 100644
--- a/libdtrace/dt_cc.c
+++ b/libdtrace/dt_cc.c
@@ -1164,6 +1164,9 @@ dt_link_construct(dtrace_hdl_t *dtp, const dt_probe_t *prp, dtrace_difo_t *dp,
nrp->dofr_data = total_offset;
continue;
}
+ case DT_CONST_DCTX_RODATA:
+ nrp->dofr_data = DCTX_RODATA;
+ continue;
case DT_CONST_RODATA_OFF:
nrp->dofr_data = dtp->dt_rooffset;
continue;
diff --git a/libdtrace/dt_dlibs.c b/libdtrace/dt_dlibs.c
index bdd02f4a..99f3075f 100644
--- a/libdtrace/dt_dlibs.c
+++ b/libdtrace/dt_dlibs.c
@@ -91,6 +91,7 @@ static const dt_ident_t dt_bpf_symbols[] = {
DT_BPF_SYMBOL_ID(TASK_COMM, DT_IDENT_SCALAR, DT_CONST_TASK_COMM),
DT_BPF_SYMBOL_ID(MUTEX_OWNER, DT_IDENT_SCALAR, DT_CONST_MUTEX_OWNER),
DT_BPF_SYMBOL_ID(RWLOCK_CNTS, DT_IDENT_SCALAR, DT_CONST_RWLOCK_CNTS),
+ DT_BPF_SYMBOL_ID(DCTX_RODATA, DT_IDENT_SCALAR, DT_CONST_DCTX_RODATA),
DT_BPF_SYMBOL_ID(RODATA_OFF, DT_IDENT_SCALAR, DT_CONST_RODATA_OFF),
DT_BPF_SYMBOL_ID(RODATA_SIZE, DT_IDENT_SCALAR, DT_CONST_RODATA_SIZE),
DT_BPF_SYMBOL_ID(ZERO_OFF, DT_IDENT_SCALAR, DT_CONST_ZERO_OFF),
--
2.18.4
More information about the DTrace-devel
mailing list