Guard against frames across pages, in the profiler.
On Windows, if a page is not touched yet by the stack's thread, the page may be a guard page.
BUG=
R=johnmccutchan@google.com
Review URL: https://codereview.chromium.org//293133007
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@36623 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/runtime/vm/profiler.cc b/runtime/vm/profiler.cc
index de2afea..1c6e2cc 100644
--- a/runtime/vm/profiler.cc
+++ b/runtime/vm/profiler.cc
@@ -1687,7 +1687,7 @@
// Stack pointer should not be above frame pointer.
return 1;
}
- intptr_t gap = original_fp_ - original_sp_;
+ const intptr_t gap = original_fp_ - original_sp_;
if (gap >= kMaxStep) {
// Gap between frame pointer and stack pointer is
// too large.
@@ -1698,8 +1698,19 @@
// the isolates stack limit.
lower_bound_ = original_sp_;
}
- // Store the PC marker for the top frame.
- sample_->set_pc_marker(GetCurrentFramePcMarker(fp));
+#if defined(TARGET_OS_WINDOWS)
+ // If the original_fp_ is at the beginning of a page, it may be unsafe
+ // to access the pc marker, because we are reading it from a different
+ // thread on Windows. The next page may be a guard page.
+ const intptr_t kPageMask = kMaxStep - 1;
+ bool safe_to_read_pc_marker = (original_fp_ & kPageMask) != 0;
+#else
+ bool safe_to_read_pc_marker = true;
+#endif
+ if (safe_to_read_pc_marker && (gap > 0)) {
+ // Store the PC marker for the top frame.
+ sample_->set_pc_marker(GetCurrentFramePcMarker(fp));
+ }
int i = 0;
for (; i < FLAG_profile_depth; i++) {
if (FLAG_profile_verify_stack_walk) {
diff --git a/runtime/vm/thread_interrupter_win.cc b/runtime/vm/thread_interrupter_win.cc
index 4f952e1..b39c188 100644
--- a/runtime/vm/thread_interrupter_win.cc
+++ b/runtime/vm/thread_interrupter_win.cc
@@ -19,7 +19,7 @@
static bool GrabRegisters(HANDLE handle, InterruptedThreadState* state) {
CONTEXT context;
memset(&context, 0, sizeof(context));
- context.ContextFlags = CONTEXT_FULL;
+ context.ContextFlags = CONTEXT_CONTROL;
if (GetThreadContext(handle, &context) != 0) {
#if defined(TARGET_ARCH_IA32)
state->pc = static_cast<uintptr_t>(context.Eip);
@@ -41,6 +41,7 @@
static void Interrupt(InterruptableThreadState* state) {
ASSERT(!Thread::Compare(GetCurrentThreadId(), state->id));
HANDLE handle = OpenThread(THREAD_GET_CONTEXT |
+ THREAD_QUERY_INFORMATION |
THREAD_SUSPEND_RESUME,
false,
state->id);