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