mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 22:26:06 +00:00
mac: Crashpad for macOS on arm64, phase 2: build tests
This gets all tests building. They don’t all pass, and there aren’t any guarantees that anything else works yet, either. This is mostly a lot of CPU context shuffling. Bug: crashpad:345 Change-Id: I684017a5816f44917392964d7fb6d08083770b38 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2285962 Reviewed-by: Robert Sesek <rsesek@chromium.org> Commit-Queue: Mark Mentovai <mark@chromium.org>
This commit is contained in:
parent
809939c9d1
commit
0c3f50c8e1
@ -200,6 +200,28 @@ class TestSimulateCrashMac final : public MachMultiprocess,
|
||||
case x86_DEBUG_STATE64:
|
||||
EXPECT_EQ(old_state_count, x86_DEBUG_STATE64_COUNT);
|
||||
break;
|
||||
#elif defined(ARCH_CPU_ARM64)
|
||||
case ARM_UNIFIED_THREAD_STATE: {
|
||||
EXPECT_EQ(old_state_count, ARM_UNIFIED_THREAD_STATE_COUNT);
|
||||
const arm_unified_thread_state* state =
|
||||
reinterpret_cast<const arm_unified_thread_state*>(old_state);
|
||||
EXPECT_EQ(state->ash.flavor,
|
||||
implicit_cast<uint32_t>(ARM_THREAD_STATE64));
|
||||
if (state->ash.flavor == ARM_THREAD_STATE64) {
|
||||
EXPECT_EQ(state->ash.count,
|
||||
implicit_cast<uint32_t>(ARM_THREAD_STATE64_COUNT));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ARM_THREAD_STATE64:
|
||||
EXPECT_EQ(old_state_count, ARM_THREAD_STATE64_COUNT);
|
||||
break;
|
||||
case ARM_NEON_STATE64:
|
||||
EXPECT_EQ(old_state_count, ARM_NEON_STATE64_COUNT);
|
||||
break;
|
||||
case ARM_DEBUG_STATE64:
|
||||
EXPECT_EQ(old_state_count, ARM_DEBUG_STATE64_COUNT);
|
||||
break;
|
||||
#else
|
||||
#error Port to your CPU architecture
|
||||
#endif
|
||||
@ -338,6 +360,11 @@ TEST(SimulateCrash, SimulateCrash) {
|
||||
x86_FLOAT_STATE64,
|
||||
x86_DEBUG_STATE64,
|
||||
#endif
|
||||
#elif defined(ARCH_CPU_ARM64)
|
||||
ARM_UNIFIED_THREAD_STATE,
|
||||
ARM_THREAD_STATE64,
|
||||
ARM_NEON_STATE64,
|
||||
ARM_DEBUG_STATE64,
|
||||
#else
|
||||
#error Port to your CPU architecture
|
||||
#endif
|
||||
|
@ -68,6 +68,8 @@ using Nlist = struct nlist;
|
||||
constexpr int kCPUType = CPU_TYPE_X86_64;
|
||||
#elif defined(ARCH_CPU_X86)
|
||||
constexpr int kCPUType = CPU_TYPE_X86;
|
||||
#elif defined(ARCH_CPU_ARM64)
|
||||
constexpr int kCPUType = CPU_TYPE_ARM64;
|
||||
#endif
|
||||
|
||||
// Verifies that |expect_section| and |actual_section| agree.
|
||||
|
@ -69,6 +69,8 @@ TEST_F(SystemSnapshotMacTest, GetCPUArchitecture) {
|
||||
EXPECT_EQ(cpu_architecture, kCPUArchitectureX86);
|
||||
#elif defined(ARCH_CPU_X86_64)
|
||||
EXPECT_EQ(cpu_architecture, kCPUArchitectureX86_64);
|
||||
#elif defined(ARCH_CPU_ARM64)
|
||||
EXPECT_EQ(cpu_architecture, kCPUArchitectureARM64);
|
||||
#else
|
||||
#error port to your architecture
|
||||
#endif
|
||||
@ -87,6 +89,8 @@ TEST_F(SystemSnapshotMacTest, CPUVendor) {
|
||||
if (cpu_vendor != "GenuineIntel" && cpu_vendor != "AuthenticAMD") {
|
||||
FAIL() << "cpu_vendor " << cpu_vendor;
|
||||
}
|
||||
#elif defined(ARCH_CPU_ARM64)
|
||||
EXPECT_EQ(cpu_vendor, "Apple processor");
|
||||
#else
|
||||
#error port to your architecture
|
||||
#endif
|
||||
|
@ -1152,10 +1152,10 @@ TEST(ExcServerVariants, ThreadStates) {
|
||||
// _MachineStateCount[] array indexed by the flavor number to obtain the
|
||||
// buffer size. 10.9.4 xnu-2422.110.17/osfmk/i386/pcb.c contains the
|
||||
// definition of this array for the x86 family. The slots corresponding to
|
||||
// thread, float, and exception state flavors in both native-width (32-
|
||||
// and 64-bit) and universal are correct, but the remaining elements in
|
||||
// the array are not. This includes elements that would correspond to
|
||||
// debug and AVX state flavors, so these cannot be tested here.
|
||||
// thread, float, and exception state flavors in both native-width (32- and
|
||||
// 64-bit) and universal are correct, but the remaining elements in the
|
||||
// array are not. This includes elements that would correspond to debug and
|
||||
// AVX state flavors, so these cannot be tested here.
|
||||
//
|
||||
// When machine_thread_get_state() (the machine-specific implementation of
|
||||
// thread_get_state()) encounters an undersized buffer as reported by the
|
||||
@ -1167,19 +1167,23 @@ TEST(ExcServerVariants, ThreadStates) {
|
||||
//
|
||||
// Additionaly, the AVX state flavors are also not tested because they’re
|
||||
// not available on all CPUs and OS versions.
|
||||
{x86_THREAD_STATE, x86_THREAD_STATE_COUNT},
|
||||
{x86_FLOAT_STATE, x86_FLOAT_STATE_COUNT},
|
||||
{x86_EXCEPTION_STATE, x86_EXCEPTION_STATE_COUNT},
|
||||
#if defined(ARCH_CPU_X86)
|
||||
{x86_THREAD_STATE32, x86_THREAD_STATE32_COUNT},
|
||||
{x86_FLOAT_STATE32, x86_FLOAT_STATE32_COUNT},
|
||||
{x86_EXCEPTION_STATE32, x86_EXCEPTION_STATE32_COUNT},
|
||||
#endif
|
||||
#if defined(ARCH_CPU_X86_64)
|
||||
#elif defined(ARCH_CPU_X86_64)
|
||||
{x86_THREAD_STATE64, x86_THREAD_STATE64_COUNT},
|
||||
{x86_FLOAT_STATE64, x86_FLOAT_STATE64_COUNT},
|
||||
{x86_EXCEPTION_STATE64, x86_EXCEPTION_STATE64_COUNT},
|
||||
#endif
|
||||
{x86_THREAD_STATE, x86_THREAD_STATE_COUNT},
|
||||
{x86_FLOAT_STATE, x86_FLOAT_STATE_COUNT},
|
||||
{x86_EXCEPTION_STATE, x86_EXCEPTION_STATE_COUNT},
|
||||
#elif defined(ARCH_CPU_ARM64)
|
||||
{ARM_UNIFIED_THREAD_STATE, ARM_UNIFIED_THREAD_STATE_COUNT},
|
||||
{ARM_THREAD_STATE64, ARM_THREAD_STATE64_COUNT},
|
||||
{ARM_NEON_STATE64, ARM_NEON_STATE64_COUNT},
|
||||
{ARM_EXCEPTION_STATE64, ARM_EXCEPTION_STATE64_COUNT},
|
||||
#else
|
||||
#error Port this test to your CPU architecture.
|
||||
#endif
|
||||
|
@ -41,18 +41,7 @@ TEST(ExceptionTypes, ExcCrashRecoverOriginalException) {
|
||||
{0xb100002, EXC_BAD_ACCESS, KERN_PROTECTION_FAILURE, SIGSEGV},
|
||||
{0xa100002, EXC_BAD_ACCESS, KERN_PROTECTION_FAILURE, SIGBUS},
|
||||
{0xa100005, EXC_BAD_ACCESS, VM_PROT_READ | VM_PROT_EXECUTE, SIGBUS},
|
||||
{0xa10000d, EXC_BAD_ACCESS, EXC_I386_GPFLT, SIGBUS},
|
||||
{0x9100032, EXC_BAD_ACCESS, KERN_CODESIGN_ERROR, SIGKILL},
|
||||
{0x4200001, EXC_BAD_INSTRUCTION, EXC_I386_INVOP, SIGILL},
|
||||
{0x420000b, EXC_BAD_INSTRUCTION, EXC_I386_SEGNPFLT, SIGILL},
|
||||
{0x420000c, EXC_BAD_INSTRUCTION, EXC_I386_STKFLT, SIGILL},
|
||||
{0x8300001, EXC_ARITHMETIC, EXC_I386_DIV, SIGFPE},
|
||||
{0x8300002, EXC_ARITHMETIC, EXC_I386_INTO, SIGFPE},
|
||||
{0x8300005, EXC_ARITHMETIC, EXC_I386_EXTERR, SIGFPE},
|
||||
{0x8300008, EXC_ARITHMETIC, EXC_I386_SSEEXTERR, SIGFPE},
|
||||
{0x5500007, EXC_SOFTWARE, EXC_I386_BOUND, SIGTRAP},
|
||||
{0x5600001, EXC_BREAKPOINT, EXC_I386_SGL, SIGTRAP},
|
||||
{0x5600002, EXC_BREAKPOINT, EXC_I386_BPT, SIGTRAP},
|
||||
{0x0700080, EXC_SYSCALL, 128, 0},
|
||||
{0x0706000, EXC_SYSCALL, 0x6000, 0},
|
||||
{0x3000000, 0, 0, SIGQUIT},
|
||||
@ -65,6 +54,20 @@ TEST(ExceptionTypes, ExcCrashRecoverOriginalException) {
|
||||
{0xb000000, 0, 0, SIGSEGV},
|
||||
{0xc000000, 0, 0, SIGSYS},
|
||||
{0, 0, 0, 0},
|
||||
#if defined(ARCH_CPU_X86_FAMILY)
|
||||
{0xa10000d, EXC_BAD_ACCESS, EXC_I386_GPFLT, SIGBUS},
|
||||
{0x4200001, EXC_BAD_INSTRUCTION, EXC_I386_INVOP, SIGILL},
|
||||
{0x420000b, EXC_BAD_INSTRUCTION, EXC_I386_SEGNPFLT, SIGILL},
|
||||
{0x420000c, EXC_BAD_INSTRUCTION, EXC_I386_STKFLT, SIGILL},
|
||||
{0x8300001, EXC_ARITHMETIC, EXC_I386_DIV, SIGFPE},
|
||||
{0x8300002, EXC_ARITHMETIC, EXC_I386_INTO, SIGFPE},
|
||||
{0x8300005, EXC_ARITHMETIC, EXC_I386_EXTERR, SIGFPE},
|
||||
{0x8300008, EXC_ARITHMETIC, EXC_I386_SSEEXTERR, SIGFPE},
|
||||
{0x5500007, EXC_SOFTWARE, EXC_I386_BOUND, SIGTRAP},
|
||||
{0x5600001, EXC_BREAKPOINT, EXC_I386_SGL, SIGTRAP},
|
||||
{0x5600002, EXC_BREAKPOINT, EXC_I386_BPT, SIGTRAP},
|
||||
#endif
|
||||
// TODO(macos_arm64): Add arm64 test data.
|
||||
};
|
||||
|
||||
for (size_t index = 0; index < base::size(kTestData); ++index) {
|
||||
@ -142,8 +145,11 @@ TEST(ExceptionTypes, ExceptionCodeForMetrics) {
|
||||
ENCODE_EXC(EXC_BAD_ACCESS, KERN_INVALID_ADDRESS),
|
||||
ENCODE_EXC(EXC_BAD_ACCESS, KERN_PROTECTION_FAILURE),
|
||||
ENCODE_EXC(EXC_BAD_ACCESS, VM_PROT_READ | VM_PROT_EXECUTE),
|
||||
ENCODE_EXC(EXC_BAD_ACCESS, EXC_I386_GPFLT),
|
||||
ENCODE_EXC(EXC_BAD_ACCESS, KERN_CODESIGN_ERROR),
|
||||
ENCODE_EXC(EXC_SYSCALL, 128),
|
||||
ENCODE_EXC(EXC_SYSCALL, 0x6000),
|
||||
#if defined(ARCH_CPU_X86_FAMILY)
|
||||
ENCODE_EXC(EXC_BAD_ACCESS, EXC_I386_GPFLT),
|
||||
ENCODE_EXC(EXC_BAD_INSTRUCTION, EXC_I386_INVOP),
|
||||
ENCODE_EXC(EXC_BAD_INSTRUCTION, EXC_I386_SEGNPFLT),
|
||||
ENCODE_EXC(EXC_BAD_INSTRUCTION, EXC_I386_STKFLT),
|
||||
@ -154,8 +160,8 @@ TEST(ExceptionTypes, ExceptionCodeForMetrics) {
|
||||
ENCODE_EXC(EXC_SOFTWARE, EXC_I386_BOUND),
|
||||
ENCODE_EXC(EXC_BREAKPOINT, EXC_I386_SGL),
|
||||
ENCODE_EXC(EXC_BREAKPOINT, EXC_I386_BPT),
|
||||
ENCODE_EXC(EXC_SYSCALL, 128),
|
||||
ENCODE_EXC(EXC_SYSCALL, 0x6000),
|
||||
#endif
|
||||
// TODO(macos_arm64): Add arm64 test data.
|
||||
#undef ENCODE_EXC
|
||||
|
||||
#define ENCODE_EXC_CRASH(type, code_0) \
|
||||
@ -166,8 +172,11 @@ TEST(ExceptionTypes, ExceptionCodeForMetrics) {
|
||||
ENCODE_EXC_CRASH(EXC_BAD_ACCESS, KERN_INVALID_ADDRESS),
|
||||
ENCODE_EXC_CRASH(EXC_BAD_ACCESS, KERN_PROTECTION_FAILURE),
|
||||
ENCODE_EXC_CRASH(EXC_BAD_ACCESS, VM_PROT_READ | VM_PROT_EXECUTE),
|
||||
ENCODE_EXC_CRASH(EXC_BAD_ACCESS, EXC_I386_GPFLT),
|
||||
ENCODE_EXC_CRASH(EXC_BAD_ACCESS, KERN_CODESIGN_ERROR),
|
||||
ENCODE_EXC_CRASH(EXC_SYSCALL, 128),
|
||||
ENCODE_EXC_CRASH(EXC_SYSCALL, 0x6000),
|
||||
#if defined(ARCH_CPU_X86_FAMILY)
|
||||
ENCODE_EXC_CRASH(EXC_BAD_ACCESS, EXC_I386_GPFLT),
|
||||
ENCODE_EXC_CRASH(EXC_BAD_INSTRUCTION, EXC_I386_INVOP),
|
||||
ENCODE_EXC_CRASH(EXC_BAD_INSTRUCTION, EXC_I386_SEGNPFLT),
|
||||
ENCODE_EXC_CRASH(EXC_BAD_INSTRUCTION, EXC_I386_STKFLT),
|
||||
@ -178,8 +187,8 @@ TEST(ExceptionTypes, ExceptionCodeForMetrics) {
|
||||
ENCODE_EXC_CRASH(EXC_SOFTWARE, EXC_I386_BOUND),
|
||||
ENCODE_EXC_CRASH(EXC_BREAKPOINT, EXC_I386_SGL),
|
||||
ENCODE_EXC_CRASH(EXC_BREAKPOINT, EXC_I386_BPT),
|
||||
ENCODE_EXC_CRASH(EXC_SYSCALL, 128),
|
||||
ENCODE_EXC_CRASH(EXC_SYSCALL, 0x6000),
|
||||
#endif
|
||||
// TODO(macos_arm64): Add arm64 test data.
|
||||
#undef ENCODE_EXC_CRASH
|
||||
|
||||
#define ENCODE_EXC_CRASH_SIGNAL(signal) \
|
||||
|
@ -309,7 +309,7 @@ class TestMachMessageServer : public MachMessageServer::Interface,
|
||||
// ensure that whatever buffer was allocated to receive a RequestMessage is
|
||||
// not large enough to receive a LargeRequestMessage.
|
||||
struct LargeRequestMessage : public RequestMessage {
|
||||
uint8_t data[4 * PAGE_SIZE];
|
||||
uint8_t data[4 * PAGE_MAX_SIZE];
|
||||
};
|
||||
|
||||
struct ReplyMessage : public mig_reply_error_t {
|
||||
|
@ -33,7 +33,7 @@ namespace {
|
||||
|
||||
TEST(ProcessMemoryMac, ReadMappedSelf) {
|
||||
vm_address_t address = 0;
|
||||
constexpr vm_size_t kSize = 4 * PAGE_SIZE;
|
||||
const vm_size_t kSize = 4 * PAGE_SIZE;
|
||||
kern_return_t kr =
|
||||
vm_allocate(mach_task_self(), &address, kSize, VM_FLAGS_ANYWHERE);
|
||||
ASSERT_EQ(kr, KERN_SUCCESS) << MachErrorMessage(kr, "vm_allocate");
|
||||
@ -88,7 +88,7 @@ TEST(ProcessMemoryMac, ReadMappedSelf) {
|
||||
|
||||
TEST(ProcessMemoryMac, ReadSelfUnmapped) {
|
||||
vm_address_t address = 0;
|
||||
constexpr vm_size_t kSize = 2 * PAGE_SIZE;
|
||||
const vm_size_t kSize = 2 * PAGE_SIZE;
|
||||
kern_return_t kr =
|
||||
vm_allocate(mach_task_self(), &address, kSize, VM_FLAGS_ANYWHERE);
|
||||
ASSERT_EQ(kr, KERN_SUCCESS) << MachErrorMessage(kr, "vm_allocate");
|
||||
@ -150,7 +150,7 @@ TEST(ProcessMemoryMac, ReadSelfUnmapped) {
|
||||
|
||||
TEST(ProcessMemoryMac, ReadCStringSelfUnmapped) {
|
||||
vm_address_t address = 0;
|
||||
constexpr vm_size_t kSize = 2 * PAGE_SIZE;
|
||||
const vm_size_t kSize = 2 * PAGE_SIZE;
|
||||
kern_return_t kr =
|
||||
vm_allocate(mach_task_self(), &address, kSize, VM_FLAGS_ANYWHERE);
|
||||
ASSERT_EQ(kr, KERN_SUCCESS) << MachErrorMessage(kr, "vm_allocate");
|
||||
@ -259,7 +259,7 @@ TEST(ProcessMemoryMac, MappedMemoryDeallocates) {
|
||||
// This is the same but with a big buffer that’s definitely larger than a
|
||||
// single page. This makes sure that the whole mapped region winds up being
|
||||
// deallocated.
|
||||
constexpr size_t kBigSize = 4 * PAGE_SIZE;
|
||||
const size_t kBigSize = 4 * PAGE_SIZE;
|
||||
std::unique_ptr<char[]> big_buffer(new char[kBigSize]);
|
||||
test_address = FromPointerCast<mach_vm_address_t>(&big_buffer[0]);
|
||||
ASSERT_TRUE((mapped = memory.ReadMapped(test_address, kBigSize)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user