| 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_LINUX) | 8 #if defined(TARGET_OS_LINUX) |
| 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.gregs[REG_EIP]); | 16 pc = static_cast<uintptr_t>(mcontext.gregs[REG_EIP]); |
| 17 #elif defined(TARGET_ARCH_X64) | 17 #elif defined(TARGET_ARCH_X64) |
| 18 pc = static_cast<uintptr_t>(mcontext.gregs[REG_RIP]); | 18 pc = static_cast<uintptr_t>(mcontext.gregs[REG_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.gregs[REG_EIP]); | 20 pc = static_cast<uintptr_t>(mcontext.gregs[REG_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.gregs[REG_EIP]); | 22 pc = static_cast<uintptr_t>(mcontext.gregs[REG_EIP]); |
| 23 #elif defined(TARGET_ARCH_ARM64) && defined(USING_SIMULATOR) |
| 24 pc = static_cast<uintptr_t>(mcontext.gregs[REG_RIP]); |
| 23 #elif defined(TARGET_ARCH_ARM) | 25 #elif defined(TARGET_ARCH_ARM) |
| 24 pc = static_cast<uintptr_t>(mcontext.arm_pc); | 26 pc = static_cast<uintptr_t>(mcontext.arm_pc); |
| 27 #elif defined(TARGET_ARCH_ARM64) |
| 28 pc = static_cast<uintptr_t>(mcontext.pc); |
| 25 #elif defined(TARGET_ARCH_MIPS) | 29 #elif defined(TARGET_ARCH_MIPS) |
| 26 pc = static_cast<uintptr_t>(mcontext.pc); | 30 pc = static_cast<uintptr_t>(mcontext.pc); |
| 27 #else | 31 #else |
| 28 UNIMPLEMENTED(); | 32 UNIMPLEMENTED(); |
| 29 #endif // TARGET_ARCH_... | 33 #endif // TARGET_ARCH_... |
| 30 return pc; | 34 return pc; |
| 31 } | 35 } |
| 32 | 36 |
| 33 | 37 |
| 34 uintptr_t SignalHandler::GetFramePointer(const mcontext_t& mcontext) { | 38 uintptr_t SignalHandler::GetFramePointer(const mcontext_t& mcontext) { |
| 35 uintptr_t fp = 0; | 39 uintptr_t fp = 0; |
| 36 | 40 |
| 37 #if defined(TARGET_ARCH_IA32) | 41 #if defined(TARGET_ARCH_IA32) |
| 38 fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]); | 42 fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]); |
| 39 #elif defined(TARGET_ARCH_X64) | 43 #elif defined(TARGET_ARCH_X64) |
| 40 fp = static_cast<uintptr_t>(mcontext.gregs[REG_RBP]); | 44 fp = static_cast<uintptr_t>(mcontext.gregs[REG_RBP]); |
| 41 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR) | 45 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR) |
| 42 fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]); | 46 fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]); |
| 43 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR) | 47 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR) |
| 44 fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]); | 48 fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]); |
| 49 #elif defined(TARGET_ARCH_ARM64) && defined(USING_SIMULATOR) |
| 50 fp = static_cast<uintptr_t>(mcontext.gregs[REG_RBP]); |
| 45 #elif defined(TARGET_ARCH_ARM) | 51 #elif defined(TARGET_ARCH_ARM) |
| 46 fp = static_cast<uintptr_t>(mcontext.arm_fp); | 52 fp = static_cast<uintptr_t>(mcontext.arm_fp); |
| 53 #elif defined(TARGET_ARCH_ARM64) |
| 54 fp = static_cast<uintptr_t>(mcontext.regs[29]); |
| 47 #elif defined(TARGET_ARCH_MIPS) | 55 #elif defined(TARGET_ARCH_MIPS) |
| 48 fp = static_cast<uintptr_t>(mcontext.gregs[30]); | 56 fp = static_cast<uintptr_t>(mcontext.gregs[30]); |
| 49 #else | 57 #else |
| 50 UNIMPLEMENTED(); | 58 UNIMPLEMENTED(); |
| 51 #endif // TARGET_ARCH_... | 59 #endif // TARGET_ARCH_... |
| 52 | 60 |
| 53 return fp; | 61 return fp; |
| 54 } | 62 } |
| 55 | 63 |
| 56 | 64 |
| 57 uintptr_t SignalHandler::GetStackPointer(const mcontext_t& mcontext) { | 65 uintptr_t SignalHandler::GetCStackPointer(const mcontext_t& mcontext) { |
| 58 uintptr_t sp = 0; | 66 uintptr_t sp = 0; |
| 59 | 67 |
| 60 #if defined(TARGET_ARCH_IA32) | 68 #if defined(TARGET_ARCH_IA32) |
| 61 sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]); | 69 sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]); |
| 62 #elif defined(TARGET_ARCH_X64) | 70 #elif defined(TARGET_ARCH_X64) |
| 63 sp = static_cast<uintptr_t>(mcontext.gregs[REG_RSP]); | 71 sp = static_cast<uintptr_t>(mcontext.gregs[REG_RSP]); |
| 64 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR) | 72 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR) |
| 65 sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]); | 73 sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]); |
| 66 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR) | 74 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR) |
| 67 sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]); | 75 sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]); |
| 76 #elif defined(TARGET_ARCH_ARM64) && defined(USING_SIMULATOR) |
| 77 sp = static_cast<uintptr_t>(mcontext.gregs[REG_RSP]); |
| 68 #elif defined(TARGET_ARCH_ARM) | 78 #elif defined(TARGET_ARCH_ARM) |
| 69 sp = static_cast<uintptr_t>(mcontext.arm_sp); | 79 sp = static_cast<uintptr_t>(mcontext.arm_sp); |
| 80 #elif defined(TARGET_ARCH_ARM64) |
| 81 sp = static_cast<uintptr_t>(mcontext.sp); |
| 70 #elif defined(TARGET_ARCH_MIPS) | 82 #elif defined(TARGET_ARCH_MIPS) |
| 71 sp = static_cast<uintptr_t>(mcontext.gregs[29]); | 83 sp = static_cast<uintptr_t>(mcontext.gregs[29]); |
| 72 #else | 84 #else |
| 73 UNIMPLEMENTED(); | 85 UNIMPLEMENTED(); |
| 74 #endif // TARGET_ARCH_... | 86 #endif // TARGET_ARCH_... |
| 75 return sp; | 87 return sp; |
| 76 } | 88 } |
| 77 | 89 |
| 78 | 90 |
| 91 uintptr_t SignalHandler::GetDartStackPointer(const mcontext_t& mcontext) { |
| 92 #if defined(TARGET_ARCH_ARM64) && !defined(USING_SIMULATOR) |
| 93 return static_cast<uintptr_t>(mcontext.regs[18]); |
| 94 #else |
| 95 return GetCStackPointer(mcontext); |
| 96 #endif |
| 97 } |
| 98 |
| 99 |
| 79 void SignalHandler::Install(SignalAction action) { | 100 void SignalHandler::Install(SignalAction action) { |
| 80 struct sigaction act; | 101 struct sigaction act; |
| 81 act.sa_handler = NULL; | 102 act.sa_handler = NULL; |
| 82 act.sa_sigaction = action; | 103 act.sa_sigaction = action; |
| 83 sigemptyset(&act.sa_mask); | 104 sigemptyset(&act.sa_mask); |
| 84 act.sa_flags = SA_RESTART | SA_SIGINFO; | 105 act.sa_flags = SA_RESTART | SA_SIGINFO; |
| 85 // TODO(johnmccutchan): Do we care about restoring the signal handler? | 106 // TODO(johnmccutchan): Do we care about restoring the signal handler? |
| 86 struct sigaction old_act; | 107 struct sigaction old_act; |
| 87 int r = sigaction(SIGPROF, &act, &old_act); | 108 int r = sigaction(SIGPROF, &act, &old_act); |
| 88 ASSERT(r == 0); | 109 ASSERT(r == 0); |
| 89 } | 110 } |
| 90 | 111 |
| 91 | 112 |
| 92 } // namespace dart | 113 } // namespace dart |
| 93 | 114 |
| 94 #endif // defined(TARGET_OS_LINUX) | 115 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |