[DTrace-devel] [PATCH 05/14] Support dirname() for addresses that are not DTrace pointers
eugene.loh at oracle.com
eugene.loh at oracle.com
Thu Nov 3 19:52:17 UTC 2022
From: Eugene Loh <eugene.loh at oracle.com>
Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
bpf/dirname.S | 17 ++++++++++------
test/unittest/funcs/tst.dirname_nonDPTR.d | 24 +++++++++++++++++++++++
test/unittest/funcs/tst.dirname_nonDPTR.r | 2 ++
3 files changed, 37 insertions(+), 6 deletions(-)
create mode 100644 test/unittest/funcs/tst.dirname_nonDPTR.d
create mode 100644 test/unittest/funcs/tst.dirname_nonDPTR.r
diff --git a/bpf/dirname.S b/bpf/dirname.S
index e5795f06..7ff90b47 100644
--- a/bpf/dirname.S
+++ b/bpf/dirname.S
@@ -21,6 +21,11 @@ dt_dirname :
mov SRC, %r1
mov DST, %r2
+ /*
+ * Copy src to dst for two reasons:
+ * - to get the string length
+ * - to have a copy that we can access directly
+ */
/* r0 = bpf_probe_read_str(dst, STRSZ + 1, src) */
mov %r1, DST
lddw %r2, STRSZ
@@ -49,8 +54,8 @@ dt_dirname :
sub LEN, 1
/* if (len s< 0) goto Lslash */
jslt LEN, 0, .Lslash
- /* if (src[len] == '/') goto L1 */
- mov %r0, SRC
+ /* if (dst[len] == '/') goto L1 */
+ mov %r0, DST
add %r0, LEN
ldxb %r0, [%r0+0]
and %r0, 0xff
@@ -65,8 +70,8 @@ dt_dirname :
sub LEN, 1
/* if (len s< 0) goto Ldot */
jslt LEN, 0, .Ldot
- /* if (src[len] != '/') goto L2 */
- mov %r0, SRC
+ /* if (dst[len] != '/') goto L2 */
+ mov %r0, DST
add %r0, LEN
ldxb %r0, [%r0+0]
and %r0, 0xff
@@ -81,8 +86,8 @@ dt_dirname :
sub LEN, 1
/* if (len s< 0) goto Lslash */
jslt LEN, 0, .Lslash
- /* if (src[len] == '/') goto L3 */
- mov %r0, SRC
+ /* if (dst[len] == '/') goto L3 */
+ mov %r0, DST
add %r0, LEN
ldxb %r0, [%r0+0]
and %r0, 0xff
diff --git a/test/unittest/funcs/tst.dirname_nonDPTR.d b/test/unittest/funcs/tst.dirname_nonDPTR.d
new file mode 100644
index 00000000..dab80655
--- /dev/null
+++ b/test/unittest/funcs/tst.dirname_nonDPTR.d
@@ -0,0 +1,24 @@
+/*
+ * 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
+#pragma D option destructive
+
+BEGIN
+{
+ /* "/foo/bar///baz/" */
+ system("printf '\x2f\x66\x6f\x6f\x2f\x62\x61\x72\x2f\x2f\x2f\x62\x61\x7a\x2f' > /dev/null 2>&1");
+}
+
+syscall::write:entry
+/ppid == $pid/
+{
+ printf("|%s|\n", dirname((void *)arg1));
+ exit(0);
+}
+
+ERROR { exit(1); }
diff --git a/test/unittest/funcs/tst.dirname_nonDPTR.r b/test/unittest/funcs/tst.dirname_nonDPTR.r
new file mode 100644
index 00000000..bb8afc9d
--- /dev/null
+++ b/test/unittest/funcs/tst.dirname_nonDPTR.r
@@ -0,0 +1,2 @@
+|/foo/bar|
+
--
2.18.4
More information about the DTrace-devel
mailing list