[sanitizer] Fix the parent liveness check in StopTheWorld.
Comparing the parent PID with 1 isn't sufficient to ensure the parent is alive,
because of prctl(PR_SET_CHILD_SUBREAPER, ...). Compare with the real parent's
recorded PID instead.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192295 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc b/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
index d632053..163bd45 100644
--- a/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
+++ b/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
@@ -185,9 +185,10 @@
struct TracerThreadArgument {
StopTheWorldCallback callback;
void *callback_argument;
- // The tracer thread waits on this mutex while the parent finished its
+ // The tracer thread waits on this mutex while the parent finishes its
// preparations.
BlockingMutex mutex;
+ uptr parent_pid;
};
static DieCallbackType old_die_callback;
@@ -226,7 +227,7 @@
internal_prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
// Check if parent is already dead.
- if (internal_getppid() == 1)
+ if (internal_getppid() != tracer_thread_argument->parent_pid)
internal__exit(4);
// Wait for the parent thread to finish preparations.
@@ -370,6 +371,7 @@
struct TracerThreadArgument tracer_thread_argument;
tracer_thread_argument.callback = callback;
tracer_thread_argument.callback_argument = argument;
+ tracer_thread_argument.parent_pid = internal_getpid();
const uptr kTracerStackSize = 2 * 1024 * 1024;
ScopedStackSpaceWithGuard tracer_stack(kTracerStackSize);
// Block the execution of TracerThread until after we have set ptrace