From 5fe72ccbb2c5733e929b146e23ba7c5aa16faab5 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Fri, 16 Mar 2018 22:15:05 +0000 Subject: [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 --- test/asan/TestCases/Posix/vfork.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/asan/TestCases/Posix/vfork.cc (limited to 'test/asan') 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 +#include +#include +#include + +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; +} -- cgit v1.2.3