| 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(HOST_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(HOST_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(HOST_ARCH_ARM) |
| 20 pc = static_cast<uintptr_t>(mcontext.gregs[REG_EIP]); | |
| 21 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR) | |
| 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]); | |
| 25 #elif defined(TARGET_ARCH_ARM) | |
| 26 pc = static_cast<uintptr_t>(mcontext.arm_pc); | 20 pc = static_cast<uintptr_t>(mcontext.arm_pc); |
| 27 #elif defined(TARGET_ARCH_ARM64) | 21 #elif defined(HOST_ARCH_ARM64) |
| 28 pc = static_cast<uintptr_t>(mcontext.pc); | 22 pc = static_cast<uintptr_t>(mcontext.pc); |
| 29 #elif defined(TARGET_ARCH_MIPS) | 23 #elif defined(HOST_ARCH_MIPS) |
| 30 pc = static_cast<uintptr_t>(mcontext.pc); | 24 pc = static_cast<uintptr_t>(mcontext.pc); |
| 31 #else | 25 #else |
| 32 UNIMPLEMENTED(); | 26 #error Unsupported architecture. |
| 33 #endif // TARGET_ARCH_... | 27 #endif // HOST_ARCH_... |
| 34 return pc; | 28 return pc; |
| 35 } | 29 } |
| 36 | 30 |
| 37 | 31 |
| 38 uintptr_t SignalHandler::GetFramePointer(const mcontext_t& mcontext) { | 32 uintptr_t SignalHandler::GetFramePointer(const mcontext_t& mcontext) { |
| 39 uintptr_t fp = 0; | 33 uintptr_t fp = 0; |
| 40 | 34 |
| 41 #if defined(TARGET_ARCH_IA32) | 35 #if defined(HOST_ARCH_IA32) |
| 42 fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]); | 36 fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]); |
| 43 #elif defined(TARGET_ARCH_X64) | 37 #elif defined(HOST_ARCH_X64) |
| 44 fp = static_cast<uintptr_t>(mcontext.gregs[REG_RBP]); | 38 fp = static_cast<uintptr_t>(mcontext.gregs[REG_RBP]); |
| 45 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR) | 39 #elif defined(HOST_ARCH_ARM) |
| 46 fp = static_cast<uintptr_t>(mcontext.gregs[REG_EBP]); | |
| 47 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR) | |
| 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]); | |
| 51 #elif defined(TARGET_ARCH_ARM) | |
| 52 fp = static_cast<uintptr_t>(mcontext.arm_fp); | 40 fp = static_cast<uintptr_t>(mcontext.arm_fp); |
| 53 #elif defined(TARGET_ARCH_ARM64) | 41 #elif defined(HOST_ARCH_ARM64) |
| 54 fp = static_cast<uintptr_t>(mcontext.regs[29]); | 42 fp = static_cast<uintptr_t>(mcontext.regs[29]); |
| 55 #elif defined(TARGET_ARCH_MIPS) | 43 #elif defined(HOST_ARCH_MIPS) |
| 56 fp = static_cast<uintptr_t>(mcontext.gregs[30]); | 44 fp = static_cast<uintptr_t>(mcontext.gregs[30]); |
| 57 #else | 45 #else |
| 58 UNIMPLEMENTED(); | 46 #error Unsupported architecture. |
| 59 #endif // TARGET_ARCH_... | 47 #endif // HOST_ARCH_... |
| 60 | 48 |
| 61 return fp; | 49 return fp; |
| 62 } | 50 } |
| 63 | 51 |
| 64 | 52 |
| 65 uintptr_t SignalHandler::GetCStackPointer(const mcontext_t& mcontext) { | 53 uintptr_t SignalHandler::GetCStackPointer(const mcontext_t& mcontext) { |
| 66 uintptr_t sp = 0; | 54 uintptr_t sp = 0; |
| 67 | 55 |
| 68 #if defined(TARGET_ARCH_IA32) | 56 #if defined(HOST_ARCH_IA32) |
| 69 sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]); | 57 sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]); |
| 70 #elif defined(TARGET_ARCH_X64) | 58 #elif defined(HOST_ARCH_X64) |
| 71 sp = static_cast<uintptr_t>(mcontext.gregs[REG_RSP]); | 59 sp = static_cast<uintptr_t>(mcontext.gregs[REG_RSP]); |
| 72 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR) | 60 #elif defined(HOST_ARCH_ARM) |
| 73 sp = static_cast<uintptr_t>(mcontext.gregs[REG_ESP]); | |
| 74 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR) | |
| 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]); | |
| 78 #elif defined(TARGET_ARCH_ARM) | |
| 79 sp = static_cast<uintptr_t>(mcontext.arm_sp); | 61 sp = static_cast<uintptr_t>(mcontext.arm_sp); |
| 80 #elif defined(TARGET_ARCH_ARM64) | 62 #elif defined(HOST_ARCH_ARM64) |
| 81 sp = static_cast<uintptr_t>(mcontext.sp); | 63 sp = static_cast<uintptr_t>(mcontext.sp); |
| 82 #elif defined(TARGET_ARCH_MIPS) | 64 #elif defined(HOST_ARCH_MIPS) |
| 83 sp = static_cast<uintptr_t>(mcontext.gregs[29]); | 65 sp = static_cast<uintptr_t>(mcontext.gregs[29]); |
| 84 #else | 66 #else |
| 85 UNIMPLEMENTED(); | 67 #error Unsupported architecture. |
| 86 #endif // TARGET_ARCH_... | 68 #endif // HOST_ARCH_... |
| 87 return sp; | 69 return sp; |
| 88 } | 70 } |
| 89 | 71 |
| 90 | 72 |
| 91 uintptr_t SignalHandler::GetDartStackPointer(const mcontext_t& mcontext) { | 73 uintptr_t SignalHandler::GetDartStackPointer(const mcontext_t& mcontext) { |
| 92 #if defined(TARGET_ARCH_ARM64) && !defined(USING_SIMULATOR) | 74 #if defined(TARGET_ARCH_ARM64) && !defined(USING_SIMULATOR) |
| 93 return static_cast<uintptr_t>(mcontext.regs[18]); | 75 return static_cast<uintptr_t>(mcontext.regs[18]); |
| 94 #else | 76 #else |
| 95 return GetCStackPointer(mcontext); | 77 return GetCStackPointer(mcontext); |
| 96 #endif | 78 #endif |
| 97 } | 79 } |
| 98 | 80 |
| 99 | 81 |
| 100 uintptr_t SignalHandler::GetLinkRegister(const mcontext_t& mcontext) { | 82 uintptr_t SignalHandler::GetLinkRegister(const mcontext_t& mcontext) { |
| 101 uintptr_t lr = 0; | 83 uintptr_t lr = 0; |
| 102 | 84 |
| 103 #if defined(TARGET_ARCH_IA32) | 85 #if defined(HOST_ARCH_IA32) |
| 104 lr = 0; | 86 lr = 0; |
| 105 #elif defined(TARGET_ARCH_X64) | 87 #elif defined(HOST_ARCH_X64) |
| 106 lr = 0; | 88 lr = 0; |
| 107 #elif defined(TARGET_ARCH_MIPS) && defined(USING_SIMULATOR) | 89 #elif defined(HOST_ARCH_ARM) |
| 108 lr = 0; | |
| 109 #elif defined(TARGET_ARCH_ARM) && defined(USING_SIMULATOR) | |
| 110 lr = 0; | |
| 111 #elif defined(TARGET_ARCH_ARM64) && defined(USING_SIMULATOR) | |
| 112 lr = 0; | |
| 113 #elif defined(TARGET_ARCH_ARM) | |
| 114 lr = static_cast<uintptr_t>(mcontext.arm_lr); | 90 lr = static_cast<uintptr_t>(mcontext.arm_lr); |
| 115 #elif defined(TARGET_ARCH_ARM64) | 91 #elif defined(HOST_ARCH_ARM64) |
| 116 lr = static_cast<uintptr_t>(mcontext.regs[30]); | 92 lr = static_cast<uintptr_t>(mcontext.regs[30]); |
| 117 #elif defined(TARGET_ARCH_MIPS) | 93 #elif defined(HOST_ARCH_MIPS) |
| 118 lr = static_cast<uintptr_t>(mcontext.gregs[31]); | 94 lr = static_cast<uintptr_t>(mcontext.gregs[31]); |
| 119 #else | 95 #else |
| 120 UNIMPLEMENTED(); | 96 #error Unsupported architecture. |
| 121 #endif // TARGET_ARCH_... | 97 #endif // HOST_ARCH_... |
| 122 return lr; | 98 return lr; |
| 123 } | 99 } |
| 124 | 100 |
| 125 | 101 |
| 126 void SignalHandler::Install(SignalAction action) { | 102 void SignalHandler::Install(SignalAction action) { |
| 127 struct sigaction act; | 103 struct sigaction act; |
| 128 act.sa_handler = NULL; | 104 act.sa_handler = NULL; |
| 129 act.sa_sigaction = action; | 105 act.sa_sigaction = action; |
| 130 sigemptyset(&act.sa_mask); | 106 sigemptyset(&act.sa_mask); |
| 131 act.sa_flags = SA_RESTART | SA_SIGINFO; | 107 act.sa_flags = SA_RESTART | SA_SIGINFO; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 142 sigemptyset(&act.sa_mask); | 118 sigemptyset(&act.sa_mask); |
| 143 act.sa_flags = 0; | 119 act.sa_flags = 0; |
| 144 int r = sigaction(SIGPROF, &act, NULL); | 120 int r = sigaction(SIGPROF, &act, NULL); |
| 145 ASSERT(r == 0); | 121 ASSERT(r == 0); |
| 146 } | 122 } |
| 147 | 123 |
| 148 | 124 |
| 149 } // namespace dart | 125 } // namespace dart |
| 150 | 126 |
| 151 #endif // defined(TARGET_OS_LINUX) | 127 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |