[DTrace-devel] [PATCH REVIEWED 1/7] cg, bpf: Pass dctx as first arg in arg-to-tstring subroutines

Kris Van Hees kris.van.hees at oracle.com
Thu Jul 27 15:27:53 UTC 2023


Passing a pointer to the DTrace context (dctx) enables subroutines
called through arg-to-tstring to report faults if necessary.  It also
gives the implementation of these subroutines access to context data.
(None use that as of yet, but e.g. inet_ntoa6() is expected to need
it.)

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
Reviewed-by: Eugene Loh <eugene.loh at oracle.com>
---
 bpf/basename.S    | 6 +++---
 bpf/dirname.S     | 6 +++---
 bpf/inet_ntoa.S   | 6 +++---
 bpf/lltostr.S     | 6 +++---
 libdtrace/dt_cg.c | 8 +++++---
 5 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/bpf/basename.S b/bpf/basename.S
index 23cf15d0..822e0517 100644
--- a/bpf/basename.S
+++ b/bpf/basename.S
@@ -6,7 +6,7 @@
 #define BPF_FUNC_probe_read_str	45
 
 /*
- * void dt_basename(char *src, char *dst);
+ * void dt_basename(const dt_dctx_t *dctx, char *src, char *dst);
  */
 	.text
 	.align	4
@@ -19,8 +19,8 @@ dt_basename :
 #define LEN %r9
 
 	/* store copies of input arguments */
-	mov	SRC, %r1
-	mov	DST, %r2
+	mov	SRC, %r2
+	mov	DST, %r3
 
 	/*
 	 * Copy src to dst for two reasons:
diff --git a/bpf/dirname.S b/bpf/dirname.S
index 7ff90b47..2b902172 100644
--- a/bpf/dirname.S
+++ b/bpf/dirname.S
@@ -6,7 +6,7 @@
 #define BPF_FUNC_probe_read_str	45
 
 /*
- * void dt_dirname(char *src, char *dst);
+ * void dt_dirname(const dt_dctx_t *dctx, char *src, char *dst);
  */
 	.text
 	.align	4
@@ -18,8 +18,8 @@ dt_dirname :
 #define LEN %r8
 
 	/* store copies of input arguments */
-	mov	SRC, %r1
-	mov	DST, %r2
+	mov	SRC, %r2
+	mov	DST, %r3
 
 	/*
 	 * Copy src to dst for two reasons:
diff --git a/bpf/inet_ntoa.S b/bpf/inet_ntoa.S
index 1ef3b13a..38da1e04 100644
--- a/bpf/inet_ntoa.S
+++ b/bpf/inet_ntoa.S
@@ -114,7 +114,7 @@ dt_inet_ntoa_write_uint8:
 #undef PTR
 
 /*
- * void dt_inet_ntoa(uint8_t *src, char *dst) {
+ * void dt_inet_ntoa(const dt_dctx_t *dctx, uint8_t *src, char *dst) {
  *     uint64_t off, inp, len;
  *
  *     bpf_probe_read(fp + -4, 4, src);
@@ -159,9 +159,9 @@ dt_inet_ntoa:
 #define DST %r7
 #define LEN %r8
 
-	mov	DST, %r2
+	mov	DST, %r3
 
-	mov	%r3, %r1
+	mov	%r3, %r2
 	mov	%r2, 4
 	mov	%r1, %fp
 	add	%r1, -4
diff --git a/bpf/lltostr.S b/bpf/lltostr.S
index b21001ab..3fa2895c 100644
--- a/bpf/lltostr.S
+++ b/bpf/lltostr.S
@@ -8,7 +8,7 @@
 
 	.text
 /*
- * void dt_lltostr(uint64_t VAL, char *STR)
+ * void dt_lltostr(const dt_dctx_t *dctx, uint64_t VAL, char *STR)
  * {
  *     // start writing at the end (IDX==1 is the last char)
  *     IDX = 1
@@ -74,8 +74,8 @@ dt_lltostr:
 #define IDX %r8
 #define SGN %r9
 
-	mov	VAL, %r1
-	mov	STR, %r2
+	mov	VAL, %r2
+	mov	STR, %r3
 
 	mov	IDX, 1				/* IDX = 1 */
 
diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index 5391a143..bb6cff4a 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -4567,7 +4567,8 @@ dt_cg_array_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp)
 
 /*
  * Emit code to call a precompiled BPF function (named by fname)
- * that is of return type void and takes two arguments:
+ * that is of return type void and takes three arguments:
+ *   - a pointer to the DTrace context (dctx)
  *   - one input value
  *   - a pointer to an output tstring, allocated here
  */
@@ -4599,12 +4600,13 @@ dt_cg_subr_arg_to_tstring(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp,
 	if (dt_regset_xalloc_args(drp) == -1)
 		longjmp(yypcb->pcb_jmpbuf, EDT_NOREG);
 
-	emit(dlp, BPF_MOV_REG(BPF_REG_1, arg->dn_reg));
+	emit(dlp, BPF_LOAD(BPF_DW, BPF_REG_1, BPF_REG_FP, DT_STK_DCTX));
+	emit(dlp, BPF_MOV_REG(BPF_REG_2, arg->dn_reg));
 	dt_regset_free(drp, arg->dn_reg);
 	if (dt_node_is_string(arg))
 		dt_cg_tstring_free(yypcb, arg);
 
-	emit(dlp,  BPF_MOV_REG(BPF_REG_2, dnp->dn_reg));
+	emit(dlp,  BPF_MOV_REG(BPF_REG_3, dnp->dn_reg));
 
 	idp = dt_dlib_get_func(yypcb->pcb_hdl, fname);
 	assert(idp != NULL);
-- 
2.39.3




More information about the DTrace-devel mailing list