Skip to content

Commit

Permalink
cg, bpf: Pass dctx as first arg in arg-to-tstring subroutines
Browse files Browse the repository at this point in the history
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@oracle.com>
  • Loading branch information
kvanhees committed Jul 21, 2023
1 parent e3529a5 commit aabbba8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
6 changes: 3 additions & 3 deletions bpf/basename.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions bpf/dirname.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions bpf/inet_ntoa.S
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ dt_inet_ntoa_write_uint8:
#undef PTR

/*
* uint64_t dt_inet_ntoa(uint8_t *src, char *dst) {
* uint64_t 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);
Expand Down Expand Up @@ -161,9 +161,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
Expand Down
6 changes: 3 additions & 3 deletions bpf/lltostr.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */

Expand Down
8 changes: 5 additions & 3 deletions libdtrace/dt_cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit aabbba8

Please sign in to comment.