From 64b8791f4523bbae346b35bd5bf34b80f4431e49 Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Tue, 21 Apr 2020 11:59:44 -0400 Subject: [PATCH] ios: Build util/mach/exc_server_variants.cc, support code, and tests This makes UniversalMachExcServer available on iOS. UniversalMachExcServer is the foundation for a Mach exc and mach_exc server. Some code in UniversalMachExcServer needs to be evaluated to ensure that portions that run in the same process that has sustained the exception are safe to do so at that time. For example, SimplifiedExcServer::Interface instantiates and appends to a std::vector<>, which is generally unsafe in this context. However, that code responds to exc requests. The mach_exc equivalent, SimplifiedMachExcServer::Interface, does not use a vector at all. This also enables support code in the form of CompositeMachMessageServer and UniversalExceptionRaise, all of the tests for CompositeMachMessageServer, and most of the test for exc_server_variants.cc. The multiprocess-based exc_server_variants tests remain disabled on iOS. Bug: crashpad:31 Change-Id: I838ed770a33ca29c37383c32245eb340fb3ad2fb Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2159287 Reviewed-by: Justin Cohen Commit-Queue: Mark Mentovai --- util/BUILD.gn | 16 ++++++++-------- util/mach/exc_server_variants.cc | 3 ++- util/mach/exc_server_variants_test.cc | 14 +++++++++++++- util/mach/mach_extensions.cc | 4 ++-- util/mach/mach_extensions_test.cc | 4 ++-- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/util/BUILD.gn b/util/BUILD.gn index d7c1b132..c924b93e 100644 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -288,6 +288,12 @@ static_library("util") { sources += [ "mac/xattr.cc", "mac/xattr.h", + "mach/composite_mach_message_server.cc", + "mach/composite_mach_message_server.h", + "mach/exc_client_variants.cc", + "mach/exc_client_variants.h", + "mach/exc_server_variants.cc", + "mach/exc_server_variants.h", "mach/exception_behaviors.cc", "mach/exception_behaviors.h", "mach/exception_ports.cc", @@ -320,12 +326,6 @@ static_library("util") { "mach/child_port_server.cc", "mach/child_port_server.h", "mach/child_port_types.h", - "mach/composite_mach_message_server.cc", - "mach/composite_mach_message_server.h", - "mach/exc_client_variants.cc", - "mach/exc_client_variants.h", - "mach/exc_server_variants.cc", - "mach/exc_server_variants.h", "mach/exception_types.cc", "mach/exception_types.h", "mach/notify_server.cc", @@ -704,6 +704,8 @@ source_set("util_test") { if (crashpad_is_mac || crashpad_is_ios) { sources += [ "mac/xattr_test.cc", + "mach/composite_mach_message_server_test.cc", + "mach/exc_server_variants_test.cc", "mach/exception_behaviors_test.cc", "mach/mach_extensions_test.cc", "mach/mach_message_test.cc", @@ -718,9 +720,7 @@ source_set("util_test") { "mach/bootstrap_test.cc", "mach/child_port_handshake_test.cc", "mach/child_port_server_test.cc", - "mach/composite_mach_message_server_test.cc", "mach/exc_client_variants_test.cc", - "mach/exc_server_variants_test.cc", "mach/exception_ports_test.cc", "mach/exception_types_test.cc", "mach/mach_message_server_test.cc", diff --git a/util/mach/exc_server_variants.cc b/util/mach/exc_server_variants.cc index 6264cb33..c272ae72 100644 --- a/util/mach/exc_server_variants.cc +++ b/util/mach/exc_server_variants.cc @@ -22,6 +22,7 @@ #include "base/logging.h" #include "base/stl_util.h" +#include "build/build_config.h" #include "util/mac/mac_util.h" #include "util/mach/composite_mach_message_server.h" #include "util/mach/exc.h" @@ -682,7 +683,7 @@ kern_return_t ExcServerSuccessfulReturnValue(exception_type_t exception, exception_behavior_t behavior, bool set_thread_state) { if (exception == EXC_CRASH -#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11 +#if !defined(OS_IOS) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11 && MacOSXMinorVersion() >= 11 #endif ) { diff --git a/util/mach/exc_server_variants_test.cc b/util/mach/exc_server_variants_test.cc index 078d4aed..bea3d767 100644 --- a/util/mach/exc_server_variants_test.cc +++ b/util/mach/exc_server_variants_test.cc @@ -25,13 +25,16 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" #include "test/mac/mach_errors.h" -#include "test/mac/mach_multiprocess.h" #include "util/mac/mac_util.h" #include "util/mach/exception_behaviors.h" #include "util/mach/exception_types.h" #include "util/mach/mach_message.h" #include "util/misc/implicit_cast.h" +#if !defined(OS_IOS) +#include "test/mac/mach_multiprocess.h" +#endif // !OS_IOS + namespace crashpad { namespace test { namespace { @@ -958,6 +961,8 @@ TEST(ExcServerVariants, MachMessageServerRequestIDs) { expect_request_ids); } +#if !defined(OS_IOS) + class TestExcServerVariants : public MachMultiprocess, public UniversalMachExcServer::Interface { public: @@ -1193,9 +1198,16 @@ TEST(ExcServerVariants, ThreadStates) { } } +#endif // !OS_IOS + TEST(ExcServerVariants, ExcServerSuccessfulReturnValue) { +#if defined(OS_IOS) + // iOS 9 ≅ OS X 10.11. + const kern_return_t prefer_not_set_thread_state = KERN_SUCCESS; +#else const kern_return_t prefer_not_set_thread_state = MacOSXMinorVersion() < 11 ? MACH_RCV_PORT_DIED : KERN_SUCCESS; +#endif const struct { exception_type_t exception; diff --git a/util/mach/mach_extensions.cc b/util/mach/mach_extensions.cc index 9e310120..cefb9bf3 100644 --- a/util/mach/mach_extensions.cc +++ b/util/mach/mach_extensions.cc @@ -46,7 +46,7 @@ exception_mask_t ExcMaskAll() { // xnu-2422.110.17/osfmk/mach/ipc_tt.c. #if defined(OS_IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0 -// iOS 7 ≅ macOS 10.9. +// iOS 7 ≅ OS X 10.9. #error This code was not ported to iOS versions older than 7 #endif @@ -93,7 +93,7 @@ exception_mask_t ExcMaskAll() { exception_mask_t ExcMaskValid() { const exception_mask_t kExcMaskValid_10_6 = ExcMaskAll() | EXC_MASK_CRASH; #if defined(OS_IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0 -// iOS 9 ≅ macOS 10.11. +// iOS 9 ≅ OS X 10.11. #error This code was not ported to iOS versions older than 9 #endif diff --git a/util/mach/mach_extensions_test.cc b/util/mach/mach_extensions_test.cc index 748e0aa5..9fd49402 100644 --- a/util/mach/mach_extensions_test.cc +++ b/util/mach/mach_extensions_test.cc @@ -81,7 +81,7 @@ TEST(MachExtensions, ExcMaskAll) { EXPECT_FALSE(exc_mask_all & EXC_MASK_CORPSE_NOTIFY); #if defined(OS_IOS) - // Assume at least iOS 7 (≅ macOS 10.9). + // Assume at least iOS 7 (≅ OS X 10.9). EXPECT_TRUE(exc_mask_all & EXC_MASK_RESOURCE); EXPECT_TRUE(exc_mask_all & EXC_MASK_GUARD); #else // OS_IOS @@ -113,7 +113,7 @@ TEST(MachExtensions, ExcMaskValid) { EXPECT_TRUE(exc_mask_valid & EXC_MASK_CRASH); #if defined(OS_IOS) - // Assume at least iOS 9 (≅ macOS 10.11). + // Assume at least iOS 9 (≅ OS X 10.11). EXPECT_TRUE(exc_mask_valid & EXC_MASK_RESOURCE); EXPECT_TRUE(exc_mask_valid & EXC_MASK_GUARD); EXPECT_TRUE(exc_mask_valid & EXC_MASK_CORPSE_NOTIFY);