StackSamplingProfiler: walk a copy of the stack

Changes the stack walking strategy to copy the stack while the target
thread is suspended, then walk the copy of the stack after the thread
has been resumed. This avoids deadlock on locks taken by
RtlLookupFunctionEntry when walking the actual stack while the target
thread is suspended.

BUG=528129

Review URL: https://codereview.chromium.org/1367633002

Cr-Commit-Position: refs/heads/master@{#353004}
NOINLINE void TargetThread::SignalAndWaitUntilSignaled(
NOINLINE const void* TargetThread::SignalAndWaitUntilSignaled(
     WaitableEvent* thread_started_event,
     WaitableEvent* finish_event) {
  if (thread_started_event && finish_event) {
    thread_started_event->Signal();
    finish_event->Wait();
  }

  // Volatile to prevent a tail call to GetProgramCounter().
  const void* volatile program_counter = GetProgramCounter();
  return program_counter;
 }

NOINLINE void TargetThread::SignalAndWaitUntilSignaled(
     WaitableEvent* thread_started_event,
     WaitableEvent* finish_event) {
  thread_started_event->Signal();
  volatile int x = 1;
  finish_event->Wait();
  x = 0;  // Prevent tail call to WaitableEvent::Wait().
  ALLOW_UNUSED_LOCAL(x);
 }
