-
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.
Add support for built-in variable errno
The built-in variable errno should be: *) the errno for failed system calls for syscall:::return probes *) 0 otherwise The D errno variable is different from the C library errno variable. Also, the behavior differs from that described in the DTrace Guide, which allows errno to be non-0 for non-syscall probes. Introduce an mst->syscall_errno, and have the provider trampolines set it to 0. Then have syscall:::return probes check arg0, setting mst->syscall_errno=-arg0 if the value would be within bounds. Finally, have dt_get_bvar() retrieve errno from mst->syscall_errno. Update tests. The only particularly meaningful test for errno is tst.errno2.d, which will not yet work since it still needs other as yet unsupported features. Add a tst.errno3.sh test for the new errno support. Signed-off-by: Eugene Loh <eugene.loh@oracle.com> Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
- Loading branch information
Showing
9 changed files
with
81 additions
and
3 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
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 @@ | ||
0 0 0 0 0 0 0 0 0 2 0 9 0 2 0 9 0 0 0 0 0 0 0 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,56 @@ | ||
#!/bin/bash | ||
# | ||
# Oracle Linux DTrace. | ||
# Copyright (c) 2021, 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. | ||
# | ||
|
||
dtrace=$1 | ||
CC=/usr/bin/gcc | ||
|
||
DIRNAME="$tmpdir/builtinvar-errno3.$$.$RANDOM" | ||
mkdir -p $DIRNAME | ||
cd $DIRNAME | ||
|
||
cat << EOF > main.c | ||
#include <stdio.h> | ||
#include <errno.h> | ||
#include <sys/types.h> /* open() */ | ||
#include <sys/stat.h> /* open() */ | ||
#include <fcntl.h> /* open() */ | ||
#include <unistd.h> /* close() */ | ||
void foo(char *s) { | ||
int fd = open(s, O_WRONLY); | ||
close(fd); | ||
} | ||
int main(int c, char **v) { | ||
foo("/dev/null"); | ||
foo("/dev/null"); | ||
foo("/no/such/path/exists"); | ||
foo("/no/such/path/exists"); | ||
foo("/dev/null"); | ||
foo("/dev/null"); | ||
return 0; | ||
} | ||
EOF | ||
|
||
$CC main.c | ||
if [ $? -ne 0 ]; then | ||
echo compilation failed | ||
exit 1 | ||
fi | ||
|
||
$dtrace $dt_flags -Zqn ' | ||
syscall::open:, | ||
syscall::openat:, | ||
syscall::close: | ||
/pid == $target/ | ||
{ printf(" %d", errno); } | ||
' -c ./a.out | ||
if [ $? -ne 0 ]; then | ||
echo DTrace failed | ||
exit 1 | ||
fi | ||
|
||
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