mac: 10.13 SDK compatibility, adapt to x86_state_hdr changes

In the 10.12 SDK, x86_state_hdr from <mach/i386/thread_status.h> was
defined as:

struct x86_state_hdr {
  int flavor;
  int count;
};

This has changed in the 10.13 SDK to:

struct x86_state_hdr {
  uint32_t flavor;
  uint32_t count;
};

This triggers signedness mismatch errors where these values are used
with CHECK/DCHECK macros and gtest EXPECT/ASSERT macros.

Compatibility with existing and new SDKs must be maintained, so more
casts must be used.

Bug: crashpad:185, crashpad:188
Change-Id: I8844d6a78520430a8b5b90a35403896c3c6cfa37
Reviewed-on: https://chromium-review.googlesource.com/533375
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Mark Mentovai 2017-06-13 14:00:36 -04:00 committed by Commit Bot
parent 8c35d92ae4
commit f845797732
3 changed files with 22 additions and 18 deletions

View File

@ -35,11 +35,15 @@ namespace {
// gtest assertions.
void SanityCheckContext(const NativeCPUContext& context) {
#if defined(ARCH_CPU_X86)
ASSERT_EQ(context.tsh.flavor, x86_THREAD_STATE32);
ASSERT_EQ(context.tsh.count, implicit_cast<int>(x86_THREAD_STATE32_COUNT));
ASSERT_EQ(implicit_cast<thread_state_flavor_t>(context.tsh.flavor),
implicit_cast<thread_state_flavor_t>(x86_THREAD_STATE32));
ASSERT_EQ(implicit_cast<uint32_t>(context.tsh.count),
implicit_cast<uint32_t>(x86_THREAD_STATE32_COUNT));
#elif defined(ARCH_CPU_X86_64)
ASSERT_EQ(context.tsh.flavor, x86_THREAD_STATE64);
ASSERT_EQ(context.tsh.count, implicit_cast<int>(x86_THREAD_STATE64_COUNT));
ASSERT_EQ(implicit_cast<thread_state_flavor_t>(context.tsh.flavor),
implicit_cast<thread_state_flavor_t>(x86_THREAD_STATE64));
ASSERT_EQ(implicit_cast<uint32_t>(context.tsh.count),
implicit_cast<uint32_t>(x86_THREAD_STATE64_COUNT));
#endif
#if defined(ARCH_CPU_X86_FAMILY)

View File

@ -177,12 +177,12 @@ bool DeliverException(thread_t thread,
void SimulateCrash(const NativeCPUContext& cpu_context) {
#if defined(ARCH_CPU_X86)
DCHECK_EQ(cpu_context.tsh.flavor,
DCHECK_EQ(implicit_cast<thread_state_flavor_t>(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),
x86_THREAD_STATE32_COUNT);
#elif defined(ARCH_CPU_X86_64)
DCHECK_EQ(cpu_context.tsh.flavor,
DCHECK_EQ(implicit_cast<thread_state_flavor_t>(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),
x86_THREAD_STATE64_COUNT);

View File

@ -130,12 +130,12 @@ class TestSimulateCrashMac final : public MachMultiprocess,
reinterpret_cast<const x86_thread_state*>(old_state);
switch (state->tsh.flavor) {
case x86_THREAD_STATE32:
EXPECT_EQ(state->tsh.count,
implicit_cast<int>(x86_THREAD_STATE32_COUNT));
EXPECT_EQ(implicit_cast<uint32_t>(state->tsh.count),
implicit_cast<uint32_t>(x86_THREAD_STATE32_COUNT));
break;
case x86_THREAD_STATE64:
EXPECT_EQ(state->tsh.count,
implicit_cast<int>(x86_THREAD_STATE64_COUNT));
EXPECT_EQ(implicit_cast<uint32_t>(state->tsh.count),
implicit_cast<uint32_t>(x86_THREAD_STATE64_COUNT));
break;
default:
ADD_FAILURE() << "unexpected tsh.flavor " << state->tsh.flavor;
@ -149,12 +149,12 @@ class TestSimulateCrashMac final : public MachMultiprocess,
reinterpret_cast<const x86_float_state*>(old_state);
switch (state->fsh.flavor) {
case x86_FLOAT_STATE32:
EXPECT_EQ(state->fsh.count,
implicit_cast<int>(x86_FLOAT_STATE32_COUNT));
EXPECT_EQ(implicit_cast<uint32_t>(state->fsh.count),
implicit_cast<uint32_t>(x86_FLOAT_STATE32_COUNT));
break;
case x86_FLOAT_STATE64:
EXPECT_EQ(state->fsh.count,
implicit_cast<int>(x86_FLOAT_STATE64_COUNT));
EXPECT_EQ(implicit_cast<uint32_t>(state->fsh.count),
implicit_cast<uint32_t>(x86_FLOAT_STATE64_COUNT));
break;
default:
ADD_FAILURE() << "unexpected fsh.flavor " << state->fsh.flavor;
@ -168,12 +168,12 @@ class TestSimulateCrashMac final : public MachMultiprocess,
reinterpret_cast<const x86_debug_state*>(old_state);
switch (state->dsh.flavor) {
case x86_DEBUG_STATE32:
EXPECT_EQ(state->dsh.count,
implicit_cast<int>(x86_DEBUG_STATE32_COUNT));
EXPECT_EQ(implicit_cast<uint32_t>(state->dsh.count),
implicit_cast<uint32_t>(x86_DEBUG_STATE32_COUNT));
break;
case x86_DEBUG_STATE64:
EXPECT_EQ(state->dsh.count,
implicit_cast<int>(x86_DEBUG_STATE64_COUNT));
EXPECT_EQ(implicit_cast<uint32_t>(state->dsh.count),
implicit_cast<uint32_t>(x86_DEBUG_STATE64_COUNT));
break;
default:
ADD_FAILURE() << "unexpected dsh.flavor " << state->dsh.flavor;