-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement strlen() based on bpf_probe_read_str()
The bpf_probe_read_str() BPF helper returns the number of characters it copies (incl. the terminating NUL byte), up to the maximum number passed as one of the arguments. This can be used to determine the length of a string. This new strlen() implementation makes use of the unused space at the end of the string constant table, which is sized so that it can contain the largest string possible. The implementation of substr() is adjusted to reflect this change as well. Rather than calling the strlen() function, it uses the BPF helper directly. This patch also introduces tests for the strlen() function. Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com> Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
- Loading branch information
Showing
14 changed files
with
248 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* ASSERTION: The argument to strlen() should be a string. | ||
* | ||
* SECTION: Actions and Subroutines/strlen() | ||
*/ | ||
|
||
BEGIN | ||
{ | ||
strlen(12); | ||
exit(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* ASSERTION: strlen() requires an argument | ||
* | ||
* SECTION: Actions and Subroutines/strlen() | ||
*/ | ||
|
||
BEGIN | ||
{ | ||
strlen(); | ||
exit(0); | ||
} |
18 changes: 18 additions & 0 deletions
18
test/unittest/funcs/strlen/err.D_PROTO_LEN.too_many_args.d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/* | ||
* ASSERTION: strlen() accepts exactly one argument | ||
* | ||
* SECTION: Actions and Subroutines/strlen() | ||
*/ | ||
|
||
BEGIN | ||
{ | ||
strlen("", 1); | ||
exit(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
*/ | ||
|
||
/* | ||
* ASSERTION: The strlen() subroutine returns the correct result. | ||
* | ||
* SECTION: Actions and Subroutines/strlen() | ||
*/ | ||
|
||
/* @@runtest-opts: -C */ | ||
|
||
#pragma D option quiet | ||
|
||
#define TEST(s) printf("%60s %d\n", (s), strlen(s)) | ||
|
||
BEGIN | ||
{ | ||
TEST("1"); | ||
TEST("12"); | ||
TEST("123"); | ||
TEST("12345"); | ||
TEST("123456"); | ||
TEST("1234567"); | ||
TEST("12345678"); | ||
TEST("123456789"); | ||
TEST("1234567890"); | ||
TEST("12345678901234567890"); | ||
TEST("123456789012345678901234567890"); | ||
TEST("1234567890123456789012345678901234567890"); | ||
TEST("12345678901234567890123456789012345678901234567890"); | ||
TEST("123456789012345678901234567890123456789012345678901234567890"); | ||
exit(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
1 1 | ||
12 2 | ||
123 3 | ||
12345 5 | ||
123456 6 | ||
1234567 7 | ||
12345678 8 | ||
123456789 9 | ||
1234567890 10 | ||
12345678901234567890 20 | ||
123456789012345678901234567890 30 | ||
1234567890123456789012345678901234567890 40 | ||
12345678901234567890123456789012345678901234567890 50 | ||
123456789012345678901234567890123456789012345678901234567890 60 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
*/ | ||
|
||
/* | ||
* ASSERTION: strlen() obeys the maximum string size setting | ||
* | ||
* SECTION: Actions and Subroutines/strlen() | ||
*/ | ||
|
||
#pragma D option strsize=5 | ||
#pragma D option quiet | ||
|
||
BEGIN | ||
{ | ||
exit(strlen("123456789") == 5 ? 0 : 1); | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(1); | ||
} |
Oops, something went wrong.