| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 break; | 136 break; |
| 137 } | 137 } |
| 138 | 138 |
| 139 // new_state is supposed to be an out parameter only, but in case the handler | 139 // new_state is supposed to be an out parameter only, but in case the handler |
| 140 // doesn't touch it, make sure it's initialized to a valid thread state. | 140 // doesn't touch it, make sure it's initialized to a valid thread state. |
| 141 // Otherwise, the thread_set_state() call below would set a garbage thread | 141 // Otherwise, the thread_set_state() call below would set a garbage thread |
| 142 // state. | 142 // state. |
| 143 thread_state_data_t new_state; | 143 thread_state_data_t new_state; |
| 144 size_t state_size = | 144 size_t state_size = |
| 145 sizeof(natural_t) * | 145 sizeof(natural_t) * |
| 146 std::min(state_count, static_cast<unsigned int>(THREAD_STATE_MAX)); | 146 std::min(state_count, implicit_cast<unsigned int>(THREAD_STATE_MAX)); |
| 147 memcpy(new_state, state, state_size); | 147 memcpy(new_state, state, state_size); |
| 148 mach_msg_type_number_t new_state_count = THREAD_STATE_MAX; | 148 mach_msg_type_number_t new_state_count = THREAD_STATE_MAX; |
| 149 | 149 |
| 150 kr = UniversalExceptionRaise(handler.behavior, | 150 kr = UniversalExceptionRaise(handler.behavior, |
| 151 handler.port, | 151 handler.port, |
| 152 thread, | 152 thread, |
| 153 task, | 153 task, |
| 154 exception, | 154 exception, |
| 155 code, | 155 code, |
| 156 code_count, | 156 code_count, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 174 } | 174 } |
| 175 | 175 |
| 176 return success; | 176 return success; |
| 177 } | 177 } |
| 178 | 178 |
| 179 } // namespace | 179 } // namespace |
| 180 | 180 |
| 181 void SimulateCrash(const NativeCPUContext* cpu_context) { | 181 void SimulateCrash(const NativeCPUContext* cpu_context) { |
| 182 #if defined(ARCH_CPU_X86) | 182 #if defined(ARCH_CPU_X86) |
| 183 DCHECK_EQ(cpu_context->tsh.flavor, | 183 DCHECK_EQ(cpu_context->tsh.flavor, |
| 184 static_cast<thread_state_flavor_t>(x86_THREAD_STATE32)); | 184 implicit_cast<thread_state_flavor_t>(x86_THREAD_STATE32)); |
| 185 DCHECK_EQ(static_cast<mach_msg_type_number_t>(cpu_context->tsh.count), | 185 DCHECK_EQ(implicit_cast<mach_msg_type_number_t>(cpu_context->tsh.count), |
| 186 x86_THREAD_STATE32_COUNT); | 186 x86_THREAD_STATE32_COUNT); |
| 187 #elif defined(ARCH_CPU_X86_64) | 187 #elif defined(ARCH_CPU_X86_64) |
| 188 DCHECK_EQ(cpu_context->tsh.flavor, | 188 DCHECK_EQ(cpu_context->tsh.flavor, |
| 189 static_cast<thread_state_flavor_t>(x86_THREAD_STATE64)); | 189 implicit_cast<thread_state_flavor_t>(x86_THREAD_STATE64)); |
| 190 DCHECK_EQ(static_cast<mach_msg_type_number_t>(cpu_context->tsh.count), | 190 DCHECK_EQ(implicit_cast<mach_msg_type_number_t>(cpu_context->tsh.count), |
| 191 x86_THREAD_STATE64_COUNT); | 191 x86_THREAD_STATE64_COUNT); |
| 192 #endif | 192 #endif |
| 193 | 193 |
| 194 base::mac::ScopedMachSendRight thread(mach_thread_self()); | 194 base::mac::ScopedMachSendRight thread(mach_thread_self()); |
| 195 exception_type_t exception = kMachExceptionSimulated; | 195 exception_type_t exception = kMachExceptionSimulated; |
| 196 mach_exception_data_type_t codes[] = {0, 0}; | 196 mach_exception_data_type_t codes[] = {0, 0}; |
| 197 mach_msg_type_number_t code_count = arraysize(codes); | 197 mach_msg_type_number_t code_count = arraysize(codes); |
| 198 | 198 |
| 199 // Look up the handler for EXC_CRASH exceptions in the same way that the | 199 // Look up the handler for EXC_CRASH exceptions in the same way that the |
| 200 // kernel would: try a thread handler, then a task handler, and finally a host | 200 // kernel would: try a thread handler, then a task handler, and finally a host |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 false); | 235 false); |
| 236 } | 236 } |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 | 239 |
| 240 LOG_IF(WARNING, !success) | 240 LOG_IF(WARNING, !success) |
| 241 << "SimulateCrash did not find an appropriate exception handler"; | 241 << "SimulateCrash did not find an appropriate exception handler"; |
| 242 } | 242 } |
| 243 | 243 |
| 244 } // namespace crashpad | 244 } // namespace crashpad |
| OLD | NEW |