Skip to content

Commit

Permalink
Provide and use standard functions to clear or copy CPU registers
Browse files Browse the repository at this point in the history
Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed Jul 6, 2021
1 parent 351d461 commit 2cea90a
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 77 deletions.
44 changes: 44 additions & 0 deletions libdtrace/dt_cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,50 @@ dt_cg_tramp_prologue(dt_pcb_t *pcb)
dt_cg_tramp_prologue_act(pcb, DT_ACTIVITY_ACTIVE);
}

/*
* Clear the content of the 'regs' member of the machine state.
*
* The caller must ensure that %r7 contains the value set by the
* dt_cg_tramp_prologue*() functions.
*/
void
dt_cg_tramp_clear_regs(dt_pcb_t *pcb)
{
dt_irlist_t *dlp = &pcb->pcb_ir;
int i;

/*
* memset(&dctx->mst->regs, 0, sizeof(dt_pt_regs);
* // stdw [%7 + DMST_REGS + 0 * 8], 0
* // stdw [%7 + DMST_REGS + 1 * 8], 0
* // (...)
*/
for (i = 0; i < sizeof(dt_pt_regs); i += 8)
emit(dlp, BPF_STORE_IMM(BPF_DW, BPF_REG_7, DMST_REGS + i, 0));
}

/*
* Copy the content of a dt_pt_regs structure referenced by the 'rp' argument
* into the 'regs' member of the machine state.
*
* The caller must ensure that %r7 contains the value set by the
* dt_cg_tramp_prologue*() functions.
*/
void
dt_cg_tramp_copy_regs(dt_pcb_t *pcb, int rp)
{
dt_irlist_t *dlp = &pcb->pcb_ir;
int i;

/*
* dctx->mst->regs = *(dt_pt_regs *)rp;
*/
for (i = 0; i < sizeof(dt_pt_regs); i += 8) {
emit(dlp, BPF_LOAD(BPF_DW, BPF_REG_0, BPF_REG_8, i));
emit(dlp, BPF_STORE(BPF_DW, BPF_REG_7, DMST_REGS + i, BPF_REG_0));
}
}

/*
* Copy arguments from a dt_pt_regs structure referenced by the 'rp' argument.
*
Expand Down
2 changes: 2 additions & 0 deletions libdtrace/dt_cg.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ extern void dt_cg_xsetx(dt_irlist_t *, dt_ident_t *, uint_t, int, uint64_t);
extern dt_irnode_t *dt_cg_node_alloc(uint_t, struct bpf_insn);
extern void dt_cg_tramp_prologue_act(dt_pcb_t *pcb, dt_activity_t act);
extern void dt_cg_tramp_prologue(dt_pcb_t *pcb);
extern void dt_cg_tramp_clear_regs(dt_pcb_t *pcb);
extern void dt_cg_tramp_copy_regs(dt_pcb_t *pcb, int rp);
extern void dt_cg_tramp_copy_args_from_regs(dt_pcb_t *pcb, int rp);
extern void dt_cg_tramp_call_clauses(dt_pcb_t *pcb, const dt_probe_t *prp,
dt_activity_t act);
Expand Down
2 changes: 0 additions & 2 deletions libdtrace/dt_dctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ typedef struct dt_mstate {
int32_t syscall_errno; /* syscall errno */
uint64_t fault; /* DTrace fault flags */
uint64_t tstamp; /* cached timestamp value */
#if 0
dt_pt_regs regs; /* CPU registers */
#endif
uint64_t argv[10]; /* Probe arguments */
} dt_mstate_t;

Expand Down
16 changes: 1 addition & 15 deletions libdtrace/dt_prov_dtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,7 @@ static void trampoline(dt_pcb_t *pcb)
emit(dlp, BPF_MOV_IMM(BPF_REG_4, BPF_ANY));
emit(dlp, BPF_CALL_HELPER(BPF_FUNC_map_update_elem));

#if 0
/*
* dctx->mst->regs = *(dt_pt_regs *)dctx->ctx;
* // lddw %r0, [%r8 + 0]
* // stdw [%r7 + DMST_REGS + 0], %r0
* // lddw %r0, [%r8 + 8]
* // stdw [%r7 + DMST_REGS + 8], %r0
* // (...)
*/
for (i = 0; i < sizeof(dt_pt_regs); i += 8) {
emit(dlp, BPF_LOAD(BPF_DW, BPF_REG_0, BPF_REG_8, i));
emit(dlp, BPF_STORE(BPF_DW, BPF_REG_7, DMST_REGS + i, BPF_REG_0));
}
#endif

dt_cg_tramp_copy_regs(pcb, BPF_REG_8);
dt_cg_tramp_copy_args_from_regs(pcb, BPF_REG_8);

dt_cg_tramp_epilogue_advance(pcb, act);
Expand Down
11 changes: 1 addition & 10 deletions libdtrace/dt_prov_fbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,7 @@ static void trampoline(dt_pcb_t *pcb)
* // (%r8 = dctx->ctx)
*/

