6#if defined(DART_HOST_OS_WINDOWS)
19#define kThreadError -1
21class ThreadInterrupterWin :
public AllStatic {
23 static bool GrabRegisters(
HANDLE handle, InterruptedThreadState*
state) {
25 memset(&context, 0,
sizeof(context));
26#if defined(HOST_ARCH_IA32)
28 context.ContextFlags = CONTEXT_CONTROL;
29#elif defined(HOST_ARCH_X64) || defined(HOST_ARCH_ARM) || \
30 defined(HOST_ARCH_ARM64)
33 context.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER;
35#error Unsupported architecture.
37 if (GetThreadContext(handle, &context) != 0) {
38#if defined(HOST_ARCH_IA32)
39 state->pc =
static_cast<uintptr_t
>(context.Eip);
40 state->fp =
static_cast<uintptr_t
>(context.Ebp);
41 state->csp =
static_cast<uintptr_t
>(context.Esp);
42 state->dsp =
static_cast<uintptr_t
>(context.Esp);
44#elif defined(HOST_ARCH_X64)
45 state->pc =
static_cast<uintptr_t
>(context.Rip);
46 state->fp =
static_cast<uintptr_t
>(context.Rbp);
47 state->csp =
static_cast<uintptr_t
>(context.Rsp);
48 state->dsp =
static_cast<uintptr_t
>(context.Rsp);
50#elif defined(HOST_ARCH_ARM)
51 state->pc =
static_cast<uintptr_t
>(context.Pc);
52 state->fp =
static_cast<uintptr_t
>(context.R11);
53 state->csp =
static_cast<uintptr_t
>(context.Sp);
54 state->dsp =
static_cast<uintptr_t
>(context.Sp);
55 state->lr =
static_cast<uintptr_t
>(context.R14);
56#elif defined(HOST_ARCH_ARM64)
57 state->pc =
static_cast<uintptr_t
>(context.Pc);
58 state->fp =
static_cast<uintptr_t
>(context.Fp);
59 state->csp =
static_cast<uintptr_t
>(context.Sp);
60 state->dsp =
static_cast<uintptr_t
>(context.X15);
61 state->lr =
static_cast<uintptr_t
>(context.Lr);
63#error Unsupported architecture.
70 static void Interrupt(OSThread* os_thread) {
72 HANDLE handle = OpenThread(
73 THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION | THREAD_SUSPEND_RESUME,
74 false, os_thread->id());
77 if (
result == kThreadError) {
78 if (FLAG_trace_thread_interrupter) {
79 OS::PrintErr(
"ThreadInterrupter failed to suspend thread %p\n",
80 reinterpret_cast<void*
>(os_thread->id()));
85 InterruptedThreadState its;
86 if (!GrabRegisters(handle, &its)) {
89 if (FLAG_trace_thread_interrupter) {
90 OS::PrintErr(
"ThreadInterrupter failed to get registers for %p\n",
91 reinterpret_cast<void*
>(os_thread->id()));
99 Thread* thread =
static_cast<Thread*
>(os_thread->thread());
100 if (thread !=
nullptr) {
101 ThreadInterruptScope signal_handler_scope;
104 ResumeThread(handle);
110 if (FLAG_trace_thread_interrupter) {
112 reinterpret_cast<void*
>(thread->id()));
114 ThreadInterrupterWin::Interrupt(thread);
115 if (FLAG_trace_thread_interrupter) {
117 reinterpret_cast<void*
>(thread->id()));
121void ThreadInterrupter::InstallSignalHandler() {
125void ThreadInterrupter::RemoveSignalHandler() {
static bool Compare(ThreadId a, ThreadId b)
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static void SampleThread(Thread *thread, const InterruptedThreadState &state)
static void InterruptThread(OSThread *thread)
DECLARE_FLAG(bool, show_invisible_frames)