From 54da37c2d2c1d847530b485beaaba46f1a1bd20b Mon Sep 17 00:00:00 2001 From: Alan Zhao Date: Tue, 30 Aug 2022 16:27:51 -0400 Subject: [PATCH] Remove std::vector from crashpad_wer When assertions were enabled in Chrome in https://crrev.com/c/3833545, crashpad_wer now requires libc++ to be explicitly included if compiled with -std=c++20 because would now reference symbols defined outside the libc++ headers. We attempted to add libc++ as a dependency in https://crrev.com/c/3862974; however, that was deemed unacceptable because the library needs to be kept small in order for Windows to load it to handle crashes. Therefore, the only alternative is to update the library to remove std::vector Bug: chromium:1357827 Change-Id: I1494204a7bd679fa1632a0f08597cb7e93267196 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3864248 Reviewed-by: Joshua Peraza Commit-Queue: Alan Zhao --- handler/win/wer/crashpad_wer.cc | 25 ++++++++++++++++--------- handler/win/wer/crashpad_wer.h | 13 +++++++------ handler/win/wer/crashpad_wer_main.cc | 9 ++++++--- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/handler/win/wer/crashpad_wer.cc b/handler/win/wer/crashpad_wer.cc index f3de028e..6266fab6 100644 --- a/handler/win/wer/crashpad_wer.cc +++ b/handler/win/wer/crashpad_wer.cc @@ -61,7 +61,8 @@ ScopedHandle DuplicateFromTarget(HANDLE target_process, HANDLE target_handle) { return ScopedHandle(hTmp); } -bool ProcessException(std::vector& handled_exceptions, +bool ProcessException(DWORD* handled_exceptions, + size_t num_handled_exceptions, const PVOID pContext, const PWER_RUNTIME_EXCEPTION_INFORMATION e_info) { // Need to have been given a context. @@ -72,13 +73,15 @@ bool ProcessException(std::vector& handled_exceptions, return false; // Only deal with exceptions that crashpad would not have handled. - if (handled_exceptions.size() && - std::find(handled_exceptions.begin(), - handled_exceptions.end(), - e_info->exceptionRecord.ExceptionCode) == - handled_exceptions.end()) { - return false; + bool found = false; + for (size_t i = 0; i < num_handled_exceptions; i++) { + if (handled_exceptions[i] == e_info->exceptionRecord.ExceptionCode) { + found = true; + break; + } } + if (!found) + return false; // Grab out the handles to the crashpad server. WerRegistration target_registration = {}; @@ -168,10 +171,14 @@ bool ProcessException(std::vector& handled_exceptions, } // namespace bool ExceptionEvent( - std::vector& handled_exceptions, + DWORD* handled_exceptions, + size_t num_handled_exceptions, const PVOID pContext, const PWER_RUNTIME_EXCEPTION_INFORMATION pExceptionInformation) { - return ProcessException(handled_exceptions, pContext, pExceptionInformation); + return ProcessException(handled_exceptions, + num_handled_exceptions, + pContext, + pExceptionInformation); } } // namespace crashpad::wer diff --git a/handler/win/wer/crashpad_wer.h b/handler/win/wer/crashpad_wer.h index 5a3a52f9..1e820207 100644 --- a/handler/win/wer/crashpad_wer.h +++ b/handler/win/wer/crashpad_wer.h @@ -15,8 +15,6 @@ #ifndef CRASHPAD_HANDLER_WIN_WER_CRASHPAD_WER_H_ #define CRASHPAD_HANDLER_WIN_WER_CRASHPAD_WER_H_ -#include - #include #include @@ -26,9 +24,11 @@ namespace crashpad::wer { //! In the embedder's WER runtime exception helper, call this during //! OutOfProcessExceptionEventCallback(). //! -//! \param[in] handled_exceptions is a list of exception codes that the helper -//! should pass on to crashpad handler (if possible). Provide an empty list -//! to pass every exception on to the crashpad handler. +//! \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. +//! \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. //! \param[in] pExceptionInformation is the exception information provided by //! WerFault to the helper DLL. @@ -36,7 +36,8 @@ namespace crashpad::wer { //! \return `true` if the target process was dumped by the crashpad handler then //! terminated, or `false` otherwise. bool ExceptionEvent( - std::vector& handled_exceptions, + 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 4613b353..d33e31eb 100644 --- a/handler/win/wer/crashpad_wer_main.cc +++ b/handler/win/wer/crashpad_wer_main.cc @@ -36,14 +36,17 @@ HRESULT OutOfProcessExceptionEventCallback( PWSTR pwszEventName, PDWORD pchSize, PDWORD pdwSignatureCount) { - std::vector wanted_exceptions = { + 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, pContext, pExceptionInformation); + bool result = + crashpad::wer::ExceptionEvent(wanted_exceptions, + sizeof(wanted_exceptions) / sizeof(DWORD), + pContext, + pExceptionInformation); if (result) { *pbOwnershipClaimed = TRUE;