summaryrefslogtreecommitdiff
path: root/test/asan
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2018-03-16 22:15:05 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2018-03-16 22:15:05 +0000
commit5fe72ccbb2c5733e929b146e23ba7c5aa16faab5 (patch)
tree61ca64efa12cb05334d476a7e1dc19164cd90903 /test/asan
parentda8ddca6ddbd7f12d73eb42c268f37a0c0a345c5 (diff)
[asan] Replace vfork with fork.
Summary: vfork is not ASan-friendly because it modifies stack shadow in the parent process address space. While it is possible to compensate for that with, for example, __asan_handle_no_return before each call to _exit or execve and friends, simply replacing vfork with fork looks like by far the easiest solution. Posix compliant programs can not detect the difference between vfork and fork. Fixes https://github.com/google/sanitizers/issues/925 Reviewers: kcc, vitalybuka Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D44587 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@327752 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/asan')
-rw-r--r--test/asan/TestCases/Posix/vfork.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/asan/TestCases/Posix/vfork.cc b/test/asan/TestCases/Posix/vfork.cc
new file mode 100644
index 000000000..5fcb11f53
--- /dev/null
+++ b/test/asan/TestCases/Posix/vfork.cc
@@ -0,0 +1,30 @@
+// Test that vfork() is fork().
+// https://github.com/google/sanitizers/issues/925
+
+// RUN: %clangxx_asan -O0 %s -o %t && %run %t 2>&1
+
+#include <assert.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+int volatile global;
+
+int main(int argc, char **argv) {
+ pid_t pid = vfork();
+ if (pid) {
+ // parent
+ int status;
+ int res;
+ do {
+ res = waitpid(pid, &status, 0);
+ } while (res >= 0 && !WIFEXITED(status) && !WIFSIGNALED(status));
+ assert(global == 0);
+ } else {
+ // child
+ global = 42;
+ _exit(0);
+ }
+
+ return 0;
+}