mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
877284947b
Like HOST_ARCH_*, HOST_OS_* describes the OS the VM is running on, which may be different from the OS the VM is generating code for during AOT compilation. Currently we conflate the two when emitting AOT as assembly, and we get away with it because Flutter only uses assembly for targeting iOS and one can only target iOS from a Mac, but we expect to use assembly for Android as well so native tools can unwind Dart frames. R=zra@google.com Review-Url: https://codereview.chromium.org/2750843003 .
79 lines
2.1 KiB
C++
79 lines
2.1 KiB
C++
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "platform/globals.h"
|
|
#if defined(HOST_OS_ANDROID)
|
|
|
|
#include <sys/syscall.h> // NOLINT
|
|
#include <errno.h> // NOLINT
|
|
|
|
#include "vm/flags.h"
|
|
#include "vm/os.h"
|
|
#include "vm/profiler.h"
|
|
#include "vm/signal_handler.h"
|
|
#include "vm/thread_interrupter.h"
|
|
|
|
namespace dart {
|
|
|
|
#ifndef PRODUCT
|
|
|
|
DECLARE_FLAG(bool, thread_interrupter);
|
|
DECLARE_FLAG(bool, trace_thread_interrupter);
|
|
|
|
class ThreadInterrupterAndroid : public AllStatic {
|
|
public:
|
|
static void ThreadInterruptSignalHandler(int signal,
|
|
siginfo_t* info,
|
|
void* context_) {
|
|
if (signal != SIGPROF) {
|
|
return;
|
|
}
|
|
Thread* thread = Thread::Current();
|
|
if (thread == NULL) {
|
|
return;
|
|
}
|
|
// Extract thread state.
|
|
ucontext_t* context = reinterpret_cast<ucontext_t*>(context_);
|
|
mcontext_t mcontext = context->uc_mcontext;
|
|
InterruptedThreadState its;
|
|
its.pc = SignalHandler::GetProgramCounter(mcontext);
|
|
its.fp = SignalHandler::GetFramePointer(mcontext);
|
|
its.csp = SignalHandler::GetCStackPointer(mcontext);
|
|
its.dsp = SignalHandler::GetDartStackPointer(mcontext);
|
|
its.lr = SignalHandler::GetLinkRegister(mcontext);
|
|
Profiler::SampleThread(thread, its);
|
|
}
|
|
};
|
|
|
|
|
|
bool ThreadInterrupter::IsDebuggerAttached() {
|
|
return false;
|
|
}
|
|
|
|
|
|
void ThreadInterrupter::InterruptThread(OSThread* thread) {
|
|
if (FLAG_trace_thread_interrupter) {
|
|
OS::PrintErr("ThreadInterrupter interrupting %p\n",
|
|
reinterpret_cast<void*>(thread->id()));
|
|
}
|
|
int result = syscall(__NR_tgkill, getpid(), thread->id(), SIGPROF);
|
|
ASSERT((result == 0) || (result == ESRCH));
|
|
}
|
|
|
|
|
|
void ThreadInterrupter::InstallSignalHandler() {
|
|
SignalHandler::Install<
|
|
ThreadInterrupterAndroid::ThreadInterruptSignalHandler>();
|
|
}
|
|
|
|
|
|
void ThreadInterrupter::RemoveSignalHandler() {
|
|
SignalHandler::Remove();
|
|
}
|
|
|
|
#endif // !PRODUCT
|
|
|
|
} // namespace dart
|
|
|
|
#endif // defined(HOST_OS_ANDROID)
|