-
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.
In C, strings are (char*), and it is possible to have a NULL pointer. In D, strings have fixed length strsize. There may still be NULL pointers -- say, as inputs to strtok() or as outputs from unsuccessful strchr() (and other) functions. Such NULL pointers are not a problem for storing strings as dynamic variables (thread-local variables or associative arrays), since storing 0 clears a dynamic element and reading a cleared element means 0. Static (global and local) variables are a different story. Each string has strsize bytes allocated for it, and every possible string value is legal: bytes up to the first NUL are part of the string and subsequent bytes are ignored. There is no value that represents a NULL string. Specifically, there is an important semantic difference between NULL and empty strings. The former are NULL pointers, while the latter are strings that simply start with the NUL terminating char. Add code to handle store and load of NULL-pointer strings to and from global and local variables. Specifically, define a byte string DT_NULL_STRING whose first byte is 0x00 but with extra nonzero bytes to distinguish between empty and NULL strings. An empty string stored as a static variable will have its first bytes all zero. A NULL string will have its first bytes be DT_NULL_STRING. That is, both will have initial byte 0, and then we have to go further to distinguish the two cases. We require strsize >= sizeof(DT_NULL_STRING), which is reasonable. Note that comparisons between NULL and empty strings should work the same way as between NULL strings and any other non-NULL strings. Note that Solaris and legacy DTrace on Linux incorrectly treated comparisons between NULL and empty strings as between equal values. Signed-off-by: Eugene Loh <eugene.loh@oracle.com> Reviewed-by: Nick Alcock <nick.alcock@oracle.com> Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
- Loading branch information
Showing
29 changed files
with
555 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Oracle Linux DTrace. | ||
* Copyright (c) 2023, 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 | ||
|
||
BEGIN | ||
{ | ||
s[1234] = "ABCDEFG"; | ||
trace(s[1234][1]); | ||
} | ||
|
||
BEGIN | ||
{ | ||
s[1234] = NULL; | ||
trace(s[1234][1]); | ||
} | ||
|
||
BEGIN | ||
{ | ||
exit(0); | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(1); | ||
} |
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,3 @@ | ||
66 | ||
-- @@stderr -- | ||
dtrace: error on enabled probe ID 4 (ID 1: dtrace:::BEGIN): invalid address (1) in action #2 at BPF pc NNN |
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,6 @@ | ||
#!/usr/bin/sed -f | ||
|
||
# runtest.sh looks for "0x" to filter out pointer values. | ||
# Strip the 0x so that the illegal address will not be filtered out; | ||
# we want the address to be checked. | ||
s/0x// |
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,30 @@ | ||
/* | ||
* Oracle Linux DTrace. | ||
* Copyright (c) 2023, 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 | ||
|
||
BEGIN | ||
{ | ||
s = "ABCDEFG"; | ||
trace(s[1]); | ||
} | ||
|
||
BEGIN | ||
{ | ||
s = NULL; | ||
trace(s[1]); | ||
} | ||
|
||
BEGIN | ||
{ | ||
exit(0); | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(1); | ||
} |
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,3 @@ | ||
66 | ||
-- @@stderr -- | ||
dtrace: error on enabled probe ID 4 (ID 1: dtrace:::BEGIN): invalid address (1) in action #2 at BPF pc NNN |
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,6 @@ | ||
#!/usr/bin/sed -f | ||
|
||
# runtest.sh looks for "0x" to filter out pointer values. | ||
# Strip the 0x so that the illegal address will not be filtered out; | ||
# we want the address to be checked. | ||
s/0x// |
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,30 @@ | ||
/* | ||
* Oracle Linux DTrace. | ||
* Copyright (c) 2023, 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 | ||
|
||
BEGIN | ||
{ | ||
this->s = "ABCDEFG"; | ||
trace(this->s[1]); | ||
} | ||
|
||
BEGIN | ||
{ | ||
this->s = NULL; | ||
trace(this->s[1]); | ||
} | ||
|
||
BEGIN | ||
{ | ||
exit(0); | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(1); | ||
} |
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,3 @@ | ||
66 | ||
-- @@stderr -- | ||
dtrace: error on enabled probe ID 4 (ID 1: dtrace:::BEGIN): invalid address (1) in action #2 at BPF pc NNN |
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,6 @@ | ||
#!/usr/bin/sed -f | ||
|
||
# runtest.sh looks for "0x" to filter out pointer values. | ||
# Strip the 0x so that the illegal address will not be filtered out; | ||
# we want the address to be checked. | ||
s/0x// |
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,30 @@ | ||
/* | ||
* Oracle Linux DTrace. | ||
* Copyright (c) 2023, 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 | ||
|
||
BEGIN | ||
{ | ||
self->s = "ABCDEFG"; | ||
trace(self->s[1]); | ||
} | ||
|
||
BEGIN | ||
{ | ||
self->s = NULL; | ||
trace(self->s[1]); | ||
} | ||
|
||
BEGIN | ||
{ | ||
exit(0); | ||
} | ||
|
||
ERROR | ||
{ | ||
exit(1); | ||
} |
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,3 @@ | ||
66 | ||
-- @@stderr -- | ||
dtrace: error on enabled probe ID 4 (ID 1: dtrace:::BEGIN): invalid address (1) in action #2 at BPF pc NNN |
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,6 @@ | ||
#!/usr/bin/sed -f | ||
|
||
# runtest.sh looks for "0x" to filter out pointer values. | ||
# Strip the 0x so that the illegal address will not be filtered out; | ||
# we want the address to be checked. | ||
s/0x// |
Oops, something went wrong.