Skip to content

Commit

Permalink
provider: change the trampoline return type
Browse files Browse the repository at this point in the history
The trampoline callback can now return 1 to indicate that no calls
should be made to clause functions (or 0 to retain the regular
operation of calling the clause functions).

This will be used by some providers to attach to probes that perform
auxiliary operations, e.g. setting up some data items that will be
needed for the actual probe processing.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed May 25, 2023
1 parent 065af40 commit 1218323
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 18 deletions.
7 changes: 5 additions & 2 deletions libdtrace/dt_cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,13 +590,16 @@ dt_cg_add_dependent(dtrace_hdl_t *dtp, dt_probe_t *prp, void *arg)
dt_ident_t *idp = dt_dlib_add_probe_var(pcb->pcb_hdl, prp);
dt_probe_t *saved_prp = pcb->pcb_probe;
uint_t exitlbl = dt_irlist_label(dlp);
int skip = 0;

dt_cg_tramp_save_args(pcb);
pcb->pcb_probe = prp;
emite(dlp, BPF_STORE_IMM(BPF_W, BPF_REG_7, DMST_PRID, prp->desc->id), idp);
if (prp->prov->impl->trampoline != NULL)
prp->prov->impl->trampoline(pcb, exitlbl);
dt_cg_tramp_call_clauses(pcb, prp, DT_ACTIVITY_ACTIVE);
skip = prp->prov->impl->trampoline(pcb, exitlbl);

if (!skip)
dt_cg_tramp_call_clauses(pcb, prp, DT_ACTIVITY_ACTIVE);

pcb->pcb_probe = saved_prp;
dt_cg_tramp_restore_args(pcb);
Expand Down
4 changes: 3 additions & 1 deletion libdtrace/dt_prov_cpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ static int provide(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp)
* __u64 addr;
* }
*/
static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
{
int i;
dt_irlist_t *dlp = &pcb->pcb_ir;
Expand All @@ -406,6 +406,8 @@ static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
emit(dlp, BPF_STORE_IMM(BPF_DW, BPF_REG_7, DMST_ARG(i), 0));

dt_cg_tramp_epilogue(pcb);

return 0;
}

static int attach(dtrace_hdl_t *dtp, const dt_probe_t *prp, int bpf_fd)
Expand Down
8 changes: 5 additions & 3 deletions libdtrace/dt_prov_dtrace.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*
Expand Down Expand Up @@ -77,7 +77,7 @@ static int populate(dtrace_hdl_t *dtp)
* The trampoline will populate a dt_dctx_t struct and then call the function
* that implements the compiled D clause. It returns 0 to the caller.
*/
static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
{
dt_irlist_t *dlp = &pcb->pcb_ir;
dt_activity_t act = DT_ACTIVITY_ACTIVE;
Expand All @@ -90,7 +90,7 @@ static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
*/
if (strcmp(pcb->pcb_probe->desc->prb, "ERROR") == 0) {
dt_cg_tramp_error(pcb);
return;
return 0;
}

/*
Expand Down Expand Up @@ -163,6 +163,8 @@ static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
emit(dlp, BPF_STORE_IMM(BPF_DW, BPF_REG_7, DMST_ARG(i), 0));

dt_cg_tramp_epilogue_advance(pcb, act);

return 0;
}

static char *uprobe_spec(const char *prb)
Expand Down
4 changes: 3 additions & 1 deletion libdtrace/dt_prov_fbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static int populate(dtrace_hdl_t *dtp)
* The trampoline will populate a dt_dctx_t struct and then call the function
* that implements the compiled D clause. It returns 0 to the caller.
*/
static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
{
dt_cg_tramp_prologue(pcb);

Expand Down Expand Up @@ -181,6 +181,8 @@ static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
} else
dt_cg_tramp_copy_args_from_regs(pcb, 1);
dt_cg_tramp_epilogue(pcb);

return 0;
}

static int attach(dtrace_hdl_t *dtp, const dt_probe_t *prp, int bpf_fd)
Expand Down
4 changes: 3 additions & 1 deletion libdtrace/dt_prov_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ static void enable(dtrace_hdl_t *dtp, dt_probe_t *prp)
* that implements the compiled D clause. It returns the value that it gets
* back from that function.
*/
static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
{
dtrace_hdl_t *dtp = pcb->pcb_hdl;
dt_irlist_t *dlp = &pcb->pcb_ir;
Expand Down Expand Up @@ -388,6 +388,8 @@ static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
emit(dlp, BPF_STORE(BPF_DW, BPF_REG_7, DMST_ARG(0), BPF_REG_0));
emit(dlp, BPF_STORE(BPF_DW, BPF_REG_7, DMST_ARG(1), BPF_REG_1));
}

return 0;
}

