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_MACOS) |
| 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->__ss.__eip); |
| 16 #elif defined(TARGET_ARCH_X64) |
| 17 pc = static_cast<uintptr_t>(mcontext->__ss.__rip); |
| 18 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR) |
| 19 pc = static_cast<uintptr_t>(mcontext->__ss.__eip); |
| 20 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR) |
| 21 pc = static_cast<uintptr_t>(mcontext->__ss.__eip); |
| 22 #else |
| 23 UNIMPLEMENTED() |
| 24 #endif // TARGET_ARCH_... |
| 25 |
| 26 return pc; |
| 27 } |
| 28 |
| 29 |
| 30 uintptr_t SignalHandler::GetFramePointer(const mcontext_t& mcontext) { |
| 31 uintptr_t fp = 0; |
| 32 |
| 33 #if defined(TARGET_ARCH_IA32) |
| 34 fp = static_cast<uintptr_t>(mcontext->__ss.__ebp); |
| 35 #elif defined(TARGET_ARCH_X64) |
| 36 fp = static_cast<uintptr_t>(mcontext->__ss.__rbp); |
| 37 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR) |
| 38 fp = static_cast<uintptr_t>(mcontext->__ss.__ebp); |
| 39 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR) |
| 40 fp = static_cast<uintptr_t>(mcontext->__ss.__ebp); |
| 41 #else |
| 42 UNIMPLEMENTED() |
| 43 #endif // TARGET_ARCH_... |
| 44 |
| 45 return fp; |
| 46 } |
| 47 |
| 48 |
| 49 uintptr_t SignalHandler::GetStackPointer(const mcontext_t& mcontext) { |
| 50 uintptr_t sp = 0; |
| 51 |
| 52 #if defined(TARGET_ARCH_IA32) |
| 53 sp = static_cast<uintptr_t>(mcontext->__ss.__esp); |
| 54 #elif defined(TARGET_ARCH_X64) |
| 55 sp = static_cast<uintptr_t>(mcontext->__ss.__rsp); |
| 56 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR) |
| 57 sp = static_cast<uintptr_t>(mcontext->__ss.__esp); |
| 58 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR) |
| 59 sp = static_cast<uintptr_t>(mcontext->__ss.__esp); |
| 60 #else |
| 61 UNIMPLEMENTED() |
| 62 #endif // TARGET_ARCH_... |
| 63 |
| 64 return sp; |
| 65 } |
| 66 |
| 67 |
| 68 void SignalHandler::Install(SignalAction action) { |
| 69 struct sigaction act; |
| 70 act.sa_handler = NULL; |
| 71 act.sa_sigaction = action; |
| 72 sigemptyset(&act.sa_mask); |
| 73 act.sa_flags = SA_RESTART | SA_SIGINFO; |
| 74 // TODO(johnmccutchan): Do we care about restoring the signal handler? |
| 75 struct sigaction old_act; |
| 76 int r = sigaction(SIGPROF, &act, &old_act); |
| 77 ASSERT(r == 0); |
| 78 } |
| 79 |
| 80 |
| 81 ScopedSignalBlocker::ScopedSignalBlocker() { |
| 82 sigset_t set; |
| 83 sigemptyset(&set); |
| 84 sigaddset(&set, SIGPROF); |
| 85 pthread_sigmask(SIG_SETMASK, &set, &old_); |
| 86 } |
| 87 |
| 88 |
| 89 ScopedSignalBlocker::~ScopedSignalBlocker() { |
| 90 pthread_sigmask(SIG_SETMASK, &old_, NULL); |
| 91 } |
| 92 |
| 93 } // namespace dart |
| 94 |
| 95 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |