From 02399418fc472a70a5aef5873a25da956e528cf4 Mon Sep 17 00:00:00 2001 From: Alan Zhao Date: Tue, 13 Sep 2022 13:32:07 -0700 Subject: [PATCH 1/8] Fix comment in crashpad_wer.h Empty arrays aren't allowed in C/C++, so we advise callers to pass nullptr instead. Change-Id: If6724fa5a8b657207337df8b36fa2b3b4fddd955 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3894498 Reviewed-by: Ben Hamilton Commit-Queue: Alan Zhao --- handler/win/wer/crashpad_wer.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/handler/win/wer/crashpad_wer.h b/handler/win/wer/crashpad_wer.h index c47c3b53a6..0dfc7c7350 100644 --- a/handler/win/wer/crashpad_wer.h +++ b/handler/win/wer/crashpad_wer.h @@ -25,8 +25,9 @@ namespace crashpad::wer { //! OutOfProcessExceptionEventCallback(). //! //! \param[in] handled_exceptions is an array of exception codes that the helper -//! should pass on to crashpad handler (if possible). Provide an empty -//! array to pass every exception on to the crashpad handler. +//! should pass on to crashpad handler (if possible). Pass nullptr and set +//! num_handled_exceptions to 0 to pass every exception on to the crashpad +//! handler. //! \param[in] num_handled_exceptions is the number of elements in the array //! passed to handled_exceptions. //! \param[in] pContext is the context provided by WerFault to the helper. From 9f472e5a18d7611adaeb5df727b51102f35e109e Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Thu, 15 Sep 2022 12:31:04 -0700 Subject: [PATCH 2/8] [code-health] Remove .vpython file This file only applies to python 2 and is no longer valid. Bug: 1336295 Change-Id: I55e56275250f28fb7fbe3a2423b934f678c34fa9 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3900797 Reviewed-by: Mark Mentovai Commit-Queue: Mark Mentovai Commit-Queue: Fabrice de Gans --- .vpython | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 .vpython diff --git a/.vpython b/.vpython deleted file mode 100644 index 3086f5d14d..0000000000 --- a/.vpython +++ /dev/null @@ -1,32 +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. - -# This is a vpython "spec" file. -# -# It describes patterns for python wheel dependencies of the python scripts. -# -# Read more about `vpython` and how to modify this file here: -# https://chromium.googlesource.com/infra/infra/+/master/doc/users/vpython.md - -# This is needed for snapshot/win/end_to_end_test.py. -wheel: < - name: "infra/python/wheels/pypiwin32/${vpython_platform}" - version: "version:219" - match_tag: < - platform: "win32" - > - match_tag: < - platform: "win_amd64" - > -> From 833219f1ad4c5c97f45ff6df14d5e53a6b4b382b Mon Sep 17 00:00:00 2001 From: Ben Hamilton Date: Thu, 15 Sep 2022 13:14:19 -0600 Subject: [PATCH 3/8] [ios] Add optional UploadBehavior enum to InProcessHandler::StartProcessingPendingReports() Previously, StartProcessingPendingReports() only started the prune and upload threads if it thought the application was actively running in the foreground. However, some Crashpad clients would like to replicate Breakpad's behavior of allowing uploads while the application is starting up (before it moves to the foreground). This CL introdues an optional UploadBehavior enum to InProcessHandler::StartProcessingPendingReports(), defaulting to the current behavior of only uploading processed crash reports while the application is in the foreground. If the enum is set to UploadBehavior::kUploadImmediately, then InProcessHandler will start the prune and upload threads regardless of the application state. (If the application state later transitions to a non-active state, then InProcessHandler will stop the prune and upload threads as normal.) Change-Id: I4f13f3a3006d636dd3e511b21ccc23a90b2ea639 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3894230 Reviewed-by: Mark Mentovai Commit-Queue: Justin Cohen Reviewed-by: Justin Cohen --- client/BUILD.gn | 1 + client/crashpad_client.h | 11 +++++++- client/crashpad_client_ios.cc | 9 ++++--- client/ios_handler/in_process_handler.cc | 26 ++++++++++++++----- client/ios_handler/in_process_handler.h | 15 +++++++++-- client/upload_behavior_ios.h | 33 ++++++++++++++++++++++++ 6 files changed, 82 insertions(+), 13 deletions(-) create mode 100644 client/upload_behavior_ios.h diff --git a/client/BUILD.gn b/client/BUILD.gn index ca767afd44..3f8880561b 100644 --- a/client/BUILD.gn +++ b/client/BUILD.gn @@ -42,6 +42,7 @@ crashpad_static_library("client") { "ios_handler/prune_intermediate_dumps_and_crash_reports_thread.cc", "ios_handler/prune_intermediate_dumps_and_crash_reports_thread.h", "simulate_crash_ios.h", + "upload_behavior_ios.h", ] } diff --git a/client/crashpad_client.h b/client/crashpad_client.h index fc22467476..412ca68307 100644 --- a/client/crashpad_client.h +++ b/client/crashpad_client.h @@ -39,6 +39,10 @@ #include #endif +#if BUILDFLAG(IS_IOS) +#include "client/upload_behavior_ios.h" +#endif + namespace crashpad { //! \brief The primary interface for an application to have Crashpad monitor @@ -531,7 +535,12 @@ class CrashpadClient { //! on another thread. This method does not block. //! //! A handler must have already been installed before calling this method. - static void StartProcessingPendingReports(); + //! + //! \param[in] upload_behavior Controls when the upload thread will run and + //! process pending reports. By default, only uploads pending reports + //! when the application is active. + static void StartProcessingPendingReports( + UploadBehavior upload_behavior = UploadBehavior::kUploadWhenAppIsActive); //! \brief Requests that the handler capture an intermediate dump even though //! there hasn't been a crash. The intermediate dump will be converted diff --git a/client/crashpad_client_ios.cc b/client/crashpad_client_ios.cc index 7ac14bca63..53adf8d4a9 100644 --- a/client/crashpad_client_ios.cc +++ b/client/crashpad_client_ios.cc @@ -148,9 +148,9 @@ class CrashHandler : public Thread, context, kMachExceptionSimulated, path); } - void StartProcessingPendingReports() { + void StartProcessingPendingReports(UploadBehavior upload_behavior) { INITIALIZATION_STATE_DCHECK_VALID(initialized_); - in_process_handler_.StartProcessingPendingReports(); + in_process_handler_.StartProcessingPendingReports(upload_behavior); } void SetMachExceptionCallbackForTesting(void (*callback)()) { @@ -439,10 +439,11 @@ void CrashpadClient::ProcessIntermediateDump( } // static -void CrashpadClient::StartProcessingPendingReports() { +void CrashpadClient::StartProcessingPendingReports( + UploadBehavior upload_behavior) { CrashHandler* crash_handler = CrashHandler::Get(); DCHECK(crash_handler); - crash_handler->StartProcessingPendingReports(); + crash_handler->StartProcessingPendingReports(upload_behavior); } // static diff --git a/client/ios_handler/in_process_handler.cc b/client/ios_handler/in_process_handler.cc index 7ec943ac28..4dd032f054 100644 --- a/client/ios_handler/in_process_handler.cc +++ b/client/ios_handler/in_process_handler.cc @@ -65,7 +65,7 @@ InProcessHandler::~InProcessHandler() { if (cached_writer_) { cached_writer_->Close(); } - UpdatePruneAndUploadThreads(false); + UpdatePruneAndUploadThreads(false, UploadBehavior::kUploadWhenAppIsActive); } bool InProcessHandler::Initialize( @@ -118,7 +118,8 @@ bool InProcessHandler::Initialize( system_data_.SetActiveApplicationCallback([this](bool active) { dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - UpdatePruneAndUploadThreads(active); + UpdatePruneAndUploadThreads(active, + UploadBehavior::kUploadWhenAppIsActive); }); }); } @@ -272,7 +273,8 @@ void InProcessHandler::ProcessIntermediateDump( } } -void InProcessHandler::StartProcessingPendingReports() { +void InProcessHandler::StartProcessingPendingReports( + UploadBehavior upload_behavior) { if (!upload_thread_) return; @@ -284,15 +286,27 @@ void InProcessHandler::StartProcessingPendingReports() { // TODO(crbug.com/crashpad/400): Consider moving prune and upload thread to // BackgroundTasks and/or NSURLSession. This might allow uploads to continue // in the background. - UpdatePruneAndUploadThreads(system_data_.IsApplicationActive()); + UpdatePruneAndUploadThreads(system_data_.IsApplicationActive(), + upload_behavior); } -void InProcessHandler::UpdatePruneAndUploadThreads(bool active) { +void InProcessHandler::UpdatePruneAndUploadThreads( + bool active, + UploadBehavior upload_behavior) { base::AutoLock lock_owner(prune_and_upload_lock_); // TODO(crbug.com/crashpad/400): Consider moving prune and upload thread to // BackgroundTasks and/or NSURLSession. This might allow uploads to continue // in the background. - if (active) { + bool threads_should_run; + switch (upload_behavior) { + case UploadBehavior::kUploadWhenAppIsActive: + threads_should_run = active; + break; + case UploadBehavior::kUploadImmediately: + threads_should_run = true; + break; + } + if (threads_should_run) { if (!prune_thread_->is_running()) prune_thread_->Start(); if (upload_thread_enabled_ && !upload_thread_->is_running()) { diff --git a/client/ios_handler/in_process_handler.h b/client/ios_handler/in_process_handler.h index 62797b32e5..13c18cb8ef 100644 --- a/client/ios_handler/in_process_handler.h +++ b/client/ios_handler/in_process_handler.h @@ -24,6 +24,7 @@ #include "base/files/file_path.h" #include "base/synchronization/lock.h" #include "client/ios_handler/prune_intermediate_dumps_and_crash_reports_thread.h" +#include "client/upload_behavior_ios.h" #include "handler/crash_report_upload_thread.h" #include "snapshot/ios/process_snapshot_ios_intermediate_dump.h" #include "util/ios/ios_intermediate_dump_writer.h" @@ -172,7 +173,12 @@ class InProcessHandler { //! \brief Requests that the handler begin in-process uploading of any //! pending reports. - void StartProcessingPendingReports(); + //! + //! \param[in] upload_behavior Controls when the upload thread will run and + //! process pending reports. By default, only uploads pending reports + //! when the application is active. + void StartProcessingPendingReports( + UploadBehavior upload_behavior = UploadBehavior::kUploadWhenAppIsActive); //! \brief Inject a callback into Mach handling. Intended to be used by //! tests to trigger a reentrant exception. @@ -224,7 +230,12 @@ class InProcessHandler { }; //! \brief Manage the prune and upload thread when the active state changes. - void UpdatePruneAndUploadThreads(bool active); + //! + //! \param[in] active `true` if the application is actively running in the + //! foreground, `false` otherwise. + //! \param[in] upload_behavior Controls when the upload thread will run and + //! process pending reports. + void UpdatePruneAndUploadThreads(bool active, UploadBehavior upload_behavior); //! \brief Writes a minidump to the Crashpad database from the //! \a process_snapshot, and triggers the upload_thread_ if started. diff --git a/client/upload_behavior_ios.h b/client/upload_behavior_ios.h new file mode 100644 index 0000000000..7e022d8ff4 --- /dev/null +++ b/client/upload_behavior_ios.h @@ -0,0 +1,33 @@ +// Copyright 2022 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_CLIENT_UPLOAD_BEHAVIOR_IOS_H_ +#define CRASHPAD_CLIENT_UPLOAD_BEHAVIOR_IOS_H_ + +namespace crashpad { + +//! \brief Enum to control upload behavior when processing pending reports. +enum class UploadBehavior { + //! \brief Only upload reports while the application is active (e.g., in the + //! foreground). + kUploadWhenAppIsActive = 1, + + //! \brief Upload reports immediately, regardless of whether or not the + //! application is active. + kUploadImmediately = 2, +}; + +} // namespace crashpad + +#endif // CRASHPAD_CLIENT_UPLOAD_BEHAVIOR_IOS_H_ From ca928c8d6b651b7123f1a5cad36dba08ca2416bc Mon Sep 17 00:00:00 2001 From: Alex Gough Date: Mon, 19 Sep 2022 10:28:14 -0700 Subject: [PATCH 4/8] Work around pre 19041 SDK definition SDK definition of WER_RUNTIME_EXCEPTION_INFORMATION changed in SDK 19041 to add the bIsFatal field which we use. This adds a local definition of the newer structure to allow the WER handler to build on earlier SDKs. Bug: crashpad:423 Change-Id: I23bb69cc002ac8d469227e549f29b0af4849c893 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3880663 Reviewed-by: Mark Mentovai Commit-Queue: Alex Gough --- handler/win/wer/BUILD.gn | 1 + handler/win/wer/crashpad_wer.cc | 24 ++++++++++++++++++- .../win/wer/crashpad_wer_module_unittest.cc | 8 +++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/handler/win/wer/BUILD.gn b/handler/win/wer/BUILD.gn index 3c75f6ceaa..71c0126ca3 100644 --- a/handler/win/wer/BUILD.gn +++ b/handler/win/wer/BUILD.gn @@ -43,5 +43,6 @@ source_set("crashpad_wer_test") { "../../../client:client", "../../../test:test", "../../../third_party/googletest:googletest", + "../../../util:util_registration_protocol", ] } diff --git a/handler/win/wer/crashpad_wer.cc b/handler/win/wer/crashpad_wer.cc index 7e62c4f610..b4ca1a55b0 100644 --- a/handler/win/wer/crashpad_wer.cc +++ b/handler/win/wer/crashpad_wer.cc @@ -27,6 +27,18 @@ namespace crashpad::wer { namespace { using crashpad::WerRegistration; +// bIsFatal and dwReserved fields are not present in SDK < 19041. +struct WER_RUNTIME_EXCEPTION_INFORMATION_19041 { + DWORD dwSize; + HANDLE hProcess; + HANDLE hThread; + EXCEPTION_RECORD exceptionRecord; + CONTEXT context; + PCWSTR pwszReportId; + BOOL bIsFatal; + DWORD dwReserved; +}; + // We have our own version of this to avoid pulling in //base. class ScopedHandle { public: @@ -69,8 +81,18 @@ bool ProcessException(DWORD* handled_exceptions, if (!pContext) return false; - if (!e_info->bIsFatal) + // Older OSes might provide a smaller structure than SDK 19041 defines. + if (e_info->dwSize <= + offsetof(WER_RUNTIME_EXCEPTION_INFORMATION_19041, bIsFatal)) { + return false; + } + + // If building with SDK < 19041 then the bIsFatal field isn't defined, so + // use our internal definition here. + if (!reinterpret_cast(e_info) + ->bIsFatal) { return false; + } // Only deal with exceptions that crashpad would not have handled. bool found = false; diff --git a/handler/win/wer/crashpad_wer_module_unittest.cc b/handler/win/wer/crashpad_wer_module_unittest.cc index b5ba548fa4..529398f1df 100644 --- a/handler/win/wer/crashpad_wer_module_unittest.cc +++ b/handler/win/wer/crashpad_wer_module_unittest.cc @@ -56,8 +56,8 @@ TEST(CrashpadWerModule, Basic) { ASSERT_EQ(res, E_FAIL); // Dummy args for OutOfProcessExceptionEventCallback. - crashpad::WerRegistration registration; WER_RUNTIME_EXCEPTION_INFORMATION wer_ex; + wer_ex.dwSize = sizeof(WER_RUNTIME_EXCEPTION_INFORMATION); BOOL bClaimed = FALSE; // No context => skip. @@ -65,6 +65,10 @@ TEST(CrashpadWerModule, Basic) { ASSERT_EQ(res, S_OK); ASSERT_EQ(bClaimed, FALSE); + // Following tests only make sense if building on SDK >= 19041 as + // bIsFatalField only exists after that. +#if defined(NTDDI_WIN10_VB) && (WDK_NTDDI_VERSION >= NTDDI_WIN10_VB) + crashpad::WerRegistration registration; // Non-fatal exceptions are skipped. wer_ex.bIsFatal = FALSE; res = wref(®istration, &wer_ex, &bClaimed, nullptr, nullptr, nullptr); @@ -77,7 +81,7 @@ TEST(CrashpadWerModule, Basic) { res = wref(®istration, &wer_ex, &bClaimed, nullptr, nullptr, nullptr); ASSERT_EQ(res, S_OK); ASSERT_EQ(bClaimed, FALSE); - +#endif // defined(NTDDI_WIN10_VB) && WDK_NTDDI_VERSION >= NTDDI_WIN10_VB FreeLibrary(hMod); } From cca548be8467ce9d6e854467b366ad3a00c487ee Mon Sep 17 00:00:00 2001 From: Alan Zhao Date: Mon, 19 Sep 2022 13:48:20 -0700 Subject: [PATCH 5/8] Minor fixes for crashpad_wer_main.cc These were suggested after https://crrev.com/c/3864248 was submitted. Change-Id: I73c451a3ea52721d8476e229cff7a0aded6746ac Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3902210 Commit-Queue: Alan Zhao Reviewed-by: Mark Mentovai Commit-Queue: Mark Mentovai --- handler/win/wer/crashpad_wer.cc | 4 ++-- handler/win/wer/crashpad_wer.h | 2 +- handler/win/wer/crashpad_wer_main.cc | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/handler/win/wer/crashpad_wer.cc b/handler/win/wer/crashpad_wer.cc index b4ca1a55b0..3379d00d2d 100644 --- a/handler/win/wer/crashpad_wer.cc +++ b/handler/win/wer/crashpad_wer.cc @@ -73,7 +73,7 @@ ScopedHandle DuplicateFromTarget(HANDLE target_process, HANDLE target_handle) { return ScopedHandle(hTmp); } -bool ProcessException(DWORD* handled_exceptions, +bool ProcessException(const DWORD* handled_exceptions, size_t num_handled_exceptions, const PVOID pContext, const PWER_RUNTIME_EXCEPTION_INFORMATION e_info) { @@ -193,7 +193,7 @@ bool ProcessException(DWORD* handled_exceptions, } // namespace bool ExceptionEvent( - DWORD* handled_exceptions, + const DWORD* handled_exceptions, size_t num_handled_exceptions, const PVOID pContext, const PWER_RUNTIME_EXCEPTION_INFORMATION pExceptionInformation) { diff --git a/handler/win/wer/crashpad_wer.h b/handler/win/wer/crashpad_wer.h index 0dfc7c7350..ee99e40c84 100644 --- a/handler/win/wer/crashpad_wer.h +++ b/handler/win/wer/crashpad_wer.h @@ -37,7 +37,7 @@ namespace crashpad::wer { //! \return `true` if the target process was dumped by the crashpad handler then //! terminated, or `false` otherwise. bool ExceptionEvent( - DWORD* handled_exceptions, + const DWORD* handled_exceptions, size_t num_handled_exceptions, const PVOID pContext, const PWER_RUNTIME_EXCEPTION_INFORMATION pExceptionInformation); diff --git a/handler/win/wer/crashpad_wer_main.cc b/handler/win/wer/crashpad_wer_main.cc index 693752034d..1b767e38b3 100644 --- a/handler/win/wer/crashpad_wer_main.cc +++ b/handler/win/wer/crashpad_wer_main.cc @@ -36,17 +36,17 @@ HRESULT OutOfProcessExceptionEventCallback( PWSTR pwszEventName, PDWORD pchSize, PDWORD pdwSignatureCount) { - DWORD wanted_exceptions[] = { + static constexpr DWORD wanted_exceptions[] = { 0xC0000602, // STATUS_FAIL_FAST_EXCEPTION 0xC0000409, // STATUS_STACK_BUFFER_OVERRUN }; // Default to not-claiming as bailing out is easier. *pbOwnershipClaimed = FALSE; - bool result = - crashpad::wer::ExceptionEvent(wanted_exceptions, - sizeof(wanted_exceptions) / sizeof(DWORD), - pContext, - pExceptionInformation); + bool result = crashpad::wer::ExceptionEvent( + wanted_exceptions, + sizeof(wanted_exceptions) / sizeof(wanted_exceptions[0]), + pContext, + pExceptionInformation); if (result) { *pbOwnershipClaimed = TRUE; From 0acdadf032955add4a996332c19e08f7cecd7558 Mon Sep 17 00:00:00 2001 From: Stephan Hartmann Date: Fri, 30 Sep 2022 14:07:07 +0200 Subject: [PATCH 6/8] snapshot: remove redundant template parameter GCC 12 does not allow it in C++20 mode anymore. Bug: chromium:819294 Change-Id: I025dda8046739fefc4ff449d4496ef496374eff5 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3929186 Commit-Queue: Mark Mentovai Reviewed-by: Mark Mentovai --- snapshot/elf/elf_image_reader.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snapshot/elf/elf_image_reader.cc b/snapshot/elf/elf_image_reader.cc index 9d3ba43ab0..30e8b987c0 100644 --- a/snapshot/elf/elf_image_reader.cc +++ b/snapshot/elf/elf_image_reader.cc @@ -56,14 +56,14 @@ template class ElfImageReader::ProgramHeaderTableSpecific : public ElfImageReader::ProgramHeaderTable { public: - ProgramHeaderTableSpecific() {} + ProgramHeaderTableSpecific() {} - ProgramHeaderTableSpecific( + ProgramHeaderTableSpecific( const ProgramHeaderTableSpecific&) = delete; ProgramHeaderTableSpecific& operator=( const ProgramHeaderTableSpecific&) = delete; - ~ProgramHeaderTableSpecific() {} + ~ProgramHeaderTableSpecific() {} bool Initialize(const ProcessMemoryRange& memory, VMAddress address, From b00da64ac856adf5f9bde404c5842f0904392cb5 Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Tue, 4 Oct 2022 17:38:56 -0400 Subject: [PATCH 7/8] ios: Correct iOS forbidden allocators on iOS 16.1 There's a new try_free_default in malloc zone 13, and tests now need to replace zone functions in all zones, not just the default zone. Change-Id: I5a9893a73f8c9f7068e52bf25f57632f9e409aa2 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3934555 Reviewed-by: Joshua Peraza Commit-Queue: Justin Cohen --- test/ios/host/handler_forbidden_allocators.cc | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/ios/host/handler_forbidden_allocators.cc b/test/ios/host/handler_forbidden_allocators.cc index 8c234388d0..34e93e3a62 100644 --- a/test/ios/host/handler_forbidden_allocators.cc +++ b/test/ios/host/handler_forbidden_allocators.cc @@ -154,6 +154,18 @@ boolean_t handler_forbidden_claimed_address(struct _malloc_zone_t* zone, return g_old_zone.claimed_address(zone, ptr); } +#if defined(__IPHONE_16_1) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_16_1 +void handler_forbidden_try_free_default(struct _malloc_zone_t* zone, + void* ptr) { + if (is_handler_thread()) { + CRASHPAD_RAW_LOG( + "handler_forbidden_try_free_default allocator used in handler."); + exit(EXIT_FAILURE); + } + g_old_zone.try_free_default(zone, ptr); +} +#endif + size_t handler_forbidden_size(struct _malloc_zone_t* zone, const void* ptr) { if (is_handler_thread()) { CRASHPAD_RAW_LOG("handler_forbidden_size allocator used in handler."); @@ -246,6 +258,11 @@ void ReplaceZoneFunctions(malloc_zone_t* zone, const malloc_zone_t* functions) { zone->free_definite_size = functions->free_definite_size; zone->pressure_relief = functions->pressure_relief; zone->claimed_address = functions->claimed_address; +#if defined(__IPHONE_16_1) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_16_1 + if (zone->version >= 13 && functions->try_free_default) { + zone->try_free_default = functions->try_free_default; + } +#endif // Restore protection if it was active. if (reprotection_start) { @@ -285,8 +302,22 @@ void ReplaceAllocatorsWithHandlerForbidden() { new_functions.free_definite_size = handler_forbidden_free_definite_size; new_functions.pressure_relief = handler_forbidden_pressure_relief; new_functions.claimed_address = handler_forbidden_claimed_address; +#if defined(__IPHONE_16_1) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_16_1 + new_functions.try_free_default = handler_forbidden_try_free_default; +#endif ReplaceZoneFunctions(default_zone, &new_functions); + vm_address_t* zones; + unsigned int count; + kern_return_t kr = + malloc_get_all_zones(mach_task_self(), nullptr, &zones, &count); + if (kr != KERN_SUCCESS) + return; + for (unsigned int i = 0; i < count; ++i) { + malloc_zone_t* zone = reinterpret_cast(zones[i]); + ReplaceZoneFunctions(zone, &new_functions); + } + malloc_zone_t* purgeable_zone = malloc_default_purgeable_zone(); ReplaceZoneFunctions(purgeable_zone, &new_functions); } From 31af46b91e94d8c86cd3e5ab0ba11078e5555f6a Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Thu, 6 Oct 2022 22:57:42 -0400 Subject: [PATCH 8/8] Update copyright boilerplate in third_party/edo From https://chromium-review.googlesource.com/c/3936784/1/third_party/crashpad/crashpad/third_party/edo/BUILD.gn. Bug: chromium:1098010 Change-Id: Ia18db07d4d9be43c0dae5eb84d91dd68531a75e3 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3938565 Commit-Queue: Mark Mentovai Reviewed-by: Joshua Peraza --- third_party/edo/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/edo/BUILD.gn b/third_party/edo/BUILD.gn index ea6e9d38b4..00a486cbb1 100644 --- a/third_party/edo/BUILD.gn +++ b/third_party/edo/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright 2018 The Chromium Authors. All rights reserved. +# Copyright 2018 The Chromium Authors. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file.