Skip to content

Commit

Permalink
Add support for getmajor() and getminor() subroutines
Browse files Browse the repository at this point in the history
Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
euloh authored and kvanhees committed Apr 21, 2022
1 parent 14b51ea commit ebfecdf
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
30 changes: 28 additions & 2 deletions libdtrace/dt_cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -3949,6 +3949,32 @@ dt_cg_subr_rindex(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp)
TRACE_REGSET(" subr-rindex:End ");
}

/*
* For getmajor and getminor, use MAJOR(dev) and MINOR(dev)
* as defined in kernel header include/linux/kdev_t.h, not
* as defined in user header /usr/include/linux/kdev_t.h.
*/
static void
dt_cg_subr_getmajor(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp)
{
dt_node_t *arg = dnp->dn_args;

dt_cg_node(arg, dlp, drp);
dnp->dn_reg = arg->dn_reg;
emit(dlp, BPF_ALU64_IMM(BPF_LSH, dnp->dn_reg, 32));
emit(dlp, BPF_ALU64_IMM(BPF_RSH, dnp->dn_reg, 32 + 20));
}

static void
dt_cg_subr_getminor(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp)
{
dt_node_t *arg = dnp->dn_args;

dt_cg_node(arg, dlp, drp);
dnp->dn_reg = arg->dn_reg;
emit(dlp, BPF_ALU64_IMM(BPF_AND, dnp->dn_reg, 0xfffff));
}

/*
* Get and return a new speculation ID. These are unallocated entries in the
* specs map, obtained by calling dt_speculation(). Return zero if none is
Expand Down Expand Up @@ -4594,8 +4620,8 @@ static dt_cg_subr_f *_dt_cg_subr[DIF_SUBR_MAX + 1] = {
[DIF_SUBR_COPYINTO] = NULL,
[DIF_SUBR_MSGDSIZE] = NULL,
[DIF_SUBR_MSGSIZE] = NULL,
[DIF_SUBR_GETMAJOR] = NULL,
[DIF_SUBR_GETMINOR] = NULL,
[DIF_SUBR_GETMAJOR] = &dt_cg_subr_getmajor,
[DIF_SUBR_GETMINOR] = &dt_cg_subr_getminor,
[DIF_SUBR_DDI_PATHNAME] = NULL,
[DIF_SUBR_STRJOIN] = dt_cg_subr_strjoin,
[DIF_SUBR_LLTOSTR] = &dt_cg_subr_lltostr,
Expand Down
19 changes: 19 additions & 0 deletions test/unittest/funcs/tst.getmajor.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2022, 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.
*/

#pragma D option quiet

BEGIN
{
printf("%x", getmajor(0xabcdef0123456789ll));
exit(0);
}

ERROR
{
exit(1);
}
1 change: 1 addition & 0 deletions test/unittest/funcs/tst.getmajor.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
234
19 changes: 19 additions & 0 deletions test/unittest/funcs/tst.getminor.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2022, 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.
*/

#pragma D option quiet

BEGIN
{
printf("%x", getminor(0xabcdef0123456789ll));
exit(0);
}

ERROR
{
exit(1);
}
1 change: 1 addition & 0 deletions test/unittest/funcs/tst.getminor.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
56789

0 comments on commit ebfecdf

Please sign in to comment.