#if 0
/*
* dctx->mst->regs = *(dt_pt_regs *)dctx->ctx;
*/
for (i = 0; i < sizeof(dt_pt_regs); i += 8) {
emit(dlp, BPF_LOAD(BPF_DW, BPF_REG_0, BPF_REG_8, i));
emit(dlp, BPF_STORE(BPF_DW, BPF_REG_7, DMST_REGS + i, BPF_REG_0));
}
#endif

dt_cg_tramp_copy_regs(pcb, BPF_REG_8);
dt_cg_tramp_copy_args_from_regs(pcb, BPF_REG_8);
dt_cg_tramp_epilogue(pcb);
}
Expand Down
16 changes: 1 addition & 15 deletions libdtrace/dt_prov_pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,7 @@ static void trampoline(dt_pcb_t *pcb)
* // (%r8 = dctx->ctx)
*/

#if 0
/*
* dctx->mst->regs = *(dt_pt_regs *)dctx->ctx;
* // lddw %r0, [%r8 + 0]
* // stdw [%r7 + DMST_REGS + 0], %r0
* // lddw %r0, [%r8 + 8]
* // stdw [%r7 + DMST_REGS + 8], %r0
* // (...)
*/
for (i = 0; i < sizeof(dt_pt_regs); i += 8) {
emit(dlp, BPF_LOAD(BPF_DW, BPF_REG_0, BPF_REG_8, i));
emit(dlp, BPF_STORE(BPF_DW, BPF_REG_7, DMST_REGS + i, BPF_REG_0));
}
#endif

dt_cg_tramp_copy_regs(pcb, BPF_REG_8);
dt_cg_tramp_copy_args_from_regs(pcb, BPF_REG_8);

/*
Expand Down
13 changes: 1 addition & 12 deletions libdtrace/dt_prov_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,7 @@ static void trampoline(dt_pcb_t *pcb)
* // (%r8 = dctx->ctx)
*/

#if 0
/*
* dctx->mst->regs = *(dt_pt_regs *)&dctx->ctx->regs;
* // (we use the fact that regs is the
* // member at offset 0, and there can
* // copy *(dt_pt_regs *)dctx->ctx)
*/
for (i = 0; i < sizeof(dt_pt_regs); i += 8) {
emit(dlp, BPF_LOAD(BPF_DW, BPF_REG_0, BPF_REG_8, i));
emit(dlp, BPF_STORE(BPF_DW, BPF_REG_7, DMST_REGS + i, BPF_REG_0));
}
#endif
dt_cg_tramp_copy_regs(pcb, BPF_REG_8);

/*
* TODO:
Expand Down
16 changes: 3 additions & 13 deletions libdtrace/dt_prov_sdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static int populate(dtrace_hdl_t *dtp)
* The trampoline function is called when a SDT probe triggers, and it must
* satisfy the following prototype:
*
* int dt_sdt(struct syscall_data *scd)
* int dt_sdt(void *data)
*
* The trampoline will populate a dt_dctx_t struct and then call the function
* that implements the compiled D clause. It returns the value that it gets
Expand All @@ -142,17 +142,7 @@ static void trampoline(dt_pcb_t *pcb)
* // (%r8 = dctx->ctx)
*/

#if 0
/*
* memset(&dctx->mst->regs, 0, sizeof(dt_pt_regs);
* // stdw [%7 + DMST_REGS + 0], 0
* // stdw [%7 + DMST_REGS + 8], 0
* // (...)
*/
for (i = 0; i < sizeof(dt_pt_regs); i += 8) {
emit(dlp, BPF_STORE_IMM(BPF_DW, BPF_REG_7, DMST_REGS + i, 0));
}
#endif
dt_cg_tramp_clear_regs(pcb);

/*
* for (i = 0; i < ARRAY_SIZE(((dt_mstate_t *)0)->argv); i++)
Expand All @@ -175,7 +165,7 @@ static int probe_info(dtrace_hdl_t *dtp, const dt_probe_t *prp,

/*
* If the tracepoint has already been created and we have its info,
* there is no need to retrive the info again.
* there is no need to retrieve the info again.
*/
if (dt_tp_is_created(tpp))
return -1;
Expand Down
11 changes: 1 addition & 10 deletions libdtrace/dt_prov_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,7 @@ static void trampoline(dt_pcb_t *pcb)
* // (%r8 = dctx->ctx)
*/

#if 0
/*
* memset(&dctx->mst->regs, 0, sizeof(dt_pt_regs);
* // stdw [%7 + DMST_REGS + 0], 0
* // stdw [%7 + DMST_REGS + 8], 0
* // (...)
*/
for (i = 0; i < sizeof(dt_pt_regs); i += 8)
emit(dlp, BPF_STORE_IMM(BPF_DW, BPF_REG_7, DMST_REGS + i, 0));
#endif
dt_cg_tramp_clear_regs(pcb);

/*
* for (i = 0; i < argc; i++)
Expand Down

0 comments on commit 2cea90a

Please sign in to comment.