[DTrace-devel] [PATCH 2/4] provider, cg: add reject_clasue() callback

Kris Van Hees kris.van.hees at oracle.com
Tue Jul 15 05:48:10 UTC 2025


Future providers will require functionality to determine whether a
clause for one of its probes needs to be rejected for some reason.

Since the callback is invoked during trampoline creation, rejection
must result in a compilation error.  The callback is responsible for
this.  If it returns, the clause is accepted.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_cg.c       | 22 ++++++++++++++++------
 libdtrace/dt_provider.h |  2 ++
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index d80b0a55..738597ed 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -855,16 +855,26 @@ dt_cg_tramp_map_args(dt_pcb_t *pcb, dt_argdesc_t *args, size_t nargs)
 }
 
 typedef struct {
-	dt_irlist_t	*dlp;
-	dt_activity_t	act;
-	uint_t		lbl_exit;
+	const dt_probe_t	*prp;
+	dt_irlist_t		*dlp;
+	dt_activity_t		act;
+	uint_t			lbl_exit;
 } dt_clause_arg_t;
 
 static int
 dt_cg_call_clause(dtrace_hdl_t *dtp, dtrace_stmtdesc_t *sdp, dt_clause_arg_t *arg)
 {
-	dt_irlist_t	*dlp = arg->dlp;
-	dt_ident_t	*idp = sdp->dtsd_clause;
+	const dt_probe_t	*prp = arg->prp;
+	dt_irlist_t		*dlp = arg->dlp;
+	dt_ident_t		*idp = sdp->dtsd_clause;
+
+	/*
+	 * Ensure the clause is valid for the probe.  Call the reject_clause()
+	 * hook if defined, otherwise apply default checks.  Rejection of the
+	 * clause must be reported as a compilation error.
+	 */
+	if (prp->prov->impl->reject_clause != NULL)
+		prp->prov->impl->reject_clause(prp, sdp->dtsd_clauseflags);
 
 	/*
 	 *	if (*dctx.act != act)	// ldw %r0, [%r9 + DCTX_ACT]
@@ -895,7 +905,7 @@ void
 dt_cg_tramp_call_clauses(dt_pcb_t *pcb, const dt_probe_t *prp, dt_activity_t act)
 {
 	dt_irlist_t	*dlp = &pcb->pcb_ir;
-	dt_clause_arg_t	arg = { dlp, act, pcb->pcb_exitlbl };
+	dt_clause_arg_t	arg = { prp, dlp, act, pcb->pcb_exitlbl };
 
 	dt_probe_stmt_iter(pcb->pcb_hdl, prp, (dt_stmt_f *)dt_cg_call_clause, &arg);
 }
diff --git a/libdtrace/dt_provider.h b/libdtrace/dt_provider.h
index 2a3bba80..a7263f5d 100644
--- a/libdtrace/dt_provider.h
+++ b/libdtrace/dt_provider.h
@@ -52,6 +52,8 @@ typedef struct dt_provimpl {
 		       const pid_probespec_t *psp);
 	void (*enable)(dtrace_hdl_t *dtp,	/* enable the given probe */
 		       struct dt_probe *prp);
+	void (*reject_clause)(const struct dt_probe *prp, int clsflags);
+						/* check clause flags */
 	int (*trampoline)(dt_pcb_t *pcb,	/* generate BPF trampoline */
 			   uint_t exitlbl);
 	int (*load_prog)(dtrace_hdl_t *dtp, const struct dt_probe *prp,
-- 
2.43.5




More information about the DTrace-devel mailing list