OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #include "vm/globals.h" |
| 6 #include "vm/signal_handler.h" |
| 7 #if defined(TARGET_OS_LINUX) |
| 8 |
| 9 namespace dart { |
| 10 |
| 11 uintptr_t SignalHandler::GetProgramCounter(const mcontext_t& mcontext) { |
| 12 uintptr_t pc = 0; |
| 13 |
| 14 #if defined(TARGET_ARCH_IA32) |
| 15 pc = static_cast<uintptr_t>(mcontext.gregs[REG_EIP]); |
| 16 #elif defined(TARGET_ARCH_X64) |
| 17 pc = static_cast<uintptr_t>(mcontext.gregs[REG_RIP]); |
| 18 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR) |
| 19 pc = static_cast<uintptr_t>(mcontext.gregs[REG_EIP]); |
| 20 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR) |
| 21 pc = static_cast<uintptr_t>(mcontext.gregs[REG_EIP]); |
| 22 #else |
| 23 UNIMPLEMENTED() |
| 24 #endif // TARGET_ARCH_... |
| 25 return pc; |
| 26 } |
| 27 |
| 28 |
| 29 uintptr_t SignalHandler::GetFramePointer(const mcontext_t& mcontext) { |
| 30 uintptr_t fp = 0; |
| 31 |
| 32 #if defined(TARGET_ARCH_IA32) |
| 33 fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]); |
| 34 #elif defined(TARGET_ARCH_X64) |
| 35 fp = static_cast<uintptr_t>(mcontext.gregs[REG_RBP]); |
| 36 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR) |
| 37 fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]); |
| 38 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR) |
| 39 fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]); |
| 40 #else |
| 41 UNIMPLEMENTED() |
| 42 #endif // TARGET_ARCH_... |
| 43 |
| 44 return fp; |
| 45 } |
| 46 |
| 47 |
| 48 uintptr_t SignalHandler::GetStackPointer(const mcontext_t& mcontext) { |
| 49 uintptr_t sp = 0; |
| 50 |
| 51 #if defined(TARGET_ARCH_IA32) |
| 52 sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]); |
| 53 #elif defined(TARGET_ARCH_X64) |
| 54 sp = static_cast<uintptr_t>(mcontext.gregs[REG_RSP]); |
| 55 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR) |
| 56 sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]); |
| 57 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR) |
| 58 sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]); |
| 59 #else |
| 60 UNIMPLEMENTED() |
| 61 #endif // TARGET_ARCH_... |
| 62 return sp; |
| 63 } |
| 64 |
| 65 |
| 66 void SignalHandler::Install(SignalAction action) { |
| 67 struct sigaction act; |
| 68 act.sa_handler = NULL; |
| 69 act.sa_sigaction = action; |
| 70 sigemptyset(&act.sa_mask); |
| 71 act.sa_flags = SA_RESTART | SA_SIGINFO; |
| 72 // TODO(johnmccutchan): Do we care about restoring the signal handler? |
| 73 struct sigaction old_act; |
| 74 int r = sigaction(SIGPROF, &act, &old_act); |
| 75 ASSERT(r == 0); |
| 76 } |
| 77 |
| 78 |
| 79 ScopedSignalBlocker::ScopedSignalBlocker() { |
| 80 sigset_t set; |
| 81 sigemptyset(&set); |
| 82 sigaddset(&set, SIGPROF); |
| 83 pthread_sigmask(SIG_SETMASK, &set, &old_); |
| 84 } |
| 85 |
| 86 |
| 87 ScopedSignalBlocker::~ScopedSignalBlocker() { |
| 88 pthread_sigmask(SIG_SETMASK, &old_, NULL); |
| 89 } |
| 90 |
| 91 } // namespace dart |
| 92 |
| 93 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |