mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 20:51:50 +00:00
816bf5af2e
On arm64, in Dart code, R18(SP) is the stack pointer. In C++ code, R31(CSP) is the stack pointer. The profiler must choose the right one when performing its bounds checks. This change also fixes a bug in the InvokeDartCode stub on arm64 so that CSP is set to the Isolate's stack limit immediately, rather than a bit later. When it was set a bit later, if a profiler interrupt came in in the interim, the stack would be smashed. R=johnmccutchan@google.com Review URL: https://codereview.chromium.org//583683002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@40502 260f80e4-7a28-3924-810f-c04153c831b5
64 lines
2 KiB
C++
64 lines
2 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(TARGET_OS_ANDROID)
|
|
|
|
#include <sys/syscall.h> // NOLINT
|
|
|
|
#include "vm/flags.h"
|
|
#include "vm/os.h"
|
|
#include "vm/signal_handler.h"
|
|
#include "vm/thread_interrupter.h"
|
|
|
|
namespace dart {
|
|
|
|
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;
|
|
}
|
|
InterruptableThreadState* state = ThreadInterrupter::CurrentThreadState();
|
|
if ((state == NULL) || (state->callback == NULL)) {
|
|
// No interrupter state or callback.
|
|
return;
|
|
}
|
|
ASSERT(Thread::Compare(state->id, Thread::GetCurrentThreadId()));
|
|
// Extract thread state.
|
|
ucontext_t* context = reinterpret_cast<ucontext_t*>(context_);
|
|
mcontext_t mcontext = context->uc_mcontext;
|
|
InterruptedThreadState its;
|
|
its.tid = state->id;
|
|
its.pc = SignalHandler::GetProgramCounter(mcontext);
|
|
its.fp = SignalHandler::GetFramePointer(mcontext);
|
|
its.csp = SignalHandler::GetCStackPointer(mcontext);
|
|
its.dsp = SignalHandler::GetDartStackPointer(mcontext);
|
|
state->callback(its, state->data);
|
|
}
|
|
};
|
|
|
|
|
|
void ThreadInterrupter::InterruptThread(InterruptableThreadState* state) {
|
|
if (FLAG_trace_thread_interrupter) {
|
|
OS::Print("ThreadInterrupter interrupting %p\n",
|
|
reinterpret_cast<void*>(state->id));
|
|
}
|
|
syscall(__NR_tgkill, getpid(), state->id, SIGPROF);
|
|
}
|
|
|
|
|
|
void ThreadInterrupter::InstallSignalHandler() {
|
|
SignalHandler::Install(
|
|
ThreadInterrupterAndroid::ThreadInterruptSignalHandler);
|
|
}
|
|
|
|
} // namespace dart
|
|
|
|
#endif // defined(TARGET_OS_ANDROID)
|