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/instructions.h" | 6 #include "vm/instructions.h" |
| 7 #include "vm/signal_handler.h" |
7 #include "vm/simulator.h" | 8 #include "vm/simulator.h" |
8 #include "vm/signal_handler.h" | |
9 #if defined(HOST_OS_MACOS) | 9 #if defined(HOST_OS_MACOS) |
10 | 10 |
11 namespace dart { | 11 namespace dart { |
12 | 12 |
13 uintptr_t SignalHandler::GetProgramCounter(const mcontext_t& mcontext) { | 13 uintptr_t SignalHandler::GetProgramCounter(const mcontext_t& mcontext) { |
14 uintptr_t pc = 0; | 14 uintptr_t pc = 0; |
15 | 15 |
16 #if defined(HOST_ARCH_IA32) | 16 #if defined(HOST_ARCH_IA32) |
17 pc = static_cast<uintptr_t>(mcontext->__ss.__eip); | 17 pc = static_cast<uintptr_t>(mcontext->__ss.__eip); |
18 #elif defined(HOST_ARCH_X64) | 18 #elif defined(HOST_ARCH_X64) |
19 pc = static_cast<uintptr_t>(mcontext->__ss.__rip); | 19 pc = static_cast<uintptr_t>(mcontext->__ss.__rip); |
20 #elif defined(HOST_ARCH_ARM) | 20 #elif defined(HOST_ARCH_ARM) |
21 pc = static_cast<uintptr_t>(mcontext->__ss.__pc); | 21 pc = static_cast<uintptr_t>(mcontext->__ss.__pc); |
22 #elif defined(HOST_ARCH_ARM64) | 22 #elif defined(HOST_ARCH_ARM64) |
23 pc = static_cast<uintptr_t>(mcontext->__ss.__pc); | 23 pc = static_cast<uintptr_t>(mcontext->__ss.__pc); |
24 #else | 24 #else |
25 #error Unsuported architecture. | 25 #error Unsuported architecture. |
26 #endif // HOST_ARCH_... | 26 #endif // HOST_ARCH_... |
27 | 27 |
28 return pc; | 28 return pc; |
29 } | 29 } |
30 | 30 |
31 | |
32 uintptr_t SignalHandler::GetFramePointer(const mcontext_t& mcontext) { | 31 uintptr_t SignalHandler::GetFramePointer(const mcontext_t& mcontext) { |
33 uintptr_t fp = 0; | 32 uintptr_t fp = 0; |
34 | 33 |
35 #if defined(HOST_ARCH_IA32) | 34 #if defined(HOST_ARCH_IA32) |
36 fp = static_cast<uintptr_t>(mcontext->__ss.__ebp); | 35 fp = static_cast<uintptr_t>(mcontext->__ss.__ebp); |
37 #elif defined(HOST_ARCH_X64) | 36 #elif defined(HOST_ARCH_X64) |
38 fp = static_cast<uintptr_t>(mcontext->__ss.__rbp); | 37 fp = static_cast<uintptr_t>(mcontext->__ss.__rbp); |
39 #elif defined(HOST_ARCH_ARM) | 38 #elif defined(HOST_ARCH_ARM) |
40 fp = static_cast<uintptr_t>(mcontext->__ss.__r[7]); | 39 fp = static_cast<uintptr_t>(mcontext->__ss.__r[7]); |
41 #elif defined(HOST_ARCH_ARM64) | 40 #elif defined(HOST_ARCH_ARM64) |
42 fp = static_cast<uintptr_t>(mcontext->__ss.__fp); | 41 fp = static_cast<uintptr_t>(mcontext->__ss.__fp); |
43 #else | 42 #else |
44 #error Unsuported architecture. | 43 #error Unsuported architecture. |
45 #endif // HOST_ARCH_... | 44 #endif // HOST_ARCH_... |
46 | 45 |
47 return fp; | 46 return fp; |
48 } | 47 } |
49 | 48 |
50 | |
51 uintptr_t SignalHandler::GetCStackPointer(const mcontext_t& mcontext) { | 49 uintptr_t SignalHandler::GetCStackPointer(const mcontext_t& mcontext) { |
52 uintptr_t sp = 0; | 50 uintptr_t sp = 0; |
53 | 51 |
54 #if defined(HOST_ARCH_IA32) | 52 #if defined(HOST_ARCH_IA32) |
55 sp = static_cast<uintptr_t>(mcontext->__ss.__esp); | 53 sp = static_cast<uintptr_t>(mcontext->__ss.__esp); |
56 #elif defined(HOST_ARCH_X64) | 54 #elif defined(HOST_ARCH_X64) |
57 sp = static_cast<uintptr_t>(mcontext->__ss.__rsp); | 55 sp = static_cast<uintptr_t>(mcontext->__ss.__rsp); |
58 #elif defined(HOST_ARCH_ARM) | 56 #elif defined(HOST_ARCH_ARM) |
59 sp = static_cast<uintptr_t>(mcontext->__ss.__sp); | 57 sp = static_cast<uintptr_t>(mcontext->__ss.__sp); |
60 #elif defined(HOST_ARCH_ARM64) | 58 #elif defined(HOST_ARCH_ARM64) |
61 sp = static_cast<uintptr_t>(mcontext->__ss.__sp); | 59 sp = static_cast<uintptr_t>(mcontext->__ss.__sp); |
62 #else | 60 #else |
63 UNIMPLEMENTED(); | 61 UNIMPLEMENTED(); |
64 #endif // HOST_ARCH_... | 62 #endif // HOST_ARCH_... |
65 | 63 |
66 return sp; | 64 return sp; |
67 } | 65 } |
68 | 66 |
69 | |
70 uintptr_t SignalHandler::GetDartStackPointer(const mcontext_t& mcontext) { | 67 uintptr_t SignalHandler::GetDartStackPointer(const mcontext_t& mcontext) { |
71 #if defined(TARGET_ARCH_ARM64) && !defined(USING_SIMULATOR) | 68 #if defined(TARGET_ARCH_ARM64) && !defined(USING_SIMULATOR) |
72 return static_cast<uintptr_t>(mcontext->__ss.__x[SPREG]); | 69 return static_cast<uintptr_t>(mcontext->__ss.__x[SPREG]); |
73 #else | 70 #else |
74 return GetCStackPointer(mcontext); | 71 return GetCStackPointer(mcontext); |
75 #endif | 72 #endif |
76 } | 73 } |
77 | 74 |
78 | |
79 uintptr_t SignalHandler::GetLinkRegister(const mcontext_t& mcontext) { | 75 uintptr_t SignalHandler::GetLinkRegister(const mcontext_t& mcontext) { |
80 uintptr_t lr = 0; | 76 uintptr_t lr = 0; |
81 | 77 |
82 #if defined(HOST_ARCH_IA32) | 78 #if defined(HOST_ARCH_IA32) |
83 lr = 0; | 79 lr = 0; |
84 #elif defined(HOST_ARCH_X64) | 80 #elif defined(HOST_ARCH_X64) |
85 lr = 0; | 81 lr = 0; |
86 #elif defined(HOST_ARCH_ARM) | 82 #elif defined(HOST_ARCH_ARM) |
87 lr = static_cast<uintptr_t>(mcontext->__ss.__lr); | 83 lr = static_cast<uintptr_t>(mcontext->__ss.__lr); |
88 #elif defined(HOST_ARCH_ARM64) | 84 #elif defined(HOST_ARCH_ARM64) |
89 lr = static_cast<uintptr_t>(mcontext->__ss.__lr); | 85 lr = static_cast<uintptr_t>(mcontext->__ss.__lr); |
90 #else | 86 #else |
91 #error Unsupported architecture. | 87 #error Unsupported architecture. |
92 #endif // HOST_ARCH_... | 88 #endif // HOST_ARCH_... |
93 | 89 |
94 return lr; | 90 return lr; |
95 } | 91 } |
96 | 92 |
97 | |
98 void SignalHandler::InstallImpl(SignalAction action) { | 93 void SignalHandler::InstallImpl(SignalAction action) { |
99 struct sigaction act; | 94 struct sigaction act; |
100 act.sa_handler = NULL; | 95 act.sa_handler = NULL; |
101 act.sa_sigaction = action; | 96 act.sa_sigaction = action; |
102 sigemptyset(&act.sa_mask); | 97 sigemptyset(&act.sa_mask); |
103 act.sa_flags = SA_RESTART | SA_SIGINFO; | 98 act.sa_flags = SA_RESTART | SA_SIGINFO; |
104 int r = sigaction(SIGPROF, &act, NULL); | 99 int r = sigaction(SIGPROF, &act, NULL); |
105 ASSERT(r == 0); | 100 ASSERT(r == 0); |
106 } | 101 } |
107 | 102 |
108 | |
109 void SignalHandler::Remove() { | 103 void SignalHandler::Remove() { |
110 // Ignore future SIGPROF signals because by default SIGPROF will terminate | 104 // Ignore future SIGPROF signals because by default SIGPROF will terminate |
111 // the process and we may have some signals in flight. | 105 // the process and we may have some signals in flight. |
112 struct sigaction act; | 106 struct sigaction act; |
113 act.sa_handler = SIG_IGN; | 107 act.sa_handler = SIG_IGN; |
114 sigemptyset(&act.sa_mask); | 108 sigemptyset(&act.sa_mask); |
115 act.sa_flags = 0; | 109 act.sa_flags = 0; |
116 int r = sigaction(SIGPROF, &act, NULL); | 110 int r = sigaction(SIGPROF, &act, NULL); |
117 ASSERT(r == 0); | 111 ASSERT(r == 0); |
118 } | 112 } |
119 | 113 |
120 | |
121 } // namespace dart | 114 } // namespace dart |
122 | 115 |
123 #endif // defined(HOST_OS_MACOS) | 116 #endif // defined(HOST_OS_MACOS) |
OLD | NEW |