From 4773a37f0a95fbbfbd6e7698ee5dc1a1371f6e2f Mon Sep 17 00:00:00 2001 From: avvall Date: Tue, 4 Apr 2023 17:02:57 +0000 Subject: [PATCH 001/107] Crashpad: Adding PAC bit stripping to stack sanitization. Pointer Authentication works by adding a signature to the top bits of an instruction or data pointer (only instruction pointers on the stack are currently signed in Chromium). This can confuse range checks, because they need to strip the top bits. Masking these bits during sanitization range checks prevents confusion. Test: Testing was done manually on a device with pointer authentication enabled. Bug: crashpad:364 Bug: 919548 Change-Id: I2e739cadb2844cfaf73a75596d664135aeb5faac Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4387271 Commit-Queue: Adam Walls Reviewed-by: Joshua Peraza Reviewed-by: Ben Hamilton --- .../sanitized/memory_snapshot_sanitized.cc | 7 +++- .../sanitized/process_snapshot_sanitized.cc | 4 +- util/BUILD.gn | 2 + util/linux/pac_helper.cc | 38 +++++++++++++++++++ util/linux/pac_helper.h | 29 ++++++++++++++ 5 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 util/linux/pac_helper.cc create mode 100644 util/linux/pac_helper.h diff --git a/snapshot/sanitized/memory_snapshot_sanitized.cc b/snapshot/sanitized/memory_snapshot_sanitized.cc index b4f9ba42..58bcdde4 100644 --- a/snapshot/sanitized/memory_snapshot_sanitized.cc +++ b/snapshot/sanitized/memory_snapshot_sanitized.cc @@ -16,6 +16,8 @@ #include +#include "util/linux/pac_helper.h" + namespace crashpad { namespace internal { @@ -62,8 +64,9 @@ class MemorySanitizer : public MemorySnapshot::Delegate { auto words = reinterpret_cast(static_cast(data) + aligned_offset); for (size_t index = 0; index < word_count; ++index) { - if (words[index] > MemorySnapshotSanitized::kSmallWordMax && - !ranges_->Contains(words[index])) { + auto word = StripPACBits(words[index]); + if (word > MemorySnapshotSanitized::kSmallWordMax && + !ranges_->Contains(word)) { words[index] = defaced; } } diff --git a/snapshot/sanitized/process_snapshot_sanitized.cc b/snapshot/sanitized/process_snapshot_sanitized.cc index 1e003706..afa1c9f8 100644 --- a/snapshot/sanitized/process_snapshot_sanitized.cc +++ b/snapshot/sanitized/process_snapshot_sanitized.cc @@ -17,6 +17,7 @@ #include #include "snapshot/cpu_context.h" +#include "util/linux/pac_helper.h" #include "util/numeric/safe_assignment.h" namespace crashpad { @@ -61,7 +62,8 @@ class StackReferencesAddressRange : public MemorySnapshot::Delegate { aligned_sp_offset); size_t word_count = (size - aligned_sp_offset) / sizeof(Pointer); for (size_t index = 0; index < word_count; ++index) { - if (words[index] >= low_ && words[index] < high_) { + auto word = StripPACBits(words[index]); + if (word >= low_ && word < high_) { return true; } } diff --git a/util/BUILD.gn b/util/BUILD.gn index b84a251a..4a828a6a 100644 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -432,6 +432,8 @@ crashpad_static_library("util") { "linux/exception_information.h", "linux/memory_map.cc", "linux/memory_map.h", + "linux/pac_helper.cc", + "linux/pac_helper.h", "linux/proc_stat_reader.cc", "linux/proc_stat_reader.h", "linux/proc_task_reader.cc", diff --git a/util/linux/pac_helper.cc b/util/linux/pac_helper.cc new file mode 100644 index 00000000..742d366e --- /dev/null +++ b/util/linux/pac_helper.cc @@ -0,0 +1,38 @@ +// Copyright 2023 The Crashpad Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "util/linux/pac_helper.h" + +#if __has_feature(ptrauth_intrinsics) +#include +#endif + +#include "util/misc/address_types.h" + +namespace crashpad { + +VMAddress StripPACBits(VMAddress address) { +#if __has_feature(ptrauth_intrinsics) + address = ptrauth_strip(address, ptrauth_key_function_pointer); +#elif defined(ARCH_CPU_ARM64) + // Strip any pointer authentication bits that are assigned to the address. + register uintptr_t x30 __asm("x30") = address; + asm("xpaclri" : "+r"(x30)); + address = x30; +#endif + return address; +} + +} // namespace crashpad + diff --git a/util/linux/pac_helper.h b/util/linux/pac_helper.h new file mode 100644 index 00000000..6fcea652 --- /dev/null +++ b/util/linux/pac_helper.h @@ -0,0 +1,29 @@ +// Copyright 2023 The Crashpad Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef CRASHPAD_UTIL_LINUX_PAC_HELPER_H_ +#define CRASHPAD_UTIL_LINUX_PAC_HELPER_H_ + +#include "util/misc/address_types.h" + +namespace crashpad { + +//! \brief Strips PAC bits from an address +VMAddress StripPACBits(VMAddress address); + +} // namespace crashpad + + +#endif // CRASHPAD_UTIL_LINUX_PAC_HELPER_H_ + From ada8dfa4a7eab70755cc5210026f23e394358d13 Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Mon, 10 Apr 2023 14:19:23 -0400 Subject: [PATCH 002/107] ios: Always reset IOSIntermediateDumpWriter file descriptor on close. Always reset the file descriptor to -1, even if FlushWriteBuffer or RawLoggingCloseFile fails. Bug: 1431760 Change-Id: I193f526d65f477bba002dd9faf68996020e48a3b Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4406657 Reviewed-by: Ben Hamilton Commit-Queue: Justin Cohen Reviewed-by: Robert Sesek --- util/ios/ios_intermediate_dump_writer.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/util/ios/ios_intermediate_dump_writer.cc b/util/ios/ios_intermediate_dump_writer.cc index bccd1539..c180fc08 100644 --- a/util/ios/ios_intermediate_dump_writer.cc +++ b/util/ios/ios_intermediate_dump_writer.cc @@ -83,12 +83,10 @@ bool IOSIntermediateDumpWriter::Close() { if (fd_ < 0) { return true; } - if (!FlushWriteBuffer()) { - return false; - } - int fd = fd_; + const bool flushed = FlushWriteBuffer(); + const bool closed = RawLoggingCloseFile(fd_); fd_ = -1; - return RawLoggingCloseFile(fd); + return flushed && closed; } bool IOSIntermediateDumpWriter::AddPropertyCString(IntermediateDumpKey key, From 0e3758bef69ab6aa77019acaad60278a1f380252 Mon Sep 17 00:00:00 2001 From: Stephan Hartmann Date: Wed, 12 Apr 2023 17:39:38 +0200 Subject: [PATCH 003/107] pac_helper: test for __has_feature macro __has_feature is a clang extension. GCC errors out on the test. Define a helper macro to make the code working with other compilers. Bug: chromium:819294 Change-Id: I359150acd4700e65b4faf5f297b29664c18000d3 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4418706 Reviewed-by: Joshua Peraza Commit-Queue: Joshua Peraza Reviewed-by: Ben Hamilton --- util/linux/pac_helper.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/util/linux/pac_helper.cc b/util/linux/pac_helper.cc index 742d366e..a9d5f045 100644 --- a/util/linux/pac_helper.cc +++ b/util/linux/pac_helper.cc @@ -14,8 +14,14 @@ #include "util/linux/pac_helper.h" -#if __has_feature(ptrauth_intrinsics) -#include +#if defined(__has_feature) +#define CRASHPAD_HAS_FEATURE(x) __has_feature(x) +#else +#define CRASHPAD_HAS_FEATURE(x) 0 +#endif + +#if CRASHPAD_HAS_FEATURE(ptrauth_intrinsics) + #include #endif #include "util/misc/address_types.h" @@ -23,7 +29,7 @@ namespace crashpad { VMAddress StripPACBits(VMAddress address) { -#if __has_feature(ptrauth_intrinsics) +#if CRASHPAD_HAS_FEATURE(ptrauth_intrinsics) address = ptrauth_strip(address, ptrauth_key_function_pointer); #elif defined(ARCH_CPU_ARM64) // Strip any pointer authentication bits that are assigned to the address. From 3a6bc8c527ede01d82d7c9bd7c08687f7a924de7 Mon Sep 17 00:00:00 2001 From: Zequan Wu Date: Fri, 21 Apr 2023 13:26:17 -0400 Subject: [PATCH 004/107] [tests] Disable clang optimization on the infinite recursion function. In the recent llvm upstream change, https://reviews.llvm.org/D148269, clang becomes smarter and will remove the infinite recursion function. Use the clang attribute __attribute__((optnone)) to disable optimization for it. Bug: chromium:1435016 Change-Id: I74e823bf64d0b03d81c0bda7a8338e2fa67033aa Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4456156 Reviewed-by: Mark Mentovai Commit-Queue: Zequan Wu --- client/crashpad_client_linux_test.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/crashpad_client_linux_test.cc b/client/crashpad_client_linux_test.cc index 08418487..9b207db3 100644 --- a/client/crashpad_client_linux_test.cc +++ b/client/crashpad_client_linux_test.cc @@ -225,6 +225,9 @@ void ValidateDump(const StartHandlerForSelfTestOptions& options, #if defined(COMPILER_GCC) __attribute__((noinline)) #endif +#if defined(__clang__) +__attribute__((optnone)) +#endif int RecurseInfinitely(int* ptr) { int buf[1 << 20]; return *ptr + RecurseInfinitely(buf); From 07827d9807c7217efdb97ced845c5bad66b23650 Mon Sep 17 00:00:00 2001 From: Ho Cheung Date: Tue, 25 Apr 2023 23:33:34 +0800 Subject: [PATCH 005/107] Remove `base/cxx17_backports.h` from the code in third_patry/crashpad Remove the reference to `base/cxx17_backports.h` from the code. Bug: chromium:1373621 Change-Id: I84dd5fc1b069b168e4558316344c1f1c5377a68b Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4471860 Commit-Queue: Mark Mentovai Reviewed-by: Mark Mentovai --- AUTHORS | 1 + client/ios_handler/in_process_handler.cc | 1 - snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc | 3 ++- snapshot/minidump/thread_snapshot_minidump.cc | 3 ++- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index 02103924..e797d3db 100644 --- a/AUTHORS +++ b/AUTHORS @@ -13,3 +13,4 @@ Vewd Software AS LG Electronics, Inc. MIPS Technologies, Inc. Darshan Sen +Ho Cheung diff --git a/client/ios_handler/in_process_handler.cc b/client/ios_handler/in_process_handler.cc index 4dd032f0..668acc66 100644 --- a/client/ios_handler/in_process_handler.cc +++ b/client/ios_handler/in_process_handler.cc @@ -19,7 +19,6 @@ #include -#include "base/cxx17_backports.h" #include "base/logging.h" #include "client/ios_handler/in_process_intermediate_dump_handler.h" #include "client/prune_crash_reports.h" diff --git a/snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc b/snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc index 21c71bbe..6d64b1d0 100644 --- a/snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc +++ b/snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc @@ -16,7 +16,8 @@ #include -#include "base/cxx17_backports.h" +#include + #include "base/files/scoped_file.h" #include "base/posix/eintr_wrapper.h" #include "build/build_config.h" diff --git a/snapshot/minidump/thread_snapshot_minidump.cc b/snapshot/minidump/thread_snapshot_minidump.cc index babf4c63..10e8f485 100644 --- a/snapshot/minidump/thread_snapshot_minidump.cc +++ b/snapshot/minidump/thread_snapshot_minidump.cc @@ -17,7 +17,8 @@ #include #include -#include "base/cxx17_backports.h" +#include + #include "minidump/minidump_context.h" namespace crashpad { From a280d65971c2e5e2b59a5c2cb02a2c2374fa1de1 Mon Sep 17 00:00:00 2001 From: Thomas Gales Date: Fri, 5 May 2023 22:13:31 +0000 Subject: [PATCH 006/107] Update linux-syscall-support (LSS) version Newer versions of LSS include support for RISC-V. Fixed: fuchsia:125946 Change-Id: Iab65174e9a5f2a7075faadd34dc54b0c23ce3da4 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4510030 Reviewed-by: Joshua Peraza --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index 0ef3c1f4..c9bbe880 100644 --- a/DEPS +++ b/DEPS @@ -44,7 +44,7 @@ deps = { 'af29db7ec28d6df1c7f0f745186884091e602e07', 'crashpad/third_party/lss/lss': Var('chromium_git') + '/linux-syscall-support.git@' + - 'e1e7b0ad8ee99a875b272c8e33e308472e897660', + '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + '4332ddb6963750e1106efdcece6d6e2de6dc6430', From 3307c7cefcc21cffecafa7fde90832fc9dde008a Mon Sep 17 00:00:00 2001 From: Thomas Gales Date: Fri, 5 May 2023 21:11:35 +0000 Subject: [PATCH 007/107] Fix ASan failures for MinidumpCrashpadInfoWriter Fuchsia AddressSanitizer tests were failing because of unaligned memory access in several unit tests. Fixed: fuchsia:125877 Change-Id: If577ea9b7be24ef40865a637d8f6b6d94daaeb67 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4510016 Reviewed-by: Joshua Peraza --- .../minidump_crashpad_info_writer_test.cc | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/minidump/minidump_crashpad_info_writer_test.cc b/minidump/minidump_crashpad_info_writer_test.cc index 39c791c2..d01655d8 100644 --- a/minidump/minidump_crashpad_info_writer_test.cc +++ b/minidump/minidump_crashpad_info_writer_test.cc @@ -148,8 +148,17 @@ TEST(MinidumpCrashpadInfoWriter, AddressMask) { ASSERT_TRUE(empty_client_id.InitializeFromString( "00000000-0000-0000-0000-000000000000")); + // Copy address_mask into a local variable because + // |MinidumpCrashpadInfo::address_mask| requires 8-byte alignment but the + // struct itself is 4-byte aligned. + const auto address_mask = [&crashpad_info] { + uint64_t data = 0; + memcpy(&data, &crashpad_info->address_mask, sizeof(data)); + return data; + }(); + EXPECT_EQ(crashpad_info->version, MinidumpCrashpadInfo::kVersion); - EXPECT_EQ(crashpad_info->address_mask, mask); + EXPECT_EQ(address_mask, mask); EXPECT_EQ(crashpad_info->report_id, empty_report_id); EXPECT_EQ(crashpad_info->client_id, empty_client_id); EXPECT_FALSE(simple_annotations); @@ -172,7 +181,16 @@ TEST(MinidumpCrashpadInfoWriter, EmptyAddressMask) { ASSERT_NO_FATAL_FAILURE(GetCrashpadInfoStream( string_file.string(), &crashpad_info, &simple_annotations, &module_list)); - EXPECT_EQ(crashpad_info->address_mask, 0UL); + // Copy address_mask into a local variable because + // |MinidumpCrashpadInfo::address_mask| requires 8-byte alignment but the + // struct itself is 4-byte aligned. + const auto address_mask = [&crashpad_info] { + uint64_t data = 0; + memcpy(&data, &crashpad_info->address_mask, sizeof(data)); + return data; + }(); + + EXPECT_EQ(address_mask, 0UL); } TEST(MinidumpCrashpadInfoWriter, SimpleAnnotations) { From 8525d5384ed244dda917df1a1799df52960a8258 Mon Sep 17 00:00:00 2001 From: Thomas Gales Date: Wed, 17 May 2023 14:28:25 +0000 Subject: [PATCH 008/107] Fix broken doc links Links to/from run_with_crashpad.md were broken due to a location change. Change-Id: I5bb6d1f945bd22d9e55affa60909aa3b58e532bc Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4544457 Reviewed-by: Mark Mentovai --- doc/appengine/src/crashpad-home/main.go | 2 +- doc/man.md | 2 +- handler/crashpad_handler.md | 4 ++-- tools/run_with_crashpad.md | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/appengine/src/crashpad-home/main.go b/doc/appengine/src/crashpad-home/main.go index 1af2125e..d988af3c 100644 --- a/doc/appengine/src/crashpad-home/main.go +++ b/doc/appengine/src/crashpad-home/main.go @@ -63,7 +63,7 @@ func handler(w http.ResponseWriter, r *http.Request) { "/man/generate_dump.html": mainBaseURL + "tools/generate_dump.md", "/man/index.html": mainBaseURL + "doc/man.md", "/man/on_demand_service_tool.html": mainBaseURL + "tools/mac/on_demand_service_tool.md", - "/man/run_with_crashpad.html": mainBaseURL + "tools/mac/run_with_crashpad.md", + "/man/run_with_crashpad.html": mainBaseURL + "tools/run_with_crashpad.md", } ctx := appengine.NewContext(r) diff --git a/doc/man.md b/doc/man.md index 7789a014..098c8483 100644 --- a/doc/man.md +++ b/doc/man.md @@ -27,7 +27,7 @@ limitations under the License. * [catch_exception_tool](../tools/mac/catch_exception_tool.md) * [exception_port_tool](../tools/mac/exception_port_tool.md) * [on_demand_service_tool](../tools/mac/on_demand_service_tool.md) - * [run_with_crashpad](../tools/mac/run_with_crashpad.md) + * [run_with_crashpad](../tools/run_with_crashpad.md) ## Section 8: Dӕmons diff --git a/handler/crashpad_handler.md b/handler/crashpad_handler.md index 324957de..3e722bad 100644 --- a/handler/crashpad_handler.md +++ b/handler/crashpad_handler.md @@ -83,7 +83,7 @@ closed. It is not normally appropriate to invoke this program directly. Usually, it will be invoked by a Crashpad client using the Crashpad client library, or started by another system service. On macOS, arbitrary programs may be run with a Crashpad -handler by using [run_with_crashpad(1)](../tools/mac/run_with_crashpad.md) to +handler by using [run_with_crashpad(1)](../tools/run_with_crashpad.md) to establish the Crashpad client environment before running a program. ## Options @@ -321,7 +321,7 @@ establish the Crashpad client environment before running a program. [catch_exception_tool(1)](../tools/mac/catch_exception_tool.md), [crashpad_database_util(1)](../tools/crashpad_database_util.md), [generate_dump(1)](../tools/generate_dump.md), -[run_with_crashpad(1)](../tools/mac/run_with_crashpad.md) +[run_with_crashpad(1)](../tools/run_with_crashpad.md) ## Resources diff --git a/tools/run_with_crashpad.md b/tools/run_with_crashpad.md index 7210c1d4..69302eef 100644 --- a/tools/run_with_crashpad.md +++ b/tools/run_with_crashpad.md @@ -27,7 +27,7 @@ run_with_crashpad—Run a program with a Crashpad exception handler ## Description Starts a Crashpad exception handler server such as -[crashpad_handler(8)](../../handler/crashpad_handler.md) and becomes its client, +[crashpad_handler(8)](../handler/crashpad_handler.md) and becomes its client, setting an exception port referencing the handler. Then, executes _COMMAND_ along with any arguments specified (_ARG…_) with the new exception port in effect. @@ -88,7 +88,7 @@ Illegal instruction: 4 ``` Starts a Crashpad exception handler server at a nonstandard path, and runs -[exception_port_tool(1)](exception_port_tool.md) to show the task-level +[exception_port_tool(1)](mac/exception_port_tool.md) to show the task-level exception ports. ``` @@ -118,8 +118,8 @@ task exception port 0, mask 0x1c00 (CRASH|RESOURCE|GUARD), port 0x30b, behavior ## See Also -[crashpad_handler(8)](../../handler/crashpad_handler.md), -[exception_port_tool(1)](exception_port_tool.md) +[crashpad_handler(8)](../handler/crashpad_handler.md), +[exception_port_tool(1)](mac/exception_port_tool.md) ## Resources From 1103dfc65def733ed50ed1a4471c263c3ab11b28 Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Fri, 19 May 2023 23:55:11 -0400 Subject: [PATCH 009/107] ios: Add fallbacks to try_free_default and claimed_address in forbidden allocators. This test only change should improve flake on iOS XCUITests. try_free_default can receive a pointer which doesn't belong to the allocator and claimed_address may not be implemented in specified zone. Add fallbacks for both. This logic is identical to the Chromium equivalent shim in base/allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_mac_zoned_malloc.cc Bug:b/270620301 Change-Id: I4a788d4fbc7b324caff18e41618a5f999b4b8d4e Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4549684 Reviewed-by: Mark Mentovai --- test/ios/host/handler_forbidden_allocators.cc | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/test/ios/host/handler_forbidden_allocators.cc b/test/ios/host/handler_forbidden_allocators.cc index 34e93e3a..38f1c383 100644 --- a/test/ios/host/handler_forbidden_allocators.cc +++ b/test/ios/host/handler_forbidden_allocators.cc @@ -151,10 +151,46 @@ boolean_t handler_forbidden_claimed_address(struct _malloc_zone_t* zone, "handler_forbidden_claimed_address allocator used in handler."); exit(EXIT_FAILURE); } - return g_old_zone.claimed_address(zone, ptr); + + if (g_old_zone.claimed_address) { + return g_old_zone.claimed_address(zone, ptr); + } + + // If the fast API 'claimed_address' is not implemented in the specified zone, + // fall back to 'size' function, which also tells whether the given address + // belongs to the zone or not although it'd be slow. + return g_old_zone.size(zone, ptr); } #if defined(__IPHONE_16_1) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_16_1 +// The fallback function to be called when try_free_default_function receives a +// pointer which doesn't belong to the allocator. +void TryFreeDefaultFallbackToFindZoneAndFree(void* ptr) { + unsigned int zone_count = 0; + vm_address_t* zones = nullptr; + kern_return_t result = + malloc_get_all_zones(mach_task_self(), nullptr, &zones, &zone_count); + MACH_CHECK(result == KERN_SUCCESS, result) << "malloc_get_all_zones"; + + // "find_zone_and_free" expected by try_free_default. + // + // libmalloc's zones call find_registered_zone() in case the default one + // doesn't handle the allocation. We can't, so we try to emulate it. See the + // implementation in libmalloc/src/malloc.c for details. + // https://github.com/apple-oss-distributions/libmalloc/blob/main/src/malloc.c + for (unsigned int i = 0; i < zone_count; ++i) { + malloc_zone_t* zone = reinterpret_cast(zones[i]); + if (size_t size = zone->size(zone, ptr)) { + if (zone->version >= 6 && zone->free_definite_size) { + zone->free_definite_size(zone, ptr, size); + } else { + zone->free(zone, ptr); + } + return; + } + } +} + void handler_forbidden_try_free_default(struct _malloc_zone_t* zone, void* ptr) { if (is_handler_thread()) { @@ -162,7 +198,11 @@ void handler_forbidden_try_free_default(struct _malloc_zone_t* zone, "handler_forbidden_try_free_default allocator used in handler."); exit(EXIT_FAILURE); } - g_old_zone.try_free_default(zone, ptr); + + if (g_old_zone.try_free_default) { + return g_old_zone.try_free_default(zone, ptr); + } + TryFreeDefaultFallbackToFindZoneAndFree(ptr); } #endif From 402d43192adc90b5bef3dabddb62655c7346533e Mon Sep 17 00:00:00 2001 From: Thomas Gales Date: Wed, 24 May 2023 18:00:27 +0000 Subject: [PATCH 010/107] Update mini_chromium Update to a version of mini_chromium that supports RISCV64. Bug: fuchsia:127655 Tested: `python build/run_tests.py` for Linux target Change-Id: I872e5e79933eb8f9b9fe7f4ae243ee9bb04c14b0 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4563254 Reviewed-by: Mark Mentovai --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index c9bbe880..95d01aa9 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - '4332ddb6963750e1106efdcece6d6e2de6dc6430', + 'f0eebea8bd59215be300ffbe5e7883e85a6fdc0e', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', From 1fdbd3736ca4fb523b5bd6fc9a663ac5cf8f6de4 Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Tue, 30 May 2023 18:22:53 -0400 Subject: [PATCH 011/107] ios: More deflaking handler forbidden allocators. - Stop overloading introspect (or implement this in the future) - Store each overridden allocation zone and correctly direct calls to the requested zone. Change-Id: I7294e476bb683149acc61419b095ec0e1098781b Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4574037 Reviewed-by: Joshua Peraza --- test/ios/host/handler_forbidden_allocators.cc | 74 +++++++++++++------ 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/test/ios/host/handler_forbidden_allocators.cc b/test/ios/host/handler_forbidden_allocators.cc index 38f1c383..6d41b8dc 100644 --- a/test/ios/host/handler_forbidden_allocators.cc +++ b/test/ios/host/handler_forbidden_allocators.cc @@ -30,7 +30,25 @@ namespace { uint64_t g_main_thread = 0; uint64_t g_mach_exception_thread = 0; -malloc_zone_t g_old_zone; + +// Somewhat simplified logic copied from Chromium's +// base/allocator/partition_allocator/shim/malloc_zone_functions_mac.h. The +// arrays g_original_zones and g_original_zones_ptr stores all information about +// malloc zones before they are shimmed. This information needs to be accessed +// during dispatch back into the zone. +constexpr int kMaxZoneCount = 30; +malloc_zone_t g_original_zones[kMaxZoneCount]; +malloc_zone_t* g_original_zones_ptr[kMaxZoneCount]; +unsigned int g_zone_count = 0; + +struct _malloc_zone_t original_zone_for_zone(struct _malloc_zone_t* zone) { + for (unsigned int i = 0; i < g_zone_count; ++i) { + if (g_original_zones_ptr[i] == zone) { + return g_original_zones[i]; + } + } + return g_original_zones[0]; +} bool is_handler_thread() { uint64_t thread_self; @@ -44,7 +62,7 @@ void* handler_forbidden_malloc(struct _malloc_zone_t* zone, size_t size) { CRASHPAD_RAW_LOG("handler_forbidden_malloc allocator used in handler."); exit(EXIT_FAILURE); } - return g_old_zone.malloc(zone, size); + return original_zone_for_zone(zone).malloc(zone, size); } void* handler_forbidden_calloc(struct _malloc_zone_t* zone, @@ -54,7 +72,7 @@ void* handler_forbidden_calloc(struct _malloc_zone_t* zone, CRASHPAD_RAW_LOG("handler_forbidden_calloc allocator used in handler."); exit(EXIT_FAILURE); } - return g_old_zone.calloc(zone, num_items, size); + return original_zone_for_zone(zone).calloc(zone, num_items, size); } void* handler_forbidden_valloc(struct _malloc_zone_t* zone, size_t size) { @@ -62,7 +80,7 @@ void* handler_forbidden_valloc(struct _malloc_zone_t* zone, size_t size) { CRASHPAD_RAW_LOG("handler_forbidden_valloc allocator used in handler."); exit(EXIT_FAILURE); } - return g_old_zone.valloc(zone, size); + return original_zone_for_zone(zone).valloc(zone, size); } void handler_forbidden_free(struct _malloc_zone_t* zone, void* ptr) { @@ -70,7 +88,7 @@ void handler_forbidden_free(struct _malloc_zone_t* zone, void* ptr) { CRASHPAD_RAW_LOG("handler_forbidden_free allocator used in handler."); exit(EXIT_FAILURE); } - g_old_zone.free(zone, ptr); + original_zone_for_zone(zone).free(zone, ptr); } void* handler_forbidden_realloc(struct _malloc_zone_t* zone, @@ -80,7 +98,7 @@ void* handler_forbidden_realloc(struct _malloc_zone_t* zone, CRASHPAD_RAW_LOG("handler_forbidden_realloc allocator used in handler."); exit(EXIT_FAILURE); } - return g_old_zone.realloc(zone, ptr, size); + return original_zone_for_zone(zone).realloc(zone, ptr, size); } void handler_forbidden_destroy(struct _malloc_zone_t* zone) { @@ -88,7 +106,7 @@ void handler_forbidden_destroy(struct _malloc_zone_t* zone) { CRASHPAD_RAW_LOG("handler_forbidden_destroy allocator used in handler."); exit(EXIT_FAILURE); } - g_old_zone.destroy(zone); + original_zone_for_zone(zone).destroy(zone); } void* handler_forbidden_memalign(struct _malloc_zone_t* zone, @@ -98,7 +116,7 @@ void* handler_forbidden_memalign(struct _malloc_zone_t* zone, CRASHPAD_RAW_LOG("handler_forbidden_memalign allocator used in handler."); exit(EXIT_FAILURE); } - return g_old_zone.memalign(zone, alignment, size); + return original_zone_for_zone(zone).memalign(zone, alignment, size); } unsigned handler_forbidden_batch_malloc(struct _malloc_zone_t* zone, @@ -110,7 +128,8 @@ unsigned handler_forbidden_batch_malloc(struct _malloc_zone_t* zone, "handler_forbidden_batch_malloc allocator used in handler."); exit(EXIT_FAILURE); } - return g_old_zone.batch_malloc(zone, size, results, num_requested); + return original_zone_for_zone(zone).batch_malloc( + zone, size, results, num_requested); } void handler_forbidden_batch_free(struct _malloc_zone_t* zone, @@ -120,7 +139,7 @@ void handler_forbidden_batch_free(struct _malloc_zone_t* zone, CRASHPAD_RAW_LOG("handler_forbidden_batch_free allocator used in handler."); exit(EXIT_FAILURE); } - g_old_zone.batch_free(zone, to_be_freed, num_to_be_freed); + original_zone_for_zone(zone).batch_free(zone, to_be_freed, num_to_be_freed); } void handler_forbidden_free_definite_size(struct _malloc_zone_t* zone, @@ -131,7 +150,7 @@ void handler_forbidden_free_definite_size(struct _malloc_zone_t* zone, "handler_forbidden_free_definite_size allocator used in handler."); exit(EXIT_FAILURE); } - g_old_zone.free_definite_size(zone, ptr, size); + original_zone_for_zone(zone).free_definite_size(zone, ptr, size); } size_t handler_forbidden_pressure_relief(struct _malloc_zone_t* zone, @@ -141,7 +160,7 @@ size_t handler_forbidden_pressure_relief(struct _malloc_zone_t* zone, "handler_forbidden_pressure_relief allocator used in handler."); exit(EXIT_FAILURE); } - return g_old_zone.pressure_relief(zone, goal); + return original_zone_for_zone(zone).pressure_relief(zone, goal); } boolean_t handler_forbidden_claimed_address(struct _malloc_zone_t* zone, @@ -152,14 +171,14 @@ boolean_t handler_forbidden_claimed_address(struct _malloc_zone_t* zone, exit(EXIT_FAILURE); } - if (g_old_zone.claimed_address) { - return g_old_zone.claimed_address(zone, ptr); + if (original_zone_for_zone(zone).claimed_address) { + return original_zone_for_zone(zone).claimed_address(zone, ptr); } // If the fast API 'claimed_address' is not implemented in the specified zone, // fall back to 'size' function, which also tells whether the given address // belongs to the zone or not although it'd be slow. - return g_old_zone.size(zone, ptr); + return original_zone_for_zone(zone).size(zone, ptr); } #if defined(__IPHONE_16_1) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_16_1 @@ -199,8 +218,8 @@ void handler_forbidden_try_free_default(struct _malloc_zone_t* zone, exit(EXIT_FAILURE); } - if (g_old_zone.try_free_default) { - return g_old_zone.try_free_default(zone, ptr); + if (original_zone_for_zone(zone).try_free_default) { + return original_zone_for_zone(zone).try_free_default(zone, ptr); } TryFreeDefaultFallbackToFindZoneAndFree(ptr); } @@ -211,7 +230,7 @@ size_t handler_forbidden_size(struct _malloc_zone_t* zone, const void* ptr) { CRASHPAD_RAW_LOG("handler_forbidden_size allocator used in handler."); exit(EXIT_FAILURE); } - return g_old_zone.size(zone, ptr); + return original_zone_for_zone(zone).size(zone, ptr); } bool DeprotectMallocZone(malloc_zone_t* default_zone, @@ -293,7 +312,6 @@ void ReplaceZoneFunctions(malloc_zone_t* zone, const malloc_zone_t* functions) { zone->destroy = functions->destroy; zone->batch_malloc = functions->batch_malloc; zone->batch_free = functions->batch_free; - zone->introspect = functions->introspect; zone->memalign = functions->memalign; zone->free_definite_size = functions->free_definite_size; zone->pressure_relief = functions->pressure_relief; @@ -326,8 +344,6 @@ void ReplaceAllocatorsWithHandlerForbidden() { CrashpadClient crashpad_client; g_mach_exception_thread = crashpad_client.GetThreadIdForTesting(); - malloc_zone_t* default_zone = malloc_default_zone(); - memcpy(&g_old_zone, default_zone, sizeof(g_old_zone)); malloc_zone_t new_functions = {}; new_functions.size = handler_forbidden_size; new_functions.malloc = handler_forbidden_malloc; @@ -345,8 +361,16 @@ void ReplaceAllocatorsWithHandlerForbidden() { #if defined(__IPHONE_16_1) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_16_1 new_functions.try_free_default = handler_forbidden_try_free_default; #endif + malloc_zone_t* default_zone = malloc_default_zone(); + g_original_zones_ptr[g_zone_count] = default_zone; + ReplaceZoneFunctions(&g_original_zones[g_zone_count++], default_zone); ReplaceZoneFunctions(default_zone, &new_functions); + malloc_zone_t* purgeable_zone = malloc_default_purgeable_zone(); + g_original_zones_ptr[g_zone_count] = purgeable_zone; + ReplaceZoneFunctions(&g_original_zones[g_zone_count++], purgeable_zone); + ReplaceZoneFunctions(purgeable_zone, &new_functions); + vm_address_t* zones; unsigned int count; kern_return_t kr = @@ -355,11 +379,13 @@ void ReplaceAllocatorsWithHandlerForbidden() { return; for (unsigned int i = 0; i < count; ++i) { malloc_zone_t* zone = reinterpret_cast(zones[i]); + g_original_zones_ptr[g_zone_count] = zone; + ReplaceZoneFunctions(&g_original_zones[g_zone_count++], zone); ReplaceZoneFunctions(zone, &new_functions); - } - malloc_zone_t* purgeable_zone = malloc_default_purgeable_zone(); - ReplaceZoneFunctions(purgeable_zone, &new_functions); + if (g_zone_count >= kMaxZoneCount) + break; + } } } // namespace test From 788b72f922bb123cc8c1c38ed75ba643873c8c7b Mon Sep 17 00:00:00 2001 From: Eran Rom Date: Fri, 2 Jun 2023 13:22:52 +0300 Subject: [PATCH 012/107] Remove Mac OS X Server support Mac OS X Server has been discontinued as a separate operating system flavor since 10.6. Current minimal requirements for both Crashpad and Chromium are above that. Change-Id: Ia9063be2e55a48e45d9f9974ac2e51bac004f37d Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4584570 Reviewed-by: Mark Mentovai --- snapshot/mac/system_snapshot_mac.cc | 4 +--- snapshot/mac/system_snapshot_mac.h | 1 - util/mac/mac_util.cc | 31 ++++++++--------------------- util/mac/mac_util.h | 1 - util/mac/mac_util_test.mm | 10 ++++------ 5 files changed, 13 insertions(+), 34 deletions(-) diff --git a/snapshot/mac/system_snapshot_mac.cc b/snapshot/mac/system_snapshot_mac.cc index 3b17252d..334627ff 100644 --- a/snapshot/mac/system_snapshot_mac.cc +++ b/snapshot/mac/system_snapshot_mac.cc @@ -86,7 +86,6 @@ SystemSnapshotMac::SystemSnapshotMac() os_version_major_(0), os_version_minor_(0), os_version_bugfix_(0), - os_server_(false), initialized_() { } @@ -107,7 +106,6 @@ void SystemSnapshotMac::Initialize(ProcessReaderMac* process_reader, &os_version_minor_, &os_version_bugfix_, &os_version_build_, - &os_server_, &os_version_string); std::string uname_string; @@ -304,7 +302,7 @@ SystemSnapshot::OperatingSystem SystemSnapshotMac::GetOperatingSystem() const { bool SystemSnapshotMac::OSServer() const { INITIALIZATION_STATE_DCHECK_VALID(initialized_); - return os_server_; + return false; } void SystemSnapshotMac::OSVersion(int* major, diff --git a/snapshot/mac/system_snapshot_mac.h b/snapshot/mac/system_snapshot_mac.h index cf8fbbe9..275ae5fe 100644 --- a/snapshot/mac/system_snapshot_mac.h +++ b/snapshot/mac/system_snapshot_mac.h @@ -93,7 +93,6 @@ class SystemSnapshotMac final : public SystemSnapshot { int os_version_major_; int os_version_minor_; int os_version_bugfix_; - bool os_server_; InitializationStateDcheck initialized_; }; diff --git a/util/mac/mac_util.cc b/util/mac/mac_util.cc index a1382343..ed2bfb73 100644 --- a/util/mac/mac_util.cc +++ b/util/mac/mac_util.cc @@ -45,7 +45,6 @@ extern "C" { // TryCFCopy*VersionDictionary() helpers to account for the possibility that // they may not be present at runtime. CFDictionaryRef _CFCopySystemVersionDictionary() WEAK_IMPORT; -CFDictionaryRef _CFCopyServerVersionDictionary() WEAK_IMPORT; // Don’t use these constants with CFDictionaryGetValue() directly, use them with // the TryCFDictionaryGetValue() wrapper to account for the possibility that @@ -85,8 +84,8 @@ int DarwinMajorVersion() { int rv = uname(&uname_info); PCHECK(rv == 0) << "uname"; - DCHECK_EQ(strcmp(uname_info.sysname, "Darwin"), 0) << "unexpected sysname " - << uname_info.sysname; + DCHECK_EQ(strcmp(uname_info.sysname, "Darwin"), 0) + << "unexpected sysname " << uname_info.sysname; char* dot = strchr(uname_info.release, '.'); CHECK(dot); @@ -109,13 +108,6 @@ CFDictionaryRef TryCFCopySystemVersionDictionary() { return nullptr; } -CFDictionaryRef TryCFCopyServerVersionDictionary() { - if (_CFCopyServerVersionDictionary) { - return _CFCopyServerVersionDictionary(); - } - return nullptr; -} - const void* TryCFDictionaryGetValue(CFDictionaryRef dictionary, const void* value) { if (value) { @@ -242,19 +234,12 @@ bool MacOSVersionComponents(int* major, int* minor, int* bugfix, std::string* build, - bool* server, std::string* version_string) { base::ScopedCFTypeRef dictionary( - TryCFCopyServerVersionDictionary()); - if (dictionary) { - *server = true; - } else { - dictionary.reset(TryCFCopySystemVersionDictionary()); - if (!dictionary) { - LOG(ERROR) << "_CFCopySystemVersionDictionary failed"; - return false; - } - *server = false; + TryCFCopySystemVersionDictionary()); + if (!dictionary) { + LOG(ERROR) << "_CFCopySystemVersionDictionary failed"; + return false; } bool success = true; @@ -338,8 +323,8 @@ void MacModelAndBoard(std::string* model, std::string* board_id) { // alternative. CFStringRef kBoardProperty = CFSTR("target-type"); #endif - board_id->assign(IORegistryEntryDataPropertyAsString(platform_expert, - kBoardProperty)); + board_id->assign( + IORegistryEntryDataPropertyAsString(platform_expert, kBoardProperty)); } else { model->clear(); board_id->clear(); diff --git a/util/mac/mac_util.h b/util/mac/mac_util.h index c6215e0d..7a32b5f9 100644 --- a/util/mac/mac_util.h +++ b/util/mac/mac_util.h @@ -65,7 +65,6 @@ bool MacOSVersionComponents(int* major, int* minor, int* bugfix, std::string* build, - bool* server, std::string* version_string); //! \brief Returns the model name and board ID of the running system. diff --git a/util/mac/mac_util_test.mm b/util/mac/mac_util_test.mm index 49ee0903..c086ac65 100644 --- a/util/mac/mac_util_test.mm +++ b/util/mac/mac_util_test.mm @@ -65,10 +65,9 @@ void SwVers(NSString* argument, std::string* output) { int minor; int bugfix; std::string build; - bool server; std::string version_string; - ASSERT_TRUE(MacOSVersionComponents( - &major, &minor, &bugfix, &build, &server, &version_string)); + ASSERT_TRUE( + MacOSVersionComponents(&major, &minor, &bugfix, &build, &version_string)); EXPECT_GE(major, 10); EXPECT_LE(major, 99); @@ -116,10 +115,9 @@ void SwVers(NSString* argument, std::string* output) { int minor; int bugfix; std::string build; - bool server; std::string version_string; - ASSERT_TRUE(MacOSVersionComponents( - &major, &minor, &bugfix, &build, &server, &version_string)); + ASSERT_TRUE( + MacOSVersionComponents(&major, &minor, &bugfix, &build, &version_string)); EXPECT_EQ(macos_version_number, major * 1'00'00 + minor * 1'00 + From 25f724d783b91c48a2f76e79cd85a14e5fd98b1a Mon Sep 17 00:00:00 2001 From: Thomas Gales Date: Tue, 6 Jun 2023 22:48:28 +0000 Subject: [PATCH 013/107] [fuchsia] Add fp registers to x86 context This lays groundwork for floating point registers to also be included in RISC-V CPU context. Bug: fuchsia:5496 Tested: `fx test crashpad` Change-Id: I6230f146f955ac27f053f670f7f45dfff3560d02 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4594586 Reviewed-by: Mark Mentovai --- snapshot/fuchsia/cpu_context_fuchsia.cc | 16 +++++++++++++++- snapshot/fuchsia/cpu_context_fuchsia.h | 5 +++-- snapshot/fuchsia/exception_snapshot_fuchsia.cc | 6 +++--- snapshot/fuchsia/process_reader_fuchsia.cc | 10 ++++++++++ snapshot/fuchsia/process_reader_fuchsia.h | 4 ++++ snapshot/fuchsia/thread_snapshot_fuchsia.cc | 6 +++--- 6 files changed, 38 insertions(+), 9 deletions(-) diff --git a/snapshot/fuchsia/cpu_context_fuchsia.cc b/snapshot/fuchsia/cpu_context_fuchsia.cc index 8c907cb9..9730a0a7 100644 --- a/snapshot/fuchsia/cpu_context_fuchsia.cc +++ b/snapshot/fuchsia/cpu_context_fuchsia.cc @@ -21,8 +21,9 @@ namespace internal { #if defined(ARCH_CPU_X86_64) -void InitializeCPUContextX86_64_NoFloatingPoint( +void InitializeCPUContextX86_64( const zx_thread_state_general_regs_t& thread_context, + const zx_thread_state_fp_regs_t& float_context, CPUContextX86_64* context) { memset(context, 0, sizeof(*context)); context->rax = thread_context.rax; @@ -43,6 +44,19 @@ void InitializeCPUContextX86_64_NoFloatingPoint( context->r15 = thread_context.r15; context->rip = thread_context.rip; context->rflags = thread_context.rflags; + + context->fxsave.fcw = float_context.fcw; + context->fxsave.fsw = float_context.fsw; + context->fxsave.ftw = float_context.ftw; + context->fxsave.fop = float_context.fop; + context->fxsave.fpu_ip_64 = float_context.fip; + context->fxsave.fpu_dp_64 = float_context.fdp; + + for (size_t i = 0; i < std::size(float_context.st); ++i) { + memcpy(&context->fxsave.st_mm[i], + &float_context.st[i], + sizeof(float_context.st[i])); + } } #elif defined(ARCH_CPU_ARM64) diff --git a/snapshot/fuchsia/cpu_context_fuchsia.h b/snapshot/fuchsia/cpu_context_fuchsia.h index 3cce60ed..99bfa6f9 100644 --- a/snapshot/fuchsia/cpu_context_fuchsia.h +++ b/snapshot/fuchsia/cpu_context_fuchsia.h @@ -29,13 +29,14 @@ namespace internal { //! \brief Initializes a CPUContextX86_64 structure from native context //! structures on Fuchsia. //! -//! Floating point registers are currently initialized to zero. //! Segment registers are currently initialized to zero. //! //! \param[in] thread_context The native thread context. +//! \param[in] float_context The native floating point context. //! \param[out] context The CPUContextX86_64 structure to initialize. -void InitializeCPUContextX86_64_NoFloatingPoint( +void InitializeCPUContextX86_64( const zx_thread_state_general_regs_t& thread_context, + const zx_thread_state_fp_regs_t& float_context, CPUContextX86_64* context); #endif // ARCH_CPU_X86_64 || DOXYGEN diff --git a/snapshot/fuchsia/exception_snapshot_fuchsia.cc b/snapshot/fuchsia/exception_snapshot_fuchsia.cc index 50ea6fff..017a6c67 100644 --- a/snapshot/fuchsia/exception_snapshot_fuchsia.cc +++ b/snapshot/fuchsia/exception_snapshot_fuchsia.cc @@ -70,9 +70,9 @@ bool ExceptionSnapshotFuchsia::Initialize( #if defined(ARCH_CPU_X86_64) context_.architecture = kCPUArchitectureX86_64; context_.x86_64 = &context_arch_; - // TODO(fxbug.dev/5496): Add float context once saved in |t|. - InitializeCPUContextX86_64_NoFloatingPoint(t->general_registers, - context_.x86_64); + // TODO(fxbug.dev/5496): Add vector context. + InitializeCPUContextX86_64( + t->general_registers, t->fp_registers, context_.x86_64); #elif defined(ARCH_CPU_ARM64) context_.architecture = kCPUArchitectureARM64; context_.arm64 = &context_arch_; diff --git a/snapshot/fuchsia/process_reader_fuchsia.cc b/snapshot/fuchsia/process_reader_fuchsia.cc index 02be7c29..06f4c2e4 100644 --- a/snapshot/fuchsia/process_reader_fuchsia.cc +++ b/snapshot/fuchsia/process_reader_fuchsia.cc @@ -346,6 +346,16 @@ void ProcessReaderFuchsia::InitializeThreads() { } } + zx_thread_state_fp_regs_t fp_regs; + status = thread_handles[i].read_state( + ZX_THREAD_STATE_FP_REGS, &fp_regs, sizeof(fp_regs)); + if (status != ZX_OK) { + ZX_LOG(WARNING, status) + << "zx_thread_read_state(ZX_THREAD_STATE_FP_REGS)"; + } else { + thread.fp_registers = fp_regs; + } + zx_thread_state_vector_regs_t vector_regs; status = thread_handles[i].read_state( ZX_THREAD_STATE_VECTOR_REGS, &vector_regs, sizeof(vector_regs)); diff --git a/snapshot/fuchsia/process_reader_fuchsia.h b/snapshot/fuchsia/process_reader_fuchsia.h index cfeb6781..31e78869 100644 --- a/snapshot/fuchsia/process_reader_fuchsia.h +++ b/snapshot/fuchsia/process_reader_fuchsia.h @@ -76,6 +76,10 @@ class ProcessReaderFuchsia { //! returned by `zx_thread_read_state()`. zx_thread_state_general_regs_t general_registers = {}; + //! \brief The raw architecture-specific `zx_thread_state_fp_regs_t` as + //! returned by `zx_thread_read_state()`. + zx_thread_state_fp_regs_t fp_registers = {}; + //! \brief The raw architecture-specific `zx_thread_state_vector_regs_t` as //! returned by `zx_thread_read_state()`. zx_thread_state_vector_regs_t vector_registers = {}; diff --git a/snapshot/fuchsia/thread_snapshot_fuchsia.cc b/snapshot/fuchsia/thread_snapshot_fuchsia.cc index 20b85dde..0681ca27 100644 --- a/snapshot/fuchsia/thread_snapshot_fuchsia.cc +++ b/snapshot/fuchsia/thread_snapshot_fuchsia.cc @@ -40,9 +40,9 @@ bool ThreadSnapshotFuchsia::Initialize( #if defined(ARCH_CPU_X86_64) context_.architecture = kCPUArchitectureX86_64; context_.x86_64 = &context_arch_; - // TODO(fuchsia/DX-642): Add float context once saved in |thread|. - InitializeCPUContextX86_64_NoFloatingPoint(thread.general_registers, - context_.x86_64); + // TODO(fxbug.dev/5496): Add vector context. + InitializeCPUContextX86_64( + thread.general_registers, thread.fp_registers, context_.x86_64); #elif defined(ARCH_CPU_ARM64) context_.architecture = kCPUArchitectureARM64; context_.arm64 = &context_arch_; From 656fc625893ee8376c8cd9d9145925056cef322b Mon Sep 17 00:00:00 2001 From: Leonard Chan Date: Wed, 7 Jun 2023 20:38:09 +0000 Subject: [PATCH 014/107] [snapshot] Suppress function type mismatch UB UBSan is detecting a function type mismatch in this test. This is because TestModule_GetCrashpadInfo returns a TestCrashpadInfo* but the function expectes to return a CrashpadInfo*. Structurally, the TestCrashpadInfo struct is meant to replicate a CrashpadInfo byte-for-byte, but there's no relationship between the types. Bug: fxbug.dev/128274 Change-Id: I7b02ca802e55274116d46513b3aa6dc998f6d292 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4599482 Reviewed-by: Mark Mentovai --- snapshot/crashpad_info_client_options_test.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/snapshot/crashpad_info_client_options_test.cc b/snapshot/crashpad_info_client_options_test.cc index bc097902..005dfd59 100644 --- a/snapshot/crashpad_info_client_options_test.cc +++ b/snapshot/crashpad_info_client_options_test.cc @@ -241,6 +241,22 @@ TEST(CrashpadInfoClientOptions, TwoModules) { class CrashpadInfoSizes_ClientOptions : public testing::TestWithParam {}; +// UBSan detects a function type mismatch when calling +// TestModule_GetCrashpadInfo since the expected function signature should +// return a CrashpadInfo* but the actual TestModule_GetCrashpadInfo defined for +// the test returns a TestCrashpadInfo*. CrashpadInfo is a struct with its +// members set as private and TestCrashpadInfo is a POD meant to replicate the +// layout of CrashpadInfo byte-for-byte. Note this is intentional since the +// whole point of the test is to exercise the snapshot reader’s ability to +// handle CrashpadInfo. +#if defined(__clang__) +[[clang::no_sanitize("function")]] +#endif +inline CrashpadInfo* +CallGetCrashpadInfo(CrashpadInfo* (*func)()) { + return func(); +} + TEST_P(CrashpadInfoSizes_ClientOptions, DifferentlySizedStruct) { base::FilePath::StringType artifact(FILE_PATH_LITERAL("module_")); artifact += GetParam(); @@ -279,7 +295,8 @@ TEST_P(CrashpadInfoSizes_ClientOptions, DifferentlySizedStruct) { EXPECT_EQ(options.gather_indirectly_referenced_memory, TriState::kUnset); // Get the remote CrashpadInfo structure. - CrashpadInfo* remote_crashpad_info = TestModule_GetCrashpadInfo(); + CrashpadInfo* remote_crashpad_info = + CallGetCrashpadInfo(TestModule_GetCrashpadInfo); ASSERT_TRUE(remote_crashpad_info); { From 4f5dd672296e82f7bccc245125e6cd77d6e56528 Mon Sep 17 00:00:00 2001 From: Thomas Gales Date: Thu, 8 Jun 2023 21:08:54 +0000 Subject: [PATCH 015/107] [riscv] Add RISC-V Linux support Only RV64GC is supported. Bug: fuchsia:127655 Tested: `python build/run_tests.py` on RISC-V emulator Tested: Created minidump via self-induced crash on RISC-V emulator, ran through Breakpad stackwalker Change-Id: I713797cd623b0a758269048e01696cbce502ca6c Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4581050 Reviewed-by: Joshua Peraza --- minidump/minidump_context.h | 50 +++++++++++ minidump/minidump_context_writer.cc | 45 ++++++++++ minidump/minidump_context_writer.h | 44 ++++++++++ minidump/minidump_context_writer_test.cc | 60 ++++++++++++++ minidump/minidump_extensions.h | 3 + minidump/minidump_misc_info_writer.cc | 2 + minidump/minidump_system_info_writer.cc | 3 + minidump/test/minidump_context_test_util.cc | 44 ++++++++++ minidump/test/minidump_context_test_util.h | 5 ++ snapshot/capture_memory.cc | 5 ++ snapshot/cpu_architecture.h | 5 +- snapshot/cpu_context.cc | 6 ++ snapshot/cpu_context.h | 10 +++ snapshot/elf/elf_image_reader.cc | 7 +- snapshot/linux/cpu_context_linux.cc | 15 ++++ snapshot/linux/cpu_context_linux.h | 14 ++++ snapshot/linux/exception_snapshot_linux.cc | 44 ++++++++++ snapshot/linux/exception_snapshot_linux.h | 2 + .../linux/exception_snapshot_linux_test.cc | 28 +++++++ snapshot/linux/process_reader_linux.cc | 2 + snapshot/linux/signal_context.h | 34 ++++++++ snapshot/linux/system_snapshot_linux.cc | 11 +++ snapshot/linux/test_modules.cc | 7 ++ snapshot/linux/thread_snapshot_linux.cc | 6 ++ snapshot/linux/thread_snapshot_linux.h | 2 + .../minidump/minidump_context_converter.cc | 27 ++++++ snapshot/minidump/system_snapshot_minidump.cc | 2 + snapshot/test/test_cpu_context.cc | 22 +++++ snapshot/test/test_cpu_context.h | 1 + test/linux/get_tls.cc | 2 + util/linux/auxiliary_vector_test.cc | 5 ++ util/linux/ptracer.cc | 37 +++++++++ util/linux/thread_info.h | 24 +++++- util/misc/capture_context.h | 1 + util/misc/capture_context_linux.S | 83 +++++++++++++++++++ util/misc/capture_context_test_util_linux.cc | 7 ++ util/net/http_transport_libcurl.cc | 2 + 37 files changed, 662 insertions(+), 5 deletions(-) diff --git a/minidump/minidump_context.h b/minidump/minidump_context.h index 30988d8c..12413de0 100644 --- a/minidump/minidump_context.h +++ b/minidump/minidump_context.h @@ -637,6 +637,56 @@ struct MinidumpContextMIPS64 { uint64_t fir; }; +//! \brief 64-bit RISCV-specific flags for +//! MinidumpContextRISCV64::context_flags. +enum MinidumpContextRISCV64Flags : uint32_t { + //! \brief Identifies the context structure as RISCV64. + kMinidumpContextRISCV64 = 0x08000000, + + //! \brief Indicates the validity of integer registers. + //! + //! Registers 'pc' and `x1`-`x31` are valid. + kMinidumpContextRISCV64Integer = kMinidumpContextRISCV64 | 0x00000001, + + //! \brief Indicates the validity of floating point registers. + //! + //! Floating point registers `f0`-`f31` are valid. + kMinidumpContextRISCV64FloatingPoint = kMinidumpContextRISCV64 | 0x00000002, + + //! \brief Indicates the validity of all registers. + kMinidumpContextRISCV64All = kMinidumpContextRISCV64Integer | + kMinidumpContextRISCV64FloatingPoint, +}; + +//! \brief A 64-bit RISC-V CPU context (register state) carried in a minidump +//! file. +//! +//! This structure is versioned. Increment |kVersion| when changing this +//! structure. +struct MinidumpContextRISCV64 { + + //! \brief The structure’s currently-defined version number. + static constexpr uint32_t kVersion = 1; + + //! \brief Indicates the validity of fields in this structure. + uint32_t context_flags; + + //! \brief The structure’s version number. + uint32_t version; + + //! \brief The program counter register. + uint64_t pc; + + //! \brief The integer registers, x1 through x31. + uint64_t regs[31]; + + //! \brief The floating point registers. + uint64_t fpregs[32]; + + //! \brief The floating point control and status register. + uint32_t fcsr; +}; + } // namespace crashpad #endif // CRASHPAD_MINIDUMP_MINIDUMP_CONTEXT_H_ diff --git a/minidump/minidump_context_writer.cc b/minidump/minidump_context_writer.cc index 5f741ed7..84c01482 100644 --- a/minidump/minidump_context_writer.cc +++ b/minidump/minidump_context_writer.cc @@ -102,6 +102,13 @@ MinidumpContextWriter::CreateFromSnapshot(const CPUContext* context_snapshot) { break; } + case kCPUArchitectureRISCV64: { + context = std::make_unique(); + reinterpret_cast(context.get()) + ->InitializeFromSnapshot(context_snapshot->riscv64); + break; + } + default: { LOG(ERROR) << "unknown context architecture " << context_snapshot->architecture; @@ -556,4 +563,42 @@ size_t MinidumpContextMIPS64Writer::ContextSize() const { return sizeof(context_); } +MinidumpContextRISCV64Writer::MinidumpContextRISCV64Writer() + : MinidumpContextWriter(), context_() { + context_.context_flags = kMinidumpContextRISCV64; + context_.version = MinidumpContextRISCV64::kVersion; +} + +MinidumpContextRISCV64Writer::~MinidumpContextRISCV64Writer() = default; + +void MinidumpContextRISCV64Writer::InitializeFromSnapshot( + const CPUContextRISCV64* context_snapshot) { + DCHECK_EQ(state(), kStateMutable); + DCHECK_EQ(context_.context_flags, kMinidumpContextRISCV64); + + context_.context_flags = kMinidumpContextRISCV64All; + context_.version = MinidumpContextRISCV64::kVersion; + context_.pc = context_snapshot->pc; + + static_assert(sizeof(context_.regs) == sizeof(context_snapshot->regs), + "GPRs size mismatch"); + memcpy(context_.regs, context_snapshot->regs, sizeof(context_.regs)); + + static_assert(sizeof(context_.fpregs) == sizeof(context_snapshot->fpregs), + "FPRs size mismatch"); + memcpy(context_.fpregs, context_snapshot->fpregs, sizeof(context_.fpregs)); + context_.fcsr = context_snapshot->fcsr; +} + +bool MinidumpContextRISCV64Writer::WriteObject( + FileWriterInterface* file_writer) { + DCHECK_EQ(state(), kStateWritable); + return file_writer->Write(&context_, sizeof(context_)); +} + +size_t MinidumpContextRISCV64Writer::ContextSize() const { + DCHECK_GE(state(), kStateFrozen); + return sizeof(context_); +} + } // namespace crashpad diff --git a/minidump/minidump_context_writer.h b/minidump/minidump_context_writer.h index 6660be43..8e39c669 100644 --- a/minidump/minidump_context_writer.h +++ b/minidump/minidump_context_writer.h @@ -369,6 +369,50 @@ class MinidumpContextMIPS64Writer final : public MinidumpContextWriter { MinidumpContextMIPS64 context_; }; +//! \brief The writer for a MinidumpContextRISCV64 structure in a minidump file. +class MinidumpContextRISCV64Writer final : public MinidumpContextWriter { + public: + MinidumpContextRISCV64Writer(); + + MinidumpContextRISCV64Writer(const MinidumpContextRISCV64Writer&) = delete; + MinidumpContextRISCV64Writer& operator=(const MinidumpContextRISCV64Writer&) = + delete; + + ~MinidumpContextRISCV64Writer() override; + + //! \brief Initializes the MinidumpContextRISCV64 based on \a + //! context_snapshot. + //! + //! \param[in] context_snapshot The context snapshot to use as source data. + //! + //! \note Valid in #kStateMutable. No mutation of context() may be done before + //! calling this method, and it is not normally necessary to alter + //! context() after calling this method. + void InitializeFromSnapshot(const CPUContextRISCV64* context_snapshot); + + //! \brief Returns a pointer to the context structure that this object will + //! write. + //! + //! \attention This returns a non-`const` pointer to this object’s private + //! data so that a caller can populate the context structure directly. + //! This is done because providing setter interfaces to each field in the + //! context structure would be unwieldy and cumbersome. Care must be taken + //! to populate the context structure correctly. The context structure + //! must only be modified while this object is in the #kStateMutable + //! state. + MinidumpContextRISCV64* context() { return &context_; } + + protected: + // MinidumpWritable: + bool WriteObject(FileWriterInterface* file_writer) override; + + // MinidumpContextWriter: + size_t ContextSize() const override; + + private: + MinidumpContextRISCV64 context_; +}; + } // namespace crashpad #endif // CRASHPAD_MINIDUMP_MINIDUMP_CONTEXT_WRITER_H_ diff --git a/minidump/minidump_context_writer_test.cc b/minidump/minidump_context_writer_test.cc index e2a04d1d..9eebe81b 100644 --- a/minidump/minidump_context_writer_test.cc +++ b/minidump/minidump_context_writer_test.cc @@ -143,6 +143,49 @@ TYPED_TEST(MinidumpContextWriter, MinidumpContextAMD64Writer) { } } +TYPED_TEST(MinidumpContextWriter, MinidumpContextRISCV64Writer) { + { + // Make sure that a heap-allocated context writer has the proper alignment, + // because it may be nonstandard. + auto context_writer = std::make_unique(); + EXPECT_EQ(reinterpret_cast(context_writer.get()) & + (alignof(MinidumpContextRISCV64Writer) - 1), + 0u); + } + + StringFile string_file; + + { + // Make sure that a context writer that’s untouched writes a zeroed-out + // context. + SCOPED_TRACE("zero"); + + EmptyContextTest(ExpectMinidumpContextRISCV64); + } + + { + SCOPED_TRACE("nonzero"); + + string_file.Reset(); + constexpr uint32_t kSeed = 0x808664; + + MinidumpContextRISCV64Writer context_writer; + InitializeMinidumpContextRISCV64(context_writer.context(), kSeed); + + EXPECT_TRUE(context_writer.WriteEverything(&string_file)); + ASSERT_EQ(string_file.string().size(), sizeof(MinidumpContextRISCV64)); + + const MinidumpContextRISCV64* observed = + MinidumpWritableAtRVA(string_file.string(), + TypeParam(0)); + ASSERT_TRUE(observed); + + ExpectMinidumpContextRISCV64(kSeed, observed, false); + } +} + template void FromSnapshotTest(const CPUContext& snapshot_context, void (*expect_context)(uint32_t, const Context*, bool), @@ -268,6 +311,23 @@ TYPED_TEST(MinidumpContextWriter, MIPS64_FromSnapshot) { TypeParam>(context, ExpectMinidumpContextMIPS64, kSeed); } +TYPED_TEST(MinidumpContextWriter, RISCV64_Zeros) { + EmptyContextTest(ExpectMinidumpContextRISCV64); +} + +TYPED_TEST(MinidumpContextWriter, RISCV64_FromSnapshot) { + constexpr uint32_t kSeed = 64; + CPUContextRISCV64 context_riscv64; + CPUContext context; + context.riscv64 = &context_riscv64; + InitializeCPUContextRISCV64(&context, kSeed); + FromSnapshotTest(context, ExpectMinidumpContextRISCV64, kSeed); +} + } // namespace } // namespace test } // namespace crashpad diff --git a/minidump/minidump_extensions.h b/minidump/minidump_extensions.h index f96cf25b..a5f442bf 100644 --- a/minidump/minidump_extensions.h +++ b/minidump/minidump_extensions.h @@ -210,6 +210,9 @@ enum MinidumpCPUArchitecture : uint16_t { //! \deprecated Use #kMinidumpCPUArchitectureARM64 instead. kMinidumpCPUArchitectureARM64Breakpad = 0x8003, + //! \brief Used by Breakpad for 64-bit RISC-V. + kMinidumpCPUArchitectureRISCV64Breakpad = 0x8006, + //! \brief Unknown CPU architecture. kMinidumpCPUArchitectureUnknown = PROCESSOR_ARCHITECTURE_UNKNOWN, }; diff --git a/minidump/minidump_misc_info_writer.cc b/minidump/minidump_misc_info_writer.cc index 133ae308..1abb46c3 100644 --- a/minidump/minidump_misc_info_writer.cc +++ b/minidump/minidump_misc_info_writer.cc @@ -175,6 +175,8 @@ std::string MinidumpMiscInfoDebugBuildString() { static constexpr char kCPU[] = "mips"; #elif defined(ARCH_CPU_MIPS64EL) static constexpr char kCPU[] = "mips64"; +#elif defined(ARCH_CPU_RISCV64) + static constexpr char kCPU[] = "riscv64"; #else #error define kCPU for this CPU #endif diff --git a/minidump/minidump_system_info_writer.cc b/minidump/minidump_system_info_writer.cc index 4468c41a..e2ab775a 100644 --- a/minidump/minidump_system_info_writer.cc +++ b/minidump/minidump_system_info_writer.cc @@ -132,6 +132,9 @@ void MinidumpSystemInfoWriter::InitializeFromSnapshot( case kCPUArchitectureARM64: cpu_architecture = kMinidumpCPUArchitectureARM64; break; + case kCPUArchitectureRISCV64: + cpu_architecture = kMinidumpCPUArchitectureRISCV64Breakpad; + break; default: NOTREACHED(); cpu_architecture = kMinidumpCPUArchitectureUnknown; diff --git a/minidump/test/minidump_context_test_util.cc b/minidump/test/minidump_context_test_util.cc index 5746e4c3..b40558cf 100644 --- a/minidump/test/minidump_context_test_util.cc +++ b/minidump/test/minidump_context_test_util.cc @@ -272,6 +272,31 @@ void InitializeMinidumpContextMIPS64(MinidumpContextMIPS64* context, context->dsp_control = value++; } +void InitializeMinidumpContextRISCV64(MinidumpContextRISCV64* context, + uint32_t seed) { + if (seed == 0) { + memset(context, 0, sizeof(*context)); + context->context_flags = kMinidumpContextRISCV64; + context->version = MinidumpContextRISCV64::kVersion; + return; + } + + context->context_flags = kMinidumpContextRISCV64All; + context->version = MinidumpContextRISCV64::kVersion; + + uint32_t value = seed; + + context->pc = value++; + for (size_t index = 0; index < std::size(context->regs); ++index) { + context->regs[index] = value++; + } + + for (size_t index = 0; index < std::size(context->fpregs); ++index) { + context->fpregs[index] = value++; + } + context->fcsr = value++; +} + namespace { // Using Google Test assertions, compares |expected| to |observed|. This is @@ -601,5 +626,24 @@ void ExpectMinidumpContextMIPS64(uint32_t expect_seed, EXPECT_EQ(observed->dsp_control, expected.dsp_control); } +void ExpectMinidumpContextRISCV64(uint32_t expect_seed, + const MinidumpContextRISCV64* observed, + bool snapshot) { + MinidumpContextRISCV64 expected; + InitializeMinidumpContextRISCV64(&expected, expect_seed); + + EXPECT_EQ(observed->context_flags, expected.context_flags); + EXPECT_EQ(observed->version, expected.version); + + for (size_t index = 0; index < std::size(expected.regs); ++index) { + EXPECT_EQ(observed->regs[index], expected.regs[index]); + } + + for (size_t index = 0; index < std::size(expected.fpregs); ++index) { + EXPECT_EQ(observed->fpregs[index], expected.fpregs[index]); + } + EXPECT_EQ(observed->fcsr, expected.fcsr); +} + } // namespace test } // namespace crashpad diff --git a/minidump/test/minidump_context_test_util.h b/minidump/test/minidump_context_test_util.h index 793e2c39..4ce5c1e1 100644 --- a/minidump/test/minidump_context_test_util.h +++ b/minidump/test/minidump_context_test_util.h @@ -47,6 +47,8 @@ void InitializeMinidumpContextARM64(MinidumpContextARM64* context, void InitializeMinidumpContextMIPS(MinidumpContextMIPS* context, uint32_t seed); void InitializeMinidumpContextMIPS64(MinidumpContextMIPS* context, uint32_t seed); +void InitializeMinidumpContextRISCV64(MinidumpContextRISCV64* context, + uint32_t seed); //! \} //! \brief Verifies, via Google Test assertions, that a context structure @@ -85,6 +87,9 @@ void ExpectMinidumpContextMIPS(uint32_t expect_seed, void ExpectMinidumpContextMIPS64(uint32_t expect_seed, const MinidumpContextMIPS64* observed, bool snapshot); +void ExpectMinidumpContextRISCV64(uint32_t expect_seed, + const MinidumpContextRISCV64* observed, + bool snapshot); //! \} } // namespace test diff --git a/snapshot/capture_memory.cc b/snapshot/capture_memory.cc index 0a465d22..c1c6fba5 100644 --- a/snapshot/capture_memory.cc +++ b/snapshot/capture_memory.cc @@ -117,6 +117,11 @@ void CaptureMemory::PointedToByContext(const CPUContext& context, for (size_t i = 0; i < std::size(context.mipsel->regs); ++i) { MaybeCaptureMemoryAround(delegate, context.mipsel->regs[i]); } +#elif defined(ARCH_CPU_RISCV64) + MaybeCaptureMemoryAround(delegate, context.riscv64->pc); + for (size_t i = 0; i < std::size(context.riscv64->regs); ++i) { + MaybeCaptureMemoryAround(delegate, context.riscv64->regs[i]); + } #else #error Port. #endif diff --git a/snapshot/cpu_architecture.h b/snapshot/cpu_architecture.h index 4003a929..26d45f84 100644 --- a/snapshot/cpu_architecture.h +++ b/snapshot/cpu_architecture.h @@ -43,7 +43,10 @@ enum CPUArchitecture { kCPUArchitectureMIPSEL, //! \brief 64-bit MIPSEL. - kCPUArchitectureMIPS64EL + kCPUArchitectureMIPS64EL, + + //! \brief 64-bit RISC-V. + kCPUArchitectureRISCV64, }; } // namespace crashpad diff --git a/snapshot/cpu_context.cc b/snapshot/cpu_context.cc index 6eaa853f..492a0f7f 100644 --- a/snapshot/cpu_context.cc +++ b/snapshot/cpu_context.cc @@ -20,6 +20,7 @@ #include #include "base/notreached.h" +#include "cpu_architecture.h" #include "util/misc/arraysize.h" #include "util/misc/implicit_cast.h" @@ -170,6 +171,8 @@ uint64_t CPUContext::InstructionPointer() const { return arm->pc; case kCPUArchitectureARM64: return arm64->pc; + case kCPUArchitectureRISCV64: + return riscv64->pc; default: NOTREACHED(); return ~0ull; @@ -186,6 +189,8 @@ uint64_t CPUContext::StackPointer() const { return arm->sp; case kCPUArchitectureARM64: return arm64->sp; + case kCPUArchitectureRISCV64: + return riscv64->regs[1]; default: NOTREACHED(); return ~0ull; @@ -226,6 +231,7 @@ bool CPUContext::Is64Bit() const { case kCPUArchitectureX86_64: case kCPUArchitectureARM64: case kCPUArchitectureMIPS64EL: + case kCPUArchitectureRISCV64: return true; case kCPUArchitectureX86: case kCPUArchitectureARM: diff --git a/snapshot/cpu_context.h b/snapshot/cpu_context.h index 7bc252be..c3640c32 100644 --- a/snapshot/cpu_context.h +++ b/snapshot/cpu_context.h @@ -362,6 +362,15 @@ struct CPUContextMIPS64 { uint64_t fir; }; +//! \brief A context structure carrying RISCV64 CPU state. +struct CPUContextRISCV64 { + uint64_t pc; + uint64_t regs[31]; + + uint64_t fpregs[32]; + uint32_t fcsr; +}; + //! \brief A context structure capable of carrying the context of any supported //! CPU architecture. struct CPUContext { @@ -402,6 +411,7 @@ struct CPUContext { CPUContextARM64* arm64; CPUContextMIPS* mipsel; CPUContextMIPS64* mips64; + CPUContextRISCV64* riscv64; }; }; diff --git a/snapshot/elf/elf_image_reader.cc b/snapshot/elf/elf_image_reader.cc index 30e8b987..dcab025a 100644 --- a/snapshot/elf/elf_image_reader.cc +++ b/snapshot/elf/elf_image_reader.cc @@ -733,8 +733,11 @@ bool ElfImageReader::GetAddressFromDynamicArray(uint64_t tag, if (!dynamic_array_->GetValue(tag, log, address)) { return false; } -#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA) - // The GNU loader updates the dynamic array according to the load bias. + +#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA) || \ + (defined(__GLIBC__) && defined(ARCH_CPU_RISCV64)) + // The GNU loader updates the dynamic array according to the load bias (except + // for RISC-V: https://sourceware.org/bugzilla/show_bug.cgi?id=24484). // The Android and Fuchsia loaders only update the debug address. if (tag != DT_DEBUG) { *address += GetLoadBias(); diff --git a/snapshot/linux/cpu_context_linux.cc b/snapshot/linux/cpu_context_linux.cc index 21db2343..6c4cb3eb 100644 --- a/snapshot/linux/cpu_context_linux.cc +++ b/snapshot/linux/cpu_context_linux.cc @@ -266,6 +266,21 @@ void InitializeCPUContextARM64_OnlyFPSIMD( context->fpcr = float_context.fpcr; } +#elif defined(ARCH_CPU_RISCV64) + +void InitializeCPUContextRISCV64(const ThreadContext::t64_t& thread_context, + const FloatContext::f64_t& float_context, + CPUContextRISCV64* context) { + context->pc = thread_context.pc; + + static_assert(sizeof(context->regs) == sizeof(thread_context.regs)); + memcpy(context->regs, thread_context.regs, sizeof(context->regs)); + + static_assert(sizeof(context->fpregs) == sizeof(float_context.fpregs)); + memcpy(context->fpregs, float_context.fpregs, sizeof(context->fpregs)); + context->fcsr = float_context.fcsr; +} + #endif // ARCH_CPU_X86_FAMILY } // namespace internal diff --git a/snapshot/linux/cpu_context_linux.h b/snapshot/linux/cpu_context_linux.h index 1ea5eecd..507d1b44 100644 --- a/snapshot/linux/cpu_context_linux.h +++ b/snapshot/linux/cpu_context_linux.h @@ -174,6 +174,20 @@ void InitializeCPUContextMIPS( #endif // ARCH_CPU_MIPS_FAMILY || DOXYGEN +#if defined(ARCH_CPU_RISCV64) || DOXYGEN + +//! \brief Initializes a CPUContextRISCV64 structure from native context +//! structures on Linux. +//! +//! \param[in] thread_context The native thread context. +//! \param[in] float_context The native float context. +//! \param[out] context The CPUContextRISCV64 structure to initialize. +void InitializeCPUContextRISCV64(const ThreadContext::t64_t& thread_context, + const FloatContext::f64_t& float_context, + CPUContextRISCV64* context); + +#endif // ARCH_CPU_RISCV64 || DOXYGEN + } // namespace internal } // namespace crashpad diff --git a/snapshot/linux/exception_snapshot_linux.cc b/snapshot/linux/exception_snapshot_linux.cc index 4e6ec11f..677afdaa 100644 --- a/snapshot/linux/exception_snapshot_linux.cc +++ b/snapshot/linux/exception_snapshot_linux.cc @@ -325,6 +325,48 @@ bool ExceptionSnapshotLinux::ReadContext( reader, context_address, context_.mips64); } +#elif defined(ARCH_CPU_RISCV64) + +static bool ReadContext(ProcessReaderLinux* reader, + LinuxVMAddress context_address, + typename ContextTraits64::CPUContext* dest_context) { + const ProcessMemory* memory = reader->Memory(); + + LinuxVMAddress gregs_address = context_address + + offsetof(UContext, mcontext) + + offsetof(MContext64, regs); + + typename ContextTraits64::SignalThreadContext thread_context; + if (!memory->Read(gregs_address, sizeof(thread_context), &thread_context)) { + LOG(ERROR) << "Couldn't read gregs"; + return false; + } + + LinuxVMAddress fpregs_address = + context_address + offsetof(UContext, mcontext) + + offsetof(MContext64, fpregs); + + typename ContextTraits64::SignalFloatContext fp_context; + if (!memory->Read(fpregs_address, sizeof(fp_context), &fp_context)) { + LOG(ERROR) << "Couldn't read fpregs"; + return false; + } + + InitializeCPUContextRISCV64(thread_context, fp_context, dest_context); + + return true; +} + +template <> +bool ExceptionSnapshotLinux::ReadContext( + ProcessReaderLinux* reader, + LinuxVMAddress context_address) { + context_.architecture = kCPUArchitectureRISCV64; + context_.riscv64 = &context_union_.riscv64; + + return internal::ReadContext(reader, context_address, context_.riscv64); +} + #endif // ARCH_CPU_X86_FAMILY bool ExceptionSnapshotLinux::Initialize( @@ -355,10 +397,12 @@ bool ExceptionSnapshotLinux::Initialize( return false; } } else { +#if !defined(ARCH_CPU_RISCV64) if (!ReadContext(process_reader, context_address) || !ReadSiginfo(process_reader, siginfo_address)) { return false; } +#endif } CaptureMemoryDelegateLinux capture_memory_delegate( diff --git a/snapshot/linux/exception_snapshot_linux.h b/snapshot/linux/exception_snapshot_linux.h index 3ea3d931..f931d330 100644 --- a/snapshot/linux/exception_snapshot_linux.h +++ b/snapshot/linux/exception_snapshot_linux.h @@ -89,6 +89,8 @@ class ExceptionSnapshotLinux final : public ExceptionSnapshot { #elif defined(ARCH_CPU_MIPS_FAMILY) CPUContextMIPS mipsel; CPUContextMIPS64 mips64; +#elif defined(ARCH_CPU_RISCV64) + CPUContextRISCV64 riscv64; #endif } context_union_; CPUContext context_; diff --git a/snapshot/linux/exception_snapshot_linux_test.cc b/snapshot/linux/exception_snapshot_linux_test.cc index 0f5e21af..94f45f1e 100644 --- a/snapshot/linux/exception_snapshot_linux_test.cc +++ b/snapshot/linux/exception_snapshot_linux_test.cc @@ -297,6 +297,34 @@ void ExpectContext(const CPUContext& actual, const NativeCPUContext& expected) { #undef CPU_ARCH_NAME } +#elif defined(ARCH_CPU_RISCV64) +using NativeCPUContext = ucontext_t; + +void InitializeContext(NativeCPUContext* context) { + for (size_t reg = 0; reg < std::size(context->uc_mcontext.__gregs); ++reg) { + context->uc_mcontext.__gregs[reg] = reg; + } + + memset(&context->uc_mcontext.__fpregs, + 44, + sizeof(context->uc_mcontext.__fpregs)); +} + +void ExpectContext(const CPUContext& actual, const NativeCPUContext& expected) { + EXPECT_EQ(actual.architecture, kCPUArchitectureRISCV64); + + EXPECT_EQ(actual.riscv64->pc, expected.uc_mcontext.__gregs[0]); + + for (size_t reg = 0; reg < std::size(actual.riscv64->regs); ++reg) { + EXPECT_EQ(actual.riscv64->regs[reg], expected.uc_mcontext.__gregs[reg + 1]); + } + + EXPECT_EQ(memcmp(&actual.riscv64->fpregs, + &expected.uc_mcontext.__fpregs, + sizeof(actual.riscv64->fpregs)), + 0); +} + #else #error Port. #endif diff --git a/snapshot/linux/process_reader_linux.cc b/snapshot/linux/process_reader_linux.cc index 8ec0edc6..45713386 100644 --- a/snapshot/linux/process_reader_linux.cc +++ b/snapshot/linux/process_reader_linux.cc @@ -127,6 +127,8 @@ void ProcessReaderLinux::Thread::InitializeStack(ProcessReaderLinux* reader) { #elif defined(ARCH_CPU_MIPS_FAMILY) stack_pointer = reader->Is64Bit() ? thread_info.thread_context.t64.regs[29] : thread_info.thread_context.t32.regs[29]; +#elif defined(ARCH_CPU_RISCV64) + stack_pointer = thread_info.thread_context.t64.regs[1]; #else #error Port. #endif diff --git a/snapshot/linux/signal_context.h b/snapshot/linux/signal_context.h index 6ac7adea..89e697a0 100644 --- a/snapshot/linux/signal_context.h +++ b/snapshot/linux/signal_context.h @@ -422,6 +422,40 @@ static_assert(offsetof(UContext, mcontext.fpregs) == "context offset mismatch"); #endif +#elif defined(ARCH_CPU_RISCV64) + +struct ContextTraits64 : public Traits64 { + using SignalThreadContext = ThreadContext::t64_t; + using SignalFloatContext = FloatContext::f64_t; + using CPUContext = CPUContextRISCV64; +}; + +struct MContext64 { + ThreadContext::t64_t regs; + FloatContext::f64_t fpregs; +}; + +template +struct UContext { + typename Traits::ULong flags; + typename Traits::Address link; + SignalStack stack; + Sigset sigmask; + char alignment_padding_[8]; + char padding[128 - sizeof(Sigset)]; + MContext64 mcontext; +}; + +static_assert(offsetof(UContext, mcontext) == + offsetof(ucontext_t, uc_mcontext), + "context offset mismatch"); +static_assert(offsetof(UContext, mcontext.regs) == + offsetof(ucontext_t, uc_mcontext.__gregs), + "context offset mismatch"); +static_assert(offsetof(UContext, mcontext.fpregs) == + offsetof(ucontext_t, uc_mcontext.__fpregs), + "context offset mismatch"); + #else #error Port. #endif // ARCH_CPU_X86_FAMILY diff --git a/snapshot/linux/system_snapshot_linux.cc b/snapshot/linux/system_snapshot_linux.cc index 84871551..20b95fba 100644 --- a/snapshot/linux/system_snapshot_linux.cc +++ b/snapshot/linux/system_snapshot_linux.cc @@ -205,6 +205,8 @@ CPUArchitecture SystemSnapshotLinux::GetCPUArchitecture() const { #elif defined(ARCH_CPU_MIPS_FAMILY) return process_reader_->Is64Bit() ? kCPUArchitectureMIPS64EL : kCPUArchitectureMIPSEL; +#elif defined(ARCH_CPU_RISCV64) + return kCPUArchitectureRISCV64; #else #error port to your architecture #endif @@ -220,6 +222,9 @@ uint32_t SystemSnapshotLinux::CPURevision() const { #elif defined(ARCH_CPU_MIPS_FAMILY) // Not implementable on MIPS return 0; +#elif defined(ARCH_CPU_RISCV64) + // Not implemented + return 0; #else #error port to your architecture #endif @@ -240,6 +245,9 @@ std::string SystemSnapshotLinux::CPUVendor() const { #elif defined(ARCH_CPU_MIPS_FAMILY) // Not implementable on MIPS return std::string(); +#elif defined(ARCH_CPU_RISCV64) + // Not implemented + return std::string(); #else #error port to your architecture #endif @@ -373,6 +381,9 @@ bool SystemSnapshotLinux::NXEnabled() const { #elif defined(ARCH_CPU_MIPS_FAMILY) // Not implementable on MIPS return false; +#elif defined(ARCH_CPU_RISCV64) + // Not implemented + return false; #else #error Port. #endif // ARCH_CPU_X86_FAMILY diff --git a/snapshot/linux/test_modules.cc b/snapshot/linux/test_modules.cc index 7d9d08d2..c03cbaae 100644 --- a/snapshot/linux/test_modules.cc +++ b/snapshot/linux/test_modules.cc @@ -110,6 +110,13 @@ bool WriteTestModule(const base::FilePath& module_path, module.ehdr.e_machine = EM_AARCH64; #elif defined(ARCH_CPU_MIPSEL) || defined(ARCH_CPU_MIPS64EL) module.ehdr.e_machine = EM_MIPS; +#elif defined(ARCH_CPU_RISCV64) + module.ehdr.e_machine = EM_RISCV; +#endif + +#if defined(ARCH_CPU_RISCV64) + // Crashpad supports RV64GC + module.ehdr.e_flags = EF_RISCV_RVC | EF_RISCV_FLOAT_ABI_DOUBLE; #endif module.ehdr.e_version = EV_CURRENT; diff --git a/snapshot/linux/thread_snapshot_linux.cc b/snapshot/linux/thread_snapshot_linux.cc index ba334010..85882e8e 100644 --- a/snapshot/linux/thread_snapshot_linux.cc +++ b/snapshot/linux/thread_snapshot_linux.cc @@ -190,6 +190,12 @@ bool ThreadSnapshotLinux::Initialize( thread.thread_info.float_context.f32, context_.mipsel); } +#elif defined(ARCH_CPU_RISCV64) + context_.architecture = kCPUArchitectureRISCV64; + context_.riscv64 = &context_union_.riscv64; + InitializeCPUContextRISCV64(thread.thread_info.thread_context.t64, + thread.thread_info.float_context.f64, + context_.riscv64); #else #error Port. #endif diff --git a/snapshot/linux/thread_snapshot_linux.h b/snapshot/linux/thread_snapshot_linux.h index bd03f582..5795bfb9 100644 --- a/snapshot/linux/thread_snapshot_linux.h +++ b/snapshot/linux/thread_snapshot_linux.h @@ -74,6 +74,8 @@ class ThreadSnapshotLinux final : public ThreadSnapshot { #elif defined(ARCH_CPU_MIPS_FAMILY) CPUContextMIPS mipsel; CPUContextMIPS64 mips64; +#elif defined(ARCH_CPU_RISCV64) + CPUContextRISCV64 riscv64; #else #error Port. #endif // ARCH_CPU_X86_FAMILY diff --git a/snapshot/minidump/minidump_context_converter.cc b/snapshot/minidump/minidump_context_converter.cc index f2fa2ab3..ec02dff1 100644 --- a/snapshot/minidump/minidump_context_converter.cc +++ b/snapshot/minidump/minidump_context_converter.cc @@ -266,6 +266,33 @@ bool MinidumpContextConverter::Initialize( context_.mips64->fir = src->fir; memcpy(&context_.mips64->fpregs, &src->fpregs, sizeof(src->fpregs)); + } else if (context_.architecture == + CPUArchitecture::kCPUArchitectureRISCV64) { + context_memory_.resize(sizeof(CPUContextRISCV64)); + context_.riscv64 = + reinterpret_cast(context_memory_.data()); + const MinidumpContextRISCV64* src = + reinterpret_cast( + minidump_context.data()); + if (minidump_context.size() < sizeof(MinidumpContextRISCV64)) { + return false; + } + + if (!(src->context_flags & kMinidumpContextRISCV64)) { + return false; + } + + context_.riscv64->pc = src->pc; + + static_assert(sizeof(context_.riscv64->regs) == sizeof(src->regs), + "GPR size mismatch"); + memcpy(&context_.riscv64->regs, &src->regs, sizeof(src->regs)); + + static_assert(sizeof(context_.riscv64->fpregs) == sizeof(src->fpregs), + "FPR size mismatch"); + memcpy(&context_.riscv64->fpregs, &src->fpregs, sizeof(src->fpregs)); + + context_.riscv64->fcsr = src->fcsr; } else { // Architecture is listed as "unknown". DLOG(ERROR) << "Unknown architecture"; diff --git a/snapshot/minidump/system_snapshot_minidump.cc b/snapshot/minidump/system_snapshot_minidump.cc index abccda31..58bd7b36 100644 --- a/snapshot/minidump/system_snapshot_minidump.cc +++ b/snapshot/minidump/system_snapshot_minidump.cc @@ -68,6 +68,8 @@ CPUArchitecture SystemSnapshotMinidump::GetCPUArchitecture() const { case kMinidumpCPUArchitectureMIPS: return kCPUArchitectureMIPSEL; // No word on how MIPS64 is signalled + case kMinidumpCPUArchitectureRISCV64Breakpad: + return kCPUArchitectureRISCV64; default: return CPUArchitecture::kCPUArchitectureUnknown; diff --git a/snapshot/test/test_cpu_context.cc b/snapshot/test/test_cpu_context.cc index 7efbf5af..99822946 100644 --- a/snapshot/test/test_cpu_context.cc +++ b/snapshot/test/test_cpu_context.cc @@ -295,5 +295,27 @@ void InitializeCPUContextMIPS64(CPUContext* context, uint32_t seed) { mips64->dsp_control = value++; } +void InitializeCPUContextRISCV64(CPUContext* context, uint32_t seed) { + context->architecture = kCPUArchitectureRISCV64; + CPUContextRISCV64* riscv64 = context->riscv64; + + if (seed == 0) { + memset(riscv64, 0, sizeof(*riscv64)); + return; + } + + uint32_t value = seed; + + riscv64->pc = value++; + for (size_t index = 0; index < std::size(riscv64->regs); ++index) { + riscv64->regs[index] = value++; + } + + for (size_t index = 0; index < std::size(riscv64->fpregs); ++index) { + riscv64->fpregs[index] = value++; + } + riscv64->fcsr = value++; +} + } // namespace test } // namespace crashpad diff --git a/snapshot/test/test_cpu_context.h b/snapshot/test/test_cpu_context.h index e4372cee..053dec28 100644 --- a/snapshot/test/test_cpu_context.h +++ b/snapshot/test/test_cpu_context.h @@ -63,6 +63,7 @@ void InitializeCPUContextARM(CPUContext* context, uint32_t seed); void InitializeCPUContextARM64(CPUContext* context, uint32_t seed); void InitializeCPUContextMIPS(CPUContext* context, uint32_t seed); void InitializeCPUContextMIPS64(CPUContext* context, uint32_t seed); +void InitializeCPUContextRISCV64(CPUContext* context, uint32_t seed); //! \} } // namespace test diff --git a/test/linux/get_tls.cc b/test/linux/get_tls.cc index c8147f0d..405976ea 100644 --- a/test/linux/get_tls.cc +++ b/test/linux/get_tls.cc @@ -49,6 +49,8 @@ LinuxVMAddress GetTLS() { : "=r"(tls) : : "$3"); +#elif defined(ARCH_CPU_RISCV64) + asm("mv %0, tp" : "=r"(tls)); #else #error Port. #endif // ARCH_CPU_ARMEL diff --git a/util/linux/auxiliary_vector_test.cc b/util/linux/auxiliary_vector_test.cc index 04554974..0c97781f 100644 --- a/util/linux/auxiliary_vector_test.cc +++ b/util/linux/auxiliary_vector_test.cc @@ -96,10 +96,15 @@ void TestAgainstCloneOrSelf(pid_t pid) { ProcessMemoryLinux memory(&connection); +// AT_PLATFORM is null for RISC-V: +// https://elixir.bootlin.com/linux/v6.4-rc4/C/ident/ELF_PLATFORM +#if !defined(ARCH_CPU_RISCV64) LinuxVMAddress platform_addr; ASSERT_TRUE(aux.GetValue(AT_PLATFORM, &platform_addr)); std::string platform; ASSERT_TRUE(memory.ReadCStringSizeLimited(platform_addr, 10, &platform)); +#endif // ARCH_CPU_RISCV64 + #if defined(ARCH_CPU_X86) EXPECT_STREQ(platform.c_str(), "i686"); #elif defined(ARCH_CPU_X86_64) diff --git a/util/linux/ptracer.cc b/util/linux/ptracer.cc index 25c89ea9..d8129ada 100644 --- a/util/linux/ptracer.cc +++ b/util/linux/ptracer.cc @@ -398,6 +398,37 @@ bool GetThreadArea64(pid_t tid, return true; } +#elif defined(ARCH_CPU_RISCV64) + +bool GetFloatingPointRegisters64(pid_t tid, + FloatContext* context, + bool can_log) { + iovec iov; + iov.iov_base = context; + iov.iov_len = sizeof(*context); + if (ptrace( + PTRACE_GETREGSET, tid, reinterpret_cast(NT_PRFPREG), &iov) != + 0) { + PLOG_IF(ERROR, can_log) << "ptrace"; + return false; + } + if (iov.iov_len != sizeof(context->f64)) { + LOG_IF(ERROR, can_log) << "Unexpected registers size " << iov.iov_len + << " != " << sizeof(context->f64); + return false; + } + return true; +} + +bool GetThreadArea64(pid_t tid, + const ThreadContext& context, + LinuxVMAddress* address, + bool can_log) { + // Thread pointer register + *address = context.t64.regs[3]; + return true; +} + #else #error Port. #endif // ARCH_CPU_X86_FAMILY @@ -426,6 +457,7 @@ size_t GetGeneralPurposeRegistersAndLength(pid_t tid, return iov.iov_len; } +#if !defined(ARCH_CPU_RISCV64) bool GetGeneralPurposeRegisters32(pid_t tid, ThreadContext* context, bool can_log) { @@ -437,6 +469,7 @@ bool GetGeneralPurposeRegisters32(pid_t tid, } return true; } +#endif bool GetGeneralPurposeRegisters64(pid_t tid, ThreadContext* context, @@ -500,12 +533,16 @@ bool Ptracer::GetThreadInfo(pid_t tid, ThreadInfo* info) { can_log_); } +#if !defined(ARCH_CPU_RISCV64) return GetGeneralPurposeRegisters32(tid, &info->thread_context, can_log_) && GetFloatingPointRegisters32(tid, &info->float_context, can_log_) && GetThreadArea32(tid, info->thread_context, &info->thread_specific_data_address, can_log_); +#else + return false; +#endif } ssize_t Ptracer::ReadUpTo(pid_t pid, diff --git a/util/linux/thread_info.h b/util/linux/thread_info.h index 9f60bd3e..808b35a3 100644 --- a/util/linux/thread_info.h +++ b/util/linux/thread_info.h @@ -29,6 +29,11 @@ #include #endif +// x86_64 has compilation errors if asm/ptrace.h is #included. +#if defined(ARCH_CPU_RISCV64) +#include +#endif + namespace crashpad { //! \brief The set of general purpose registers for an architecture family. @@ -80,6 +85,8 @@ union ThreadContext { uint32_t cp0_status; uint32_t cp0_cause; uint32_t padding1_; +#elif defined(ARCH_CPU_RISCV64) + // 32 bit RISC-V not supported #else #error Port. #endif // ARCH_CPU_X86_FAMILY @@ -133,12 +140,17 @@ union ThreadContext { uint64_t cp0_badvaddr; uint64_t cp0_status; uint64_t cp0_cause; +#elif defined(ARCH_CPU_RISCV64) + // Reflects user_regs_struct in asm/ptrace.h. + uint64_t pc; + uint64_t regs[31]; #else #error Port. #endif // ARCH_CPU_X86_FAMILY } t64; -#if defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARM64) +#if defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARM64) || \ + defined(ARCH_CPU_RISCV64) using NativeThreadContext = user_regs_struct; #elif defined(ARCH_CPU_ARMEL) using NativeThreadContext = user_regs; @@ -146,7 +158,7 @@ union ThreadContext { // No appropriate NativeThreadsContext type available for MIPS #else #error Port. -#endif // ARCH_CPU_X86_FAMILY || ARCH_CPU_ARM64 +#endif // ARCH_CPU_X86_FAMILY || ARCH_CPU_ARM64 || ARCH_CPU_RISCV64 #if !defined(ARCH_CPU_MIPS_FAMILY) #if defined(ARCH_CPU_32_BITS) @@ -219,6 +231,8 @@ union FloatContext { } fpregs[32]; uint32_t fpcsr; uint32_t fpu_id; +#elif defined(ARCH_CPU_RISCV64) + // 32 bit RISC-V not supported #else #error Port. #endif // ARCH_CPU_X86_FAMILY @@ -253,6 +267,10 @@ union FloatContext { double fpregs[32]; uint32_t fpcsr; uint32_t fpu_id; +#elif defined(ARCH_CPU_RISCV64) + // Reflects __riscv_d_ext_state in asm/ptrace.h + uint64_t fpregs[32]; + uint64_t fcsr; #else #error Port. #endif // ARCH_CPU_X86_FAMILY @@ -282,6 +300,8 @@ union FloatContext { static_assert(sizeof(f64) == sizeof(user_fpsimd_struct), "Size mismatch"); #elif defined(ARCH_CPU_MIPS_FAMILY) // No appropriate floating point context native type for available MIPS. +#elif defined(ARCH_CPU_RISCV64) + static_assert(sizeof(f64) == sizeof(__riscv_d_ext_state), "Size mismatch"); #else #error Port. #endif // ARCH_CPU_X86 diff --git a/util/misc/capture_context.h b/util/misc/capture_context.h index a5503d68..e838dbab 100644 --- a/util/misc/capture_context.h +++ b/util/misc/capture_context.h @@ -69,6 +69,7 @@ using NativeCPUContext = ucontext_t; //! macOS/Linux/Fuchsia | x86_64 | `%%rdi` //! Linux | ARM/ARM64 | `r0`/`x0` //! Linux | MIPS/MIPS64 | `$a0` +//! Linux | RISCV64 | `a0` //! //! Additionally, the value `LR` on ARM/ARM64 will be the return address of //! this function. diff --git a/util/misc/capture_context_linux.S b/util/misc/capture_context_linux.S index 9c3a7263..cfad8573 100644 --- a/util/misc/capture_context_linux.S +++ b/util/misc/capture_context_linux.S @@ -36,6 +36,8 @@ .type CAPTURECONTEXT_SYMBOL2, %function #elif defined(__mips__) .balign 4, 0x0 +#elif defined(__riscv) + .balign 4, 0x0 #endif CAPTURECONTEXT_SYMBOL: @@ -427,4 +429,85 @@ CAPTURECONTEXT_SYMBOL2: jr $ra .set at + +#elif defined(__riscv) + + #define MCONTEXT_GREGS_OFFSET 176 + + // x1/ra is the return address. Store it as the pc. + // The original x10/a0 can't be recovered. + sd x1, (0 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x1, (1 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x2, (2 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x3, (3 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x4, (4 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x5, (5 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x6, (6 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x7, (7 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x8, (8 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x9, (9 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x10, (10 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x11, (11 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x12, (12 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x13, (13 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x14, (14 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x15, (15 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x16, (16 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x17, (17 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x18, (18 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x19, (19 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x20, (20 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x21, (21 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x22, (22 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x23, (23 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x24, (24 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x25, (25 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x26, (26 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x27, (27 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x28, (28 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x29, (29 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x30, (30 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x31, (31 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + + #define MCONTEXT_FPREGS_OFFSET MCONTEXT_GREGS_OFFSET + 32*8 + + // Use x31/t6 as scratch register. + frcsr x31 + sw x31, (32 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + + fsd f0, (0 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f1, (1 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f2, (2 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f3, (3 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f4, (4 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f5, (5 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f6, (6 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f7, (7 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f8, (8 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f9, (9 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f10, (10 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f11, (11 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f12, (12 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f13, (13 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f14, (14 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f15, (15 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f16, (16 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f17, (17 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f18, (18 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f19, (19 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f20, (20 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f21, (21 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f22, (22 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f23, (23 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f24, (24 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f25, (25 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f26, (26 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f27, (27 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f28, (28 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f29, (29 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f30, (30 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f31, (31 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + + ret + #endif // __i386__ diff --git a/util/misc/capture_context_test_util_linux.cc b/util/misc/capture_context_test_util_linux.cc index 35751bf8..55820b9e 100644 --- a/util/misc/capture_context_test_util_linux.cc +++ b/util/misc/capture_context_test_util_linux.cc @@ -35,6 +35,9 @@ void SanityCheckContext(const NativeCPUContext& context) { EXPECT_EQ(context.uc_mcontext.regs[0], FromPointerCast(&context)); #elif defined(ARCH_CPU_MIPS_FAMILY) EXPECT_EQ(context.uc_mcontext.gregs[4], FromPointerCast(&context)); +#elif defined(ARCH_CPU_RISCV64) + EXPECT_EQ(context.uc_mcontext.__gregs[10], + FromPointerCast(&context)); #endif } @@ -49,6 +52,8 @@ uintptr_t ProgramCounterFromContext(const NativeCPUContext& context) { return context.uc_mcontext.pc; #elif defined(ARCH_CPU_MIPS_FAMILY) return context.uc_mcontext.pc; +#elif defined(ARCH_CPU_RISCV64) + return context.uc_mcontext.__gregs[0]; #endif } @@ -63,6 +68,8 @@ uintptr_t StackPointerFromContext(const NativeCPUContext& context) { return context.uc_mcontext.sp; #elif defined(ARCH_CPU_MIPS_FAMILY) return context.uc_mcontext.gregs[29]; +#elif defined(ARCH_CPU_RISCV64) + return context.uc_mcontext.__gregs[2]; #endif } diff --git a/util/net/http_transport_libcurl.cc b/util/net/http_transport_libcurl.cc index d5c9177f..df63a772 100644 --- a/util/net/http_transport_libcurl.cc +++ b/util/net/http_transport_libcurl.cc @@ -237,6 +237,8 @@ std::string UserAgent() { #elif defined(ARCH_CPU_BIG_ENDIAN) static constexpr char arch[] = "aarch64_be"; #endif +#elif defined (ARCH_CPU_RISCV64) + static constexpr char arch[] = "riscv64"; #else #error Port #endif From 2cf938a41d43cab4d213c7452b963277f6fa2416 Mon Sep 17 00:00:00 2001 From: Thomas Gales Date: Fri, 9 Jun 2023 19:20:23 +0000 Subject: [PATCH 016/107] [riscv][fuchsia] Add RISC-V Fuchsia support Only RV64GC is supported. RISC-V Fuchsia is not able to serve packages yet so unit testing is not possible. Bug: fuchsia:127655 Tested: `crasher` with crashpad added to crashsvc, ran minidump through Breakpad stackwalker Change-Id: I1b6d79128759281aee348e333ea15434ab397001 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4602412 Reviewed-by: Mark Mentovai Reviewed-by: Joshua Peraza --- snapshot/fuchsia/cpu_context_fuchsia.cc | 46 +++++++++++ snapshot/fuchsia/cpu_context_fuchsia.h | 15 ++++ .../fuchsia/exception_snapshot_fuchsia.cc | 11 +++ snapshot/fuchsia/exception_snapshot_fuchsia.h | 2 + snapshot/fuchsia/process_reader_fuchsia.cc | 2 +- .../fuchsia/process_snapshot_fuchsia_test.cc | 2 +- snapshot/fuchsia/system_snapshot_fuchsia.cc | 4 + snapshot/fuchsia/thread_snapshot_fuchsia.cc | 5 ++ snapshot/fuchsia/thread_snapshot_fuchsia.h | 2 + util/misc/capture_context_fuchsia.S | 82 +++++++++++++++++++ .../misc/capture_context_test_util_fuchsia.cc | 7 ++ 11 files changed, 176 insertions(+), 2 deletions(-) diff --git a/snapshot/fuchsia/cpu_context_fuchsia.cc b/snapshot/fuchsia/cpu_context_fuchsia.cc index 9730a0a7..989bc463 100644 --- a/snapshot/fuchsia/cpu_context_fuchsia.cc +++ b/snapshot/fuchsia/cpu_context_fuchsia.cc @@ -103,6 +103,52 @@ void InitializeCPUContextARM64( memcpy(&context->fpsimd, &vector_context.v, sizeof(vector_context.v)); } +#elif defined(ARCH_CPU_RISCV64) + +void InitializeCPUContextRISCV64( + const zx_thread_state_general_regs_t& thread_context, + const zx_thread_state_fp_regs_t& float_context, + CPUContextRISCV64* context) { + context->pc = thread_context.pc; + context->regs[0] = thread_context.ra; + context->regs[1] = thread_context.sp; + context->regs[2] = thread_context.gp; + context->regs[3] = thread_context.tp; + context->regs[4] = thread_context.t0; + context->regs[5] = thread_context.t1; + context->regs[6] = thread_context.t2; + context->regs[7] = thread_context.s0; + context->regs[8] = thread_context.s1; + context->regs[9] = thread_context.a0; + context->regs[10] = thread_context.a1; + context->regs[11] = thread_context.a2; + context->regs[12] = thread_context.a3; + context->regs[13] = thread_context.a4; + context->regs[14] = thread_context.a5; + context->regs[15] = thread_context.a6; + context->regs[16] = thread_context.a7; + context->regs[17] = thread_context.s2; + context->regs[18] = thread_context.s3; + context->regs[19] = thread_context.s4; + context->regs[20] = thread_context.s5; + context->regs[21] = thread_context.s6; + context->regs[22] = thread_context.s7; + context->regs[23] = thread_context.s8; + context->regs[24] = thread_context.s9; + context->regs[25] = thread_context.s10; + context->regs[26] = thread_context.s11; + context->regs[27] = thread_context.t3; + context->regs[28] = thread_context.t4; + context->regs[29] = thread_context.t5; + context->regs[30] = thread_context.t6; + + for (size_t i = 0; i < std::size(context->fpregs); ++i) { + context->fpregs[i] = float_context.q[i].low; + } + + context->fcsr = float_context.fcsr; +} + #endif // ARCH_CPU_X86_64 } // namespace internal diff --git a/snapshot/fuchsia/cpu_context_fuchsia.h b/snapshot/fuchsia/cpu_context_fuchsia.h index 99bfa6f9..5d4cd8e8 100644 --- a/snapshot/fuchsia/cpu_context_fuchsia.h +++ b/snapshot/fuchsia/cpu_context_fuchsia.h @@ -57,6 +57,21 @@ void InitializeCPUContextARM64( #endif // ARCH_CPU_ARM64 || DOXYGEN +#if defined(ARCH_CPU_RISCV64) || DOXYGEN + +//! \brief Initializes a CPUContextRISCV64 structure from native context +//! structures on Fuchsia. +//! +//! \param[in] thread_context The native thread context. +//! \param[in] float_context The native floating point context. +//! \param[out] context The CPUContextRISCV64 structure to initialize. +void InitializeCPUContextRISCV64( + const zx_thread_state_general_regs_t& thread_context, + const zx_thread_state_fp_regs_t& float_context, + CPUContextRISCV64* context); + +#endif // ARCH_CPU_RISCV64 || DOXYGEN + } // namespace internal } // namespace crashpad diff --git a/snapshot/fuchsia/exception_snapshot_fuchsia.cc b/snapshot/fuchsia/exception_snapshot_fuchsia.cc index 017a6c67..be71ca22 100644 --- a/snapshot/fuchsia/exception_snapshot_fuchsia.cc +++ b/snapshot/fuchsia/exception_snapshot_fuchsia.cc @@ -42,6 +42,8 @@ bool ExceptionSnapshotFuchsia::Initialize( exception_info_ = exception_report.context.arch.u.x86_64.err_code; #elif defined(ARCH_CPU_ARM64) exception_info_ = exception_report.context.arch.u.arm_64.esr; +#elif defined(ARCH_CPU_RISCV64) + exception_info_ = exception_report.context.arch.u.riscv_64.cause; #endif codes_.push_back(exception_); @@ -52,6 +54,8 @@ bool ExceptionSnapshotFuchsia::Initialize( codes_.push_back(exception_report.context.arch.u.x86_64.cr2); #elif defined(ARCH_CPU_ARM64) codes_.push_back(exception_report.context.arch.u.arm_64.far); +#elif defined(ARCH_CPU_RISCV64) + codes_.push_back(exception_report.context.arch.u.riscv_64.tval); #endif const auto threads = process_reader->Threads(); @@ -78,6 +82,11 @@ bool ExceptionSnapshotFuchsia::Initialize( context_.arm64 = &context_arch_; InitializeCPUContextARM64( t->general_registers, t->vector_registers, context_.arm64); +#elif defined(ARCH_CPU_RISCV64) + context_.architecture = kCPUArchitectureRISCV64; + context_.riscv64 = &context_arch_; + InitializeCPUContextRISCV64( + t->general_registers, t->fp_registers, context_.riscv64); #else #error Port. #endif @@ -92,6 +101,8 @@ bool ExceptionSnapshotFuchsia::Initialize( exception_address_ = exception_report.context.arch.u.x86_64.cr2; #elif defined(ARCH_CPU_ARM64) exception_address_ = exception_report.context.arch.u.arm_64.far; +#elif defined(ARCH_CPU_RISCV64) + exception_address_ = exception_report.context.arch.u.riscv_64.tval; #else #error Port. #endif diff --git a/snapshot/fuchsia/exception_snapshot_fuchsia.h b/snapshot/fuchsia/exception_snapshot_fuchsia.h index 59f4d42b..2d9701f9 100644 --- a/snapshot/fuchsia/exception_snapshot_fuchsia.h +++ b/snapshot/fuchsia/exception_snapshot_fuchsia.h @@ -69,6 +69,8 @@ class ExceptionSnapshotFuchsia final : public ExceptionSnapshot { CPUContextX86_64 context_arch_; #elif defined(ARCH_CPU_ARM64) CPUContextARM64 context_arch_; +#elif defined(ARCH_CPU_RISCV64) + CPUContextRISCV64 context_arch_; #endif CPUContext context_; std::vector codes_; diff --git a/snapshot/fuchsia/process_reader_fuchsia.cc b/snapshot/fuchsia/process_reader_fuchsia.cc index 06f4c2e4..1c8464b1 100644 --- a/snapshot/fuchsia/process_reader_fuchsia.cc +++ b/snapshot/fuchsia/process_reader_fuchsia.cc @@ -40,7 +40,7 @@ void GetStackRegions( uint64_t sp; #if defined(ARCH_CPU_X86_64) sp = regs.rsp; -#elif defined(ARCH_CPU_ARM64) +#elif defined(ARCH_CPU_ARM64) || defined(ARCH_CPU_RISCV64) sp = regs.sp; #else #error Port diff --git a/snapshot/fuchsia/process_snapshot_fuchsia_test.cc b/snapshot/fuchsia/process_snapshot_fuchsia_test.cc index 7fcbb53c..af245d3e 100644 --- a/snapshot/fuchsia/process_snapshot_fuchsia_test.cc +++ b/snapshot/fuchsia/process_snapshot_fuchsia_test.cc @@ -200,7 +200,7 @@ class InvalidStackPointerTest : public MultiprocessExec { constexpr uint64_t kOffsetIntoMapping = 1024; #if defined(ARCH_CPU_X86_64) regs.rsp = address_of_large_mapping + kOffsetIntoMapping; -#elif defined(ARCH_CPU_ARM64) +#elif defined(ARCH_CPU_ARM64) || defined(ARCH_CPU_RISCV64) regs.sp = address_of_large_mapping + kOffsetIntoMapping; #else #error diff --git a/snapshot/fuchsia/system_snapshot_fuchsia.cc b/snapshot/fuchsia/system_snapshot_fuchsia.cc index b820ed96..31074820 100644 --- a/snapshot/fuchsia/system_snapshot_fuchsia.cc +++ b/snapshot/fuchsia/system_snapshot_fuchsia.cc @@ -45,6 +45,8 @@ void SystemSnapshotFuchsia::Initialize(const timeval* snapshot_time) { static constexpr const char kArch[] = "x86_64"; #elif defined(ARCH_CPU_ARM64) static constexpr const char kArch[] = "aarch64"; +#elif defined(ARCH_CPU_RISCV64) + static constexpr const char kArch[] = "riscv64"; #else static constexpr const char kArch[] = "unknown"; #endif @@ -61,6 +63,8 @@ CPUArchitecture SystemSnapshotFuchsia::GetCPUArchitecture() const { return kCPUArchitectureX86_64; #elif defined(ARCH_CPU_ARM64) return kCPUArchitectureARM64; +#elif defined(ARCH_CPU_RISCV64) + return kCPUArchitectureRISCV64; #else #error Port #endif diff --git a/snapshot/fuchsia/thread_snapshot_fuchsia.cc b/snapshot/fuchsia/thread_snapshot_fuchsia.cc index 0681ca27..75989525 100644 --- a/snapshot/fuchsia/thread_snapshot_fuchsia.cc +++ b/snapshot/fuchsia/thread_snapshot_fuchsia.cc @@ -48,6 +48,11 @@ bool ThreadSnapshotFuchsia::Initialize( context_.arm64 = &context_arch_; InitializeCPUContextARM64( thread.general_registers, thread.vector_registers, context_.arm64); +#elif defined(ARCH_CPU_RISCV64) + context_.architecture = kCPUArchitectureRISCV64; + context_.riscv64 = &context_arch_; + InitializeCPUContextRISCV64( + thread.general_registers, thread.fp_registers, context_.riscv64); #else #error Port. #endif diff --git a/snapshot/fuchsia/thread_snapshot_fuchsia.h b/snapshot/fuchsia/thread_snapshot_fuchsia.h index 8f5ebc72..84cac3df 100644 --- a/snapshot/fuchsia/thread_snapshot_fuchsia.h +++ b/snapshot/fuchsia/thread_snapshot_fuchsia.h @@ -69,6 +69,8 @@ class ThreadSnapshotFuchsia final : public ThreadSnapshot { CPUContextX86_64 context_arch_; #elif defined(ARCH_CPU_ARM64) CPUContextARM64 context_arch_; +#elif defined(ARCH_CPU_RISCV64) + CPUContextRISCV64 context_arch_; #else #error Port. #endif diff --git a/util/misc/capture_context_fuchsia.S b/util/misc/capture_context_fuchsia.S index 97954f02..a0bbd22f 100644 --- a/util/misc/capture_context_fuchsia.S +++ b/util/misc/capture_context_fuchsia.S @@ -24,6 +24,8 @@ .balign 16, 0x90 #elif defined(__aarch64__) .balign 4, 0x0 +#elif defined(__riscv) + .balign 4, 0x0 #endif CAPTURECONTEXT_SYMBOL: @@ -170,4 +172,84 @@ CAPTURECONTEXT_SYMBOL: ret +#elif defined(__riscv) + + #define MCONTEXT_GREGS_OFFSET 176 + + // x1/ra is the return address. Store it as the pc. + // The original x10/a0 can't be recovered. + sd x1, (0 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x1, (1 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x2, (2 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x3, (3 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x4, (4 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x5, (5 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x6, (6 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x7, (7 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x8, (8 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x9, (9 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x10, (10 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x11, (11 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x12, (12 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x13, (13 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x14, (14 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x15, (15 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x16, (16 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x17, (17 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x18, (18 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x19, (19 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x20, (20 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x21, (21 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x22, (22 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x23, (23 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x24, (24 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x25, (25 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x26, (26 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x27, (27 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x28, (28 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x29, (29 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x30, (30 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + sd x31, (31 * 8 + MCONTEXT_GREGS_OFFSET)(a0) + + #define MCONTEXT_FPREGS_OFFSET MCONTEXT_GREGS_OFFSET + 32*8 + + // Use x31/t6 as scratch register. + frcsr x31 + sw x31, (32 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + + fsd f0, (0 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f1, (1 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f2, (2 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f3, (3 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f4, (4 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f5, (5 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f6, (6 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f7, (7 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f8, (8 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f9, (9 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f10, (10 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f11, (11 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f12, (12 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f13, (13 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f14, (14 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f15, (15 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f16, (16 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f17, (17 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f18, (18 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f19, (19 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f20, (20 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f21, (21 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f22, (22 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f23, (23 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f24, (24 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f25, (25 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f26, (26 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f27, (27 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f28, (28 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f29, (29 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f30, (30 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + fsd f31, (31 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) + + ret + #endif // __x86_64__ diff --git a/util/misc/capture_context_test_util_fuchsia.cc b/util/misc/capture_context_test_util_fuchsia.cc index ef38afeb..57cc9d76 100644 --- a/util/misc/capture_context_test_util_fuchsia.cc +++ b/util/misc/capture_context_test_util_fuchsia.cc @@ -35,6 +35,9 @@ void SanityCheckContext(const NativeCPUContext& context) { FromPointerCast(&context)); #elif defined(ARCH_CPU_ARM64) EXPECT_EQ(context.uc_mcontext.regs[0], FromPointerCast(&context)); +#elif defined(ARCH_CPU_RISCV64) + EXPECT_EQ(context.uc_mcontext.__gregs[10], + FromPointerCast(&context)); #endif } @@ -43,6 +46,8 @@ uintptr_t ProgramCounterFromContext(const NativeCPUContext& context) { return context.uc_mcontext.gregs[REG_RIP]; #elif defined(ARCH_CPU_ARM64) return context.uc_mcontext.pc; +#elif defined(ARCH_CPU_RISCV64) + return context.uc_mcontext.__gregs[0]; #endif } @@ -51,6 +56,8 @@ uintptr_t StackPointerFromContext(const NativeCPUContext& context) { return context.uc_mcontext.gregs[REG_RSP]; #elif defined(ARCH_CPU_ARM64) return context.uc_mcontext.sp; +#elif defined(ARCH_CPU_RISCV64) + return context.uc_mcontext.__gregs[2]; #endif } From 9464ef52c71a587585f9cf49afd3c78170d2f7ef Mon Sep 17 00:00:00 2001 From: Thomas Gales Date: Tue, 13 Jun 2023 18:21:15 +0000 Subject: [PATCH 017/107] [fuchsia] Don't build crashpad_database_util Fuchsia does its own storage and upload now, so crashpad_database_util is no longer relevant to Fuchsia. Tested: Compiled for and in Fuchsia. Verified crashpad_database_util artifacts no longer produced. Change-Id: Ie20bb9b308b77bdd39924f5fe70f182c5c2a0782 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4610969 Reviewed-by: Joshua Peraza --- BUILD.gn | 5 ----- tools/BUILD.gn | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index db65cffc..83c4a32c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -123,11 +123,6 @@ if (crashpad_is_in_chromium || crashpad_is_in_fuchsia) { deps = _resources } - fuchsia_shell_package("crashpad-database-util") { - package_name = "crashpad_database_util" - deps = [ "tools:crashpad_database_util" ] - } - group("tests") { testonly = true diff --git a/tools/BUILD.gn b/tools/BUILD.gn index 3a042edd..845dab47 100644 --- a/tools/BUILD.gn +++ b/tools/BUILD.gn @@ -41,7 +41,7 @@ crashpad_executable("dump_minidump_annotations") { } } -if (!crashpad_is_ios) { +if (!crashpad_is_ios && !crashpad_is_fuchsia) { crashpad_executable("crashpad_database_util") { sources = [ "crashpad_database_util.cc" ] From a540e583ac6454fd6e61026c243342533cb37e06 Mon Sep 17 00:00:00 2001 From: Thomas Gales Date: Wed, 14 Jun 2023 21:43:46 +0000 Subject: [PATCH 018/107] [fuchsia] Remove/replace outdated bug references Fuchsia migrated issue tracking to fxbug.dev. It appears that DX-1193 did not get migrated. Fixed: 121707 Change-Id: I4a7fdf00aed223fedd8b66df87647a29139782a1 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4616910 Reviewed-by: Joshua Peraza --- snapshot/fuchsia/process_reader_fuchsia.cc | 3 +-- snapshot/fuchsia/system_snapshot_fuchsia.cc | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/snapshot/fuchsia/process_reader_fuchsia.cc b/snapshot/fuchsia/process_reader_fuchsia.cc index 1c8464b1..5f792838 100644 --- a/snapshot/fuchsia/process_reader_fuchsia.cc +++ b/snapshot/fuchsia/process_reader_fuchsia.cc @@ -234,7 +234,7 @@ void ProcessReaderFuchsia::InitializeModules() { // Crashpad needs to use the same module name at run time for symbol // resolution to work properly. // - // TODO(fuchsia/DX-1234): once Crashpad switches to elf-search, the + // TODO: https://fxbug.dev/6057 - once Crashpad switches to elf-search, the // following overwrites won't be necessary as only shared libraries will // have a soname at runtime, just like at build time. // @@ -265,7 +265,6 @@ void ProcessReaderFuchsia::InitializeModules() { if (dsoname.empty()) { // This value must be kept in sync with what is used at build time to // index symbols for executables and loadable modules. - // See fuchsia/DX-1193 for more details. module.name = "<_>"; module.type = ModuleSnapshot::kModuleTypeExecutable; } else { diff --git a/snapshot/fuchsia/system_snapshot_fuchsia.cc b/snapshot/fuchsia/system_snapshot_fuchsia.cc index 31074820..81a9d301 100644 --- a/snapshot/fuchsia/system_snapshot_fuchsia.cc +++ b/snapshot/fuchsia/system_snapshot_fuchsia.cc @@ -75,7 +75,7 @@ uint32_t SystemSnapshotFuchsia::CPURevision() const { #if defined(ARCH_CPU_X86_64) return cpuid_.Revision(); #else - // TODO(fuchsia/DX-712): Read actual revision. + // TODO: https://fxbug.dev/5561 - Read actual revision. return 0; #endif } @@ -90,7 +90,7 @@ std::string SystemSnapshotFuchsia::CPUVendor() const { #if defined(ARCH_CPU_X86_64) return cpuid_.Vendor(); #else - // TODO(fuchsia/DX-712): Read actual vendor. + // TODO: https://fxbug.dev/5561 - Read actual vendor. return std::string(); #endif } @@ -193,7 +193,7 @@ bool SystemSnapshotFuchsia::NXEnabled() const { #if defined(ARCH_CPU_X86_64) return cpuid_.NXEnabled(); #else - // TODO(fuchsia/DX-712): Read actual NX bit value. + // TODO: https://fxbug.dev/5561 - Read actual NX bit value. return false; #endif } From dcdccf56f24f40d49ef01ca0d67e570813a47a91 Mon Sep 17 00:00:00 2001 From: Thomas Gales Date: Thu, 15 Jun 2023 19:54:26 +0000 Subject: [PATCH 019/107] [fuchsia][arm64] Don't query for fp registers Fuchsia devices are failing to read floating point context for ARM because floating point registers are in the vector context for ARM. This CL prevents warning logs from being emitted in this situation. Fixed: fuchsia:129171 Tested: `fx shell crasher` @ 659207de7293cb30 Change-Id: I1d8d928da122aeb1bc4ac66b789cb638969d0fdf Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4617960 Reviewed-by: Joshua Peraza --- snapshot/fuchsia/process_reader_fuchsia.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/snapshot/fuchsia/process_reader_fuchsia.cc b/snapshot/fuchsia/process_reader_fuchsia.cc index 5f792838..89aa74d9 100644 --- a/snapshot/fuchsia/process_reader_fuchsia.cc +++ b/snapshot/fuchsia/process_reader_fuchsia.cc @@ -345,6 +345,8 @@ void ProcessReaderFuchsia::InitializeThreads() { } } +// Floating point registers are in the vector context for ARM. +#if !defined(ARCH_CPU_ARM64) zx_thread_state_fp_regs_t fp_regs; status = thread_handles[i].read_state( ZX_THREAD_STATE_FP_REGS, &fp_regs, sizeof(fp_regs)); @@ -354,6 +356,7 @@ void ProcessReaderFuchsia::InitializeThreads() { } else { thread.fp_registers = fp_regs; } +#endif zx_thread_state_vector_regs_t vector_regs; status = thread_handles[i].read_state( From 7e5b8ab50b2e1c4baada95774965386079f11306 Mon Sep 17 00:00:00 2001 From: Alex Gough Date: Fri, 23 Jun 2023 10:09:41 -0700 Subject: [PATCH 020/107] Disable fastfail end_to_end tests on Windows Something in how python is launching these tests changed and means that although fastfails in fastfail_test_program launch WerFault it is not looking for or finding the registered module, so crashpad_wer.dll isn't being loaded, so no crashes are there to be analyzed. Run individually the test programs do produce a crash, and Chrome continues to catch fast fails. Bug: crashpad:458 Change-Id: I52a6aa7aefb02d393c93c2c43ec67fc92b2bd0b0 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4637536 Commit-Queue: Alex Gough Reviewed-by: Mark Mentovai --- snapshot/win/end_to_end_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/snapshot/win/end_to_end_test.py b/snapshot/win/end_to_end_test.py index 136d5b9a..86da4651 100755 --- a/snapshot/win/end_to_end_test.py +++ b/snapshot/win/end_to_end_test.py @@ -542,7 +542,8 @@ def main(args): Run7zDumpTest(cdb_path, z7_dump_path) # __fastfail() & CFG crash caught by WerRuntimeExceptionHelperModule. - if (Win32_20H1()): + # TODO(crashpad:458) These are not working when launched from python. + if (False and Win32_20H1()): cfg_path = GetDumpFromFastFailProgram(args[0], pipe_name, "cf") if not cfg_path: return 1 From bc1e904f09c0e000a9fa9295e8c846c9863685c5 Mon Sep 17 00:00:00 2001 From: Alex Gough Date: Fri, 23 Jun 2023 13:33:37 -0700 Subject: [PATCH 021/107] SetErrorMode() in fastfail tests Some versions of python call SetErrorMode which disables WerFault handling for the fastfail test programs. We can set this to a useful value, allowing these tests to run again locally. This does not enable the tests on the bots as they continue to fail. Bug: crashpad:458 Change-Id: Ibdd2f92ed872bd76490db32dccb2257dd91f8280 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4641231 Reviewed-by: Mark Mentovai Commit-Queue: Alex Gough --- handler/win/fastfail_test_program.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/handler/win/fastfail_test_program.cc b/handler/win/fastfail_test_program.cc index 510ee56e..346aa68a 100644 --- a/handler/win/fastfail_test_program.cc +++ b/handler/win/fastfail_test_program.cc @@ -129,6 +129,10 @@ int CrashyMain(int argc, wchar_t* argv[]) { return EXIT_FAILURE; } + // Some versions of python call SetErrorMode() which extends to children, and + // prevents the WerFault infrastructure from running. + SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); + if (type == L"cf") CfgCrash(); if (type == L"ff") From a5e179663a3876ed652b0bc8631abab2ba9334a2 Mon Sep 17 00:00:00 2001 From: Alex Gough Date: Fri, 23 Jun 2023 14:53:06 -0700 Subject: [PATCH 022/107] Catch heap corruption failures on Windows Windows claims that heap corruption crashes are passed to Windows Error Reporting but they are not, they are swallowed and the process is simply terminated. WerFault.exe does not run. We can however intercept these crashes using a vectored exception handler which forwards STATUS_HEAP_CORRUPTION to the normal crash handler. Adds an end-to-end test. Bug: 2515 Change-Id: I2e1361dacef6fd03ea0f00327fee0b05a0c4899e Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4637533 Commit-Queue: Alex Gough Reviewed-by: Joshua Peraza --- client/crashpad_client_win.cc | 19 ++++++ handler/BUILD.gn | 18 ++++- handler/win/heap_corrupting_program.cc | 95 ++++++++++++++++++++++++++ snapshot/win/end_to_end_test.py | 19 ++++++ 4 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 handler/win/heap_corrupting_program.cc diff --git a/client/crashpad_client_win.cc b/client/crashpad_client_win.cc index 3de50779..37469b20 100644 --- a/client/crashpad_client_win.cc +++ b/client/crashpad_client_win.cc @@ -187,6 +187,15 @@ LONG WINAPI UnhandledExceptionHandler(EXCEPTION_POINTERS* exception_pointers) { return EXCEPTION_CONTINUE_SEARCH; } +LONG WINAPI HandleHeapCorruption(EXCEPTION_POINTERS* exception_pointers) { + if (exception_pointers->ExceptionRecord->ExceptionCode == + STATUS_HEAP_CORRUPTION) { + return UnhandledExceptionHandler(exception_pointers); + } + + return EXCEPTION_CONTINUE_SEARCH; +} + void HandleAbortSignal(int signum) { DCHECK_EQ(signum, SIGABRT); @@ -580,6 +589,16 @@ void CommonInProcessInitialization() { void RegisterHandlers() { SetUnhandledExceptionFilter(&UnhandledExceptionHandler); + // Windows swallows heap corruption failures but we can intercept them with + // a vectored exception handler. +#if defined(ADDRESS_SANITIZER) + // Let ASAN have first go. + bool go_first = false; +#else + bool go_first = true; +#endif + AddVectoredExceptionHandler(go_first, HandleHeapCorruption); + // The Windows CRT's signal.h lists: // - SIGINT // - SIGILL diff --git a/handler/BUILD.gn b/handler/BUILD.gn index 02bf11a6..7cab5191 100644 --- a/handler/BUILD.gn +++ b/handler/BUILD.gn @@ -49,10 +49,9 @@ static_library("handler") { "linux/cros_crash_report_exception_handler.cc", "linux/cros_crash_report_exception_handler.h", ] + # TODO(https://crbug.com/1420445): Remove this config when M115 branches. - configs += [ - "../build:crashpad_is_in_chromium", - ] + configs += [ "../build:crashpad_is_in_chromium" ] } if (crashpad_is_win) { @@ -346,6 +345,19 @@ if (crashpad_is_win) { ] } + crashpad_executable("heap_corrupting_program") { + testonly = true + + sources = [ "win/heap_corrupting_program.cc" ] + + deps = [ + "../client", + "../compat", + "../snapshot", + "../third_party/mini_chromium:base", + ] + } + if (current_cpu == "x86") { # Cannot create an x64 DLL with embedded debug info. crashpad_executable("crashy_z7_loader") { diff --git a/handler/win/heap_corrupting_program.cc b/handler/win/heap_corrupting_program.cc new file mode 100644 index 00000000..6c7c2cd5 --- /dev/null +++ b/handler/win/heap_corrupting_program.cc @@ -0,0 +1,95 @@ +// Copyright 2023 The Crashpad Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include "base/files/file_path.h" +#include "base/logging.h" +#include "client/crashpad_client.h" +#include "util/misc/paths.h" + +#include + +// We set up a program that crashes with a heap corruption exception. +// STATUS_HEAP_CORRUPTION (0xC0000374 3221226356). +namespace crashpad { +namespace { + +void HeapCorruptionCrash() { + __try { + HANDLE heap = ::HeapCreate(0, 0, 0); + CHECK(heap); + CHECK(HeapSetInformation( + heap, HeapEnableTerminationOnCorruption, nullptr, 0)); + void* addr = ::HeapAlloc(heap, 0, 0x1000); + CHECK(addr); + // Corrupt heap header. + char* addr_mutable = reinterpret_cast(addr); + memset(addr_mutable - sizeof(addr), 0xCC, sizeof(addr)); + + HeapFree(heap, 0, addr); + HeapDestroy(heap); + } __except (EXCEPTION_EXECUTE_HANDLER) { + // Heap corruption exception should never be caught. + CHECK(false); + } + // Should never reach here. + abort(); +} + +int CrashyMain(int argc, wchar_t* argv[]) { + static CrashpadClient* client = new crashpad::CrashpadClient(); + + if (argc == 2) { + // We call this from end_to_end_test.py. + if (!client->SetHandlerIPCPipe(argv[1])) { + LOG(ERROR) << "SetHandler"; + return EXIT_FAILURE; + } + } else if (argc == 3) { + // This is helpful for debugging. + if (!client->StartHandler(base::FilePath(argv[1]), + base::FilePath(argv[2]), + base::FilePath(), + std::string(), + std::map(), + std::vector(), + false, + true)) { + LOG(ERROR) << "StartHandler"; + return EXIT_FAILURE; + } + // Got to have a handler & registration. + if (!client->WaitForHandlerStart(10000)) { + LOG(ERROR) << "Handler failed to start"; + return EXIT_FAILURE; + } + } else { + fprintf(stderr, "Usage: %ls \n", argv[0]); + fprintf(stderr, " %ls \n", argv[0]); + return EXIT_FAILURE; + } + + HeapCorruptionCrash(); + + LOG(ERROR) << "Invalid type or exception failed."; + return EXIT_FAILURE; +} + +} // namespace +} // namespace crashpad + +int wmain(int argc, wchar_t* argv[]) { + return crashpad::CrashyMain(argc, argv); +} diff --git a/snapshot/win/end_to_end_test.py b/snapshot/win/end_to_end_test.py index 86da4651..25f661c1 100755 --- a/snapshot/win/end_to_end_test.py +++ b/snapshot/win/end_to_end_test.py @@ -212,6 +212,12 @@ def GetDumpFromZ7Program(out_dir, pipe_name): win32con.EXCEPTION_ACCESS_VIOLATION) +def GetDumpFromHeapCorruptingProgram(out_dir, pipe_name): + STATUS_HEAP_CORRUPTION = 0xC0000374 + return GetDumpFromProgram(out_dir, pipe_name, 'heap_corrupting_program.exe', + STATUS_HEAP_CORRUPTION) + + def GetDumpFromFastFailProgram(out_dir, pipe_name, *args): STATUS_STACK_BUFFER_OVERRUN = 0xc0000409 return GetDumpFromProgram(out_dir, pipe_name, 'fastfail_program.exe', @@ -444,6 +450,14 @@ def RunSigAbrtTest(cdb_path, sigabrt_main_path, sigabrt_background_path): out.Check('code 40000015', 'got sigabrt signal from background thread') +def RunHeapCorruptionTest(cdb_path, heap_path): + """Runs tests on heap corruption caught using the vectored handler.""" + out = CdbRun(cdb_path, heap_path, '.ecxr;k') + out.Check('code c0000374', 'captured exception from heap corruption crash') + out.Check('::HeapCorruptionCrash', 'See expected throwing function') + out = CdbRun(cdb_path, heap_path, '.ecxr;k') + + def RunFastFailDumpTest(cdb_path, fastfail_path): """Runs tests on __fastfail() caught using the runtime exception helper.""" out = CdbRun(cdb_path, fastfail_path, '.ecxr;k') @@ -541,6 +555,11 @@ def main(args): return 1 Run7zDumpTest(cdb_path, z7_dump_path) + heap_path = GetDumpFromHeapCorruptingProgram(args[0], pipe_name) + if not heap_path: + return 1 + RunHeapCorruptionTest(cdb_path, heap_path) + # __fastfail() & CFG crash caught by WerRuntimeExceptionHelperModule. # TODO(crashpad:458) These are not working when launched from python. if (False and Win32_20H1()): From 87e1883047fcf0a5a6bc4fb677893ca9fa2d28b6 Mon Sep 17 00:00:00 2001 From: Chong Gu Date: Wed, 28 Jun 2023 20:08:55 +0000 Subject: [PATCH 023/107] [Fuchsia] Replace checking out gn SDK with core The gen_build_defs.py file is lightly modified from the original one in https://source.chromium.org/chromium/chromium/src/+/main:build/fuchsia/gen_build_defs.py to accommodate for the fact that the SDK gets downloaded into a different folder in crashpad Bug: chromium:1432399 Change-Id: I2c5a5337220b6aca138ca6eb1c37895ca32e72cd Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4600615 Commit-Queue: Chong Gu Reviewed-by: Joshua Peraza --- DEPS | 18 +- build/fuchsia/gen_build_defs.py | 350 ++++++++++++++++++++++++++++++++ 2 files changed, 366 insertions(+), 2 deletions(-) create mode 100755 build/fuchsia/gen_build_defs.py diff --git a/DEPS b/DEPS index 95d01aa9..9258a579 100644 --- a/DEPS +++ b/DEPS @@ -116,10 +116,15 @@ deps = { 'condition': 'checkout_fuchsia and host_os == "linux"', 'dep_type': 'cipd' }, + 'crashpad/third_party/fuchsia-gn-sdk': { + 'url': Var('chromium_git') + '/chromium/src/third_party/fuchsia-gn-sdk.git@' + + '0d6902558d92fe3d49ba9a8f638ddea829be595b', + 'condition': 'checkout_fuchsia', + }, 'crashpad/third_party/fuchsia/sdk/mac-amd64': { 'packages': [ { - 'package': 'fuchsia/sdk/gn/mac-amd64', + 'package': 'fuchsia/sdk/core/mac-amd64', 'version': 'latest' }, ], @@ -129,7 +134,7 @@ deps = { 'crashpad/third_party/fuchsia/sdk/linux-amd64': { 'packages': [ { - 'package': 'fuchsia/sdk/gn/linux-amd64', + 'package': 'fuchsia/sdk/core/linux-amd64', 'version': 'latest' }, ], @@ -249,6 +254,15 @@ hooks = [ 'crashpad/build/install_linux_sysroot.py', ], }, + { + 'name': 'Generate Fuchsia Build Definitions', + 'pattern': '.', + 'condition': 'checkout_fuchsia', + 'action': [ + 'python3', + 'crashpad/build/fuchsia/gen_build_defs.py' + ], + }, { 'name': 'setup_gn_ios', 'pattern': '.', diff --git a/build/fuchsia/gen_build_defs.py b/build/fuchsia/gen_build_defs.py new file mode 100755 index 00000000..22414d1c --- /dev/null +++ b/build/fuchsia/gen_build_defs.py @@ -0,0 +1,350 @@ +#!/usr/bin/env vpython3 +# Copyright 2023 The Chromium Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# Generates a single BUILD.gn file with build targets generated using the +# manifest files in the SDK. + +import json +import logging +import os +import shutil +import sys + + +DIR_SRC_ROOT = os.path.abspath( + os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) + +def GetHostOS(): + """Get host operating system.""" + + host_platform = sys.platform + if host_platform.startswith('linux'): + return 'linux' + if host_platform.startswith('darwin'): + return 'mac' + raise Exception('Unsupported host platform: %s' % host_platform) + + +# Inserted at the top of the generated BUILD.gn file. +_GENERATED_PREAMBLE = """# DO NOT EDIT! This file was generated by +# //build/fuchsia/gen_build_def.py. +# Any changes made to this file will be discarded. + +import("//third_party/fuchsia/sdk/{host_os}-amd64/build/fidl_library.gni") +import("//third_party/fuchsia/sdk/{host_os}-amd64/build/fuchsia_sdk_pkg.gni") + +""".format(host_os=GetHostOS()) + +SDK_ROOT = os.path.join(DIR_SRC_ROOT, 'third_party', 'fuchsia', 'sdk', + f'{GetHostOS()}-amd64') + + +def ReformatTargetName(dep_name): + """"Substitutes characters in |dep_name| which are not valid in GN target + names (e.g. dots become hyphens).""" + return dep_name + + +def FormatGNTarget(fields): + """Returns a GN target definition as a string. + + |fields|: The GN fields to include in the target body. + 'target_name' and 'type' are mandatory.""" + + output = '%s("%s") {\n' % (fields['type'], fields['target_name']) + del fields['target_name'] + del fields['type'] + + # Ensure that fields with no ordering requirement are sorted. + for field in ['sources', 'public_deps']: + if field in fields: + fields[field].sort() + + for key, val in fields.items(): + if isinstance(val, str): + val_serialized = '\"%s\"' % val + elif isinstance(val, list): + # Serialize a list of strings in the prettiest possible manner. + if len(val) == 0: + val_serialized = '[]' + elif len(val) == 1: + val_serialized = '[ \"%s\" ]' % val[0] + else: + val_serialized = '[\n ' + ',\n '.join(['\"%s\"' % x + for x in val]) + '\n ]' + else: + raise Exception('Could not serialize %r' % val) + + output += ' %s = %s\n' % (key, val_serialized) + output += '}' + + return output + + +def MetaRootRelativePaths(sdk_relative_paths, meta_root): + return [os.path.relpath(path, meta_root) for path in sdk_relative_paths] + + +def ConvertCommonFields(json): + """Extracts fields from JSON manifest data which are used across all + target types. Note that FIDL packages do their own processing.""" + + meta_root = json['root'] + + converted = {'target_name': ReformatTargetName(json['name'])} + + if 'deps' in json: + converted['public_deps'] = MetaRootRelativePaths(json['deps'], + os.path.dirname(meta_root)) + + # FIDL bindings dependencies are relative to the "fidl" sub-directory. + if 'fidl_binding_deps' in json: + for entry in json['fidl_binding_deps']: + converted['public_deps'] += MetaRootRelativePaths([ + 'fidl/' + dep + ':' + os.path.basename(dep) + '_' + + entry['binding_type'] for dep in entry['deps'] + ], meta_root) + + return converted + + +def ConvertFidlLibrary(json): + """Converts a fidl_library manifest entry to a GN target. + + Arguments: + json: The parsed manifest JSON. + Returns: + The GN target definition, represented as a string.""" + + meta_root = json['root'] + + converted = ConvertCommonFields(json) + converted['type'] = 'fidl_library' + converted['sources'] = MetaRootRelativePaths(json['sources'], meta_root) + converted['library_name'] = json['name'] + + return converted + + +def ConvertCcPrebuiltLibrary(json): + """Converts a cc_prebuilt_library manifest entry to a GN target. + + Arguments: + json: The parsed manifest JSON. + Returns: + The GN target definition, represented as a string.""" + + meta_root = json['root'] + + converted = ConvertCommonFields(json) + converted['type'] = 'fuchsia_sdk_pkg' + + converted['sources'] = MetaRootRelativePaths(json['headers'], meta_root) + + converted['include_dirs'] = MetaRootRelativePaths([json['include_dir']], + meta_root) + + if json['format'] == 'shared': + converted['shared_libs'] = [json['name']] + else: + converted['static_libs'] = [json['name']] + + return converted + + +def ConvertCcSourceLibrary(json): + """Converts a cc_source_library manifest entry to a GN target. + + Arguments: + json: The parsed manifest JSON. + Returns: + The GN target definition, represented as a string.""" + + meta_root = json['root'] + + converted = ConvertCommonFields(json) + converted['type'] = 'fuchsia_sdk_pkg' + + # Headers and source file paths can be scattered across "sources", "headers", + # and "files". Merge them together into one source list. + converted['sources'] = MetaRootRelativePaths(json['sources'], meta_root) + if 'headers' in json: + converted['sources'] += MetaRootRelativePaths(json['headers'], meta_root) + if 'files' in json: + converted['sources'] += MetaRootRelativePaths(json['files'], meta_root) + converted['sources'] = list(set(converted['sources'])) + + converted['include_dirs'] = MetaRootRelativePaths([json['include_dir']], + meta_root) + + return converted + + +def ConvertLoadableModule(json): + """Converts a loadable module manifest entry to GN targets. + + Arguments: + json: The parsed manifest JSON. + Returns: + A list of GN target definitions.""" + + name = json['name'] + if name != 'vulkan_layers': + raise RuntimeError('Unsupported loadable_module: %s' % name) + + # Copy resources and binaries + resources = json['resources'] + + binaries = json['binaries'] + + def _filename_no_ext(name): + return os.path.splitext(os.path.basename(name))[0] + + # Pair each json resource with its corresponding binary. Each such pair + # is a "layer". We only need to check one arch because each arch has the + # same list of binaries. + arch = next(iter(binaries)) + binary_names = binaries[arch] + local_pkg = json['root'] + vulkan_targets = [] + + for res in resources: + layer_name = _filename_no_ext(res) + + # Filter binaries for a matching name. + filtered = [n for n in binary_names if _filename_no_ext(n) == layer_name] + + if not filtered: + # If the binary could not be found then do not generate a + # target for this layer. The missing targets will cause a + # mismatch with the "golden" outputs. + continue + + # Replace hardcoded arch in the found binary filename. + binary = filtered[0].replace('/' + arch + '/', "/${target_cpu}/") + + target = {} + target['name'] = layer_name + target['config'] = os.path.relpath(res, start=local_pkg) + target['binary'] = os.path.relpath(binary, start=local_pkg) + + vulkan_targets.append(target) + + converted = [] + all_target = {} + all_target['target_name'] = 'all' + all_target['type'] = 'group' + all_target['data_deps'] = [] + for target in vulkan_targets: + config_target = {} + config_target['target_name'] = target['name'] + '_config' + config_target['type'] = 'copy' + config_target['sources'] = [target['config']] + config_target['outputs'] = ['${root_gen_dir}/' + target['config']] + converted.append(config_target) + lib_target = {} + lib_target['target_name'] = target['name'] + '_lib' + lib_target['type'] = 'copy' + lib_target['sources'] = [target['binary']] + lib_target['outputs'] = ['${root_out_dir}/lib/{{source_file_part}}'] + converted.append(lib_target) + group_target = {} + group_target['target_name'] = target['name'] + group_target['type'] = 'group' + group_target['data_deps'] = [ + ':' + target['name'] + '_config', ':' + target['name'] + '_lib' + ] + converted.append(group_target) + all_target['data_deps'].append(':' + target['name']) + converted.append(all_target) + return converted + + +def ConvertNoOp(json): + """Null implementation of a conversion function. No output is generated.""" + + return None + + +"""Maps manifest types to conversion functions.""" +_CONVERSION_FUNCTION_MAP = { + 'fidl_library': ConvertFidlLibrary, + 'cc_source_library': ConvertCcSourceLibrary, + 'cc_prebuilt_library': ConvertCcPrebuiltLibrary, + 'loadable_module': ConvertLoadableModule, + + # No need to build targets for these types yet. + 'companion_host_tool': ConvertNoOp, + 'component_manifest': ConvertNoOp, + 'config': ConvertNoOp, + 'dart_library': ConvertNoOp, + 'data': ConvertNoOp, + 'device_profile': ConvertNoOp, + 'documentation': ConvertNoOp, + 'ffx_tool': ConvertNoOp, + 'host_tool': ConvertNoOp, + 'image': ConvertNoOp, + 'sysroot': ConvertNoOp, +} + + +def ConvertMeta(meta_path): + parsed = json.load(open(meta_path)) + if 'type' not in parsed: + return + + convert_function = _CONVERSION_FUNCTION_MAP.get(parsed['type']) + if convert_function is None: + logging.warning('Unexpected SDK artifact type %s in %s.' % + (parsed['type'], meta_path)) + return + + converted = convert_function(parsed) + if not converted: + return + output_path = os.path.join(os.path.dirname(meta_path), 'BUILD.gn') + if os.path.exists(output_path): + os.unlink(output_path) + with open(output_path, 'w') as buildfile: + buildfile.write(_GENERATED_PREAMBLE) + + # Loadable modules have multiple targets + if convert_function != ConvertLoadableModule: + buildfile.write(FormatGNTarget(converted) + '\n\n') + else: + for target in converted: + buildfile.write(FormatGNTarget(target) + '\n\n') + + +def ProcessSdkManifest(): + toplevel_meta = json.load( + open(os.path.join(SDK_ROOT, 'meta', 'manifest.json'))) + + for part in toplevel_meta['parts']: + meta_path = os.path.join(SDK_ROOT, part['meta']) + ConvertMeta(meta_path) + + +def main(): + + # Exit if there's no Fuchsia support for this platform. + try: + GetHostOS() + except: + logging.warning('Fuchsia SDK is not supported on this platform.') + return 0 + + # TODO(crbug/1432399): Remove this when links to these files inside the sdk + # directory have been redirected. + shutil.copytree(os.path.join(DIR_SRC_ROOT, 'third_party', 'fuchsia-gn-sdk', + 'src'), + os.path.join(SDK_ROOT, 'build'), + dirs_exist_ok=True) + + ProcessSdkManifest() + + +if __name__ == '__main__': + sys.exit(main()) From 9e37dc46b62c3a0509f80f56db5d3993587243e5 Mon Sep 17 00:00:00 2001 From: Avi Drissman Date: Fri, 30 Jun 2023 11:39:44 -0400 Subject: [PATCH 024/107] Convert Crashpad to use ARC See https://chromium.googlesource.com/chromium/src/+/main/docs/mac/arc.md for information about this conversion. Bug: chromium:1280726 Change-Id: I9ed10e9a255eb6b13035b05bcc587c4b6cb7b78e Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4651106 Reviewed-by: Mark Mentovai Commit-Queue: Mark Mentovai Reviewed-by: Mark Mentovai --- DEPS | 2 +- build/BUILD.gn | 14 +++--- build/crashpad_buildconfig.gni | 2 + client/BUILD.gn | 20 ++++++-- client/crash_report_database_mac.mm | 4 ++ client/crashpad_client_ios_test.mm | 4 ++ client/ios_handler/exception_processor.mm | 12 +++-- .../ios_handler/exception_processor_test.mm | 4 ++ compat/BUILD.gn | 6 +-- handler/BUILD.gn | 2 +- snapshot/BUILD.gn | 2 +- test/BUILD.gn | 16 +++--- test/ios/BUILD.gn | 6 +-- test/ios/host/BUILD.gn | 4 +- third_party/edo/BUILD.gn | 2 +- tools/BUILD.gn | 20 ++++---- tools/mac/on_demand_service_tool.mm | 10 ++-- util/BUILD.gn | 31 +++++++----- util/ios/ios_system_data_collector.mm | 4 ++ util/mac/launchd.mm | 22 ++++---- util/mac/launchd_test.mm | 50 ++++++++++++------- util/mac/mac_util_test.mm | 9 ++-- util/mac/service_management_test.mm | 8 ++- util/net/http_transport_mac.mm | 22 ++++---- 24 files changed, 174 insertions(+), 102 deletions(-) diff --git a/DEPS b/DEPS index 9258a579..3b97d622 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - 'f0eebea8bd59215be300ffbe5e7883e85a6fdc0e', + 'e009af846ef4790a90d69fe13ed54df25b93fdef', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', diff --git a/build/BUILD.gn b/build/BUILD.gn index 49a2afa3..3763d2e1 100644 --- a/build/BUILD.gn +++ b/build/BUILD.gn @@ -31,9 +31,8 @@ config("crashpad_is_in_fuchsia") { } config("flock_always_supported_defines") { - defines = [ - "CRASHPAD_FLOCK_ALWAYS_SUPPORTED=$crashpad_flock_always_supported", - ] + defines = + [ "CRASHPAD_FLOCK_ALWAYS_SUPPORTED=$crashpad_flock_always_supported" ] } group("default_exe_manifest_win") { @@ -52,16 +51,17 @@ config("crashpad_fuzzer_flags") { ldflags = [ "-fsanitize=address" ] } -if (crashpad_is_ios) { - group("ios_enable_arc") { +if (crashpad_is_apple) { + group("apple_enable_arc") { if (crashpad_is_in_chromium) { public_configs = [ "//build/config/compiler:enable_arc" ] } else if (crashpad_is_standalone) { - public_configs = - [ "//third_party/mini_chromium/mini_chromium/build/config:ios_enable_arc" ] + public_configs = [ "//third_party/mini_chromium/mini_chromium/build/config:apple_enable_arc" ] } } +} +if (crashpad_is_ios) { group("ios_xctest") { if (crashpad_is_in_chromium) { public_configs = [ "//build/config/ios:xctest_config" ] diff --git a/build/crashpad_buildconfig.gni b/build/crashpad_buildconfig.gni index 3de3f8db..4e9091a2 100644 --- a/build/crashpad_buildconfig.gni +++ b/build/crashpad_buildconfig.gni @@ -59,6 +59,7 @@ if (crashpad_is_external || crashpad_is_in_dart) { if (crashpad_is_in_chromium) { crashpad_is_mac = is_mac crashpad_is_ios = is_ios + crashpad_is_apple = is_apple crashpad_is_win = is_win crashpad_is_linux = is_linux || is_chromeos crashpad_is_android = is_android @@ -73,6 +74,7 @@ if (crashpad_is_in_chromium) { crashpad_is_mac = mini_chromium_is_mac crashpad_is_ios = mini_chromium_is_ios + crashpad_is_apple = mini_chromium_is_apple crashpad_is_win = mini_chromium_is_win crashpad_is_linux = mini_chromium_is_linux crashpad_is_android = mini_chromium_is_android diff --git a/client/BUILD.gn b/client/BUILD.gn index 5c71dcc9..bc67b32f 100644 --- a/client/BUILD.gn +++ b/client/BUILD.gn @@ -89,6 +89,10 @@ crashpad_static_library("client") { cflags = [ "/wd4201" ] # nonstandard extension used : nameless struct/union } + if (crashpad_is_apple) { + deps += [ "../build:apple_enable_arc" ] + } + if (crashpad_is_ios) { deps += [ "../handler:common", @@ -127,7 +131,7 @@ static_library("common") { "simple_string_dictionary.h", ] - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { sources += [ "crash_report_database_mac.mm" ] } if (crashpad_is_win) { @@ -147,17 +151,19 @@ static_library("common") { ] deps = [ "../util" ] configs += [ "../build:flock_always_supported_defines" ] + + if (crashpad_is_apple) { + deps += [ "../build:apple_enable_arc" ] + } } crashpad_executable("ring_buffer_annotation_load_test") { testonly = true - sources = [ - "ring_buffer_annotation_load_test_main.cc", - ] + sources = [ "ring_buffer_annotation_load_test_main.cc" ] deps = [ ":client", - "../tools:tool_support", "$mini_chromium_source_parent:base", + "../tools:tool_support", ] } @@ -212,6 +218,10 @@ source_set("client_test") { data_deps = [ "../handler:crashpad_handler" ] } + if (crashpad_is_apple) { + deps += [ "../build:apple_enable_arc" ] + } + if (crashpad_is_win) { data_deps += [ "../handler:crashpad_handler_console", diff --git a/client/crash_report_database_mac.mm b/client/crash_report_database_mac.mm index 7221b595..d3bf9850 100644 --- a/client/crash_report_database_mac.mm +++ b/client/crash_report_database_mac.mm @@ -49,6 +49,10 @@ #include "util/ios/scoped_background_task.h" #endif // BUILDFLAG(IS_IOS) +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { namespace { diff --git a/client/crashpad_client_ios_test.mm b/client/crashpad_client_ios_test.mm index 29f3df65..409de95b 100644 --- a/client/crashpad_client_ios_test.mm +++ b/client/crashpad_client_ios_test.mm @@ -27,6 +27,10 @@ #include "testing/platform_test.h" #include "util/thread/thread.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { namespace test { namespace { diff --git a/client/ios_handler/exception_processor.mm b/client/ios_handler/exception_processor.mm index e0b0dcf2..920825dc 100644 --- a/client/ios_handler/exception_processor.mm +++ b/client/ios_handler/exception_processor.mm @@ -54,6 +54,10 @@ #include "client/annotation.h" #include "client/simulate_crash_ios.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { namespace { @@ -65,7 +69,7 @@ Class cls_unremapped; }; struct objc_exception { - id obj; + id __unsafe_unretained obj; objc_typeinfo tinfo; }; @@ -219,7 +223,7 @@ id HandleUncaughtException(NativeCPUContext* cpu_context, id exception) { // preprocessor didn't catch anything, so pass the frames or just the context // to the exception_delegate. void FinalizeUncaughtNSException(id exception) { - if (last_exception() == exception && + if (last_exception() == (__bridge void*)exception && !last_handled_intermediate_dump_.empty() && exception_delegate_->MoveIntermediateDumpAtPathToPending( last_handled_intermediate_dump_)) { @@ -331,10 +335,10 @@ id ObjcExceptionPreprocessor(id exception) { // ignore it. ExceptionPreprocessorState* preprocessor_state = ExceptionPreprocessorState::Get(); - if (preprocessor_state->last_exception() == exception) { + if (preprocessor_state->last_exception() == (__bridge void*)exception) { return preprocessor_state->MaybeCallNextPreprocessor(exception); } - preprocessor_state->set_last_exception(exception); + preprocessor_state->set_last_exception((__bridge void*)exception); static bool seen_first_exception; diff --git a/client/ios_handler/exception_processor_test.mm b/client/ios_handler/exception_processor_test.mm index 8be70890..ad5ea7b6 100644 --- a/client/ios_handler/exception_processor_test.mm +++ b/client/ios_handler/exception_processor_test.mm @@ -19,6 +19,10 @@ #include "gtest/gtest.h" #include "testing/platform_test.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { namespace test { namespace { diff --git a/compat/BUILD.gn b/compat/BUILD.gn index 63cfa6eb..d75c26e1 100644 --- a/compat/BUILD.gn +++ b/compat/BUILD.gn @@ -17,7 +17,7 @@ import("../build/crashpad_buildconfig.gni") config("compat_config") { include_dirs = [] - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { include_dirs += [ "mac" ] } @@ -41,7 +41,7 @@ config("compat_config") { } template("compat_target") { - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { # There are no sources to compile, which doesn’t mix will with a # static_library. group(target_name) { @@ -64,7 +64,7 @@ template("compat_target") { compat_target("compat") { sources = [] - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { sources += [ "mac/Availability.h", "mac/AvailabilityVersions.h", diff --git a/handler/BUILD.gn b/handler/BUILD.gn index 7cab5191..a2d6f7fb 100644 --- a/handler/BUILD.gn +++ b/handler/BUILD.gn @@ -100,7 +100,7 @@ static_library("common") { "minidump_to_upload_parameters.cc", "minidump_to_upload_parameters.h", ] - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { sources += [ "mac/file_limit_annotation.cc", "mac/file_limit_annotation.h", diff --git a/snapshot/BUILD.gn b/snapshot/BUILD.gn index 044f33db..a364f956 100644 --- a/snapshot/BUILD.gn +++ b/snapshot/BUILD.gn @@ -566,7 +566,7 @@ if ((crashpad_is_linux || crashpad_is_android || crashpad_is_fuchsia) && } } -if (crashpad_is_mac || crashpad_is_ios) { +if (crashpad_is_apple) { crashpad_loadable_module("crashpad_snapshot_test_module_crashy_initializer") { testonly = true sources = [ diff --git a/test/BUILD.gn b/test/BUILD.gn index bf21bfee..f20c66f2 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -61,12 +61,10 @@ static_library("test") { # TODO(crbug.com/812974): Remove !crashpad_is_fuchsia when Fuchsia is no # longer treated as a posix platform. if (crashpad_is_posix && !crashpad_is_fuchsia) { - sources += [ - "scoped_set_thread_name_posix.cc", - ] + sources += [ "scoped_set_thread_name_posix.cc" ] } - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { sources += [ "mac/mach_errors.cc", "mac/mach_errors.h", @@ -135,9 +133,9 @@ static_library("test") { data = [ "test_paths_test_data_root.txt" ] deps = [ + "$mini_chromium_source_parent:base", "../compat", "../third_party/googletest:googletest", - "$mini_chromium_source_parent:base", "../util", ] @@ -214,10 +212,10 @@ source_set("test_test") { deps = [ ":test", + "$mini_chromium_source_parent:base", "../compat", "../third_party/googletest:googlemock", "../third_party/googletest:googletest", - "$mini_chromium_source_parent:base", "../util", ] @@ -243,10 +241,10 @@ static_library("googlemock_main") { defines = [ "CRASHPAD_TEST_LAUNCHER_GOOGLEMOCK" ] deps = [ ":test", - "../third_party/googletest:googlemock", - "../third_party/googletest:googletest", "$mini_chromium_source_parent:base", "$mini_chromium_source_parent:base_test_support", + "../third_party/googletest:googlemock", + "../third_party/googletest:googletest", ] if (crashpad_is_android) { deps += [ "../util" ] @@ -263,9 +261,9 @@ static_library("googletest_main") { defines = [ "CRASHPAD_TEST_LAUNCHER_GOOGLETEST" ] deps = [ ":test", - "../third_party/googletest:googletest", "$mini_chromium_source_parent:base", "$mini_chromium_source_parent:base_test_support", + "../third_party/googletest:googletest", ] if (crashpad_is_android) { deps += [ "../util" ] diff --git a/test/ios/BUILD.gn b/test/ios/BUILD.gn index 6e4195ad..6b1deca8 100644 --- a/test/ios/BUILD.gn +++ b/test/ios/BUILD.gn @@ -40,7 +40,7 @@ source_set("google_test_runner") { configs += [ "../..:crashpad_config" ] deps = [ "../$mini_chromium_source_parent:base", - "../../build:ios_enable_arc", + "../../build:apple_enable_arc", "../../build:ios_xctest", "../../test/ios:google_test_runner_shared_headers", ] @@ -57,7 +57,7 @@ source_set("google_test_setup") { deps = [ ":google_test_runner_shared_headers", "../$mini_chromium_source_parent:base", - "../../build:ios_enable_arc", + "../../build:apple_enable_arc", "../../third_party/googletest:googletest", ] frameworks = [ "UIKit.framework" ] @@ -72,7 +72,7 @@ source_set("xcuitests") { ] deps = [ - "../../build:ios_enable_arc", + "../../build:apple_enable_arc", "../../build:ios_xctest", "../../client:common", "../../test/ios/host:app_shared_sources", diff --git a/test/ios/host/BUILD.gn b/test/ios/host/BUILD.gn index 77f145d0..7d2e9849 100644 --- a/test/ios/host/BUILD.gn +++ b/test/ios/host/BUILD.gn @@ -24,7 +24,7 @@ source_set("app_shared_sources") { testonly = true sources = [ "cptest_shared_object.h" ] configs += [ "../../..:crashpad_config" ] - deps = [ "../../../build:ios_enable_arc" ] + deps = [ "../../../build:apple_enable_arc" ] frameworks = [ "UIKit.framework" ] } @@ -42,7 +42,7 @@ static_library("app_host_sources") { configs += [ "../../..:crashpad_config" ] deps = [ ":app_shared_sources", - "../../../build:ios_enable_arc", + "../../../build:apple_enable_arc", "../../../client", "../../../snapshot", "../../../test", diff --git a/third_party/edo/BUILD.gn b/third_party/edo/BUILD.gn index f026f61d..1bd98e17 100644 --- a/third_party/edo/BUILD.gn +++ b/third_party/edo/BUILD.gn @@ -139,6 +139,6 @@ if (crashpad_is_in_chromium) { ] public_configs = [ ":config" ] - deps = [ "../../build:ios_enable_arc" ] + deps = [ "../../build:apple_enable_arc" ] } } diff --git a/tools/BUILD.gn b/tools/BUILD.gn index 845dab47..157ee929 100644 --- a/tools/BUILD.gn +++ b/tools/BUILD.gn @@ -36,8 +36,7 @@ crashpad_executable("dump_minidump_annotations") { ] if (crashpad_is_win) { - cflags = - [ "/wd4201" ] # nonstandard extension used : nameless struct/union + cflags = [ "/wd4201" ] # nonstandard extension used : nameless struct/union } } @@ -47,10 +46,10 @@ if (!crashpad_is_ios && !crashpad_is_fuchsia) { deps = [ ":tool_support", + "$mini_chromium_source_parent:base", "../build:default_exe_manifest_win", "../client", "../compat", - "$mini_chromium_source_parent:base", "../util", ] } @@ -60,9 +59,9 @@ if (!crashpad_is_ios && !crashpad_is_fuchsia) { deps = [ ":tool_support", + "$mini_chromium_source_parent:base", "../build:default_exe_manifest_win", "../compat", - "$mini_chromium_source_parent:base", "../util", "../util:net", ] @@ -73,8 +72,8 @@ crashpad_executable("base94_encoder") { sources = [ "base94_encoder.cc" ] deps = [ ":tool_support", - "../build:default_exe_manifest_win", "$mini_chromium_source_parent:base", + "../build:default_exe_manifest_win", "../util", ] } @@ -85,11 +84,11 @@ if (!crashpad_is_fuchsia && !crashpad_is_ios) { deps = [ ":tool_support", + "$mini_chromium_source_parent:base", "../build:default_exe_manifest_win", "../compat", "../minidump", "../snapshot", - "$mini_chromium_source_parent:base", "../util", ] @@ -119,9 +118,9 @@ if (crashpad_is_mac || crashpad_is_fuchsia) { deps = [ ":tool_support", + "$mini_chromium_source_parent:base", "../client", "../compat", - "$mini_chromium_source_parent:base", "../util", ] } @@ -133,8 +132,8 @@ if (crashpad_is_mac) { deps = [ ":tool_support", - "../compat", "$mini_chromium_source_parent:base", + "../compat", "../util", ] } @@ -154,8 +153,8 @@ if (crashpad_is_mac) { deps = [ ":tool_support", - "../compat", "$mini_chromium_source_parent:base", + "../compat", "../util", ] } @@ -170,8 +169,9 @@ if (crashpad_is_mac) { deps = [ ":tool_support", - "../compat", "$mini_chromium_source_parent:base", + "../build:apple_enable_arc", + "../compat", "../util", ] } diff --git a/tools/mac/on_demand_service_tool.mm b/tools/mac/on_demand_service_tool.mm index 41896ff8..3faec7a6 100644 --- a/tools/mac/on_demand_service_tool.mm +++ b/tools/mac/on_demand_service_tool.mm @@ -24,12 +24,16 @@ #include #include -#include "base/mac/foundation_util.h" +#include "base/apple/bridging.h" #include "base/strings/sys_string_conversions.h" #include "tools/tool_support.h" #include "util/mac/service_management.h" #include "util/stdlib/objc.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { namespace { @@ -158,13 +162,13 @@ int OnDemandServiceToolMain(int argc, char* argv[]) { } NSMutableDictionary* mutable_job_dictionary = - [[job_dictionary mutableCopy] autorelease]; + [job_dictionary mutableCopy]; mutable_job_dictionary[@LAUNCH_JOBKEY_MACHSERVICES] = mach_services; job_dictionary = mutable_job_dictionary; } CFDictionaryRef job_dictionary_cf = - base::mac::NSToCFCast(job_dictionary); + base::apple::NSToCFPtrCast(job_dictionary); if (!ServiceManagementSubmitJob(job_dictionary_cf)) { fprintf(stderr, "%s: failed to submit job\n", me.c_str()); return EXIT_FAILURE; diff --git a/util/BUILD.gn b/util/BUILD.gn index 4a828a6a..207d3808 100644 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -19,7 +19,7 @@ if (crashpad_is_in_chromium) { import("//build/config/sanitizers/sanitizers.gni") } -if (crashpad_is_mac || crashpad_is_ios) { +if (crashpad_is_apple) { if (crashpad_is_in_chromium || crashpad_is_in_fuchsia) { import("//build/config/sysroot.gni") } else { @@ -317,7 +317,7 @@ crashpad_static_library("util") { } } - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { sources += [ "mac/xattr.cc", "mac/xattr.h", @@ -401,10 +401,10 @@ crashpad_static_library("util") { "ios/raw_logging.h", "ios/scoped_background_task.h", "ios/scoped_background_task.mm", - "ios/scoped_vm_read.cc", - "ios/scoped_vm_read.h", "ios/scoped_vm_map.cc", "ios/scoped_vm_map.h", + "ios/scoped_vm_read.cc", + "ios/scoped_vm_read.h", ] } @@ -585,13 +585,12 @@ crashpad_static_library("util") { configs = [ "../build:flock_always_supported_defines" ] - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { include_dirs += [ "$root_gen_dir" ] - deps += [ ":mig_output" ] - } - - if (crashpad_is_ios) { - deps += [ "../build:ios_enable_arc" ] + deps += [ + ":mig_output", + "../build:apple_enable_arc", + ] } if (crashpad_is_mac && !crashpad_is_in_fuchsia) { @@ -652,6 +651,10 @@ crashpad_static_library("net") { "$mini_chromium_source_parent:base", ] + if (crashpad_is_apple) { + deps += [ "../build:apple_enable_arc" ] + } + if (crashpad_is_mac && !crashpad_is_in_fuchsia) { sources += [ "net/http_transport_mac.mm" ] } @@ -804,7 +807,7 @@ source_set("util_test") { sources += [ "posix/scoped_mmap_test.cc" ] } - if (crashpad_is_mac || crashpad_is_ios) { + if (crashpad_is_apple) { sources += [ "mac/xattr_test.cc", "mach/composite_mach_message_server_test.cc", @@ -840,8 +843,8 @@ source_set("util_test") { sources += [ "ios/ios_intermediate_dump_reader_test.cc", "ios/ios_intermediate_dump_writer_test.cc", - "ios/scoped_vm_read_test.cc", "ios/scoped_vm_map_test.cc", + "ios/scoped_vm_read_test.cc", ] sources -= [ @@ -919,6 +922,10 @@ source_set("util_test") { } } + if (crashpad_is_apple) { + deps += [ "../build:apple_enable_arc" ] + } + if (crashpad_is_mac) { frameworks = [ "Foundation.framework" ] } diff --git a/util/ios/ios_system_data_collector.mm b/util/ios/ios_system_data_collector.mm index 564c8e79..93e81dc8 100644 --- a/util/ios/ios_system_data_collector.mm +++ b/util/ios/ios_system_data_collector.mm @@ -27,6 +27,10 @@ #include "base/strings/sys_string_conversions.h" #include "build/build_config.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace { std::string ReadStringSysctlByName(const char* name) { diff --git a/util/mac/launchd.mm b/util/mac/launchd.mm index eb94ff37..18149f3d 100644 --- a/util/mac/launchd.mm +++ b/util/mac/launchd.mm @@ -16,12 +16,17 @@ #import +#include "base/apple/bridging.h" #include "base/mac/foundation_util.h" -#include "base/mac/scoped_launch_data.h" #include "base/mac/scoped_cftyperef.h" +#include "base/mac/scoped_launch_data.h" #include "base/strings/sys_string_conversions.h" #include "util/misc/implicit_cast.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { @@ -34,7 +39,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { CFTypeID type_id_cf = CFGetTypeID(property_cf); if (type_id_cf == CFDictionaryGetTypeID()) { - NSDictionary* dictionary_ns = base::mac::CFToNSCast( + NSDictionary* dictionary_ns = base::apple::CFToNSPtrCast( base::mac::CFCastStrict(property_cf)); base::mac::ScopedLaunchData dictionary_launch( LaunchDataAlloc(LAUNCH_DATA_DICTIONARY)); @@ -45,7 +50,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { } CFPropertyListRef value_cf = - implicit_cast(dictionary_ns[key]); + (__bridge CFPropertyListRef)dictionary_ns[key]; launch_data_t value_launch = CFPropertyToLaunchData(value_cf); if (!value_launch) { return nullptr; @@ -58,15 +63,14 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { data_launch = dictionary_launch.release(); } else if (type_id_cf == CFArrayGetTypeID()) { - NSArray* array_ns = base::mac::CFToNSCast( + NSArray* array_ns = base::apple::CFToNSPtrCast( base::mac::CFCastStrict(property_cf)); base::mac::ScopedLaunchData array_launch( LaunchDataAlloc(LAUNCH_DATA_ARRAY)); size_t index = 0; for (id element_ns in array_ns) { - CFPropertyListRef element_cf = - implicit_cast(element_ns); + CFPropertyListRef element_cf = (__bridge CFPropertyListRef)element_ns; launch_data_t element_launch = CFPropertyToLaunchData(element_cf); if (!element_launch) { return nullptr; @@ -79,7 +83,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { } else if (type_id_cf == CFNumberGetTypeID()) { CFNumberRef number_cf = base::mac::CFCastStrict(property_cf); - NSNumber* number_ns = base::mac::CFToNSCast(number_cf); + NSNumber* number_ns = base::apple::CFToNSPtrCast(number_cf); switch (CFNumberGetType(number_cf)) { case kCFNumberSInt8Type: case kCFNumberSInt16Type: @@ -113,7 +117,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { data_launch = LaunchDataNewBool(CFBooleanGetValue(boolean_cf)); } else if (type_id_cf == CFStringGetTypeID()) { - NSString* string_ns = base::mac::CFToNSCast( + NSString* string_ns = base::apple::CFToNSPtrCast( base::mac::CFCastStrict(property_cf)); // -fileSystemRepresentation might be more correct than -UTF8String, @@ -125,7 +129,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { data_launch = LaunchDataNewString([string_ns UTF8String]); } else if (type_id_cf == CFDataGetTypeID()) { - NSData* data_ns = base::mac::CFToNSCast( + NSData* data_ns = base::apple::CFToNSPtrCast( base::mac::CFCastStrict(property_cf)); data_launch = LaunchDataNewOpaque([data_ns bytes], [data_ns length]); } else { diff --git a/util/mac/launchd_test.mm b/util/mac/launchd_test.mm index 5949594c..c069919a 100644 --- a/util/mac/launchd_test.mm +++ b/util/mac/launchd_test.mm @@ -23,10 +23,15 @@ #include #include +#include "base/apple/bridging.h" #include "base/mac/scoped_launch_data.h" #include "gtest/gtest.h" #include "util/stdlib/objc.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { namespace test { namespace { @@ -60,7 +65,8 @@ for (size_t index = 0; index < std::size(integer_nses); ++index) { NSNumber* integer_ns = integer_nses[index]; - launch_data.reset(CFPropertyToLaunchData(integer_ns)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(integer_ns))); ASSERT_TRUE(launch_data.get()); ASSERT_EQ(LaunchDataGetType(launch_data.get()), LAUNCH_DATA_INTEGER); EXPECT_EQ(LaunchDataGetInteger(launch_data.get()), @@ -90,7 +96,8 @@ for (size_t index = 0; index < std::size(double_nses); ++index) { NSNumber* double_ns = double_nses[index]; - launch_data.reset(CFPropertyToLaunchData(double_ns)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(double_ns))); ASSERT_TRUE(launch_data.get()); ASSERT_EQ(LaunchDataGetType(launch_data.get()), LAUNCH_DATA_REAL); double expected_double_value = [double_ns doubleValue]; @@ -109,17 +116,19 @@ @autoreleasepool { base::mac::ScopedLaunchData launch_data; - NSNumber* bool_nses[] = { - @NO, - @YES, + // Use CFBooleanRefs here because calling NSToCFPtrCast on an NSNumber + // boolean can fail. Casting an NSNumber expects a CFNumberRef as a result + // but a cast boolean will end up as a CFBooleanRef. + CFBooleanRef bools[] = { + kCFBooleanFalse, + kCFBooleanTrue, }; - for (size_t index = 0; index < std::size(bool_nses); ++index) { - NSNumber* bool_ns = bool_nses[index]; - launch_data.reset(CFPropertyToLaunchData(bool_ns)); + for (CFBooleanRef bool_cf : bools) { + launch_data.reset(CFPropertyToLaunchData(bool_cf)); ASSERT_TRUE(launch_data.get()); ASSERT_EQ(LaunchDataGetType(launch_data.get()), LAUNCH_DATA_BOOL); - if ([bool_ns boolValue]) { + if (CFBooleanGetValue(bool_cf)) { EXPECT_TRUE(LaunchDataGetBool(launch_data.get())); } else { EXPECT_FALSE(LaunchDataGetBool(launch_data.get())); @@ -140,7 +149,8 @@ for (size_t index = 0; index < std::size(string_nses); ++index) { NSString* string_ns = string_nses[index]; - launch_data.reset(CFPropertyToLaunchData(string_ns)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(string_ns))); ASSERT_TRUE(launch_data.get()); ASSERT_EQ(LaunchDataGetType(launch_data.get()), LAUNCH_DATA_STRING); EXPECT_STREQ([string_ns UTF8String], @@ -156,7 +166,8 @@ static constexpr uint8_t data_c[] = { 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 9, 8, 7, 6, 5, 4, 3, 2}; NSData* data_ns = [NSData dataWithBytes:data_c length:sizeof(data_c)]; - launch_data.reset(CFPropertyToLaunchData(data_ns)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(data_ns))); ASSERT_TRUE(launch_data.get()); ASSERT_EQ(LaunchDataGetType(launch_data.get()), LAUNCH_DATA_OPAQUE); EXPECT_EQ(LaunchDataGetOpaqueSize(launch_data.get()), sizeof(data_c)); @@ -174,7 +185,8 @@ @"key" : @"value", }; - launch_data.reset(CFPropertyToLaunchData(dictionary_ns)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(dictionary_ns))); ASSERT_TRUE(launch_data.get()); ASSERT_EQ(LaunchDataGetType(launch_data.get()), LAUNCH_DATA_DICTIONARY); EXPECT_EQ(LaunchDataDictGetCount(launch_data.get()), [dictionary_ns count]); @@ -193,7 +205,8 @@ NSArray* array_ns = @[ @"element_1", @"element_2", ]; - launch_data.reset(CFPropertyToLaunchData(array_ns)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(array_ns))); ASSERT_TRUE(launch_data.get()); ASSERT_EQ(LaunchDataGetType(launch_data.get()), LAUNCH_DATA_ARRAY); EXPECT_EQ(LaunchDataArrayGetCount(launch_data.get()), [array_ns count]); @@ -219,18 +232,20 @@ base::mac::ScopedLaunchData launch_data; NSDate* date = [NSDate date]; - launch_data.reset(CFPropertyToLaunchData(date)); + launch_data.reset(CFPropertyToLaunchData(base::apple::NSToCFPtrCast(date))); EXPECT_FALSE(launch_data.get()); NSDictionary* date_dictionary = @{ @"key" : @"value", @"date" : date, }; - launch_data.reset(CFPropertyToLaunchData(date_dictionary)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(date_dictionary))); EXPECT_FALSE(launch_data.get()); NSArray* date_array = @[ @"string_1", date, @"string_2", ]; - launch_data.reset(CFPropertyToLaunchData(date_array)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(date_array))); EXPECT_FALSE(launch_data.get()); } } @@ -249,7 +264,8 @@ }, }; - launch_data.reset(CFPropertyToLaunchData(job_dictionary)); + launch_data.reset( + CFPropertyToLaunchData(base::apple::NSToCFPtrCast(job_dictionary))); ASSERT_TRUE(launch_data.get()); ASSERT_EQ(LaunchDataGetType(launch_data.get()), LAUNCH_DATA_DICTIONARY); EXPECT_EQ(LaunchDataDictGetCount(launch_data.get()), 4u); diff --git a/util/mac/mac_util_test.mm b/util/mac/mac_util_test.mm index c086ac65..35c7904d 100644 --- a/util/mac/mac_util_test.mm +++ b/util/mac/mac_util_test.mm @@ -19,10 +19,13 @@ #include -#include "base/mac/scoped_nsobject.h" #include "base/strings/stringprintf.h" #include "gtest/gtest.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { namespace test { namespace { @@ -33,8 +36,8 @@ // check for with ASSERT_NO_FATAL_FAILURE() or testing::Test::HasFatalFailure(). void SwVers(NSString* argument, std::string* output) { @autoreleasepool { - base::scoped_nsobject pipe([[NSPipe alloc] init]); - base::scoped_nsobject task([[NSTask alloc] init]); + NSPipe* pipe = [[NSPipe alloc] init]; + NSTask* task = [[NSTask alloc] init]; [task setStandardOutput:pipe]; [task setLaunchPath:@"/usr/bin/sw_vers"]; [task setArguments:@[ argument ]]; diff --git a/util/mac/service_management_test.mm b/util/mac/service_management_test.mm index 461228d8..fbf4fddd 100644 --- a/util/mac/service_management_test.mm +++ b/util/mac/service_management_test.mm @@ -20,7 +20,7 @@ #include #include -#include "base/mac/foundation_util.h" +#include "base/apple/bridging.h" #include "base/mac/scoped_cftyperef.h" #include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" @@ -30,6 +30,10 @@ #include "util/posix/process_info.h" #include "util/stdlib/objc.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + namespace crashpad { namespace test { namespace { @@ -124,7 +128,7 @@ void ExpectProcessIsNotRunning(pid_t pid, std::string& last_arg) { @[ @"/bin/sh", @"-c", shell_script_ns, ], }; CFDictionaryRef job_dictionary_cf = - base::mac::NSToCFCast(job_dictionary_ns); + base::apple::NSToCFPtrCast(job_dictionary_ns); // The job may be left over from a failed previous run. if (ServiceManagementIsJobLoaded(kJobLabel)) { diff --git a/util/net/http_transport_mac.mm b/util/net/http_transport_mac.mm index 04f5c347..41012799 100644 --- a/util/net/http_transport_mac.mm +++ b/util/net/http_transport_mac.mm @@ -17,8 +17,8 @@ #import #include +#include "base/apple/bridging.h" #include "base/mac/foundation_util.h" -#import "base/mac/scoped_nsobject.h" #include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" #include "build/build_config.h" @@ -28,12 +28,16 @@ #include "util/misc/metrics.h" #include "util/net/http_body.h" +#if !defined(__has_feature) || !__has_feature(objc_arc) +#error "This file requires ARC support." +#endif + // An implementation of NSInputStream that reads from a // crashpad::HTTPBodyStream. @interface CrashpadHTTPBodyStreamTransport : NSInputStream { @private NSStreamStatus _streamStatus; - id _delegate; + id __strong _delegate; crashpad::HTTPBodyStream* _bodyStream; // weak } - (instancetype)initWithBodyStream:(crashpad::HTTPBodyStream*)bodyStream; @@ -154,12 +158,13 @@ - (BOOL)setProperty:(id)property forKey:(NSStreamPropertyKey)key { // Expected to be CFNetwork. NSBundle* nsurl_bundle = [NSBundle bundleForClass:[NSURLRequest class]]; NSString* bundle_name = base::mac::ObjCCast([nsurl_bundle - objectForInfoDictionaryKey:base::mac::CFToNSCast(kCFBundleNameKey)]); + objectForInfoDictionaryKey:base::apple::CFToNSPtrCast(kCFBundleNameKey)]); if (bundle_name) { user_agent = AppendEscapedFormat(user_agent, @" %@", bundle_name); - NSString* bundle_version = base::mac::ObjCCast([nsurl_bundle - objectForInfoDictionaryKey:base::mac::CFToNSCast(kCFBundleVersionKey)]); + NSString* bundle_version = base::mac::ObjCCast( + [nsurl_bundle objectForInfoDictionaryKey:base::apple::CFToNSPtrCast( + kCFBundleVersionKey)]); if (bundle_version) { user_agent = AppendEscapedFormat(user_agent, @"/%@", bundle_version); } @@ -240,10 +245,9 @@ - (BOOL)setProperty:(id)property forKey:(NSStreamPropertyKey)key { forHTTPHeaderField:base::SysUTF8ToNSString(pair.first)]; } - base::scoped_nsobject input_stream( - [[CrashpadHTTPBodyStreamTransport alloc] - initWithBodyStream:body_stream()]); - [request setHTTPBodyStream:input_stream.get()]; + NSInputStream* input_stream = [[CrashpadHTTPBodyStreamTransport alloc] + initWithBodyStream:body_stream()]; + [request setHTTPBodyStream:input_stream]; NSURLResponse* response = nil; NSError* error = nil; From 00ce1f9f8f4585d82caa0ff17deb35f8608416bf Mon Sep 17 00:00:00 2001 From: Avi Drissman Date: Wed, 5 Jul 2023 11:34:17 -0400 Subject: [PATCH 025/107] Disable PtraceBroker.SameBitness Bug: chromium:1459865 Change-Id: I28d5caa739c5b59f4af1f062616443aa16fadfa1 Fixed: chromium:1459862 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4663174 Reviewed-by: Mark Mentovai Commit-Queue: Mark Mentovai --- util/linux/ptrace_broker_test.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/util/linux/ptrace_broker_test.cc b/util/linux/ptrace_broker_test.cc index 0b9e917c..11f1684a 100644 --- a/util/linux/ptrace_broker_test.cc +++ b/util/linux/ptrace_broker_test.cc @@ -277,7 +277,10 @@ class SameBitnessTest : public Multiprocess { ScopedMmap mapping_; }; -TEST(PtraceBroker, SameBitness) { +// TODO(https://crbug.com/1459865): This test consistently fails on ASAN/LSAN +// but it's not clear if this test is correct in the general case (see comment 2 +// on that issue). +TEST(PtraceBroker, DISABLED_SameBitness) { SameBitnessTest test; test.Run(); } From dcba40ceea1ad512db6eada176e6b119bf47bf98 Mon Sep 17 00:00:00 2001 From: Clayton McCray Date: Tue, 11 Jul 2023 16:46:31 +0000 Subject: [PATCH 026/107] [inspect] Route InspectSink in crashpad Bug: 93344 Change-Id: Id794e3c79983b4c2352842edfe73a81ad3958b6e Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4676565 Commit-Queue: Clayton McCray Commit-Queue: Francois Rousseau Reviewed-by: Francois Rousseau --- test/fuchsia_crashpad_tests.cml | 1 + 1 file changed, 1 insertion(+) diff --git a/test/fuchsia_crashpad_tests.cml b/test/fuchsia_crashpad_tests.cml index b5c0c8a0..63ec2e20 100644 --- a/test/fuchsia_crashpad_tests.cml +++ b/test/fuchsia_crashpad_tests.cml @@ -4,6 +4,7 @@ { include: [ "//src/sys/test_runners/elf/ambient_exec.shard.cml", + "inspect/offer.shard.cml", "syslog/client.shard.cml", ], program: { From 3df478b96d2f243be2b1832413c4325d4cb5e608 Mon Sep 17 00:00:00 2001 From: Avi Drissman Date: Wed, 26 Jul 2023 16:46:52 -0400 Subject: [PATCH 027/107] Remove redundant ARC configuration in Crashpad ARC is now enabled by default in Chromium, so enabling it explicitly in Crashpad is redundant. Bug: chromium:733237 Change-Id: I59dd863c0f8e7e16e88b6daccc5f900829c0cec5 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4721646 Reviewed-by: Mark Mentovai Commit-Queue: Mark Mentovai Commit-Queue: Avi Drissman --- build/BUILD.gn | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/build/BUILD.gn b/build/BUILD.gn index 3763d2e1..7d7e08bb 100644 --- a/build/BUILD.gn +++ b/build/BUILD.gn @@ -53,9 +53,10 @@ config("crashpad_fuzzer_flags") { if (crashpad_is_apple) { group("apple_enable_arc") { - if (crashpad_is_in_chromium) { - public_configs = [ "//build/config/compiler:enable_arc" ] - } else if (crashpad_is_standalone) { + # If `crashpad_is_in_chromium`, then because Chromium enables ARC + # compilation by default, no special configuration is needed. + + if (crashpad_is_standalone) { public_configs = [ "//third_party/mini_chromium/mini_chromium/build/config:apple_enable_arc" ] } } From 8dcf2b216f6bfa8fb46024b2db14f1fe0a47275f Mon Sep 17 00:00:00 2001 From: Thomas Gales Date: Tue, 25 Jul 2023 17:14:58 +0000 Subject: [PATCH 028/107] [fuchsia] Don't build CaptureContext CaptureContext isn't actually used on Fuchsia and there is a desire to remove `ucontext_t` from Fuchsia as it isn't a real concept on Fuchsia and was only added as a placeholder. Moreover, `ucontext_t` won't ever be added to Fuchsia for RISC-V. Bug: fuchsia:123052 Fixed: fuchsia:131112 Fixed: fuchsia:127655 Tested: `fx test crashpad` on core.x64 emulator Tested: `fx test crashpad` on ARM64 device Tested: `fx shell crasher` @ 16b19a9891978487 on ARM64 device, ran through Breakpad stackwalker locally as well Tested: `fx build crashpad_tests` for minimal.riscv64 Change-Id: I4695054426df78a9deff8c9ea9c478b5bf9701b1 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4717085 Reviewed-by: Mark Mentovai Commit-Queue: Thomas Gales --- client/crashpad_client.h | 3 + util/BUILD.gn | 8 +- util/misc/capture_context.h | 10 +- util/misc/capture_context_fuchsia.S | 255 ------------------ util/misc/capture_context_test.cc | 9 - .../misc/capture_context_test_util_fuchsia.cc | 65 ----- 6 files changed, 14 insertions(+), 336 deletions(-) delete mode 100644 util/misc/capture_context_fuchsia.S delete mode 100644 util/misc/capture_context_test_util_fuchsia.cc diff --git a/client/crashpad_client.h b/client/crashpad_client.h index 412ca683..11fa66e2 100644 --- a/client/crashpad_client.h +++ b/client/crashpad_client.h @@ -27,7 +27,10 @@ #include "build/build_config.h" #include "build/chromeos_buildflags.h" #include "util/file/file_io.h" + +#if !BUILDFLAG(IS_FUCHSIA) #include "util/misc/capture_context.h" +#endif // !BUILDFLAG(IS_FUCHSIA) #if BUILDFLAG(IS_APPLE) #include "base/mac/scoped_mach_port.h" diff --git a/util/BUILD.gn b/util/BUILD.gn index 207d3808..7e06fcda 100644 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -555,11 +555,12 @@ crashpad_static_library("util") { "fuchsia/scoped_task_suspend.cc", "fuchsia/scoped_task_suspend.h", "fuchsia/traits.h", - "misc/capture_context_fuchsia.S", "misc/paths_fuchsia.cc", "process/process_memory_fuchsia.cc", "process/process_memory_fuchsia.h", ] + + sources -= [ "misc/capture_context.h" ] } public_configs = [ "..:crashpad_config" ] @@ -869,7 +870,10 @@ source_set("util_test") { } if (crashpad_is_fuchsia) { - sources += [ "misc/capture_context_test_util_fuchsia.cc" ] + sources -= [ + "misc/capture_context_test.cc", + "misc/capture_context_test_util.h", + ] } if (crashpad_is_win) { diff --git a/util/misc/capture_context.h b/util/misc/capture_context.h index e838dbab..ac7707b4 100644 --- a/util/misc/capture_context.h +++ b/util/misc/capture_context.h @@ -23,8 +23,6 @@ #include #elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) #include -#elif BUILDFLAG(IS_FUCHSIA) -#include #endif // BUILDFLAG(IS_APPLE) namespace crashpad { @@ -37,8 +35,7 @@ using NativeCPUContext = arm_unified_thread_state; #endif #elif BUILDFLAG(IS_WIN) using NativeCPUContext = CONTEXT; -#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \ - BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_FUCHSIA) +#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) using NativeCPUContext = ucontext_t; #endif // BUILDFLAG(IS_APPLE) @@ -57,6 +54,9 @@ using NativeCPUContext = ucontext_t; //! `RtlCaptureContext()` capture only the state of the integer registers, //! ignoring floating-point and vector state. //! +//! CaptureContext isn't used on Fuchsia, nor does a concept of `ucontext_t` +//! exist on Fuchsia. +//! //! \param[out] cpu_context The structure to store the context in. //! //! \note The ABI may require that this function's argument is passed by @@ -66,7 +66,7 @@ using NativeCPUContext = ucontext_t; //! OS | Architecture | Register //! --------------------|--------------|--------- //! Win | x86_64 | `%%rcx` -//! macOS/Linux/Fuchsia | x86_64 | `%%rdi` +//! macOS/Linux | x86_64 | `%%rdi` //! Linux | ARM/ARM64 | `r0`/`x0` //! Linux | MIPS/MIPS64 | `$a0` //! Linux | RISCV64 | `a0` diff --git a/util/misc/capture_context_fuchsia.S b/util/misc/capture_context_fuchsia.S deleted file mode 100644 index a0bbd22f..00000000 --- a/util/misc/capture_context_fuchsia.S +++ /dev/null @@ -1,255 +0,0 @@ -// Copyright 2018 The Crashpad Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// namespace crashpad { -// void CaptureContext(ucontext_t* context); -// } // namespace crashpad - -#define CAPTURECONTEXT_SYMBOL _ZN8crashpad14CaptureContextEP8ucontext - - .text - .globl CAPTURECONTEXT_SYMBOL -#if defined(__x86_64__) - .balign 16, 0x90 -#elif defined(__aarch64__) - .balign 4, 0x0 -#elif defined(__riscv) - .balign 4, 0x0 -#endif - -CAPTURECONTEXT_SYMBOL: - -#if defined(__x86_64__) - - .cfi_startproc - - pushq %rbp - .cfi_def_cfa_offset 16 - .cfi_offset %rbp, -16 - movq %rsp, %rbp - .cfi_def_cfa_register %rbp - - // Note that 16-byte stack alignment is not maintained because this function - // does not call out to any other. - - // pushfq first, because some instructions (but probably none used here) - // affect %rflags. %rflags will be in -8(%rbp). - pushfq - - // General-purpose registers whose values haven’t changed can be captured - // directly. - movq %r8, 0x28(%rdi) // context->uc_mcontext.r8 - movq %r9, 0x30(%rdi) // context->uc_mcontext.r9 - movq %r10, 0x38(%rdi) // context->uc_mcontext.r10 - movq %r11, 0x40(%rdi) // context->uc_mcontext.r11 - movq %r12, 0x48(%rdi) // context->uc_mcontext.r12 - movq %r13, 0x50(%rdi) // context->uc_mcontext.r13 - movq %r14, 0x58(%rdi) // context->uc_mcontext.r14 - movq %r15, 0x60(%rdi) // context->uc_mcontext.r15 - - // Because of the calling convention, there’s no way to recover the value of - // the caller’s %rdi as it existed prior to calling this function. This - // function captures a snapshot of the register state at its return, which - // involves %rdi containing a pointer to its first argument. Callers that - // require the value of %rdi prior to calling this function should obtain it - // separately. For example: - // uint64_t rdi; - // asm("movq %%rdi, %0" : "=m"(rdi)); - movq %rdi, 0x68(%rdi) // context->uc_mcontext.rdi - - movq %rsi, 0x70(%rdi) // context->uc_mcontext.rsi - - // Use %r8 as a scratch register now that it has been saved. - // The original %rbp was saved on the stack in this function’s prologue. - movq (%rbp), %r8 - movq %r8, 0x78(%rdi) // context->uc_mcontext.rbp - - // Save the remaining general-purpose registers. - movq %rbx, 0x80(%rdi) // context->uc_mcontext.rbx - movq %rdx, 0x88(%rdi) // context->uc_mcontext.rdx - movq %rax, 0x90(%rdi) // context->uc_mcontext.rax - movq %rcx, 0x98(%rdi) // context->uc_mcontext.rcx - - // %rsp was saved in %rbp in this function’s prologue, but the caller’s %rsp - // is 16 more than this value: 8 for the original %rbp saved on the stack in - // this function’s prologue, and 8 for the return address saved on the stack - // by the call instruction that reached this function. - leaq 16(%rbp), %r8 - movq %r8, 0xa0(%rdi) // context->uc_mcontext.rsp - - // The return address saved on the stack used by the call of this function is - // likely more useful than the current RIP here. - movq 8(%rbp), %r8 - movq %r8, 0xa8(%rdi) // context->uc_mcontext.rip - - // The original %rflags was saved on the stack above. - movq -8(%rbp), %r8 - movq %r8, 0xb0(%rdi) // context->uc_mcontext.eflags - - // Save the segment registers - movw %cs, 0xb8(%rdi) // context->uc_mcontext.cs - movw %gs, 0xba(%rdi) // context->uc_mcontext.gs - movw %fs, 0xbc(%rdi) // context->uc_mcontext.fs - - xorw %ax, %ax - movw %ax, 0xbe(%rdi) // context->uc_mcontext.padding - - // Zero out the remainder of the unused pseudo-registers - xorq %r8, %r8 - movq %r8, 0xc0(%rdi) // context->uc_mcontext.err - movq %r8, 0xc8(%rdi) // context->uc_mcontext.trapno - movq %r8, 0xd0(%rdi) // context->uc_mcontext.oldmask - movq %r8, 0xd8(%rdi) // context->uc_mcontext.cr2 - - // Clean up by restoring clobbered registers, even those considered volatile - // by the ABI, so that the captured context represents the state at this - // function’s exit. - movq 0x90(%rdi), %rax - movq 0x28(%rdi), %r8 - - // TODO(https://crashpad.chromium.org/bug/300): save floating-point registers. - - popfq - - popq %rbp - - ret - - .cfi_endproc - -#elif defined(__aarch64__) - - // Zero out fault_address, which is unused. - str x31, [x0, #0xb0] // context->uc_mcontext.fault_address - - // Save general purpose registers in context->uc_mcontext.regs[i]. - // The original x0 can't be recovered. - stp x0, x1, [x0, #0xb8] - stp x2, x3, [x0, #0xc8] - stp x4, x5, [x0, #0xd8] - stp x6, x7, [x0, #0xe8] - stp x8, x9, [x0, #0xf8] - stp x10, x11, [x0, #0x108] - stp x12, x13, [x0, #0x118] - stp x14, x15, [x0, #0x128] - stp x16, x17, [x0, #0x138] - stp x18, x19, [x0, #0x148] - stp x20, x21, [x0, #0x158] - stp x22, x23, [x0, #0x168] - stp x24, x25, [x0, #0x178] - stp x26, x27, [x0, #0x188] - stp x28, x29, [x0, #0x198] - - // The original LR can't be recovered. - str LR, [x0, #0x1a8] - - // Use x1 as a scratch register. - mov x1, SP - str x1, [x0, #0x1b0] // context->uc_mcontext.sp - - // The link register holds the return address for this function. - str LR, [x0, #0x1b8] // context->uc_mcontext.pc - - // pstate should hold SPSR but NZCV are the only bits we know about. - mrs x1, NZCV - str x1, [x0, #0x1c0] // context->uc_mcontext.pstate - - // Restore x1 from the saved context. - ldr x1, [x0, #0xc0] - - // TODO(https://crashpad.chromium.org/bug/300): save floating-point registers. - - ret - -#elif defined(__riscv) - - #define MCONTEXT_GREGS_OFFSET 176 - - // x1/ra is the return address. Store it as the pc. - // The original x10/a0 can't be recovered. - sd x1, (0 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x1, (1 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x2, (2 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x3, (3 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x4, (4 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x5, (5 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x6, (6 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x7, (7 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x8, (8 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x9, (9 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x10, (10 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x11, (11 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x12, (12 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x13, (13 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x14, (14 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x15, (15 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x16, (16 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x17, (17 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x18, (18 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x19, (19 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x20, (20 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x21, (21 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x22, (22 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x23, (23 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x24, (24 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x25, (25 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x26, (26 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x27, (27 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x28, (28 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x29, (29 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x30, (30 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - sd x31, (31 * 8 + MCONTEXT_GREGS_OFFSET)(a0) - - #define MCONTEXT_FPREGS_OFFSET MCONTEXT_GREGS_OFFSET + 32*8 - - // Use x31/t6 as scratch register. - frcsr x31 - sw x31, (32 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - - fsd f0, (0 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f1, (1 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f2, (2 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f3, (3 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f4, (4 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f5, (5 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f6, (6 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f7, (7 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f8, (8 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f9, (9 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f10, (10 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f11, (11 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f12, (12 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f13, (13 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f14, (14 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f15, (15 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f16, (16 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f17, (17 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f18, (18 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f19, (19 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f20, (20 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f21, (21 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f22, (22 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f23, (23 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f24, (24 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f25, (25 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f26, (26 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f27, (27 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f28, (28 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f29, (29 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f30, (30 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - fsd f31, (31 * 8 + MCONTEXT_FPREGS_OFFSET)(a0) - - ret - -#endif // __x86_64__ diff --git a/util/misc/capture_context_test.cc b/util/misc/capture_context_test.cc index f353aebe..2cd92c84 100644 --- a/util/misc/capture_context_test.cc +++ b/util/misc/capture_context_test.cc @@ -28,15 +28,6 @@ namespace crashpad { namespace test { namespace { -#if BUILDFLAG(IS_FUCHSIA) -// Fuchsia uses -fsanitize=safe-stack by default, which splits local variables -// and the call stack into separate regions (see -// https://clang.llvm.org/docs/SafeStack.html). Because this test would like to -// find an approximately valid stack pointer by comparing locals to the -// captured one, disable safe-stack for this function. -__attribute__((no_sanitize("safe-stack"))) -#endif // BUILDFLAG(IS_FUCHSIA) - #if defined(MEMORY_SANITIZER) // CaptureContext() calls inline assembly and is incompatible with MSan. __attribute__((no_sanitize("memory"))) diff --git a/util/misc/capture_context_test_util_fuchsia.cc b/util/misc/capture_context_test_util_fuchsia.cc deleted file mode 100644 index 57cc9d76..00000000 --- a/util/misc/capture_context_test_util_fuchsia.cc +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2018 The Crashpad Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "util/misc/capture_context_test_util.h" - -#include "gtest/gtest.h" -#include "util/misc/from_pointer_cast.h" - -namespace crashpad { -namespace test { - -#if defined(ARCH_CPU_X86_64) -static_assert(offsetof(NativeCPUContext, uc_mcontext) == 0x28, - "unexpected mcontext offset"); -static_assert(offsetof(NativeCPUContext, uc_mcontext.gregs[REG_RSP]) == 0xa0, - "unexpected rsp offset"); -static_assert(offsetof(NativeCPUContext, uc_mcontext.gregs[REG_RIP]) == 0xa8, - "unexpected rip offset"); -#endif // ARCH_CPU_X86_64 - -void SanityCheckContext(const NativeCPUContext& context) { -#if defined(ARCH_CPU_X86_64) - EXPECT_EQ(context.uc_mcontext.gregs[REG_RDI], - FromPointerCast(&context)); -#elif defined(ARCH_CPU_ARM64) - EXPECT_EQ(context.uc_mcontext.regs[0], FromPointerCast(&context)); -#elif defined(ARCH_CPU_RISCV64) - EXPECT_EQ(context.uc_mcontext.__gregs[10], - FromPointerCast(&context)); -#endif -} - -uintptr_t ProgramCounterFromContext(const NativeCPUContext& context) { -#if defined(ARCH_CPU_X86_64) - return context.uc_mcontext.gregs[REG_RIP]; -#elif defined(ARCH_CPU_ARM64) - return context.uc_mcontext.pc; -#elif defined(ARCH_CPU_RISCV64) - return context.uc_mcontext.__gregs[0]; -#endif -} - -uintptr_t StackPointerFromContext(const NativeCPUContext& context) { -#if defined(ARCH_CPU_X86_64) - return context.uc_mcontext.gregs[REG_RSP]; -#elif defined(ARCH_CPU_ARM64) - return context.uc_mcontext.sp; -#elif defined(ARCH_CPU_RISCV64) - return context.uc_mcontext.__gregs[2]; -#endif -} - -} // namespace test -} // namespace crashpad From ca6d64d0ae4905ad7033adab0a28273a0741ee5c Mon Sep 17 00:00:00 2001 From: Thomas Gales Date: Wed, 2 Aug 2023 21:07:53 +0000 Subject: [PATCH 029/107] [fuchsia][mac] Fix build errors A recent CL [1] broke Fuchsia's Crashpad roller due to duplicate build argument declarations. This CL ensures that sysroot.gni is only imported once. [1] https://chromium-review.googlesource.com/c/chromium/mini_chromium/+/4651973 Fixed: fuchsia:131454 Change-Id: Idcf6ac65cdffee2c9a9551559a8aab0063044428 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4743381 Reviewed-by: Joshua Peraza Commit-Queue: Thomas Gales --- util/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/BUILD.gn b/util/BUILD.gn index 7e06fcda..15bebdec 100644 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -20,9 +20,9 @@ if (crashpad_is_in_chromium) { } if (crashpad_is_apple) { - if (crashpad_is_in_chromium || crashpad_is_in_fuchsia) { + if (crashpad_is_in_chromium) { import("//build/config/sysroot.gni") - } else { + } else if (!crashpad_is_in_fuchsia) { import("$mini_chromium_import_root/build/sysroot.gni") } From b1e66e322ddd07f4640ee8bad93397a0511cd313 Mon Sep 17 00:00:00 2001 From: Keishi Hattori Date: Wed, 2 Aug 2023 19:56:12 +0000 Subject: [PATCH 030/107] Add SetLastChanceExceptionHandler to implement permissive MTE mode SetLastChanceExceptionHandler sets a callback to be called after a crash has been reported. Returning true from this callback will not reraise the signal so the execution can continue. This will be used to implement permissive MTE mode, which will continue execution after a MTE crash. Bug: chromium:1467915 Change-Id: I93a28ceea921fe977805482cf47c07643ca6133c Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4707688 Reviewed-by: Robert Sesek Commit-Queue: Keishi Hattori --- client/crashpad_client.h | 18 +++++++++++++ client/crashpad_client_linux.cc | 18 +++++++++++++ client/crashpad_client_linux_test.cc | 39 +++++++++++++++++++++++++--- 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/client/crashpad_client.h b/client/crashpad_client.h index 11fa66e2..3070e2e0 100644 --- a/client/crashpad_client.h +++ b/client/crashpad_client.h @@ -456,6 +456,24 @@ class CrashpadClient { //! \param[in] handler The custom crash signal handler to install. static void SetFirstChanceExceptionHandler(FirstChanceHandler handler); + //! \brief Installs a custom crash signal handler which runs after the + //! currently installed Crashpad handler. + //! + //! Handling signals appropriately can be tricky and use of this method + //! should be avoided, if possible. + //! + //! A handler must have already been installed before calling this method. + //! + //! The custom handler runs in a signal handler context and must be safe for + //! that purpose. + //! + //! If the custom handler returns `true`, the signal is not reraised. + //! + //! \param[in] handler The custom crash signal handler to install. + static void SetLastChanceExceptionHandler(bool (*handler)(int, + siginfo_t*, + ucontext_t*)); + //! \brief Configures a set of signals that shouldn't have Crashpad signal //! handlers installed. //! diff --git a/client/crashpad_client_linux.cc b/client/crashpad_client_linux.cc index 630c24f1..f805ff1f 100644 --- a/client/crashpad_client_linux.cc +++ b/client/crashpad_client_linux.cc @@ -131,6 +131,8 @@ std::vector BuildArgsToLaunchWithLinker( #endif // BUILDFLAG(IS_ANDROID) +using LastChanceHandler = bool (*)(int, siginfo_t*, ucontext_t*); + // A base class for Crashpad signal handler implementations. class SignalHandler { public: @@ -154,6 +156,10 @@ class SignalHandler { first_chance_handler_ = handler; } + void SetLastChanceExceptionHandler(LastChanceHandler handler) { + last_chance_handler_ = handler; + } + // The base implementation for all signal handlers, suitable for calling // directly to simulate signal delivery. void HandleCrash(int signo, siginfo_t* siginfo, void* context) { @@ -212,6 +218,11 @@ class SignalHandler { if (!handler_->disabled_.test_and_set()) { handler_->HandleCrash(signo, siginfo, context); handler_->WakeThreads(); + if (handler_->last_chance_handler_ && + handler_->last_chance_handler_( + signo, siginfo, static_cast(context))) { + return; + } } else { // Processes on Android normally have several chained signal handlers that // co-operate to report crashes. e.g. WebView will have this signal @@ -254,6 +265,7 @@ class SignalHandler { Signals::OldActions old_actions_ = {}; ExceptionInformation exception_information_ = {}; CrashpadClient::FirstChanceHandler first_chance_handler_ = nullptr; + LastChanceHandler last_chance_handler_ = nullptr; int32_t dump_done_futex_ = kDumpNotDone; #if !defined(__cpp_lib_atomic_value_initialization) || \ __cpp_lib_atomic_value_initialization < 201911L @@ -739,6 +751,12 @@ void CrashpadClient::SetFirstChanceExceptionHandler( SignalHandler::Get()->SetFirstChanceHandler(handler); } +// static +void CrashpadClient::SetLastChanceExceptionHandler(LastChanceHandler handler) { + DCHECK(SignalHandler::Get()); + SignalHandler::Get()->SetLastChanceExceptionHandler(handler); +} + void CrashpadClient::SetUnhandledSignals(const std::set& signals) { DCHECK(!SignalHandler::Get()); unhandled_signals_ = signals; diff --git a/client/crashpad_client_linux_test.cc b/client/crashpad_client_linux_test.cc index 9b207db3..8f4151e5 100644 --- a/client/crashpad_client_linux_test.cc +++ b/client/crashpad_client_linux_test.cc @@ -71,11 +71,14 @@ enum class CrashType : uint32_t { kBuiltinTrap, kInfiniteRecursion, kSegvWithTagBits, + // kFakeSegv is meant to simulate a MTE segv error. + kFakeSegv, }; struct StartHandlerForSelfTestOptions { bool start_handler_at_crash; bool set_first_chance_handler; + bool set_last_chance_handler; bool crash_non_main_thread; bool client_uses_signals; bool gather_indirectly_referenced_memory; @@ -84,7 +87,7 @@ struct StartHandlerForSelfTestOptions { class StartHandlerForSelfTest : public testing::TestWithParam< - std::tuple> { + std::tuple> { public: StartHandlerForSelfTest() = default; @@ -99,6 +102,7 @@ class StartHandlerForSelfTest memset(&options_, 0, sizeof(options_)); std::tie(options_.start_handler_at_crash, options_.set_first_chance_handler, + options_.set_last_chance_handler, options_.crash_non_main_thread, options_.client_uses_signals, options_.gather_indirectly_referenced_memory, @@ -244,6 +248,10 @@ bool HandleCrashSuccessfully(int, siginfo_t*, ucontext_t*) { #pragma clang diagnostic pop } +bool HandleCrashSuccessfullyAfterReporting(int, siginfo_t*, ucontext_t*) { + return true; +} + void DoCrash(const StartHandlerForSelfTestOptions& options, CrashpadClient* client) { if (sigsetjmp(do_crash_sigjmp_env, 1) != 0) { @@ -273,6 +281,11 @@ void DoCrash(const StartHandlerForSelfTestOptions& options, *x; break; } + + case CrashType::kFakeSegv: { + raise(SIGSEGV); + break; + } } } @@ -403,6 +416,10 @@ CRASHPAD_CHILD_TEST_MAIN(StartHandlerForSelfTestChild) { client.SetFirstChanceExceptionHandler(HandleCrashSuccessfully); } + if (options.set_last_chance_handler) { + client.SetLastChanceExceptionHandler(HandleCrashSuccessfullyAfterReporting); + } + #if BUILDFLAG(IS_ANDROID) if (android_set_abort_message) { android_set_abort_message(kTestAbortMessage); @@ -440,6 +457,16 @@ class StartHandlerForSelfInChildTest : public MultiprocessExec { case CrashType::kSegvWithTagBits: SetExpectedChildTermination(TerminationReason::kTerminationSignal, SIGSEGV); + break; + case CrashType::kFakeSegv: + if (!options.set_last_chance_handler) { + SetExpectedChildTermination(TerminationReason::kTerminationSignal, + SIGSEGV); + } else { + SetExpectedChildTermination(TerminationReason::kTerminationNormal, + EXIT_SUCCESS); + } + break; } } } @@ -471,7 +498,11 @@ class StartHandlerForSelfInChildTest : public MultiprocessExec { writer.Close(); if (options_.client_uses_signals && !options_.set_first_chance_handler && - options_.crash_type != CrashType::kSimulated) { + options_.crash_type != CrashType::kSimulated && + // The last chance handler will prevent the client handler from being + // called if crash type is kFakeSegv. + (!options_.set_last_chance_handler || + options_.crash_type != CrashType::kFakeSegv)) { // Wait for child's client signal handler. char c; EXPECT_TRUE(LoggingReadFileExactly(ReadPipeHandle(), &c, sizeof(c))); @@ -549,10 +580,12 @@ INSTANTIATE_TEST_SUITE_P( testing::Bool(), testing::Bool(), testing::Bool(), + testing::Bool(), testing::Values(CrashType::kSimulated, CrashType::kBuiltinTrap, CrashType::kInfiniteRecursion, - CrashType::kSegvWithTagBits))); + CrashType::kSegvWithTagBits, + CrashType::kFakeSegv))); // Test state for starting the handler for another process. class StartHandlerForClientTest { From ce7f0f1de9bb9cdb88ff93046fe3e498b1f19295 Mon Sep 17 00:00:00 2001 From: Keishi Hattori Date: Thu, 3 Aug 2023 19:10:49 +0000 Subject: [PATCH 031/107] Revert "Add SetLastChanceExceptionHandler to implement permissive MTE mode" This reverts commit b1e66e322ddd07f4640ee8bad93397a0511cd313. Reason for revert: test was flaky on Android bot Original change's description: > Add SetLastChanceExceptionHandler to implement permissive MTE mode > > SetLastChanceExceptionHandler sets a callback to be called after a > crash has been reported. Returning true from this callback will > not reraise the signal so the execution can continue. This will be > used to implement permissive MTE mode, which will continue execution > after a MTE crash. > > Bug: chromium:1467915 > Change-Id: I93a28ceea921fe977805482cf47c07643ca6133c > Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4707688 > Reviewed-by: Robert Sesek > Commit-Queue: Keishi Hattori Bug: chromium:1467915 Change-Id: Id815a780b576088974101117a4587adec64cfe8c No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4750459 Commit-Queue: Keishi Hattori Bot-Commit: Rubber Stamper --- client/crashpad_client.h | 18 ------------- client/crashpad_client_linux.cc | 18 ------------- client/crashpad_client_linux_test.cc | 39 +++------------------------- 3 files changed, 3 insertions(+), 72 deletions(-) diff --git a/client/crashpad_client.h b/client/crashpad_client.h index 3070e2e0..11fa66e2 100644 --- a/client/crashpad_client.h +++ b/client/crashpad_client.h @@ -456,24 +456,6 @@ class CrashpadClient { //! \param[in] handler The custom crash signal handler to install. static void SetFirstChanceExceptionHandler(FirstChanceHandler handler); - //! \brief Installs a custom crash signal handler which runs after the - //! currently installed Crashpad handler. - //! - //! Handling signals appropriately can be tricky and use of this method - //! should be avoided, if possible. - //! - //! A handler must have already been installed before calling this method. - //! - //! The custom handler runs in a signal handler context and must be safe for - //! that purpose. - //! - //! If the custom handler returns `true`, the signal is not reraised. - //! - //! \param[in] handler The custom crash signal handler to install. - static void SetLastChanceExceptionHandler(bool (*handler)(int, - siginfo_t*, - ucontext_t*)); - //! \brief Configures a set of signals that shouldn't have Crashpad signal //! handlers installed. //! diff --git a/client/crashpad_client_linux.cc b/client/crashpad_client_linux.cc index f805ff1f..630c24f1 100644 --- a/client/crashpad_client_linux.cc +++ b/client/crashpad_client_linux.cc @@ -131,8 +131,6 @@ std::vector BuildArgsToLaunchWithLinker( #endif // BUILDFLAG(IS_ANDROID) -using LastChanceHandler = bool (*)(int, siginfo_t*, ucontext_t*); - // A base class for Crashpad signal handler implementations. class SignalHandler { public: @@ -156,10 +154,6 @@ class SignalHandler { first_chance_handler_ = handler; } - void SetLastChanceExceptionHandler(LastChanceHandler handler) { - last_chance_handler_ = handler; - } - // The base implementation for all signal handlers, suitable for calling // directly to simulate signal delivery. void HandleCrash(int signo, siginfo_t* siginfo, void* context) { @@ -218,11 +212,6 @@ class SignalHandler { if (!handler_->disabled_.test_and_set()) { handler_->HandleCrash(signo, siginfo, context); handler_->WakeThreads(); - if (handler_->last_chance_handler_ && - handler_->last_chance_handler_( - signo, siginfo, static_cast(context))) { - return; - } } else { // Processes on Android normally have several chained signal handlers that // co-operate to report crashes. e.g. WebView will have this signal @@ -265,7 +254,6 @@ class SignalHandler { Signals::OldActions old_actions_ = {}; ExceptionInformation exception_information_ = {}; CrashpadClient::FirstChanceHandler first_chance_handler_ = nullptr; - LastChanceHandler last_chance_handler_ = nullptr; int32_t dump_done_futex_ = kDumpNotDone; #if !defined(__cpp_lib_atomic_value_initialization) || \ __cpp_lib_atomic_value_initialization < 201911L @@ -751,12 +739,6 @@ void CrashpadClient::SetFirstChanceExceptionHandler( SignalHandler::Get()->SetFirstChanceHandler(handler); } -// static -void CrashpadClient::SetLastChanceExceptionHandler(LastChanceHandler handler) { - DCHECK(SignalHandler::Get()); - SignalHandler::Get()->SetLastChanceExceptionHandler(handler); -} - void CrashpadClient::SetUnhandledSignals(const std::set& signals) { DCHECK(!SignalHandler::Get()); unhandled_signals_ = signals; diff --git a/client/crashpad_client_linux_test.cc b/client/crashpad_client_linux_test.cc index 8f4151e5..9b207db3 100644 --- a/client/crashpad_client_linux_test.cc +++ b/client/crashpad_client_linux_test.cc @@ -71,14 +71,11 @@ enum class CrashType : uint32_t { kBuiltinTrap, kInfiniteRecursion, kSegvWithTagBits, - // kFakeSegv is meant to simulate a MTE segv error. - kFakeSegv, }; struct StartHandlerForSelfTestOptions { bool start_handler_at_crash; bool set_first_chance_handler; - bool set_last_chance_handler; bool crash_non_main_thread; bool client_uses_signals; bool gather_indirectly_referenced_memory; @@ -87,7 +84,7 @@ struct StartHandlerForSelfTestOptions { class StartHandlerForSelfTest : public testing::TestWithParam< - std::tuple> { + std::tuple> { public: StartHandlerForSelfTest() = default; @@ -102,7 +99,6 @@ class StartHandlerForSelfTest memset(&options_, 0, sizeof(options_)); std::tie(options_.start_handler_at_crash, options_.set_first_chance_handler, - options_.set_last_chance_handler, options_.crash_non_main_thread, options_.client_uses_signals, options_.gather_indirectly_referenced_memory, @@ -248,10 +244,6 @@ bool HandleCrashSuccessfully(int, siginfo_t*, ucontext_t*) { #pragma clang diagnostic pop } -bool HandleCrashSuccessfullyAfterReporting(int, siginfo_t*, ucontext_t*) { - return true; -} - void DoCrash(const StartHandlerForSelfTestOptions& options, CrashpadClient* client) { if (sigsetjmp(do_crash_sigjmp_env, 1) != 0) { @@ -281,11 +273,6 @@ void DoCrash(const StartHandlerForSelfTestOptions& options, *x; break; } - - case CrashType::kFakeSegv: { - raise(SIGSEGV); - break; - } } } @@ -416,10 +403,6 @@ CRASHPAD_CHILD_TEST_MAIN(StartHandlerForSelfTestChild) { client.SetFirstChanceExceptionHandler(HandleCrashSuccessfully); } - if (options.set_last_chance_handler) { - client.SetLastChanceExceptionHandler(HandleCrashSuccessfullyAfterReporting); - } - #if BUILDFLAG(IS_ANDROID) if (android_set_abort_message) { android_set_abort_message(kTestAbortMessage); @@ -457,16 +440,6 @@ class StartHandlerForSelfInChildTest : public MultiprocessExec { case CrashType::kSegvWithTagBits: SetExpectedChildTermination(TerminationReason::kTerminationSignal, SIGSEGV); - break; - case CrashType::kFakeSegv: - if (!options.set_last_chance_handler) { - SetExpectedChildTermination(TerminationReason::kTerminationSignal, - SIGSEGV); - } else { - SetExpectedChildTermination(TerminationReason::kTerminationNormal, - EXIT_SUCCESS); - } - break; } } } @@ -498,11 +471,7 @@ class StartHandlerForSelfInChildTest : public MultiprocessExec { writer.Close(); if (options_.client_uses_signals && !options_.set_first_chance_handler && - options_.crash_type != CrashType::kSimulated && - // The last chance handler will prevent the client handler from being - // called if crash type is kFakeSegv. - (!options_.set_last_chance_handler || - options_.crash_type != CrashType::kFakeSegv)) { + options_.crash_type != CrashType::kSimulated) { // Wait for child's client signal handler. char c; EXPECT_TRUE(LoggingReadFileExactly(ReadPipeHandle(), &c, sizeof(c))); @@ -580,12 +549,10 @@ INSTANTIATE_TEST_SUITE_P( testing::Bool(), testing::Bool(), testing::Bool(), - testing::Bool(), testing::Values(CrashType::kSimulated, CrashType::kBuiltinTrap, CrashType::kInfiniteRecursion, - CrashType::kSegvWithTagBits, - CrashType::kFakeSegv))); + CrashType::kSegvWithTagBits))); // Test state for starting the handler for another process. class StartHandlerForClientTest { From 617429d3584eefb9d0cb06bb4083e7456fd582e1 Mon Sep 17 00:00:00 2001 From: Avi Drissman Date: Thu, 3 Aug 2023 14:58:07 -0400 Subject: [PATCH 032/107] Remove ARC boilerplate in Crashpad MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ARC is now enabled by default, so there’s no need to enforce it against files being put into non-ARC targets. Bug: chromium:1468376 Change-Id: I58bbb4d1736293a6e9977954ce932dcfe2bafa54 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4750419 Reviewed-by: Mark Mentovai Commit-Queue: Mark Mentovai --- client/crash_report_database_mac.mm | 4 ---- client/crashpad_client_ios_test.mm | 4 ---- client/ios_handler/exception_processor.mm | 4 ---- client/ios_handler/exception_processor_test.mm | 4 ---- test/ios/cptest_google_test_runner.mm | 4 ---- test/ios/crash_type_xctest.mm | 4 ---- test/ios/google_test_setup.mm | 4 ---- test/ios/host/cptest_application_delegate.mm | 4 ---- test/ios/host/cptest_crash_view_controller.mm | 4 ---- test/ios/host/main.mm | 4 ---- tools/mac/on_demand_service_tool.mm | 4 ---- util/ios/ios_system_data_collector.mm | 4 ---- util/ios/scoped_background_task.mm | 4 ---- util/mac/launchd.mm | 4 ---- util/mac/launchd_test.mm | 4 ---- util/mac/mac_util_test.mm | 4 ---- util/mac/service_management_test.mm | 4 ---- util/net/http_transport_mac.mm | 4 ---- 18 files changed, 72 deletions(-) diff --git a/client/crash_report_database_mac.mm b/client/crash_report_database_mac.mm index d3bf9850..7221b595 100644 --- a/client/crash_report_database_mac.mm +++ b/client/crash_report_database_mac.mm @@ -49,10 +49,6 @@ #include "util/ios/scoped_background_task.h" #endif // BUILDFLAG(IS_IOS) -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - namespace crashpad { namespace { diff --git a/client/crashpad_client_ios_test.mm b/client/crashpad_client_ios_test.mm index 409de95b..29f3df65 100644 --- a/client/crashpad_client_ios_test.mm +++ b/client/crashpad_client_ios_test.mm @@ -27,10 +27,6 @@ #include "testing/platform_test.h" #include "util/thread/thread.h" -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - namespace crashpad { namespace test { namespace { diff --git a/client/ios_handler/exception_processor.mm b/client/ios_handler/exception_processor.mm index 920825dc..b61d56c2 100644 --- a/client/ios_handler/exception_processor.mm +++ b/client/ios_handler/exception_processor.mm @@ -54,10 +54,6 @@ #include "client/annotation.h" #include "client/simulate_crash_ios.h" -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - namespace crashpad { namespace { diff --git a/client/ios_handler/exception_processor_test.mm b/client/ios_handler/exception_processor_test.mm index ad5ea7b6..8be70890 100644 --- a/client/ios_handler/exception_processor_test.mm +++ b/client/ios_handler/exception_processor_test.mm @@ -19,10 +19,6 @@ #include "gtest/gtest.h" #include "testing/platform_test.h" -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - namespace crashpad { namespace test { namespace { diff --git a/test/ios/cptest_google_test_runner.mm b/test/ios/cptest_google_test_runner.mm index 9e950393..3958f8c1 100644 --- a/test/ios/cptest_google_test_runner.mm +++ b/test/ios/cptest_google_test_runner.mm @@ -18,10 +18,6 @@ #include "base/check.h" #import "test/ios/cptest_google_test_runner_delegate.h" -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - @interface CPTestGoogleTestRunner : XCTestCase @end diff --git a/test/ios/crash_type_xctest.mm b/test/ios/crash_type_xctest.mm index d73d359f..8d4038db 100644 --- a/test/ios/crash_type_xctest.mm +++ b/test/ios/crash_type_xctest.mm @@ -24,10 +24,6 @@ #include "util/mach/exception_types.h" #include "util/mach/mach_extensions.h" -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - @interface CPTestTestCase : XCTestCase { XCUIApplication* app_; CPTestSharedObject* rootObject_; diff --git a/test/ios/google_test_setup.mm b/test/ios/google_test_setup.mm index dc71c672..e68f4d01 100644 --- a/test/ios/google_test_setup.mm +++ b/test/ios/google_test_setup.mm @@ -20,10 +20,6 @@ #include "gtest/gtest.h" #include "test/ios/cptest_google_test_runner_delegate.h" -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - @interface UIApplication (Testing) - (void)_terminateWithStatus:(int)status; @end diff --git a/test/ios/host/cptest_application_delegate.mm b/test/ios/host/cptest_application_delegate.mm index 923a7c66..531a4cde 100644 --- a/test/ios/host/cptest_application_delegate.mm +++ b/test/ios/host/cptest_application_delegate.mm @@ -50,10 +50,6 @@ #include "util/ios/raw_logging.h" #include "util/thread/thread.h" -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - using OperationStatus = crashpad::CrashReportDatabase::OperationStatus; using Report = crashpad::CrashReportDatabase::Report; diff --git a/test/ios/host/cptest_crash_view_controller.mm b/test/ios/host/cptest_crash_view_controller.mm index 8e4076e3..c866388c 100644 --- a/test/ios/host/cptest_crash_view_controller.mm +++ b/test/ios/host/cptest_crash_view_controller.mm @@ -14,10 +14,6 @@ #import "test/ios/host/cptest_crash_view_controller.h" -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - @implementation CPTestCrashViewController - (void)loadView { diff --git a/test/ios/host/main.mm b/test/ios/host/main.mm index d1d6b00f..cf06f30d 100644 --- a/test/ios/host/main.mm +++ b/test/ios/host/main.mm @@ -16,10 +16,6 @@ #import "test/ios/host/cptest_application_delegate.h" -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - int main(int argc, char* argv[]) { NSString* appDelegateClassName; @autoreleasepool { diff --git a/tools/mac/on_demand_service_tool.mm b/tools/mac/on_demand_service_tool.mm index 3faec7a6..05ddae1d 100644 --- a/tools/mac/on_demand_service_tool.mm +++ b/tools/mac/on_demand_service_tool.mm @@ -30,10 +30,6 @@ #include "util/mac/service_management.h" #include "util/stdlib/objc.h" -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - namespace crashpad { namespace { diff --git a/util/ios/ios_system_data_collector.mm b/util/ios/ios_system_data_collector.mm index 93e81dc8..564c8e79 100644 --- a/util/ios/ios_system_data_collector.mm +++ b/util/ios/ios_system_data_collector.mm @@ -27,10 +27,6 @@ #include "base/strings/sys_string_conversions.h" #include "build/build_config.h" -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - namespace { std::string ReadStringSysctlByName(const char* name) { diff --git a/util/ios/scoped_background_task.mm b/util/ios/scoped_background_task.mm index b4900963..2af7bb8e 100644 --- a/util/ios/scoped_background_task.mm +++ b/util/ios/scoped_background_task.mm @@ -16,10 +16,6 @@ #import -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - namespace crashpad { namespace internal { diff --git a/util/mac/launchd.mm b/util/mac/launchd.mm index 18149f3d..35620ba5 100644 --- a/util/mac/launchd.mm +++ b/util/mac/launchd.mm @@ -23,10 +23,6 @@ #include "base/strings/sys_string_conversions.h" #include "util/misc/implicit_cast.h" -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - namespace crashpad { launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { diff --git a/util/mac/launchd_test.mm b/util/mac/launchd_test.mm index c069919a..27e0bdea 100644 --- a/util/mac/launchd_test.mm +++ b/util/mac/launchd_test.mm @@ -28,10 +28,6 @@ #include "gtest/gtest.h" #include "util/stdlib/objc.h" -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - namespace crashpad { namespace test { namespace { diff --git a/util/mac/mac_util_test.mm b/util/mac/mac_util_test.mm index 35c7904d..e1cc3ad7 100644 --- a/util/mac/mac_util_test.mm +++ b/util/mac/mac_util_test.mm @@ -22,10 +22,6 @@ #include "base/strings/stringprintf.h" #include "gtest/gtest.h" -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - namespace crashpad { namespace test { namespace { diff --git a/util/mac/service_management_test.mm b/util/mac/service_management_test.mm index fbf4fddd..85335284 100644 --- a/util/mac/service_management_test.mm +++ b/util/mac/service_management_test.mm @@ -30,10 +30,6 @@ #include "util/posix/process_info.h" #include "util/stdlib/objc.h" -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - namespace crashpad { namespace test { namespace { diff --git a/util/net/http_transport_mac.mm b/util/net/http_transport_mac.mm index 41012799..ef51beb6 100644 --- a/util/net/http_transport_mac.mm +++ b/util/net/http_transport_mac.mm @@ -28,10 +28,6 @@ #include "util/misc/metrics.h" #include "util/net/http_body.h" -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - // An implementation of NSInputStream that reads from a // crashpad::HTTPBodyStream. @interface CrashpadHTTPBodyStreamTransport : NSInputStream { From 8132af7ccba15a772c071a22253bb81eb544a196 Mon Sep 17 00:00:00 2001 From: Peter Kasting Date: Fri, 4 Aug 2023 09:21:22 -0700 Subject: [PATCH 033/107] Roll crashpad/third_party/mini_chromium/mini_chromium/ e009af846..d1baeddcb (3 commits) https://chromium.googlesource.com/chromium/mini_chromium/+log/e009af846ef4..d1baeddcb8de $ git log e009af846..d1baeddcb --date=short --no-merges --format='%ad %ae %s' 2023-08-03 pkasting Reorder string_util.h platform-specific #includes to match Chromium. 2023-08-04 rahul.yadav Add base/types/cxx23_to_underlying.h to mini_chromium base 2023-08-03 pkasting Add base::IsAscii(Digit,Whitespace) to mini_chromium. Created with: roll-dep crashpad/third_party/mini_chromium/mini_chromium Change-Id: I93ba6ef4eba235840e18d0981aaaa926da26159a Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4750022 Reviewed-by: Mark Mentovai Commit-Queue: Peter Kasting --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index 3b97d622..b3ed9507 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - 'e009af846ef4790a90d69fe13ed54df25b93fdef', + 'd1baeddcb8de15654e427e8c86a4c7c7add0e731', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', From 419f995aab828946555a449b7e0f3b562bcfb9e4 Mon Sep 17 00:00:00 2001 From: Peter Kasting Date: Thu, 3 Aug 2023 13:20:50 -0700 Subject: [PATCH 034/107] Ban [w]ctype.h: crashpad Bug: chromium:1361094 Change-Id: Ia5dacb9038cd74b5d490282a8070fb4579ebe3ae Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4750179 Reviewed-by: Mark Mentovai Commit-Queue: Peter Kasting --- util/misc/lexing.cc | 4 ++-- util/stdlib/string_number_conversion.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/util/misc/lexing.cc b/util/misc/lexing.cc index b65bdf14..36d239c9 100644 --- a/util/misc/lexing.cc +++ b/util/misc/lexing.cc @@ -14,7 +14,6 @@ #include "util/misc/lexing.h" -#include #include #include #include @@ -23,6 +22,7 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/string_piece.h" +#include "base/strings/string_util.h" namespace crashpad { @@ -55,7 +55,7 @@ bool AdvancePastNumber(const char** input, T* value) { if (std::numeric_limits::is_signed && **input == '-') { ++length; } - while (isdigit((*input)[length])) { + while (base::IsAsciiDigit((*input)[length])) { ++length; } bool success = diff --git a/util/stdlib/string_number_conversion.cc b/util/stdlib/string_number_conversion.cc index 91a6abe4..1be54687 100644 --- a/util/stdlib/string_number_conversion.cc +++ b/util/stdlib/string_number_conversion.cc @@ -14,7 +14,6 @@ #include "util/stdlib/string_number_conversion.h" -#include #include #include #include @@ -22,6 +21,7 @@ #include +#include "base/strings/string_util.h" namespace { @@ -141,7 +141,7 @@ bool StringToIntegerInternal(const std::string& string, Traits::TypeCheck(); - if (string.empty() || isspace(string[0])) { + if (string.empty() || base::IsAsciiWhitespace(string[0])) { return false; } From 343aa69084e5462c0f790e2490991d270233cfd7 Mon Sep 17 00:00:00 2001 From: Thomas Gales Date: Fri, 4 Aug 2023 20:09:44 +0000 Subject: [PATCH 035/107] Revert "[fuchsia][mac] Fix build errors" This reverts commit ca6d64d0ae4905ad7033adab0a28273a0741ee5c. Reason for revert: The changes did not actually fix the problem once combined with the latest changes from mini_chromium. Original change's description: > [fuchsia][mac] Fix build errors > > A recent CL [1] broke Fuchsia's Crashpad roller due to duplicate build > argument declarations. This CL ensures that sysroot.gni is only imported once. > > [1] https://chromium-review.googlesource.com/c/chromium/mini_chromium/+/4651973 > > Fixed: fuchsia:131454 > Change-Id: Idcf6ac65cdffee2c9a9551559a8aab0063044428 > Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4743381 > Reviewed-by: Joshua Peraza > Commit-Queue: Thomas Gales Change-Id: Id3dc42484fbd87e242756c8d2889d2e404370ac7 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4753637 Commit-Queue: Thomas Gales Reviewed-by: Joshua Peraza --- util/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/BUILD.gn b/util/BUILD.gn index 15bebdec..7e06fcda 100644 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -20,9 +20,9 @@ if (crashpad_is_in_chromium) { } if (crashpad_is_apple) { - if (crashpad_is_in_chromium) { + if (crashpad_is_in_chromium || crashpad_is_in_fuchsia) { import("//build/config/sysroot.gni") - } else if (!crashpad_is_in_fuchsia) { + } else { import("$mini_chromium_import_root/build/sysroot.gni") } From 77c1ad28d489c1422c8700d3b34855e426a50f0e Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Tue, 8 Aug 2023 12:47:12 -0400 Subject: [PATCH 036/107] Add support for linux-arm64 To support linux-arm64 build hosts, use an appropraite build of gn on those systems. To support linux-arm64 targets, this also updates mini_chromium to 2035d204bd0f812ac95a1ed72038e6bdbcfce4a2: 2035d204bd0f Add support for linux-arm64 Change-Id: I04139d9136d36fcb0a15aee2ce0694909d44ae95 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4760265 Reviewed-by: Joshua Peraza --- DEPS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DEPS b/DEPS index b3ed9507..3c72f1e5 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - 'd1baeddcb8de15654e427e8c86a4c7c7add0e731', + '2035d204bd0f812ac95a1ed72038e6bdbcfce4a2', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', @@ -59,7 +59,7 @@ deps = { 'buildtools/linux64': { 'packages': [ { - 'package': 'gn/gn/linux-amd64', + 'package': 'gn/gn/linux-${{arch}}', 'version': Var('gn_version'), } ], From 3f3b7a856d88827189679627d75c39258bf96771 Mon Sep 17 00:00:00 2001 From: Thomas Gales Date: Tue, 8 Aug 2023 17:20:30 +0000 Subject: [PATCH 037/107] Roll crashpad/third_party/mini_chromium/mini_chromium/ 2035d204b..a722d31ef (1 commit) https://chromium.googlesource.com/chromium/mini_chromium/+log/2035d204bd0f..a722d31ef524 $ git log 2035d204b..a722d31ef --date=short --no-merges --format='%ad %ae %s' 2023-08-07 tgales [fuchsia][mac] Fix build errors Created with: roll-dep crashpad/third_party/mini_chromium/mini_chromium Fixed: fuchsia:131454 Change-Id: I77d9291cb9cd9cdf967761567e27ae9b0b32b98b Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4761366 Reviewed-by: Joshua Peraza Commit-Queue: Thomas Gales Reviewed-by: Mark Mentovai --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index 3c72f1e5..75180399 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - '2035d204bd0f812ac95a1ed72038e6bdbcfce4a2', + 'a722d31ef5245c1859ee8317796bc29bc7b08069', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', From 43d04a8661b2de61277fd20de7e8cc0dedc8e6de Mon Sep 17 00:00:00 2001 From: Avi Drissman Date: Wed, 16 Aug 2023 12:54:45 -0400 Subject: [PATCH 038/107] Update comment for new file location https://crrev.com/c/4781926 moves PA files to new locations. This updates the filename reference. Bug: chromium:1444927 Change-Id: I7947711055eb444ab5bc28d4e3c6ca2c39a17e04 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4784548 Commit-Queue: Avi Drissman Reviewed-by: Mark Mentovai --- test/ios/host/handler_forbidden_allocators.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ios/host/handler_forbidden_allocators.cc b/test/ios/host/handler_forbidden_allocators.cc index 6d41b8dc..5ede632c 100644 --- a/test/ios/host/handler_forbidden_allocators.cc +++ b/test/ios/host/handler_forbidden_allocators.cc @@ -32,7 +32,7 @@ uint64_t g_main_thread = 0; uint64_t g_mach_exception_thread = 0; // Somewhat simplified logic copied from Chromium's -// base/allocator/partition_allocator/shim/malloc_zone_functions_mac.h. The +// base/allocator/partition_allocator/shim/malloc_zone_functions_apple.h. The // arrays g_original_zones and g_original_zones_ptr stores all information about // malloc zones before they are shimmed. This information needs to be accessed // during dispatch back into the zone. From 6a9e2e6003096a33e4006290e570bbd3da59e5c6 Mon Sep 17 00:00:00 2001 From: Avi Drissman Date: Wed, 16 Aug 2023 16:30:40 -0400 Subject: [PATCH 039/107] Adjust to movement of base/ files to base/apple This CL rolls mini_chromium to pick up the move of a bunch of files to base/apple, and makes changes to adjust. Bug: chromium:1444927 Change-Id: Ib692e2a1628e2c0c8228795eaecdb7f35b1c09fa Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4786387 Reviewed-by: Mark Mentovai Commit-Queue: Avi Drissman --- DEPS | 2 +- client/crash_report_database_mac.mm | 4 +- client/crashpad_client.h | 8 ++-- client/crashpad_client_ios.cc | 6 +-- client/crashpad_client_mac.cc | 39 ++++++++++--------- client/simulate_crash_mac.cc | 6 +-- handler/handler_main.cc | 4 +- handler/mac/crash_report_exception_handler.cc | 8 ++-- handler/mac/exception_handler_server.cc | 8 ++-- handler/mac/exception_handler_server.h | 8 ++-- ...xception_snapshot_ios_intermediate_dump.cc | 2 +- .../module_snapshot_ios_intermediate_dump.cc | 2 +- .../system_snapshot_ios_intermediate_dump.cc | 2 +- .../thread_snapshot_ios_intermediate_dump.cc | 2 +- snapshot/mac/process_reader_mac.cc | 8 ++-- snapshot/mac/process_reader_mac_test.cc | 6 +-- test/ios/host/handler_forbidden_allocators.cc | 2 +- test/mac/exception_swallower.cc | 8 ++-- test/mac/mach_errors.h | 5 ++- test/mac/mach_multiprocess.cc | 8 ++-- tools/generate_dump.cc | 4 +- tools/mac/catch_exception_tool.cc | 6 +-- tools/mac/exception_port_tool.cc | 12 +++--- util/ios/ios_intermediate_dump_writer_test.cc | 6 +-- util/ios/ios_system_data_collector.mm | 2 +- util/ios/scoped_vm_map_test.cc | 6 +-- util/ios/scoped_vm_read_test.cc | 6 +-- util/mach/bootstrap.cc | 14 +++---- util/mach/bootstrap.h | 9 +++-- util/mach/bootstrap_test.cc | 17 ++++---- util/mach/child_port_handshake.cc | 11 +++--- util/mach/child_port_handshake.h | 6 +-- util/mach/child_port_handshake_test.cc | 10 ++--- util/mach/exception_ports.cc | 2 +- util/mach/exception_ports_test.cc | 12 +++--- util/mach/exception_types.cc | 2 +- util/mach/mach_extensions.cc | 2 +- util/mach/mach_extensions_test.cc | 11 +++--- util/mach/mach_message.cc | 2 +- util/mach/mach_message_server.cc | 6 +-- util/mach/mach_message_server_test.cc | 6 +-- util/mach/mach_message_test.cc | 7 ++-- util/mach/notify_server_test.cc | 38 +++++++++--------- util/mach/scoped_task_suspend.cc | 2 +- util/mach/task_for_pid.cc | 6 +-- util/misc/clock_mac.cc | 2 +- util/posix/process_info_mac.cc | 2 +- util/process/process_memory_mac.cc | 2 +- util/process/process_memory_mac.h | 4 +- util/process/process_memory_mac_test.cc | 12 +++--- 50 files changed, 186 insertions(+), 179 deletions(-) diff --git a/DEPS b/DEPS index 75180399..42037773 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - 'a722d31ef5245c1859ee8317796bc29bc7b08069', + 'f5370228f40bbb8c453e17f6af6c6742858c45d1', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', diff --git a/client/crash_report_database_mac.mm b/client/crash_report_database_mac.mm index 7221b595..c8522623 100644 --- a/client/crash_report_database_mac.mm +++ b/client/crash_report_database_mac.mm @@ -30,8 +30,8 @@ #include #include +#include "base/apple/scoped_nsautorelease_pool.h" #include "base/logging.h" -#include "base/mac/scoped_nsautorelease_pool.h" #include "base/posix/eintr_wrapper.h" #include "base/scoped_generic.h" #include "base/strings/string_piece.h" @@ -813,7 +813,7 @@ OperationStatus ReportsInDirectory(const base::FilePath& path, CrashReportDatabase::OperationStatus CrashReportDatabaseMac::ReportsInDirectory( const base::FilePath& path, std::vector* reports) { - base::mac::ScopedNSAutoreleasePool pool; + base::apple::ScopedNSAutoreleasePool pool; DCHECK(reports->empty()); diff --git a/client/crashpad_client.h b/client/crashpad_client.h index 11fa66e2..24424414 100644 --- a/client/crashpad_client.h +++ b/client/crashpad_client.h @@ -33,7 +33,7 @@ #endif // !BUILDFLAG(IS_FUCHSIA) #if BUILDFLAG(IS_APPLE) -#include "base/mac/scoped_mach_port.h" +#include "base/apple/scoped_mach_port.h" #elif BUILDFLAG(IS_WIN) #include #include "util/win/scoped_handle.h" @@ -627,7 +627,7 @@ class CrashpadClient { //! Crashpad exception handler service. //! //! \return `true` on success, `false` on failure with a message logged. - bool SetHandlerMachPort(base::mac::ScopedMachSendRight exception_port); + bool SetHandlerMachPort(base::apple::ScopedMachSendRight exception_port); //! \brief Retrieves a send right to the process’ crash handler Mach port. //! @@ -648,7 +648,7 @@ class CrashpadClient { //! SetHandlerMachService(). This method must only be called after a //! successful call to one of those methods. `MACH_PORT_NULL` on failure //! with a message logged. - base::mac::ScopedMachSendRight GetHandlerMachPort() const; + base::apple::ScopedMachSendRight GetHandlerMachPort() const; #endif #if BUILDFLAG(IS_WIN) || DOXYGEN @@ -790,7 +790,7 @@ class CrashpadClient { private: #if BUILDFLAG(IS_APPLE) - base::mac::ScopedMachSendRight exception_port_; + base::apple::ScopedMachSendRight exception_port_; #elif BUILDFLAG(IS_WIN) std::wstring ipc_pipe_; ScopedKernelHANDLE handler_start_thread_; diff --git a/client/crashpad_client_ios.cc b/client/crashpad_client_ios.cc index 53adf8d4..a34cc15e 100644 --- a/client/crashpad_client_ios.cc +++ b/client/crashpad_client_ios.cc @@ -21,9 +21,9 @@ #include #include +#include "base/apple/mach_logging.h" +#include "base/apple/scoped_mach_port.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" -#include "base/mac/scoped_mach_port.h" #include "client/ios_handler/exception_processor.h" #include "client/ios_handler/in_process_handler.h" #include "util/ios/raw_logging.h" @@ -393,7 +393,7 @@ class CrashHandler : public Thread, Signals::RestoreHandlerAndReraiseSignalOnReturn(siginfo, old_action); } - base::mac::ScopedMachReceiveRight exception_port_; + base::apple::ScopedMachReceiveRight exception_port_; ExceptionPorts::ExceptionHandlerVector original_handlers_; struct sigaction old_action_ = {}; internal::InProcessHandler in_process_handler_; diff --git a/client/crashpad_client_mac.cc b/client/crashpad_client_mac.cc index c5fc708d..8b85ac73 100644 --- a/client/crashpad_client_mac.cc +++ b/client/crashpad_client_mac.cc @@ -24,8 +24,8 @@ #include #include +#include "base/apple/mach_logging.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" #include "base/strings/stringprintf.h" #include "util/mac/mac_util.h" #include "util/mach/bootstrap.h" @@ -122,7 +122,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface { //! //! \return On success, a send right to the Crashpad handler that has been //! started. On failure, `MACH_PORT_NULL` with a message logged. - static base::mac::ScopedMachSendRight InitialStart( + static base::apple::ScopedMachSendRight InitialStart( const base::FilePath& handler, const base::FilePath& database, const base::FilePath& metrics_dir, @@ -130,10 +130,10 @@ class HandlerStarter final : public NotifyServer::DefaultInterface { const std::map& annotations, const std::vector& arguments, bool restartable) { - base::mac::ScopedMachReceiveRight receive_right( + base::apple::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); if (!receive_right.is_valid()) { - return base::mac::ScopedMachSendRight(); + return base::apple::ScopedMachSendRight(); } mach_port_t port; @@ -145,9 +145,9 @@ class HandlerStarter final : public NotifyServer::DefaultInterface { &right_type); if (kr != KERN_SUCCESS) { MACH_LOG(ERROR, kr) << "mach_port_extract_right"; - return base::mac::ScopedMachSendRight(); + return base::apple::ScopedMachSendRight(); } - base::mac::ScopedMachSendRight send_right(port); + base::apple::ScopedMachSendRight send_right(port); DCHECK_EQ(port, receive_right.get()); DCHECK_EQ(right_type, implicit_cast(MACH_MSG_TYPE_PORT_SEND)); @@ -171,7 +171,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface { std::move(receive_right), handler_restarter.get(), false)) { - return base::mac::ScopedMachSendRight(); + return base::apple::ScopedMachSendRight(); } if (handler_restarter && @@ -211,7 +211,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface { url_, annotations_, arguments_, - base::mac::ScopedMachReceiveRight(rights), + base::apple::ScopedMachReceiveRight(rights), this, true); @@ -256,7 +256,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface { const std::string& url, const std::map& annotations, const std::vector& arguments, - base::mac::ScopedMachReceiveRight receive_right, + base::apple::ScopedMachReceiveRight receive_right, HandlerStarter* handler_restarter, bool restart) { DCHECK(!restart || handler_restarter); @@ -282,7 +282,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface { // port-destroyed notifications can be delivered. handler_restarter->notify_port_.reset(); } else { - base::mac::ScopedMachSendRight previous_owner(previous); + base::apple::ScopedMachSendRight previous_owner(previous); DCHECK(restart || !previous_owner.is_valid()); } @@ -430,7 +430,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface { std::string url_; std::map annotations_; std::vector arguments_; - base::mac::ScopedMachReceiveRight notify_port_; + base::apple::ScopedMachReceiveRight notify_port_; uint64_t last_start_time_; }; @@ -458,7 +458,7 @@ bool CrashpadClient::StartHandler( // The “restartable” behavior can only be selected on OS X 10.10 and later. In // previous OS versions, if the initial client were to crash while attempting // to restart the handler, it would become an unkillable process. - base::mac::ScopedMachSendRight exception_port(HandlerStarter::InitialStart( + base::apple::ScopedMachSendRight exception_port(HandlerStarter::InitialStart( handler, database, metrics_dir, @@ -476,7 +476,8 @@ bool CrashpadClient::StartHandler( } bool CrashpadClient::SetHandlerMachService(const std::string& service_name) { - base::mac::ScopedMachSendRight exception_port(BootstrapLookUp(service_name)); + base::apple::ScopedMachSendRight exception_port( + BootstrapLookUp(service_name)); if (!exception_port.is_valid()) { return false; } @@ -486,7 +487,7 @@ bool CrashpadClient::SetHandlerMachService(const std::string& service_name) { } bool CrashpadClient::SetHandlerMachPort( - base::mac::ScopedMachSendRight exception_port) { + base::apple::ScopedMachSendRight exception_port) { DCHECK(!exception_port_.is_valid()); DCHECK(exception_port.is_valid()); @@ -498,7 +499,7 @@ bool CrashpadClient::SetHandlerMachPort( return true; } -base::mac::ScopedMachSendRight CrashpadClient::GetHandlerMachPort() const { +base::apple::ScopedMachSendRight CrashpadClient::GetHandlerMachPort() const { DCHECK(exception_port_.is_valid()); // For the purposes of this method, only return a port set by @@ -519,16 +520,16 @@ base::mac::ScopedMachSendRight CrashpadClient::GetHandlerMachPort() const { mach_task_self(), exception_port_.get(), MACH_PORT_RIGHT_SEND, 1); if (kr != KERN_SUCCESS) { MACH_LOG(ERROR, kr) << "mach_port_mod_refs"; - return base::mac::ScopedMachSendRight(MACH_PORT_NULL); + return base::apple::ScopedMachSendRight(MACH_PORT_NULL); } - return base::mac::ScopedMachSendRight(exception_port_.get()); + return base::apple::ScopedMachSendRight(exception_port_.get()); } // static void CrashpadClient::UseSystemDefaultHandler() { - base::mac::ScopedMachSendRight - system_crash_reporter_handler(SystemCrashReporterHandler()); + base::apple::ScopedMachSendRight system_crash_reporter_handler( + SystemCrashReporterHandler()); // Proceed even if SystemCrashReporterHandler() failed, setting MACH_PORT_NULL // to clear the current exception ports. diff --git a/client/simulate_crash_mac.cc b/client/simulate_crash_mac.cc index d801a431..427d9d54 100644 --- a/client/simulate_crash_mac.cc +++ b/client/simulate_crash_mac.cc @@ -19,10 +19,10 @@ #include +#include "base/apple/mach_logging.h" +#include "base/apple/scoped_mach_port.h" #include "base/check_op.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" -#include "base/mac/scoped_mach_port.h" #include "build/build_config.h" #include "util/mach/exc_client_variants.h" #include "util/mach/exception_behaviors.h" @@ -205,7 +205,7 @@ void SimulateCrash(const NativeCPUContext& cpu_context) { #error Port to your CPU architecture #endif - base::mac::ScopedMachSendRight thread(mach_thread_self()); + base::apple::ScopedMachSendRight thread(mach_thread_self()); exception_type_t exception = kMachExceptionSimulated; mach_exception_data_type_t codes[] = {0, 0}; mach_msg_type_number_t code_count = std::size(codes); diff --git a/handler/handler_main.cc b/handler/handler_main.cc index b7ba6b14..7e908c0a 100644 --- a/handler/handler_main.cc +++ b/handler/handler_main.cc @@ -71,7 +71,7 @@ #include #include -#include "base/mac/scoped_mach_port.h" +#include "base/apple/scoped_mach_port.h" #include "handler/mac/crash_report_exception_handler.h" #include "handler/mac/exception_handler_server.h" #include "handler/mac/file_limit_annotation.h" @@ -1113,7 +1113,7 @@ int HandlerMain(int argc, CloseStdinAndStdout(); } - base::mac::ScopedMachReceiveRight receive_right; + base::apple::ScopedMachReceiveRight receive_right; if (options.handshake_fd >= 0) { receive_right.reset( diff --git a/handler/mac/crash_report_exception_handler.cc b/handler/mac/crash_report_exception_handler.cc index 01a7895e..28d5e2ab 100644 --- a/handler/mac/crash_report_exception_handler.cc +++ b/handler/mac/crash_report_exception_handler.cc @@ -17,9 +17,9 @@ #include #include +#include "base/apple/mach_logging.h" +#include "base/apple/scoped_mach_port.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" -#include "base/mac/scoped_mach_port.h" #include "base/strings/stringprintf.h" #include "client/settings.h" #include "handler/mac/file_limit_annotation.h" @@ -200,8 +200,8 @@ kern_return_t CrashReportExceptionHandler::CatchMachException( // processes that haven’t actually crashed, and could result in reports not // actually associated with crashes being sent to the operating system // vendor. - base::mac::ScopedMachSendRight - system_crash_reporter_handler(SystemCrashReporterHandler()); + base::apple::ScopedMachSendRight system_crash_reporter_handler( + SystemCrashReporterHandler()); if (system_crash_reporter_handler.get()) { // Make copies of mutable out parameters so that the system crash reporter // can’t influence the state returned by this method. diff --git a/handler/mac/exception_handler_server.cc b/handler/mac/exception_handler_server.cc index 0e7f505c..5357c8cd 100644 --- a/handler/mac/exception_handler_server.cc +++ b/handler/mac/exception_handler_server.cc @@ -16,8 +16,8 @@ #include +#include "base/apple/mach_logging.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" #include "util/mach/composite_mach_message_server.h" #include "util/mach/mach_extensions.h" #include "util/mach/mach_message.h" @@ -73,7 +73,7 @@ class ExceptionHandlerServerRun : public UniversalMachExcServer::Interface, MACH_MSG_TYPE_MAKE_SEND_ONCE, &previous); MACH_CHECK(kr == KERN_SUCCESS, kr) << "mach_port_request_notification"; - base::mac::ScopedMachSendRight previous_owner(previous); + base::apple::ScopedMachSendRight previous_owner(previous); } // A single CompositeMachMessageServer will dispatch both exception messages @@ -84,7 +84,7 @@ class ExceptionHandlerServerRun : public UniversalMachExcServer::Interface, // from ever existing. Using distinct receive rights also allows the handler // methods to ensure that the messages they process were sent by a holder of // the proper send right. - base::mac::ScopedMachPortSet server_port_set( + base::apple::ScopedMachPortSet server_port_set( NewMachPort(MACH_PORT_RIGHT_PORT_SET)); CHECK(server_port_set.is_valid()); @@ -192,7 +192,7 @@ class ExceptionHandlerServerRun : public UniversalMachExcServer::Interface, } // namespace ExceptionHandlerServer::ExceptionHandlerServer( - base::mac::ScopedMachReceiveRight receive_port, + base::apple::ScopedMachReceiveRight receive_port, bool launchd) : receive_port_(std::move(receive_port)), notify_port_(NewMachPort(MACH_PORT_RIGHT_RECEIVE)), diff --git a/handler/mac/exception_handler_server.h b/handler/mac/exception_handler_server.h index 085ebd8a..6d63a290 100644 --- a/handler/mac/exception_handler_server.h +++ b/handler/mac/exception_handler_server.h @@ -17,7 +17,7 @@ #include -#include "base/mac/scoped_mach_port.h" +#include "base/apple/scoped_mach_port.h" #include "util/mach/exc_server_variants.h" namespace crashpad { @@ -34,7 +34,7 @@ class ExceptionHandlerServer { //! launchd. \a receive_port is not monitored for no-senders //! notifications, and instead, Stop() must be called to provide a “quit” //! signal. - ExceptionHandlerServer(base::mac::ScopedMachReceiveRight receive_port, + ExceptionHandlerServer(base::apple::ScopedMachReceiveRight receive_port, bool launchd); ExceptionHandlerServer(const ExceptionHandlerServer&) = delete; @@ -73,8 +73,8 @@ class ExceptionHandlerServer { void Stop(); private: - base::mac::ScopedMachReceiveRight receive_port_; - base::mac::ScopedMachReceiveRight notify_port_; + base::apple::ScopedMachReceiveRight receive_port_; + base::apple::ScopedMachReceiveRight notify_port_; bool launchd_; }; diff --git a/snapshot/ios/exception_snapshot_ios_intermediate_dump.cc b/snapshot/ios/exception_snapshot_ios_intermediate_dump.cc index ede18d4c..cee9c8a7 100644 --- a/snapshot/ios/exception_snapshot_ios_intermediate_dump.cc +++ b/snapshot/ios/exception_snapshot_ios_intermediate_dump.cc @@ -14,8 +14,8 @@ #include "snapshot/ios/exception_snapshot_ios_intermediate_dump.h" +#include "base/apple/mach_logging.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" #include "snapshot/cpu_context.h" #include "snapshot/ios/intermediate_dump_reader_util.h" #include "snapshot/mac/cpu_context_mac.h" diff --git a/snapshot/ios/module_snapshot_ios_intermediate_dump.cc b/snapshot/ios/module_snapshot_ios_intermediate_dump.cc index 44c8c202..09498f14 100644 --- a/snapshot/ios/module_snapshot_ios_intermediate_dump.cc +++ b/snapshot/ios/module_snapshot_ios_intermediate_dump.cc @@ -17,8 +17,8 @@ #include #include +#include "base/apple/mach_logging.h" #include "base/files/file_path.h" -#include "base/mac/mach_logging.h" #include "client/annotation.h" #include "snapshot/ios/intermediate_dump_reader_util.h" #include "util/ios/ios_intermediate_dump_data.h" diff --git a/snapshot/ios/system_snapshot_ios_intermediate_dump.cc b/snapshot/ios/system_snapshot_ios_intermediate_dump.cc index be676857..15f66992 100644 --- a/snapshot/ios/system_snapshot_ios_intermediate_dump.cc +++ b/snapshot/ios/system_snapshot_ios_intermediate_dump.cc @@ -22,8 +22,8 @@ #include +#include "base/apple/mach_logging.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" #include "base/strings/stringprintf.h" #include "build/build_config.h" #include "snapshot/cpu_context.h" diff --git a/snapshot/ios/thread_snapshot_ios_intermediate_dump.cc b/snapshot/ios/thread_snapshot_ios_intermediate_dump.cc index 901e1f11..d37ccef3 100644 --- a/snapshot/ios/thread_snapshot_ios_intermediate_dump.cc +++ b/snapshot/ios/thread_snapshot_ios_intermediate_dump.cc @@ -14,7 +14,7 @@ #include "snapshot/ios/thread_snapshot_ios_intermediate_dump.h" -#include "base/mac/mach_logging.h" +#include "base/apple/mach_logging.h" #include "snapshot/ios/intermediate_dump_reader_util.h" #include "snapshot/mac/cpu_context_mac.h" #include "util/ios/ios_intermediate_dump_data.h" diff --git a/snapshot/mac/process_reader_mac.cc b/snapshot/mac/process_reader_mac.cc index c694eb0e..ebc3c970 100644 --- a/snapshot/mac/process_reader_mac.cc +++ b/snapshot/mac/process_reader_mac.cc @@ -21,10 +21,10 @@ #include #include +#include "base/apple/mach_logging.h" +#include "base/apple/scoped_mach_port.h" +#include "base/apple/scoped_mach_vm.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" -#include "base/mac/scoped_mach_port.h" -#include "base/mac/scoped_mach_vm.h" #include "base/strings/stringprintf.h" #include "snapshot/mac/mach_o_image_reader.h" #include "snapshot/mac/process_types.h" @@ -265,7 +265,7 @@ void ProcessReaderMac::InitializeThreads() { // loop below will leak thread port send rights. ScopedForbidReturn threads_need_owners; - base::mac::ScopedMachVM threads_vm( + base::apple::ScopedMachVM threads_vm( reinterpret_cast(threads), mach_vm_round_page(thread_count * sizeof(*threads))); diff --git a/snapshot/mac/process_reader_mac_test.cc b/snapshot/mac/process_reader_mac_test.cc index 14cf33d3..e2cb0b0a 100644 --- a/snapshot/mac/process_reader_mac_test.cc +++ b/snapshot/mac/process_reader_mac_test.cc @@ -30,9 +30,9 @@ #include #include +#include "base/apple/mach_logging.h" #include "base/check_op.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" #include "base/posix/eintr_wrapper.h" #include "base/strings/stringprintf.h" #include "build/build_config.h" @@ -361,7 +361,7 @@ void ExpectSeveralThreads(ThreadMap* thread_map, // Non-main threads use the stack region to store thread data. See // macOS 12 libpthread-486.100.11 src/pthread.c _pthread_allocate(). #if defined(ARCH_CPU_ARM64) - // arm64 has an additional offset for alignment. See macOS 12 + // arm64 has an additional offset for alignment. See macOS 12 // libpthread-486.100.11 src/pthread.c _pthread_allocate() and // PTHREAD_T_OFFSET (defined in src/types_internal.h). expected_stack_region_end += sizeof(_opaque_pthread_t) + 0x3000; @@ -864,7 +864,7 @@ TEST(ProcessReaderMac, SelfModules) { bool expect_timestamp; if (index == 0 && MacOSVersionNumber() < 12'00'00) { - // Pre-dyld4, dyld didn’t set the main executable's timestamp, and it was + // Pre-dyld4, dyld didn’t set the main executable's timestamp, and it was // reported as 0. EXPECT_EQ(modules[index].timestamp, 0); } else if (IsMalformedCLKernelsModule(modules[index].reader->FileType(), diff --git a/test/ios/host/handler_forbidden_allocators.cc b/test/ios/host/handler_forbidden_allocators.cc index 5ede632c..4e829f0b 100644 --- a/test/ios/host/handler_forbidden_allocators.cc +++ b/test/ios/host/handler_forbidden_allocators.cc @@ -19,7 +19,7 @@ #include #include -#include "base/mac/mach_logging.h" +#include "base/apple/mach_logging.h" #include "client/crashpad_client.h" #include "util/ios/raw_logging.h" diff --git a/test/mac/exception_swallower.cc b/test/mac/exception_swallower.cc index 52c2a2d6..132fb428 100644 --- a/test/mac/exception_swallower.cc +++ b/test/mac/exception_swallower.cc @@ -20,8 +20,8 @@ #include +#include "base/apple/scoped_mach_port.h" #include "base/check_op.h" -#include "base/mac/scoped_mach_port.h" #include "base/strings/stringprintf.h" #include "handler/mac/exception_handler_server.h" #include "util/mach/bootstrap.h" @@ -58,7 +58,7 @@ class ExceptionSwallower::ExceptionSwallowerThread public UniversalMachExcServer::Interface { public: explicit ExceptionSwallowerThread( - base::mac::ScopedMachReceiveRight receive_right) + base::apple::ScopedMachReceiveRight receive_right) : Thread(), UniversalMachExcServer::Interface(), exception_handler_server_(std::move(receive_right), true), @@ -129,7 +129,7 @@ ExceptionSwallower::ExceptionSwallower() : exception_swallower_thread_() { base::StringPrintf("org.chromium.crashpad.test.exception_swallower.%d.%s", getpid(), RandomString().c_str()); - base::mac::ScopedMachReceiveRight receive_right( + base::apple::ScopedMachReceiveRight receive_right( BootstrapCheckIn(service_name)); CHECK(receive_right.is_valid()); @@ -164,7 +164,7 @@ void ExceptionSwallower::SwallowExceptions() { const char* service_name = CheckedGetenv(kServiceEnvironmentVariable); CHECK(service_name); - base::mac::ScopedMachSendRight exception_swallower_port( + base::apple::ScopedMachSendRight exception_swallower_port( BootstrapLookUp(service_name)); CHECK(exception_swallower_port.is_valid()); diff --git a/test/mac/mach_errors.h b/test/mac/mach_errors.h index ba3191b0..862d717c 100644 --- a/test/mac/mach_errors.h +++ b/test/mac/mach_errors.h @@ -23,8 +23,9 @@ namespace crashpad { namespace test { // This function formats messages in a similar way to the Mach error logging -// macros in base/mac/mach_logging.h. It exists to interoperate with Google Test -// assertions, which don’t interoperate with logging but can be streamed to. +// macros in base/apple/mach_logging.h. It exists to interoperate with Google +// Test assertions, which don’t interoperate with logging but can be streamed +// to. // // Where non-test code could do: // MACH_CHECK(kr == KERN_SUCCESS, kr) << "vm_deallocate"; diff --git a/test/mac/mach_multiprocess.cc b/test/mac/mach_multiprocess.cc index 6af870e8..d317055f 100644 --- a/test/mac/mach_multiprocess.cc +++ b/test/mac/mach_multiprocess.cc @@ -21,8 +21,8 @@ #include #include +#include "base/apple/scoped_mach_port.h" #include "base/auto_reset.h" -#include "base/mac/scoped_mach_port.h" #include "gtest/gtest.h" #include "test/errors.h" #include "test/mac/mach_errors.h" @@ -64,9 +64,9 @@ struct MachMultiprocessInfo { } std::string service_name; - base::mac::ScopedMachReceiveRight local_port; - base::mac::ScopedMachSendRight remote_port; - base::mac::ScopedMachSendRight child_task; // valid only in parent + base::apple::ScopedMachReceiveRight local_port; + base::apple::ScopedMachSendRight remote_port; + base::apple::ScopedMachSendRight child_task; // valid only in parent }; } // namespace internal diff --git a/tools/generate_dump.cc b/tools/generate_dump.cc index f0aad1ba..75e0e535 100644 --- a/tools/generate_dump.cc +++ b/tools/generate_dump.cc @@ -38,7 +38,7 @@ #if BUILDFLAG(IS_APPLE) #include -#include "base/mac/scoped_mach_port.h" +#include "base/apple/scoped_mach_port.h" #include "snapshot/mac/process_snapshot_mac.h" #include "util/mach/scoped_task_suspend.h" #include "util/mach/task_for_pid.h" @@ -144,7 +144,7 @@ int GenerateDumpMain(int argc, char* argv[]) { if (task == TASK_NULL) { return EXIT_FAILURE; } - base::mac::ScopedMachSendRight task_owner(task); + base::apple::ScopedMachSendRight task_owner(task); // This tool may have been installed as a setuid binary so that TaskForPID() // could succeed. Drop any privileges now that they’re no longer necessary. diff --git a/tools/mac/catch_exception_tool.cc b/tools/mac/catch_exception_tool.cc index 8d71a337..3f226597 100644 --- a/tools/mac/catch_exception_tool.cc +++ b/tools/mac/catch_exception_tool.cc @@ -24,9 +24,9 @@ #include #include +#include "base/apple/mach_logging.h" #include "base/files/scoped_file.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" #include "tools/tool_support.h" #include "util/mach/bootstrap.h" #include "util/mach/exc_server_variants.h" @@ -267,8 +267,8 @@ int CatchExceptionToolMain(int argc, char* argv[]) { return EXIT_FAILURE; } - base::mac::ScopedMachReceiveRight - service_port(BootstrapCheckIn(options.mach_service)); + base::apple::ScopedMachReceiveRight service_port( + BootstrapCheckIn(options.mach_service)); if (service_port == kMachPortNull) { return EXIT_FAILURE; } diff --git a/tools/mac/exception_port_tool.cc b/tools/mac/exception_port_tool.cc index 0c0a2aa8..437c15f4 100644 --- a/tools/mac/exception_port_tool.cc +++ b/tools/mac/exception_port_tool.cc @@ -25,8 +25,8 @@ #include #include -#include "base/mac/mach_logging.h" -#include "base/mac/scoped_mach_port.h" +#include "base/apple/mach_logging.h" +#include "base/apple/scoped_mach_port.h" #include "tools/tool_support.h" #include "util/mach/bootstrap.h" #include "util/mach/exception_ports.h" @@ -43,7 +43,7 @@ namespace { //! destruction. //! //! This class effectively implements what a vector of -//! base::mac::ScopedMachSendRight objects would be. +//! base::apple::ScopedMachSendRight objects would be. //! //! The various “show” operations performed by this program display Mach ports //! by their names as they are known in this task. For this to be useful, rights @@ -191,7 +191,7 @@ bool ParseHandlerString(const char* handler_string_ro, // |mach_send_right_pool|. void ShowBootstrapService(const std::string& service_name, MachSendRightPool* mach_send_right_pool) { - base::mac::ScopedMachSendRight service_port(BootstrapLookUp(service_name)); + base::apple::ScopedMachSendRight service_port(BootstrapLookUp(service_name)); if (service_port == kMachPortNull) { return; } @@ -283,7 +283,7 @@ void ShowExceptionPorts(const ExceptionPorts& exception_ports, // desired. bool SetExceptionPort(const ExceptionHandlerDescription* description, mach_port_t target_port) { - base::mac::ScopedMachSendRight service_port; + base::apple::ScopedMachSendRight service_port; if (description->handler.compare( 0, strlen(kHandlerBootstrapColon), kHandlerBootstrapColon) == 0) { const char* service_name = @@ -490,7 +490,7 @@ int ExceptionPortToolMain(int argc, char* argv[]) { return kExitFailure; } - base::mac::ScopedMachSendRight alternate_task_owner; + base::apple::ScopedMachSendRight alternate_task_owner; if (options.pid) { if (argc) { ToolSupport::UsageHint(me, "cannot combine -p with COMMAND"); diff --git a/util/ios/ios_intermediate_dump_writer_test.cc b/util/ios/ios_intermediate_dump_writer_test.cc index d1eb583e..2bf2b780 100644 --- a/util/ios/ios_intermediate_dump_writer_test.cc +++ b/util/ios/ios_intermediate_dump_writer_test.cc @@ -17,8 +17,8 @@ #include #include +#include "base/apple/scoped_mach_vm.h" #include "base/files/scoped_file.h" -#include "base/mac/scoped_mach_vm.h" #include "base/posix/eintr_wrapper.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -141,8 +141,8 @@ TEST_F(IOSIntermediateDumpWriterTest, MissingPropertyString) { region_size, VM_FLAGS_ANYWHERE), 0); - base::mac::ScopedMachVM vm_owner(reinterpret_cast(region), - region_size); + base::apple::ScopedMachVM vm_owner(reinterpret_cast(region), + region_size); // Fill first page with 'A' and second with 'B'. memset(region, 'A', page_size); diff --git a/util/ios/ios_system_data_collector.mm b/util/ios/ios_system_data_collector.mm index 564c8e79..28ede182 100644 --- a/util/ios/ios_system_data_collector.mm +++ b/util/ios/ios_system_data_collector.mm @@ -21,7 +21,7 @@ #include #import -#include "base/mac/mach_logging.h" +#include "base/apple/mach_logging.h" #include "base/numerics/safe_conversions.h" #include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" diff --git a/util/ios/scoped_vm_map_test.cc b/util/ios/scoped_vm_map_test.cc index e88568a7..6a6b3ebc 100644 --- a/util/ios/scoped_vm_map_test.cc +++ b/util/ios/scoped_vm_map_test.cc @@ -16,7 +16,7 @@ #include -#include "base/mac/scoped_mach_vm.h" +#include "base/apple/scoped_mach_vm.h" #include "gtest/gtest.h" #include "test/mac/mach_errors.h" @@ -73,8 +73,8 @@ TEST(ScopedVMMapTest, MissingMiddleVM) { VM_FLAGS_ANYWHERE); ASSERT_EQ(kr, KERN_SUCCESS) << MachErrorMessage(kr, "vm_allocate"); - base::mac::ScopedMachVM vm_owner(reinterpret_cast(region), - region_size); + base::apple::ScopedMachVM vm_owner(reinterpret_cast(region), + region_size); internal::ScopedVMMap vmmap_missing_middle; ASSERT_TRUE(vmmap_missing_middle.Map(region, region_size)); diff --git a/util/ios/scoped_vm_read_test.cc b/util/ios/scoped_vm_read_test.cc index c8b2e758..29e5c232 100644 --- a/util/ios/scoped_vm_read_test.cc +++ b/util/ios/scoped_vm_read_test.cc @@ -16,7 +16,7 @@ #include -#include "base/mac/scoped_mach_vm.h" +#include "base/apple/scoped_mach_vm.h" #include "gtest/gtest.h" #include "test/mac/mach_errors.h" @@ -68,8 +68,8 @@ TEST(ScopedVMReadTest, MissingMiddleVM) { VM_FLAGS_ANYWHERE); ASSERT_EQ(kr, KERN_SUCCESS) << MachErrorMessage(kr, "vm_allocate"); - base::mac::ScopedMachVM vm_owner(reinterpret_cast(region), - region_size); + base::apple::ScopedMachVM vm_owner(reinterpret_cast(region), + region_size); internal::ScopedVMRead vmread_missing_middle; ASSERT_TRUE(vmread_missing_middle.Read(region, region_size)); diff --git a/util/mach/bootstrap.cc b/util/mach/bootstrap.cc index be2769b2..f369f7f3 100644 --- a/util/mach/bootstrap.cc +++ b/util/mach/bootstrap.cc @@ -17,7 +17,7 @@ #include #include -#include "base/mac/mach_logging.h" +#include "base/apple/mach_logging.h" namespace { @@ -26,7 +26,7 @@ namespace { // and the right type returned. struct BootstrapCheckInTraits { - using Type = base::mac::ScopedMachReceiveRight; + using Type = base::apple::ScopedMachReceiveRight; static kern_return_t Call(mach_port_t bootstrap_port, const char* service_name, mach_port_t* service_port) { @@ -37,7 +37,7 @@ struct BootstrapCheckInTraits { constexpr char BootstrapCheckInTraits::kName[]; struct BootstrapLookUpTraits { - using Type = base::mac::ScopedMachSendRight; + using Type = base::apple::ScopedMachSendRight; static kern_return_t Call(mach_port_t bootstrap_port, const char* service_name, mach_port_t* service_port) { @@ -73,14 +73,14 @@ typename Traits::Type BootstrapCheckInOrLookUp( namespace crashpad { -base::mac::ScopedMachReceiveRight BootstrapCheckIn( +base::apple::ScopedMachReceiveRight BootstrapCheckIn( const std::string& service_name) { return BootstrapCheckInOrLookUp(service_name); } -base::mac::ScopedMachSendRight BootstrapLookUp( +base::apple::ScopedMachSendRight BootstrapLookUp( const std::string& service_name) { - base::mac::ScopedMachSendRight send( + base::apple::ScopedMachSendRight send( BootstrapCheckInOrLookUp(service_name)); // It’s possible to race the bootstrap server when the receive right @@ -102,7 +102,7 @@ base::mac::ScopedMachSendRight BootstrapLookUp( return send; } -base::mac::ScopedMachSendRight SystemCrashReporterHandler() { +base::apple::ScopedMachSendRight SystemCrashReporterHandler() { return BootstrapLookUp("com.apple.ReportCrash"); } diff --git a/util/mach/bootstrap.h b/util/mach/bootstrap.h index 362627eb..35004c32 100644 --- a/util/mach/bootstrap.h +++ b/util/mach/bootstrap.h @@ -17,7 +17,7 @@ #include -#include "base/mac/scoped_mach_port.h" +#include "base/apple/scoped_mach_port.h" namespace crashpad { @@ -30,7 +30,7 @@ namespace crashpad { //! //! \return On success, a receive right to the service port. On failure, //! `MACH_PORT_NULL` with a message logged. -base::mac::ScopedMachReceiveRight BootstrapCheckIn( +base::apple::ScopedMachReceiveRight BootstrapCheckIn( const std::string& service_name); //! \brief Makes a `boostrap_look_up()` call to the process’ bootstrap server. @@ -42,7 +42,8 @@ base::mac::ScopedMachReceiveRight BootstrapCheckIn( //! //! \return On success, a send right to the service port. On failure, //! `MACH_PORT_NULL` with a message logged. -base::mac::ScopedMachSendRight BootstrapLookUp(const std::string& service_name); +base::apple::ScopedMachSendRight BootstrapLookUp( + const std::string& service_name); //! \brief Obtains the system’s default Mach exception handler for crash-type //! exceptions. @@ -56,7 +57,7 @@ base::mac::ScopedMachSendRight BootstrapLookUp(const std::string& service_name); //! \return On success, a send right to an `exception_handler_t` corresponding //! to the system’s default crash reporter. On failure, `MACH_PORT_NULL`, //! with a message logged. -base::mac::ScopedMachSendRight SystemCrashReporterHandler(); +base::apple::ScopedMachSendRight SystemCrashReporterHandler(); } // namespace crashpad diff --git a/util/mach/bootstrap_test.cc b/util/mach/bootstrap_test.cc index a4089bf1..196f5949 100644 --- a/util/mach/bootstrap_test.cc +++ b/util/mach/bootstrap_test.cc @@ -14,7 +14,7 @@ #include "util/mach/bootstrap.h" -#include "base/mac/scoped_mach_port.h" +#include "base/apple/scoped_mach_port.h" #include "gtest/gtest.h" #include "util/mach/mach_extensions.h" #include "util/misc/random_string.h" @@ -25,7 +25,7 @@ namespace { TEST(Bootstrap, BootstrapCheckInAndLookUp) { // This should always exist. - base::mac::ScopedMachSendRight report_crash( + base::apple::ScopedMachSendRight report_crash( BootstrapLookUp("com.apple.ReportCrash")); EXPECT_NE(report_crash, kMachPortNull); @@ -34,11 +34,11 @@ TEST(Bootstrap, BootstrapCheckInAndLookUp) { { // The new service hasn’t checked in yet, so this should fail. - base::mac::ScopedMachSendRight send(BootstrapLookUp(service_name)); + base::apple::ScopedMachSendRight send(BootstrapLookUp(service_name)); EXPECT_EQ(send, kMachPortNull); // Check it in. - base::mac::ScopedMachReceiveRight receive(BootstrapCheckIn(service_name)); + base::apple::ScopedMachReceiveRight receive(BootstrapCheckIn(service_name)); EXPECT_NE(receive, kMachPortNull); // Now it should be possible to look up the new service. @@ -46,21 +46,22 @@ TEST(Bootstrap, BootstrapCheckInAndLookUp) { EXPECT_NE(send, kMachPortNull); // It shouldn’t be possible to check the service in while it’s active. - base::mac::ScopedMachReceiveRight receive_2(BootstrapCheckIn(service_name)); + base::apple::ScopedMachReceiveRight receive_2( + BootstrapCheckIn(service_name)); EXPECT_EQ(receive_2, kMachPortNull); } // The new service should be gone now. - base::mac::ScopedMachSendRight send(BootstrapLookUp(service_name)); + base::apple::ScopedMachSendRight send(BootstrapLookUp(service_name)); EXPECT_EQ(send, kMachPortNull); // It should be possible to check it in again. - base::mac::ScopedMachReceiveRight receive(BootstrapCheckIn(service_name)); + base::apple::ScopedMachReceiveRight receive(BootstrapCheckIn(service_name)); EXPECT_NE(receive, kMachPortNull); } TEST(Bootstrap, SystemCrashReporterHandler) { - base::mac::ScopedMachSendRight system_crash_reporter_handler( + base::apple::ScopedMachSendRight system_crash_reporter_handler( SystemCrashReporterHandler()); EXPECT_TRUE(system_crash_reporter_handler.is_valid()); } diff --git a/util/mach/child_port_handshake.cc b/util/mach/child_port_handshake.cc index 6277a144..afbf55f1 100644 --- a/util/mach/child_port_handshake.cc +++ b/util/mach/child_port_handshake.cc @@ -27,10 +27,10 @@ #include #include +#include "base/apple/mach_logging.h" +#include "base/apple/scoped_mach_port.h" #include "base/check_op.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" -#include "base/mac/scoped_mach_port.h" #include "base/notreached.h" #include "base/posix/eintr_wrapper.h" #include "base/rand_util.h" @@ -113,7 +113,8 @@ mach_port_t ChildPortHandshakeServer::RunServer( // Check the new service in with the bootstrap server, obtaining a receive // right for it. - base::mac::ScopedMachReceiveRight server_port(BootstrapCheckIn(service_name)); + base::apple::ScopedMachReceiveRight server_port( + BootstrapCheckIn(service_name)); CHECK(server_port.is_valid()); // Share the service name with the client via the pipe. @@ -137,7 +138,7 @@ mach_port_t ChildPortHandshakeServer::RunServer( // MACH_PORT_RIGHT_PORT_SET, to 10.12.0 xnu-3789.1.32/osfmk/ipc/ipc_pset.c // filt_machportattach(), which also handles MACH_PORT_TYPE_RECEIVE. Create a // new port set and add the receive right to it. - base::mac::ScopedMachPortSet server_port_set( + base::apple::ScopedMachPortSet server_port_set( NewMachPort(MACH_PORT_RIGHT_PORT_SET)); CHECK(server_port_set.is_valid()); @@ -442,7 +443,7 @@ bool ChildPortHandshake::RunClientInternal_SendCheckIn( mach_msg_type_name_t right_type) { // Get a send right to the server by looking up the service with the bootstrap // server by name. - base::mac::ScopedMachSendRight server_port(BootstrapLookUp(service_name)); + base::apple::ScopedMachSendRight server_port(BootstrapLookUp(service_name)); if (server_port == kMachPortNull) { return false; } diff --git a/util/mach/child_port_handshake.h b/util/mach/child_port_handshake.h index 77a17714..9a0b8e10 100644 --- a/util/mach/child_port_handshake.h +++ b/util/mach/child_port_handshake.h @@ -107,7 +107,7 @@ class ChildPortHandshakeTest; //! server_write_fd.reset(); //! //! // Make a new Mach receive right. -//! base::mac::ScopedMachReceiveRight +//! base::apple::ScopedMachReceiveRight //! receive_right(NewMachPort(MACH_PORT_RIGHT_RECEIVE)); //! //! // Make a send right corresponding to the receive right. @@ -118,7 +118,7 @@ class ChildPortHandshakeTest; //! MACH_MSG_TYPE_MAKE_SEND, //! &send_right, //! &send_right_type); -//! base::mac::ScopedMachSendRight send_right_owner(send_right); +//! base::apple::ScopedMachSendRight send_right_owner(send_right); //! //! // Send the receive right to the child process, retaining the send right //! // for use in the parent process. @@ -136,7 +136,7 @@ class ChildPortHandshakeTest; //! base::ScopedFD server_write_fd(atoi(argv[1])); //! //! // Obtain a receive right from the parent process. -//! base::mac::ScopedMachReceiveRight receive_right( +//! base::apple::ScopedMachReceiveRight receive_right( //! ChildPortHandshake::RunServerForFD( //! std::move(server_write_fd), //! ChildPortHandshake::PortRightType::kReceiveRight)); diff --git a/util/mach/child_port_handshake_test.cc b/util/mach/child_port_handshake_test.cc index fc85f559..e8fe91b7 100644 --- a/util/mach/child_port_handshake_test.cc +++ b/util/mach/child_port_handshake_test.cc @@ -14,7 +14,7 @@ #include "util/mach/child_port_handshake.h" -#include "base/mac/scoped_mach_port.h" +#include "base/apple/scoped_mach_port.h" #include "gtest/gtest.h" #include "test/multiprocess.h" #include "util/mach/child_port_types.h" @@ -99,8 +99,8 @@ class ChildPortHandshakeTest : public Multiprocess { return; } - base::mac::ScopedMachReceiveRight receive_right; - base::mac::ScopedMachSendRight send_right; + base::apple::ScopedMachReceiveRight receive_right; + base::apple::ScopedMachSendRight send_right; if (test_type_ == TestType::kClientChecksIn_ReceiveRight) { receive_right.reset(child_port_handshake_.RunServer( ChildPortHandshake::PortRightType::kReceiveRight)); @@ -152,7 +152,7 @@ class ChildPortHandshakeTest : public Multiprocess { } case TestType::kClientChecksIn_SendOnceRight: { - base::mac::ScopedMachReceiveRight receive_right( + base::apple::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); ASSERT_TRUE(child_port_handshake_.RunClient( receive_right.get(), MACH_MSG_TYPE_MAKE_SEND_ONCE)); @@ -372,7 +372,7 @@ TEST(ChildPortHandshake, NoClient) { // is similar to kClientDoesNotCheckIn, but because there’s no client at all, // the server is guaranteed to see that its pipe partner is gone. ChildPortHandshake child_port_handshake; - base::mac::ScopedMachSendRight child_port(child_port_handshake.RunServer( + base::apple::ScopedMachSendRight child_port(child_port_handshake.RunServer( ChildPortHandshake::PortRightType::kSendRight)); EXPECT_FALSE(child_port.is_valid()); } diff --git a/util/mach/exception_ports.cc b/util/mach/exception_ports.cc index 1184045c..b983cc6c 100644 --- a/util/mach/exception_ports.cc +++ b/util/mach/exception_ports.cc @@ -14,8 +14,8 @@ #include "util/mach/exception_ports.h" +#include "base/apple/mach_logging.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" #include "base/notreached.h" namespace crashpad { diff --git a/util/mach/exception_ports_test.cc b/util/mach/exception_ports_test.cc index f6a88672..b37a99a2 100644 --- a/util/mach/exception_ports_test.cc +++ b/util/mach/exception_ports_test.cc @@ -19,9 +19,9 @@ #include #include +#include "base/apple/mach_logging.h" +#include "base/apple/scoped_mach_port.h" #include "base/check.h" -#include "base/mac/mach_logging.h" -#include "base/mac/scoped_mach_port.h" #include "base/notreached.h" #include "build/build_config.h" #include "gtest/gtest.h" @@ -444,8 +444,8 @@ class TestExceptionPorts : public MachMultiprocess, ScopedForbidReturn threads_need_owners; ASSERT_EQ(thread_count, 2u); - base::mac::ScopedMachSendRight main_thread(threads[0]); - base::mac::ScopedMachSendRight other_thread(threads[1]); + base::apple::ScopedMachSendRight main_thread(threads[0]); + base::apple::ScopedMachSendRight other_thread(threads[1]); threads_need_owners.Disarm(); ExceptionPorts main_thread_ports(ExceptionPorts::kTargetTypeThread, @@ -467,7 +467,7 @@ class TestExceptionPorts : public MachMultiprocess, mach_task_self(), local_port, local_port, MACH_MSG_TYPE_MAKE_SEND); ASSERT_EQ(kr, KERN_SUCCESS) << MachErrorMessage(kr, "mach_port_insert_right"); - base::mac::ScopedMachSendRight send_owner(local_port); + base::apple::ScopedMachSendRight send_owner(local_port); switch (set_or_swap_) { case kSetExceptionPort: { @@ -819,7 +819,7 @@ TEST(ExceptionPorts, HostExceptionPorts) { const bool expect_success = geteuid() == 0; - base::mac::ScopedMachSendRight host(mach_host_self()); + base::apple::ScopedMachSendRight host(mach_host_self()); ExceptionPorts explicit_host_ports(ExceptionPorts::kTargetTypeHost, host.get()); EXPECT_STREQ("host", explicit_host_ports.TargetTypeName()); diff --git a/util/mach/exception_types.cc b/util/mach/exception_types.cc index c050b285..e73b7c8b 100644 --- a/util/mach/exception_types.cc +++ b/util/mach/exception_types.cc @@ -21,9 +21,9 @@ #include #include +#include "base/apple/mach_logging.h" #include "base/check_op.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" #include "util/mac/mac_util.h" #include "util/mach/mach_extensions.h" #include "util/misc/no_cfi_icall.h" diff --git a/util/mach/mach_extensions.cc b/util/mach/mach_extensions.cc index 885d6074..463d364a 100644 --- a/util/mach/mach_extensions.cc +++ b/util/mach/mach_extensions.cc @@ -17,7 +17,7 @@ #include #include -#include "base/mac/mach_logging.h" +#include "base/apple/mach_logging.h" #include "build/build_config.h" #include "util/mac/mac_util.h" diff --git a/util/mach/mach_extensions_test.cc b/util/mach/mach_extensions_test.cc index 0314b698..31042f7c 100644 --- a/util/mach/mach_extensions_test.cc +++ b/util/mach/mach_extensions_test.cc @@ -14,7 +14,7 @@ #include "util/mach/mach_extensions.h" -#include "base/mac/scoped_mach_port.h" +#include "base/apple/scoped_mach_port.h" #include "build/build_config.h" #include "gtest/gtest.h" #include "test/mac/mach_errors.h" @@ -25,12 +25,13 @@ namespace test { namespace { TEST(MachExtensions, MachThreadSelf) { - base::mac::ScopedMachSendRight thread_self(mach_thread_self()); + base::apple::ScopedMachSendRight thread_self(mach_thread_self()); EXPECT_EQ(MachThreadSelf(), thread_self); } TEST(MachExtensions, NewMachPort_Receive) { - base::mac::ScopedMachReceiveRight port(NewMachPort(MACH_PORT_RIGHT_RECEIVE)); + base::apple::ScopedMachReceiveRight port( + NewMachPort(MACH_PORT_RIGHT_RECEIVE)); ASSERT_NE(port, kMachPortNull); mach_port_type_t type; @@ -41,7 +42,7 @@ TEST(MachExtensions, NewMachPort_Receive) { } TEST(MachExtensions, NewMachPort_PortSet) { - base::mac::ScopedMachPortSet port(NewMachPort(MACH_PORT_RIGHT_PORT_SET)); + base::apple::ScopedMachPortSet port(NewMachPort(MACH_PORT_RIGHT_PORT_SET)); ASSERT_NE(port, kMachPortNull); mach_port_type_t type; @@ -52,7 +53,7 @@ TEST(MachExtensions, NewMachPort_PortSet) { } TEST(MachExtensions, NewMachPort_DeadName) { - base::mac::ScopedMachSendRight port(NewMachPort(MACH_PORT_RIGHT_DEAD_NAME)); + base::apple::ScopedMachSendRight port(NewMachPort(MACH_PORT_RIGHT_DEAD_NAME)); ASSERT_NE(port, kMachPortNull); mach_port_type_t type; diff --git a/util/mach/mach_message.cc b/util/mach/mach_message.cc index 008724fb..28e42279 100644 --- a/util/mach/mach_message.cc +++ b/util/mach/mach_message.cc @@ -18,8 +18,8 @@ #include +#include "base/apple/mach_logging.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" #include "build/build_config.h" #include "util/misc/clock.h" #include "util/misc/implicit_cast.h" diff --git a/util/mach/mach_message_server.cc b/util/mach/mach_message_server.cc index e1529c66..bfe8a8cf 100644 --- a/util/mach/mach_message_server.cc +++ b/util/mach/mach_message_server.cc @@ -18,9 +18,9 @@ #include +#include "base/apple/mach_logging.h" +#include "base/apple/scoped_mach_vm.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" -#include "base/mac/scoped_mach_vm.h" #include "util/mach/mach_message.h" namespace crashpad { @@ -83,7 +83,7 @@ class MachMessageBuffer { } private: - base::mac::ScopedMachVM vm_; + base::apple::ScopedMachVM vm_; }; // Wraps MachMessageWithDeadline(), using a MachMessageBuffer argument which diff --git a/util/mach/mach_message_server_test.cc b/util/mach/mach_message_server_test.cc index dd6c1b2c..335aa7bf 100644 --- a/util/mach/mach_message_server_test.cc +++ b/util/mach/mach_message_server_test.cc @@ -22,7 +22,7 @@ #include #include -#include "base/mac/scoped_mach_port.h" +#include "base/apple/scoped_mach_port.h" #include "gtest/gtest.h" #include "test/mac/mach_errors.h" #include "test/mac/mach_multiprocess.h" @@ -445,7 +445,7 @@ class TestMachMessageServer : public MachMessageServer::Interface, // local_receive_port_owner will the receive right that is created in this // scope and intended to be destroyed when leaving this scope, after it has // been carried in a Mach message. - base::mac::ScopedMachReceiveRight local_receive_port_owner; + base::apple::ScopedMachReceiveRight local_receive_port_owner; // A LargeRequestMessage is always allocated, but the message that will be // sent will be a normal RequestMessage due to the msgh_size field @@ -582,7 +582,7 @@ class TestMachMessageServer : public MachMessageServer::Interface, // A receive right allocated in the child process. A send right will be // created from this right and sent to the parent parent process in the // request message. - base::mac::ScopedMachReceiveRight child_complex_message_port_; + base::apple::ScopedMachReceiveRight child_complex_message_port_; // The send right received in the parent process. This right is stored in a // member variable to test that resources carried in complex messages are diff --git a/util/mach/mach_message_test.cc b/util/mach/mach_message_test.cc index b7778132..5698179e 100644 --- a/util/mach/mach_message_test.cc +++ b/util/mach/mach_message_test.cc @@ -18,7 +18,7 @@ #include -#include "base/mac/scoped_mach_port.h" +#include "base/apple/scoped_mach_port.h" #include "build/build_config.h" #include "gtest/gtest.h" #include "test/mac/mach_errors.h" @@ -116,7 +116,7 @@ TEST(MachMessage, MachMessageDestroyReceivedPort) { ASSERT_NE(port, kMachPortNull); EXPECT_TRUE(MachMessageDestroyReceivedPort(port, MACH_MSG_TYPE_PORT_RECEIVE)); - base::mac::ScopedMachReceiveRight receive( + base::apple::ScopedMachReceiveRight receive( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); mach_msg_type_name_t right_type; kern_return_t kr = mach_port_extract_right(mach_task_self(), @@ -163,7 +163,8 @@ TEST(MachMessage, MachMessageDestroyReceivedPort) { #if BUILDFLAG(IS_MAC) TEST(MachMessage, AuditPIDFromMachMessageTrailer) { - base::mac::ScopedMachReceiveRight port(NewMachPort(MACH_PORT_RIGHT_RECEIVE)); + base::apple::ScopedMachReceiveRight port( + NewMachPort(MACH_PORT_RIGHT_RECEIVE)); ASSERT_NE(port, kMachPortNull); mach_msg_empty_send_t send = {}; diff --git a/util/mach/notify_server_test.cc b/util/mach/notify_server_test.cc index 324439ed..2c9e7e6a 100644 --- a/util/mach/notify_server_test.cc +++ b/util/mach/notify_server_test.cc @@ -16,8 +16,8 @@ #include +#include "base/apple/scoped_mach_port.h" #include "base/compiler_specific.h" -#include "base/mac/scoped_mach_port.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "test/mac/mach_errors.h" @@ -234,7 +234,7 @@ class NotifyServerTestBase : public testing::Test, return false; } - base::mac::ScopedMachSendRight previous_owner(previous); + base::apple::ScopedMachSendRight previous_owner(previous); EXPECT_EQ(previous, kMachPortNull); return true; @@ -284,7 +284,7 @@ class NotifyServerTestBase : public testing::Test, void TearDown() override { server_port_.reset(); } private: - base::mac::ScopedMachReceiveRight server_port_; + base::apple::ScopedMachReceiveRight server_port_; }; using NotifyServerTest = StrictMock; @@ -319,11 +319,11 @@ TEST_F(NotifyServerTest, NoNotification) { // When a send-once right with a dead-name notification request is deallocated, // a port-deleted notification should be generated. TEST_F(NotifyServerTest, MachNotifyPortDeleted) { - base::mac::ScopedMachReceiveRight receive_right( + base::apple::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); ASSERT_TRUE(receive_right.is_valid()); - base::mac::ScopedMachSendRight send_once_right( + base::apple::ScopedMachSendRight send_once_right( SendOnceRightFromReceiveRight(receive_right.get())); ASSERT_TRUE(send_once_right.is_valid()); @@ -346,7 +346,7 @@ TEST_F(NotifyServerTest, MachNotifyPortDeleted) { // When a receive right with a port-destroyed notification request is destroyed, // a port-destroyed notification should be generated. TEST_F(NotifyServerTest, MachNotifyPortDestroyed) { - base::mac::ScopedMachReceiveRight receive_right( + base::apple::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); ASSERT_TRUE(receive_right.is_valid()); @@ -370,7 +370,7 @@ TEST_F(NotifyServerTest, MachNotifyPortDestroyed) { // When a receive right with a port-destroyed notification request is not // destroyed, no port-destroyed notification should be generated. TEST_F(NotifyServerTest, MachNotifyPortDestroyed_NoNotification) { - base::mac::ScopedMachReceiveRight receive_right( + base::apple::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); ASSERT_TRUE(receive_right.is_valid()); @@ -383,7 +383,7 @@ TEST_F(NotifyServerTest, MachNotifyPortDestroyed_NoNotification) { // When a no-senders notification request is registered for a receive right with // no senders, a no-senders notification should be generated. TEST_F(NotifyServerTest, MachNotifyNoSenders_NoSendRight) { - base::mac::ScopedMachReceiveRight receive_right( + base::apple::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); ASSERT_TRUE(receive_right.is_valid()); @@ -403,11 +403,11 @@ TEST_F(NotifyServerTest, MachNotifyNoSenders_NoSendRight) { // notification request is deallocated, a no-senders notification should be // generated. TEST_F(NotifyServerTest, MachNotifyNoSenders_SendRightDeallocated) { - base::mac::ScopedMachReceiveRight receive_right( + base::apple::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); ASSERT_TRUE(receive_right.is_valid()); - base::mac::ScopedMachSendRight send_right( + base::apple::ScopedMachSendRight send_right( SendRightFromReceiveRight(receive_right.get())); ASSERT_TRUE(send_right.is_valid()); @@ -428,15 +428,15 @@ TEST_F(NotifyServerTest, MachNotifyNoSenders_SendRightDeallocated) { // When the a receive right with a no-senders notification request never loses // all senders, no no-senders notification should be generated. TEST_F(NotifyServerTest, MachNotifyNoSenders_NoNotification) { - base::mac::ScopedMachReceiveRight receive_right( + base::apple::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); ASSERT_TRUE(receive_right.is_valid()); - base::mac::ScopedMachSendRight send_right_0( + base::apple::ScopedMachSendRight send_right_0( SendRightFromReceiveRight(receive_right.get())); ASSERT_TRUE(send_right_0.is_valid()); - base::mac::ScopedMachSendRight send_right_1( + base::apple::ScopedMachSendRight send_right_1( SendRightFromReceiveRight(receive_right.get())); ASSERT_TRUE(send_right_1.is_valid()); @@ -454,7 +454,7 @@ TEST_F(NotifyServerTest, MachNotifyNoSenders_NoNotification) { // When a send-once right is deallocated without being used, a send-once // notification notification should be sent via the send-once right. TEST_F(NotifyServerTest, MachNotifySendOnce_ExplicitDeallocation) { - base::mac::ScopedMachSendRight send_once_right( + base::apple::ScopedMachSendRight send_once_right( SendOnceRightFromReceiveRight(ServerPort())); ASSERT_TRUE(send_once_right.is_valid()); @@ -473,7 +473,7 @@ TEST_F(NotifyServerTest, MachNotifySendOnce_ExplicitDeallocation) { // the send-once right is destroyed, and a send-once notification should appear // on the reply port. TEST_F(NotifyServerTest, MachNotifySendOnce_ImplicitDeallocation) { - base::mac::ScopedMachReceiveRight receive_right( + base::apple::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); ASSERT_TRUE(receive_right.is_valid()); @@ -507,11 +507,11 @@ TEST_F(NotifyServerTest, MachNotifySendOnce_ImplicitDeallocation) { // notification request is destroyed, a dead-name notification should be // generated. TEST_F(NotifyServerTest, MachNotifyDeadName) { - base::mac::ScopedMachReceiveRight receive_right( + base::apple::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); ASSERT_TRUE(receive_right.is_valid()); - base::mac::ScopedMachSendRight send_once_right( + base::apple::ScopedMachSendRight send_once_right( SendOnceRightFromReceiveRight(receive_right.get())); ASSERT_TRUE(send_once_right.is_valid()); @@ -546,11 +546,11 @@ TEST_F(NotifyServerTest, MachNotifyDeadName) { // notification request is not destroyed, no dead-name notification should be // generated. TEST_F(NotifyServerTest, MachNotifyDeadName_NoNotification) { - base::mac::ScopedMachReceiveRight receive_right( + base::apple::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); ASSERT_TRUE(receive_right.is_valid()); - base::mac::ScopedMachSendRight send_once_right( + base::apple::ScopedMachSendRight send_once_right( SendOnceRightFromReceiveRight(receive_right.get())); ASSERT_TRUE(send_once_right.is_valid()); diff --git a/util/mach/scoped_task_suspend.cc b/util/mach/scoped_task_suspend.cc index b91a16a6..67cad4f1 100644 --- a/util/mach/scoped_task_suspend.cc +++ b/util/mach/scoped_task_suspend.cc @@ -14,9 +14,9 @@ #include "util/mach/scoped_task_suspend.h" +#include "base/apple/mach_logging.h" #include "base/check_op.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" namespace crashpad { diff --git a/util/mach/task_for_pid.cc b/util/mach/task_for_pid.cc index 08e031d7..5827dc45 100644 --- a/util/mach/task_for_pid.cc +++ b/util/mach/task_for_pid.cc @@ -21,8 +21,8 @@ #include #include -#include "base/mac/mach_logging.h" -#include "base/mac/scoped_mach_port.h" +#include "base/apple/mach_logging.h" +#include "base/apple/scoped_mach_port.h" #include "util/posix/process_info.h" namespace crashpad { @@ -154,7 +154,7 @@ task_t TaskForPID(pid_t pid) { return TASK_NULL; } - base::mac::ScopedMachSendRight task_owner(task); + base::apple::ScopedMachSendRight task_owner(task); if (!TaskForPIDCheck(task)) { return TASK_NULL; diff --git a/util/misc/clock_mac.cc b/util/misc/clock_mac.cc index e2142ed4..81e53170 100644 --- a/util/misc/clock_mac.cc +++ b/util/misc/clock_mac.cc @@ -16,7 +16,7 @@ #include -#include "base/mac/mach_logging.h" +#include "base/apple/mach_logging.h" namespace { diff --git a/util/posix/process_info_mac.cc b/util/posix/process_info_mac.cc index 23f8b72f..07a93a5b 100644 --- a/util/posix/process_info_mac.cc +++ b/util/posix/process_info_mac.cc @@ -18,8 +18,8 @@ #include +#include "base/apple/mach_logging.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" namespace crashpad { diff --git a/util/process/process_memory_mac.cc b/util/process/process_memory_mac.cc index fc8719b4..a3cb6696 100644 --- a/util/process/process_memory_mac.cc +++ b/util/process/process_memory_mac.cc @@ -19,8 +19,8 @@ #include +#include "base/apple/mach_logging.h" #include "base/logging.h" -#include "base/mac/mach_logging.h" #include "base/strings/stringprintf.h" #include "util/stdlib/strnlen.h" diff --git a/util/process/process_memory_mac.h b/util/process/process_memory_mac.h index 6c76e3d2..9803daf9 100644 --- a/util/process/process_memory_mac.h +++ b/util/process/process_memory_mac.h @@ -21,7 +21,7 @@ #include #include -#include "base/mac/scoped_mach_vm.h" +#include "base/apple/scoped_mach_vm.h" #include "util/misc/address_types.h" #include "util/misc/initialization_state_dcheck.h" #include "util/process/process_memory.h" @@ -82,7 +82,7 @@ class ProcessMemoryMac : public ProcessMemory { size_t user_offset, size_t user_size); - base::mac::ScopedMachVM vm_; + base::apple::ScopedMachVM vm_; const void* data_; size_t user_size_; diff --git a/util/process/process_memory_mac_test.cc b/util/process/process_memory_mac_test.cc index 9e2b7b06..296b536d 100644 --- a/util/process/process_memory_mac_test.cc +++ b/util/process/process_memory_mac_test.cc @@ -21,8 +21,8 @@ #include #include -#include "base/mac/scoped_mach_port.h" -#include "base/mac/scoped_mach_vm.h" +#include "base/apple/scoped_mach_port.h" +#include "base/apple/scoped_mach_vm.h" #include "gtest/gtest.h" #include "test/mac/mach_errors.h" #include "util/misc/from_pointer_cast.h" @@ -37,7 +37,7 @@ TEST(ProcessMemoryMac, ReadMappedSelf) { kern_return_t kr = vm_allocate(mach_task_self(), &address, kSize, VM_FLAGS_ANYWHERE); ASSERT_EQ(kr, KERN_SUCCESS) << MachErrorMessage(kr, "vm_allocate"); - base::mac::ScopedMachVM vm_owner(address, mach_vm_round_page(kSize)); + base::apple::ScopedMachVM vm_owner(address, mach_vm_round_page(kSize)); char* region = reinterpret_cast(address); for (size_t index = 0; index < kSize; ++index) { @@ -92,7 +92,7 @@ TEST(ProcessMemoryMac, ReadSelfUnmapped) { kern_return_t kr = vm_allocate(mach_task_self(), &address, kSize, VM_FLAGS_ANYWHERE); ASSERT_EQ(kr, KERN_SUCCESS) << MachErrorMessage(kr, "vm_allocate"); - base::mac::ScopedMachVM vm_owner(address, mach_vm_round_page(kSize)); + base::apple::ScopedMachVM vm_owner(address, mach_vm_round_page(kSize)); char* region = reinterpret_cast(address); for (size_t index = 0; index < kSize; ++index) { @@ -154,7 +154,7 @@ TEST(ProcessMemoryMac, ReadCStringSelfUnmapped) { kern_return_t kr = vm_allocate(mach_task_self(), &address, kSize, VM_FLAGS_ANYWHERE); ASSERT_EQ(kr, KERN_SUCCESS) << MachErrorMessage(kr, "vm_allocate"); - base::mac::ScopedMachVM vm_owner(address, mach_vm_round_page(kSize)); + base::apple::ScopedMachVM vm_owner(address, mach_vm_round_page(kSize)); char* region = reinterpret_cast(address); for (size_t index = 0; index < kSize; ++index) { @@ -219,7 +219,7 @@ bool IsAddressMapped(vm_address_t address) { // |object| will be MACH_PORT_NULL (10.9.4 xnu-2422.110.17/osfmk/vm/vm_map.c // vm_map_region()), but the interface acts as if it might carry a send // right, so treat it as documented. - base::mac::ScopedMachSendRight object_owner(object); + base::apple::ScopedMachSendRight object_owner(object); return address >= region_address && address <= region_address + region_size; } From 13e3accfe82059b0028844b5a05c690f730a36ba Mon Sep 17 00:00:00 2001 From: Avi Drissman Date: Thu, 17 Aug 2023 11:10:53 -0400 Subject: [PATCH 040/107] Roll mini_chromium, adjust to more files in base/apple This rolls mini_chromium to the version that has more files in base/apple, and adjusts the code to match. Bug: chromium:1444927 Change-Id: I9642698c8c16151bd0aaca7b46745a59d6e5e6d3 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4791121 Reviewed-by: Mark Mentovai Commit-Queue: Avi Drissman --- DEPS | 2 +- util/mac/launchd.mm | 17 +++++++++-------- util/mac/mac_util.cc | 17 +++++++++-------- util/mac/service_management_test.mm | 2 +- util/net/http_transport_mac.mm | 8 ++++---- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/DEPS b/DEPS index 42037773..d268bd96 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - 'f5370228f40bbb8c453e17f6af6c6742858c45d1', + 'e35fc73aa87bb27e10306900b15a18b0e9c7ca42', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', diff --git a/util/mac/launchd.mm b/util/mac/launchd.mm index 35620ba5..c711747b 100644 --- a/util/mac/launchd.mm +++ b/util/mac/launchd.mm @@ -17,8 +17,8 @@ #import #include "base/apple/bridging.h" -#include "base/mac/foundation_util.h" -#include "base/mac/scoped_cftyperef.h" +#include "base/apple/foundation_util.h" +#include "base/apple/scoped_cftyperef.h" #include "base/mac/scoped_launch_data.h" #include "base/strings/sys_string_conversions.h" #include "util/misc/implicit_cast.h" @@ -36,7 +36,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { if (type_id_cf == CFDictionaryGetTypeID()) { NSDictionary* dictionary_ns = base::apple::CFToNSPtrCast( - base::mac::CFCastStrict(property_cf)); + base::apple::CFCastStrict(property_cf)); base::mac::ScopedLaunchData dictionary_launch( LaunchDataAlloc(LAUNCH_DATA_DICTIONARY)); @@ -60,7 +60,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { } else if (type_id_cf == CFArrayGetTypeID()) { NSArray* array_ns = base::apple::CFToNSPtrCast( - base::mac::CFCastStrict(property_cf)); + base::apple::CFCastStrict(property_cf)); base::mac::ScopedLaunchData array_launch( LaunchDataAlloc(LAUNCH_DATA_ARRAY)); size_t index = 0; @@ -78,7 +78,8 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { data_launch = array_launch.release(); } else if (type_id_cf == CFNumberGetTypeID()) { - CFNumberRef number_cf = base::mac::CFCastStrict(property_cf); + CFNumberRef number_cf = + base::apple::CFCastStrict(property_cf); NSNumber* number_ns = base::apple::CFToNSPtrCast(number_cf); switch (CFNumberGetType(number_cf)) { case kCFNumberSInt8Type: @@ -109,12 +110,12 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { } else if (type_id_cf == CFBooleanGetTypeID()) { CFBooleanRef boolean_cf = - base::mac::CFCastStrict(property_cf); + base::apple::CFCastStrict(property_cf); data_launch = LaunchDataNewBool(CFBooleanGetValue(boolean_cf)); } else if (type_id_cf == CFStringGetTypeID()) { NSString* string_ns = base::apple::CFToNSPtrCast( - base::mac::CFCastStrict(property_cf)); + base::apple::CFCastStrict(property_cf)); // -fileSystemRepresentation might be more correct than -UTF8String, // because these strings can hold paths. The analogous function in @@ -126,7 +127,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { } else if (type_id_cf == CFDataGetTypeID()) { NSData* data_ns = base::apple::CFToNSPtrCast( - base::mac::CFCastStrict(property_cf)); + base::apple::CFCastStrict(property_cf)); data_launch = LaunchDataNewOpaque([data_ns bytes], [data_ns length]); } else { base::ScopedCFTypeRef type_name_cf( diff --git a/util/mac/mac_util.cc b/util/mac/mac_util.cc index ed2bfb73..f1898620 100644 --- a/util/mac/mac_util.cc +++ b/util/mac/mac_util.cc @@ -21,10 +21,10 @@ #include #include +#include "base/apple/foundation_util.h" +#include "base/apple/scoped_cftyperef.h" #include "base/check_op.h" #include "base/logging.h" -#include "base/mac/foundation_util.h" -#include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_ioobject.h" #include "base/notreached.h" #include "base/strings/string_number_conversions.h" @@ -168,7 +168,7 @@ std::string IORegistryEntryDataPropertyAsString(io_registry_entry_t entry, CFStringRef key) { base::ScopedCFTypeRef property( IORegistryEntryCreateCFProperty(entry, key, kCFAllocatorDefault, 0)); - CFDataRef data = base::mac::CFCast(property); + CFDataRef data = base::apple::CFCast(property); if (data && CFDataGetLength(data) > 0) { return reinterpret_cast(CFDataGetBytePtr(data)); } @@ -244,7 +244,7 @@ bool MacOSVersionComponents(int* major, bool success = true; - CFStringRef version_cf = base::mac::CFCast( + CFStringRef version_cf = base::apple::CFCast( TryCFDictionaryGetValue(dictionary, _kCFSystemVersionProductVersionKey)); std::string version; if (!version_cf) { @@ -264,7 +264,7 @@ bool MacOSVersionComponents(int* major, } } - CFStringRef build_cf = base::mac::CFCast( + CFStringRef build_cf = base::apple::CFCast( TryCFDictionaryGetValue(dictionary, _kCFSystemVersionBuildVersionKey)); if (!build_cf) { LOG(ERROR) << "build_cf not found"; @@ -273,7 +273,7 @@ bool MacOSVersionComponents(int* major, build->assign(base::SysCFStringRefToUTF8(build_cf)); } - CFStringRef product_cf = base::mac::CFCast( + CFStringRef product_cf = base::apple::CFCast( TryCFDictionaryGetValue(dictionary, _kCFSystemVersionProductNameKey)); std::string product; if (!product_cf) { @@ -284,8 +284,9 @@ bool MacOSVersionComponents(int* major, } // This key is not required, and in fact is normally not present. - CFStringRef extra_cf = base::mac::CFCast(TryCFDictionaryGetValue( - dictionary, _kCFSystemVersionProductVersionExtraKey)); + CFStringRef extra_cf = + base::apple::CFCast(TryCFDictionaryGetValue( + dictionary, _kCFSystemVersionProductVersionExtraKey)); std::string extra; if (extra_cf) { extra = base::SysCFStringRefToUTF8(extra_cf); diff --git a/util/mac/service_management_test.mm b/util/mac/service_management_test.mm index 85335284..26c96049 100644 --- a/util/mac/service_management_test.mm +++ b/util/mac/service_management_test.mm @@ -21,7 +21,7 @@ #include #include "base/apple/bridging.h" -#include "base/mac/scoped_cftyperef.h" +#include "base/apple/scoped_cftyperef.h" #include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" #include "gtest/gtest.h" diff --git a/util/net/http_transport_mac.mm b/util/net/http_transport_mac.mm index ef51beb6..e65a690f 100644 --- a/util/net/http_transport_mac.mm +++ b/util/net/http_transport_mac.mm @@ -18,7 +18,7 @@ #include #include "base/apple/bridging.h" -#include "base/mac/foundation_util.h" +#include "base/apple/foundation_util.h" #include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" #include "build/build_config.h" @@ -153,12 +153,12 @@ - (BOOL)setProperty:(id)property forKey:(NSStreamPropertyKey)key { // Expected to be CFNetwork. NSBundle* nsurl_bundle = [NSBundle bundleForClass:[NSURLRequest class]]; - NSString* bundle_name = base::mac::ObjCCast([nsurl_bundle + NSString* bundle_name = base::apple::ObjCCast([nsurl_bundle objectForInfoDictionaryKey:base::apple::CFToNSPtrCast(kCFBundleNameKey)]); if (bundle_name) { user_agent = AppendEscapedFormat(user_agent, @" %@", bundle_name); - NSString* bundle_version = base::mac::ObjCCast( + NSString* bundle_version = base::apple::ObjCCast( [nsurl_bundle objectForInfoDictionaryKey:base::apple::CFToNSPtrCast( kCFBundleVersionKey)]); if (bundle_version) { @@ -268,7 +268,7 @@ - (BOOL)setProperty:(id)property forKey:(NSStreamPropertyKey)key { return false; } NSHTTPURLResponse* http_response = - base::mac::ObjCCast(response); + base::apple::ObjCCast(response); if (!http_response) { LOG(ERROR) << "no http_response"; return false; From 50ce1550a1ca05d1940b399fb03845f563044082 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Mon, 7 Aug 2023 19:23:58 +0200 Subject: [PATCH 041/107] [fuchsia] Move //zircon/public/lib/zx to //zircon/system/ulib/zx Bug: fuchsia:70426 Change-Id: I346b0d4c1bd411ef106fdc36ca4d846d875fceb9 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4753382 Commit-Queue: Mark Mentovai Reviewed-by: Mark Mentovai --- third_party/fuchsia/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/fuchsia/BUILD.gn b/third_party/fuchsia/BUILD.gn index 7594c1c9..51aa43ba 100644 --- a/third_party/fuchsia/BUILD.gn +++ b/third_party/fuchsia/BUILD.gn @@ -18,7 +18,7 @@ if (crashpad_is_in_fuchsia) { group("fuchsia") { public_deps = [ "//sdk/lib/fdio", - "//zircon/public/lib/zx", + "//zircon/system/ulib/zx", ] } } else if (crashpad_is_in_chromium) { From a736f7d070c872a4cc786c31755fd769fb2e50b3 Mon Sep 17 00:00:00 2001 From: Avi Drissman Date: Mon, 21 Aug 2023 16:03:53 -0400 Subject: [PATCH 042/107] Roll mini_chromium putting /base/apple files into base::apple:: Bug: chromium:1474628 Change-Id: Ief0efef22759b935045bf0216a313c2de8025403 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4799234 Reviewed-by: Mark Mentovai Commit-Queue: Avi Drissman --- DEPS | 2 +- util/mac/launchd.mm | 2 +- util/mac/mac_util.cc | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DEPS b/DEPS index d268bd96..2c67a689 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - 'e35fc73aa87bb27e10306900b15a18b0e9c7ca42', + '0c540fd5462a266277e86fa32a230cad4a859037', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', diff --git a/util/mac/launchd.mm b/util/mac/launchd.mm index c711747b..d295ffc6 100644 --- a/util/mac/launchd.mm +++ b/util/mac/launchd.mm @@ -130,7 +130,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { base::apple::CFCastStrict(property_cf)); data_launch = LaunchDataNewOpaque([data_ns bytes], [data_ns length]); } else { - base::ScopedCFTypeRef type_name_cf( + base::apple::ScopedCFTypeRef type_name_cf( CFCopyTypeIDDescription(type_id_cf)); DLOG(ERROR) << "unable to convert CFTypeID " << type_id_cf << " (" << base::SysCFStringRefToUTF8(type_name_cf) << ")"; diff --git a/util/mac/mac_util.cc b/util/mac/mac_util.cc index f1898620..c74fbf36 100644 --- a/util/mac/mac_util.cc +++ b/util/mac/mac_util.cc @@ -166,7 +166,7 @@ bool StringToVersionNumbers(const std::string& version, std::string IORegistryEntryDataPropertyAsString(io_registry_entry_t entry, CFStringRef key) { - base::ScopedCFTypeRef property( + base::apple::ScopedCFTypeRef property( IORegistryEntryCreateCFProperty(entry, key, kCFAllocatorDefault, 0)); CFDataRef data = base::apple::CFCast(property); if (data && CFDataGetLength(data) > 0) { @@ -235,7 +235,7 @@ bool MacOSVersionComponents(int* major, int* bugfix, std::string* build, std::string* version_string) { - base::ScopedCFTypeRef dictionary( + base::apple::ScopedCFTypeRef dictionary( TryCFCopySystemVersionDictionary()); if (!dictionary) { LOG(ERROR) << "_CFCopySystemVersionDictionary failed"; From 52c427a2e4d461a37f2d591f021438e0402b054d Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 22 Aug 2023 18:09:55 -0400 Subject: [PATCH 043/107] tests: stop using legacy gtest APIs These are being removed from gtest, so stop using them. Bug: chromium:1474588 Change-Id: I0d42da9f14dad5c5dc17d980146cb289d444dbda Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4803329 Reviewed-by: Mark Mentovai Commit-Queue: Mike Frysinger --- test/win/win_child_process.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/win/win_child_process.cc b/test/win/win_child_process.cc index 72b55087..d1a767c4 100644 --- a/test/win/win_child_process.cc +++ b/test/win/win_child_process.cc @@ -191,7 +191,7 @@ std::unique_ptr WinChildProcess::Launch() { TestPaths::Executable().value() + base::UTF8ToWide(base::StringPrintf( " --gtest_filter=%s.%s %s=0x%x|0x%x --gtest_also_run_disabled_tests", - test_info->test_case_name(), + test_info->test_suite_name(), test_info->name(), kIsMultiprocessChild, HandleToInt(write_for_child.get()), From ea0496c82eb085a6b3cef3bd0d9191980f865f41 Mon Sep 17 00:00:00 2001 From: Thomas Gales Date: Tue, 29 Aug 2023 23:18:51 +0000 Subject: [PATCH 044/107] Roll crashpad/third_party/mini_chromium/mini_chromium/ 0c540fd54..10f39a976 (1 commit) https://chromium.googlesource.com/chromium/mini_chromium/+log/0c540fd5462a..10f39a97650a $ git log 0c540fd54..10f39a976 --date=short --no-merges --format='%ad %ae %s' 2023-08-09 tgales [riscv][android] Add Android RISC-V support Created with: roll-dep crashpad/third_party/mini_chromium/mini_chromium Fixed: fuchsia:128936 Change-Id: Iee194c24b1dd4418e0f882c7e8c96e2c85eaa617 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4824417 Reviewed-by: Joshua Peraza Commit-Queue: Thomas Gales --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index 2c67a689..b7d44b11 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - '0c540fd5462a266277e86fa32a230cad4a859037', + '10f39a97650a0fe0b305415c15434443c0690a20', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', From a7cfe95351e301512eb0efc03f92fee63c1c82b2 Mon Sep 17 00:00:00 2001 From: Keishi Hattori Date: Thu, 31 Aug 2023 17:27:07 +0000 Subject: [PATCH 045/107] Reland "Add SetLastChanceExceptionHandler to implement permissive MTE mode" This is a reland of commit b1e66e322ddd07f4640ee8bad93397a0511cd313 Original change's description: > Add SetLastChanceExceptionHandler to implement permissive MTE mode > > SetLastChanceExceptionHandler sets a callback to be called after a > crash has been reported. Returning true from this callback will > not reraise the signal so the execution can continue. This will be > used to implement permissive MTE mode, which will continue execution > after a MTE crash. > > Bug: chromium:1467915 > Change-Id: I93a28ceea921fe977805482cf47c07643ca6133c > Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4707688 > Reviewed-by: Robert Sesek > Commit-Queue: Keishi Hattori Bug: chromium:1467915 Change-Id: Ibdc18084deb08bccf3c74f688b7d48ff24fe81f9 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4756235 Reviewed-by: Robert Sesek Commit-Queue: Keishi Hattori --- client/crashpad_client.h | 18 ++++++++++ client/crashpad_client_linux.cc | 18 ++++++++++ client/crashpad_client_linux_test.cc | 52 ++++++++++++++++++++++++++-- 3 files changed, 85 insertions(+), 3 deletions(-) diff --git a/client/crashpad_client.h b/client/crashpad_client.h index 24424414..f8756044 100644 --- a/client/crashpad_client.h +++ b/client/crashpad_client.h @@ -456,6 +456,24 @@ class CrashpadClient { //! \param[in] handler The custom crash signal handler to install. static void SetFirstChanceExceptionHandler(FirstChanceHandler handler); + //! \brief Installs a custom crash signal handler which runs after the + //! currently installed Crashpad handler. + //! + //! Handling signals appropriately can be tricky and use of this method + //! should be avoided, if possible. + //! + //! A handler must have already been installed before calling this method. + //! + //! The custom handler runs in a signal handler context and must be safe for + //! that purpose. + //! + //! If the custom handler returns `true`, the signal is not reraised. + //! + //! \param[in] handler The custom crash signal handler to install. + static void SetLastChanceExceptionHandler(bool (*handler)(int, + siginfo_t*, + ucontext_t*)); + //! \brief Configures a set of signals that shouldn't have Crashpad signal //! handlers installed. //! diff --git a/client/crashpad_client_linux.cc b/client/crashpad_client_linux.cc index 630c24f1..f805ff1f 100644 --- a/client/crashpad_client_linux.cc +++ b/client/crashpad_client_linux.cc @@ -131,6 +131,8 @@ std::vector BuildArgsToLaunchWithLinker( #endif // BUILDFLAG(IS_ANDROID) +using LastChanceHandler = bool (*)(int, siginfo_t*, ucontext_t*); + // A base class for Crashpad signal handler implementations. class SignalHandler { public: @@ -154,6 +156,10 @@ class SignalHandler { first_chance_handler_ = handler; } + void SetLastChanceExceptionHandler(LastChanceHandler handler) { + last_chance_handler_ = handler; + } + // The base implementation for all signal handlers, suitable for calling // directly to simulate signal delivery. void HandleCrash(int signo, siginfo_t* siginfo, void* context) { @@ -212,6 +218,11 @@ class SignalHandler { if (!handler_->disabled_.test_and_set()) { handler_->HandleCrash(signo, siginfo, context); handler_->WakeThreads(); + if (handler_->last_chance_handler_ && + handler_->last_chance_handler_( + signo, siginfo, static_cast(context))) { + return; + } } else { // Processes on Android normally have several chained signal handlers that // co-operate to report crashes. e.g. WebView will have this signal @@ -254,6 +265,7 @@ class SignalHandler { Signals::OldActions old_actions_ = {}; ExceptionInformation exception_information_ = {}; CrashpadClient::FirstChanceHandler first_chance_handler_ = nullptr; + LastChanceHandler last_chance_handler_ = nullptr; int32_t dump_done_futex_ = kDumpNotDone; #if !defined(__cpp_lib_atomic_value_initialization) || \ __cpp_lib_atomic_value_initialization < 201911L @@ -739,6 +751,12 @@ void CrashpadClient::SetFirstChanceExceptionHandler( SignalHandler::Get()->SetFirstChanceHandler(handler); } +// static +void CrashpadClient::SetLastChanceExceptionHandler(LastChanceHandler handler) { + DCHECK(SignalHandler::Get()); + SignalHandler::Get()->SetLastChanceExceptionHandler(handler); +} + void CrashpadClient::SetUnhandledSignals(const std::set& signals) { DCHECK(!SignalHandler::Get()); unhandled_signals_ = signals; diff --git a/client/crashpad_client_linux_test.cc b/client/crashpad_client_linux_test.cc index 9b207db3..5d492009 100644 --- a/client/crashpad_client_linux_test.cc +++ b/client/crashpad_client_linux_test.cc @@ -71,11 +71,14 @@ enum class CrashType : uint32_t { kBuiltinTrap, kInfiniteRecursion, kSegvWithTagBits, + // kFakeSegv is meant to simulate a MTE segv error. + kFakeSegv, }; struct StartHandlerForSelfTestOptions { bool start_handler_at_crash; bool set_first_chance_handler; + bool set_last_chance_handler; bool crash_non_main_thread; bool client_uses_signals; bool gather_indirectly_referenced_memory; @@ -84,7 +87,7 @@ struct StartHandlerForSelfTestOptions { class StartHandlerForSelfTest : public testing::TestWithParam< - std::tuple> { + std::tuple> { public: StartHandlerForSelfTest() = default; @@ -99,6 +102,7 @@ class StartHandlerForSelfTest memset(&options_, 0, sizeof(options_)); std::tie(options_.start_handler_at_crash, options_.set_first_chance_handler, + options_.set_last_chance_handler, options_.crash_non_main_thread, options_.client_uses_signals, options_.gather_indirectly_referenced_memory, @@ -244,6 +248,10 @@ bool HandleCrashSuccessfully(int, siginfo_t*, ucontext_t*) { #pragma clang diagnostic pop } +bool HandleCrashSuccessfullyAfterReporting(int, siginfo_t*, ucontext_t*) { + return true; +} + void DoCrash(const StartHandlerForSelfTestOptions& options, CrashpadClient* client) { if (sigsetjmp(do_crash_sigjmp_env, 1) != 0) { @@ -273,6 +281,15 @@ void DoCrash(const StartHandlerForSelfTestOptions& options, *x; break; } + + case CrashType::kFakeSegv: { + // With a regular SIGSEGV like null dereference, the signal gets reraised + // automatically, causing HandleOrReraiseSignal() to be called a second + // time, terminating the process with the signal regardless of the last + // chance handler. + raise(SIGSEGV); + break; + } } } @@ -403,6 +420,10 @@ CRASHPAD_CHILD_TEST_MAIN(StartHandlerForSelfTestChild) { client.SetFirstChanceExceptionHandler(HandleCrashSuccessfully); } + if (options.set_last_chance_handler) { + client.SetLastChanceExceptionHandler(HandleCrashSuccessfullyAfterReporting); + } + #if BUILDFLAG(IS_ANDROID) if (android_set_abort_message) { android_set_abort_message(kTestAbortMessage); @@ -440,6 +461,16 @@ class StartHandlerForSelfInChildTest : public MultiprocessExec { case CrashType::kSegvWithTagBits: SetExpectedChildTermination(TerminationReason::kTerminationSignal, SIGSEGV); + break; + case CrashType::kFakeSegv: + if (!options.set_last_chance_handler) { + SetExpectedChildTermination(TerminationReason::kTerminationSignal, + SIGSEGV); + } else { + SetExpectedChildTermination(TerminationReason::kTerminationNormal, + EXIT_SUCCESS); + } + break; } } } @@ -471,7 +502,11 @@ class StartHandlerForSelfInChildTest : public MultiprocessExec { writer.Close(); if (options_.client_uses_signals && !options_.set_first_chance_handler && - options_.crash_type != CrashType::kSimulated) { + options_.crash_type != CrashType::kSimulated && + // The last chance handler will prevent the client handler from being + // called if crash type is kFakeSegv. + (!options_.set_last_chance_handler || + options_.crash_type != CrashType::kFakeSegv)) { // Wait for child's client signal handler. char c; EXPECT_TRUE(LoggingReadFileExactly(ReadPipeHandle(), &c, sizeof(c))); @@ -517,6 +552,15 @@ TEST_P(StartHandlerForSelfTest, StartHandlerInChild) { } #endif // defined(ADDRESS_SANITIZER) + // kFakeSegv does raise(SIGSEGV) to simulate a MTE error which is a SEGSEGV + // that doesn't get reraised automatically, but this causes the child process + // to flakily terminate normally on some bots (e.g. android-nougat-x86-rel) + // for some reason so this is skipped. + if (!Options().set_last_chance_handler && + Options().crash_type == CrashType::kFakeSegv) { + GTEST_SKIP(); + } + if (Options().crash_type == CrashType::kSegvWithTagBits) { #if !defined(ARCH_CPU_ARM64) GTEST_SKIP() << "Testing for tag bits only exists on aarch64."; @@ -549,10 +593,12 @@ INSTANTIATE_TEST_SUITE_P( testing::Bool(), testing::Bool(), testing::Bool(), + testing::Bool(), testing::Values(CrashType::kSimulated, CrashType::kBuiltinTrap, CrashType::kInfiniteRecursion, - CrashType::kSegvWithTagBits))); + CrashType::kSegvWithTagBits, + CrashType::kFakeSegv))); // Test state for starting the handler for another process. class StartHandlerForClientTest { From d25c33222851478b0d59c14b2b0e5eeb443feca6 Mon Sep 17 00:00:00 2001 From: Anne Redulla Date: Tue, 29 Aug 2023 15:25:41 +1000 Subject: [PATCH 046/107] [ssci] Added Shipped field to READMEs This CL adds the Shipped field in READMEs. See the LSC doc at go/lsc-chrome-metadata. Bug: b:285450740 Change-Id: I3dcd5e027f06982f4c2dd98136d3a6d7f6228b4e Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4666416 Reviewed-by: Mark Mentovai Commit-Queue: Mark Mentovai --- third_party/cpp-httplib/README.crashpad | 1 + third_party/edo/README.crashpad | 1 + third_party/getopt/README.crashpad | 1 + third_party/googletest/README.crashpad | 1 + third_party/gyp/README.crashpad | 1 + third_party/lss/README.crashpad | 1 + third_party/mini_chromium/README.crashpad | 1 + third_party/ninja/README.crashpad | 1 + third_party/xnu/README.crashpad | 1 + third_party/zlib/README.crashpad | 1 + 10 files changed, 10 insertions(+) diff --git a/third_party/cpp-httplib/README.crashpad b/third_party/cpp-httplib/README.crashpad index cfb476e0..a1ba93aa 100644 --- a/third_party/cpp-httplib/README.crashpad +++ b/third_party/cpp-httplib/README.crashpad @@ -5,6 +5,7 @@ Revision: 5b3187e2f9e77c672063d49a1167bbb563da023e License: MIT License File: cpp-httplib/LICENSE Security Critical: no (test only) +Shipped: no Description: A C++11 header-only HTTP library. diff --git a/third_party/edo/README.crashpad b/third_party/edo/README.crashpad index fb831582..770026aa 100644 --- a/third_party/edo/README.crashpad +++ b/third_party/edo/README.crashpad @@ -5,6 +5,7 @@ Revision: See DEPS License: Apache 2.0 License File: edo/LICENSE Security Critical: no +Shipped: no Description: iOS remote method invocations (distant object) over Inter-process communication layer. diff --git a/third_party/getopt/README.crashpad b/third_party/getopt/README.crashpad index b7ff9543..ac3201a6 100644 --- a/third_party/getopt/README.crashpad +++ b/third_party/getopt/README.crashpad @@ -4,6 +4,7 @@ URL: https://sourceware.org/ml/newlib/2005/msg00758.html License: Public domain License File: LICENSE Security Critical: no +Shipped: yes Description: A public domain implementation of getopt. diff --git a/third_party/googletest/README.crashpad b/third_party/googletest/README.crashpad index 9a6ca6c6..ecdce887 100644 --- a/third_party/googletest/README.crashpad +++ b/third_party/googletest/README.crashpad @@ -5,6 +5,7 @@ Revision: See DEPS License: BSD 3-clause License File: googletest/googletest/LICENSE Security Critical: no +Shipped: no Description: Google Test (Google C++ Testing Framework) is Google’s framework for writing C++ diff --git a/third_party/gyp/README.crashpad b/third_party/gyp/README.crashpad index 18eb1649..ea5a342b 100644 --- a/third_party/gyp/README.crashpad +++ b/third_party/gyp/README.crashpad @@ -5,6 +5,7 @@ Revision: See DEPS License: BSD 3-clause License File: gyp/LICENSE Security Critical: no +Shipped: no Description: GYP is used to generate build files. diff --git a/third_party/lss/README.crashpad b/third_party/lss/README.crashpad index d1ac9913..9a12c1c8 100644 --- a/third_party/lss/README.crashpad +++ b/third_party/lss/README.crashpad @@ -5,6 +5,7 @@ Revision: See DEPS License: BSD 3-clause License File: lss/linux_syscall_support.h Security Critical: yes +Shipped: yes Description: Every so often, projects need to directly embed Linux system calls instead of diff --git a/third_party/mini_chromium/README.crashpad b/third_party/mini_chromium/README.crashpad index 37d507bf..2ebdfffe 100644 --- a/third_party/mini_chromium/README.crashpad +++ b/third_party/mini_chromium/README.crashpad @@ -5,6 +5,7 @@ Revision: See DEPS License: BSD 3-clause License File: mini_chromium/LICENSE Security Critical: yes +Shipped in Chromium: no Description: mini_chromium is a small collection of useful low-level (“base”) routines from diff --git a/third_party/ninja/README.crashpad b/third_party/ninja/README.crashpad index e79bd45f..8a5f1eeb 100644 --- a/third_party/ninja/README.crashpad +++ b/third_party/ninja/README.crashpad @@ -5,6 +5,7 @@ Revision: See the CIPD version in DEPS License: Apache License 2.0 License File: https://github.com/ninja-build/ninja/blob/master/COPYING Security Critical: no +Shipped: no Description: Ninja is a small build system with a focus on speed, and is used to build diff --git a/third_party/xnu/README.crashpad b/third_party/xnu/README.crashpad index f8471d38..dbcf7408 100644 --- a/third_party/xnu/README.crashpad +++ b/third_party/xnu/README.crashpad @@ -6,6 +6,7 @@ Version: 6153.11.26 (from macOS 10.15.0) License: APSL 2.0 License File: APPLE_LICENSE Security Critical: no +Shipped: yes Description: XNU is the operating system kernel used on macOS and other Apple systems. diff --git a/third_party/zlib/README.crashpad b/third_party/zlib/README.crashpad index 8a9533d3..bf3af780 100644 --- a/third_party/zlib/README.crashpad +++ b/third_party/zlib/README.crashpad @@ -5,6 +5,7 @@ Revision: See zlib/README.chromium License: zlib License File: zlib/LICENSE Security Critical: yes +Shipped: yes Description: “A massively spiffy yet delicately unobtrusive compression library.” From 8da335ffad361191fa467de56a30715223f04014 Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Tue, 19 Sep 2023 16:22:22 -0400 Subject: [PATCH 047/107] =?UTF-8?q?mac:=20Fix=20build=20with=20deployment?= =?UTF-8?q?=20target=20=E2=89=A5=2011?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes the following warning during compilation: > process_reader_mac_test.cc:670:7: warning: address of function > '_dyld_shared_cache_contains_path' will always evaluate to 'true' > [-Wpointer-bool-conversion] while still retaining compatibility with pre-macOS 11 runtimes when built with a suitable deployment target. Bug: 461 Change-Id: I61a360e8e02ceb7209c887819a4916a68384b89d Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4873433 Reviewed-by: Joshua Peraza Commit-Queue: Mark Mentovai --- snapshot/mac/process_reader_mac_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snapshot/mac/process_reader_mac_test.cc b/snapshot/mac/process_reader_mac_test.cc index e2cb0b0a..ae7827bf 100644 --- a/snapshot/mac/process_reader_mac_test.cc +++ b/snapshot/mac/process_reader_mac_test.cc @@ -666,7 +666,7 @@ void VerifyImageExistenceAndTimestamp(const char* path, time_t timestamp) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunguarded-availability" - if (_dyld_shared_cache_contains_path && + if (&_dyld_shared_cache_contains_path && _dyld_shared_cache_contains_path(path)) { #pragma clang diagnostic pop // The timestamp will either match the timestamp of the dyld_shared_cache From ac0c27a92397b847faae89c0ac5d6825f79d7979 Mon Sep 17 00:00:00 2001 From: Alex Gough Date: Thu, 28 Sep 2023 10:09:17 -0700 Subject: [PATCH 048/107] Deregister vectored exception handler on client destruction Some users of crashpad load and unload the dll that hosts crashpad code. crashpad registers a vectored exception handler to help collect heap corruption crashes. If the dll is unloaded this handler might still be called. This CL adds a scoped handler for such registrations and uses it on Windows crashpad client. To allow this to be stored, RegisterHandler() on the client needs to move onto the client object from being a helper function. Bug: crashpad:462 Change-Id: I5d77c056e2a9a61ddcfa9d0186ab4bfd85a19bff Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4898263 Reviewed-by: Ben Hamilton Reviewed-by: Joshua Peraza Commit-Queue: Alex Gough --- client/crashpad_client.h | 6 +++ client/crashpad_client_win.cc | 76 ++++++++++++++++++----------------- util/win/scoped_handle.cc | 4 ++ util/win/scoped_handle.h | 8 ++++ 4 files changed, 57 insertions(+), 37 deletions(-) diff --git a/client/crashpad_client.h b/client/crashpad_client.h index f8756044..3c966686 100644 --- a/client/crashpad_client.h +++ b/client/crashpad_client.h @@ -807,11 +807,17 @@ class CrashpadClient { #endif private: +#if BUILDFLAG(IS_WIN) + //! \brief Registers process handlers for the client. + void RegisterHandlers(); +#endif + #if BUILDFLAG(IS_APPLE) base::apple::ScopedMachSendRight exception_port_; #elif BUILDFLAG(IS_WIN) std::wstring ipc_pipe_; ScopedKernelHANDLE handler_start_thread_; + ScopedVectoredExceptionRegistration vectored_handler_; #elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) std::set unhandled_signals_; #endif // BUILDFLAG(IS_APPLE) diff --git a/client/crashpad_client_win.cc b/client/crashpad_client_win.cc index 37469b20..13e29002 100644 --- a/client/crashpad_client_win.cc +++ b/client/crashpad_client_win.cc @@ -586,45 +586,10 @@ void CommonInProcessInitialization() { g_non_crash_dump_lock = new base::Lock(); } -void RegisterHandlers() { - SetUnhandledExceptionFilter(&UnhandledExceptionHandler); - - // Windows swallows heap corruption failures but we can intercept them with - // a vectored exception handler. -#if defined(ADDRESS_SANITIZER) - // Let ASAN have first go. - bool go_first = false; -#else - bool go_first = true; -#endif - AddVectoredExceptionHandler(go_first, HandleHeapCorruption); - - // The Windows CRT's signal.h lists: - // - SIGINT - // - SIGILL - // - SIGFPE - // - SIGSEGV - // - SIGTERM - // - SIGBREAK - // - SIGABRT - // SIGILL and SIGTERM are documented as not being generated. SIGBREAK and - // SIGINT are for Ctrl-Break and Ctrl-C, and aren't something for which - // capturing a dump is warranted. SIGFPE and SIGSEGV are captured as regular - // exceptions through the unhandled exception filter. This leaves SIGABRT. In - // the standard CRT, abort() is implemented as a synchronous call to the - // SIGABRT signal handler if installed, but after doing so, the unhandled - // exception filter is not triggered (it instead __fastfail()s). So, register - // to handle SIGABRT to catch abort() calls, as client code might use this and - // expect it to cause a crash dump. This will only work when the abort() - // that's called in client code is the same (or has the same behavior) as the - // one in use here. - void (*rv)(int) = signal(SIGABRT, HandleAbortSignal); - DCHECK_NE(rv, SIG_ERR); -} - } // namespace -CrashpadClient::CrashpadClient() : ipc_pipe_(), handler_start_thread_() {} +CrashpadClient::CrashpadClient() + : ipc_pipe_(), handler_start_thread_(), vectored_handler_() {} CrashpadClient::~CrashpadClient() {} @@ -698,6 +663,43 @@ bool CrashpadClient::StartHandler( } } +void CrashpadClient::RegisterHandlers() { + SetUnhandledExceptionFilter(&UnhandledExceptionHandler); + + // Windows swallows heap corruption failures but we can intercept them with + // a vectored exception handler. +#if defined(ADDRESS_SANITIZER) + // Let ASAN have first go. + bool go_first = false; +#else + bool go_first = true; +#endif + PVOID handler = AddVectoredExceptionHandler(go_first, HandleHeapCorruption); + vectored_handler_.reset(handler); + + // The Windows CRT's signal.h lists: + // - SIGINT + // - SIGILL + // - SIGFPE + // - SIGSEGV + // - SIGTERM + // - SIGBREAK + // - SIGABRT + // SIGILL and SIGTERM are documented as not being generated. SIGBREAK and + // SIGINT are for Ctrl-Break and Ctrl-C, and aren't something for which + // capturing a dump is warranted. SIGFPE and SIGSEGV are captured as regular + // exceptions through the unhandled exception filter. This leaves SIGABRT. In + // the standard CRT, abort() is implemented as a synchronous call to the + // SIGABRT signal handler if installed, but after doing so, the unhandled + // exception filter is not triggered (it instead __fastfail()s). So, register + // to handle SIGABRT to catch abort() calls, as client code might use this and + // expect it to cause a crash dump. This will only work when the abort() + // that's called in client code is the same (or has the same behavior) as the + // one in use here. + void (*rv)(int) = signal(SIGABRT, HandleAbortSignal); + DCHECK_NE(rv, SIG_ERR); +} + bool CrashpadClient::SetHandlerIPCPipe(const std::wstring& ipc_pipe) { DCHECK(ipc_pipe_.empty()); DCHECK(!ipc_pipe.empty()); diff --git a/util/win/scoped_handle.cc b/util/win/scoped_handle.cc index e9f7a9a7..b979134a 100644 --- a/util/win/scoped_handle.cc +++ b/util/win/scoped_handle.cc @@ -32,5 +32,9 @@ void ScopedSearchHANDLECloseTraits::Free(HANDLE handle) { PCHECK(FindClose(handle)) << "FindClose"; } +void ScopedVectoredExceptionRegistrationCloseTraits::Free(PVOID handle) { + PCHECK(::RemoveVectoredExceptionHandler(handle)); +} + } // namespace internal } // namespace crashpad diff --git a/util/win/scoped_handle.h b/util/win/scoped_handle.h index 5d629104..62e7e807 100644 --- a/util/win/scoped_handle.h +++ b/util/win/scoped_handle.h @@ -38,6 +38,11 @@ struct ScopedSearchHANDLECloseTraits { static void Free(HANDLE handle); }; +struct ScopedVectoredExceptionRegistrationCloseTraits { + static PVOID InvalidValue() { return nullptr; } + static void Free(PVOID handle); +}; + } // namespace internal using ScopedFileHANDLE = @@ -46,6 +51,9 @@ using ScopedKernelHANDLE = base::ScopedGeneric; using ScopedSearchHANDLE = base::ScopedGeneric; +using ScopedVectoredExceptionRegistration = base::ScopedGeneric< + PVOID, + internal::ScopedVectoredExceptionRegistrationCloseTraits>; } // namespace crashpad From 7f6d9e9c7ffa756c2a03ea97aff910abab1cae71 Mon Sep 17 00:00:00 2001 From: Rupert Ben Wiser Date: Fri, 29 Sep 2023 15:54:13 +0000 Subject: [PATCH 049/107] Add support for matching with key allowlist WebView makes use of this allowlist. We are hoping to include switches and features in our crash keys as users can enable these with an easily available developer UI. These crash keys follow a pattern of "switch-" so it is impractical to indefinitely add a larger list of switch keys. Adding this matcher lets us rather add "switch-*". Bug: 1484644 Change-Id: I667cef70cce1efb0710b4a2f009d8d80a1eeae5a Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4894239 Commit-Queue: Rupert Wiser Reviewed-by: Joshua Peraza --- DEPS | 2 +- snapshot/sanitized/module_snapshot_sanitized.cc | 4 +++- snapshot/sanitized/process_snapshot_sanitized.h | 1 + .../sanitized/process_snapshot_sanitized_test.cc | 12 ++++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/DEPS b/DEPS index b7d44b11..ec7b12ea 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - '10f39a97650a0fe0b305415c15434443c0690a20', + '076bcf6a916171c180f46c3487ee3e5c7bca5f20', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', diff --git a/snapshot/sanitized/module_snapshot_sanitized.cc b/snapshot/sanitized/module_snapshot_sanitized.cc index 192b4cb1..0ad2ee97 100644 --- a/snapshot/sanitized/module_snapshot_sanitized.cc +++ b/snapshot/sanitized/module_snapshot_sanitized.cc @@ -14,6 +14,8 @@ #include "snapshot/sanitized/module_snapshot_sanitized.h" +#include "base/strings/pattern.h" + namespace crashpad { namespace internal { @@ -22,7 +24,7 @@ namespace { bool KeyIsAllowed(const std::string& name, const std::vector& allowed_keys) { for (const auto& key : allowed_keys) { - if (name == key) { + if (base::MatchPattern(name, key)) { return true; } } diff --git a/snapshot/sanitized/process_snapshot_sanitized.h b/snapshot/sanitized/process_snapshot_sanitized.h index c5dfa4a0..af65fb68 100644 --- a/snapshot/sanitized/process_snapshot_sanitized.h +++ b/snapshot/sanitized/process_snapshot_sanitized.h @@ -53,6 +53,7 @@ class ProcessSnapshotSanitized final : public ProcessSnapshot { //! \param[in] allowed_annotations A list of annotations names to allow to //! be returned by AnnotationsSimpleMap() or from this object's module //! snapshots. If `nullptr`, all annotations will be returned. + // These annotation names support pattern matching, eg: "switch-*" //! \param[in] allowed_memory_ranges A list of memory ranges to allow to be //! accessible via Memory(), or `nullptr` to allow all ranges. //! \param[in] target_module_address An address in the target process' diff --git a/snapshot/sanitized/process_snapshot_sanitized_test.cc b/snapshot/sanitized/process_snapshot_sanitized_test.cc index ba1272b5..329c3c76 100644 --- a/snapshot/sanitized/process_snapshot_sanitized_test.cc +++ b/snapshot/sanitized/process_snapshot_sanitized_test.cc @@ -79,6 +79,8 @@ class ExceptionGenerator { }; constexpr char kAllowedAnnotationName[] = "name_of_allowed_anno"; +constexpr char kAllowedAnnotationNamePattern[] = "name_of_another_*"; +constexpr char kAllowedAnnotationNamePatternActual[] = "name_of_another_anno"; constexpr char kAllowedAnnotationValue[] = "some_value"; constexpr char kNonAllowedAnnotationName[] = "non_allowed_anno"; constexpr char kNonAllowedAnnotationValue[] = "private_annotation"; @@ -99,6 +101,10 @@ void ChildTestFunction() { static StringAnnotation<32> allowed_annotation(kAllowedAnnotationName); allowed_annotation.Set(kAllowedAnnotationValue); + static StringAnnotation<32> allowed_matched_annotation( + kAllowedAnnotationNamePatternActual); + allowed_matched_annotation.Set(kAllowedAnnotationValue); + static StringAnnotation<32> non_allowed_annotation(kNonAllowedAnnotationName); non_allowed_annotation.Set(kNonAllowedAnnotationValue); @@ -129,11 +135,15 @@ CRASHPAD_CHILD_TEST_MAIN(ChildToBeSanitized) { void ExpectAnnotations(ProcessSnapshot* snapshot, bool sanitized) { bool found_allowed = false; + bool found_matched_allowed = false; bool found_non_allowed = false; for (auto module : snapshot->Modules()) { for (const auto& anno : module->AnnotationObjects()) { if (anno.name == kAllowedAnnotationName) { found_allowed = true; + } + if (anno.name == kAllowedAnnotationNamePatternActual) { + found_matched_allowed = true; } else if (anno.name == kNonAllowedAnnotationName) { found_non_allowed = true; } @@ -141,6 +151,7 @@ void ExpectAnnotations(ProcessSnapshot* snapshot, bool sanitized) { } EXPECT_TRUE(found_allowed); + EXPECT_TRUE(found_matched_allowed); if (sanitized) { EXPECT_FALSE(found_non_allowed); } else { @@ -279,6 +290,7 @@ class SanitizeTest : public MultiprocessExec { auto allowed_annotations = std::make_unique>(); allowed_annotations->push_back(kAllowedAnnotationName); + allowed_annotations->push_back(kAllowedAnnotationNamePattern); auto allowed_memory_ranges = std::make_unique>>(); From 485cfaf26ee8315aace73552b1fbce7624fb1644 Mon Sep 17 00:00:00 2001 From: Rupert Ben Wiser Date: Fri, 29 Sep 2023 20:11:13 +0000 Subject: [PATCH 050/107] Update chromium_mini dependency We had an issue that was causing breackages with Fuchsia builders. We needed to copy over additional code to mini_chromium. Making sure this relies on the improved version as well. Bug: 1484644 Change-Id: I0250a44cb29c758d7865cc6222d32a69048c9157 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4905890 Reviewed-by: Mark Mentovai Commit-Queue: Mark Mentovai --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index ec7b12ea..29d9df5b 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - '076bcf6a916171c180f46c3487ee3e5c7bca5f20', + 'd47195ee4aac06ca6cd80857ebad9562098c86a0', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', From b90db3e47fb7a0d802f332109ca6f428e78e7511 Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Wed, 4 Oct 2023 14:14:11 -0400 Subject: [PATCH 051/107] ios: Fix Chromium bundle id for xcuitest. This is needed in Chromium for enabling iOS PartitionAlloc Rolls mini_chromium to support overriding the BundleIdentifier. Bug: 1489308 Change-Id: I314958182f35edba3300e545b2877d288b43ccb9 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4911575 Reviewed-by: Mark Mentovai Commit-Queue: Justin Cohen --- DEPS | 2 +- build/ios/Unittest-Info.plist | 2 +- test/ios/host/BUILD.gn | 3 +++ test/ios/host/Info.plist | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/DEPS b/DEPS index 29d9df5b..967754c3 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - 'd47195ee4aac06ca6cd80857ebad9562098c86a0', + '276f2ac531cd8c5c54a32638ea3889069094a8a1', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', diff --git a/build/ios/Unittest-Info.plist b/build/ios/Unittest-Info.plist index fdca91fb..0af7bbc4 100644 --- a/build/ios/Unittest-Info.plist +++ b/build/ios/Unittest-Info.plist @@ -3,7 +3,7 @@ CFBundleIdentifier - ${IOS_BUNDLE_ID_PREFIX}.googletest.${GTEST_BUNDLE_ID_SUFFIX:rfc1034identifier} + ${IOS_BUNDLE_ID_PREFIX}.${GTEST_BUNDLE_ID_SUFFIX:rfc1034identifier} UIApplicationDelegate CrashpadUnitTestDelegate diff --git a/test/ios/host/BUILD.gn b/test/ios/host/BUILD.gn index 7d2e9849..9a8b8b5b 100644 --- a/test/ios/host/BUILD.gn +++ b/test/ios/host/BUILD.gn @@ -67,6 +67,9 @@ bundle_data("crashy_module_bundle") { ios_app_bundle("ios_crash_xcuitests") { info_plist = "Info.plist" testonly = true + if (crashpad_is_in_chromium && ios_use_shared_bundle_id_for_test_apps) { + bundle_identifier = shared_bundle_id_for_test_apps + } deps = [ ":app_host_sources", ":crashy_module_bundle", diff --git a/test/ios/host/Info.plist b/test/ios/host/Info.plist index 4c62e969..16716116 100644 --- a/test/ios/host/Info.plist +++ b/test/ios/host/Info.plist @@ -9,7 +9,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - ${IOS_BUNDLE_ID_PREFIX}.googletest.${EXECUTABLE_NAME:rfc1034identifier} + ${BUNDLE_IDENTIFIER} CFBundleInfoDictionaryVersion 6.0 CFBundleName From a1b467ab45df0be7ed7b60443ceee7bf9081d818 Mon Sep 17 00:00:00 2001 From: Thomas Gales Date: Fri, 6 Oct 2023 20:46:54 +0000 Subject: [PATCH 052/107] Pull latest toolchain The previous CIPD location was stale and the packages there are no longer updated. Compiling for Fuchsia using the latest toolchain revealed that zlib needed to be updated as well to resolve errors thrown by -Wstrict-prototypes. Newer versions of zlib fail to compile for Fuchsia without the addition of -Wno-sign-compare, recommended for this situation by the Fuchsia toolchain team. Bug: fuchsia:128938 Bug: fuchsia:128939 Change-Id: Iccf6dcb1aef1e1811f458fd18a2f04e7b044a918 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4893089 Commit-Queue: Thomas Gales Reviewed-by: Mark Mentovai --- DEPS | 14 +++++++------- third_party/zlib/BUILD.gn | 16 ++++++++++------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/DEPS b/DEPS index 967754c3..6bae243f 100644 --- a/DEPS +++ b/DEPS @@ -53,7 +53,7 @@ deps = { 'fda403cf93ecb8792cb1d061564d89a6553ca020', 'crashpad/third_party/zlib/zlib': Var('chromium_git') + '/chromium/src/third_party/zlib@' + - '13dc246a58e4b72104d35f9b1809af95221ebda7', + 'fef58692c1d7bec94c4ed3d030a45a1832a9615d', # CIPD packages. 'buildtools/linux64': { @@ -89,8 +89,8 @@ deps = { 'crashpad/third_party/linux/clang/linux-amd64': { 'packages': [ { - 'package': 'fuchsia/clang/linux-amd64', - 'version': 'goma', + 'package': 'fuchsia/third_party/clang/linux-amd64', + 'version': 'Tpc85d1ZwSlZ6UKl2d96GRUBGNA5JKholOKe24sRDr0C', }, ], 'condition': 'checkout_linux and pull_linux_clang', @@ -99,8 +99,8 @@ deps = { 'crashpad/third_party/fuchsia/clang/mac-amd64': { 'packages': [ { - 'package': 'fuchsia/clang/mac-amd64', - 'version': 'goma', + 'package': 'fuchsia/third_party/clang/mac-amd64', + 'version': 'MAOjNhwTu5JU3P_0C9dITiyCTtQ1n7lRJnMfB9hhvOkC', }, ], 'condition': 'checkout_fuchsia and host_os == "mac"', @@ -109,8 +109,8 @@ deps = { 'crashpad/third_party/fuchsia/clang/linux-amd64': { 'packages': [ { - 'package': 'fuchsia/clang/linux-amd64', - 'version': 'goma', + 'package': 'fuchsia/third_party/clang/linux-amd64', + 'version': 'Tpc85d1ZwSlZ6UKl2d96GRUBGNA5JKholOKe24sRDr0C', }, ], 'condition': 'checkout_fuchsia and host_os == "linux"', diff --git a/third_party/zlib/BUILD.gn b/third_party/zlib/BUILD.gn index 986a057b..92069a57 100644 --- a/third_party/zlib/BUILD.gn +++ b/third_party/zlib/BUILD.gn @@ -38,6 +38,10 @@ config("zlib_config") { } } +config("Wno-sign-compare") { + cflags = [ "-Wno-sign-compare" ] +} + if (zlib_source == "external") { group("zlib") { public_configs = [ ":zlib_config" ] @@ -112,6 +116,11 @@ if (zlib_source == "external") { ] } + if (crashpad_is_fuchsia) { + # Fuchsia build's default warnings include -Wsign-compare (indirectly) + configs += [ ":Wno-sign-compare" ] + } + if (crashpad_is_standalone) { configs -= [ "//third_party/mini_chromium/mini_chromium/build/config:Wimplicit_fallthrough" ] } else if (crashpad_is_external) { @@ -119,14 +128,11 @@ if (zlib_source == "external") { } if (zlib_source == "embedded") { - sources += [ "$zlib_dir/names.h" ] + sources += [ "$zlib_dir/chromeconf.h" ] if (current_cpu == "x86" || current_cpu == "x64") { sources += [ "$zlib_dir/crc_folding.c", - "$zlib_dir/fill_window_sse.c", - "$zlib_dir/x86.c", - "$zlib_dir/x86.h", ] if (!crashpad_is_win || crashpad_is_clang) { cflags += [ @@ -137,8 +143,6 @@ if (zlib_source == "external") { if (crashpad_is_clang) { cflags += [ "-Wno-incompatible-pointer-types" ] } - } else { - sources += [ "$zlib_dir/simd_stub.c" ] } } } From 0fc1b6ae780e7ba854652bd5581f936abf824a5e Mon Sep 17 00:00:00 2001 From: Leonard Grey Date: Fri, 6 Oct 2023 15:22:47 -0400 Subject: [PATCH 053/107] Mac: update ProcessReaderMac and tests for macOS 14 dyld in macOS 14 has two changes that impact how we read in modules: - Timestamp is always empty - The executable appears *last* rather than first in the dyld_all_image_infos array (see comment for details) This change: - Removes all timestamp checks in the tests - Removes 10.6 era code that worked around a different "executable in the wrong place" issue. Replaces this with a new branch that checks if the executable is in the last position, and rotates it to the front if so. This is necessary instead of just swapping (as in the 10.6 code) so that it can match the order returned by the `dyld_get_image...` family. Bug: chromium:1452203 Change-Id: Iac9b29a0d9b9461b0ef386c9541661171ef9fd11 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4917145 Commit-Queue: Leonard Grey Reviewed-by: Mark Mentovai --- snapshot/mac/mach_o_image_segment_reader.cc | 31 ++++---------- snapshot/mac/mach_o_image_segment_reader.h | 9 +--- snapshot/mac/process_reader_mac.cc | 33 ++++++++------- snapshot/mac/process_reader_mac_test.cc | 46 +++------------------ 4 files changed, 33 insertions(+), 86 deletions(-) diff --git a/snapshot/mac/mach_o_image_segment_reader.cc b/snapshot/mac/mach_o_image_segment_reader.cc index 6e328f9a..efa7cc68 100644 --- a/snapshot/mac/mach_o_image_segment_reader.cc +++ b/snapshot/mac/mach_o_image_segment_reader.cc @@ -39,35 +39,23 @@ std::string SizeLimitedCString(const char* c_string, size_t max_length) { } // namespace bool IsMalformedCLKernelsModule(uint32_t mach_o_file_type, - const std::string& module_name, - bool* has_timestamp) { + const std::string& module_name) { #if defined(ARCH_CPU_X86_FAMILY) if (mach_o_file_type != MH_BUNDLE) { return false; } if (module_name == "cl_kernels") { - if (__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10 || - MacOSVersionNumber() >= 10'10'00) { - if (has_timestamp) { - *has_timestamp = false; - } - return true; - } - return false; + return __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10 || + MacOSVersionNumber() >= 10'10'00; } static const char kCvmsObjectPathPrefix[] = "/private/var/db/CVMS/cvmsCodeSignObj"; - if (module_name.compare( - 0, strlen(kCvmsObjectPathPrefix), kCvmsObjectPathPrefix) == 0 && - (__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_14 || - MacOSVersionNumber() >= 10'14'00)) { - if (has_timestamp) { - *has_timestamp = true; - } - return true; - } + return module_name.compare( + 0, strlen(kCvmsObjectPathPrefix), kCvmsObjectPathPrefix) == 0 && + (__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_14 || + MacOSVersionNumber() >= 10'14'00); #endif // ARCH_CPU_X86_FAMILY return false; @@ -165,9 +153,8 @@ bool MachOImageSegmentReader::Initialize(ProcessReaderMac* process_reader, // // https://openradar.appspot.com/20239912 if (section_segment_name != segment_name && - !(IsMalformedCLKernelsModule(file_type, module_name, nullptr) && - segment_name == SEG_TEXT && - section_segment_name == "__LD" && + !(IsMalformedCLKernelsModule(file_type, module_name) && + segment_name == SEG_TEXT && section_segment_name == "__LD" && section_name == "__compact_unwind" && (section.flags & S_ATTR_DEBUG))) { LOG(WARNING) << "section.segname incorrect in segment " << segment_name diff --git a/snapshot/mac/mach_o_image_segment_reader.h b/snapshot/mac/mach_o_image_segment_reader.h index a5665292..a4f17274 100644 --- a/snapshot/mac/mach_o_image_segment_reader.h +++ b/snapshot/mac/mach_o_image_segment_reader.h @@ -53,18 +53,11 @@ namespace crashpad { //! \param[in] mach_o_file_type The Mach-O type of the module being examined. //! \param[in] module_name The pathname that `dyld` reported having loaded the //! module from. -//! \param[out] has_timestamp Optional, may be `nullptr`. If provided, and the -//! module is a maformed `cl_kernels` module, this will be set to `true` if -//! the module was loaded from the filesystem (as is the case when loaded -//! from the CVMS directory) and is expected to have a timestamp, and -//! `false` otherwise. Note that even when loaded from the filesystem, these -//! modules are unlinked from the filesystem after loading. //! //! \return `true` if the module appears to be a malformed `cl_kernels` module //! based on the provided information, `false` otherwise. bool IsMalformedCLKernelsModule(uint32_t mach_o_file_type, - const std::string& module_name, - bool* has_timestamp); + const std::string& module_name); //! \brief A reader for `LC_SEGMENT` or `LC_SEGMENT_64` load commands in Mach-O //! images mapped into another process. diff --git a/snapshot/mac/process_reader_mac.cc b/snapshot/mac/process_reader_mac.cc index ebc3c970..53dae075 100644 --- a/snapshot/mac/process_reader_mac.cc +++ b/snapshot/mac/process_reader_mac.cc @@ -509,26 +509,27 @@ void ProcessReaderMac::InitializeModules() { } if (file_type == MH_EXECUTE) { - // On Mac OS X 10.6, the main executable does not normally show up at - // index 0. This is because of how 10.6.8 dyld-132.13/src/dyld.cpp - // notifyGDB(), the function resposible for causing - // dyld_all_image_infos::infoArray to be updated, is called. It is - // registered to be called when all dependents of an image have been - // mapped (dyld_image_state_dependents_mapped), meaning that the main - // executable won’t be added to the list until all of the libraries it - // depends on are, even though dyld begins looking at the main executable - // first. This changed in later versions of dyld, including those present - // in 10.7. 10.9.4 dyld-239.4/src/dyld.cpp updateAllImages() (renamed from - // notifyGDB()) is registered to be called when an image itself has been - // mapped (dyld_image_state_mapped), regardless of the libraries that it - // depends on. + // On macOS 14, the main executable does not normally show up at + // index 0. In previous versions of dyld, each loaded image was + // appended to the all image info vector as it was loaded. + // (For example, see RuntimeState::notifyDebuggerLoad in dyld-1066.8). + // Starting from dyld-1122.1, notifyDebuggerLoad calls + // ExternallyViewableState::addImages for all but the main executable + // (which has already been added). ExternallyViewableState::addImages + // inserts all new image infos at the front of the vector, leaving the + // main executable as the last item. // // The interface requires that the main executable be first in the list, // so swap it into the right position. size_t index = modules_.size() - 1; - if (main_executable_count == 0) { - std::swap(modules_[0], modules_[index]); - } else { + if (index > 0) { + CHECK_EQ(index, image_info_vector.size() - 1); + if (main_executable_count == 0) { + std::rotate( + modules_.rbegin(), modules_.rbegin() + 1, modules_.rend()); + } + } + if (main_executable_count > 0) { LOG(WARNING) << base::StringPrintf( "multiple MH_EXECUTE modules (%s, %s)", modules_[0].name.c_str(), diff --git a/snapshot/mac/process_reader_mac_test.cc b/snapshot/mac/process_reader_mac_test.cc index ae7827bf..a6e009e9 100644 --- a/snapshot/mac/process_reader_mac_test.cc +++ b/snapshot/mac/process_reader_mac_test.cc @@ -654,9 +654,8 @@ T GetDyldFunction(const char* symbol) { return reinterpret_cast(dlsym(dl_handle, symbol)); } -void VerifyImageExistenceAndTimestamp(const char* path, time_t timestamp) { +void VerifyImageExistence(const char* path) { const char* stat_path; - bool timestamp_may_be_0; #if __MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_16 static auto _dyld_shared_cache_contains_path = @@ -686,18 +685,13 @@ void VerifyImageExistenceAndTimestamp(const char* path, time_t timestamp) { }(); stat_path = dyld_shared_cache_file_path; - timestamp_may_be_0 = true; } else { stat_path = path; - timestamp_may_be_0 = false; } struct stat stat_buf; int rv = stat(stat_path, &stat_buf); EXPECT_EQ(rv, 0) << ErrnoMessage("stat"); - if (rv == 0 && (!timestamp_may_be_0 || timestamp != 0)) { - EXPECT_EQ(timestamp, stat_buf.st_mtime); - } } // cl_kernels images (OpenCL kernels) are weird. They’re not ld output and don’t @@ -862,25 +856,16 @@ TEST(ProcessReaderMac, SelfModules) { modules[index].reader->Address(), FromPointerCast(_dyld_get_image_header(index))); - bool expect_timestamp; if (index == 0 && MacOSVersionNumber() < 12'00'00) { // Pre-dyld4, dyld didn’t set the main executable's timestamp, and it was // reported as 0. EXPECT_EQ(modules[index].timestamp, 0); } else if (IsMalformedCLKernelsModule(modules[index].reader->FileType(), - modules[index].name, - &expect_timestamp)) { - // cl_kernels doesn’t exist as a file, but may still have a timestamp. - if (!expect_timestamp) { - EXPECT_EQ(modules[index].timestamp, 0); - } else { - EXPECT_NE(modules[index].timestamp, 0); - } + modules[index].name)) { found_cl_kernels = true; } else { // Hope that the module didn’t change on disk. - VerifyImageExistenceAndTimestamp(dyld_image_name, - modules[index].timestamp); + VerifyImageExistence(dyld_image_name); } } @@ -889,10 +874,6 @@ TEST(ProcessReaderMac, SelfModules) { size_t index = modules.size() - 1; EXPECT_EQ(modules[index].name, kDyldPath); - // dyld didn’t load itself either, so it couldn’t record its timestamp, and it - // is also reported as 0. - EXPECT_EQ(modules[index].timestamp, 0); - const dyld_all_image_infos* dyld_image_infos = DyldGetAllImageInfos(); if (dyld_image_infos->version >= 2) { ASSERT_TRUE(modules[index].reader); @@ -954,27 +935,12 @@ class ProcessReaderModulesChild final : public MachMultiprocess { ASSERT_TRUE(modules[index].reader); EXPECT_EQ(modules[index].reader->Address(), expect_address); - bool expect_timestamp; - if ((index == 0 && MacOSVersionNumber() < 12'00'00) || - index == modules.size() - 1) { - // Pre-dyld4, dyld didn’t set the main executable's timestamp, and it - // was reported as 0. - // The last module is dyld. - EXPECT_EQ(modules[index].timestamp, 0); - } else if (IsMalformedCLKernelsModule(modules[index].reader->FileType(), - modules[index].name, - &expect_timestamp)) { - // cl_kernels doesn’t exist as a file, but may still have a timestamp. - if (!expect_timestamp) { - EXPECT_EQ(modules[index].timestamp, 0); - } else { - EXPECT_NE(modules[index].timestamp, 0); - } + if (IsMalformedCLKernelsModule(modules[index].reader->FileType(), + modules[index].name)) { found_cl_kernels = true; } else { // Hope that the module didn’t change on disk. - VerifyImageExistenceAndTimestamp(expect_name.c_str(), - modules[index].timestamp); + VerifyImageExistence(expect_name.c_str()); } } From f145b54e8378c8e2bd1fbb427684ca9b4c54ea9c Mon Sep 17 00:00:00 2001 From: Rich Mckeever Date: Thu, 12 Oct 2023 15:53:23 -0400 Subject: [PATCH 054/107] Stop registering Windows VEH in ASAN builds. ASAN injects a bad de-reference in HandleHeapCorruption() that causes it to be recursively invoked. Bug: crashpad:464 Change-Id: I5e8db5555462166b963e0e43c6eb8ac0b327219e Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4935953 Reviewed-by: Alex Gough Commit-Queue: Rich Mckeever --- client/crashpad_client_win.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/client/crashpad_client_win.cc b/client/crashpad_client_win.cc index 13e29002..aafb59f4 100644 --- a/client/crashpad_client_win.cc +++ b/client/crashpad_client_win.cc @@ -667,15 +667,14 @@ void CrashpadClient::RegisterHandlers() { SetUnhandledExceptionFilter(&UnhandledExceptionHandler); // Windows swallows heap corruption failures but we can intercept them with - // a vectored exception handler. -#if defined(ADDRESS_SANITIZER) - // Let ASAN have first go. - bool go_first = false; -#else - bool go_first = true; -#endif - PVOID handler = AddVectoredExceptionHandler(go_first, HandleHeapCorruption); + // a vectored exception handler. Note that a vectored exception handler is + // not compatible with or generally helpful in ASAN builds (ASAN inserts a + // bad dereference at the beginning of the handler, leading to recursive + // invocation of the handler). +#if !defined(ADDRESS_SANITIZER) + PVOID handler = AddVectoredExceptionHandler(true, HandleHeapCorruption); vectored_handler_.reset(handler); +#endif // The Windows CRT's signal.h lists: // - SIGINT From 2f6cffa676795d3ac66e50d5fde4a286edfc9377 Mon Sep 17 00:00:00 2001 From: Leonard Grey Date: Fri, 13 Oct 2023 12:42:13 -0400 Subject: [PATCH 055/107] Mac: don't consider module order in process reader tests This is a follow-up to 0fc1b6ae780e7ba854652bd5581f936abf824a5e. The change in macOS 14's dyld to insert new modules in the front of `dyld_all_image_infos` means that if any images are loaded after the executable and its direct dependencies, it's no longer possible to rotate the list to match the order used by the `dyld_get_image...` APIs. This forces us to dispense with checking the order at all except to ensure that the executable is first, and dyld itself is last. Additionally fixes an unreachable return introduced in 0fc1b6ae780e7ba854652bd5581f936abf824a5e. Bug: chromium:1452203 Change-Id: If0b09b9110d8f60d29cca79ea6a59050b0293c5e Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4935952 Commit-Queue: Leonard Grey Reviewed-by: Mark Mentovai --- snapshot/mac/mach_o_image_segment_reader.cc | 4 +- snapshot/mac/process_reader_mac_test.cc | 146 ++++++++++++-------- 2 files changed, 87 insertions(+), 63 deletions(-) diff --git a/snapshot/mac/mach_o_image_segment_reader.cc b/snapshot/mac/mach_o_image_segment_reader.cc index efa7cc68..75f229ef 100644 --- a/snapshot/mac/mach_o_image_segment_reader.cc +++ b/snapshot/mac/mach_o_image_segment_reader.cc @@ -56,9 +56,9 @@ bool IsMalformedCLKernelsModule(uint32_t mach_o_file_type, 0, strlen(kCvmsObjectPathPrefix), kCvmsObjectPathPrefix) == 0 && (__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_14 || MacOSVersionNumber() >= 10'14'00); -#endif // ARCH_CPU_X86_FAMILY - +#else return false; +#endif // ARCH_CPU_X86_FAMILY } MachOImageSegmentReader::MachOImageSegmentReader() diff --git a/snapshot/mac/process_reader_mac_test.cc b/snapshot/mac/process_reader_mac_test.cc index a6e009e9..ed699237 100644 --- a/snapshot/mac/process_reader_mac_test.cc +++ b/snapshot/mac/process_reader_mac_test.cc @@ -28,6 +28,7 @@ #include #include +#include #include #include "base/apple/mach_logging.h" @@ -54,6 +55,15 @@ namespace crashpad { namespace test { namespace { +using ModulePathAndAddress = std::pair; +struct PathAndAddressHash { + std::size_t operator()(const ModulePathAndAddress& pair) const { + return std::hash()(pair.first) ^ + std::hash()(pair.second); + } +}; +using ModuleSet = std::unordered_set; + constexpr char kDyldPath[] = "/usr/lib/dyld"; TEST(ProcessReaderMac, SelfBasic) { @@ -833,54 +843,57 @@ TEST(ProcessReaderMac, SelfModules) { ASSERT_TRUE(process_reader.Initialize(mach_task_self())); uint32_t dyld_image_count = _dyld_image_count(); - const std::vector& modules = - process_reader.Modules(); - // There needs to be at least an entry for the main executable, for a dylib, - // and for dyld. - ASSERT_GE(modules.size(), 3u); + std::set cl_kernel_names; + auto modules = process_reader.Modules(); + ModuleSet actual_modules; + for (size_t i = 0; i < modules.size(); ++i) { + auto& module = modules[i]; + ASSERT_TRUE(module.reader); + if (i == modules.size() - 1) { + EXPECT_EQ(module.name, kDyldPath); + const dyld_all_image_infos* dyld_image_infos = DyldGetAllImageInfos(); + if (dyld_image_infos->version >= 2) { + EXPECT_EQ(module.reader->Address(), + FromPointerCast( + dyld_image_infos->dyldImageLoadAddress)); + } + // Don't include dyld, since dyld image APIs will not have an entry for + // dyld itself. + continue; + } + // Ensure executable is first, and that there's only one. + uint32_t file_type = module.reader->FileType(); + if (i == 0) { + EXPECT_EQ(file_type, static_cast(MH_EXECUTE)); + } else { + EXPECT_NE(file_type, static_cast(MH_EXECUTE)); + } + if (IsMalformedCLKernelsModule(module.reader->FileType(), module.name)) { + cl_kernel_names.insert(module.name); + } + actual_modules.insert( + std::make_pair(module.name, module.reader->Address())); + } + EXPECT_EQ(cl_kernel_names.size() > 0, + ExpectCLKernels() && ensure_cl_kernels.success()); - // dyld_image_count doesn’t include an entry for dyld itself, but |modules| - // does. - ASSERT_EQ(modules.size(), dyld_image_count + 1); + // There needs to be at least an entry for the main executable and a dylib. + ASSERT_GE(actual_modules.size(), 2u); + ASSERT_EQ(actual_modules.size(), dyld_image_count); - bool found_cl_kernels = false; + ModuleSet expect_modules; for (uint32_t index = 0; index < dyld_image_count; ++index) { - SCOPED_TRACE(base::StringPrintf( - "index %u, name %s", index, modules[index].name.c_str())); - const char* dyld_image_name = _dyld_get_image_name(index); - EXPECT_EQ(modules[index].name, dyld_image_name); - ASSERT_TRUE(modules[index].reader); - EXPECT_EQ( - modules[index].reader->Address(), - FromPointerCast(_dyld_get_image_header(index))); - - if (index == 0 && MacOSVersionNumber() < 12'00'00) { - // Pre-dyld4, dyld didn’t set the main executable's timestamp, and it was - // reported as 0. - EXPECT_EQ(modules[index].timestamp, 0); - } else if (IsMalformedCLKernelsModule(modules[index].reader->FileType(), - modules[index].name)) { - found_cl_kernels = true; - } else { - // Hope that the module didn’t change on disk. + mach_vm_address_t dyld_image_address = + FromPointerCast(_dyld_get_image_header(index)); + expect_modules.insert( + std::make_pair(std::string(dyld_image_name), dyld_image_address)); + if (cl_kernel_names.find(dyld_image_name) == cl_kernel_names.end()) { VerifyImageExistence(dyld_image_name); } } - - EXPECT_EQ(found_cl_kernels, ExpectCLKernels() && ensure_cl_kernels.success()); - - size_t index = modules.size() - 1; - EXPECT_EQ(modules[index].name, kDyldPath); - - const dyld_all_image_infos* dyld_image_infos = DyldGetAllImageInfos(); - if (dyld_image_infos->version >= 2) { - ASSERT_TRUE(modules[index].reader); - EXPECT_EQ(modules[index].reader->Address(), - FromPointerCast( - dyld_image_infos->dyldImageLoadAddress)); - } + EXPECT_EQ(actual_modules, expect_modules); } class ProcessReaderModulesChild final : public MachMultiprocess { @@ -899,27 +912,45 @@ class ProcessReaderModulesChild final : public MachMultiprocess { void MachMultiprocessParent() override { ProcessReaderMac process_reader; ASSERT_TRUE(process_reader.Initialize(ChildTask())); - const std::vector& modules = process_reader.Modules(); + ModuleSet actual_modules; + std::set cl_kernel_names; + for (size_t i = 0; i < modules.size(); ++i) { + auto& module = modules[i]; + ASSERT_TRUE(module.reader); + uint32_t file_type = module.reader->FileType(); + if (i == 0) { + EXPECT_EQ(file_type, static_cast(MH_EXECUTE)); + } else if (i == modules.size() - 1) { + EXPECT_EQ(file_type, static_cast(MH_DYLINKER)); + + } else { + EXPECT_NE(file_type, static_cast(MH_EXECUTE)); + EXPECT_NE(file_type, static_cast(MH_DYLINKER)); + } + if (IsMalformedCLKernelsModule(module.reader->FileType(), module.name)) { + cl_kernel_names.insert(module.name); + } + actual_modules.insert( + std::make_pair(module.name, module.reader->Address())); + } + // There needs to be at least an entry for the main executable, for a dylib, // and for dyld. - ASSERT_GE(modules.size(), 3u); + ASSERT_GE(actual_modules.size(), 3u); FileHandle read_handle = ReadPipeHandle(); - uint32_t expect_modules; + uint32_t expect_modules_size; CheckedReadFileExactly( - read_handle, &expect_modules, sizeof(expect_modules)); - - ASSERT_EQ(modules.size(), expect_modules); + read_handle, &expect_modules_size, sizeof(expect_modules_size)); - bool found_cl_kernels = false; - for (size_t index = 0; index < modules.size(); ++index) { - SCOPED_TRACE(base::StringPrintf( - "index %zu, name %s", index, modules[index].name.c_str())); + ASSERT_EQ(actual_modules.size(), expect_modules_size); + ModuleSet expect_modules; + for (size_t index = 0; index < expect_modules_size; ++index) { uint32_t expect_name_length; CheckedReadFileExactly( read_handle, &expect_name_length, sizeof(expect_name_length)); @@ -927,25 +958,18 @@ class ProcessReaderModulesChild final : public MachMultiprocess { // The NUL terminator is not read. std::string expect_name(expect_name_length, '\0'); CheckedReadFileExactly(read_handle, &expect_name[0], expect_name_length); - EXPECT_EQ(modules[index].name, expect_name); mach_vm_address_t expect_address; CheckedReadFileExactly( read_handle, &expect_address, sizeof(expect_address)); - ASSERT_TRUE(modules[index].reader); - EXPECT_EQ(modules[index].reader->Address(), expect_address); - - if (IsMalformedCLKernelsModule(modules[index].reader->FileType(), - modules[index].name)) { - found_cl_kernels = true; - } else { - // Hope that the module didn’t change on disk. + expect_modules.insert(std::make_pair(expect_name, expect_address)); + if (cl_kernel_names.find(expect_name) == cl_kernel_names.end()) { VerifyImageExistence(expect_name.c_str()); } } - - EXPECT_EQ(found_cl_kernels, + EXPECT_EQ(cl_kernel_names.size() > 0, ExpectCLKernels() && ensure_cl_kernels_success_); + EXPECT_EQ(expect_modules, actual_modules); } void MachMultiprocessChild() override { From 63ec9482cf357c4312e3c1bd803b915bb7355dc1 Mon Sep 17 00:00:00 2001 From: Leonard Grey Date: Fri, 13 Oct 2023 16:38:27 -0400 Subject: [PATCH 056/107] Windows: don't compile HandleHeapCorruption on ASAN f145b54e8378c8e2bd1fbb427684ca9b4c54ea9c put the only reference to this in a non-ASAN block, so we're hitting an unused function warning rolling into Chromium Bug: crashpad:464 Change-Id: I225debd48a255aa5214e02a6821dcd72c618f141 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4939552 Reviewed-by: Mark Mentovai Commit-Queue: Leonard Grey --- client/crashpad_client_win.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/crashpad_client_win.cc b/client/crashpad_client_win.cc index aafb59f4..8ba75482 100644 --- a/client/crashpad_client_win.cc +++ b/client/crashpad_client_win.cc @@ -187,6 +187,7 @@ LONG WINAPI UnhandledExceptionHandler(EXCEPTION_POINTERS* exception_pointers) { return EXCEPTION_CONTINUE_SEARCH; } +#if !defined(ADDRESS_SANITIZER) LONG WINAPI HandleHeapCorruption(EXCEPTION_POINTERS* exception_pointers) { if (exception_pointers->ExceptionRecord->ExceptionCode == STATUS_HEAP_CORRUPTION) { @@ -195,6 +196,7 @@ LONG WINAPI HandleHeapCorruption(EXCEPTION_POINTERS* exception_pointers) { return EXCEPTION_CONTINUE_SEARCH; } +#endif void HandleAbortSignal(int signum) { DCHECK_EQ(signum, SIGABRT); From 7c89d500cd7774ec768141705b04dc085564441d Mon Sep 17 00:00:00 2001 From: Sylvain Defresne Date: Mon, 16 Oct 2023 16:59:44 +0200 Subject: [PATCH 057/107] [ios] Remove ios_use_shared_bundle_id_for_test_apps gn variable The variable was to true in https://crrev.com/c/3308823 and is never overridden. Remove it as it simplify the logic of the test targets (and remove code duplication). This is a followup to https://crrev.com/c/4935576 which make the corresponding change in the Chromium repository. Bug: 1250788 Change-Id: Ide05fa3bf4177b5761ef0ad5c6edf9baf181b28c Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4943570 Commit-Queue: Sylvain Defresne Reviewed-by: Robert Sesek --- test/ios/host/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ios/host/BUILD.gn b/test/ios/host/BUILD.gn index 9a8b8b5b..7a735f34 100644 --- a/test/ios/host/BUILD.gn +++ b/test/ios/host/BUILD.gn @@ -65,9 +65,9 @@ bundle_data("crashy_module_bundle") { } ios_app_bundle("ios_crash_xcuitests") { - info_plist = "Info.plist" testonly = true - if (crashpad_is_in_chromium && ios_use_shared_bundle_id_for_test_apps) { + info_plist = "Info.plist" + if (crashpad_is_in_chromium) { bundle_identifier = shared_bundle_id_for_test_apps } deps = [ From aef75040fd02010e40ecce1b86d636489a889b2c Mon Sep 17 00:00:00 2001 From: Peter Kasting Date: Mon, 16 Oct 2023 12:56:05 -0700 Subject: [PATCH 058/107] Use format macros for int64_t instead of hardcoding the format. Bug: 1371963 Change-Id: I7fa4557472684cdd2b8e0cc977230941f26f1eaa Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4943901 Reviewed-by: Mark Mentovai Commit-Queue: Peter Kasting --- util/win/initial_client_data.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/win/initial_client_data.cc b/util/win/initial_client_data.cc index c119ad95..d74d66c2 100644 --- a/util/win/initial_client_data.cc +++ b/util/win/initial_client_data.cc @@ -16,6 +16,7 @@ #include +#include "base/format_macros.h" #include "base/logging.h" #include "base/strings/stringprintf.h" #include "util/stdlib/string_number_conversion.h" @@ -99,7 +100,8 @@ bool InitialClientData::InitializeFromString(const std::string& str) { } std::string InitialClientData::StringRepresentation() const { - return base::StringPrintf("0x%x,0x%x,0x%x,0x%x,0x%x,0x%I64x,0x%I64x,0x%I64x", + return base::StringPrintf("0x%x,0x%x,0x%x,0x%x,0x%x,0x%" PRIx64 ",0x%" PRIx64 + ",0x%" PRIx64, HandleToInt(request_crash_dump_), HandleToInt(request_non_crash_dump_), HandleToInt(non_crash_dump_completed_), From ce4e3d6ee0bd0407d755584fdcd33135096ec352 Mon Sep 17 00:00:00 2001 From: Peter Kasting Date: Mon, 16 Oct 2023 17:05:34 -0700 Subject: [PATCH 059/107] Roll crashpad/third_party/mini_chromium/mini_chromium/ 276f2ac53..42f1fddfe (1 commit) https://chromium.googlesource.com/chromium/mini_chromium/+log/276f2ac531cd..42f1fddfec57 $ git log 276f2ac53..42f1fddfe --date=short --no-merges --format='%ad %ae %s' 2023-10-16 pkasting Use POSIX format specifiers on Windows. Created with: roll-dep crashpad/third_party/mini_chromium/mini_chromium Bug: 1371963 Change-Id: I7210b416b5e498b9888d1c942084c07ef177b667 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4944315 Commit-Queue: Peter Kasting Reviewed-by: Mark Mentovai --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index 6bae243f..bf1910ff 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - '276f2ac531cd8c5c54a32638ea3889069094a8a1', + '42f1fddfec57b255a3c0fdc804ca75226b493dc8', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', From c63c073d27ad2bec05177ff30419229dd9f493b6 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 18 Oct 2023 12:08:10 -0700 Subject: [PATCH 060/107] Do IWYU for check_op.h Include check_op.h directly, instead of relying on the transitive include from logging.h. This transitive include does not exist in Chromium's //base. Change-Id: I15962a9cdc26ac206032157b8d2659cf263ad695 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4950200 Reviewed-by: Mark Mentovai Commit-Queue: Lei Zhang --- client/crash_report_database_generic.cc | 1 + client/crash_report_database_win.cc | 1 + client/crashpad_client_fuchsia.cc | 1 + client/crashpad_client_linux.cc | 1 + client/crashpad_client_mac.cc | 1 + client/crashpad_client_win.cc | 1 + client/ios_handler/in_process_intermediate_dump_handler.cc | 1 + handler/linux/exception_handler_server.cc | 1 + minidump/minidump_annotation_writer.cc | 1 + minidump/minidump_byte_array_writer.cc | 1 + minidump/minidump_context_writer.cc | 1 + minidump/minidump_file_writer.cc | 1 + minidump/minidump_handle_writer.cc | 1 + minidump/minidump_memory_writer.cc | 1 + minidump/minidump_module_crashpad_info_writer.cc | 1 + minidump/minidump_module_writer.cc | 1 + minidump/minidump_rva_list_writer.cc | 1 + minidump/minidump_simple_string_dictionary_writer.cc | 1 + minidump/minidump_string_writer.cc | 1 + minidump/minidump_thread_name_list_writer.cc | 1 + minidump/minidump_thread_writer.cc | 1 + minidump/minidump_unloaded_module_writer.cc | 1 + minidump/minidump_writable.cc | 1 + snapshot/elf/elf_image_reader.cc | 1 + snapshot/fuchsia/process_reader_fuchsia.cc | 1 + snapshot/ios/exception_snapshot_ios_intermediate_dump.cc | 1 + snapshot/ios/memory_snapshot_ios_intermediate_dump.cc | 2 ++ snapshot/linux/system_snapshot_linux.cc | 1 + snapshot/mac/mach_o_image_reader.cc | 1 + snapshot/mac/mach_o_image_segment_reader.cc | 1 + snapshot/mac/process_reader_mac.cc | 1 + snapshot/minidump/module_snapshot_minidump.cc | 1 + snapshot/win/process_reader_win.cc | 1 + test/ios/host/handler_forbidden_allocators.cc | 2 ++ util/file/file_io_posix.cc | 1 + util/file/file_io_win.cc | 1 + util/file/file_reader.cc | 1 + util/file/file_writer.cc | 1 + util/file/string_file.cc | 1 + util/fuchsia/scoped_task_suspend.cc | 1 + util/ios/ios_intermediate_dump_writer.cc | 1 + util/linux/exception_handler_client.cc | 1 + util/linux/memory_map.cc | 1 + util/linux/proc_task_reader.cc | 1 + util/linux/ptrace_client.cc | 1 + util/linux/ptracer.cc | 1 + util/mac/xattr.cc | 1 + util/mach/mach_message_server.cc | 1 + util/net/http_body_gzip.cc | 1 + util/net/http_transport_socket.cc | 1 + util/net/http_transport_win.cc | 1 + util/posix/close_multiple.cc | 1 + util/posix/process_info_mac.cc | 1 + util/process/process_memory_fuchsia.cc | 3 ++- util/process/process_memory_linux.cc | 1 + util/process/process_memory_mac.cc | 1 + util/process/process_memory_win.cc | 1 + util/win/process_info.cc | 1 + 58 files changed, 61 insertions(+), 1 deletion(-) diff --git a/client/crash_report_database_generic.cc b/client/crash_report_database_generic.cc index 28a393d0..617a0745 100644 --- a/client/crash_report_database_generic.cc +++ b/client/crash_report_database_generic.cc @@ -22,6 +22,7 @@ #include #include +#include "base/check_op.h" #include "base/logging.h" #include "build/build_config.h" #include "client/settings.h" diff --git a/client/crash_report_database_win.cc b/client/crash_report_database_win.cc index b0c5229e..e925cf9f 100644 --- a/client/crash_report_database_win.cc +++ b/client/crash_report_database_win.cc @@ -25,6 +25,7 @@ #include #include +#include "base/check_op.h" #include "base/logging.h" #include "base/numerics/safe_math.h" #include "base/strings/utf_string_conversions.h" diff --git a/client/crashpad_client_fuchsia.cc b/client/crashpad_client_fuchsia.cc index e6addb1c..9b09ad1b 100644 --- a/client/crashpad_client_fuchsia.cc +++ b/client/crashpad_client_fuchsia.cc @@ -20,6 +20,7 @@ #include #include +#include "base/check_op.h" #include "base/fuchsia/fuchsia_logging.h" #include "base/logging.h" #include "client/client_argv_handling.h" diff --git a/client/crashpad_client_linux.cc b/client/crashpad_client_linux.cc index f805ff1f..1d79be7a 100644 --- a/client/crashpad_client_linux.cc +++ b/client/crashpad_client_linux.cc @@ -30,6 +30,7 @@ #include +#include "base/check_op.h" #include "base/logging.h" #include "base/strings/stringprintf.h" #include "build/build_config.h" diff --git a/client/crashpad_client_mac.cc b/client/crashpad_client_mac.cc index 8b85ac73..28c9588b 100644 --- a/client/crashpad_client_mac.cc +++ b/client/crashpad_client_mac.cc @@ -25,6 +25,7 @@ #include #include "base/apple/mach_logging.h" +#include "base/check_op.h" #include "base/logging.h" #include "base/strings/stringprintf.h" #include "util/mac/mac_util.h" diff --git a/client/crashpad_client_win.cc b/client/crashpad_client_win.cc index 8ba75482..2f02001d 100644 --- a/client/crashpad_client_win.cc +++ b/client/crashpad_client_win.cc @@ -25,6 +25,7 @@ #include #include "base/atomicops.h" +#include "base/check_op.h" #include "base/logging.h" #include "base/scoped_generic.h" #include "base/strings/stringprintf.h" diff --git a/client/ios_handler/in_process_intermediate_dump_handler.cc b/client/ios_handler/in_process_intermediate_dump_handler.cc index 06eaccee..a7ac5dae 100644 --- a/client/ios_handler/in_process_intermediate_dump_handler.cc +++ b/client/ios_handler/in_process_intermediate_dump_handler.cc @@ -24,6 +24,7 @@ #include #include +#include "base/check_op.h" #include "build/build_config.h" #include "snapshot/snapshot_constants.h" #include "util/ios/ios_intermediate_dump_writer.h" diff --git a/handler/linux/exception_handler_server.cc b/handler/linux/exception_handler_server.cc index a267e2f1..00b07646 100644 --- a/handler/linux/exception_handler_server.cc +++ b/handler/linux/exception_handler_server.cc @@ -25,6 +25,7 @@ #include +#include "base/check_op.h" #include "base/compiler_specific.h" #include "base/logging.h" #include "base/posix/eintr_wrapper.h" diff --git a/minidump/minidump_annotation_writer.cc b/minidump/minidump_annotation_writer.cc index 1d6a4928..751dd013 100644 --- a/minidump/minidump_annotation_writer.cc +++ b/minidump/minidump_annotation_writer.cc @@ -16,6 +16,7 @@ #include +#include "base/check_op.h" #include "base/logging.h" #include "util/file/file_writer.h" #include "util/numeric/safe_assignment.h" diff --git a/minidump/minidump_byte_array_writer.cc b/minidump/minidump_byte_array_writer.cc index 38ce1c7e..b3c8aa9d 100644 --- a/minidump/minidump_byte_array_writer.cc +++ b/minidump/minidump_byte_array_writer.cc @@ -14,6 +14,7 @@ #include "minidump/minidump_byte_array_writer.h" +#include "base/check_op.h" #include "base/logging.h" #include "util/file/file_writer.h" #include "util/numeric/safe_assignment.h" diff --git a/minidump/minidump_context_writer.cc b/minidump/minidump_context_writer.cc index 84c01482..326b51fe 100644 --- a/minidump/minidump_context_writer.cc +++ b/minidump/minidump_context_writer.cc @@ -19,6 +19,7 @@ #include #include +#include "base/check_op.h" #include "base/compiler_specific.h" #include "base/logging.h" #include "build/build_config.h" diff --git a/minidump/minidump_file_writer.cc b/minidump/minidump_file_writer.cc index 6c9b5cc2..021b1876 100644 --- a/minidump/minidump_file_writer.cc +++ b/minidump/minidump_file_writer.cc @@ -16,6 +16,7 @@ #include +#include "base/check_op.h" #include "base/logging.h" #include "minidump/minidump_crashpad_info_writer.h" #include "minidump/minidump_exception_writer.h" diff --git a/minidump/minidump_handle_writer.cc b/minidump/minidump_handle_writer.cc index bed4f100..72f1b196 100644 --- a/minidump/minidump_handle_writer.cc +++ b/minidump/minidump_handle_writer.cc @@ -16,6 +16,7 @@ #include +#include "base/check_op.h" #include "base/logging.h" #include "minidump/minidump_extensions.h" #include "util/file/file_writer.h" diff --git a/minidump/minidump_memory_writer.cc b/minidump/minidump_memory_writer.cc index f52e6a4c..dd6c91ae 100644 --- a/minidump/minidump_memory_writer.cc +++ b/minidump/minidump_memory_writer.cc @@ -19,6 +19,7 @@ #include #include "base/auto_reset.h" +#include "base/check_op.h" #include "base/logging.h" #include "util/file/file_writer.h" #include "util/numeric/safe_assignment.h" diff --git a/minidump/minidump_module_crashpad_info_writer.cc b/minidump/minidump_module_crashpad_info_writer.cc index 456f4bd4..7f3dcda9 100644 --- a/minidump/minidump_module_crashpad_info_writer.cc +++ b/minidump/minidump_module_crashpad_info_writer.cc @@ -16,6 +16,7 @@ #include +#include "base/check_op.h" #include "base/logging.h" #include "minidump/minidump_annotation_writer.h" #include "minidump/minidump_simple_string_dictionary_writer.h" diff --git a/minidump/minidump_module_writer.cc b/minidump/minidump_module_writer.cc index 237fee0d..1287a6de 100644 --- a/minidump/minidump_module_writer.cc +++ b/minidump/minidump_module_writer.cc @@ -19,6 +19,7 @@ #include #include +#include "base/check_op.h" #include "base/logging.h" #include "base/numerics/safe_conversions.h" #include "minidump/minidump_string_writer.h" diff --git a/minidump/minidump_rva_list_writer.cc b/minidump/minidump_rva_list_writer.cc index 77e10d47..3a1ee8e8 100644 --- a/minidump/minidump_rva_list_writer.cc +++ b/minidump/minidump_rva_list_writer.cc @@ -16,6 +16,7 @@ #include +#include "base/check_op.h" #include "base/logging.h" #include "util/file/file_writer.h" #include "util/numeric/safe_assignment.h" diff --git a/minidump/minidump_simple_string_dictionary_writer.cc b/minidump/minidump_simple_string_dictionary_writer.cc index f4c9011c..cb25098b 100644 --- a/minidump/minidump_simple_string_dictionary_writer.cc +++ b/minidump/minidump_simple_string_dictionary_writer.cc @@ -16,6 +16,7 @@ #include +#include "base/check_op.h" #include "base/logging.h" #include "util/file/file_writer.h" #include "util/numeric/safe_assignment.h" diff --git a/minidump/minidump_string_writer.cc b/minidump/minidump_string_writer.cc index ea7856ab..0b0a3e86 100644 --- a/minidump/minidump_string_writer.cc +++ b/minidump/minidump_string_writer.cc @@ -16,6 +16,7 @@ #include +#include "base/check_op.h" #include "base/logging.h" #include "minidump/minidump_writer_util.h" #include "util/file/file_writer.h" diff --git a/minidump/minidump_thread_name_list_writer.cc b/minidump/minidump_thread_name_list_writer.cc index 5679b811..aba496a5 100644 --- a/minidump/minidump_thread_name_list_writer.cc +++ b/minidump/minidump_thread_name_list_writer.cc @@ -16,6 +16,7 @@ #include +#include "base/check_op.h" #include "base/logging.h" #include "minidump/minidump_thread_id_map.h" #include "snapshot/thread_snapshot.h" diff --git a/minidump/minidump_thread_writer.cc b/minidump/minidump_thread_writer.cc index 02870f6e..b7aa889a 100644 --- a/minidump/minidump_thread_writer.cc +++ b/minidump/minidump_thread_writer.cc @@ -16,6 +16,7 @@ #include +#include "base/check_op.h" #include "base/logging.h" #include "minidump/minidump_context_writer.h" #include "minidump/minidump_memory_writer.h" diff --git a/minidump/minidump_unloaded_module_writer.cc b/minidump/minidump_unloaded_module_writer.cc index 3f1c8e5d..c7bf3452 100644 --- a/minidump/minidump_unloaded_module_writer.cc +++ b/minidump/minidump_unloaded_module_writer.cc @@ -17,6 +17,7 @@ #include #include +#include "base/check_op.h" #include "minidump/minidump_writer_util.h" #include "util/file/file_writer.h" #include "util/numeric/in_range_cast.h" diff --git a/minidump/minidump_writable.cc b/minidump/minidump_writable.cc index cb23b3ff..c0badd72 100644 --- a/minidump/minidump_writable.cc +++ b/minidump/minidump_writable.cc @@ -18,6 +18,7 @@ #include +#include "base/check_op.h" #include "base/logging.h" #include "util/file/file_writer.h" #include "util/numeric/safe_assignment.h" diff --git a/snapshot/elf/elf_image_reader.cc b/snapshot/elf/elf_image_reader.cc index dcab025a..b0340e5f 100644 --- a/snapshot/elf/elf_image_reader.cc +++ b/snapshot/elf/elf_image_reader.cc @@ -21,6 +21,7 @@ #include #include +#include "base/check_op.h" #include "base/logging.h" #include "base/numerics/safe_math.h" #include "build/build_config.h" diff --git a/snapshot/fuchsia/process_reader_fuchsia.cc b/snapshot/fuchsia/process_reader_fuchsia.cc index 89aa74d9..5bf2acf7 100644 --- a/snapshot/fuchsia/process_reader_fuchsia.cc +++ b/snapshot/fuchsia/process_reader_fuchsia.cc @@ -18,6 +18,7 @@ #include #include +#include "base/check_op.h" #include "base/fuchsia/fuchsia_logging.h" #include "base/logging.h" #include "util/fuchsia/koid_utilities.h" diff --git a/snapshot/ios/exception_snapshot_ios_intermediate_dump.cc b/snapshot/ios/exception_snapshot_ios_intermediate_dump.cc index cee9c8a7..e3478454 100644 --- a/snapshot/ios/exception_snapshot_ios_intermediate_dump.cc +++ b/snapshot/ios/exception_snapshot_ios_intermediate_dump.cc @@ -15,6 +15,7 @@ #include "snapshot/ios/exception_snapshot_ios_intermediate_dump.h" #include "base/apple/mach_logging.h" +#include "base/check_op.h" #include "base/logging.h" #include "snapshot/cpu_context.h" #include "snapshot/ios/intermediate_dump_reader_util.h" diff --git a/snapshot/ios/memory_snapshot_ios_intermediate_dump.cc b/snapshot/ios/memory_snapshot_ios_intermediate_dump.cc index a3c7a137..b272eb65 100644 --- a/snapshot/ios/memory_snapshot_ios_intermediate_dump.cc +++ b/snapshot/ios/memory_snapshot_ios_intermediate_dump.cc @@ -14,6 +14,8 @@ #include "snapshot/ios/memory_snapshot_ios_intermediate_dump.h" +#include "base/check_op.h" + namespace crashpad { namespace internal { diff --git a/snapshot/linux/system_snapshot_linux.cc b/snapshot/linux/system_snapshot_linux.cc index 20b95fba..b32f22d7 100644 --- a/snapshot/linux/system_snapshot_linux.cc +++ b/snapshot/linux/system_snapshot_linux.cc @@ -20,6 +20,7 @@ #include +#include "base/check_op.h" #include "base/files/file_path.h" #include "base/logging.h" #include "base/notreached.h" diff --git a/snapshot/mac/mach_o_image_reader.cc b/snapshot/mac/mach_o_image_reader.cc index 72825521..b648f7f2 100644 --- a/snapshot/mac/mach_o_image_reader.cc +++ b/snapshot/mac/mach_o_image_reader.cc @@ -22,6 +22,7 @@ #include #include +#include "base/check_op.h" #include "base/logging.h" #include "base/strings/stringprintf.h" #include "client/crashpad_info.h" diff --git a/snapshot/mac/mach_o_image_segment_reader.cc b/snapshot/mac/mach_o_image_segment_reader.cc index 75f229ef..17b7bd33 100644 --- a/snapshot/mac/mach_o_image_segment_reader.cc +++ b/snapshot/mac/mach_o_image_segment_reader.cc @@ -20,6 +20,7 @@ #include +#include "base/check_op.h" #include "base/logging.h" #include "base/strings/stringprintf.h" #include "build/build_config.h" diff --git a/snapshot/mac/process_reader_mac.cc b/snapshot/mac/process_reader_mac.cc index 53dae075..c77c0d39 100644 --- a/snapshot/mac/process_reader_mac.cc +++ b/snapshot/mac/process_reader_mac.cc @@ -24,6 +24,7 @@ #include "base/apple/mach_logging.h" #include "base/apple/scoped_mach_port.h" #include "base/apple/scoped_mach_vm.h" +#include "base/check_op.h" #include "base/logging.h" #include "base/strings/stringprintf.h" #include "snapshot/mac/mach_o_image_reader.h" diff --git a/snapshot/minidump/module_snapshot_minidump.cc b/snapshot/minidump/module_snapshot_minidump.cc index 43229e7a..50e5ea85 100644 --- a/snapshot/minidump/module_snapshot_minidump.cc +++ b/snapshot/minidump/module_snapshot_minidump.cc @@ -17,6 +17,7 @@ #include #include +#include "base/check_op.h" #include "base/logging.h" #include "base/notreached.h" #include "minidump/minidump_extensions.h" diff --git a/snapshot/win/process_reader_win.cc b/snapshot/win/process_reader_win.cc index 0c4ca0c6..469d789c 100644 --- a/snapshot/win/process_reader_win.cc +++ b/snapshot/win/process_reader_win.cc @@ -19,6 +19,7 @@ #include +#include "base/check_op.h" #include "base/notreached.h" #include "base/numerics/safe_conversions.h" #include "base/strings/utf_string_conversions.h" diff --git a/test/ios/host/handler_forbidden_allocators.cc b/test/ios/host/handler_forbidden_allocators.cc index 4e829f0b..65e0a136 100644 --- a/test/ios/host/handler_forbidden_allocators.cc +++ b/test/ios/host/handler_forbidden_allocators.cc @@ -17,9 +17,11 @@ #include #include #include + #include #include "base/apple/mach_logging.h" +#include "base/check_op.h" #include "client/crashpad_client.h" #include "util/ios/raw_logging.h" diff --git a/util/file/file_io_posix.cc b/util/file/file_io_posix.cc index 07c24c31..6d02462b 100644 --- a/util/file/file_io_posix.cc +++ b/util/file/file_io_posix.cc @@ -24,6 +24,7 @@ #include #include +#include "base/check_op.h" #include "base/files/file_path.h" #include "base/logging.h" #include "base/notreached.h" diff --git a/util/file/file_io_win.cc b/util/file/file_io_win.cc index 595e3579..cb9ea147 100644 --- a/util/file/file_io_win.cc +++ b/util/file/file_io_win.cc @@ -17,6 +17,7 @@ #include #include +#include "base/check_op.h" #include "base/files/file_path.h" #include "base/logging.h" #include "base/notreached.h" diff --git a/util/file/file_reader.cc b/util/file/file_reader.cc index b4e89563..f8fcf818 100644 --- a/util/file/file_reader.cc +++ b/util/file/file_reader.cc @@ -14,6 +14,7 @@ #include "util/file/file_reader.h" +#include "base/check_op.h" #include "base/logging.h" #include "base/numerics/safe_conversions.h" #include "build/build_config.h" diff --git a/util/file/file_writer.cc b/util/file/file_writer.cc index 74c55d64..a5bfa081 100644 --- a/util/file/file_writer.cc +++ b/util/file/file_writer.cc @@ -20,6 +20,7 @@ #include +#include "base/check_op.h" #include "base/logging.h" #include "base/numerics/safe_conversions.h" #include "build/build_config.h" diff --git a/util/file/string_file.cc b/util/file/string_file.cc index 93a4f320..959d0474 100644 --- a/util/file/string_file.cc +++ b/util/file/string_file.cc @@ -19,6 +19,7 @@ #include #include +#include "base/check_op.h" #include "base/logging.h" #include "base/numerics/safe_math.h" #include "util/misc/implicit_cast.h" diff --git a/util/fuchsia/scoped_task_suspend.cc b/util/fuchsia/scoped_task_suspend.cc index 0dd54251..ef057ae3 100644 --- a/util/fuchsia/scoped_task_suspend.cc +++ b/util/fuchsia/scoped_task_suspend.cc @@ -21,6 +21,7 @@ #include +#include "base/check_op.h" #include "base/fuchsia/fuchsia_logging.h" #include "base/logging.h" #include "util/fuchsia/koid_utilities.h" diff --git a/util/ios/ios_intermediate_dump_writer.cc b/util/ios/ios_intermediate_dump_writer.cc index c180fc08..67d804b3 100644 --- a/util/ios/ios_intermediate_dump_writer.cc +++ b/util/ios/ios_intermediate_dump_writer.cc @@ -23,6 +23,7 @@ #include #include "base/check.h" +#include "base/check_op.h" #include "base/posix/eintr_wrapper.h" #include "build/build_config.h" #include "util/ios/raw_logging.h" diff --git a/util/linux/exception_handler_client.cc b/util/linux/exception_handler_client.cc index cef493df..68dc67ef 100644 --- a/util/linux/exception_handler_client.cc +++ b/util/linux/exception_handler_client.cc @@ -20,6 +20,7 @@ #include #include +#include "base/check_op.h" #include "base/logging.h" #include "base/posix/eintr_wrapper.h" #include "build/build_config.h" diff --git a/util/linux/memory_map.cc b/util/linux/memory_map.cc index 2c18f30b..58de835e 100644 --- a/util/linux/memory_map.cc +++ b/util/linux/memory_map.cc @@ -19,6 +19,7 @@ #include #include "base/bit_cast.h" +#include "base/check_op.h" #include "base/files/file_path.h" #include "base/logging.h" #include "build/build_config.h" diff --git a/util/linux/proc_task_reader.cc b/util/linux/proc_task_reader.cc index ee8422be..159d8cac 100644 --- a/util/linux/proc_task_reader.cc +++ b/util/linux/proc_task_reader.cc @@ -18,6 +18,7 @@ #include +#include "base/check_op.h" #include "base/files/file_path.h" #include "base/logging.h" #include "base/strings/string_number_conversions.h" diff --git a/util/linux/ptrace_client.cc b/util/linux/ptrace_client.cc index c04ca5b4..56bc5556 100644 --- a/util/linux/ptrace_client.cc +++ b/util/linux/ptrace_client.cc @@ -21,6 +21,7 @@ #include #include +#include "base/check_op.h" #include "base/logging.h" #include "base/strings/string_number_conversions.h" #include "util/file/file_io.h" diff --git a/util/linux/ptracer.cc b/util/linux/ptracer.cc index d8129ada..a985cb1d 100644 --- a/util/linux/ptracer.cc +++ b/util/linux/ptracer.cc @@ -20,6 +20,7 @@ #include #include +#include "base/check_op.h" #include "base/logging.h" #include "build/build_config.h" #include "util/misc/from_pointer_cast.h" diff --git a/util/mac/xattr.cc b/util/mac/xattr.cc index ae3555d7..6c12e913 100644 --- a/util/mac/xattr.cc +++ b/util/mac/xattr.cc @@ -19,6 +19,7 @@ #include #include +#include "base/check_op.h" #include "base/logging.h" #include "base/numerics/safe_conversions.h" #include "base/strings/string_number_conversions.h" diff --git a/util/mach/mach_message_server.cc b/util/mach/mach_message_server.cc index bfe8a8cf..b4509a9a 100644 --- a/util/mach/mach_message_server.cc +++ b/util/mach/mach_message_server.cc @@ -20,6 +20,7 @@ #include "base/apple/mach_logging.h" #include "base/apple/scoped_mach_vm.h" +#include "base/check_op.h" #include "base/logging.h" #include "util/mach/mach_message.h" diff --git a/util/net/http_body_gzip.cc b/util/net/http_body_gzip.cc index bd0ec5f8..a7882ea8 100644 --- a/util/net/http_body_gzip.cc +++ b/util/net/http_body_gzip.cc @@ -16,6 +16,7 @@ #include +#include "base/check_op.h" #include "base/logging.h" #include "base/numerics/safe_conversions.h" #include "third_party/zlib/zlib_crashpad.h" diff --git a/util/net/http_transport_socket.cc b/util/net/http_transport_socket.cc index 3aec8c0a..0d7fc0d1 100644 --- a/util/net/http_transport_socket.cc +++ b/util/net/http_transport_socket.cc @@ -20,6 +20,7 @@ #include +#include "base/check_op.h" #include "base/logging.h" #include "base/numerics/safe_conversions.h" #include "base/posix/eintr_wrapper.h" diff --git a/util/net/http_transport_win.cc b/util/net/http_transport_win.cc index 6bc2481d..df444d86 100644 --- a/util/net/http_transport_win.cc +++ b/util/net/http_transport_win.cc @@ -24,6 +24,7 @@ #include +#include "base/check_op.h" #include "base/logging.h" #include "base/numerics/safe_conversions.h" #include "base/scoped_generic.h" diff --git a/util/posix/close_multiple.cc b/util/posix/close_multiple.cc index 628beeab..8c94e750 100644 --- a/util/posix/close_multiple.cc +++ b/util/posix/close_multiple.cc @@ -23,6 +23,7 @@ #include #include +#include "base/check_op.h" #include "base/files/scoped_file.h" #include "base/logging.h" #include "base/posix/eintr_wrapper.h" diff --git a/util/posix/process_info_mac.cc b/util/posix/process_info_mac.cc index 07a93a5b..cf615194 100644 --- a/util/posix/process_info_mac.cc +++ b/util/posix/process_info_mac.cc @@ -19,6 +19,7 @@ #include #include "base/apple/mach_logging.h" +#include "base/check_op.h" #include "base/logging.h" namespace crashpad { diff --git a/util/process/process_memory_fuchsia.cc b/util/process/process_memory_fuchsia.cc index 7129f8a7..a14c2ac6 100644 --- a/util/process/process_memory_fuchsia.cc +++ b/util/process/process_memory_fuchsia.cc @@ -16,8 +16,9 @@ #include -#include "base/logging.h" +#include "base/check_op.h" #include "base/fuchsia/fuchsia_logging.h" +#include "base/logging.h" namespace crashpad { diff --git a/util/process/process_memory_linux.cc b/util/process/process_memory_linux.cc index 1e9002d7..9c2edea3 100644 --- a/util/process/process_memory_linux.cc +++ b/util/process/process_memory_linux.cc @@ -22,6 +22,7 @@ #include #include +#include "base/check_op.h" #include "base/logging.h" #include "base/posix/eintr_wrapper.h" #include "build/build_config.h" diff --git a/util/process/process_memory_mac.cc b/util/process/process_memory_mac.cc index a3cb6696..a972401d 100644 --- a/util/process/process_memory_mac.cc +++ b/util/process/process_memory_mac.cc @@ -20,6 +20,7 @@ #include #include "base/apple/mach_logging.h" +#include "base/check_op.h" #include "base/logging.h" #include "base/strings/stringprintf.h" #include "util/stdlib/strnlen.h" diff --git a/util/process/process_memory_win.cc b/util/process/process_memory_win.cc index 8c5a1679..c120827a 100644 --- a/util/process/process_memory_win.cc +++ b/util/process/process_memory_win.cc @@ -19,6 +19,7 @@ #include #include +#include "base/check_op.h" #include "base/logging.h" #include "base/memory/page_size.h" #include "base/numerics/safe_conversions.h" diff --git a/util/win/process_info.cc b/util/win/process_info.cc index c5d41388..888b9ea2 100644 --- a/util/win/process_info.cc +++ b/util/win/process_info.cc @@ -23,6 +23,7 @@ #include #include +#include "base/check_op.h" #include "base/logging.h" #include "base/memory/free_deleter.h" #include "base/process/memory.h" From b6d3cdcc4deadbd590edc91415559a042eaf0646 Mon Sep 17 00:00:00 2001 From: Peter Kasting Date: Wed, 18 Oct 2023 14:15:06 -0700 Subject: [PATCH 061/107] Roll crashpad/third_party/mini_chromium/mini_chromium/ 42f1fddfe..bc8dca83b (3 commits) https://chromium.googlesource.com/chromium/mini_chromium/+log/42f1fddfec57..bc8dca83bd2f $ git log 42f1fddfe..bc8dca83b --date=short --no-merges --format='%ad %ae %s' 2023-10-18 pkasting Add iter_reference_t to template_util.h. 2023-10-18 thestig Remove check_op.h from base/logging.h 2023-10-17 pkasting Add base::StrCat(). Created with: roll-dep crashpad/third_party/mini_chromium/mini_chromium Bug: 1371963 Change-Id: I19a74661930c733814403c9813fe544fe0540b1f Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4953853 Reviewed-by: Mark Mentovai Commit-Queue: Peter Kasting --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index bf1910ff..c23ad82b 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - '42f1fddfec57b255a3c0fdc804ca75226b493dc8', + 'bc8dca83bd2f755bc91a2fd55ae229d5a1f13dc2', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', From 376e8c0e699490bdaba5c1661abc98926f5c4231 Mon Sep 17 00:00:00 2001 From: Peter Kasting Date: Wed, 18 Oct 2023 14:16:23 -0700 Subject: [PATCH 062/107] Eliminate call to StringPrintf() with non-constexpr format string. Bug: 1371963 Change-Id: Ic3cc2010e48c399de8d19b94c3b515b53e2d18a3 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4953795 Commit-Queue: Peter Kasting Reviewed-by: Mark Mentovai --- client/crash_report_database_mac.mm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/crash_report_database_mac.mm b/client/crash_report_database_mac.mm index c8522623..5d72b17e 100644 --- a/client/crash_report_database_mac.mm +++ b/client/crash_report_database_mac.mm @@ -34,8 +34,8 @@ #include "base/logging.h" #include "base/posix/eintr_wrapper.h" #include "base/scoped_generic.h" +#include "base/strings/strcat.h" #include "base/strings/string_piece.h" -#include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" #include "client/settings.h" #include "util/file/directory_reader.h" @@ -116,9 +116,9 @@ bool CreateOrEnsureDirectoryExists(const base::FilePath& path) { // have changed, and new_name determines whether the returned xattr name will be // the old name or its new equivalent. std::string XattrNameInternal(const base::StringPiece& name, bool new_name) { - return base::StringPrintf(new_name ? "org.chromium.crashpad.database.%s" - : "com.googlecode.crashpad.%s", - name.data()); + return base::StrCat({new_name ? "org.chromium.crashpad.database." + : "com.googlecode.crashpad.", + name}); } } // namespace From e17518a9e879f63b578db6c184c6bb17f1b13a06 Mon Sep 17 00:00:00 2001 From: Rich Mckeever Date: Thu, 26 Oct 2023 15:21:09 -0400 Subject: [PATCH 063/107] Add an option to start a Windows client with global hooks disabled. Change-Id: I645d6136788ca4ccebfc73005c8c2455dc4b2cee Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4949671 Reviewed-by: Mark Mentovai Commit-Queue: Rich Mckeever --- client/crashpad_client.h | 16 ++++ client/crashpad_client_win.cc | 7 +- client/crashpad_client_win_test.cc | 123 ++++++++++++++++++++++++++++- 3 files changed, 143 insertions(+), 3 deletions(-) diff --git a/client/crashpad_client.h b/client/crashpad_client.h index 3c966686..23a16ce7 100644 --- a/client/crashpad_client.h +++ b/client/crashpad_client.h @@ -486,6 +486,21 @@ class CrashpadClient { #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) || // BUILDFLAG(IS_CHROMEOS) || DOXYGEN +#if BUILDFLAG(IS_WIN) || DOXYGEN + //! \brief Configures this client to not install any process-global hooks, + //! such as an unhandled exception filter or vectored exception handler. + //! + //! This may be useful if this client is being used in the context of an + //! extension library, which only wants to capture crashes in its own code, + //! via catch blocks, and not all crashes in the host process. + //! + //! This method must be called before calling StartHandler(), + //! SetHandlerSocket(), or other methods that install global hooks. + void DisableGlobalHooks() { + disable_global_hooks_ = true; + } +#endif // BUILDFLAG(IS_WIN) || DOXYGEN + #if BUILDFLAG(IS_IOS) || DOXYGEN //! \brief Observation callback invoked each time this object finishes //! processing and attempting to upload on-disk crash reports (whether or @@ -818,6 +833,7 @@ class CrashpadClient { std::wstring ipc_pipe_; ScopedKernelHANDLE handler_start_thread_; ScopedVectoredExceptionRegistration vectored_handler_; + bool disable_global_hooks_; #elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) std::set unhandled_signals_; #endif // BUILDFLAG(IS_APPLE) diff --git a/client/crashpad_client_win.cc b/client/crashpad_client_win.cc index 2f02001d..4cbaf88e 100644 --- a/client/crashpad_client_win.cc +++ b/client/crashpad_client_win.cc @@ -592,7 +592,8 @@ void CommonInProcessInitialization() { } // namespace CrashpadClient::CrashpadClient() - : ipc_pipe_(), handler_start_thread_(), vectored_handler_() {} + : ipc_pipe_(), handler_start_thread_(), vectored_handler_(), + disable_global_hooks_(false) {} CrashpadClient::~CrashpadClient() {} @@ -667,6 +668,10 @@ bool CrashpadClient::StartHandler( } void CrashpadClient::RegisterHandlers() { + if (disable_global_hooks_) { + return; + } + SetUnhandledExceptionFilter(&UnhandledExceptionHandler); // Windows swallows heap corruption failures but we can intercept them with diff --git a/client/crashpad_client_win_test.cc b/client/crashpad_client_win_test.cc index 901cf81f..99c0e204 100644 --- a/client/crashpad_client_win_test.cc +++ b/client/crashpad_client_win_test.cc @@ -17,6 +17,7 @@ #include #include "base/files/file_path.h" +#include "client/crash_report_database.h" #include "gtest/gtest.h" #include "test/test_paths.h" #include "test/scoped_temp_dir.h" @@ -29,11 +30,10 @@ namespace crashpad { namespace test { namespace { -void StartAndUseHandler(const base::FilePath& temp_dir) { +void StartAndUseHandler(CrashpadClient& client, const base::FilePath& temp_dir) { base::FilePath handler_path = TestPaths::Executable().DirName().Append( FILE_PATH_LITERAL("crashpad_handler.com")); - CrashpadClient client; ASSERT_TRUE(client.StartHandler(handler_path, temp_dir, base::FilePath(), @@ -45,6 +45,11 @@ void StartAndUseHandler(const base::FilePath& temp_dir) { ASSERT_TRUE(client.WaitForHandlerStart(INFINITE)); } +void StartAndUseHandler(const base::FilePath& temp_dir) { + CrashpadClient client; + StartAndUseHandler(client, temp_dir); +} + class StartWithInvalidHandles final : public WinMultiprocessWithTempDir { public: StartWithInvalidHandles() : WinMultiprocessWithTempDir() {} @@ -192,6 +197,120 @@ TEST(CrashpadClient, HandlerLaunchFailureDumpWithoutCrash) { WinMultiprocess::Run(); } +class NoDumpExpected : public WinMultiprocessWithTempDir { + private: + void WinMultiprocessParentAfterChild(HANDLE child) override { + // Make sure no dump was generated. + std::unique_ptr database( + CrashReportDatabase::Initialize(GetTempDirPath())); + ASSERT_TRUE(database); + + std::vector reports; + ASSERT_EQ(database->GetPendingReports(&reports), + CrashReportDatabase::kNoError); + ASSERT_EQ(reports.size(), 0u); + } +}; + +// Crashing the process under test does not result in a crashed status as an +// exit code in debug builds, so we only verify this behavior in release +// builds. +#if defined(NDEBUG) +class CrashWithDisabledGlobalHooks final : public NoDumpExpected { + public: + CrashWithDisabledGlobalHooks() : NoDumpExpected() {} + ~CrashWithDisabledGlobalHooks() {} + + private: + void WinMultiprocessParent() override { + SetExpectedChildExitCode(STATUS_ACCESS_VIOLATION); + } + + void WinMultiprocessChild() override { + CrashpadClient client; + client.DisableGlobalHooks(); + StartAndUseHandler(client, GetTempDirPath()); + int* bad = nullptr; + *bad = 1; + } +}; + +TEST(CrashpadClient, CrashWithDisabledGlobalHooks) { + WinMultiprocessWithTempDir::Run(); +} +#endif // defined(NDEBUG) + +class DumpAndCrashWithDisabledGlobalHooks final + : public WinMultiprocessWithTempDir { + public: + DumpAndCrashWithDisabledGlobalHooks() : WinMultiprocessWithTempDir() {} + ~DumpAndCrashWithDisabledGlobalHooks() {} + + private: + static constexpr DWORD kExpectedExitCode = 0x1CEB00DA; + + void WinMultiprocessParent() override { + SetExpectedChildExitCode(kExpectedExitCode); + } + + void WinMultiprocessChild() override { + CrashpadClient client; + client.DisableGlobalHooks(); + StartAndUseHandler(client, GetTempDirPath()); + EXCEPTION_RECORD exception_record = {kExpectedExitCode, + EXCEPTION_NONCONTINUABLE}; + CONTEXT context; + CaptureContext(&context); + EXCEPTION_POINTERS exception_pointers = {&exception_record, &context}; + CrashpadClient::DumpAndCrash(&exception_pointers); + } + + void WinMultiprocessParentAfterChild(HANDLE child) override { + // Make sure the dump was generated. + std::unique_ptr database( + CrashReportDatabase::Initialize(GetTempDirPath())); + ASSERT_TRUE(database); + + std::vector reports; + ASSERT_EQ(database->GetPendingReports(&reports), + CrashReportDatabase::kNoError); + ASSERT_EQ(reports.size(), 1u); + + // Delegate the cleanup to the superclass. + WinMultiprocessWithTempDir::WinMultiprocessParentAfterChild(child); + } +}; + +TEST(CrashpadClient, DumpAndCrashWithDisabledGlobalHooks) { + WinMultiprocessWithTempDir::Run(); +} + +#if !defined(ADDRESS_SANITIZER) +class HeapCorruptionWithDisabledGlobalHooks final : public NoDumpExpected { + public: + HeapCorruptionWithDisabledGlobalHooks() : NoDumpExpected() {} + ~HeapCorruptionWithDisabledGlobalHooks() {} + + private: + void WinMultiprocessParent() override { + SetExpectedChildExitCode(STATUS_HEAP_CORRUPTION); + } + + void WinMultiprocessChild() override { + CrashpadClient client; + client.DisableGlobalHooks(); + StartAndUseHandler(client, GetTempDirPath()); + int* bad = reinterpret_cast(1); + delete bad; + } +}; + +TEST(CrashpadClient, HeapCorruptionWithDisabledGlobalHooks) { + WinMultiprocessWithTempDir::Run(); +} + +#endif // !defined(ADDRESS_SANITIZER) + } // namespace } // namespace test } // namespace crashpad From 59fc31ce00d245d59cff282f5ee8f0785b710a2c Mon Sep 17 00:00:00 2001 From: Eric Astor Date: Thu, 26 Oct 2023 17:51:24 +0000 Subject: [PATCH 064/107] Update mini_chromium & use its new support for wide streaming in file_path Fixes a pending issue when we eventually move to C++20. Original author: Dean Sturtevant Change-Id: I7bb0648c73df6b6a28a3a4debdb4524d3cd27b38 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4979733 Reviewed-by: Justin Cohen Commit-Queue: Eric Astor --- DEPS | 2 +- client/crash_report_database_win.cc | 13 ++++------ handler/win/crash_report_exception_handler.cc | 4 +-- util/file/filesystem_win.cc | 26 +++++++++---------- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/DEPS b/DEPS index c23ad82b..85f57ed2 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - 'bc8dca83bd2f755bc91a2fd55ae229d5a1f13dc2', + '707c87bd258dcb8c19be8a69e92efae9fd1b51ad', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', diff --git a/client/crash_report_database_win.cc b/client/crash_report_database_win.cc index e925cf9f..d0a63045 100644 --- a/client/crash_report_database_win.cc +++ b/client/crash_report_database_win.cc @@ -546,8 +546,7 @@ void Metadata::Write() { for (const auto& report : reports_) { const base::FilePath& path = report.file_path; if (path.DirName() != report_dir_) { - LOG(ERROR) << path.value().c_str() << " expected to start with " - << base::WideToUTF8(report_dir_.value()); + LOG(ERROR) << path << " expected to start with " << report_dir_; return; } records.push_back(MetadataFileReportRecord(report, &string_table)); @@ -591,12 +590,11 @@ OperationStatus Metadata::VerifyReport(const ReportDisk& report_disk, bool EnsureDirectory(const base::FilePath& path) { DWORD fileattr = GetFileAttributes(path.value().c_str()); if (fileattr == INVALID_FILE_ATTRIBUTES) { - PLOG(ERROR) << "GetFileAttributes " << base::WideToUTF8(path.value()); + PLOG(ERROR) << "GetFileAttributes " << path; return false; } if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) == 0) { - LOG(ERROR) << "GetFileAttributes " << base::WideToUTF8(path.value()) - << ": not a directory"; + LOG(ERROR) << "GetFileAttributes " << path << ": not a directory"; return false; } return true; @@ -878,7 +876,7 @@ OperationStatus CrashReportDatabaseWin::DeleteReport(const UUID& uuid) { return os; if (!DeleteFile(report_path.value().c_str())) { - PLOG(ERROR) << "DeleteFile " << base::WideToUTF8(report_path.value()); + PLOG(ERROR) << "DeleteFile " << report_path; return kFileSystemError; } @@ -1022,8 +1020,7 @@ void CrashReportDatabaseWin::CleanOrphanedAttachments() { if (IsDirectory(path, false)) { UUID uuid; if (!uuid.InitializeFromString(filename.value())) { - LOG(ERROR) << "unexpected attachment dir name " - << filename.value().c_str(); + LOG(ERROR) << "unexpected attachment dir name " << filename; continue; } diff --git a/handler/win/crash_report_exception_handler.cc b/handler/win/crash_report_exception_handler.cc index eab593cd..84979f10 100644 --- a/handler/win/crash_report_exception_handler.cc +++ b/handler/win/crash_report_exception_handler.cc @@ -115,7 +115,7 @@ unsigned int CrashReportExceptionHandler::ExceptionHandlerServerException( for (const auto& attachment : (*attachments_)) { FileReader file_reader; if (!file_reader.Open(attachment)) { - LOG(ERROR) << "attachment " << attachment.value().c_str() + LOG(ERROR) << "attachment " << attachment << " couldn't be opened, skipping"; continue; } @@ -124,7 +124,7 @@ unsigned int CrashReportExceptionHandler::ExceptionHandlerServerException( FileWriter* file_writer = new_report->AddAttachment(base::WideToUTF8(filename.value())); if (file_writer == nullptr) { - LOG(ERROR) << "attachment " << filename.value().c_str() + LOG(ERROR) << "attachment " << filename << " couldn't be created, skipping"; continue; } diff --git a/util/file/filesystem_win.cc b/util/file/filesystem_win.cc index 510d8e44..b6454b3a 100644 --- a/util/file/filesystem_win.cc +++ b/util/file/filesystem_win.cc @@ -18,7 +18,6 @@ #include #include "base/logging.h" -#include "base/strings/utf_string_conversions.h" #include "util/file/directory_reader.h" #include "util/misc/time.h" @@ -35,7 +34,7 @@ bool IsSymbolicLink(const base::FilePath& path) { nullptr, 0)); if (!handle.is_valid()) { - PLOG(ERROR) << "FindFirstFileEx " << base::WideToUTF8(path.value()); + PLOG(ERROR) << "FindFirstFileEx " << path; return false; } @@ -45,7 +44,7 @@ bool IsSymbolicLink(const base::FilePath& path) { bool LoggingRemoveDirectoryImpl(const base::FilePath& path) { if (!RemoveDirectory(path.value().c_str())) { - PLOG(ERROR) << "RemoveDirectory " << base::WideToUTF8(path.value()); + PLOG(ERROR) << "RemoveDirectory " << path; return false; } return true; @@ -69,13 +68,13 @@ bool FileModificationTime(const base::FilePath& path, timespec* mtime) { flags, nullptr)); if (!handle.is_valid()) { - PLOG(ERROR) << "CreateFile " << base::WideToUTF8(path.value()); + PLOG(ERROR) << "CreateFile " << path; return false; } FILETIME file_mtime; if (!GetFileTime(handle.get(), nullptr, nullptr, &file_mtime)) { - PLOG(ERROR) << "GetFileTime " << base::WideToUTF8(path.value()); + PLOG(ERROR) << "GetFileTime " << path; return false; } *mtime = FiletimeToTimespecEpoch(file_mtime); @@ -90,12 +89,12 @@ bool LoggingCreateDirectory(const base::FilePath& path, } if (may_reuse && GetLastError() == ERROR_ALREADY_EXISTS) { if (!IsDirectory(path, true)) { - LOG(ERROR) << base::WideToUTF8(path.value()) << " not a directory"; + LOG(ERROR) << path << " not a directory"; return false; } return true; } - PLOG(ERROR) << "CreateDirectory " << base::WideToUTF8(path.value()); + PLOG(ERROR) << "CreateDirectory " << path; return false; } @@ -104,8 +103,7 @@ bool MoveFileOrDirectory(const base::FilePath& source, if (!MoveFileEx(source.value().c_str(), dest.value().c_str(), IsDirectory(source, false) ? 0 : MOVEFILE_REPLACE_EXISTING)) { - PLOG(ERROR) << "MoveFileEx" << base::WideToUTF8(source.value()) << ", " - << base::WideToUTF8(dest.value()); + PLOG(ERROR) << "MoveFileEx" << source << ", " << dest; return false; } return true; @@ -114,7 +112,7 @@ bool MoveFileOrDirectory(const base::FilePath& source, bool IsRegularFile(const base::FilePath& path) { DWORD fileattr = GetFileAttributes(path.value().c_str()); if (fileattr == INVALID_FILE_ATTRIBUTES) { - PLOG(ERROR) << "GetFileAttributes " << base::WideToUTF8(path.value()); + PLOG(ERROR) << "GetFileAttributes " << path; return false; } if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0 || @@ -127,7 +125,7 @@ bool IsRegularFile(const base::FilePath& path) { bool IsDirectory(const base::FilePath& path, bool allow_symlinks) { DWORD fileattr = GetFileAttributes(path.value().c_str()); if (fileattr == INVALID_FILE_ATTRIBUTES) { - PLOG(ERROR) << "GetFileAttributes " << base::WideToUTF8(path.value()); + PLOG(ERROR) << "GetFileAttributes " << path; return false; } if (!allow_symlinks && (fileattr & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { @@ -146,7 +144,7 @@ bool LoggingRemoveFile(const base::FilePath& path) { } if (!DeleteFile(path.value().c_str())) { - PLOG(ERROR) << "DeleteFile " << base::WideToUTF8(path.value()); + PLOG(ERROR) << "DeleteFile " << path; return false; } return true; @@ -154,7 +152,7 @@ bool LoggingRemoveFile(const base::FilePath& path) { bool LoggingRemoveDirectory(const base::FilePath& path) { if (IsSymbolicLink(path)) { - LOG(ERROR) << "Not a directory " << base::WideToUTF8(path.value()); + LOG(ERROR) << "Not a directory " << path; return false; } return LoggingRemoveDirectoryImpl(path); @@ -169,7 +167,7 @@ uint64_t GetFileSize(const base::FilePath& filepath) { if (ret_value == 0) { return statbuf.st_size; } - PLOG(ERROR) << "stat " << filepath.value().c_str(); + PLOG(ERROR) << "stat " << filepath; return 0; } From 188ad792982184af5a9db6e3edb040cc4c5d9058 Mon Sep 17 00:00:00 2001 From: Avi Drissman Date: Fri, 27 Oct 2023 11:57:43 -0400 Subject: [PATCH 065/107] Roll crashpad/third_party/mini_chromium/mini_chromium/ 707c87bd2..98bbdbe49 (1 commit) + changes https://chromium.googlesource.com/chromium/mini_chromium/+log/707c87bd258d..98bbdbe49f4a $ git log 707c87bd2..98bbdbe49 --date=short --no-merges --format='%ad %ae %s' 2023-10-27 avi Update ScopedTypeRef Created with: roll-dep crashpad/third_party/mini_chromium/mini_chromium --- In addition, change implicit unwrapping of ScopedCFTypeRef to be explicit. Bug: chromium:1495438, chromium:1495439 Change-Id: I47dd12f94f71caaad74cf23be9da9d03a59772db Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4984741 Commit-Queue: Avi Drissman Reviewed-by: Mark Mentovai --- DEPS | 2 +- util/mac/launchd.mm | 2 +- util/mac/mac_util.cc | 27 +++++++++++++++------------ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/DEPS b/DEPS index 85f57ed2..909ef7dc 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - '707c87bd258dcb8c19be8a69e92efae9fd1b51ad', + '98bbdbe49f4ac26318f88aa7e84296a3da22f7d8', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', diff --git a/util/mac/launchd.mm b/util/mac/launchd.mm index d295ffc6..e2ced32d 100644 --- a/util/mac/launchd.mm +++ b/util/mac/launchd.mm @@ -133,7 +133,7 @@ launch_data_t CFPropertyToLaunchData(CFPropertyListRef property_cf) { base::apple::ScopedCFTypeRef type_name_cf( CFCopyTypeIDDescription(type_id_cf)); DLOG(ERROR) << "unable to convert CFTypeID " << type_id_cf << " (" - << base::SysCFStringRefToUTF8(type_name_cf) << ")"; + << base::SysCFStringRefToUTF8(type_name_cf.get()) << ")"; } return data_launch; diff --git a/util/mac/mac_util.cc b/util/mac/mac_util.cc index c74fbf36..cef23872 100644 --- a/util/mac/mac_util.cc +++ b/util/mac/mac_util.cc @@ -168,7 +168,7 @@ std::string IORegistryEntryDataPropertyAsString(io_registry_entry_t entry, CFStringRef key) { base::apple::ScopedCFTypeRef property( IORegistryEntryCreateCFProperty(entry, key, kCFAllocatorDefault, 0)); - CFDataRef data = base::apple::CFCast(property); + CFDataRef data = base::apple::CFCast(property.get()); if (data && CFDataGetLength(data) > 0) { return reinterpret_cast(CFDataGetBytePtr(data)); } @@ -244,8 +244,9 @@ bool MacOSVersionComponents(int* major, bool success = true; - CFStringRef version_cf = base::apple::CFCast( - TryCFDictionaryGetValue(dictionary, _kCFSystemVersionProductVersionKey)); + CFStringRef version_cf = + base::apple::CFCast(TryCFDictionaryGetValue( + dictionary.get(), _kCFSystemVersionProductVersionKey)); std::string version; if (!version_cf) { LOG(ERROR) << "version_cf not found"; @@ -264,8 +265,9 @@ bool MacOSVersionComponents(int* major, } } - CFStringRef build_cf = base::apple::CFCast( - TryCFDictionaryGetValue(dictionary, _kCFSystemVersionBuildVersionKey)); + CFStringRef build_cf = + base::apple::CFCast(TryCFDictionaryGetValue( + dictionary.get(), _kCFSystemVersionBuildVersionKey)); if (!build_cf) { LOG(ERROR) << "build_cf not found"; success = false; @@ -273,8 +275,9 @@ bool MacOSVersionComponents(int* major, build->assign(base::SysCFStringRefToUTF8(build_cf)); } - CFStringRef product_cf = base::apple::CFCast( - TryCFDictionaryGetValue(dictionary, _kCFSystemVersionProductNameKey)); + CFStringRef product_cf = + base::apple::CFCast(TryCFDictionaryGetValue( + dictionary.get(), _kCFSystemVersionProductNameKey)); std::string product; if (!product_cf) { LOG(ERROR) << "product_cf not found"; @@ -286,7 +289,7 @@ bool MacOSVersionComponents(int* major, // This key is not required, and in fact is normally not present. CFStringRef extra_cf = base::apple::CFCast(TryCFDictionaryGetValue( - dictionary, _kCFSystemVersionProductVersionExtraKey)); + dictionary.get(), _kCFSystemVersionProductVersionExtraKey)); std::string extra; if (extra_cf) { extra = base::SysCFStringRefToUTF8(extra_cf); @@ -313,8 +316,8 @@ void MacModelAndBoard(std::string* model, std::string* board_id) { IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"))); if (platform_expert) { - model->assign( - IORegistryEntryDataPropertyAsString(platform_expert, CFSTR("model"))); + model->assign(IORegistryEntryDataPropertyAsString(platform_expert.get(), + CFSTR("model"))); #if defined(ARCH_CPU_X86_FAMILY) CFStringRef kBoardProperty = CFSTR("board-id"); #elif defined(ARCH_CPU_ARM64) @@ -324,8 +327,8 @@ void MacModelAndBoard(std::string* model, std::string* board_id) { // alternative. CFStringRef kBoardProperty = CFSTR("target-type"); #endif - board_id->assign( - IORegistryEntryDataPropertyAsString(platform_expert, kBoardProperty)); + board_id->assign(IORegistryEntryDataPropertyAsString(platform_expert.get(), + kBoardProperty)); } else { model->clear(); board_id->clear(); From 4a93d7f4c407fee2168ea23195d0e30fbfc1f90c Mon Sep 17 00:00:00 2001 From: Avi Drissman Date: Fri, 27 Oct 2023 20:06:46 +0000 Subject: [PATCH 066/107] Revert "Add an option to start a Windows client with global hooks disabled." This reverts commit e17518a9e879f63b578db6c184c6bb17f1b13a06. Reason for revert: When trying to roll Crashpad into Chromium, all the new tests in this CL fail; https://crrev.com/c/4984643?checksRunsSelected=win-rel&tab=checks Original change's description: > Add an option to start a Windows client with global hooks disabled. > > Change-Id: I645d6136788ca4ccebfc73005c8c2455dc4b2cee > Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4949671 > Reviewed-by: Mark Mentovai > Commit-Queue: Rich Mckeever Change-Id: I3a41238cf0960899fac19d1e6d0ed0e527dfe13f Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4985124 Reviewed-by: Mark Mentovai Bot-Commit: Rubber Stamper Commit-Queue: Avi Drissman --- client/crashpad_client.h | 16 ---- client/crashpad_client_win.cc | 7 +- client/crashpad_client_win_test.cc | 123 +---------------------------- 3 files changed, 3 insertions(+), 143 deletions(-) diff --git a/client/crashpad_client.h b/client/crashpad_client.h index 23a16ce7..3c966686 100644 --- a/client/crashpad_client.h +++ b/client/crashpad_client.h @@ -486,21 +486,6 @@ class CrashpadClient { #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) || // BUILDFLAG(IS_CHROMEOS) || DOXYGEN -#if BUILDFLAG(IS_WIN) || DOXYGEN - //! \brief Configures this client to not install any process-global hooks, - //! such as an unhandled exception filter or vectored exception handler. - //! - //! This may be useful if this client is being used in the context of an - //! extension library, which only wants to capture crashes in its own code, - //! via catch blocks, and not all crashes in the host process. - //! - //! This method must be called before calling StartHandler(), - //! SetHandlerSocket(), or other methods that install global hooks. - void DisableGlobalHooks() { - disable_global_hooks_ = true; - } -#endif // BUILDFLAG(IS_WIN) || DOXYGEN - #if BUILDFLAG(IS_IOS) || DOXYGEN //! \brief Observation callback invoked each time this object finishes //! processing and attempting to upload on-disk crash reports (whether or @@ -833,7 +818,6 @@ class CrashpadClient { std::wstring ipc_pipe_; ScopedKernelHANDLE handler_start_thread_; ScopedVectoredExceptionRegistration vectored_handler_; - bool disable_global_hooks_; #elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) std::set unhandled_signals_; #endif // BUILDFLAG(IS_APPLE) diff --git a/client/crashpad_client_win.cc b/client/crashpad_client_win.cc index 4cbaf88e..2f02001d 100644 --- a/client/crashpad_client_win.cc +++ b/client/crashpad_client_win.cc @@ -592,8 +592,7 @@ void CommonInProcessInitialization() { } // namespace CrashpadClient::CrashpadClient() - : ipc_pipe_(), handler_start_thread_(), vectored_handler_(), - disable_global_hooks_(false) {} + : ipc_pipe_(), handler_start_thread_(), vectored_handler_() {} CrashpadClient::~CrashpadClient() {} @@ -668,10 +667,6 @@ bool CrashpadClient::StartHandler( } void CrashpadClient::RegisterHandlers() { - if (disable_global_hooks_) { - return; - } - SetUnhandledExceptionFilter(&UnhandledExceptionHandler); // Windows swallows heap corruption failures but we can intercept them with diff --git a/client/crashpad_client_win_test.cc b/client/crashpad_client_win_test.cc index 99c0e204..901cf81f 100644 --- a/client/crashpad_client_win_test.cc +++ b/client/crashpad_client_win_test.cc @@ -17,7 +17,6 @@ #include #include "base/files/file_path.h" -#include "client/crash_report_database.h" #include "gtest/gtest.h" #include "test/test_paths.h" #include "test/scoped_temp_dir.h" @@ -30,10 +29,11 @@ namespace crashpad { namespace test { namespace { -void StartAndUseHandler(CrashpadClient& client, const base::FilePath& temp_dir) { +void StartAndUseHandler(const base::FilePath& temp_dir) { base::FilePath handler_path = TestPaths::Executable().DirName().Append( FILE_PATH_LITERAL("crashpad_handler.com")); + CrashpadClient client; ASSERT_TRUE(client.StartHandler(handler_path, temp_dir, base::FilePath(), @@ -45,11 +45,6 @@ void StartAndUseHandler(CrashpadClient& client, const base::FilePath& temp_dir) ASSERT_TRUE(client.WaitForHandlerStart(INFINITE)); } -void StartAndUseHandler(const base::FilePath& temp_dir) { - CrashpadClient client; - StartAndUseHandler(client, temp_dir); -} - class StartWithInvalidHandles final : public WinMultiprocessWithTempDir { public: StartWithInvalidHandles() : WinMultiprocessWithTempDir() {} @@ -197,120 +192,6 @@ TEST(CrashpadClient, HandlerLaunchFailureDumpWithoutCrash) { WinMultiprocess::Run(); } -class NoDumpExpected : public WinMultiprocessWithTempDir { - private: - void WinMultiprocessParentAfterChild(HANDLE child) override { - // Make sure no dump was generated. - std::unique_ptr database( - CrashReportDatabase::Initialize(GetTempDirPath())); - ASSERT_TRUE(database); - - std::vector reports; - ASSERT_EQ(database->GetPendingReports(&reports), - CrashReportDatabase::kNoError); - ASSERT_EQ(reports.size(), 0u); - } -}; - -// Crashing the process under test does not result in a crashed status as an -// exit code in debug builds, so we only verify this behavior in release -// builds. -#if defined(NDEBUG) -class CrashWithDisabledGlobalHooks final : public NoDumpExpected { - public: - CrashWithDisabledGlobalHooks() : NoDumpExpected() {} - ~CrashWithDisabledGlobalHooks() {} - - private: - void WinMultiprocessParent() override { - SetExpectedChildExitCode(STATUS_ACCESS_VIOLATION); - } - - void WinMultiprocessChild() override { - CrashpadClient client; - client.DisableGlobalHooks(); - StartAndUseHandler(client, GetTempDirPath()); - int* bad = nullptr; - *bad = 1; - } -}; - -TEST(CrashpadClient, CrashWithDisabledGlobalHooks) { - WinMultiprocessWithTempDir::Run(); -} -#endif // defined(NDEBUG) - -class DumpAndCrashWithDisabledGlobalHooks final - : public WinMultiprocessWithTempDir { - public: - DumpAndCrashWithDisabledGlobalHooks() : WinMultiprocessWithTempDir() {} - ~DumpAndCrashWithDisabledGlobalHooks() {} - - private: - static constexpr DWORD kExpectedExitCode = 0x1CEB00DA; - - void WinMultiprocessParent() override { - SetExpectedChildExitCode(kExpectedExitCode); - } - - void WinMultiprocessChild() override { - CrashpadClient client; - client.DisableGlobalHooks(); - StartAndUseHandler(client, GetTempDirPath()); - EXCEPTION_RECORD exception_record = {kExpectedExitCode, - EXCEPTION_NONCONTINUABLE}; - CONTEXT context; - CaptureContext(&context); - EXCEPTION_POINTERS exception_pointers = {&exception_record, &context}; - CrashpadClient::DumpAndCrash(&exception_pointers); - } - - void WinMultiprocessParentAfterChild(HANDLE child) override { - // Make sure the dump was generated. - std::unique_ptr database( - CrashReportDatabase::Initialize(GetTempDirPath())); - ASSERT_TRUE(database); - - std::vector reports; - ASSERT_EQ(database->GetPendingReports(&reports), - CrashReportDatabase::kNoError); - ASSERT_EQ(reports.size(), 1u); - - // Delegate the cleanup to the superclass. - WinMultiprocessWithTempDir::WinMultiprocessParentAfterChild(child); - } -}; - -TEST(CrashpadClient, DumpAndCrashWithDisabledGlobalHooks) { - WinMultiprocessWithTempDir::Run(); -} - -#if !defined(ADDRESS_SANITIZER) -class HeapCorruptionWithDisabledGlobalHooks final : public NoDumpExpected { - public: - HeapCorruptionWithDisabledGlobalHooks() : NoDumpExpected() {} - ~HeapCorruptionWithDisabledGlobalHooks() {} - - private: - void WinMultiprocessParent() override { - SetExpectedChildExitCode(STATUS_HEAP_CORRUPTION); - } - - void WinMultiprocessChild() override { - CrashpadClient client; - client.DisableGlobalHooks(); - StartAndUseHandler(client, GetTempDirPath()); - int* bad = reinterpret_cast(1); - delete bad; - } -}; - -TEST(CrashpadClient, HeapCorruptionWithDisabledGlobalHooks) { - WinMultiprocessWithTempDir::Run(); -} - -#endif // !defined(ADDRESS_SANITIZER) - } // namespace } // namespace test } // namespace crashpad From 41f6ad560f41cd43ee989897704457b595483f44 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Fri, 27 Oct 2023 21:26:50 -0400 Subject: [PATCH 067/107] Fix crashpad tests under UBSan These are slightly frustrating. First, when a struct is packed, some of its fields may be underaligned. This is fine for direct access (foo.bar), but if one takes the address if the field, this creates an unaligned pointer. Dereferencing that pointer is then UB. (I'm not sure if creating that pointer is UB.) Crashpad seemingly doesn't do this, but it uses EXPECT_EQ from GTest. EXPECT_EQ seems to internally take pointers to its arguments. I'm guessing it binds them by const reference. This then trips UBSan. To avoid this, we can copy the value into a temporary before passing to EXPECT_EQ. Second, the test to divide by 0 to trigger SIGFPE is undefined behavior. The compiler is not actually obligated to trip SIGFPE. UBSan prints one of its errors instead. Instead, since this file is only built on POSIX anyway, use GCC inline assembly to do the division. That one is well-defined. Finally, casting a string to uint32_t* is undefined both by alignment and by strict aliasing (although Chromium doesn't enable the latter). Instead, type-punning should be done with memcpy. Bug: chromium:1394755 Change-Id: I79108773a04ac26f5189e7b88a0acbf62eb4401d Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4985905 Reviewed-by: Robert Sesek Commit-Queue: David Benjamin --- handler/linux/exception_handler_server_test.cc | 5 ++++- minidump/minidump_misc_info_writer_test.cc | 7 +++++-- snapshot/minidump/process_snapshot_minidump_test.cc | 5 +++-- util/posix/signals_test.cc | 9 ++++++--- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/handler/linux/exception_handler_server_test.cc b/handler/linux/exception_handler_server_test.cc index 40f06e64..e16d93b7 100644 --- a/handler/linux/exception_handler_server_test.cc +++ b/handler/linux/exception_handler_server_test.cc @@ -253,7 +253,10 @@ class ExceptionHandlerServerTest : public testing::TestWithParam { pid_t last_client; ASSERT_TRUE(server_test_->Delegate()->WaitForException( 5.0, &last_client, &last_address)); - EXPECT_EQ(last_address, info.exception_information_address); + // `exception_information_address` is underaligned and `EXPECT_EQ` + // internally takes arguments by reference. Copy it into a temporary + // before comparing to avoid undefined behavior. + EXPECT_EQ(last_address, VMAddress{info.exception_information_address}); EXPECT_EQ(last_client, ChildPID()); } else { CheckedReadFileAtEOF(ReadPipeHandle()); diff --git a/minidump/minidump_misc_info_writer_test.cc b/minidump/minidump_misc_info_writer_test.cc index 970c3338..ff132b90 100644 --- a/minidump/minidump_misc_info_writer_test.cc +++ b/minidump/minidump_misc_info_writer_test.cc @@ -178,8 +178,11 @@ void ExpectMiscInfoEqual( expected_misc_info.XStateData.SizeOfInfo); EXPECT_EQ(observed_misc_info.XStateData.ContextSize, expected_misc_info.XStateData.ContextSize); - EXPECT_EQ(observed_misc_info.XStateData.EnabledFeatures, - expected_misc_info.XStateData.EnabledFeatures); + // `EnabledFeatures` is underaligned and `EXPECT_EQ` internally takes + // arguments by reference. Copy it into a temporary before comparing to avoid + // undefined behavior. + EXPECT_EQ(uint64_t{observed_misc_info.XStateData.EnabledFeatures}, + uint64_t{expected_misc_info.XStateData.EnabledFeatures}); for (size_t feature_index = 0; feature_index < std::size(observed_misc_info.XStateData.Features); ++feature_index) { diff --git a/snapshot/minidump/process_snapshot_minidump_test.cc b/snapshot/minidump/process_snapshot_minidump_test.cc index 00fc3f84..31e304c2 100644 --- a/snapshot/minidump/process_snapshot_minidump_test.cc +++ b/snapshot/minidump/process_snapshot_minidump_test.cc @@ -868,8 +868,9 @@ TEST(ProcessSnapshotMinidump, ThreadsWithNames) { } TEST(ProcessSnapshotMinidump, System) { - const char* cpu_info = "GenuineIntel"; - const uint32_t* cpu_info_bytes = reinterpret_cast(cpu_info); + const char cpu_info[] = "GenuineIntel"; + uint32_t cpu_info_bytes[3]; + memcpy(cpu_info_bytes, cpu_info, sizeof(cpu_info_bytes)); StringFile string_file; MINIDUMP_HEADER header = {}; diff --git a/util/posix/signals_test.cc b/util/posix/signals_test.cc index de8deb22..15c44995 100644 --- a/util/posix/signals_test.cc +++ b/util/posix/signals_test.cc @@ -164,9 +164,12 @@ void CauseSignal(int sig, int code) { * Arm architecture. */ #if defined(ARCH_CPU_X86_FAMILY) - [[maybe_unused]] volatile int a = 42; - volatile int b = 0; - a = a / b; + // Dividing by zero is undefined in C, so the compiler is permitted to + // optimize out the division. Instead, divide using inline assembly. As + // this instruction will trap anyway, we skip declaring any clobbers or + // output registers. + int a = 42, b = 0; + asm volatile("idivl %2" : : "a"(0), "d"(a), "r"(b)); #endif break; } From c5e2b0313cbc4f2d930d061cf31cff9800047a22 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Sat, 28 Oct 2023 11:53:15 -0400 Subject: [PATCH 068/107] Fix UB when saving an StringAnnotation memcpy and memchr on NULL, 0 is UB due to a C language bug. Instead, use the C++ functions, which do not have this bug. Bug: chromium:1394755 Change-Id: I82023aa038c53905f9867c635b26f3b26d9994f5 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4987148 Commit-Queue: David Benjamin Reviewed-by: Robert Sesek --- client/annotation.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/annotation.h b/client/annotation.h index e80e7664..f69b9a43 100644 --- a/client/annotation.h +++ b/client/annotation.h @@ -323,9 +323,11 @@ class StringAnnotation : public Annotation { void Set(base::StringPiece string) { Annotation::ValueSizeType size = std::min(MaxSize, base::saturated_cast(string.size())); - memcpy(value_, string.data(), size); + string = string.substr(0, size); + std::copy(string.begin(), string.end(), value_); // Check for no embedded `NUL` characters. - DCHECK(!memchr(value_, '\0', size)) << "embedded NUL"; + DCHECK(string.find('\0', /*pos=*/0) == base::StringPiece::npos) + << "embedded NUL"; SetSize(size); } From c39206f699f93d4aa371028f746c729081b8eaa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kempe?= Date: Fri, 27 Oct 2023 14:43:48 +0100 Subject: [PATCH 069/107] Provide a way to iterate over a const AnnotationList This CL implements a const iterator to allow for iteration over a const AnnotationList. This way, the annotation list can passed as a const reference in search only situations. Change-Id: I53bd7871f3d914e7e7e627b6b464aa7fa79597f4 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4984053 Reviewed-by: Mark Mentovai Commit-Queue: Andre Kempe --- client/annotation.h | 8 +++ client/annotation_list.cc | 34 +++++++++++- client/annotation_list.h | 26 ++++++++++ client/annotation_list_test.cc | 94 ++++++++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+), 2 deletions(-) diff --git a/client/annotation.h b/client/annotation.h index f69b9a43..a5d14f0d 100644 --- a/client/annotation.h +++ b/client/annotation.h @@ -246,6 +246,14 @@ class Annotation { std::atomic& link_node() { return link_node_; } + Annotation* GetLinkNode(std::memory_order order = std::memory_order_seq_cst) { + return link_node_.load(order); + } + const Annotation* GetLinkNode( + std::memory_order order = std::memory_order_seq_cst) const { + return link_node_.load(order); + } + private: //! \brief Linked list next-node pointer. Accessed only by \sa AnnotationList. //! diff --git a/client/annotation_list.cc b/client/annotation_list.cc index 188cadbd..bcf7ca76 100644 --- a/client/annotation_list.cc +++ b/client/annotation_list.cc @@ -77,7 +77,7 @@ Annotation* AnnotationList::Iterator::operator*() const { AnnotationList::Iterator& AnnotationList::Iterator::operator++() { CHECK_NE(curr_, tail_); - curr_ = curr_->link_node(); + curr_ = curr_->GetLinkNode(); return *this; } @@ -86,12 +86,42 @@ bool AnnotationList::Iterator::operator==( return curr_ == other.curr_; } +AnnotationList::ConstIterator::ConstIterator(const Annotation* head, + const Annotation* tail) + : curr_(head), tail_(tail) {} + +AnnotationList::ConstIterator::~ConstIterator() = default; + +const Annotation* AnnotationList::ConstIterator::operator*() const { + CHECK_NE(curr_, tail_); + return curr_; +} + +AnnotationList::ConstIterator& AnnotationList::ConstIterator::operator++() { + CHECK_NE(curr_, tail_); + curr_ = curr_->GetLinkNode(); + return *this; +} + +bool AnnotationList::ConstIterator::operator==( + const AnnotationList::ConstIterator& other) const { + return curr_ == other.curr_; +} + AnnotationList::Iterator AnnotationList::begin() { - return Iterator(head_.link_node(), tail_pointer_); + return Iterator(head_.GetLinkNode(), tail_pointer_); +} + +AnnotationList::ConstIterator AnnotationList::cbegin() const { + return ConstIterator(head_.GetLinkNode(), tail_pointer_); } AnnotationList::Iterator AnnotationList::end() { return Iterator(&tail_, tail_pointer_); } +AnnotationList::ConstIterator AnnotationList::cend() const { + return ConstIterator(&tail_, tail_pointer_); +} + } // namespace crashpad diff --git a/client/annotation_list.h b/client/annotation_list.h index 10e6e37a..eec7fb4c 100644 --- a/client/annotation_list.h +++ b/client/annotation_list.h @@ -80,11 +80,37 @@ class AnnotationList { // Copy and assign are required. }; + //! \brief An InputIterator for iterating a const AnnotationList. + class ConstIterator { + public: + ~ConstIterator(); + + const Annotation* operator*() const; + ConstIterator& operator++(); + bool operator==(const ConstIterator& other) const; + bool operator!=(const ConstIterator& other) const { + return !(*this == other); + } + + private: + friend class AnnotationList; + ConstIterator(const Annotation* head, const Annotation* tail); + + const Annotation* curr_; + const Annotation* const tail_; + + // Copy and assign are required. + }; + //! \brief Returns an iterator to the first element of the annotation list. Iterator begin(); + ConstIterator begin() const { return cbegin(); } + ConstIterator cbegin() const; //! \brief Returns an iterator past the last element of the annotation list. Iterator end(); + ConstIterator end() const { return cend(); } + ConstIterator cend() const; protected: #if BUILDFLAG(IS_IOS) diff --git a/client/annotation_list_test.cc b/client/annotation_list_test.cc index d9473c54..0ac87ffa 100644 --- a/client/annotation_list_test.cc +++ b/client/annotation_list_test.cc @@ -128,6 +128,100 @@ TEST_F(AnnotationList, DuplicateKeys) { EXPECT_EQ(1u, annotations.size()); } +TEST_F(AnnotationList, IteratorSingleAnnotation) { + ASSERT_EQ(annotations_.begin(), annotations_.end()); + ASSERT_EQ(annotations_.cbegin(), annotations_.cend()); + + one_.Set("1"); + + auto iterator = annotations_.begin(); + auto const_iterator = annotations_.cbegin(); + + ASSERT_NE(iterator, annotations_.end()); + ASSERT_NE(const_iterator, annotations_.cend()); + + EXPECT_EQ(*iterator, &one_); + EXPECT_EQ(*const_iterator, &one_); + + ++iterator; + ++const_iterator; + + EXPECT_EQ(iterator, annotations_.end()); + EXPECT_EQ(const_iterator, annotations_.cend()); +} + +TEST_F(AnnotationList, IteratorMultipleAnnotationsInserted) { + ASSERT_EQ(annotations_.begin(), annotations_.end()); + ASSERT_EQ(annotations_.cbegin(), annotations_.cend()); + + one_.Set("1"); + two_.Set("2"); + + // New annotations are inserted to the beginning of the list. Hence, |two_| + // must be the first annotation, followed by |one_|. + { + auto iterator = annotations_.begin(); + auto const_iterator = annotations_.cbegin(); + + ASSERT_NE(iterator, annotations_.end()); + ASSERT_NE(const_iterator, annotations_.cend()); + + EXPECT_EQ(*iterator, &two_); + EXPECT_EQ(*const_iterator, &two_); + + ++iterator; + ++const_iterator; + + ASSERT_NE(iterator, annotations_.end()); + ASSERT_NE(const_iterator, annotations_.cend()); + + EXPECT_EQ(*iterator, &one_); + EXPECT_EQ(*const_iterator, &one_); + + ++iterator; + ++const_iterator; + + EXPECT_EQ(iterator, annotations_.end()); + EXPECT_EQ(const_iterator, annotations_.cend()); + } +} + +TEST_F(AnnotationList, IteratorMultipleAnnotationsInsertedAndRemoved) { + ASSERT_EQ(annotations_.begin(), annotations_.end()); + ASSERT_EQ(annotations_.cbegin(), annotations_.cend()); + + one_.Set("1"); + two_.Set("2"); + one_.Clear(); + two_.Clear(); + + // Even after clearing, Annotations are still inserted in the list and + // reachable via the iterators. + auto iterator = annotations_.begin(); + auto const_iterator = annotations_.cbegin(); + + ASSERT_NE(iterator, annotations_.end()); + ASSERT_NE(const_iterator, annotations_.cend()); + + EXPECT_EQ(*iterator, &two_); + EXPECT_EQ(*const_iterator, &two_); + + ++iterator; + ++const_iterator; + + ASSERT_NE(iterator, annotations_.end()); + ASSERT_NE(const_iterator, annotations_.cend()); + + EXPECT_EQ(*iterator, &one_); + EXPECT_EQ(*const_iterator, &one_); + + ++iterator; + ++const_iterator; + + EXPECT_EQ(iterator, annotations_.end()); + EXPECT_EQ(const_iterator, annotations_.cend()); +} + class RaceThread : public Thread { public: explicit RaceThread(test::AnnotationList* test) : Thread(), test_(test) {} From 3ba2403a73927815627fde482d19dfb3454a7a5f Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Mon, 30 Oct 2023 15:53:34 -0400 Subject: [PATCH 070/107] ios: Fix leak in iOS NSException preprocessor. Call __cxa_free_exception after __cxa_allocate_exception usage. Change-Id: I0cd5043b945652e6ac28c3bf79486c071d3aa09e Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4990028 Commit-Queue: Justin Cohen Reviewed-by: Mark Mentovai --- client/ios_handler/exception_processor.mm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/client/ios_handler/exception_processor.mm b/client/ios_handler/exception_processor.mm index b61d56c2..470b0e76 100644 --- a/client/ios_handler/exception_processor.mm +++ b/client/ios_handler/exception_processor.mm @@ -324,6 +324,20 @@ bool ModulePathMatchesSinkhole(const char* path, const char* sinkhole) { #endif } +//! \brief Helper to release memory from calls to __cxa_allocate_exception. +class ScopedException { + public: + explicit ScopedException(objc_exception* exception) : exception_(exception) {} + + ScopedException(const ScopedException&) = delete; + ScopedException& operator=(const ScopedException&) = delete; + + ~ScopedException() { __cxxabiv1::__cxa_free_exception(exception_); } + + private: + objc_exception* exception_; // weak +}; + id ObjcExceptionPreprocessor(id exception) { // Some sinkholes don't use objc_exception_rethrow when they should, which // would otherwise prevent the exception_preprocessor from getting called @@ -384,6 +398,7 @@ id ObjcExceptionPreprocessor(id exception) { // From 10.15.0 objc4-779.1/runtime/objc-exception.mm objc_exception_throw. objc_exception* exception_objc = reinterpret_cast( __cxxabiv1::__cxa_allocate_exception(sizeof(objc_exception))); + ScopedException exception_objc_owner(exception_objc); exception_objc->obj = exception; exception_objc->tinfo.vtable = objc_ehtype_vtable + 2; exception_objc->tinfo.name = object_getClassName(exception); From 1675ce7c586c2a3ad3a03dd82e983fd6c188c7fc Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 6 Nov 2023 13:34:26 -0800 Subject: [PATCH 071/107] Add missing base/check.h includes Do not rely on base/logging.h to provide it. Change-Id: I8b7d733bcf66abe9b46eabd3703b7ed549d02db7 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5007844 Commit-Queue: Lei Zhang Reviewed-by: Mark Mentovai --- DEPS | 2 +- client/pthread_create_linux.cc | 1 + handler/mac/exception_handler_server.cc | 1 + handler/win/crashy_test_program.cc | 1 + handler/win/fastfail_test_program.cc | 1 + handler/win/hanging_program.cc | 1 + handler/win/heap_corrupting_program.cc | 1 + test/test_paths.cc | 1 + test/win/win_child_process.cc | 1 + util/file/directory_reader_posix.cc | 1 + util/file/directory_reader_win.cc | 1 + util/posix/process_info_linux.cc | 1 + util/stream/file_output_stream.cc | 1 + util/win/exception_handler_server.cc | 1 + util/win/registration_protocol_win.cc | 1 + util/win/session_end_watcher.cc | 1 + 16 files changed, 16 insertions(+), 1 deletion(-) diff --git a/DEPS b/DEPS index 909ef7dc..aad7bbcb 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - '98bbdbe49f4ac26318f88aa7e84296a3da22f7d8', + 'e508a6010e25ba2619317b45995a30f65d2af9b3', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', diff --git a/client/pthread_create_linux.cc b/client/pthread_create_linux.cc index acbf57d5..86ff8dba 100644 --- a/client/pthread_create_linux.cc +++ b/client/pthread_create_linux.cc @@ -15,6 +15,7 @@ #include #include +#include "base/check.h" #include "base/logging.h" #include "client/crashpad_client.h" #include "util/misc/no_cfi_icall.h" diff --git a/handler/mac/exception_handler_server.cc b/handler/mac/exception_handler_server.cc index 5357c8cd..5c1814c8 100644 --- a/handler/mac/exception_handler_server.cc +++ b/handler/mac/exception_handler_server.cc @@ -17,6 +17,7 @@ #include #include "base/apple/mach_logging.h" +#include "base/check.h" #include "base/logging.h" #include "util/mach/composite_mach_message_server.h" #include "util/mach/mach_extensions.h" diff --git a/handler/win/crashy_test_program.cc b/handler/win/crashy_test_program.cc index 658a2253..0929f337 100644 --- a/handler/win/crashy_test_program.cc +++ b/handler/win/crashy_test_program.cc @@ -25,6 +25,7 @@ #include #include +#include "base/check.h" #include "base/files/file_path.h" #include "base/logging.h" #include "build/build_config.h" diff --git a/handler/win/fastfail_test_program.cc b/handler/win/fastfail_test_program.cc index 346aa68a..f654119f 100644 --- a/handler/win/fastfail_test_program.cc +++ b/handler/win/fastfail_test_program.cc @@ -14,6 +14,7 @@ #include +#include "base/check.h" #include "base/files/file_path.h" #include "base/logging.h" #include "client/crashpad_client.h" diff --git a/handler/win/hanging_program.cc b/handler/win/hanging_program.cc index 2404bf30..72f903f2 100644 --- a/handler/win/hanging_program.cc +++ b/handler/win/hanging_program.cc @@ -17,6 +17,7 @@ #include +#include "base/check.h" #include "base/debug/alias.h" #include "base/logging.h" #include "base/notreached.h" diff --git a/handler/win/heap_corrupting_program.cc b/handler/win/heap_corrupting_program.cc index 6c7c2cd5..8fe62f6e 100644 --- a/handler/win/heap_corrupting_program.cc +++ b/handler/win/heap_corrupting_program.cc @@ -14,6 +14,7 @@ #include +#include "base/check.h" #include "base/files/file_path.h" #include "base/logging.h" #include "client/crashpad_client.h" diff --git a/test/test_paths.cc b/test/test_paths.cc index 1e1c250a..75399ac8 100644 --- a/test/test_paths.cc +++ b/test/test_paths.cc @@ -17,6 +17,7 @@ #include #include +#include "base/check.h" #include "base/logging.h" #include "build/build_config.h" #include "util/misc/paths.h" diff --git a/test/win/win_child_process.cc b/test/win/win_child_process.cc index d1a767c4..d4d9a462 100644 --- a/test/win/win_child_process.cc +++ b/test/win/win_child_process.cc @@ -20,6 +20,7 @@ #include #include +#include "base/check.h" #include "base/logging.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" diff --git a/util/file/directory_reader_posix.cc b/util/file/directory_reader_posix.cc index d046eb11..352991d6 100644 --- a/util/file/directory_reader_posix.cc +++ b/util/file/directory_reader_posix.cc @@ -19,6 +19,7 @@ #include #include +#include "base/check.h" #include "base/logging.h" namespace crashpad { diff --git a/util/file/directory_reader_win.cc b/util/file/directory_reader_win.cc index e1bb38ec..95251183 100644 --- a/util/file/directory_reader_win.cc +++ b/util/file/directory_reader_win.cc @@ -16,6 +16,7 @@ #include +#include "base/check.h" #include "base/logging.h" namespace crashpad { diff --git a/util/posix/process_info_linux.cc b/util/posix/process_info_linux.cc index 27387616..1aca699c 100644 --- a/util/posix/process_info_linux.cc +++ b/util/posix/process_info_linux.cc @@ -16,6 +16,7 @@ #include +#include "base/check.h" #include "base/files/file_path.h" #include "base/logging.h" #include "util/file/delimited_file_reader.h" diff --git a/util/stream/file_output_stream.cc b/util/stream/file_output_stream.cc index 91aed904..a3633f9d 100644 --- a/util/stream/file_output_stream.cc +++ b/util/stream/file_output_stream.cc @@ -14,6 +14,7 @@ #include "util/stream/file_output_stream.h" +#include "base/check.h" #include "base/logging.h" namespace crashpad { diff --git a/util/win/exception_handler_server.cc b/util/win/exception_handler_server.cc index ba938ec9..e641c7fb 100644 --- a/util/win/exception_handler_server.cc +++ b/util/win/exception_handler_server.cc @@ -21,6 +21,7 @@ #include #include +#include "base/check.h" #include "base/logging.h" #include "base/numerics/safe_conversions.h" #include "base/rand_util.h" diff --git a/util/win/registration_protocol_win.cc b/util/win/registration_protocol_win.cc index d71c5603..95111f9c 100644 --- a/util/win/registration_protocol_win.cc +++ b/util/win/registration_protocol_win.cc @@ -21,6 +21,7 @@ #include +#include "base/check.h" #include "base/logging.h" #include "util/win/exception_handler_server.h" #include "util/win/loader_lock.h" diff --git a/util/win/session_end_watcher.cc b/util/win/session_end_watcher.cc index d685a995..ead6b7fc 100644 --- a/util/win/session_end_watcher.cc +++ b/util/win/session_end_watcher.cc @@ -14,6 +14,7 @@ #include "util/win/session_end_watcher.h" +#include "base/check.h" #include "base/logging.h" #include "base/scoped_generic.h" #include "util/win/scoped_set_event.h" From 573918571f30de8e58e2fbfa2ffbc809f116323c Mon Sep 17 00:00:00 2001 From: Peter Kasting Date: Mon, 6 Nov 2023 18:22:47 -0800 Subject: [PATCH 072/107] Roll crashpad/third_party/mini_chromium/mini_chromium/ e508a6010..450b10118 (1 commit) https://chromium.googlesource.com/chromium/mini_chromium/+log/e508a6010e25..450b101187b5 $ git log e508a6010..450b10118 --date=short --no-merges --format='%ad %ae %s' 2023-11-06 pkasting Rename WCHAR_T_IS_UTF* to WCHAR_T_IS_*BIT Created with: roll-dep crashpad/third_party/mini_chromium/mini_chromium Change-Id: Id39911a5dbd1275199400848428ab024bb62cf2a Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5008818 Reviewed-by: Mark Mentovai Commit-Queue: Peter Kasting --- DEPS | 2 +- minidump/minidump_misc_info_writer.h | 2 +- snapshot/minidump/process_snapshot_minidump.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DEPS b/DEPS index aad7bbcb..4b448d61 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - 'e508a6010e25ba2619317b45995a30f65d2af9b3', + '450b101187b5311317dec2981303f60a3a0760fb', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', diff --git a/minidump/minidump_misc_info_writer.h b/minidump/minidump_misc_info_writer.h index d355433d..6e3bb45a 100644 --- a/minidump/minidump_misc_info_writer.h +++ b/minidump/minidump_misc_info_writer.h @@ -145,7 +145,7 @@ class MinidumpMiscInfoWriter final : public internal::MinidumpStreamWriter { //! \brief Conversion functions from a native UTF16 C-string to a char16_t //! C-string. No-op where the native UTF16 string is std::u16string. -#if defined(WCHAR_T_IS_UTF16) || DOXYGEN +#if defined(WCHAR_T_IS_16_BIT) || DOXYGEN inline const char16_t* AsU16CStr(const wchar_t* str) { return reinterpret_cast(str); } diff --git a/snapshot/minidump/process_snapshot_minidump.cc b/snapshot/minidump/process_snapshot_minidump.cc index e88a2646..03f32171 100644 --- a/snapshot/minidump/process_snapshot_minidump.cc +++ b/snapshot/minidump/process_snapshot_minidump.cc @@ -346,7 +346,7 @@ bool ProcessSnapshotMinidump::InitializeMiscInfo() { switch (stream_it->second->DataSize) { case sizeof(MINIDUMP_MISC_INFO_5): case sizeof(MINIDUMP_MISC_INFO_4): -#if defined(WCHAR_T_IS_UTF16) +#if defined(WCHAR_T_IS_16_BIT) full_version_ = base::WideToUTF8(info.BuildString); #else full_version_ = base::UTF16ToUTF8(info.BuildString); From 5613499bbda780dfa663344ea6253844e82c88c4 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 7 Nov 2023 12:48:40 -0800 Subject: [PATCH 073/107] Replace base::WStringPiece with std::string_view Bug: chromium:691162 Change-Id: I2d34bcfd3b97d59d1811183d62b893b875b08bb4 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5010942 Reviewed-by: Mark Mentovai Commit-Queue: Lei Zhang --- DEPS | 2 +- client/crashpad_client_win.cc | 3 ++- snapshot/win/process_snapshot_win.cc | 3 ++- util/misc/uuid.cc | 3 ++- util/misc/uuid.h | 3 ++- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/DEPS b/DEPS index 4b448d61..80c1aabf 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - '450b101187b5311317dec2981303f60a3a0760fb', + '9e21183c1ea369398d6f6ddd302c8db580bd19c4', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', diff --git a/client/crashpad_client_win.cc b/client/crashpad_client_win.cc index 2f02001d..c10df2b0 100644 --- a/client/crashpad_client_win.cc +++ b/client/crashpad_client_win.cc @@ -23,6 +23,7 @@ #include #include +#include #include "base/atomicops.h" #include "base/check_op.h" @@ -517,7 +518,7 @@ bool StartHandlerProcess( // invalid command line where the first argument needed by rundll32 is not in // the correct format as required in: // https://support.microsoft.com/en-ca/help/164787/info-windows-rundll-and-rundll32-interface - const base::WStringPiece kRunDll32Exe(L"rundll32.exe"); + const std::wstring_view kRunDll32Exe(L"rundll32.exe"); bool is_embedded_in_dll = false; if (data->handler.value().size() >= kRunDll32Exe.size() && _wcsicmp(data->handler.value() diff --git a/snapshot/win/process_snapshot_win.cc b/snapshot/win/process_snapshot_win.cc index 9d599014..6c06165f 100644 --- a/snapshot/win/process_snapshot_win.cc +++ b/snapshot/win/process_snapshot_win.cc @@ -19,6 +19,7 @@ #include #include +#include #include #include "base/logging.h" @@ -329,7 +330,7 @@ void ProcessSnapshotWin::InitializeUnloadedModules() { uet.SizeOfImage, uet.CheckSum, uet.TimeDateStamp, - base::WideToUTF8(base::WStringPiece( + base::WideToUTF8(std::wstring_view( uet.ImageName, wcsnlen(uet.ImageName, std::size(uet.ImageName)))))); } diff --git a/util/misc/uuid.cc b/util/misc/uuid.cc index a3c33f4f..15870709 100644 --- a/util/misc/uuid.cc +++ b/util/misc/uuid.cc @@ -23,6 +23,7 @@ #include #include +#include #include #include "base/rand_util.h" @@ -89,7 +90,7 @@ bool UUID::InitializeFromString(const base::StringPiece& string) { } #if BUILDFLAG(IS_WIN) -bool UUID::InitializeFromString(const base::WStringPiece& string) { +bool UUID::InitializeFromString(const std::wstring_view& string) { return InitializeFromString(base::WideToUTF8(string)); } #endif diff --git a/util/misc/uuid.h b/util/misc/uuid.h index be005aaf..3e401ab0 100644 --- a/util/misc/uuid.h +++ b/util/misc/uuid.h @@ -18,6 +18,7 @@ #include #include +#include #include "base/strings/string_piece.h" #include "build/build_config.h" @@ -64,7 +65,7 @@ struct UUID { //! parsed, with the object state untouched. bool InitializeFromString(const base::StringPiece& string); #if BUILDFLAG(IS_WIN) || DOXYGEN - bool InitializeFromString(const base::WStringPiece& string); + bool InitializeFromString(const std::wstring_view& string); #endif // BUILDFLAG(IS_WIN) //! \brief Initializes the %UUID using a standard system facility to generate From 5fc60aeb3b57824b607488fadfd2d5b99f24984d Mon Sep 17 00:00:00 2001 From: Daniel Cheng Date: Sat, 2 Dec 2023 14:38:59 -0800 Subject: [PATCH 074/107] Use googletest flag macros to access googletest flags. The implementation details of flags can change; fixing this proactively makes it easier to roll googletest in chromium. Bug: chromium:1409870 Change-Id: Ib27a922a5b3147386a36f98b42e60950e2215190 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5081703 Commit-Queue: Daniel Cheng Reviewed-by: Robert Sesek --- test/multiprocess_posix_test.cc | 2 +- test/scoped_guarded_page_test.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/multiprocess_posix_test.cc b/test/multiprocess_posix_test.cc index c7015b85..02bdb7b2 100644 --- a/test/multiprocess_posix_test.cc +++ b/test/multiprocess_posix_test.cc @@ -157,7 +157,7 @@ class TestMultiprocessClosePipe final : public Multiprocess { who_closes_(who_closes), what_closes_(what_closes) { // Fails under "threadsafe" mode on macOS 10.11. - testing::GTEST_FLAG(death_test_style) = "fast"; + GTEST_FLAG_SET(death_test_style, "fast"); } TestMultiprocessClosePipe(const TestMultiprocessClosePipe&) = delete; diff --git a/test/scoped_guarded_page_test.cc b/test/scoped_guarded_page_test.cc index 2be2d51b..d8fc6749 100644 --- a/test/scoped_guarded_page_test.cc +++ b/test/scoped_guarded_page_test.cc @@ -23,7 +23,7 @@ namespace test { namespace { TEST(ScopedGuardedPage, BasicFunctionality) { - ::testing::FLAGS_gtest_death_test_style = "threadsafe"; + GTEST_FLAG_SET(death_test_style, "threadsafe"); ScopedGuardedPage page; char* address = (char*)page.Pointer(); From 7049d966b5b24bcd4ce0a27312a366592019f1e8 Mon Sep 17 00:00:00 2001 From: Avi Drissman Date: Fri, 8 Dec 2023 16:12:43 -0500 Subject: [PATCH 075/107] Fix improper use of bit_cast bit_cast should never be used on pointers, as it doesn't avoid UB and can lose qualifiers. Fortunately, the only use of bit_cast on a pointer was to cast nullptr into a function pointer, and because nullptr will implicitly behave as any kind of pointer, that cast isn't needed. Bug: none Change-Id: I3ad79b36b7fb5ab53d4b4b6dfc82dea883ec8b53 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5106728 Reviewed-by: Mark Mentovai Commit-Queue: Avi Drissman --- client/ios_handler/exception_processor.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ios_handler/exception_processor.mm b/client/ios_handler/exception_processor.mm index 470b0e76..f68963a0 100644 --- a/client/ios_handler/exception_processor.mm +++ b/client/ios_handler/exception_processor.mm @@ -552,7 +552,7 @@ id ObjcExceptionPreprocessor(id exception) { LoggingUnwStep(&cursor) > 0 && unw_get_proc_info(&cursor, &caller_frame_info) == UNW_ESUCCESS) { auto uiwindowimp_lambda = [](IMP* max) { - IMP min = *max = bit_cast(nullptr); + IMP min = *max = nullptr; unsigned int method_count = 0; std::unique_ptr method_list( class_copyMethodList(NSClassFromString(@"UIWindow"), From 337b4f7971876b2d233f2401ef25a9f4b96ff217 Mon Sep 17 00:00:00 2001 From: Ben Hamilton Date: Tue, 12 Dec 2023 10:54:51 -0700 Subject: [PATCH 076/107] [mac] mach_absolute_time() -> clock_gettime_nsec_np(CLOCK_UPTIME_RAW) https://developer.apple.com/documentation/kernel/1462446-mach_absolute_time > Prefer to use the equivalent clock_gettime_nsec_np(CLOCK_UPTIME_RAW) in nanoseconds. The two are equivalent: https://github.com/apple-oss-distributions/Libc/blob/c5a3293354e22262702a3add5b2dfc9bb0b93b85/gen/clock_gettime.c#L118 Change-Id: I1c7a08d821d1840b74fc5eaa0e9ceca2ade5bbfc Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5085307 Commit-Queue: Ben Hamilton Reviewed-by: Justin Cohen Reviewed-by: Mark Mentovai --- util/misc/clock_mac.cc | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/util/misc/clock_mac.cc b/util/misc/clock_mac.cc index 81e53170..2b4dccd0 100644 --- a/util/misc/clock_mac.cc +++ b/util/misc/clock_mac.cc @@ -14,32 +14,12 @@ #include "util/misc/clock.h" -#include - -#include "base/apple/mach_logging.h" - -namespace { - -mach_timebase_info_data_t* TimebaseInternal() { - mach_timebase_info_data_t* timebase_info = new mach_timebase_info_data_t; - kern_return_t kr = mach_timebase_info(timebase_info); - MACH_CHECK(kr == KERN_SUCCESS, kr) << "mach_timebase_info"; - return timebase_info; -} - -mach_timebase_info_data_t* Timebase() { - static mach_timebase_info_data_t* timebase_info = TimebaseInternal(); - return timebase_info; -} - -} // namespace +#include namespace crashpad { uint64_t ClockMonotonicNanoseconds() { - uint64_t absolute_time = mach_absolute_time(); - mach_timebase_info_data_t* timebase_info = Timebase(); - return absolute_time * timebase_info->numer / timebase_info->denom; + return clock_gettime_nsec_np(CLOCK_UPTIME_RAW); } } // namespace crashpad From 9f896f2581c076ec028935b8d9703551eb73a796 Mon Sep 17 00:00:00 2001 From: Avi Drissman Date: Tue, 12 Dec 2023 17:10:54 -0500 Subject: [PATCH 077/107] Qualify bit_cast with base:: The real Chromium base/bit_cast.h is in the base namespace. mini_chromium's version was just changed to be in the base namespace as well. Roll to the latest mini_chromium and scope all calls to bit_cast. Bug: chromium:1506769 Change-Id: I7b25ee512f67694ef6ed3d0250e4f6a6db151eb3 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5116880 Reviewed-by: Mark Mentovai Commit-Queue: Avi Drissman --- DEPS | 2 +- client/ios_handler/exception_processor.mm | 1 - snapshot/linux/exception_snapshot_linux_test.cc | 7 ++++--- util/linux/auxiliary_vector_test.cc | 8 ++++---- util/linux/memory_map.cc | 1 - util/misc/reinterpret_bytes_test.cc | 12 ++++++------ util/numeric/int128_test.cc | 2 +- 7 files changed, 16 insertions(+), 17 deletions(-) diff --git a/DEPS b/DEPS index 80c1aabf..9559f70a 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - '9e21183c1ea369398d6f6ddd302c8db580bd19c4', + 'ac3e7323953425b2b48af2536f5a6f778dcd0f4c', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', diff --git a/client/ios_handler/exception_processor.mm b/client/ios_handler/exception_processor.mm index f68963a0..0268b3a1 100644 --- a/client/ios_handler/exception_processor.mm +++ b/client/ios_handler/exception_processor.mm @@ -43,7 +43,6 @@ #include #include -#include "base/bit_cast.h" #include "base/format_macros.h" #include "base/logging.h" #include "base/memory/free_deleter.h" diff --git a/snapshot/linux/exception_snapshot_linux_test.cc b/snapshot/linux/exception_snapshot_linux_test.cc index 94f45f1e..b351ccaa 100644 --- a/snapshot/linux/exception_snapshot_linux_test.cc +++ b/snapshot/linux/exception_snapshot_linux_test.cc @@ -66,8 +66,9 @@ void InitializeContext(NativeCPUContext* context) { void ExpectContext(const CPUContext& actual, const NativeCPUContext& expected) { EXPECT_EQ(actual.architecture, kCPUArchitectureX86); - EXPECT_EQ(actual.x86->eax, - bit_cast(expected.ucontext.uc_mcontext.gregs[REG_EAX])); + EXPECT_EQ( + actual.x86->eax, + base::bit_cast(expected.ucontext.uc_mcontext.gregs[REG_EAX])); for (unsigned int byte_offset = 0; byte_offset < sizeof(actual.x86->fxsave); ++byte_offset) { SCOPED_TRACE(base::StringPrintf("byte offset = %u\n", byte_offset)); @@ -87,7 +88,7 @@ void InitializeContext(NativeCPUContext* context) { void ExpectContext(const CPUContext& actual, const NativeCPUContext& expected) { EXPECT_EQ(actual.architecture, kCPUArchitectureX86_64); EXPECT_EQ(actual.x86_64->rax, - bit_cast(expected.uc_mcontext.gregs[REG_RAX])); + base::bit_cast(expected.uc_mcontext.gregs[REG_RAX])); for (unsigned int byte_offset = 0; byte_offset < sizeof(actual.x86_64->fxsave); ++byte_offset) { diff --git a/util/linux/auxiliary_vector_test.cc b/util/linux/auxiliary_vector_test.cc index 0c97781f..f171ef84 100644 --- a/util/linux/auxiliary_vector_test.cc +++ b/util/linux/auxiliary_vector_test.cc @@ -187,13 +187,13 @@ TEST(AuxiliaryVector, SignedBit) { constexpr uint64_t type = 0x0000000012345678; constexpr int32_t neg1_32 = -1; - aux.Insert(type, bit_cast(neg1_32)); + aux.Insert(type, base::bit_cast(neg1_32)); int32_t outval32s; ASSERT_TRUE(aux.GetValue(type, &outval32s)); EXPECT_EQ(outval32s, neg1_32); constexpr int32_t int32_max = std::numeric_limits::max(); - aux.Insert(type, bit_cast(int32_max)); + aux.Insert(type, base::bit_cast(int32_max)); ASSERT_TRUE(aux.GetValue(type, &outval32s)); EXPECT_EQ(outval32s, int32_max); @@ -204,13 +204,13 @@ TEST(AuxiliaryVector, SignedBit) { EXPECT_EQ(outval32u, uint32_max); constexpr int64_t neg1_64 = -1; - aux.Insert(type, bit_cast(neg1_64)); + aux.Insert(type, base::bit_cast(neg1_64)); int64_t outval64s; ASSERT_TRUE(aux.GetValue(type, &outval64s)); EXPECT_EQ(outval64s, neg1_64); constexpr int64_t int64_max = std::numeric_limits::max(); - aux.Insert(type, bit_cast(int64_max)); + aux.Insert(type, base::bit_cast(int64_max)); ASSERT_TRUE(aux.GetValue(type, &outval64s)); EXPECT_EQ(outval64s, int64_max); diff --git a/util/linux/memory_map.cc b/util/linux/memory_map.cc index 58de835e..58383573 100644 --- a/util/linux/memory_map.cc +++ b/util/linux/memory_map.cc @@ -18,7 +18,6 @@ #include #include -#include "base/bit_cast.h" #include "base/check_op.h" #include "base/files/file_path.h" #include "base/logging.h" diff --git a/util/misc/reinterpret_bytes_test.cc b/util/misc/reinterpret_bytes_test.cc index ba72bc52..80bb979b 100644 --- a/util/misc/reinterpret_bytes_test.cc +++ b/util/misc/reinterpret_bytes_test.cc @@ -75,27 +75,27 @@ TEST(ReinterpretBytes, ToSigned) { ExpectReinterpret(from64, &to64, static_cast(0)); to32 = -1; - from64 = bit_cast(to32); + from64 = base::bit_cast(to32); ExpectReinterpret(from64, &to32, to32); to32 = std::numeric_limits::max(); - from64 = bit_cast(to32); + from64 = base::bit_cast(to32); ExpectReinterpret(from64, &to32, to32); to32 = std::numeric_limits::min(); - from64 = bit_cast(to32); + from64 = base::bit_cast(to32); ExpectReinterpret(from64, &to32, to32); to64 = -1; - from64 = bit_cast(to64); + from64 = base::bit_cast(to64); ExpectReinterpret(from64, &to64, to64); to64 = std::numeric_limits::max(); - from64 = bit_cast(to64); + from64 = base::bit_cast(to64); ExpectReinterpret(from64, &to64, to64); to64 = std::numeric_limits::min(); - from64 = bit_cast(to64); + from64 = base::bit_cast(to64); ExpectReinterpret(from64, &to64, to64); } diff --git a/util/numeric/int128_test.cc b/util/numeric/int128_test.cc index 2166c9a4..5bc9e415 100644 --- a/util/numeric/int128_test.cc +++ b/util/numeric/int128_test.cc @@ -33,7 +33,7 @@ TEST(Int128, UInt128) { uint128_struct uint128; static_assert(sizeof(uint128) == sizeof(kBytes), "sizes must be equal"); - uint128 = bit_cast(kBytes); + uint128 = base::bit_cast(kBytes); EXPECT_EQ(uint128.lo, 0x0706050403020100u); EXPECT_EQ(uint128.hi, 0x0f0e0d0c0b0a0908u); From 3a20cc244707120a0595efa7b8c6a4c644aee570 Mon Sep 17 00:00:00 2001 From: Ben Hamilton Date: Fri, 15 Dec 2023 14:04:51 -0700 Subject: [PATCH 078/107] [ios] Add arm64e support to in_process_intermediate_dump_handler Change-Id: Ifc373d313db71872cc0fd7706da2bdc07cf4ba1b Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5126940 Reviewed-by: Justin Cohen Commit-Queue: Ben Hamilton --- client/ios_handler/in_process_intermediate_dump_handler.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ios_handler/in_process_intermediate_dump_handler.cc b/client/ios_handler/in_process_intermediate_dump_handler.cc index a7ac5dae..1e46ddb4 100644 --- a/client/ios_handler/in_process_intermediate_dump_handler.cc +++ b/client/ios_handler/in_process_intermediate_dump_handler.cc @@ -446,7 +446,7 @@ void CaptureMemoryPointedToByThreadState(IOSIntermediateDumpWriter* writer, MaybeCaptureMemoryAround(writer, thread_state.__r15); MaybeCaptureMemoryAround(writer, thread_state.__rip); #elif defined(ARCH_CPU_ARM_FAMILY) - MaybeCaptureMemoryAround(writer, thread_state.__pc); + MaybeCaptureMemoryAround(writer, arm_thread_state64_get_pc(thread_state)); for (size_t i = 0; i < std::size(thread_state.__x); ++i) { MaybeCaptureMemoryAround(writer, thread_state.__x[i]); } @@ -870,7 +870,7 @@ void InProcessIntermediateDumpHandler::WriteThreadInfo( #if defined(ARCH_CPU_X86_64) vm_address_t stack_pointer = thread_state.__rsp; #elif defined(ARCH_CPU_ARM64) - vm_address_t stack_pointer = thread_state.__sp; + vm_address_t stack_pointer = arm_thread_state64_get_sp(thread_state); #endif vm_size_t stack_region_size; From 2905784a7dec11663a50ae575f785aab64c71517 Mon Sep 17 00:00:00 2001 From: David Fang Date: Sat, 6 Jan 2024 00:04:32 +0000 Subject: [PATCH 079/107] [build] Re-enable action tracing Avoid unconditionally running mig in incremental builds, and causing un-necessary re-build of downstream targets. Bug: b/42147841 Bug: b/42084680 Change-Id: I961189870aec8f0b1a1ced22105730218664e109 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5171755 Reviewed-by: Mark Mentovai Commit-Queue: David Fang --- util/BUILD.gn | 6 ------ 1 file changed, 6 deletions(-) diff --git a/util/BUILD.gn b/util/BUILD.gn index 7e06fcda..93b9d544 100644 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -33,12 +33,6 @@ if (crashpad_is_apple) { "mach/mig_gen.py", ] - if (crashpad_is_in_fuchsia) { - # TODO(https://fxbug.dev/68780): Remove suppression when fixed. - hermetic_deps = false - all_outputs_fresh = false - } - if (crashpad_is_mac) { sources = [ "$sysroot/usr/include/mach/exc.defs", From bbb721fd5bf791b887e730a69923a7495fc7490d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Bostr=C3=B6m?= Date: Wed, 10 Jan 2024 10:23:07 -0800 Subject: [PATCH 080/107] Roll crashpad/third_party/mini_chromium/mini_chromium/ ac3e73239..cc2ae8eb0 (1 commit) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://chromium.googlesource.com/chromium/mini_chromium/+log/ac3e73239534..cc2ae8eb01d0 $ git log ac3e73239..cc2ae8eb0 --date=short --no-merges --format='%ad %ae %s' 2024-01-10 pbos Add Flush() method to LogMessage Created with: roll-dep crashpad/third_party/mini_chromium/mini_chromium Bug: chromium:1409729 Change-Id: I59b4c9fc9701f3a504b89f396de9da49b333712f Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5185844 Commit-Queue: Peter Boström Reviewed-by: Mark Mentovai --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index 9559f70a..792528e9 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - 'ac3e7323953425b2b48af2536f5a6f778dcd0f4c', + 'cc2ae8eb01d045dd4bec4132887a1d92fd91ea5f', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', From 65f2a2bcfee456c91dd107924211120ace92ba37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Bostr=C3=B6m?= Date: Wed, 10 Jan 2024 10:59:01 -0800 Subject: [PATCH 081/107] Roll crashpad/third_party/mini_chromium/mini_chromium/ cc2ae8eb0..1e64ecb51 (1 commit) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://chromium.googlesource.com/chromium/mini_chromium/+log/cc2ae8eb01d0..1e64ecb51edf $ git log cc2ae8eb0..1e64ecb51 --date=short --no-merges --format='%ad %ae %s' 2024-01-10 pbos Make ~LogMessage virtual Created with: roll-dep crashpad/third_party/mini_chromium/mini_chromium Bug: chromium:1409729 Change-Id: Ib0011b85c35c781ea35e0d399cccb81b54916ca4 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5186000 Commit-Queue: Peter Boström Reviewed-by: Mark Mentovai --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index 792528e9..214ad881 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - 'cc2ae8eb01d045dd4bec4132887a1d92fd91ea5f', + '1e64ecb51edfb6724efe571a2c56d32c73c8fa29', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', From 4426ed99917eee51fb1f6b63b235c1a21bdb5f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Bostr=C3=B6m?= Date: Wed, 10 Jan 2024 12:42:55 -0800 Subject: [PATCH 082/107] Roll crashpad/third_party/mini_chromium/mini_chromium/ 1e64ecb51..c7fccaa8e (1 commit) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://chromium.googlesource.com/chromium/mini_chromium/+log/1e64ecb51edf..c7fccaa8ec14 $ git log 1e64ecb51..c7fccaa8e --date=short --no-merges --format='%ad %ae %s' 2024-01-10 pbos Implement base::ImmediateCrash() Created with: roll-dep crashpad/third_party/mini_chromium/mini_chromium Bug: chromium:1409729 Change-Id: Iaa4f4d81027cb0ddafe85bab8d186949eb7f852e Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5186004 Reviewed-by: Mark Mentovai Commit-Queue: Peter Boström --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index 214ad881..9dc4cc6f 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - '1e64ecb51edfb6724efe571a2c56d32c73c8fa29', + 'c7fccaa8ec14ea3a3f0e54d7f62d7945be709c07', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', From d256de317164c0eb362bdd9cbb4d259fe6d086f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Bostr=C3=B6m?= Date: Wed, 10 Jan 2024 15:14:32 -0800 Subject: [PATCH 083/107] Roll crashpad/third_party/mini_chromium/mini_chromium/ c7fccaa8e..203a01130 (1 commit) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://chromium.googlesource.com/chromium/mini_chromium/+log/c7fccaa8ec14..203a01130fac $ git log c7fccaa8e..203a01130 --date=short --no-merges --format='%ad %ae %s' 2024-01-10 pbos Fix base::ImmediateCrash() IWYU Created with: roll-dep crashpad/third_party/mini_chromium/mini_chromium Bug: chromium:1409729 Change-Id: Ic9fee112a48b66c92b8446270280d5f2a3d0ef59 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5187485 Reviewed-by: Mark Mentovai Commit-Queue: Peter Boström --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index 9dc4cc6f..f1c8b39a 100644 --- a/DEPS +++ b/DEPS @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - 'c7fccaa8ec14ea3a3f0e54d7f62d7945be709c07', + '203a01130fac64bfdcc8cab2e1798c7b2c0619bf', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', From 98d0d86e76c30965c1d353b9412c60921dce90e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Bostr=C3=B6m?= Date: Thu, 11 Jan 2024 07:53:54 -0800 Subject: [PATCH 084/107] Add [[noreturn]] version of NtstatusLogMessage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will be used by base/logging.h in chromium to make sure that LOG(FATAL) variants never return and are properly understood as [[noreturn]] by the compiler. Once that's landed in chromium it'll be up/downstreamed into mini_chromium as well. Bug: chromium:1409729 Change-Id: I75340643fe075475f997bbc45250fa10df63c9fa Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5185996 Reviewed-by: Mark Mentovai Commit-Queue: Peter Boström --- util/win/ntstatus_logging.cc | 19 +++++++++++++++++++ util/win/ntstatus_logging.h | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/util/win/ntstatus_logging.cc b/util/win/ntstatus_logging.cc index a1a9e371..f6c90cca 100644 --- a/util/win/ntstatus_logging.cc +++ b/util/win/ntstatus_logging.cc @@ -17,6 +17,7 @@ #include #include +#include "base/immediate_crash.h" #include "base/strings/stringprintf.h" namespace { @@ -68,8 +69,26 @@ NtstatusLogMessage::NtstatusLogMessage( } NtstatusLogMessage::~NtstatusLogMessage() { + AppendError(); +} + +void NtstatusLogMessage::AppendError() { stream() << ": " << FormatNtstatus(ntstatus_) << base::StringPrintf(" (0x%08lx)", ntstatus_); } +#if defined(COMPILER_MSVC) +// Ignore warning that ~NtStatusLogMessageFatal never returns. +#pragma warning(push) +#pragma warning(disable : 4722) +#endif // COMPILER_MSVC +NtstatusLogMessageFatal::~NtstatusLogMessageFatal() { + AppendError(); + Flush(); + base::ImmediateCrash(); +} +#if defined(COMPILER_MSVC) +#pragma warning(pop) // C4722 +#endif // COMPILER_MSVC + } // namespace logging diff --git a/util/win/ntstatus_logging.h b/util/win/ntstatus_logging.h index dfcac5d0..183c9067 100644 --- a/util/win/ntstatus_logging.h +++ b/util/win/ntstatus_logging.h @@ -37,10 +37,19 @@ class NtstatusLogMessage : public logging::LogMessage { ~NtstatusLogMessage(); + protected: + void AppendError(); + private: DWORD ntstatus_; }; +class NtstatusLogMessageFatal final : public NtstatusLogMessage { + public: + using NtstatusLogMessage::NtstatusLogMessage; + [[noreturn]] ~NtstatusLogMessageFatal() override; +}; + } // namespace logging #define NTSTATUS_LOG_STREAM(severity, ntstatus) \ From 30b2f4ba38f19b0b4379da721f679621e54d2935 Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Thu, 11 Jan 2024 11:03:41 -0500 Subject: [PATCH 085/107] ios: Add crashpad_uptime_ns crash key to iOS reports. This CL introduces a new crash key 'crashpad_uptime_ns' that records the number of nanoseconds between when Crashpad was initialized and when a snapshot is generated. Crashpad minidumps record the MDRawMiscInfo process_create_time using a sysctl(KERN_PROC).kp_proc.p_starttime. This time is used to display the 'uptime' of a process. However, iOS 15 and later has a feature that 'prewarms' the app to reduce the amount of time the user waits before the app is usable. This mean crashes that may happen immediately on startup would appear to happen minutes or hours after process creation time. While initial implementations of prewarming would include some parts of main, since iOS16 prewarming is complete before main, and therefore before Crashpad is typically initialized. Bug: crashpad:472 Change-Id: Iff960e37ae40121bd5927d319a2767d1cafce846 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5171091 Reviewed-by: Ben Hamilton Reviewed-by: Mark Mentovai Commit-Queue: Justin Cohen --- client/ios_handler/in_process_handler.cc | 5 ++++- .../ios_handler/in_process_intermediate_dump_handler.cc | 8 +++++++- client/ios_handler/in_process_intermediate_dump_handler.h | 6 +++++- .../in_process_intermediate_dump_handler_test.cc | 7 ++++--- snapshot/ios/process_snapshot_ios_intermediate_dump.cc | 3 +++ .../ios/process_snapshot_ios_intermediate_dump_test.cc | 7 +++++++ snapshot/ios/system_snapshot_ios_intermediate_dump.cc | 7 +++++++ snapshot/ios/system_snapshot_ios_intermediate_dump.h | 5 +++++ util/ios/ios_intermediate_dump_format.h | 1 + util/ios/ios_system_data_collector.h | 7 +++++++ util/ios/ios_system_data_collector.mm | 4 +++- 11 files changed, 53 insertions(+), 7 deletions(-) diff --git a/client/ios_handler/in_process_handler.cc b/client/ios_handler/in_process_handler.cc index 668acc66..90fec769 100644 --- a/client/ios_handler/in_process_handler.cc +++ b/client/ios_handler/in_process_handler.cc @@ -468,9 +468,12 @@ InProcessHandler::ScopedReport::ScopedReport( num_frames_(num_frames), rootMap_(writer) { DCHECK(writer); + // Grab the report creation time before writing the report. + uint64_t report_time_nanos = ClockMonotonicNanoseconds(); InProcessIntermediateDumpHandler::WriteHeader(writer); InProcessIntermediateDumpHandler::WriteProcessInfo(writer, annotations); - InProcessIntermediateDumpHandler::WriteSystemInfo(writer, system_data); + InProcessIntermediateDumpHandler::WriteSystemInfo( + writer, system_data, report_time_nanos); } InProcessHandler::ScopedReport::~ScopedReport() { diff --git a/client/ios_handler/in_process_intermediate_dump_handler.cc b/client/ios_handler/in_process_intermediate_dump_handler.cc index 1e46ddb4..e91cc02e 100644 --- a/client/ios_handler/in_process_intermediate_dump_handler.cc +++ b/client/ios_handler/in_process_intermediate_dump_handler.cc @@ -616,7 +616,8 @@ void InProcessIntermediateDumpHandler::WriteProcessInfo( // static void InProcessIntermediateDumpHandler::WriteSystemInfo( IOSIntermediateDumpWriter* writer, - const IOSSystemDataCollector& system_data) { + const IOSSystemDataCollector& system_data, + uint64_t report_time_nanos) { IOSIntermediateDumpWriter::ScopedMap system_map( writer, IntermediateDumpKey::kSystemInfo); @@ -702,6 +703,11 @@ void InProcessIntermediateDumpHandler::WriteSystemInfo( } else { CRASHPAD_RAW_LOG("host_statistics"); } + + uint64_t crashpad_uptime_nanos = + report_time_nanos - system_data.InitializationTime(); + WriteProperty( + writer, IntermediateDumpKey::kCrashpadUptime, &crashpad_uptime_nanos); } // static diff --git a/client/ios_handler/in_process_intermediate_dump_handler.h b/client/ios_handler/in_process_intermediate_dump_handler.h index 83ebff22..1cf9180c 100644 --- a/client/ios_handler/in_process_intermediate_dump_handler.h +++ b/client/ios_handler/in_process_intermediate_dump_handler.h @@ -56,8 +56,12 @@ class InProcessIntermediateDumpHandler final { //! \brief Write SystemSnapshot data to the intermediate dump. //! //! \param[in] writer The dump writer + //! \param[in] system_data An object containing various system data points. + //! \param[in] report_time Report creation time in nanoseconds as returned by + //! ClockMonotonicNanoseconds(). static void WriteSystemInfo(IOSIntermediateDumpWriter* writer, - const IOSSystemDataCollector& system_data); + const IOSSystemDataCollector& system_data, + uint64_t report_time_nanos); //! \brief Write ThreadSnapshot data to the intermediate dump. //! diff --git a/client/ios_handler/in_process_intermediate_dump_handler_test.cc b/client/ios_handler/in_process_intermediate_dump_handler_test.cc index 3b007fcf..90f76d58 100644 --- a/client/ios_handler/in_process_intermediate_dump_handler_test.cc +++ b/client/ios_handler/in_process_intermediate_dump_handler_test.cc @@ -61,8 +61,8 @@ class InProcessIntermediateDumpHandlerTest : public testing::Test { InProcessIntermediateDumpHandler::WriteHeader(writer_.get()); InProcessIntermediateDumpHandler::WriteProcessInfo( writer_.get(), {{"before_dump", "pre"}}); - InProcessIntermediateDumpHandler::WriteSystemInfo(writer_.get(), - system_data_); + InProcessIntermediateDumpHandler::WriteSystemInfo( + writer_.get(), system_data_, ClockMonotonicNanoseconds()); InProcessIntermediateDumpHandler::WriteThreadInfo(writer_.get(), 0, 0); InProcessIntermediateDumpHandler::WriteModuleInfo(writer_.get()); } @@ -161,9 +161,10 @@ TEST_F(InProcessIntermediateDumpHandlerTest, TestAnnotations) { path(), {{"after_dump", "post"}})); auto process_map = process_snapshot.AnnotationsSimpleMap(); - EXPECT_EQ(process_map.size(), 2u); + EXPECT_EQ(process_map.size(), 3u); EXPECT_EQ(process_map["before_dump"], "pre"); EXPECT_EQ(process_map["after_dump"], "post"); + EXPECT_TRUE(process_map.find("crashpad_uptime_ns") != process_map.end()); std::map all_annotations_simple_map; std::vector all_annotations; diff --git a/snapshot/ios/process_snapshot_ios_intermediate_dump.cc b/snapshot/ios/process_snapshot_ios_intermediate_dump.cc index c502b3c0..609ea654 100644 --- a/snapshot/ios/process_snapshot_ios_intermediate_dump.cc +++ b/snapshot/ios/process_snapshot_ios_intermediate_dump.cc @@ -122,6 +122,9 @@ bool ProcessSnapshotIOSIntermediateDump::InitializeWithFileInterface( } system_.Initialize(system_info); + annotations_simple_map_["crashpad_uptime_ns"] = + std::to_string(system_.CrashpadUptime()); + // Threads const IOSIntermediateDumpList* thread_list = GetListFromMap(root_map, Key::kThreads); diff --git a/snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc b/snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc index 6d64b1d0..238c52e9 100644 --- a/snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc +++ b/snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc @@ -160,6 +160,10 @@ class ProcessSnapshotIOSIntermediateDumpTest : public testing::Test { EXPECT_TRUE(writer->AddProperty(Key::kWired, &count)); EXPECT_TRUE(writer->AddProperty(Key::kFree, &count)); } + + uint64_t crashpad_report_time_nanos = 1234567890; + EXPECT_TRUE( + writer->AddProperty(Key::kCrashpadUptime, &crashpad_report_time_nanos)); } void WriteAnnotations(IOSIntermediateDumpWriter* writer, @@ -491,6 +495,9 @@ class ProcessSnapshotIOSIntermediateDumpTest : public testing::Test { ExpectModules( snapshot.Modules(), expect_module_path, expect_long_annotations); ExpectMachException(*snapshot.Exception()); + + auto map = snapshot.AnnotationsSimpleMap(); + EXPECT_EQ(map["crashpad_uptime_ns"], "1234567890"); } void CloseWriter() { EXPECT_TRUE(writer_->Close()); } diff --git a/snapshot/ios/system_snapshot_ios_intermediate_dump.cc b/snapshot/ios/system_snapshot_ios_intermediate_dump.cc index 15f66992..6a9f2c1c 100644 --- a/snapshot/ios/system_snapshot_ios_intermediate_dump.cc +++ b/snapshot/ios/system_snapshot_ios_intermediate_dump.cc @@ -119,6 +119,8 @@ void SystemSnapshotIOSIntermediateDump::Initialize( } } + GetDataValueFromMap(system_data, Key::kCrashpadUptime, &crashpad_uptime_ns_); + INITIALIZATION_STATE_SET_VALID(initialized_); } @@ -249,5 +251,10 @@ uint64_t SystemSnapshotIOSIntermediateDump::AddressMask() const { return address_mask_; } +uint64_t SystemSnapshotIOSIntermediateDump::CrashpadUptime() const { + INITIALIZATION_STATE_DCHECK_VALID(initialized_); + return crashpad_uptime_ns_; +} + } // namespace internal } // namespace crashpad diff --git a/snapshot/ios/system_snapshot_ios_intermediate_dump.h b/snapshot/ios/system_snapshot_ios_intermediate_dump.h index 6cc09ac7..339139b7 100644 --- a/snapshot/ios/system_snapshot_ios_intermediate_dump.h +++ b/snapshot/ios/system_snapshot_ios_intermediate_dump.h @@ -75,6 +75,10 @@ class SystemSnapshotIOSIntermediateDump final : public SystemSnapshot { std::string* daylight_name) const override; uint64_t AddressMask() const override; + //! \brief Returns the number of nanoseconds between Crashpad initialization + //! and snapshot generation. + uint64_t CrashpadUptime() const; + private: std::string os_version_build_; std::string machine_description_; @@ -93,6 +97,7 @@ class SystemSnapshotIOSIntermediateDump final : public SystemSnapshot { std::string standard_name_; std::string daylight_name_; uint64_t address_mask_; + uint64_t crashpad_uptime_ns_; InitializationStateDcheck initialized_; }; diff --git a/util/ios/ios_intermediate_dump_format.h b/util/ios/ios_intermediate_dump_format.h index 9fe7ccf9..2f0a8980 100644 --- a/util/ios/ios_intermediate_dump_format.h +++ b/util/ios/ios_intermediate_dump_format.h @@ -86,6 +86,7 @@ namespace internal { TD(kInactive, 5018) \ TD(kWired, 5019) \ TD(kAddressMask, 5020) \ + TD(kCrashpadUptime, 5021) \ TD(kThreads, 6000) \ TD(kDebugState, 6001) \ TD(kFloatState, 6002) \ diff --git a/util/ios/ios_system_data_collector.h b/util/ios/ios_system_data_collector.h index 2dfc373a..7bef9a2e 100644 --- a/util/ios/ios_system_data_collector.h +++ b/util/ios/ios_system_data_collector.h @@ -44,6 +44,7 @@ class IOSSystemDataCollector { const std::string& DaylightName() const { return daylight_name_; } bool IsApplicationActive() const { return active_; } uint64_t AddressMask() const { return address_mask_; } + uint64_t InitializationTime() const { return initialization_time_ns_; } // Currently unused by minidump. int Orientation() const { return orientation_; } @@ -82,6 +83,12 @@ class IOSSystemDataCollector { std::string daylight_name_; ActiveApplicationCallback active_application_callback_; uint64_t address_mask_; + + // Time in nanoseconds as returned by ClockMonotonicNanoseconds() to store the + // crashpad start time. This clock increments monotonically but pauses while + // the system is asleep. It should not be compared to other system time + // sources. + uint64_t initialization_time_ns_; }; } // namespace internal diff --git a/util/ios/ios_system_data_collector.mm b/util/ios/ios_system_data_collector.mm index 28ede182..2ec6de59 100644 --- a/util/ios/ios_system_data_collector.mm +++ b/util/ios/ios_system_data_collector.mm @@ -26,6 +26,7 @@ #include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" #include "build/build_config.h" +#include "util/misc/clock.h" namespace { @@ -86,7 +87,8 @@ void AddObserver(CFStringRef notification_name, T* observer) { standard_offset_seconds_(0), daylight_offset_seconds_(0), standard_name_(), - daylight_name_() { + daylight_name_(), + initialization_time_ns_(ClockMonotonicNanoseconds()) { NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion]; major_version_ = base::saturated_cast(version.majorVersion); From 5183bef5f384a0cd390c66b42b273535cb27d4fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Bostr=C3=B6m?= Date: Fri, 12 Jan 2024 13:27:15 -0800 Subject: [PATCH 086/107] Remove should-be-dead code after PLOG(FATAL) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will trigger dead-code warnings in chromium once LOG(FATAL) is understood as [[noreturn]], which needs to be fixed in crashpad first. Bug: 1409729 Change-Id: I75cb4d93e648ca9804f1299345e52bb3e2834cd9 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5193351 Reviewed-by: Mark Mentovai Commit-Queue: Peter Boström --- test/win/win_child_process.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/test/win/win_child_process.cc b/test/win/win_child_process.cc index d4d9a462..e31a977d 100644 --- a/test/win/win_child_process.cc +++ b/test/win/win_child_process.cc @@ -44,7 +44,6 @@ bool GetSwitch(const char* switch_name, std::string* value) { ScopedLocalAlloc scoped_args(args); // Take ownership. if (!args) { PLOG(FATAL) << "CommandLineToArgvW"; - return false; } std::string switch_name_with_equals(switch_name); From 305b648e710dc7f2547e8177b28bc8319675dea3 Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Wed, 17 Jan 2024 12:19:52 -0500 Subject: [PATCH 087/107] doc: Upgrade the crashpad-home App Engine app to the go121 flex runtime Change-Id: I0a30b816e2550e7df6d7777c6d27e6104fc2f9fa Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5206711 Reviewed-by: Robert Sesek Commit-Queue: Mark Mentovai --- doc/appengine/README | 35 ++++++++++++++-------- doc/appengine/go.mod | 10 +++++++ doc/appengine/go.sum | 37 ++++++++++++++++++++++++ doc/appengine/src/crashpad-home/app.yaml | 3 +- doc/appengine/src/crashpad-home/main.go | 6 ++-- 5 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 doc/appengine/go.mod create mode 100644 doc/appengine/go.sum diff --git a/doc/appengine/README b/doc/appengine/README index ee0e319a..7beefc61 100644 --- a/doc/appengine/README +++ b/doc/appengine/README @@ -9,26 +9,37 @@ To work on this app, obtain the following packages: instructions were tested with Go 1.14 locally but a Go 1.11 runtime when deployed), but if problems are encountered, it would be wise to use the same version for both local development and AppEngine deployment. - - The Google Cloud SDK from, https://cloud.google.com/sdk/docs. This is - necessary for both local development and for AppEngine deployment. Unpacking - this package produces a google-cloud-sdk directory, whose bin child directory - may be added to $PATH for convenience, although this is not strictly - necessary. + - The Google Cloud SDK (gcloud CLI) from + https://cloud.google.com/sdk/docs/install-sdk. This is necessary for both + local development and for AppEngine deployment. Unpacking this package + produces a google-cloud-sdk directory, whose bin child directory may be + added to $PATH for convenience, although this is not strictly necessary. The commands in this README are expected to be run from the directory containing -it. $GOPATH must also be set to include this directory: - -% export GOPATH="$(go env GOPATH):$(pwd)" +it. To test locally: -% go get -d crashpad-home -% …/google-cloud-sdk/bin/dev_appserver.py src/crashpad-home +% go get -d ./src/crashpad-home +% python3 …/google-cloud-sdk/bin/dev_appserver.py src/crashpad-home + +dev_appserver.py must be invoked using Python 3, but internally will use Python +2, and a Python 2 interpreter must be available in the PATH as python2. Look for the “Starting module "default" running at: http://localhost:8080” line, which tells you the URL of the local running instance of the app. Test -http://localhost:8080/ and http://localhost:8080/doxygen to ensure that they -work. +http://localhost:8080/ to ensure that it works. + +It would be good to test http://localhost:8080/doxygen as well, but it may fail +with HTTP status 500 and the following error returned as the HTTP response body +because memcache seems to not be available in the local dev_appserver +environment: + +service bridge HTTP failed: Post "http://appengine.googleapis.internal:10001/rpc_http": dial tcp: lookup appengine.googleapis.internal: no such host + +The /doxygen URL can be tested in a verison of the app that’s been deployed +before traffic has been migrated to it by visiting the staged deployed version +from the App Engine console. To deploy: diff --git a/doc/appengine/go.mod b/doc/appengine/go.mod new file mode 100644 index 00000000..398c008b --- /dev/null +++ b/doc/appengine/go.mod @@ -0,0 +1,10 @@ +module src/crashpad-home + +go 1.21.6 + +require google.golang.org/appengine/v2 v2.0.5 + +require ( + github.com/golang/protobuf v1.5.2 // indirect + google.golang.org/protobuf v1.30.0 // indirect +) diff --git a/doc/appengine/go.sum b/doc/appengine/go.sum new file mode 100644 index 00000000..987d3692 --- /dev/null +++ b/doc/appengine/go.sum @@ -0,0 +1,37 @@ +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine/v2 v2.0.5 h1:4C+F3Cd3L2nWEfSmFEZDPjQvDwL8T0YCeZBysZifP3k= +google.golang.org/appengine/v2 v2.0.5/go.mod h1:WoEXGoXNfa0mLvaH5sV3ZSGXwVmy8yf7Z1JKf3J3wLI= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= diff --git a/doc/appengine/src/crashpad-home/app.yaml b/doc/appengine/src/crashpad-home/app.yaml index 9af1577b..2966ba0d 100644 --- a/doc/appengine/src/crashpad-home/app.yaml +++ b/doc/appengine/src/crashpad-home/app.yaml @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -runtime: go111 +runtime: go121 +app_engine_apis: true handlers: - url: /.* diff --git a/doc/appengine/src/crashpad-home/main.go b/doc/appengine/src/crashpad-home/main.go index d988af3c..dced1e80 100644 --- a/doc/appengine/src/crashpad-home/main.go +++ b/doc/appengine/src/crashpad-home/main.go @@ -25,9 +25,9 @@ import ( "strings" "time" - "google.golang.org/appengine" - "google.golang.org/appengine/memcache" - "google.golang.org/appengine/urlfetch" + "google.golang.org/appengine/v2" + "google.golang.org/appengine/v2/memcache" + "google.golang.org/appengine/v2/urlfetch" ) func main() { From 22c386d1ac092bdd9e9ea720f68a6f054ea9e6e3 Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Fri, 19 Jan 2024 13:41:26 -0500 Subject: [PATCH 088/107] ios: Allow missing exception thread id from thread list. It's expected that iOS intermediate dumps can be written with missing information, but it's better to try and report as much as possible rather than drop the incomplete minidump. Bug: b/284959148 Change-Id: I04110b576a4ee552814234d559c9ba85db0382f0 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4582167 Commit-Queue: Justin Cohen Reviewed-by: Mark Mentovai --- minidump/minidump_exception_writer.cc | 12 +++++++++--- minidump/minidump_exception_writer.h | 7 ++++++- minidump/minidump_exception_writer_test.cc | 5 ++++- minidump/minidump_file_writer.cc | 12 +++++++++++- ...rocess_snapshot_ios_intermediate_dump_test.cc | 16 ++++++++++++++++ 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/minidump/minidump_exception_writer.cc b/minidump/minidump_exception_writer.cc index 3057c6a7..cd3a139d 100644 --- a/minidump/minidump_exception_writer.cc +++ b/minidump/minidump_exception_writer.cc @@ -34,13 +34,19 @@ MinidumpExceptionWriter::~MinidumpExceptionWriter() { void MinidumpExceptionWriter::InitializeFromSnapshot( const ExceptionSnapshot* exception_snapshot, - const MinidumpThreadIDMap& thread_id_map) { + const MinidumpThreadIDMap& thread_id_map, + bool allow_missing_thread_id_from_map) { DCHECK_EQ(state(), kStateMutable); DCHECK(!context_); auto thread_id_it = thread_id_map.find(exception_snapshot->ThreadID()); - DCHECK(thread_id_it != thread_id_map.end()); - SetThreadID(thread_id_it->second); + bool thread_id_missing = thread_id_it == thread_id_map.end(); + if (allow_missing_thread_id_from_map && thread_id_missing) { + SetThreadID(static_cast(exception_snapshot->ThreadID())); + } else { + DCHECK(!thread_id_missing); + SetThreadID(thread_id_it->second); + } SetExceptionCode(exception_snapshot->Exception()); SetExceptionFlags(exception_snapshot->ExceptionInfo()); diff --git a/minidump/minidump_exception_writer.h b/minidump/minidump_exception_writer.h index 8e6847e9..4c711127 100644 --- a/minidump/minidump_exception_writer.h +++ b/minidump/minidump_exception_writer.h @@ -50,12 +50,17 @@ class MinidumpExceptionWriter final : public internal::MinidumpStreamWriter { //! \param[in] thread_id_map A MinidumpThreadIDMap to be consulted to //! determine the 32-bit minidump thread ID to use for the thread //! identified by \a exception_snapshot. + //! \param[in] allow_missing_thread_id_from_map Whether it is valid + //! for \a exception_snapshot->ThreadID() to be absent from the + //! \a thread_id_map, such as in an incomplete iOS intermediate dump. When + //! false a missing thread id is considered invalid and will DCHECK. //! //! \note Valid in #kStateMutable. No mutator methods may be called before //! this method, and it is not normally necessary to call any mutator //! methods after this method. void InitializeFromSnapshot(const ExceptionSnapshot* exception_snapshot, - const MinidumpThreadIDMap& thread_id_map); + const MinidumpThreadIDMap& thread_id_map, + bool allow_missing_thread_id_from_map); //! \brief Arranges for MINIDUMP_EXCEPTION_STREAM::ThreadContext to point to //! the CPU context to be written by \a context. diff --git a/minidump/minidump_exception_writer_test.cc b/minidump/minidump_exception_writer_test.cc index 9b5e1f9f..06a921ea 100644 --- a/minidump/minidump_exception_writer_test.cc +++ b/minidump/minidump_exception_writer_test.cc @@ -235,7 +235,10 @@ TEST(MinidumpExceptionWriter, InitializeFromSnapshot) { thread_id_map[kThreadID] = expect_exception.ThreadId; auto exception_writer = std::make_unique(); - exception_writer->InitializeFromSnapshot(&exception_snapshot, thread_id_map); + exception_writer->InitializeFromSnapshot( + &exception_snapshot, + thread_id_map, + /*allow_missing_thread_id_from_map=*/false); MinidumpFileWriter minidump_file_writer; ASSERT_TRUE(minidump_file_writer.AddStream(std::move(exception_writer))); diff --git a/minidump/minidump_file_writer.cc b/minidump/minidump_file_writer.cc index 021b1876..35d226bb 100644 --- a/minidump/minidump_file_writer.cc +++ b/minidump/minidump_file_writer.cc @@ -18,6 +18,7 @@ #include "base/check_op.h" #include "base/logging.h" +#include "build/build_config.h" #include "minidump/minidump_crashpad_info_writer.h" #include "minidump/minidump_exception_writer.h" #include "minidump/minidump_handle_writer.h" @@ -115,7 +116,16 @@ void MinidumpFileWriter::InitializeFromSnapshot( const ExceptionSnapshot* exception_snapshot = process_snapshot->Exception(); if (exception_snapshot) { auto exception = std::make_unique(); - exception->InitializeFromSnapshot(exception_snapshot, thread_id_map); +#if BUILDFLAG(IS_IOS) + // It's expected that iOS intermediate dumps can be written with missing + // information, but it's better to try and report as much as possible + // rather than drop the incomplete minidump. + constexpr bool allow_missing_thread_id_from_map = true; +#else + constexpr bool allow_missing_thread_id_from_map = false; +#endif + exception->InitializeFromSnapshot( + exception_snapshot, thread_id_map, allow_missing_thread_id_from_map); add_stream_result = AddStream(std::move(exception)); DCHECK(add_stream_result); } diff --git a/snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc b/snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc index 238c52e9..29d26a83 100644 --- a/snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc +++ b/snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc @@ -775,6 +775,22 @@ TEST_F(ProcessSnapshotIOSIntermediateDumpTest, FuzzTestCases) { EXPECT_TRUE(process_snapshot4.InitializeWithFilePath(fuzz_path, {})); } +TEST_F(ProcessSnapshotIOSIntermediateDumpTest, WriteNoThreads) { + { + IOSIntermediateDumpWriter::ScopedRootMap rootMap(writer()); + uint8_t version = 1; + EXPECT_TRUE(writer()->AddProperty(Key::kVersion, &version)); + WriteSystemInfo(writer()); + WriteProcessInfo(writer()); + WriteMachException(writer()); + } + CloseWriter(); + ProcessSnapshotIOSIntermediateDump process_snapshot; + ASSERT_TRUE(process_snapshot.InitializeWithFilePath(path(), annotations())); + EXPECT_FALSE(IsRegularFile(path())); + EXPECT_TRUE(DumpSnapshot(process_snapshot)); +} + } // namespace } // namespace test } // namespace crashpad From a02e4935bd84712df92e0c4f7b608cbc8bc0f13b Mon Sep 17 00:00:00 2001 From: danakj Date: Thu, 25 Jan 2024 18:02:30 -0500 Subject: [PATCH 089/107] Avoid assuming string_view iterators are char* This assumption is non-portable and prevents Chromium from using bounded iterators in libc++. Bug: chromium: 1519908 Change-Id: Iafe6639ef3bc896d6fa4fb3ceb7ac0b546363017 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5237292 Reviewed-by: Mark Mentovai Commit-Queue: danakj --- util/mach/symbolic_constants_mach.cc | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/util/mach/symbolic_constants_mach.cc b/util/mach/symbolic_constants_mach.cc index eb90bd78..7a591901 100644 --- a/util/mach/symbolic_constants_mach.cc +++ b/util/mach/symbolic_constants_mach.cc @@ -299,14 +299,11 @@ bool StringToExceptionMask(const base::StringPiece& string, size_t pos = -1; do { ++pos; - const char* substring_begin = string.begin() + pos; + const size_t start = pos; pos = string.find('|', pos); - const char* substring_end = (pos == base::StringPiece::npos) - ? string.end() - : (string.begin() + pos); - base::StringPiece substring = string.substr( - substring_begin - string.begin(), substring_end - substring_begin); - + base::StringPiece substring = (pos == base::StringPiece::npos) + ? string.substr(start) + : string.substr(start, pos - start); exception_mask_t temp_mask; if (!StringToExceptionMask(substring, options, &temp_mask)) { return false; From 27b460cc7e5129be94d1e1715b9712ab5bf1120e Mon Sep 17 00:00:00 2001 From: Mitchell Kember Date: Thu, 25 Jan 2024 17:07:53 -0800 Subject: [PATCH 090/107] [fxbug.dev] Migrate bug numbers This changes fxbug.dev/ URLs from Monorail bug numbers to the new Fuchsia Issue Tracker numbers. The migration to the new issue tracker was announced here: https://groups.google.com/a/fuchsia.dev/g/announce/c/GOYfJozEqmk/m/qsGsaJ7UAAAJ Bug: 298074672 Change-Id: I5f4b7a26a3f41bf539fa79d15e1a108ea35a5b29 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5246697 Commit-Queue: Mark Mentovai Reviewed-by: Mark Mentovai --- BUILD.gn | 3 ++- build/crashpad_buildconfig.gni | 6 +++--- snapshot/BUILD.gn | 12 ++++++++---- snapshot/fuchsia/exception_snapshot_fuchsia.cc | 2 +- snapshot/fuchsia/process_reader_fuchsia.cc | 16 ++++++++-------- snapshot/fuchsia/system_snapshot_fuchsia.cc | 6 +++--- snapshot/fuchsia/thread_snapshot_fuchsia.cc | 2 +- 7 files changed, 26 insertions(+), 21 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 83c4a32c..8be9eee7 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -39,7 +39,8 @@ if (crashpad_is_in_chromium || crashpad_is_in_fuchsia) { if (crashpad_is_in_fuchsia) { # TODO(fuchsia:46559): Fix the leaks and remove this. deps += [ "//build/config/sanitizers:suppress-lsan.DO-NOT-USE-THIS" ] - # TODO(fxbug.dev/108368): Remove this once the underlying issue is addressed. + # TODO(fxbug.dev/42059784): Remove this once the underlying issue is + # addressed. exclude_toolchain_tags = [ "hwasan" ] } if (crashpad_is_android) { diff --git a/build/crashpad_buildconfig.gni b/build/crashpad_buildconfig.gni index 4e9091a2..3d0150a2 100644 --- a/build/crashpad_buildconfig.gni +++ b/build/crashpad_buildconfig.gni @@ -106,7 +106,7 @@ template("crashpad_executable") { if (crashpad_is_in_fuchsia) { conversion_config = [ "//build/config:Wno-conversion" ] if (configs + conversion_config - conversion_config == configs) { - # TODO(https://fxbug.dev/58162): Decide if these are worth enabling. + # TODO(https://fxbug.dev/42136089): Decide if these are worth enabling. configs += conversion_config } } @@ -132,7 +132,7 @@ template("crashpad_loadable_module") { if (crashpad_is_in_fuchsia) { conversion_config = [ "//build/config:Wno-conversion" ] if (configs + conversion_config - conversion_config == configs) { - # TODO(https://fxbug.dev/58162): Decide if these are worth enabling. + # TODO(https://fxbug.dev/42136089): Decide if these are worth enabling. configs += conversion_config } } @@ -158,7 +158,7 @@ template("crashpad_static_library") { if (crashpad_is_in_fuchsia) { conversion_config = [ "//build/config:Wno-conversion" ] if (configs + conversion_config - conversion_config == configs) { - # TODO(https://fxbug.dev/58162): Decide if these are worth enabling. + # TODO(https://fxbug.dev/42136089): Decide if these are worth enabling. configs += conversion_config } } diff --git a/snapshot/BUILD.gn b/snapshot/BUILD.gn index a364f956..2ae944c3 100644 --- a/snapshot/BUILD.gn +++ b/snapshot/BUILD.gn @@ -507,7 +507,8 @@ crashpad_loadable_module("crashpad_snapshot_test_module") { "../client", ] if (crashpad_is_in_fuchsia) { - # TODO(fxbug.dev/108368): Remove this once the underlying issue is addressed. + # TODO(fxbug.dev/42059784): Remove this once the underlying issue is + # addressed. exclude_toolchain_tags = [ "hwasan" ] } } @@ -526,7 +527,8 @@ crashpad_loadable_module("crashpad_snapshot_test_module_large") { deps += [ "$mini_chromium_source_parent:base" ] if (crashpad_is_in_fuchsia) { - # TODO(fxbug.dev/108368): Remove this once the underlying issue is addressed. + # TODO(fxbug.dev/42059784): Remove this once the underlying issue is + # addressed. exclude_toolchain_tags = [ "hwasan" ] } } @@ -545,7 +547,8 @@ crashpad_loadable_module("crashpad_snapshot_test_module_small") { deps += [ "$mini_chromium_source_parent:base" ] if (crashpad_is_in_fuchsia) { - # TODO(fxbug.dev/108368): Remove this once the underlying issue is addressed. + # TODO(fxbug.dev/42059784): Remove this once the underlying issue is + # addressed. exclude_toolchain_tags = [ "hwasan" ] } } @@ -560,7 +563,8 @@ if ((crashpad_is_linux || crashpad_is_android || crashpad_is_fuchsia) && ldflags = [ "-Wl,--hash-style=both" ] if (crashpad_is_in_fuchsia) { - # TODO(fxbug.dev/108368): Remove this once the underlying issue is addressed. + # TODO(fxbug.dev/42059784): Remove this once the underlying issue is + # addressed. exclude_toolchain_tags = [ "hwasan" ] } } diff --git a/snapshot/fuchsia/exception_snapshot_fuchsia.cc b/snapshot/fuchsia/exception_snapshot_fuchsia.cc index be71ca22..c595b92b 100644 --- a/snapshot/fuchsia/exception_snapshot_fuchsia.cc +++ b/snapshot/fuchsia/exception_snapshot_fuchsia.cc @@ -74,7 +74,7 @@ bool ExceptionSnapshotFuchsia::Initialize( #if defined(ARCH_CPU_X86_64) context_.architecture = kCPUArchitectureX86_64; context_.x86_64 = &context_arch_; - // TODO(fxbug.dev/5496): Add vector context. + // TODO(fxbug.dev/42132536): Add vector context. InitializeCPUContextX86_64( t->general_registers, t->fp_registers, context_.x86_64); #elif defined(ARCH_CPU_ARM64) diff --git a/snapshot/fuchsia/process_reader_fuchsia.cc b/snapshot/fuchsia/process_reader_fuchsia.cc index 5bf2acf7..8b10e2cc 100644 --- a/snapshot/fuchsia/process_reader_fuchsia.cc +++ b/snapshot/fuchsia/process_reader_fuchsia.cc @@ -47,12 +47,12 @@ void GetStackRegions( #error Port #endif - // TODO(fxbug.dev/74897): make this work for stack overflows, e.g., by looking - // up using the initial stack pointer (sp) when the thread was created. Right - // now, it gets the stack by getting the mapping that contains the current sp. - // But in the case of stack overflows, the current sp is by definition outside - // of the stack so the mapping returned is not the stack and fails the type - // check, at least on arm64. + // TODO(fxbug.dev/42154629): make this work for stack overflows, e.g., by + // looking up using the initial stack pointer (sp) when the thread was + // created. Right now, it gets the stack by getting the mapping that contains + // the current sp. But in the case of stack overflows, the current sp is by + // definition outside of the stack so the mapping returned is not the stack + // and fails the type check, at least on arm64. zx_info_maps_t range_with_sp; if (!memory_map.FindMappingForAddress(sp, &range_with_sp)) { LOG(ERROR) << "stack pointer not found in mapping"; @@ -235,8 +235,8 @@ void ProcessReaderFuchsia::InitializeModules() { // Crashpad needs to use the same module name at run time for symbol // resolution to work properly. // - // TODO: https://fxbug.dev/6057 - once Crashpad switches to elf-search, the - // following overwrites won't be necessary as only shared libraries will + // TODO: https://fxbug.dev/42138764 - once Crashpad switches to elf-search, + // the following overwrites won't be necessary as only shared libraries will // have a soname at runtime, just like at build time. // // * For shared libraries, the soname is used as module name at build time, diff --git a/snapshot/fuchsia/system_snapshot_fuchsia.cc b/snapshot/fuchsia/system_snapshot_fuchsia.cc index 81a9d301..a9b0eed1 100644 --- a/snapshot/fuchsia/system_snapshot_fuchsia.cc +++ b/snapshot/fuchsia/system_snapshot_fuchsia.cc @@ -75,7 +75,7 @@ uint32_t SystemSnapshotFuchsia::CPURevision() const { #if defined(ARCH_CPU_X86_64) return cpuid_.Revision(); #else - // TODO: https://fxbug.dev/5561 - Read actual revision. + // TODO: https://fxbug.dev/42133257 - Read actual revision. return 0; #endif } @@ -90,7 +90,7 @@ std::string SystemSnapshotFuchsia::CPUVendor() const { #if defined(ARCH_CPU_X86_64) return cpuid_.Vendor(); #else - // TODO: https://fxbug.dev/5561 - Read actual vendor. + // TODO: https://fxbug.dev/42133257 - Read actual vendor. return std::string(); #endif } @@ -193,7 +193,7 @@ bool SystemSnapshotFuchsia::NXEnabled() const { #if defined(ARCH_CPU_X86_64) return cpuid_.NXEnabled(); #else - // TODO: https://fxbug.dev/5561 - Read actual NX bit value. + // TODO: https://fxbug.dev/42133257 - Read actual NX bit value. return false; #endif } diff --git a/snapshot/fuchsia/thread_snapshot_fuchsia.cc b/snapshot/fuchsia/thread_snapshot_fuchsia.cc index 75989525..587e6a91 100644 --- a/snapshot/fuchsia/thread_snapshot_fuchsia.cc +++ b/snapshot/fuchsia/thread_snapshot_fuchsia.cc @@ -40,7 +40,7 @@ bool ThreadSnapshotFuchsia::Initialize( #if defined(ARCH_CPU_X86_64) context_.architecture = kCPUArchitectureX86_64; context_.x86_64 = &context_arch_; - // TODO(fxbug.dev/5496): Add vector context. + // TODO(fxbug.dev/42132536): Add vector context. InitializeCPUContextX86_64( thread.general_registers, thread.fp_registers, context_.x86_64); #elif defined(ARCH_CPU_ARM64) From 5d81482aeafb447d803efac7b68abcf8e20fde6b Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Tue, 30 Jan 2024 20:32:13 -0500 Subject: [PATCH 091/107] ios: Read dyld modules in reverse order. The change in macOS 14's dyld to insert new modules in the front of `dyld_all_image_infos` means that if the any images are loaded during an exception while iterating the modules list, the primary executable will be missed. Instead, read the modules in reverse order. Change-Id: I49f6468173f18ef4bd0f326c84e4b48cfc696cd3 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5249275 Commit-Queue: Justin Cohen Reviewed-by: Mark Mentovai --- client/ios_handler/in_process_intermediate_dump_handler.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ios_handler/in_process_intermediate_dump_handler.cc b/client/ios_handler/in_process_intermediate_dump_handler.cc index e91cc02e..6cc6360d 100644 --- a/client/ios_handler/in_process_intermediate_dump_handler.cc +++ b/client/ios_handler/in_process_intermediate_dump_handler.cc @@ -923,12 +923,12 @@ void InProcessIntermediateDumpHandler::WriteModuleInfo( uint32_t image_count = image_infos->infoArrayCount; const dyld_image_info* image_array = image_infos->infoArray; - for (uint32_t image_index = 0; image_index < image_count; ++image_index) { + for (int32_t image_index = image_count - 1; image_index >= 0; --image_index) { IOSIntermediateDumpWriter::ScopedArrayMap modules(writer); ScopedVMRead image; if (!image.Read(&image_array[image_index])) { CRASHPAD_RAW_LOG("Unable to dyld_image_info"); - return; + continue; } if (image->imageFilePath) { From c576bf35ea325980108eb0ae8028355aa3f1d944 Mon Sep 17 00:00:00 2001 From: Jesse McKenna Date: Fri, 9 Feb 2024 12:21:45 -0800 Subject: [PATCH 092/107] Add Update method to CrashpadInfo This change adds a method to update a CrashpadInfo stream. As part of this change, AddUserDataMinidumpStream() now returns a handle to the added stream. This handle can be passed to UpdateUserDataMinidumpStream() if a new version of the stream needs to be attached to the crash report. This method is needed for e.g., allowing Chrome's System Profile to update, as it contains some data that takes a while to collect. Bug: crashpad:474 Change-Id: I19e935a6904d8843215582e5606b189479ee338b Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5260024 Reviewed-by: Mark Mentovai Commit-Queue: Jesse McKenna --- client/BUILD.gn | 1 + client/crashpad_info.cc | 70 ++++++++++++++++--- client/crashpad_info.h | 40 ++++++++++- client/crashpad_info_test.cc | 131 +++++++++++++++++++++++++++++++++++ 4 files changed, 229 insertions(+), 13 deletions(-) create mode 100644 client/crashpad_info_test.cc diff --git a/client/BUILD.gn b/client/BUILD.gn index bc67b32f..bd150ab9 100644 --- a/client/BUILD.gn +++ b/client/BUILD.gn @@ -174,6 +174,7 @@ source_set("client_test") { "annotation_list_test.cc", "annotation_test.cc", "crash_report_database_test.cc", + "crashpad_info_test.cc", "length_delimited_ring_buffer_test.cc", "prune_crash_reports_test.cc", "ring_buffer_annotation_test.cc", diff --git a/client/crashpad_info.cc b/client/crashpad_info.cc index cd6f2348..781c0e38 100644 --- a/client/crashpad_info.cc +++ b/client/crashpad_info.cc @@ -16,6 +16,7 @@ #include +#include "base/numerics/safe_conversions.h" #include "build/build_config.h" #include "util/misc/address_sanitizer.h" #include "util/misc/from_pointer_cast.h" @@ -33,6 +34,21 @@ namespace { // understand new versions. constexpr uint32_t kCrashpadInfoVersion = 1; +// Creates a `UserDataMinidumpStreamListEntry` with the given fields, and +// returns a pointer to it. The caller takes ownership of the returned object. +crashpad::internal::UserDataMinidumpStreamListEntry* CreateListEntry( + uint64_t next, + uint32_t stream_type, + const void* data, + size_t size) { + auto to_be_added = new crashpad::internal::UserDataMinidumpStreamListEntry(); + to_be_added->next = next; + to_be_added->stream_type = stream_type; + to_be_added->base_address = crashpad::FromPointerCast(data); + to_be_added->size = base::checked_cast(size); + return to_be_added; +} + } // namespace namespace crashpad { @@ -123,16 +139,50 @@ CrashpadInfo::CrashpadInfo() user_data_minidump_stream_head_(nullptr), annotations_list_(nullptr) {} -void CrashpadInfo::AddUserDataMinidumpStream(uint32_t stream_type, - const void* data, - size_t size) { - auto to_be_added = new internal::UserDataMinidumpStreamListEntry(); - to_be_added->next = - FromPointerCast(user_data_minidump_stream_head_); - to_be_added->stream_type = stream_type; - to_be_added->base_address = FromPointerCast(data); - to_be_added->size = base::checked_cast(size); - user_data_minidump_stream_head_ = to_be_added; +UserDataMinidumpStreamHandle* CrashpadInfo::AddUserDataMinidumpStream( + uint32_t stream_type, + const void* data, + size_t size) { + user_data_minidump_stream_head_ = CreateListEntry( + crashpad::FromPointerCast(user_data_minidump_stream_head_), + stream_type, + data, + size); + return user_data_minidump_stream_head_; +} + +UserDataMinidumpStreamHandle* CrashpadInfo::UpdateUserDataMinidumpStream( + UserDataMinidumpStreamHandle* stream_to_update, + uint32_t stream_type, + const void* data, + size_t size) { + // Create a new stream that points to the node `stream_to_update` points to. + const auto new_stream = + CreateListEntry(stream_to_update->next, stream_type, data, size); + + // If `stream_to_update` is head of the list, replace the head with + // `new_stream`. + if (stream_to_update == user_data_minidump_stream_head_) { + user_data_minidump_stream_head_ = new_stream; + } else { + // Otherwise, find the node before `stream_to_update`, and make it point to + // `new_stream` instead. + auto current = user_data_minidump_stream_head_; + while (current) { + auto next = reinterpret_cast( + current->next); + if (next == stream_to_update) { + current->next = FromPointerCast(new_stream); + break; + } + current = next; + } + CHECK(current) + << "Tried to update a UserDataMinidumpStream that doesn't exist"; + } + + delete stream_to_update; + return new_stream; } } // namespace crashpad diff --git a/client/crashpad_info.h b/client/crashpad_info.h index ebfe8fe8..7d894cb0 100644 --- a/client/crashpad_info.h +++ b/client/crashpad_info.h @@ -56,6 +56,8 @@ struct UserDataMinidumpStreamListEntry { } // namespace internal +using UserDataMinidumpStreamHandle = internal::UserDataMinidumpStreamListEntry; + //! \brief A structure that can be used by a Crashpad-enabled program to //! provide information to the Crashpad crash handler. //! @@ -221,9 +223,41 @@ struct CrashpadInfo { //! which is `0xffff`. //! \param[in] data The base pointer of the stream data. //! \param[in] size The size of the stream data. - void AddUserDataMinidumpStream(uint32_t stream_type, - const void* data, - size_t size); + //! \return A handle to the added stream, for use in calling + //! UpdateUserDataMinidumpStream() if needed. + UserDataMinidumpStreamHandle* AddUserDataMinidumpStream(uint32_t stream_type, + const void* data, + size_t size); + + //! \brief Replaces the given stream with an updated stream. + //! + //! Creates a new memory block referencing the given \a data and \a size with + //! type \a stream_type. The memory referred to be \a data and \a size is + //! owned by the caller and must remain valid while it is in effect for the + //! CrashpadInfo object. + //! + //! Frees \a stream_to_update and returns a new handle to the updated stream. + //! + //! \param[in] stream_to_update A handle to the stream to be updated, received + //! from either AddUserDataMinidumpStream() or previous calls to this + //! function. + //! \param[in] stream_type The stream type identifier to use. This should be + //! normally be larger than `MINIDUMP_STREAM_TYPE::LastReservedStream` + //! which is `0xffff`. + //! \param[in] data The base pointer of the stream data. + //! \param[in] size The size of the stream data. + //! \return A handle to the new memory block that references the updated data, + //! for use in calling this method again if needed. + UserDataMinidumpStreamHandle* UpdateUserDataMinidumpStream( + UserDataMinidumpStreamHandle* stream_to_update, + uint32_t stream_type, + const void* data, + size_t size); + + internal::UserDataMinidumpStreamListEntry* + GetUserDataMinidumpStreamHeadForTesting() { + return user_data_minidump_stream_head_; + } enum : uint32_t { kSignature = 'CPad', diff --git a/client/crashpad_info_test.cc b/client/crashpad_info_test.cc new file mode 100644 index 00000000..09799f14 --- /dev/null +++ b/client/crashpad_info_test.cc @@ -0,0 +1,131 @@ +// Copyright 2024 The Crashpad Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "client/crashpad_info.h" + +#include + +#include "gtest/gtest.h" + +namespace crashpad { +namespace test { +namespace { + +constexpr uint32_t kTestStreamType = 0x33333; + +class CrashpadInfoTest : public testing::Test { + protected: + CrashpadInfo& crashpad_info() { return crashpad_info_; } + + // Returns the current head of the list of streams in `crashpad_info_`. Note + // that the returned pointer is invalidated if a stream is added or updated. + internal::UserDataMinidumpStreamListEntry* GetCurrentHead() { + return crashpad_info().GetUserDataMinidumpStreamHeadForTesting(); + } + + // Returns a pointer to the next node in the list after the given `node`. + internal::UserDataMinidumpStreamListEntry* GetNext( + internal::UserDataMinidumpStreamListEntry* node) { + return reinterpret_cast( + node->next); + } + + internal::UserDataMinidumpStreamListEntry* initial_head() { + return initial_head_; + } + + internal::UserDataMinidumpStreamListEntry* initial_tail() { + return initial_tail_; + } + + private: + void SetUp() override { + ASSERT_EQ(nullptr, GetCurrentHead()); + + // Create a simple test list with the structure + // `initial_head_` -> `initial_tail_`. + initial_tail_ = AddStream(0x11111, kInitialTailData); + initial_head_ = AddStream(0x22222, kInitialHeadData); + + // Validate the list's contents. + auto current = GetCurrentHead(); + ASSERT_EQ(initial_head_, current); + ASSERT_EQ(kInitialHeadData, reinterpret_cast(current->base_address)); + current = GetNext(current); + ASSERT_EQ(initial_tail_, current); + ASSERT_EQ(nullptr, GetNext(current)); + } + + internal::UserDataMinidumpStreamListEntry* AddStream(uint32_t stream_type, + const char* data) { + return reinterpret_cast( + crashpad_info().AddUserDataMinidumpStream( + stream_type, data, strlen(data))); + } + + CrashpadInfo crashpad_info_; + + static constexpr char kInitialHeadData[] = "head"; + static constexpr char kInitialTailData[] = "tail"; + + internal::UserDataMinidumpStreamListEntry* initial_head_ = nullptr; + internal::UserDataMinidumpStreamListEntry* initial_tail_ = nullptr; +}; + +// Tests that updating the head of the list updates the head pointer, the new +// head contains the updated data, and the updated node points to the next node. +TEST_F(CrashpadInfoTest, UpdateUserDataMinidumpStreamHead) { + const std::string new_data = "this is a new string"; + const auto new_entry = crashpad_info().UpdateUserDataMinidumpStream( + initial_head(), kTestStreamType, new_data.data(), new_data.size()); + const auto head = GetCurrentHead(); + EXPECT_EQ(new_entry, head); + EXPECT_EQ(new_data.data(), reinterpret_cast(head->base_address)); + EXPECT_EQ(new_data.size(), head->size); + EXPECT_EQ(kTestStreamType, head->stream_type); + EXPECT_EQ(initial_tail(), GetNext(head)); +} + +// Tests that updating the tail of the list results in a tail pointing to +// nullptr, and that the node before the updated node points to it. +TEST_F(CrashpadInfoTest, UpdateUserDataMinidumpStreamTail) { + const std::string new_data = "new"; + const auto new_entry = crashpad_info().UpdateUserDataMinidumpStream( + initial_tail(), kTestStreamType, new_data.data(), new_data.size()); + const auto tail = GetNext(GetCurrentHead()); + EXPECT_EQ(new_entry, tail); + EXPECT_EQ(nullptr, GetNext(tail)); +} + +// Tests that the handle returned from updating an entry is usable for updating +// the entry again. +TEST_F(CrashpadInfoTest, UpdateUserDataMinidumpStreamMultipleTimes) { + // Update the entry at the head; the updated entry should become the new head. + const std::string new_data = "new"; + const auto new_entry_1 = crashpad_info().UpdateUserDataMinidumpStream( + initial_head(), kTestStreamType, new_data.data(), new_data.size()); + EXPECT_EQ(new_entry_1, GetCurrentHead()); + + // Update the updated entry again; another new entry should replace it as + // head. + const auto new_entry_2 = crashpad_info().UpdateUserDataMinidumpStream( + new_entry_1, kTestStreamType, new_data.data(), new_data.size()); + EXPECT_NE(new_entry_1, new_entry_2); + EXPECT_EQ(new_entry_2, GetCurrentHead()); + EXPECT_EQ(initial_tail(), GetNext(GetCurrentHead())); +} + +} // namespace +} // namespace test +} // namespace crashpad From 5075fb617a384392bc0113b55a2b5ce1c0923df3 Mon Sep 17 00:00:00 2001 From: Sylvain Defresne Date: Mon, 12 Feb 2024 16:23:37 +0100 Subject: [PATCH 093/107] Honor ios_is_app_extension chromium build flag If building for chromium, honor the ios_is_app_extension gn variable that is set per toolchain. When it is defined, the code is built for an application extension (i.e. -fapplication-extension is passed to the compiler). Use CRASHPAD_IS_IOS_APP_EXTENSION build guard to not compile code that use unavailable extension when ios_is_app_extension is set. If the variable is not set, then check at runtime whether the API can be used or not (if the crashpad client uses the same toolchain for the main application and its application extensions). This is required to pass -fapplication-extension to the compiler when building application extensions (which allow catching API that is not available to application extensions). Bug: 40120082 Change-Id: I28d545fcfd0f8662430c40ff202b79b0c2b2ff8b Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5286216 Reviewed-by: Justin Cohen Commit-Queue: Sylvain Defresne --- build/BUILD.gn | 13 +++++++++++++ util/BUILD.gn | 4 ++++ util/ios/ios_system_data_collector.mm | 14 ++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/build/BUILD.gn b/build/BUILD.gn index 7d7e08bb..664e4982 100644 --- a/build/BUILD.gn +++ b/build/BUILD.gn @@ -72,4 +72,17 @@ if (crashpad_is_ios) { ] } } + + if (crashpad_is_in_chromium) { + import("//build/config/ios/ios_sdk.gni") + crashpad_is_ios_app_extension = ios_is_app_extension + } else { + crashpad_is_ios_app_extension = false + } + + config("crashpad_is_ios_app_extension") { + if (crashpad_is_ios_app_extension) { + defines = [ "CRASHPAD_IS_IOS_APP_EXTENSION" ] + } + } } diff --git a/util/BUILD.gn b/util/BUILD.gn index 93b9d544..e7ff4a8a 100644 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -597,6 +597,10 @@ crashpad_static_library("util") { ] } + if (crashpad_is_ios) { + configs += [ "../build:crashpad_is_ios_app_extension" ] + } + if (crashpad_is_win) { libs = [ "user32.lib", diff --git a/util/ios/ios_system_data_collector.mm b/util/ios/ios_system_data_collector.mm index 2ec6de59..bcadba6e 100644 --- a/util/ios/ios_system_data_collector.mm +++ b/util/ios/ios_system_data_collector.mm @@ -22,6 +22,7 @@ #import #include "base/apple/mach_logging.h" +#include "base/notreached.h" #include "base/numerics/safe_conversions.h" #include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" @@ -99,7 +100,14 @@ void AddObserver(CFStringRef notification_name, T* observer) { build_ = ReadStringSysctlByName("kern.osversion"); bundle_identifier_ = base::SysNSStringToUTF8([[NSBundle mainBundle] bundleIdentifier]); +// If CRASHPAD_IS_IOS_APP_EXTENSION is defined, then the code is compiled with +// -fapplication-extension and can only be used in an app extension. Otherwise +// check at runtime whether the code is executing in an app extension or not. +#if defined(CRASHPAD_IS_IOS_APP_EXTENSION) + is_extension_ = true; +#else is_extension_ = [[NSBundle mainBundle].bundlePath hasSuffix:@"appex"]; +#endif #if defined(ARCH_CPU_X86_64) cpu_vendor_ = ReadStringSysctlByName("machdep.cpu.vendor"); @@ -172,6 +180,7 @@ void AddObserver(CFStringRef notification_name, T* observer) { (__bridge CFStringRef)UIDeviceOrientationDidChangeNotification, this); OrientationDidChangeNotification(); +#if !defined(CRASHPAD_IS_IOS_APP_EXTENSION) // Foreground/Background. Extensions shouldn't use UIApplication*. if (!is_extension_) { AddObserver< @@ -185,6 +194,7 @@ void AddObserver(CFStringRef notification_name, T* observer) { this); ApplicationDidChangeActiveNotification(); } +#endif } void IOSSystemDataCollector::SystemTimeZoneDidChangeNotification() { @@ -228,6 +238,9 @@ void AddObserver(CFStringRef notification_name, T* observer) { } void IOSSystemDataCollector::ApplicationDidChangeActiveNotification() { +#if defined(CRASHPAD_IS_IOS_APP_EXTENSION) + NOTREACHED_NORETURN(); +#else dispatch_assert_queue_debug(dispatch_get_main_queue()); bool old_active = active_; active_ = [UIApplication sharedApplication].applicationState == @@ -235,6 +248,7 @@ void AddObserver(CFStringRef notification_name, T* observer) { if (active_ != old_active && active_application_callback_) { active_application_callback_(active_); } +#endif } } // namespace internal From 940e8a344548016451775ee84321dc4cc067b5ef Mon Sep 17 00:00:00 2001 From: Jesse McKenna Date: Tue, 13 Feb 2024 10:08:20 -0800 Subject: [PATCH 094/107] Fix leaky CrashpadInfo test CrashpadInfo::AddUserDataMinidumpStream() and UpdateUserDataMinidumpStream() allocate memory for the newly added streams. This change makes the CrashpadInfo test free that allocated memory to prevent memory leaks from these tests. This is intended to fix the ASAN failures seen on crrev.com/c/5285881: https://ci.chromium.org/ui/p/chromium/builders/try/linux_chromium_asan_rel_ng/1839072/overview Bug: crashpad:474 Change-Id: I6e030291594d22e316942a58805a177ce448053b Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5292137 Reviewed-by: Mark Mentovai Commit-Queue: Jesse McKenna --- client/crashpad_info_test.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/client/crashpad_info_test.cc b/client/crashpad_info_test.cc index 09799f14..8ea7f8a1 100644 --- a/client/crashpad_info_test.cc +++ b/client/crashpad_info_test.cc @@ -67,6 +67,17 @@ class CrashpadInfoTest : public testing::Test { ASSERT_EQ(nullptr, GetNext(current)); } + void TearDown() override { + // Free the list. The list lives until process exit in production, but must + // be freed in tests as multiple tests run in the same process. + auto current = GetCurrentHead(); + while (current) { + auto next = GetNext(current); + delete current; + current = next; + } + } + internal::UserDataMinidumpStreamListEntry* AddStream(uint32_t stream_type, const char* data) { return reinterpret_cast( From 29ac83caeb94e3f2d81bcdd4d6dbcce70ebe4ef8 Mon Sep 17 00:00:00 2001 From: Hzj_jie Date: Thu, 15 Feb 2024 13:22:35 -0800 Subject: [PATCH 095/107] [Fuchsia] remove use of fuchsia mac sdk Bug: b/325495632 Change-Id: I19df5b44b76efcdb050344e79bcc2dfd18d8e289 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5299466 Reviewed-by: Mark Mentovai Commit-Queue: Mark Mentovai --- DEPS | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/DEPS b/DEPS index f1c8b39a..88f7571c 100644 --- a/DEPS +++ b/DEPS @@ -121,16 +121,6 @@ deps = { '0d6902558d92fe3d49ba9a8f638ddea829be595b', 'condition': 'checkout_fuchsia', }, - 'crashpad/third_party/fuchsia/sdk/mac-amd64': { - 'packages': [ - { - 'package': 'fuchsia/sdk/core/mac-amd64', - 'version': 'latest' - }, - ], - 'condition': 'checkout_fuchsia and host_os == "mac"', - 'dep_type': 'cipd' - }, 'crashpad/third_party/fuchsia/sdk/linux-amd64': { 'packages': [ { From 37afd37401253ebcebcf6e07ce15c8cfecb1a1cc Mon Sep 17 00:00:00 2001 From: Joshua Peraza Date: Tue, 20 Feb 2024 18:50:05 -0800 Subject: [PATCH 096/107] Properly update iterator Bug: 325296797 Change-Id: I39f76519c46804ad663172abf91ef582bde135e7 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5310754 Commit-Queue: Joshua Peraza Reviewed-by: Justin Cohen --- snapshot/sanitized/module_snapshot_sanitized.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/snapshot/sanitized/module_snapshot_sanitized.cc b/snapshot/sanitized/module_snapshot_sanitized.cc index 0ad2ee97..c7672268 100644 --- a/snapshot/sanitized/module_snapshot_sanitized.cc +++ b/snapshot/sanitized/module_snapshot_sanitized.cc @@ -99,9 +99,11 @@ ModuleSnapshotSanitized::AnnotationsSimpleMap() const { std::map annotations = snapshot_->AnnotationsSimpleMap(); if (allowed_annotations_) { - for (auto kv = annotations.begin(); kv != annotations.end(); ++kv) { - if (!KeyIsAllowed(kv->first, *allowed_annotations_)) { - annotations.erase(kv); + for (auto kv = annotations.begin(); kv != annotations.end();) { + if (KeyIsAllowed(kv->first, *allowed_annotations_)) { + ++kv; + } else { + kv = annotations.erase(kv); } } } From bc4fd34fe2e2611689f0a947885a11a16bd122cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Bostr=C3=B6m?= Date: Wed, 21 Feb 2024 15:22:12 -0800 Subject: [PATCH 097/107] Log argv[0] for failing spawns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds argv[0] for PLOG(FATAL) calls following a failed posix_spawn or execve call to make logs more useful. Bug: chromium:324982367 Change-Id: I179928ec9f791ce5b365b3444aa3bb667f4ec4b3 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5315332 Reviewed-by: Mark Mentovai Commit-Queue: Peter Boström --- util/posix/spawn_subprocess.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/util/posix/spawn_subprocess.cc b/util/posix/spawn_subprocess.cc index df5b4a3f..8f1f13d1 100644 --- a/util/posix/spawn_subprocess.cc +++ b/util/posix/spawn_subprocess.cc @@ -190,7 +190,8 @@ bool SpawnSubprocess(const std::vector& argv, auto execve_fp = use_path ? execvpe : execve; execve_fp(argv_for_spawn[0], argv_for_spawn, envp_for_spawn); - PLOG(FATAL) << (use_path ? "execvpe" : "execve"); + PLOG(FATAL) << (use_path ? "execvpe" : "execve") << " " + << argv_for_spawn[0]; #else #if BUILDFLAG(IS_APPLE) PosixSpawnAttr attr; @@ -218,7 +219,8 @@ bool SpawnSubprocess(const std::vector& argv, attr_p, argv_for_spawn, envp_for_spawn)) != 0) { - PLOG(FATAL) << (use_path ? "posix_spawnp" : "posix_spawn"); + PLOG(FATAL) << (use_path ? "posix_spawnp" : "posix_spawn") << " " + << argv_for_spawn[0]; } // _exit() instead of exit(), because fork() was called. From 9c58b668ff3372448b1c2ef6e1f3c34930825862 Mon Sep 17 00:00:00 2001 From: Ian Barkley-Yeung Date: Thu, 7 Mar 2024 13:49:23 -0800 Subject: [PATCH 098/107] Increase kMaxNumberOfAnnotations Chrome on ChromeOS is starting to run into problems where there are more than 200 annotations, primarily because we use a lot of command-line switches (40 or more) and commandline-enabled-features as well, each of which takes up an annotation. It's still rare (100s a day) but will probably become worse over time as more CrashKey uses are added. Increase kMaxNumberOfAnnotations to 400. BUG=296821415 Change-Id: Iba7049014ee3c5ae9c45c4022600eaba50acd403 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5354336 Reviewed-by: Mark Mentovai Commit-Queue: Ian Barkley-Yeung Reviewed-by: Joshua Peraza --- snapshot/snapshot_constants.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snapshot/snapshot_constants.h b/snapshot/snapshot_constants.h index d33d30a6..2006e7b5 100644 --- a/snapshot/snapshot_constants.h +++ b/snapshot/snapshot_constants.h @@ -21,7 +21,7 @@ namespace crashpad { //! a client process. //! //! \note This maximum was chosen arbitrarily and may change in the future. -constexpr size_t kMaxNumberOfAnnotations = 200; +constexpr size_t kMaxNumberOfAnnotations = 400; } // namespace crashpad From c4d4a4d83e864df270c267888176ffa415a599b0 Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Fri, 8 Mar 2024 16:07:13 -0500 Subject: [PATCH 099/107] ios: Disable annotations tests on older simulators on macOS 14.3 There appears to be a change in dyld in macOS 14.3 that iOS 17 accounts for, but older simulators do not. This causes the main binary to be listed twice when iterating modules, breaking some tests. Bug: crbug.com/328282286 Change-Id: I71909fbc13bee6de23b10ffd92a791067f8ea909 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5353754 Reviewed-by: Mark Mentovai Commit-Queue: Justin Cohen --- ..._process_intermediate_dump_handler_test.cc | 21 +++++++++++ test/ios/crash_type_xctest.mm | 37 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/client/ios_handler/in_process_intermediate_dump_handler_test.cc b/client/ios_handler/in_process_intermediate_dump_handler_test.cc index 90f76d58..27179bb3 100644 --- a/client/ios_handler/in_process_intermediate_dump_handler_test.cc +++ b/client/ios_handler/in_process_intermediate_dump_handler_test.cc @@ -89,6 +89,18 @@ class InProcessIntermediateDumpHandlerTest : public testing::Test { const auto& path() const { return path_; } auto writer() const { return writer_.get(); } +#if TARGET_OS_SIMULATOR + // macOS 14.0 is 23A344, macOS 13.6.5 is 22G621, so if the first two + // characters in the kern.osversion are > 22, this build will reproduce the + // simulator bug in crbug.com/328282286 + bool IsMacOSVersion143OrGreaterAndiOS16OrLess() { + if (__builtin_available(iOS 17, *)) { + return false; + } + return std::stoi(system_data_.Build().substr(0, 2)) > 22; + } +#endif + private: std::unique_ptr writer_; internal::IOSSystemDataCollector system_data_; @@ -125,6 +137,15 @@ TEST_F(InProcessIntermediateDumpHandlerTest, TestSystem) { } TEST_F(InProcessIntermediateDumpHandlerTest, TestAnnotations) { +#if TARGET_OS_SIMULATOR + // This test will fail on older ( #include +#include #include @@ -24,6 +25,34 @@ #include "util/mach/exception_types.h" #include "util/mach/mach_extensions.h" +namespace { + +#if TARGET_OS_SIMULATOR +// macOS 14.0 is 23A344, macOS 13.6.5 is 22G621, so if the first two characters +// in the kern.osversion are > 22, this build will reproduce the simulator bug +// in crbug.com/328282286 +bool IsMacOSVersion143OrGreaterAndiOS16OrLess() { + if (__builtin_available(iOS 17, *)) { + return false; + } + + size_t buf_len; + static constexpr char name[] = "kern.osversion"; + if (sysctlbyname(name, nullptr, &buf_len, nullptr, 0) != 0) { + return false; + } + + std::string build(buf_len - 1, '\0'); + if (sysctlbyname(name, &build[0], &buf_len, nullptr, 0) != 0) { + return false; + } + + return std::stoi(build.substr(0, 2)) > 22; +} +#endif + +} // namespace + @interface CPTestTestCase : XCTestCase { XCUIApplication* app_; CPTestSharedObject* rootObject_; @@ -317,6 +346,14 @@ - (void)testCrashWithDyldErrorString { #endif - (void)testCrashWithAnnotations { +#if TARGET_OS_SIMULATOR + // This test will fail on older ( Date: Fri, 1 Dec 2023 13:46:02 +0000 Subject: [PATCH 100/107] Make AnnotationList's iterator compliant to input iterator This CL make the iterators implemented by AnnotationList compliant to the requirements imposed by the C++ standard on input iterators. Change-Id: I263c94a97f5bcd7edd5ef4d8b65fa28b11876974 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5093147 Reviewed-by: Mark Mentovai Commit-Queue: Mark Mentovai --- client/annotation_list.cc | 83 ++++++++++++++++------------------ client/annotation_list.h | 55 +++++++++++----------- client/annotation_list_test.cc | 66 +++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 70 deletions(-) diff --git a/client/annotation_list.cc b/client/annotation_list.cc index bcf7ca76..c7366077 100644 --- a/client/annotation_list.cc +++ b/client/annotation_list.cc @@ -19,6 +19,46 @@ namespace crashpad { +template +T* AnnotationList::IteratorBase::operator*() const { + CHECK_NE(curr_, tail_); + return curr_; +} + +template +T* AnnotationList::IteratorBase::operator->() const { + CHECK_NE(curr_, tail_); + return curr_; +} + +template +AnnotationList::IteratorBase& AnnotationList::IteratorBase::operator++() { + CHECK_NE(curr_, tail_); + curr_ = curr_->GetLinkNode(); + return *this; +} + +template +AnnotationList::IteratorBase AnnotationList::IteratorBase::operator++( + int) { + T* const old_curr = curr_; + ++(*this); + return IteratorBase(old_curr, tail_); +} + +template +bool AnnotationList::IteratorBase::operator!=( + const IteratorBase& other) const { + return !(*this == other); +} + +template +AnnotationList::IteratorBase::IteratorBase(T* head, const Annotation* tail) + : curr_(head), tail_(tail) {} + +template class AnnotationList::IteratorBase; +template class AnnotationList::IteratorBase; + AnnotationList::AnnotationList() : tail_pointer_(&tail_), head_(Annotation::Type::kInvalid, nullptr, nullptr), @@ -65,49 +105,6 @@ void AnnotationList::Add(Annotation* annotation) { } } -AnnotationList::Iterator::Iterator(Annotation* head, const Annotation* tail) - : curr_(head), tail_(tail) {} - -AnnotationList::Iterator::~Iterator() = default; - -Annotation* AnnotationList::Iterator::operator*() const { - CHECK_NE(curr_, tail_); - return curr_; -} - -AnnotationList::Iterator& AnnotationList::Iterator::operator++() { - CHECK_NE(curr_, tail_); - curr_ = curr_->GetLinkNode(); - return *this; -} - -bool AnnotationList::Iterator::operator==( - const AnnotationList::Iterator& other) const { - return curr_ == other.curr_; -} - -AnnotationList::ConstIterator::ConstIterator(const Annotation* head, - const Annotation* tail) - : curr_(head), tail_(tail) {} - -AnnotationList::ConstIterator::~ConstIterator() = default; - -const Annotation* AnnotationList::ConstIterator::operator*() const { - CHECK_NE(curr_, tail_); - return curr_; -} - -AnnotationList::ConstIterator& AnnotationList::ConstIterator::operator++() { - CHECK_NE(curr_, tail_); - curr_ = curr_->GetLinkNode(); - return *this; -} - -bool AnnotationList::ConstIterator::operator==( - const AnnotationList::ConstIterator& other) const { - return curr_ == other.curr_; -} - AnnotationList::Iterator AnnotationList::begin() { return Iterator(head_.GetLinkNode(), tail_pointer_); } diff --git a/client/annotation_list.h b/client/annotation_list.h index eec7fb4c..ce1f8613 100644 --- a/client/annotation_list.h +++ b/client/annotation_list.h @@ -15,6 +15,8 @@ #ifndef CRASHPAD_CLIENT_ANNOTATION_LIST_H_ #define CRASHPAD_CLIENT_ANNOTATION_LIST_H_ +#include + #include "build/build_config.h" #include "client/annotation.h" @@ -61,47 +63,46 @@ class AnnotationList { void Add(Annotation* annotation); //! \brief An InputIterator for the AnnotationList. - class Iterator { + template + class IteratorBase { public: - ~Iterator(); + using difference_type = signed int; + using value_type = T*; + using reference = T*; + using pointer = void; + using iterator_category = std::input_iterator_tag; - Annotation* operator*() const; - Iterator& operator++(); - bool operator==(const Iterator& other) const; - bool operator!=(const Iterator& other) const { return !(*this == other); } + IteratorBase(const IteratorBase& other) = default; + IteratorBase(IteratorBase&& other) = default; - private: - friend class AnnotationList; - Iterator(Annotation* head, const Annotation* tail); + ~IteratorBase() = default; - Annotation* curr_; - const Annotation* const tail_; + IteratorBase& operator=(const IteratorBase& other) = default; + IteratorBase& operator=(IteratorBase&& other) = default; - // Copy and assign are required. - }; + T* operator*() const; + T* operator->() const; - //! \brief An InputIterator for iterating a const AnnotationList. - class ConstIterator { - public: - ~ConstIterator(); + IteratorBase& operator++(); + IteratorBase operator++(int); - const Annotation* operator*() const; - ConstIterator& operator++(); - bool operator==(const ConstIterator& other) const; - bool operator!=(const ConstIterator& other) const { - return !(*this == other); + bool operator==(const IteratorBase& other) const { + return curr_ == other.curr_; } + bool operator!=(const IteratorBase& other) const; + private: friend class AnnotationList; - ConstIterator(const Annotation* head, const Annotation* tail); + IteratorBase(T* head, const Annotation* tail); - const Annotation* curr_; - const Annotation* const tail_; - - // Copy and assign are required. + T* curr_ = nullptr; + const Annotation* tail_ = nullptr; }; + using Iterator = IteratorBase; + using ConstIterator = IteratorBase; + //! \brief Returns an iterator to the first element of the annotation list. Iterator begin(); ConstIterator begin() const { return cbegin(); } diff --git a/client/annotation_list_test.cc b/client/annotation_list_test.cc index 0ac87ffa..41ecfa05 100644 --- a/client/annotation_list_test.cc +++ b/client/annotation_list_test.cc @@ -14,7 +14,10 @@ #include "client/annotation.h" +#include +#include #include +#include #include #include "base/rand_util.h" @@ -27,6 +30,52 @@ namespace crashpad { namespace test { namespace { +#if (__cplusplus >= 202002L) +template + requires std::input_iterator +void VerifyIsInputIterator(Iterator) {} +#else +template +struct IsLegacyIteratorImpl { + static constexpr bool value = + std::is_copy_constructible_v && + std::is_copy_assignable_v && std::is_destructible_v && + std::is_swappable_v && + // check that std::iterator_traits has the necessary types (check only one + // needed as std::iterator is required to define only if all are defined) + !std::is_same_v::reference, + void> && + std::is_same_v()), Iterator&> && + !std::is_same_v()), void>; +}; + +template +struct IsLegacyInputIteratorImpl { + static constexpr bool value = + IsLegacyIteratorImpl::value && + std::is_base_of_v< + std::input_iterator_tag, + typename std::iterator_traits::iterator_category> && + std::is_convertible_v() != + std::declval()), + bool> && + std::is_convertible_v() == + std::declval()), + bool> && + std::is_same_v()), + typename std::iterator_traits::reference> && + std::is_same_v()), Iterator&> && + std::is_same_v()++), Iterator> && + std::is_same_v())), + typename std::iterator_traits::reference>; +}; + +template +void VerifyIsInputIterator(Iterator) { + static_assert(IsLegacyInputIteratorImpl::value); +} +#endif + TEST(AnnotationListStatic, Register) { ASSERT_FALSE(AnnotationList::Get()); EXPECT_TRUE(AnnotationList::Register()); @@ -222,6 +271,23 @@ TEST_F(AnnotationList, IteratorMultipleAnnotationsInsertedAndRemoved) { EXPECT_EQ(const_iterator, annotations_.cend()); } +TEST_F(AnnotationList, IteratorIsInputIterator) { + one_.Set("1"); + two_.Set("2"); + + // Check explicitly that the iterators meet the interface of an input + // iterator. + VerifyIsInputIterator(annotations_.begin()); + VerifyIsInputIterator(annotations_.cbegin()); + VerifyIsInputIterator(annotations_.end()); + VerifyIsInputIterator(annotations_.cend()); + + // Additionally verify that std::distance accepts the iterators. It requires + // the iterators to comply to the input iterator interface. + EXPECT_EQ(std::distance(annotations_.begin(), annotations_.end()), 2); + EXPECT_EQ(std::distance(annotations_.cbegin(), annotations_.cend()), 2); +} + class RaceThread : public Thread { public: explicit RaceThread(test::AnnotationList* test) : Thread(), test_(test) {} From 6bf5e1b5c5038eaefd812f0027ff011153ae30c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kempe?= Date: Tue, 5 Mar 2024 08:38:47 +0000 Subject: [PATCH 101/107] Fix invalid check for valid key of Pointer Authentication Arm's Pointer Authentication uses two keys for signing pointers, A-key and B-key. Although by default Clang uses the A-key if PAC support is enabled at compile time, this behaviour might be overridden via compiler command line. This CL fixes the check for the B-key being enabled. The key that shall be used for Pointer Authentication is denoted by bits 0 (A-key) or 1 (B-key) of __ARM_FEATURE_PAC_DEFAULT. Hence, the previous way of checking by using bits 0 and 2 does not correctly identify the B-key. Bug: 40608466 Change-Id: Ib2f226baa12a7145fa0b6e486e49d36e6b0a3cd7 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5341090 Reviewed-by: Mark Mentovai Commit-Queue: Mark Mentovai --- util/misc/arm64_pac_bti.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/misc/arm64_pac_bti.S b/util/misc/arm64_pac_bti.S index 85da8b56..77961d41 100644 --- a/util/misc/arm64_pac_bti.S +++ b/util/misc/arm64_pac_bti.S @@ -34,7 +34,7 @@ #endif #if defined(__ARM_FEATURE_PAC_DEFAULT) -#if ((__ARM_FEATURE_PAC_DEFAULT & ((1<<0)|(1<<2))) == 0) +#if ((__ARM_FEATURE_PAC_DEFAULT & ((1<<0)|(1<<1))) == 0) #error Pointer authentication defines no valid key! #endif #define GNU_PROPERTY_AARCH64_PAC 1 // Has PAC From ccd20652bc4c7b9ab1878f5dcc0886d40d9a17c9 Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Mon, 18 Mar 2024 12:47:58 -0400 Subject: [PATCH 102/107] ios: Update exception test for Chromium release builds. After https://crrev.com/c/5375084, Chromium __libcpp_verbose_abort is handled differently for official non-dcheck builds. This change fixes the test expectation for release non-official builds. Bug: 330168249 Change-Id: Iceb6d327f9e93fd366cc07abe27eefd1adf06472 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5378380 Reviewed-by: Mark Mentovai Commit-Queue: Justin Cohen --- test/ios/crash_type_xctest.mm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/ios/crash_type_xctest.mm b/test/ios/crash_type_xctest.mm index 1b3b5671..a76f686e 100644 --- a/test/ios/crash_type_xctest.mm +++ b/test/ios/crash_type_xctest.mm @@ -177,7 +177,10 @@ - (void)testException { [rootObject_ crashException]; // After https://reviews.llvm.org/D141222 exceptions call // __libcpp_verbose_abort, which Chromium sets to `brk 0` in release. -#if defined(CRASHPAD_IS_IN_CHROMIUM) && defined(NDEBUG) + // After https://crrev.com/c/5375084, Chromium does not set `brk 0` for local + // release builds and official DCHECK builds. +#if defined(CRASHPAD_IS_IN_CHROMIUM) && defined(NDEBUG) && \ + defined(OFFICIAL_BUILD) && !defined(DCHECK_ALWAYS_ON) [self verifyCrashReportException:SIGABRT]; #else [self verifyCrashReportException:EXC_SOFT_SIGNAL]; From 1cea0473a5a1f3124f0d3a95643c573296a2bac5 Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Wed, 20 Mar 2024 12:42:43 -0400 Subject: [PATCH 103/107] ios: Capture signal exception context memory regions correctly. Previously, Crashpad would only capture iOS thread context memory regions by iterating the task_threads->thread_get_state's. For Mach exception this worked as intended. However, for signal exceptions this missed the registers from the actual signal context. This change correctly captures these regions and stores them in the exception snapshot. Change-Id: I494e753a25c2687e61b5183ed0135f520ca8bf52 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5380505 Reviewed-by: Mark Mentovai Commit-Queue: Justin Cohen --- .../in_process_intermediate_dump_handler.cc | 16 ++++----- ...xception_snapshot_ios_intermediate_dump.cc | 34 +++++++++++++++++-- ...exception_snapshot_ios_intermediate_dump.h | 3 ++ ...ess_snapshot_ios_intermediate_dump_test.cc | 18 ++++++++++ 4 files changed, 61 insertions(+), 10 deletions(-) diff --git a/client/ios_handler/in_process_intermediate_dump_handler.cc b/client/ios_handler/in_process_intermediate_dump_handler.cc index 6cc6360d..29e26cb8 100644 --- a/client/ios_handler/in_process_intermediate_dump_handler.cc +++ b/client/ios_handler/in_process_intermediate_dump_handler.cc @@ -967,19 +967,19 @@ void InProcessIntermediateDumpHandler::WriteExceptionFromSignal( WriteProperty(writer, IntermediateDumpKey::kSignalNumber, &siginfo->si_signo); WriteProperty(writer, IntermediateDumpKey::kSignalCode, &siginfo->si_code); WriteProperty(writer, IntermediateDumpKey::kSignalAddress, &siginfo->si_addr); + #if defined(ARCH_CPU_X86_64) - WriteProperty( - writer, IntermediateDumpKey::kThreadState, &context->uc_mcontext->__ss); - WriteProperty( - writer, IntermediateDumpKey::kFloatState, &context->uc_mcontext->__fs); + x86_thread_state64_t thread_state = context->uc_mcontext->__ss; + x86_float_state64_t float_state = context->uc_mcontext->__fs; #elif defined(ARCH_CPU_ARM64) - WriteProperty( - writer, IntermediateDumpKey::kThreadState, &context->uc_mcontext->__ss); - WriteProperty( - writer, IntermediateDumpKey::kFloatState, &context->uc_mcontext->__ns); + arm_thread_state64_t thread_state = context->uc_mcontext->__ss; + arm_neon_state64_t float_state = context->uc_mcontext->__ns; #else #error Port to your CPU architecture #endif + WriteProperty(writer, IntermediateDumpKey::kThreadState, &thread_state); + WriteProperty(writer, IntermediateDumpKey::kFloatState, &float_state); + CaptureMemoryPointedToByThreadState(writer, thread_state); // Thread ID. thread_identifier_info identifier_info; diff --git a/snapshot/ios/exception_snapshot_ios_intermediate_dump.cc b/snapshot/ios/exception_snapshot_ios_intermediate_dump.cc index e3478454..9f1852a6 100644 --- a/snapshot/ios/exception_snapshot_ios_intermediate_dump.cc +++ b/snapshot/ios/exception_snapshot_ios_intermediate_dump.cc @@ -149,6 +149,33 @@ bool ExceptionSnapshotIOSIntermediateDump::InitializeFromSignal( GetDataValueFromMap(exception_data, Key::kSignalCode, &code); codes_.push_back(code); + const IOSIntermediateDumpList* thread_context_memory_regions = + GetListFromMap(exception_data, Key::kThreadContextMemoryRegions); + if (thread_context_memory_regions) { + for (auto& region : *thread_context_memory_regions) { + vm_address_t address; + const IOSIntermediateDumpData* region_data = + region->GetAsData(Key::kThreadContextMemoryRegionData); + if (!region_data) + continue; + if (GetDataValueFromMap( + region.get(), Key::kThreadContextMemoryRegionAddress, &address)) { + const std::vector& bytes = region_data->bytes(); + vm_size_t data_size = bytes.size(); + if (data_size == 0) + continue; + + const vm_address_t data = + reinterpret_cast(bytes.data()); + + auto memory = + std::make_unique(); + memory->Initialize(address, data, data_size); + extra_memory_.push_back(std::move(memory)); + } + } + } + INITIALIZATION_STATE_SET_VALID(initialized_); return true; } @@ -281,8 +308,11 @@ const std::vector& ExceptionSnapshotIOSIntermediateDump::Codes() std::vector ExceptionSnapshotIOSIntermediateDump::ExtraMemory() const { - INITIALIZATION_STATE_DCHECK_VALID(initialized_); - return std::vector(); + std::vector extra_memory; + for (const auto& memory : extra_memory_) { + extra_memory.push_back(memory.get()); + } + return extra_memory; } void ExceptionSnapshotIOSIntermediateDump::LoadContextFromThread( diff --git a/snapshot/ios/exception_snapshot_ios_intermediate_dump.h b/snapshot/ios/exception_snapshot_ios_intermediate_dump.h index 90966df1..dc9d5954 100644 --- a/snapshot/ios/exception_snapshot_ios_intermediate_dump.h +++ b/snapshot/ios/exception_snapshot_ios_intermediate_dump.h @@ -23,6 +23,7 @@ #include "build/build_config.h" #include "snapshot/cpu_context.h" #include "snapshot/exception_snapshot.h" +#include "snapshot/ios/memory_snapshot_ios_intermediate_dump.h" #include "util/ios/ios_intermediate_dump_map.h" #include "util/mach/mach_extensions.h" #include "util/misc/initialization_state_dcheck.h" @@ -106,6 +107,8 @@ class ExceptionSnapshotIOSIntermediateDump final : public ExceptionSnapshot { uintptr_t exception_address_; uint32_t exception_; uint32_t exception_info_; + std::vector> + extra_memory_; InitializationStateDcheck initialized_; }; diff --git a/snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc b/snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc index 29d26a83..69cb43ed 100644 --- a/snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc +++ b/snapshot/ios/process_snapshot_ios_intermediate_dump_test.cc @@ -577,6 +577,18 @@ TEST_F(ProcessSnapshotIOSIntermediateDumpTest, EmptySignalDump) { IOSIntermediateDumpWriter::ScopedMap map(writer(), Key::kSignalException); uint64_t thread_id = 1; EXPECT_TRUE(writer()->AddProperty(Key::kThreadID, &thread_id)); + { + IOSIntermediateDumpWriter::ScopedArray contextMemoryRegions( + writer(), Key::kThreadContextMemoryRegions); + IOSIntermediateDumpWriter::ScopedArrayMap memoryMap(writer()); + + std::string random_data("random_data"); + EXPECT_TRUE(writer()->AddProperty( + Key::kThreadContextMemoryRegionAddress, &thread_id)); + EXPECT_TRUE(writer()->AddProperty(Key::kThreadContextMemoryRegionData, + random_data.c_str(), + random_data.length())); + } } { IOSIntermediateDumpWriter::ScopedArray threadArray(writer(), @@ -589,6 +601,12 @@ TEST_F(ProcessSnapshotIOSIntermediateDumpTest, EmptySignalDump) { CloseWriter(); ProcessSnapshotIOSIntermediateDump process_snapshot; ASSERT_TRUE(process_snapshot.InitializeWithFilePath(path(), annotations())); + EXPECT_EQ(process_snapshot.Exception()->ExtraMemory().size(), 1u); + ReadToString delegate; + for (auto memory : process_snapshot.Exception()->ExtraMemory()) { + memory->Read(&delegate); + EXPECT_STREQ(delegate.result.c_str(), "random_data"); + } EXPECT_FALSE(IsRegularFile(path())); EXPECT_TRUE(DumpSnapshot(process_snapshot)); } From bbb99bfa3766f06dcfe8f72a9379c59e5a44b43b Mon Sep 17 00:00:00 2001 From: danakj Date: Thu, 4 Apr 2024 14:12:33 -0400 Subject: [PATCH 104/107] Move crashpad to using Mac-13|Mac-14 (like chromium) and latest win sdk This should give crashpad a newer xcode and msvc that support C++20. These changes need to land separately from the C++20 usage, as they do not get applied until after landing, so can't affect the CQ from inside the CQ. Bug: 40284755 Change-Id: I3ae72befa008bfb37bac882de0986c5bcf9de079 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5425460 Commit-Queue: danakj Reviewed-by: Mark Mentovai --- infra/config/generated/commit-queue.cfg | 2 +- infra/config/generated/cr-buildbucket.cfg | 34 +++++++++++------------ infra/config/generated/luci-logdog.cfg | 2 +- infra/config/generated/luci-milo.cfg | 2 +- infra/config/generated/luci-scheduler.cfg | 2 +- infra/config/generated/project.cfg | 4 +-- infra/config/generated/realms.cfg | 2 +- infra/config/main.star | 6 ++-- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/infra/config/generated/commit-queue.cfg b/infra/config/generated/commit-queue.cfg index 95b31824..1a17e5c9 100644 --- a/infra/config/generated/commit-queue.cfg +++ b/infra/config/generated/commit-queue.cfg @@ -2,7 +2,7 @@ # Do not modify manually. # # For the schema of this file, see Config message: -# https://luci-config.appspot.com/schemas/projects:commit-queue.cfg +# https://config.luci.app/schemas/projects:commit-queue.cfg cq_status_host: "chromium-cq-status.appspot.com" submit_options { diff --git a/infra/config/generated/cr-buildbucket.cfg b/infra/config/generated/cr-buildbucket.cfg index a22e2411..cc62d6d3 100644 --- a/infra/config/generated/cr-buildbucket.cfg +++ b/infra/config/generated/cr-buildbucket.cfg @@ -2,7 +2,7 @@ # Do not modify manually. # # For the schema of this file, see BuildbucketCfg message: -# https://luci-config.appspot.com/schemas/projects:buildbucket.cfg +# https://config.luci.app/schemas/projects:buildbucket.cfg buckets { name: "ci" @@ -156,7 +156,7 @@ buckets { name: "crashpad_ios_arm64_dbg" swarming_host: "chromium-swarm.appspot.com" dimensions: "cpu:x86-64" - dimensions: "os:Mac-12" + dimensions: "os:Mac-13|Mac-14" dimensions: "pool:luci.flex.ci" exe { cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" @@ -193,7 +193,7 @@ buckets { name: "crashpad_ios_arm64_rel" swarming_host: "chromium-swarm.appspot.com" dimensions: "cpu:x86-64" - dimensions: "os:Mac-12" + dimensions: "os:Mac-13|Mac-14" dimensions: "pool:luci.flex.ci" exe { cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" @@ -230,7 +230,7 @@ buckets { name: "crashpad_ios_x64_dbg" swarming_host: "chromium-swarm.appspot.com" dimensions: "cpu:x86-64" - dimensions: "os:Mac-12" + dimensions: "os:Mac-13|Mac-14" dimensions: "pool:luci.flex.ci" exe { cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" @@ -266,7 +266,7 @@ buckets { name: "crashpad_ios_x64_rel" swarming_host: "chromium-swarm.appspot.com" dimensions: "cpu:x86-64" - dimensions: "os:Mac-12" + dimensions: "os:Mac-13|Mac-14" dimensions: "pool:luci.flex.ci" exe { cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" @@ -368,7 +368,7 @@ buckets { name: "crashpad_mac_x64_dbg" swarming_host: "chromium-swarm.appspot.com" dimensions: "cpu:x86-64" - dimensions: "os:Mac-12" + dimensions: "os:Mac-13|Mac-14" dimensions: "pool:luci.flex.ci" exe { cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" @@ -404,7 +404,7 @@ buckets { name: "crashpad_mac_x64_rel" swarming_host: "chromium-swarm.appspot.com" dimensions: "cpu:x86-64" - dimensions: "os:Mac-12" + dimensions: "os:Mac-13|Mac-14" dimensions: "pool:luci.flex.ci" exe { cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" @@ -451,7 +451,7 @@ buckets { properties: '{' ' "$depot_tools/windows_sdk": {' - ' "version": "uploaded:2021-04-28"' + ' "version": "uploaded:2024-01-11"' ' },' ' "$gatekeeper": {' ' "group": "client.crashpad"' @@ -487,7 +487,7 @@ buckets { properties: '{' ' "$depot_tools/windows_sdk": {' - ' "version": "uploaded:2021-04-28"' + ' "version": "uploaded:2024-01-11"' ' },' ' "$gatekeeper": {' ' "group": "client.crashpad"' @@ -658,7 +658,7 @@ buckets { name: "crashpad_ios_arm64_dbg" swarming_host: "chromium-swarm.appspot.com" dimensions: "cpu:x86-64" - dimensions: "os:Mac-12" + dimensions: "os:Mac-13|Mac-14" dimensions: "pool:luci.flex.try" exe { cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" @@ -692,7 +692,7 @@ buckets { name: "crashpad_ios_arm64_rel" swarming_host: "chromium-swarm.appspot.com" dimensions: "cpu:x86-64" - dimensions: "os:Mac-12" + dimensions: "os:Mac-13|Mac-14" dimensions: "pool:luci.flex.try" exe { cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" @@ -726,7 +726,7 @@ buckets { name: "crashpad_ios_x64_dbg" swarming_host: "chromium-swarm.appspot.com" dimensions: "cpu:x86-64" - dimensions: "os:Mac-12" + dimensions: "os:Mac-13|Mac-14" dimensions: "pool:luci.flex.try" exe { cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" @@ -759,7 +759,7 @@ buckets { name: "crashpad_ios_x64_rel" swarming_host: "chromium-swarm.appspot.com" dimensions: "cpu:x86-64" - dimensions: "os:Mac-12" + dimensions: "os:Mac-13|Mac-14" dimensions: "pool:luci.flex.try" exe { cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" @@ -852,7 +852,7 @@ buckets { name: "crashpad_mac_x64_dbg" swarming_host: "chromium-swarm.appspot.com" dimensions: "cpu:x86-64" - dimensions: "os:Mac-12" + dimensions: "os:Mac-13|Mac-14" dimensions: "pool:luci.flex.try" exe { cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" @@ -885,7 +885,7 @@ buckets { name: "crashpad_mac_x64_rel" swarming_host: "chromium-swarm.appspot.com" dimensions: "cpu:x86-64" - dimensions: "os:Mac-12" + dimensions: "os:Mac-13|Mac-14" dimensions: "pool:luci.flex.try" exe { cipd_package: "infra/recipe_bundles/chromium.googlesource.com/chromium/tools/build" @@ -929,7 +929,7 @@ buckets { properties: '{' ' "$depot_tools/windows_sdk": {' - ' "version": "uploaded:2021-04-28"' + ' "version": "uploaded:2024-01-11"' ' },' ' "$kitchen": {' ' "devshell": true,' @@ -962,7 +962,7 @@ buckets { properties: '{' ' "$depot_tools/windows_sdk": {' - ' "version": "uploaded:2021-04-28"' + ' "version": "uploaded:2024-01-11"' ' },' ' "$kitchen": {' ' "devshell": true,' diff --git a/infra/config/generated/luci-logdog.cfg b/infra/config/generated/luci-logdog.cfg index adc75bef..01a39126 100644 --- a/infra/config/generated/luci-logdog.cfg +++ b/infra/config/generated/luci-logdog.cfg @@ -2,7 +2,7 @@ # Do not modify manually. # # For the schema of this file, see ProjectConfig message: -# https://luci-config.appspot.com/schemas/projects:luci-logdog.cfg +# https://config.luci.app/schemas/projects:luci-logdog.cfg reader_auth_groups: "all" writer_auth_groups: "luci-logdog-chromium-writers" diff --git a/infra/config/generated/luci-milo.cfg b/infra/config/generated/luci-milo.cfg index 6c891b14..9a78f93f 100644 --- a/infra/config/generated/luci-milo.cfg +++ b/infra/config/generated/luci-milo.cfg @@ -2,7 +2,7 @@ # Do not modify manually. # # For the schema of this file, see Project message: -# https://luci-config.appspot.com/schemas/projects:luci-milo.cfg +# https://config.luci.app/schemas/projects:luci-milo.cfg consoles { id: "main" diff --git a/infra/config/generated/luci-scheduler.cfg b/infra/config/generated/luci-scheduler.cfg index a2251eb8..6e6e8e19 100644 --- a/infra/config/generated/luci-scheduler.cfg +++ b/infra/config/generated/luci-scheduler.cfg @@ -2,7 +2,7 @@ # Do not modify manually. # # For the schema of this file, see ProjectConfig message: -# https://luci-config.appspot.com/schemas/projects:luci-scheduler.cfg +# https://config.luci.app/schemas/projects:luci-scheduler.cfg job { id: "crashpad_fuchsia_arm64_dbg" diff --git a/infra/config/generated/project.cfg b/infra/config/generated/project.cfg index d40ae0db..08e6d529 100644 --- a/infra/config/generated/project.cfg +++ b/infra/config/generated/project.cfg @@ -2,12 +2,12 @@ # Do not modify manually. # # For the schema of this file, see ProjectCfg message: -# https://luci-config.appspot.com/schemas/projects:project.cfg +# https://config.luci.app/schemas/projects:project.cfg name: "crashpad" access: "group:all" lucicfg { - version: "1.32.1" + version: "1.43.5" package_dir: ".." config_dir: "generated" entry_point: "main.star" diff --git a/infra/config/generated/realms.cfg b/infra/config/generated/realms.cfg index 8dc05f6b..b7abb3eb 100644 --- a/infra/config/generated/realms.cfg +++ b/infra/config/generated/realms.cfg @@ -2,7 +2,7 @@ # Do not modify manually. # # For the schema of this file, see RealmsCfg message: -# https://luci-config.appspot.com/schemas/projects:realms.cfg +# https://config.luci.app/schemas/projects:realms.cfg realms { name: "@root" diff --git a/infra/config/main.star b/infra/config/main.star index ae0e8fc3..ab9e55a0 100755 --- a/infra/config/main.star +++ b/infra/config/main.star @@ -158,11 +158,11 @@ def crashpad_dimensions(platform, bucket): if platform == "fuchsia": dimensions["os"] = "Ubuntu-18.04" elif platform == "ios": - dimensions["os"] = "Mac-12" + dimensions["os"] = "Mac-13|Mac-14" elif platform == "linux": dimensions["os"] = "Ubuntu-18.04" elif platform == "mac": - dimensions["os"] = "Mac-12" + dimensions["os"] = "Mac-13|Mac-14" elif platform == "win": dimensions["os"] = "Windows-10" @@ -184,7 +184,7 @@ def crashpad_properties(platform, cpu, config, bucket): if platform == "win": properties["$depot_tools/windows_sdk"] = { - "version": "uploaded:2021-04-28", + "version": "uploaded:2024-01-11", } if bucket == "ci": From f9cee5c147db30dc8fa1a048aabd165965b5cb60 Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Wed, 10 Apr 2024 17:12:05 -0400 Subject: [PATCH 105/107] Roll mini_chromium to pick up the latest version of base::span. Also enables C++20 as span now depends on it. Roll buildtools to grab a newer libc++ that supports C++20. Explicitly capture `this` in lambdas in cpp-httplib as the implicit capture through `=` is deprecated and causes an error in C++20. Update the MacOS version to "Mac-13|Mac-14" which is the current value of `os.MAC_DEFAULT` in Chromium infra in order to have C++20 support in the std library on iOS. Moves iOS tests to run on iPhone 13 and includes a mini_chromium roll to fix Xcode 14.3 egtests. Bug: 40284755 Change-Id: Ic078f07d12473f2aaed5e84df0f0a7fb7b8c35c3 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5443384 Commit-Queue: Justin Cohen Reviewed-by: danakj --- DEPS | 4 ++-- build/run_tests.py | 6 +++--- third_party/cpp-httplib/README.crashpad | 1 + third_party/cpp-httplib/cpp-httplib/httplib.h | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/DEPS b/DEPS index 88f7571c..c8936e0e 100644 --- a/DEPS +++ b/DEPS @@ -29,7 +29,7 @@ vars = { deps = { 'buildtools': Var('chromium_git') + '/chromium/src/buildtools.git@' + - '8b16338d17cd71b04a6ba28da7322ab6739892c2', + '8919328651a559f8a974641d40fe712062cc6718', 'buildtools/clang_format/script': Var('chromium_git') + '/external/github.com/llvm/llvm-project/clang/tools/clang-format.git@' + @@ -47,7 +47,7 @@ deps = { '9719c1e1e676814c456b55f5f070eabad6709d31', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - '203a01130fac64bfdcc8cab2e1798c7b2c0619bf', + 'dce72d97d1c2e9beb5e206c6a05a702269794ca3', 'crashpad/third_party/libfuzzer/src': Var('chromium_git') + '/chromium/llvm-project/compiler-rt/lib/fuzzer.git@' + 'fda403cf93ecb8792cb1d061564d89a6553ca020', diff --git a/build/run_tests.py b/build/run_tests.py index e03e06e7..9079da40 100755 --- a/build/run_tests.py +++ b/build/run_tests.py @@ -313,7 +313,7 @@ def _adb_shell(command_args, env={}): def _RunOnIOSTarget(binary_dir, test, is_xcuitest=False, gtest_filter=None): - """Runs the given iOS |test| app on iPhone 8 with the default OS version.""" + """Runs the given iOS |test| app on a simulator with the default OS version.""" def xctest(binary_dir, test, gtest_filter=None): """Returns a dict containing the xctestrun data needed to run an @@ -368,11 +368,11 @@ def xcuitest(binary_dir, test): with tempfile.NamedTemporaryFile() as f: import plistlib - xctestrun_path = f.name + xctestrun_path = f.name + ".xctestrun" print(xctestrun_path) command = [ 'xcodebuild', 'test-without-building', '-xctestrun', xctestrun_path, - '-destination', 'platform=iOS Simulator,name=iPhone 8', + '-destination', 'platform=iOS Simulator,OS=15.5,name=iPhone 13', ] with open(xctestrun_path, 'wb') as fp: if is_xcuitest: diff --git a/third_party/cpp-httplib/README.crashpad b/third_party/cpp-httplib/README.crashpad index a1ba93aa..8246a735 100644 --- a/third_party/cpp-httplib/README.crashpad +++ b/third_party/cpp-httplib/README.crashpad @@ -14,3 +14,4 @@ Local Modifications: - Exclude test/ and example/ subdirs. - Patch httplib.h to use #include "third_party/zlib/zlib_crashpad.h" instead of . +- Make `this` capture explicit to avoid errors in C++20. diff --git a/third_party/cpp-httplib/cpp-httplib/httplib.h b/third_party/cpp-httplib/cpp-httplib/httplib.h index dadab1d8..1165e260 100644 --- a/third_party/cpp-httplib/cpp-httplib/httplib.h +++ b/third_party/cpp-httplib/cpp-httplib/httplib.h @@ -1684,7 +1684,7 @@ inline bool Server::listen_internal() } // TODO: Use thread pool... - std::thread([=]() { + std::thread([=, this]() { { std::lock_guard guard(running_threads_mutex_); running_threads_++; @@ -1861,7 +1861,7 @@ inline bool Client::is_valid() const inline socket_t Client::create_client_socket() const { return detail::create_socket(host_.c_str(), port_, - [=](socket_t sock, struct addrinfo& ai) -> bool { + [this](socket_t sock, struct addrinfo& ai) -> bool { detail::set_nonblocking(sock, true); auto ret = connect(sock, ai.ai_addr, ai.ai_addrlen); From 8df174c64ca2b9dc0f83b089d30760867966b173 Mon Sep 17 00:00:00 2001 From: Ben Hamilton Date: Mon, 1 Apr 2024 12:44:31 -0600 Subject: [PATCH 106/107] [ios] Fix TSAN issue and Mach port leak in CrashpadClient There were two issues with the iOS implementation of CrashpadClient which I reported in https://crbug.com/crashpad/481: 1) TSAN found a data race in ResetForTesting() when it modified the ScopedMachReceiveRight while the Mach exception port thread was reading it 2) The Mach port connected to the exception server was never deallocated This CL fixes both issues. Change-Id: I5bd4f79ae6d0eccca954d663be7a36f8ceb0a0e8 Bug: https://crbug.com/crashpad/481 Bug: b:332305593 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5410301 Reviewed-by: Mark Mentovai Commit-Queue: Justin Cohen --- client/crashpad_client_ios.cc | 46 ++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/client/crashpad_client_ios.cc b/client/crashpad_client_ios.cc index a34cc15e..663a17c4 100644 --- a/client/crashpad_client_ios.cc +++ b/client/crashpad_client_ios.cc @@ -53,6 +53,40 @@ namespace crashpad { namespace { +// Thread-safe version of `base::apple::ScopedMachReceiveRight` which allocates +// the Mach port upon construction and deallocates it upon destruction. +class ThreadSafeScopedMachPortWithReceiveRight { + public: + ThreadSafeScopedMachPortWithReceiveRight() + : port_(NewMachPort(MACH_PORT_RIGHT_RECEIVE)) {} + + ThreadSafeScopedMachPortWithReceiveRight( + const ThreadSafeScopedMachPortWithReceiveRight&) = delete; + ThreadSafeScopedMachPortWithReceiveRight& operator=( + const ThreadSafeScopedMachPortWithReceiveRight&) = delete; + + ~ThreadSafeScopedMachPortWithReceiveRight() { reset(); } + + mach_port_t get() { return port_.load(); } + void reset() { + mach_port_t old_port = port_.exchange(MACH_PORT_NULL); + if (old_port == MACH_PORT_NULL) { + // Already reset, nothing to do. + return; + } + kern_return_t kr = mach_port_mod_refs( + mach_task_self(), old_port, MACH_PORT_RIGHT_RECEIVE, -1); + MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) + << "ThreadSafeScopedMachPortWithReceiveRight mach_port_mod_refs"; + kr = mach_port_deallocate(mach_task_self(), old_port); + MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) + << "ThreadSafeScopedMachPortWithReceiveRight mach_port_deallocate"; + } + + private: + std::atomic port_; +}; + // A base class for signal handler and Mach exception server. class CrashHandler : public Thread, public UniversalMachExcServer::Interface, @@ -169,14 +203,14 @@ class CrashHandler : public Thread, } bool InstallMachExceptionHandler() { - exception_port_.reset(NewMachPort(MACH_PORT_RIGHT_RECEIVE)); - if (!exception_port_.is_valid()) { + mach_port_t exception_port = exception_port_.get(); + if (exception_port == MACH_PORT_NULL) { return false; } kern_return_t kr = mach_port_insert_right(mach_task_self(), - exception_port_.get(), - exception_port_.get(), + exception_port, + exception_port, MACH_MSG_TYPE_MAKE_SEND); if (kr != KERN_SUCCESS) { MACH_LOG(ERROR, kr) << "mach_port_insert_right"; @@ -194,7 +228,7 @@ class CrashHandler : public Thread, if (!exception_ports.GetExceptionPorts(mask, &original_handlers_) || !exception_ports.SetExceptionPort( mask, - exception_port_.get(), + exception_port, EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, MACHINE_THREAD_STATE)) { return false; @@ -393,7 +427,7 @@ class CrashHandler : public Thread, Signals::RestoreHandlerAndReraiseSignalOnReturn(siginfo, old_action); } - base::apple::ScopedMachReceiveRight exception_port_; + ThreadSafeScopedMachPortWithReceiveRight exception_port_; ExceptionPorts::ExceptionHandlerVector original_handlers_; struct sigaction old_action_ = {}; internal::InProcessHandler in_process_handler_; From 7e0af1d4d45b526f01677e74a56f4a951b70517d Mon Sep 17 00:00:00 2001 From: danakj Date: Thu, 11 Apr 2024 12:48:02 -0400 Subject: [PATCH 107/107] Use byte conversions over the byte swap functions base/sys_byteorder.h is going away. Instead, use the byte conversions in base::numerics to convert from a byte array in big endian to an integer. This avoids putting big endian data into integer types at all. mini_chromium was rolled and crashpad updated to work with newer mac/windows toolchains in order to support C++20 in f9cee5c147db30dc8fa1a048aabd165965b5cb60. Bug: 40284755 Change-Id: If690847b7aa54b0216e73ec297eae3d0bca2fa57 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5402184 Commit-Queue: danakj Reviewed-by: Mark Mentovai --- util/misc/uuid.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/util/misc/uuid.cc b/util/misc/uuid.cc index 15870709..3013d7b2 100644 --- a/util/misc/uuid.cc +++ b/util/misc/uuid.cc @@ -23,13 +23,15 @@ #include #include +#include #include #include +#include "base/containers/span.h" +#include "base/numerics/byte_conversions.h" #include "base/rand_util.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" -#include "base/sys_byteorder.h" #include "build/build_config.h" #if BUILDFLAG(IS_APPLE) @@ -53,11 +55,15 @@ void UUID::InitializeToZero() { memset(this, 0, sizeof(*this)); } -void UUID::InitializeFromBytes(const uint8_t* bytes) { - memcpy(this, bytes, sizeof(*this)); - data_1 = base::NetToHost32(data_1); - data_2 = base::NetToHost16(data_2); - data_3 = base::NetToHost16(data_3); +void UUID::InitializeFromBytes(const uint8_t* bytes_ptr) { + // TODO(crbug.com/40284755): This span construction is unsound. The caller + // should provide a span instead of an unbounded pointer. + base::span bytes(bytes_ptr, sizeof(UUID)); + data_1 = base::numerics::U32FromBigEndian(bytes.subspan<0u, 4u>()); + data_2 = base::numerics::U16FromBigEndian(bytes.subspan<4u, 2u>()); + data_3 = base::numerics::U16FromBigEndian(bytes.subspan<6u, 2u>()); + std::ranges::copy(bytes.subspan<8u, 2u>(), data_4); + std::ranges::copy(bytes.subspan<10u, 6u>(), data_5); } bool UUID::InitializeFromString(const base::StringPiece& string) {