Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1114)

Unified Diff: runtime/vm/signal_handler_linux.cc

Issue 25909002: Sampling profiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/signal_handler_linux.cc
diff --git a/runtime/vm/signal_handler_linux.cc b/runtime/vm/signal_handler_linux.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7fa0b29c5cd7d6b2bb927ebb3fc202455c22a6df
--- /dev/null
+++ b/runtime/vm/signal_handler_linux.cc
@@ -0,0 +1,93 @@
+// 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 "vm/globals.h"
+#include "vm/signal_handler.h"
+#if defined(TARGET_OS_LINUX)
+
+namespace dart {
+
+uintptr_t SignalHandler::GetProgramCounter(const mcontext_t& mcontext) {
+ uintptr_t pc = 0;
+
+#if defined(TARGET_ARCH_IA32)
+ pc = static_cast<uintptr_t>(mcontext.gregs[REG_EIP]);
+#elif defined(TARGET_ARCH_X64)
+ pc = static_cast<uintptr_t>(mcontext.gregs[REG_RIP]);
+#elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR)
+ pc = static_cast<uintptr_t>(mcontext.gregs[REG_EIP]);
+#elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR)
+ pc = static_cast<uintptr_t>(mcontext.gregs[REG_EIP]);
+#else
+ UNIMPLEMENTED()
+#endif // TARGET_ARCH_...
+ return pc;
+}
+
+
+uintptr_t SignalHandler::GetFramePointer(const mcontext_t& mcontext) {
+ uintptr_t fp = 0;
+
+#if defined(TARGET_ARCH_IA32)
+ fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]);
+#elif defined(TARGET_ARCH_X64)
+ fp = static_cast<uintptr_t>(mcontext.gregs[REG_RBP]);
+#elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR)
+ fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]);
+#elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR)
+ fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]);
+#else
+ UNIMPLEMENTED()
+#endif // TARGET_ARCH_...
+
+ return fp;
+}
+
+
+uintptr_t SignalHandler::GetStackPointer(const mcontext_t& mcontext) {
+ uintptr_t sp = 0;
+
+#if defined(TARGET_ARCH_IA32)
+ sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]);
+#elif defined(TARGET_ARCH_X64)
+ sp = static_cast<uintptr_t>(mcontext.gregs[REG_RSP]);
+#elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR)
+ sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]);
+#elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR)
+ sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]);
+#else
+ UNIMPLEMENTED()
+#endif // TARGET_ARCH_...
+ return sp;
+}
+
+
+void SignalHandler::Install(SignalAction action) {
+ struct sigaction act;
+ act.sa_handler = NULL;
+ act.sa_sigaction = action;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = SA_RESTART | SA_SIGINFO;
+ // TODO(johnmccutchan): Do we care about restoring the signal handler?
+ struct sigaction old_act;
+ int r = sigaction(SIGPROF, &act, &old_act);
+ ASSERT(r == 0);
+}
+
+
+ScopedSignalBlocker::ScopedSignalBlocker() {
+ sigset_t set;
+ sigemptyset(&set);
+ sigaddset(&set, SIGPROF);
+ pthread_sigmask(SIG_SETMASK, &set, &old_);
+}
+
+
+ScopedSignalBlocker::~ScopedSignalBlocker() {
+ pthread_sigmask(SIG_SETMASK, &old_, NULL);
+}
+
+} // namespace dart
+
+#endif // defined(TARGET_OS_LINUX)

Powered by Google App Engine
This is Rietveld 408576698