From 1ea22d4cdd0ca657e2b2425f72955333400fb3e2 Mon Sep 17 00:00:00 2001 From: Gabriele Svelto Date: Wed, 29 Sep 2021 07:58:13 +0000 Subject: [PATCH] Bug 1730222 - Support PHC on macOS when running on ARM-based machines r=glandium This also tightens the check for PHC-type crashes in the exception handler so that we don't accidentally try to interpret unrelated crash types as potential PHC ones. Differential Revision: https://phabricator.services.mozilla.com/D126365 --- memory/replace/phc/PHC.cpp | 24 ++++++++++++++----- .../mac/handler/exception_handler.cc | 6 ++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/memory/replace/phc/PHC.cpp b/memory/replace/phc/PHC.cpp index bdf6450d25e8..43bd38c0e2ad 100644 --- a/memory/replace/phc/PHC.cpp +++ b/memory/replace/phc/PHC.cpp @@ -55,12 +55,16 @@ // // The basic cost of PHC's operation is as follows. // -// - The physical memory cost is 64 * 4 KiB = 256 KiB per process (assuming 4 -// KiB pages) plus some metadata (including stack traces) for each page. +// - The physical memory cost is 64 pages plus some metadata (including stack +// traces) for each page. This amounts to 256 KiB per process on +// architectures with 4 KiB pages and 1024 KiB on macOS/AArch64 which uses +// 16 KiB pages. // // - The virtual memory cost is the physical memory cost plus the guard pages: -// another 64 * 4 KiB = 256 KiB per process. PHC is currently only enabled on -// 64-bit platforms so the impact of the virtual memory usage is negligible. +// another 64 pages. This amounts to another 256 KiB per process on +// architectures with 4 KiB pages and 1024 KiB on macOS/AArch64 which uses +// 16 KiB pages. PHC is currently only enabled on 64-bit platforms so the +// impact of the virtual memory usage is negligible. // // - Every allocation requires a size check and a decrement-and-check of an // atomic counter. When the counter reaches zero a PHC allocation can occur, @@ -283,8 +287,16 @@ using Time = uint64_t; // A moment in time. using Delay = uint32_t; // A time duration. // PHC only runs if the page size is 4 KiB; anything more is uncommon and would -// use too much memory. So we hardwire this size. -static const size_t kPageSize = 4096; +// use too much memory. So we hardwire this size for all platforms but macOS +// on ARM processors. For the latter we make an exception because the minimum +// page size supported is 16KiB so there's no way to go below that. +static const size_t kPageSize = +#if defined(XP_MACOSX) && defined(__aarch64__) + 16384 +#else + 4096 +#endif + ; // There are two kinds of page. // - Allocation pages, from which allocations are made. diff --git a/toolkit/crashreporter/breakpad-client/mac/handler/exception_handler.cc b/toolkit/crashreporter/breakpad-client/mac/handler/exception_handler.cc index 3eba88ba2494..4abc295d9180 100644 --- a/toolkit/crashreporter/breakpad-client/mac/handler/exception_handler.cc +++ b/toolkit/crashreporter/breakpad-client/mac/handler/exception_handler.cc @@ -413,10 +413,10 @@ bool ExceptionHandler::WriteMinidumpForChild(mach_port_t child, } #ifdef MOZ_PHC -static void GetPHCAddrInfo(int64_t exception_subcode, +static void GetPHCAddrInfo(int exception_type, int64_t exception_subcode, mozilla::phc::AddrInfo* addr_info) { // Is this a crash involving a PHC allocation? - if (exception_subcode) { + if (exception_type == EXC_BAD_ACCESS) { // `exception_subcode` is only non-zero when it's a bad access, in which // case it holds the address of the bad access. char* addr = reinterpret_cast(exception_subcode); @@ -443,7 +443,7 @@ bool ExceptionHandler::WriteMinidumpWithException( mozilla::phc::AddrInfo addr_info; #ifdef MOZ_PHC - GetPHCAddrInfo(exception_subcode, &addr_info); + GetPHCAddrInfo(exception_type, exception_subcode, &addr_info); #endif if (directCallback_) {