[DTrace-devel] [PATCH 04/14] Support basename() for addresses that are not DTrace pointers
eugene.loh at oracle.com
eugene.loh at oracle.com
Thu Nov 3 19:52:16 UTC 2022
From: Eugene Loh <eugene.loh at oracle.com>
Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
bpf/basename.S | 13 ++++++++----
test/unittest/funcs/tst.basename_nonDPTR.d | 24 ++++++++++++++++++++++
test/unittest/funcs/tst.basename_nonDPTR.r | 2 ++
3 files changed, 35 insertions(+), 4 deletions(-)
create mode 100644 test/unittest/funcs/tst.basename_nonDPTR.d
create mode 100644 test/unittest/funcs/tst.basename_nonDPTR.r
diff --git a/bpf/basename.S b/bpf/basename.S
index 6bb96b70..23cf15d0 100644
--- a/bpf/basename.S
+++ b/bpf/basename.S
@@ -22,6 +22,11 @@ dt_basename :
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
@@ -44,8 +49,8 @@ dt_basename :
sub LEN, 1
/* if (len s< 0) goto Lslash */
jslt LEN, 0, .Lslash
- /* if (src[len] == '/') goto Lend */
- mov %r1, SRC
+ /* if (dst[len] == '/') goto Lend */
+ mov %r1, DST
add %r1, LEN
ldxb %r1, [%r1+0]
and %r1, 0xff
@@ -61,8 +66,8 @@ dt_basename :
sub BGN, 1
/* if (bgn s< 0) goto Lcopy */
jslt BGN, 0, .Lcopy
- /* if (src[bgn] != '/') goto Lbgn */
- mov %r1, SRC
+ /* if (dst[bgn] != '/') goto Lbgn */
+ mov %r1, DST
add %r1, BGN
ldxb %r1, [%r1+0]
and %r1, 0xff
diff --git a/test/unittest/funcs/tst.basename_nonDPTR.d b/test/unittest/funcs/tst.basename_nonDPTR.d
new file mode 100644
index 00000000..12f6436c
--- /dev/null
+++ b/test/unittest/funcs/tst.basename_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\x62\x61\x7a\x2f\x2e\x2f\x2f' > /dev/null 2>&1");
+}
+
+syscall::write:entry
+/ppid == $pid/
+{
+ printf("|%s|\n", basename((void *)arg1));
+ exit(0);
+}
+
+ERROR { exit(1); }
diff --git a/test/unittest/funcs/tst.basename_nonDPTR.r b/test/unittest/funcs/tst.basename_nonDPTR.r
new file mode 100644
index 00000000..3e52321d
--- /dev/null
+++ b/test/unittest/funcs/tst.basename_nonDPTR.r
@@ -0,0 +1,2 @@
+|.|
+
--
2.18.4
More information about the DTrace-devel
mailing list