static int probe_info(dtrace_hdl_t *dtp, const dt_probe_t *prp,
Expand Down
4 changes: 3 additions & 1 deletion libdtrace/dt_prov_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static int provide(dtrace_hdl_t *dtp, const dtrace_probedesc_t *pdp)
* __u64 addr;
* }
*/
static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
{
int i;
dt_irlist_t *dlp = &pcb->pcb_ir;
Expand Down Expand Up @@ -252,6 +252,8 @@ static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
emit(dlp, BPF_STORE_IMM(BPF_DW, BPF_REG_7, DMST_ARG(i), 0));

dt_cg_tramp_epilogue(pcb);

return 0;
}

static int attach(dtrace_hdl_t *dtp, const dt_probe_t *prp, int bpf_fd)
Expand Down
6 changes: 4 additions & 2 deletions libdtrace/dt_prov_rawtp.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*
Expand Down Expand Up @@ -131,7 +131,7 @@ static int populate(dtrace_hdl_t *dtp)
* that implements the compiled D clause. It returns the value that it gets
* back from that function.
*/
static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
{
int i;
dt_irlist_t *dlp = &pcb->pcb_ir;
Expand All @@ -153,6 +153,8 @@ static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
}

dt_cg_tramp_epilogue(pcb);

return 0;
}

static int probe_info(dtrace_hdl_t *dtp, const dt_probe_t *prp,
Expand Down
6 changes: 4 additions & 2 deletions libdtrace/dt_prov_sdt.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*
Expand Down Expand Up @@ -128,7 +128,7 @@ static int populate(dtrace_hdl_t *dtp)
* that implements the compiled D clause. It returns the value that it gets
* back from that function.
*/
static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
{
int i;
dt_irlist_t *dlp = &pcb->pcb_ir;
Expand Down Expand Up @@ -182,6 +182,8 @@ static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
emit(dlp, BPF_STORE_IMM(BPF_DW, BPF_REG_7, DMST_ARG(i), 0));

dt_cg_tramp_epilogue(pcb);

return 0;
}

static int probe_info(dtrace_hdl_t *dtp, const dt_probe_t *prp,
Expand Down
6 changes: 4 additions & 2 deletions libdtrace/dt_prov_syscall.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*
Expand Down Expand Up @@ -131,7 +131,7 @@ static int populate(dtrace_hdl_t *dtp)
* The trampoline will populate a dt_dctx_t struct and then call the function
* that implements the compiled D clause. It returns 0 to the caller.
*/
static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
{
int i;
dt_irlist_t *dlp = &pcb->pcb_ir;
Expand Down Expand Up @@ -188,6 +188,8 @@ static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
}

dt_cg_tramp_epilogue(pcb);

return 0;
}

static int probe_info(dtrace_hdl_t *dtp, const dt_probe_t *prp,
Expand Down
8 changes: 6 additions & 2 deletions libdtrace/dt_prov_uprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ static void enable_usdt(dtrace_hdl_t *dtp, dt_probe_t *prp)
* The trampoline will first populate a dt_dctx_t struct. It will then emulate
* the firing of all dependent pid* probes and their clauses.
*/
static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
static int trampoline(dt_pcb_t *pcb, uint_t exitlbl)
{
dt_irlist_t *dlp = &pcb->pcb_ir;
const dt_probe_t *prp = pcb->pcb_probe;
Expand Down Expand Up @@ -465,6 +465,8 @@ static void trampoline(dt_pcb_t *pcb, uint_t exitlbl)
}

dt_cg_tramp_return(pcb);

return 0;
}

/*
Expand Down Expand Up @@ -503,7 +505,7 @@ copyout_val(dt_pcb_t *pcb, uint_t lbl, uint32_t val, int arg)
* The trampoline dereferences the passed-in arg and writes 1 into it if this is
* one of the processes for which the probe is enabled.
*/
static void trampoline_is_enabled(dt_pcb_t *pcb, uint_t exitlbl)
static int trampoline_is_enabled(dt_pcb_t *pcb, uint_t exitlbl)
{
dt_irlist_t *dlp = &pcb->pcb_ir;
const dt_probe_t *prp = pcb->pcb_probe;
Expand Down Expand Up @@ -579,6 +581,8 @@ static void trampoline_is_enabled(dt_pcb_t *pcb, uint_t exitlbl)
copyout_val(pcb, lbl_assign, 1, 0);

dt_cg_tramp_return(pcb);

return 0;
}

static int attach(dtrace_hdl_t *dtp, const dt_probe_t *prp, int bpf_fd)
Expand Down
2 changes: 1 addition & 1 deletion libdtrace/dt_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ typedef struct dt_provimpl {
const pid_probespec_t *psp);
void (*enable)(dtrace_hdl_t *dtp, /* enable the given probe */
struct dt_probe *prp);
void (*trampoline)(dt_pcb_t *pcb, /* generate BPF trampoline */
int (*trampoline)(dt_pcb_t *pcb, /* generate BPF trampoline */
uint_t exitlbl);
int (*attach)(dtrace_hdl_t *dtp, /* attach BPF prog to probe */
const struct dt_probe *prp, int bpf_fd);
Expand Down

0 comments on commit 1218323

Please sign in to comment.