| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
| 7 | 7 |
| 8 #include <sys/syscall.h> // NOLINT | 8 #include <sys/syscall.h> // NOLINT |
| 9 | 9 |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| 11 #include "vm/os.h" | 11 #include "vm/os.h" |
| 12 #include "vm/signal_handler.h" | 12 #include "vm/signal_handler.h" |
| 13 #include "vm/thread_interrupter.h" | 13 #include "vm/thread_interrupter.h" |
| 14 | 14 |
| 15 namespace dart { | 15 namespace dart { |
| 16 | 16 |
| 17 DECLARE_FLAG(bool, thread_interrupter); | 17 DECLARE_FLAG(bool, thread_interrupter); |
| 18 DECLARE_FLAG(bool, trace_thread_interrupter); | 18 DECLARE_FLAG(bool, trace_thread_interrupter); |
| 19 | 19 |
| 20 class ThreadInterrupterAndroid : public AllStatic { | 20 class ThreadInterrupterAndroid : public AllStatic { |
| 21 public: | 21 public: |
| 22 static void ThreadInterruptSignalHandler(int signal, siginfo_t* info, | 22 static void ThreadInterruptSignalHandler(int signal, siginfo_t* info, |
| 23 void* context_) { | 23 void* context_) { |
| 24 if (signal != SIGPROF) { | 24 if (signal != SIGPROF) { |
| 25 return; | 25 return; |
| 26 } | 26 } |
| 27 InterruptableThreadState* state = ThreadInterrupter::CurrentThreadState(); | 27 Thread* thread = Thread::Current(); |
| 28 if ((state == NULL) || (state->callback == NULL)) { | 28 if (thread == NULL) { |
| 29 // No interrupter state or callback. | |
| 30 return; | 29 return; |
| 31 } | 30 } |
| 32 ASSERT(OSThread::Compare(state->id, OSThread::GetCurrentThreadId())); | 31 ThreadInterruptCallback callback = NULL; |
| 32 void* callback_data = NULL; |
| 33 if (!thread->IsThreadInterrupterEnabled(&callback, &callback_data)) { |
| 34 return; |
| 35 } |
| 33 // Extract thread state. | 36 // Extract thread state. |
| 34 ucontext_t* context = reinterpret_cast<ucontext_t*>(context_); | 37 ucontext_t* context = reinterpret_cast<ucontext_t*>(context_); |
| 35 mcontext_t mcontext = context->uc_mcontext; | 38 mcontext_t mcontext = context->uc_mcontext; |
| 36 InterruptedThreadState its; | 39 InterruptedThreadState its; |
| 37 its.tid = state->id; | 40 its.tid = thread->id(); |
| 38 its.pc = SignalHandler::GetProgramCounter(mcontext); | 41 its.pc = SignalHandler::GetProgramCounter(mcontext); |
| 39 its.fp = SignalHandler::GetFramePointer(mcontext); | 42 its.fp = SignalHandler::GetFramePointer(mcontext); |
| 40 its.csp = SignalHandler::GetCStackPointer(mcontext); | 43 its.csp = SignalHandler::GetCStackPointer(mcontext); |
| 41 its.dsp = SignalHandler::GetDartStackPointer(mcontext); | 44 its.dsp = SignalHandler::GetDartStackPointer(mcontext); |
| 42 its.lr = SignalHandler::GetLinkRegister(mcontext); | 45 its.lr = SignalHandler::GetLinkRegister(mcontext); |
| 43 state->callback(its, state->data); | 46 callback(its, callback_data); |
| 44 } | 47 } |
| 45 }; | 48 }; |
| 46 | 49 |
| 47 | 50 |
| 48 void ThreadInterrupter::InterruptThread(InterruptableThreadState* state) { | 51 void ThreadInterrupter::InterruptThread(Thread* thread) { |
| 49 if (FLAG_trace_thread_interrupter) { | 52 if (FLAG_trace_thread_interrupter) { |
| 50 OS::Print("ThreadInterrupter interrupting %p\n", | 53 OS::Print("ThreadInterrupter interrupting %p\n", |
| 51 reinterpret_cast<void*>(state->id)); | 54 reinterpret_cast<void*>(thread->id())); |
| 52 } | 55 } |
| 53 int result = syscall(__NR_tgkill, getpid(), state->id, SIGPROF); | 56 int result = syscall(__NR_tgkill, getpid(), thread->id(), SIGPROF); |
| 54 ASSERT(result == 0); | 57 ASSERT(result == 0); |
| 55 } | 58 } |
| 56 | 59 |
| 57 | 60 |
| 58 void ThreadInterrupter::InstallSignalHandler() { | 61 void ThreadInterrupter::InstallSignalHandler() { |
| 59 SignalHandler::Install( | 62 SignalHandler::Install( |
| 60 ThreadInterrupterAndroid::ThreadInterruptSignalHandler); | 63 ThreadInterrupterAndroid::ThreadInterruptSignalHandler); |
| 61 } | 64 } |
| 62 | 65 |
| 63 | 66 |
| 64 void ThreadInterrupter::RemoveSignalHandler() { | 67 void ThreadInterrupter::RemoveSignalHandler() { |
| 65 SignalHandler::Remove(); | 68 SignalHandler::Remove(); |
| 66 } | 69 } |
| 67 | 70 |
| 68 } // namespace dart | 71 } // namespace dart |
| 69 | 72 |
| 70 #endif // defined(TARGET_OS_ANDROID) | 73 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |