[DTrace-devel] [PATCH 06/14] Support strrchr() for addresses that are not DTrace pointers
Kris Van Hees
kris.van.hees at oracle.com
Sat Feb 18 06:34:21 UTC 2023
On Thu, Nov 03, 2022 at 03:52:18PM -0400, eugene.loh--- via DTrace-devel wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
>
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
> ---
> bpf/strrchr.S | 6 +++---
> test/unittest/funcs/tst.strchr_nonDPTR.d | 25 ++++++++++++++++++++++++
> test/unittest/funcs/tst.strchr_nonDPTR.r | 3 +++
> 3 files changed, 31 insertions(+), 3 deletions(-)
> create mode 100644 test/unittest/funcs/tst.strchr_nonDPTR.d
> create mode 100644 test/unittest/funcs/tst.strchr_nonDPTR.r
>
> diff --git a/bpf/strrchr.S b/bpf/strrchr.S
> index 8273b59c..05ccecb9 100644
> --- a/bpf/strrchr.S
> +++ b/bpf/strrchr.S
> @@ -21,7 +21,7 @@
> * r8 = r6;
> * Lloop:
> * r8--;
> - * r3 = src[r8];
> + * r3 = dst[r8]; // use copy in dst[] in case src[] is unsafe memory
> * r3 <<= 56;
> * if (r3 == c) goto Lfound;
> * if (r8 > 0) goto Lloop;
> @@ -65,9 +65,9 @@ dt_strrchr :
> .Lloop:
> sub %r8, 1 /* r8-- */
> mov %r4, %r8
> - ldxdw %r3, [%fp+-8]
> + ldxdw %r3, [%fp+-24]
> add %r3, %r4
> - ldxb %r3, [%r3+0] /* r3 = src[r8] */
> + ldxb %r3, [%r3+0] /* r3 = dst[r8] */
> lsh %r3, 56 /* r3 <<= 56 */
> jeq %r3, %r5, .Lfound /* if (r3 == c) goto Lfound */
> jgt %r8, 0, .Lloop /* if (r8 > 0) goto Lloop */
> diff --git a/test/unittest/funcs/tst.strchr_nonDPTR.d b/test/unittest/funcs/tst.strchr_nonDPTR.d
> new file mode 100644
> index 00000000..95cb08c2
> --- /dev/null
> +++ b/test/unittest/funcs/tst.strchr_nonDPTR.d
> @@ -0,0 +1,25 @@
> +/*
> + * 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
> +{
> + /* "abcdef" */
> + system("printf '\x61\x62\x63\x64\x65\x66' > /dev/null 2>&1");
> +}
> +
> +syscall::write:entry
> +/ppid == $pid/
> +{
> + printf("|%s|\n", strchr((void *)arg1, 'b'));
> + printf("|%s|\n", strrchr((void *)arg1, 'b'));
> + exit(0);
> +}
> +
> +ERROR { exit(1); }
> diff --git a/test/unittest/funcs/tst.strchr_nonDPTR.r b/test/unittest/funcs/tst.strchr_nonDPTR.r
> new file mode 100644
> index 00000000..b1b10def
> --- /dev/null
> +++ b/test/unittest/funcs/tst.strchr_nonDPTR.r
> @@ -0,0 +1,3 @@
> +|bcdef|
> +|bcdef|
> +
> --
> 2.18.4
>
>
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel
More information about the DTrace-devel
mailing list