From 10e82d53189403e3abee94331d8bf3bd22c33bbc Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Fri, 19 Nov 2021 16:04:11 -0500 Subject: [PATCH] mac: Make crashpad build with the 12.0 SDK The size of dyld_all_image_infos didn't change, but the last 128 bit of `reserved` moved out of `reserved` and got names. On 64-bit, that's straightforward -- just move two uint64s out of the array into fields. On 32-bit, it's fairly awkward: It's 4 of the uintptr_t `reserved` array, which means `UIntPtr, reserved, [4]` would have to diverge between 32-bit and 64-bit, and also shared_cache_fs_obj_id would straddle the `end_v14` boundary. Since macOS 12.0 doesn't support 32-bit builds, just punt on this for 32-bit. (This might possibly mean that crashpad-on-apple-watch might not compile, but that's a build configuration that doesn't exist.) See comment 9 and 6 on the bug. Bug: crashpad:375, chromium:1265179 Change-Id: I221af20c59c30a8176d5685d3f5e84aaf3de9afe Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3253742 Commit-Queue: Nico Weber Auto-Submit: Nico Weber Reviewed-by: Mark Mentovai Message-Id: Merged from chromium 83a01b8e2cd2d4d96b0e298d012bb3a2bd93c64f Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3293642 Commit-Queue: Robert Sesek --- compat/mac/AvailabilityVersions.h | 6 ++++++ snapshot/mac/process_types/custom.cc | 1 + snapshot/mac/process_types/dyld_images.proctype | 8 ++++++-- snapshot/mac/process_types_test.cc | 12 ++++++++++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/compat/mac/AvailabilityVersions.h b/compat/mac/AvailabilityVersions.h index 0bedb3d2..b9bb74ec 100644 --- a/compat/mac/AvailabilityVersions.h +++ b/compat/mac/AvailabilityVersions.h @@ -87,4 +87,10 @@ #define __MAC_11_0 110000 #endif +// 12.0 SDK + +#ifndef __MAC_12_0 +#define __MAC_12_0 120000 +#endif + #endif // CRASHPAD_COMPAT_MAC_AVAILABILITYVERSIONS_H_ diff --git a/snapshot/mac/process_types/custom.cc b/snapshot/mac/process_types/custom.cc index d80a984b..06c13001 100644 --- a/snapshot/mac/process_types/custom.cc +++ b/snapshot/mac/process_types/custom.cc @@ -147,6 +147,7 @@ size_t dyld_all_image_infos::ExpectedSizeForVersion( std::numeric_limits::max(), // 15, see below offsetof(dyld_all_image_infos, end_v16), // 16 sizeof(dyld_all_image_infos), // 17 + sizeof(dyld_all_image_infos), // 18 }; if (version >= base::size(kSizeForVersion)) { diff --git a/snapshot/mac/process_types/dyld_images.proctype b/snapshot/mac/process_types/dyld_images.proctype index 589ad097..5c57a26f 100644 --- a/snapshot/mac/process_types/dyld_images.proctype +++ b/snapshot/mac/process_types/dyld_images.proctype @@ -127,12 +127,16 @@ PROCESS_TYPE_STRUCT_BEGIN(dyld_all_image_infos) // preceding the padding in the 32-bit structure that would natively be // addressed at index 4 of |reserved|. Treat reserved_4_32 as only available // in version 16 of the structure. + // In the 12.0 SDK, 2 of the trailing UIntPtrs on 64-bit and + // 4 of them on 32-bit were replaced by two uint64_ts. On 32-bit, that + // awkwardly straddles end_v14. Since macOS 12.0 is 64-bit only, the proctype + // version of this struct only has these uint64_ts in the 64-bit version. PROCESS_TYPE_STRUCT_MEMBER(UIntPtr, reserved, [4]) PROCESS_TYPE_STRUCT_MEMBER(Reserved64_64Only, reserved_4_64) PROCESS_TYPE_STRUCT_MEMBER(Reserved64_64Only, reserved_5) PROCESS_TYPE_STRUCT_MEMBER(Reserved64_64Only, reserved_6) - PROCESS_TYPE_STRUCT_MEMBER(Reserved64_64Only, reserved_7) - PROCESS_TYPE_STRUCT_MEMBER(Reserved64_64Only, reserved_8) + PROCESS_TYPE_STRUCT_MEMBER(Reserved64_64Only, shared_cache_fs_id) + PROCESS_TYPE_STRUCT_MEMBER(Reserved64_64Only, shared_cache_fs_obj_id) PROCESS_TYPE_STRUCT_MEMBER(Nothing, end_v14) PROCESS_TYPE_STRUCT_MEMBER(Reserved32_32Only, reserved_4_32) diff --git a/snapshot/mac/process_types_test.cc b/snapshot/mac/process_types_test.cc index e0c3c9cb..90f5c1f6 100644 --- a/snapshot/mac/process_types_test.cc +++ b/snapshot/mac/process_types_test.cc @@ -356,8 +356,16 @@ TEST(ProcessTypes, DyldImagesSelf) { self_image_infos->reserved[4]); EXPECT_EQ(proctype_image_infos.reserved_5, self_image_infos->reserved[5]); EXPECT_EQ(proctype_image_infos.reserved_6, self_image_infos->reserved[6]); - EXPECT_EQ(proctype_image_infos.reserved_7, self_image_infos->reserved[7]); - EXPECT_EQ(proctype_image_infos.reserved_8, self_image_infos->reserved[8]); +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_12_0 + uint64_t shared_cache_fs_id = self_image_infos->sharedCacheFSID; + uint64_t shared_cache_fs_obj_id = self_image_infos->sharedCacheFSObjID; +#else + uint64_t shared_cache_fs_id = self_image_infos->reserved[7]; + uint64_t shared_cache_fs_obj_id = self_image_infos->reserved[8]; +#endif + EXPECT_EQ(proctype_image_infos.shared_cache_fs_id, shared_cache_fs_id); + EXPECT_EQ(proctype_image_infos.shared_cache_fs_obj_id, + shared_cache_fs_obj_id); #endif } #endif