Use references instead of pointers for CPU context in SimulateCrash

The Windows equivalent uses references, which are better than pointers
for these const non-null objects.

R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1368023004 .
This commit is contained in:
Mark Mentovai 2015-09-25 16:26:29 -04:00
parent 0758dbde9a
commit 599eda0403
2 changed files with 13 additions and 13 deletions

View File

@ -59,7 +59,7 @@ bool DeliverException(thread_t thread,
exception_type_t exception,
const mach_exception_data_t code,
mach_msg_type_number_t code_count,
const NativeCPUContext* cpu_context,
const NativeCPUContext& cpu_context,
const ExceptionPorts::ExceptionHandler& handler,
bool set_state) {
kern_return_t kr;
@ -81,18 +81,18 @@ bool DeliverException(thread_t thread,
switch (flavor) {
#if defined(ARCH_CPU_X86_FAMILY)
case x86_THREAD_STATE:
state = reinterpret_cast<ConstThreadState>(cpu_context);
state = reinterpret_cast<ConstThreadState>(&cpu_context);
state_count = x86_THREAD_STATE_COUNT;
break;
#if defined(ARCH_CPU_X86)
case x86_THREAD_STATE32:
state = reinterpret_cast<ConstThreadState>(&cpu_context->uts.ts32);
state_count = cpu_context->tsh.count;
state = reinterpret_cast<ConstThreadState>(&cpu_context.uts.ts32);
state_count = cpu_context.tsh.count;
break;
#elif defined(ARCH_CPU_X86_64)
case x86_THREAD_STATE64:
state = reinterpret_cast<ConstThreadState>(&cpu_context->uts.ts64);
state_count = cpu_context->tsh.count;
state = reinterpret_cast<ConstThreadState>(&cpu_context.uts.ts64);
state_count = cpu_context.tsh.count;
break;
#endif
#else
@ -176,16 +176,16 @@ bool DeliverException(thread_t thread,
} // namespace
void SimulateCrash(const NativeCPUContext* cpu_context) {
void SimulateCrash(const NativeCPUContext& cpu_context) {
#if defined(ARCH_CPU_X86)
DCHECK_EQ(cpu_context->tsh.flavor,
DCHECK_EQ(cpu_context.tsh.flavor,
implicit_cast<thread_state_flavor_t>(x86_THREAD_STATE32));
DCHECK_EQ(implicit_cast<mach_msg_type_number_t>(cpu_context->tsh.count),
DCHECK_EQ(implicit_cast<mach_msg_type_number_t>(cpu_context.tsh.count),
x86_THREAD_STATE32_COUNT);
#elif defined(ARCH_CPU_X86_64)
DCHECK_EQ(cpu_context->tsh.flavor,
DCHECK_EQ(cpu_context.tsh.flavor,
implicit_cast<thread_state_flavor_t>(x86_THREAD_STATE64));
DCHECK_EQ(implicit_cast<mach_msg_type_number_t>(cpu_context->tsh.count),
DCHECK_EQ(implicit_cast<mach_msg_type_number_t>(cpu_context.tsh.count),
x86_THREAD_STATE64_COUNT);
#endif

View File

@ -45,7 +45,7 @@ namespace crashpad {
//! state flavor that the exception handler accepts. If it is not
//! compatible, the correct thread state for the handler will be obtained by
//! calling `thread_get_state()`.
void SimulateCrash(const NativeCPUContext* cpu_context);
void SimulateCrash(const NativeCPUContext& cpu_context);
} // namespace crashpad
@ -54,7 +54,7 @@ void SimulateCrash(const NativeCPUContext* cpu_context);
do { \
crashpad::NativeCPUContext cpu_context; \
crashpad::CaptureContext(&cpu_context); \
crashpad::SimulateCrash(&cpu_context); \
crashpad::SimulateCrash(cpu_context); \
} while (false)
#endif // CRASHPAD_CLIENT_SIMULATE_CRASH_MAC_H_