[DTrace-devel] [PATCH v2 2/4] Fix syscall:::return args
eugene.loh at oracle.com
eugene.loh at oracle.com
Thu May 5 01:00:21 UTC 2022
From: Eugene Loh <eugene.loh at oracle.com>
Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
libdtrace/dt_prov_syscall.c | 8 ++++--
test/unittest/syscall/tst.return_args.d | 37 +++++++++++++++++++++++++
test/unittest/syscall/tst.return_args.r | 6 ++++
3 files changed, 49 insertions(+), 2 deletions(-)
create mode 100644 test/unittest/syscall/tst.return_args.d
create mode 100644 test/unittest/syscall/tst.return_args.r
diff --git a/libdtrace/dt_prov_syscall.c b/libdtrace/dt_prov_syscall.c
index 2c6644d4..c078ce36 100644
--- a/libdtrace/dt_prov_syscall.c
+++ b/libdtrace/dt_prov_syscall.c
@@ -159,6 +159,7 @@ static void trampoline(dt_pcb_t *pcb)
dt_cg_tramp_clear_regs(pcb);
/*
+ * Copy in the probe args.
* for (i = 0; i < argc; i++)
* dctx->mst->argv[i] =
* ((struct syscall_data *)dctx->ctx)->arg[i];
@@ -171,7 +172,8 @@ static void trampoline(dt_pcb_t *pcb)
}
/*
- * for i = argc; i < ARRAY_SIZE(((dt_mstate_t *)0)->argv); i++)
+ * Zero the remaining probe args.
+ * for ( ; i < ARRAY_SIZE(((dt_mstate_t *)0)->argv); i++)
* dctx->mst->argv[i] = 0;
* // stdw [%r7 + DMST_ARG(i)], 0
*/
@@ -181,12 +183,14 @@ static void trampoline(dt_pcb_t *pcb)
/*
* For return probes, store the errno. That is, examine arg0.
* If it is >=0 or <=-2048, ignore it. Otherwise, store -arg0
- * in dctx->mst->syscall_errno.
+ * in dctx->mst->syscall_errno. In any case, copy arg0 to arg1
+ * as required for syscall:::return probe arguments.
*/
if (strcmp(pcb->pcb_probe->desc->prb, "return") == 0) {
uint_t lbl_errno_done = dt_irlist_label(dlp);
emit(dlp, BPF_LOAD(BPF_DW, BPF_REG_0, BPF_REG_7, DMST_ARG(0)));
+ emit(dlp, BPF_STORE(BPF_DW, BPF_REG_7, DMST_ARG(1), BPF_REG_0));
emit(dlp, BPF_BRANCH_IMM(BPF_JSGE, BPF_REG_0, 0, lbl_errno_done));
emit(dlp, BPF_BRANCH_IMM(BPF_JSLE, BPF_REG_0, -2048, lbl_errno_done));
emit(dlp, BPF_NEG_REG(BPF_REG_0));
diff --git a/test/unittest/syscall/tst.return_args.d b/test/unittest/syscall/tst.return_args.d
new file mode 100644
index 00000000..459afec5
--- /dev/null
+++ b/test/unittest/syscall/tst.return_args.d
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+
+/* @@trigger: bogus-ioctl */
+/* @@trigger-timing: before */
+/* @@runtest-opts: $_pid */
+
+#pragma D option destructive
+#pragma D option quiet
+
+BEGIN
+{
+ n = 0;
+}
+
+syscall::ioctl:entry
+/pid == $1/
+{
+ raise(SIGUSR1);
+}
+
+syscall::open*:return
+/pid == $1/
+{
+ n++;
+ printf("%d %d\n", arg0, arg1);
+}
+
+syscall::open*:return
+/pid == $1 && n >= 5/
+{
+ exit(0);
+}
diff --git a/test/unittest/syscall/tst.return_args.r b/test/unittest/syscall/tst.return_args.r
new file mode 100644
index 00000000..93d7c505
--- /dev/null
+++ b/test/unittest/syscall/tst.return_args.r
@@ -0,0 +1,6 @@
+0 0
+1 1
+2 2
+3 3
+4 4
+
--
2.18.4
More information about the DTrace-devel
mailing list