OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 mach_msg_type_number_t old_state_count, | 94 mach_msg_type_number_t old_state_count, |
95 thread_state_t new_state, | 95 thread_state_t new_state, |
96 mach_msg_type_number_t* new_state_count, | 96 mach_msg_type_number_t* new_state_count, |
97 const mach_msg_trailer_t* trailer, | 97 const mach_msg_trailer_t* trailer, |
98 bool* destroy_complex_request) override { | 98 bool* destroy_complex_request) override { |
99 *destroy_complex_request = true; | 99 *destroy_complex_request = true; |
100 | 100 |
101 // Check the entire exception message, because most or all of it was | 101 // Check the entire exception message, because most or all of it was |
102 // generated by SimulateCrash() instead of the kernel. | 102 // generated by SimulateCrash() instead of the kernel. |
103 | 103 |
104 EXPECT_EQ(behavior_, behavior); | 104 EXPECT_EQ(behavior, behavior_); |
105 EXPECT_EQ(LocalPort(), exception_port); | 105 EXPECT_EQ(exception_port, LocalPort()); |
106 if (ExceptionBehaviorHasIdentity(behavior)) { | 106 if (ExceptionBehaviorHasIdentity(behavior)) { |
107 EXPECT_NE(THREAD_NULL, thread); | 107 EXPECT_NE(thread, THREAD_NULL); |
108 EXPECT_EQ(ChildTask(), task); | 108 EXPECT_EQ(task, ChildTask()); |
109 } else { | 109 } else { |
110 EXPECT_EQ(THREAD_NULL, thread); | 110 EXPECT_EQ(thread, THREAD_NULL); |
111 EXPECT_EQ(TASK_NULL, task); | 111 EXPECT_EQ(task, TASK_NULL); |
112 } | 112 } |
113 EXPECT_EQ(kMachExceptionSimulated, exception); | 113 EXPECT_EQ(exception, kMachExceptionSimulated); |
114 EXPECT_EQ(2u, code_count); | 114 EXPECT_EQ(code_count, 2u); |
115 if (code_count >= 1) { | 115 if (code_count >= 1) { |
116 EXPECT_EQ(0, code[0]); | 116 EXPECT_EQ(code[0], 0); |
117 } | 117 } |
118 if (code_count >= 2) { | 118 if (code_count >= 2) { |
119 EXPECT_EQ(0, code[1]); | 119 EXPECT_EQ(code[1], 0); |
120 } | 120 } |
121 if (!ExceptionBehaviorHasState(behavior)) { | 121 if (!ExceptionBehaviorHasState(behavior)) { |
122 EXPECT_EQ(THREAD_STATE_NONE, *flavor); | 122 EXPECT_EQ(*flavor, THREAD_STATE_NONE); |
123 } else { | 123 } else { |
124 EXPECT_EQ(flavor_, *flavor); | 124 EXPECT_EQ(*flavor, flavor_); |
125 switch (*flavor) { | 125 switch (*flavor) { |
126 #if defined(ARCH_CPU_X86_FAMILY) | 126 #if defined(ARCH_CPU_X86_FAMILY) |
127 case x86_THREAD_STATE: { | 127 case x86_THREAD_STATE: { |
128 EXPECT_EQ(x86_THREAD_STATE_COUNT, old_state_count); | 128 EXPECT_EQ(old_state_count, x86_THREAD_STATE_COUNT); |
129 const x86_thread_state* state = | 129 const x86_thread_state* state = |
130 reinterpret_cast<const x86_thread_state*>(old_state); | 130 reinterpret_cast<const x86_thread_state*>(old_state); |
131 switch (state->tsh.flavor) { | 131 switch (state->tsh.flavor) { |
132 case x86_THREAD_STATE32: | 132 case x86_THREAD_STATE32: |
133 EXPECT_EQ(implicit_cast<int>(x86_THREAD_STATE32_COUNT), | 133 EXPECT_EQ(state->tsh.count, |
134 state->tsh.count); | 134 implicit_cast<int>(x86_THREAD_STATE32_COUNT)); |
135 break; | 135 break; |
136 case x86_THREAD_STATE64: | 136 case x86_THREAD_STATE64: |
137 EXPECT_EQ(implicit_cast<int>(x86_THREAD_STATE64_COUNT), | 137 EXPECT_EQ(state->tsh.count, |
138 state->tsh.count); | 138 implicit_cast<int>(x86_THREAD_STATE64_COUNT)); |
139 break; | 139 break; |
140 default: | 140 default: |
141 ADD_FAILURE() << "unexpected tsh.flavor " << state->tsh.flavor; | 141 ADD_FAILURE() << "unexpected tsh.flavor " << state->tsh.flavor; |
142 break; | 142 break; |
143 } | 143 } |
144 break; | 144 break; |
145 } | 145 } |
146 case x86_FLOAT_STATE: { | 146 case x86_FLOAT_STATE: { |
147 EXPECT_EQ(x86_FLOAT_STATE_COUNT, old_state_count); | 147 EXPECT_EQ(old_state_count, x86_FLOAT_STATE_COUNT); |
148 const x86_float_state* state = | 148 const x86_float_state* state = |
149 reinterpret_cast<const x86_float_state*>(old_state); | 149 reinterpret_cast<const x86_float_state*>(old_state); |
150 switch (state->fsh.flavor) { | 150 switch (state->fsh.flavor) { |
151 case x86_FLOAT_STATE32: | 151 case x86_FLOAT_STATE32: |
152 EXPECT_EQ(implicit_cast<int>(x86_FLOAT_STATE32_COUNT), | 152 EXPECT_EQ(state->fsh.count, |
153 state->fsh.count); | 153 implicit_cast<int>(x86_FLOAT_STATE32_COUNT)); |
154 break; | 154 break; |
155 case x86_FLOAT_STATE64: | 155 case x86_FLOAT_STATE64: |
156 EXPECT_EQ(implicit_cast<int>(x86_FLOAT_STATE64_COUNT), | 156 EXPECT_EQ(state->fsh.count, |
157 state->fsh.count); | 157 implicit_cast<int>(x86_FLOAT_STATE64_COUNT)); |
158 break; | 158 break; |
159 default: | 159 default: |
160 ADD_FAILURE() << "unexpected fsh.flavor " << state->fsh.flavor; | 160 ADD_FAILURE() << "unexpected fsh.flavor " << state->fsh.flavor; |
161 break; | 161 break; |
162 } | 162 } |
163 break; | 163 break; |
164 } | 164 } |
165 case x86_DEBUG_STATE: { | 165 case x86_DEBUG_STATE: { |
166 EXPECT_EQ(x86_DEBUG_STATE_COUNT, old_state_count); | 166 EXPECT_EQ(old_state_count, x86_DEBUG_STATE_COUNT); |
167 const x86_debug_state* state = | 167 const x86_debug_state* state = |
168 reinterpret_cast<const x86_debug_state*>(old_state); | 168 reinterpret_cast<const x86_debug_state*>(old_state); |
169 switch (state->dsh.flavor) { | 169 switch (state->dsh.flavor) { |
170 case x86_DEBUG_STATE32: | 170 case x86_DEBUG_STATE32: |
171 EXPECT_EQ(implicit_cast<int>(x86_DEBUG_STATE32_COUNT), | 171 EXPECT_EQ(state->dsh.count, |
172 state->dsh.count); | 172 implicit_cast<int>(x86_DEBUG_STATE32_COUNT)); |
173 break; | 173 break; |
174 case x86_DEBUG_STATE64: | 174 case x86_DEBUG_STATE64: |
175 EXPECT_EQ(implicit_cast<int>(x86_DEBUG_STATE64_COUNT), | 175 EXPECT_EQ(state->dsh.count, |
176 state->dsh.count); | 176 implicit_cast<int>(x86_DEBUG_STATE64_COUNT)); |
177 break; | 177 break; |
178 default: | 178 default: |
179 ADD_FAILURE() << "unexpected dsh.flavor " << state->dsh.flavor; | 179 ADD_FAILURE() << "unexpected dsh.flavor " << state->dsh.flavor; |
180 break; | 180 break; |
181 } | 181 } |
182 break; | 182 break; |
183 } | 183 } |
184 case x86_THREAD_STATE32: | 184 case x86_THREAD_STATE32: |
185 EXPECT_EQ(x86_THREAD_STATE32_COUNT, old_state_count); | 185 EXPECT_EQ(old_state_count, x86_THREAD_STATE32_COUNT); |
186 break; | 186 break; |
187 case x86_FLOAT_STATE32: | 187 case x86_FLOAT_STATE32: |
188 EXPECT_EQ(x86_FLOAT_STATE32_COUNT, old_state_count); | 188 EXPECT_EQ(old_state_count, x86_FLOAT_STATE32_COUNT); |
189 break; | 189 break; |
190 case x86_DEBUG_STATE32: | 190 case x86_DEBUG_STATE32: |
191 EXPECT_EQ(x86_DEBUG_STATE32_COUNT, old_state_count); | 191 EXPECT_EQ(old_state_count, x86_DEBUG_STATE32_COUNT); |
192 break; | 192 break; |
193 case x86_THREAD_STATE64: | 193 case x86_THREAD_STATE64: |
194 EXPECT_EQ(x86_THREAD_STATE64_COUNT, old_state_count); | 194 EXPECT_EQ(old_state_count, x86_THREAD_STATE64_COUNT); |
195 break; | 195 break; |
196 case x86_FLOAT_STATE64: | 196 case x86_FLOAT_STATE64: |
197 EXPECT_EQ(x86_FLOAT_STATE64_COUNT, old_state_count); | 197 EXPECT_EQ(old_state_count, x86_FLOAT_STATE64_COUNT); |
198 break; | 198 break; |
199 case x86_DEBUG_STATE64: | 199 case x86_DEBUG_STATE64: |
200 EXPECT_EQ(x86_DEBUG_STATE64_COUNT, old_state_count); | 200 EXPECT_EQ(old_state_count, x86_DEBUG_STATE64_COUNT); |
201 break; | 201 break; |
202 #else | 202 #else |
203 #error Port to your CPU architecture | 203 #error Port to your CPU architecture |
204 #endif | 204 #endif |
205 default: | 205 default: |
206 ADD_FAILURE() << "unexpected flavor " << *flavor; | 206 ADD_FAILURE() << "unexpected flavor " << *flavor; |
207 break; | 207 break; |
208 } | 208 } |
209 | 209 |
210 // Attempt to set a garbage thread state, which would cause the child to | 210 // Attempt to set a garbage thread state, which would cause the child to |
211 // crash inside SimulateCrash() if it actually succeeded. This tests that | 211 // crash inside SimulateCrash() if it actually succeeded. This tests that |
212 // SimulateCrash() ignores new_state instead of attempting to set the | 212 // SimulateCrash() ignores new_state instead of attempting to set the |
213 // state as the kernel would do. This operates in conjunction with the | 213 // state as the kernel would do. This operates in conjunction with the |
214 // |true| argument to ExcServerSuccessfulReturnValue() below. | 214 // |true| argument to ExcServerSuccessfulReturnValue() below. |
215 *new_state_count = old_state_count; | 215 *new_state_count = old_state_count; |
216 size_t new_state_size = sizeof(natural_t) * old_state_count; | 216 size_t new_state_size = sizeof(natural_t) * old_state_count; |
217 memset(new_state, 0xa5, new_state_size); | 217 memset(new_state, 0xa5, new_state_size); |
218 } | 218 } |
219 | 219 |
220 if (!succeed_) { | 220 if (!succeed_) { |
221 // The client has registered EXC_CRASH handlers for both its thread and | 221 // The client has registered EXC_CRASH handlers for both its thread and |
222 // task targets, and sent a simulated exception message to its | 222 // task targets, and sent a simulated exception message to its |
223 // thread-level EXC_CRASH handler. To test that it will fall back to | 223 // thread-level EXC_CRASH handler. To test that it will fall back to |
224 // trying the task-level EXC_CRASH handler, return a failure code, which | 224 // trying the task-level EXC_CRASH handler, return a failure code, which |
225 // should cause SimulateCrash() to try the next target. | 225 // should cause SimulateCrash() to try the next target. |
226 EXPECT_EQ(kExceptionPortsTargetBoth, target_); | 226 EXPECT_EQ(target_, kExceptionPortsTargetBoth); |
227 return KERN_ABORTED; | 227 return KERN_ABORTED; |
228 } | 228 } |
229 | 229 |
230 ExcServerCopyState( | 230 ExcServerCopyState( |
231 behavior, old_state, old_state_count, new_state, new_state_count); | 231 behavior, old_state, old_state_count, new_state, new_state_count); |
232 | 232 |
233 return ExcServerSuccessfulReturnValue(exception, behavior, true); | 233 return ExcServerSuccessfulReturnValue(exception, behavior, true); |
234 } | 234 } |
235 | 235 |
236 private: | 236 private: |
(...skipping 15 matching lines...) Expand all Loading... |
252 // task targets. Run a server that will return a failure code when the | 252 // task targets. Run a server that will return a failure code when the |
253 // exception message is sent to the thread target, which will cause the | 253 // exception message is sent to the thread target, which will cause the |
254 // client to fall back to the task target and send another message. | 254 // client to fall back to the task target and send another message. |
255 succeed_ = false; | 255 succeed_ = false; |
256 mr = MachMessageServer::Run(&universal_mach_exc_server, | 256 mr = MachMessageServer::Run(&universal_mach_exc_server, |
257 LocalPort(), | 257 LocalPort(), |
258 MACH_MSG_OPTION_NONE, | 258 MACH_MSG_OPTION_NONE, |
259 MachMessageServer::kOneShot, | 259 MachMessageServer::kOneShot, |
260 MachMessageServer::kReceiveLargeError, | 260 MachMessageServer::kReceiveLargeError, |
261 kMachMessageTimeoutWaitIndefinitely); | 261 kMachMessageTimeoutWaitIndefinitely); |
262 EXPECT_EQ(MACH_MSG_SUCCESS, mr) | 262 EXPECT_EQ(mr, MACH_MSG_SUCCESS) |
263 << MachErrorMessage(mr, "MachMessageServer::Run"); | 263 << MachErrorMessage(mr, "MachMessageServer::Run"); |
264 } | 264 } |
265 | 265 |
266 succeed_ = true; | 266 succeed_ = true; |
267 mr = MachMessageServer::Run(&universal_mach_exc_server, | 267 mr = MachMessageServer::Run(&universal_mach_exc_server, |
268 LocalPort(), | 268 LocalPort(), |
269 MACH_MSG_OPTION_NONE, | 269 MACH_MSG_OPTION_NONE, |
270 MachMessageServer::kOneShot, | 270 MachMessageServer::kOneShot, |
271 MachMessageServer::kReceiveLargeError, | 271 MachMessageServer::kReceiveLargeError, |
272 kMachMessageTimeoutWaitIndefinitely); | 272 kMachMessageTimeoutWaitIndefinitely); |
273 EXPECT_EQ(MACH_MSG_SUCCESS, mr) | 273 EXPECT_EQ(mr, MACH_MSG_SUCCESS) |
274 << MachErrorMessage(mr, "MachMessageServer::Run"); | 274 << MachErrorMessage(mr, "MachMessageServer::Run"); |
275 } | 275 } |
276 | 276 |
277 void MachMultiprocessChild() override { | 277 void MachMultiprocessChild() override { |
278 bool task_valid = target_ == kExceptionPortsTargetTask || | 278 bool task_valid = target_ == kExceptionPortsTargetTask || |
279 target_ == kExceptionPortsTargetBoth; | 279 target_ == kExceptionPortsTargetBoth; |
280 ExceptionPorts task_exception_ports(ExceptionPorts::kTargetTypeTask, | 280 ExceptionPorts task_exception_ports(ExceptionPorts::kTargetTypeTask, |
281 TASK_NULL); | 281 TASK_NULL); |
282 ASSERT_TRUE(task_exception_ports.SetExceptionPort( | 282 ASSERT_TRUE(task_exception_ports.SetExceptionPort( |
283 EXC_MASK_CRASH, | 283 EXC_MASK_CRASH, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 test_simulate_crash_mac.Run(); | 379 test_simulate_crash_mac.Run(); |
380 } | 380 } |
381 } | 381 } |
382 } | 382 } |
383 } | 383 } |
384 } | 384 } |
385 | 385 |
386 } // namespace | 386 } // namespace |
387 } // namespace test | 387 } // namespace test |
388 } // namespace crashpad | 388 } // namespace crashpad |
OLD | NEW |