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 <vector> 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 <jperaza@chromium.org>
Commit-Queue: Alan Zhao <ayzhao@google.com>
This commit is contained in:
Alan Zhao 2022-08-30 16:27:51 -04:00 committed by Crashpad LUCI CQ
parent fc2e7c06b8
commit 54da37c2d2
3 changed files with 29 additions and 18 deletions

View File

@ -61,7 +61,8 @@ ScopedHandle DuplicateFromTarget(HANDLE target_process, HANDLE target_handle) {
return ScopedHandle(hTmp); return ScopedHandle(hTmp);
} }
bool ProcessException(std::vector<DWORD>& handled_exceptions, bool ProcessException(DWORD* handled_exceptions,
size_t num_handled_exceptions,
const PVOID pContext, const PVOID pContext,
const PWER_RUNTIME_EXCEPTION_INFORMATION e_info) { const PWER_RUNTIME_EXCEPTION_INFORMATION e_info) {
// Need to have been given a context. // Need to have been given a context.
@ -72,13 +73,15 @@ bool ProcessException(std::vector<DWORD>& handled_exceptions,
return false; return false;
// Only deal with exceptions that crashpad would not have handled. // Only deal with exceptions that crashpad would not have handled.
if (handled_exceptions.size() && bool found = false;
std::find(handled_exceptions.begin(), for (size_t i = 0; i < num_handled_exceptions; i++) {
handled_exceptions.end(), if (handled_exceptions[i] == e_info->exceptionRecord.ExceptionCode) {
e_info->exceptionRecord.ExceptionCode) == found = true;
handled_exceptions.end()) { break;
return false; }
} }
if (!found)
return false;
// Grab out the handles to the crashpad server. // Grab out the handles to the crashpad server.
WerRegistration target_registration = {}; WerRegistration target_registration = {};
@ -168,10 +171,14 @@ bool ProcessException(std::vector<DWORD>& handled_exceptions,
} // namespace } // namespace
bool ExceptionEvent( bool ExceptionEvent(
std::vector<DWORD>& handled_exceptions, DWORD* handled_exceptions,
size_t num_handled_exceptions,
const PVOID pContext, const PVOID pContext,
const PWER_RUNTIME_EXCEPTION_INFORMATION pExceptionInformation) { const PWER_RUNTIME_EXCEPTION_INFORMATION pExceptionInformation) {
return ProcessException(handled_exceptions, pContext, pExceptionInformation); return ProcessException(handled_exceptions,
num_handled_exceptions,
pContext,
pExceptionInformation);
} }
} // namespace crashpad::wer } // namespace crashpad::wer

View File

@ -15,8 +15,6 @@
#ifndef CRASHPAD_HANDLER_WIN_WER_CRASHPAD_WER_H_ #ifndef CRASHPAD_HANDLER_WIN_WER_CRASHPAD_WER_H_
#define CRASHPAD_HANDLER_WIN_WER_CRASHPAD_WER_H_ #define CRASHPAD_HANDLER_WIN_WER_CRASHPAD_WER_H_
#include <vector>
#include <Windows.h> #include <Windows.h>
#include <werapi.h> #include <werapi.h>
@ -26,9 +24,11 @@ namespace crashpad::wer {
//! In the embedder's WER runtime exception helper, call this during //! In the embedder's WER runtime exception helper, call this during
//! OutOfProcessExceptionEventCallback(). //! OutOfProcessExceptionEventCallback().
//! //!
//! \param[in] handled_exceptions is a list of exception codes that the helper //! \param[in] handled_exceptions is an array of exception codes that the helper
//! should pass on to crashpad handler (if possible). Provide an empty list //! should pass on to crashpad handler (if possible). Provide an empty
//! to pass every exception on to the crashpad handler. //! 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] pContext is the context provided by WerFault to the helper.
//! \param[in] pExceptionInformation is the exception information provided by //! \param[in] pExceptionInformation is the exception information provided by
//! WerFault to the helper DLL. //! 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 //! \return `true` if the target process was dumped by the crashpad handler then
//! terminated, or `false` otherwise. //! terminated, or `false` otherwise.
bool ExceptionEvent( bool ExceptionEvent(
std::vector<DWORD>& handled_exceptions, DWORD* handled_exceptions,
size_t num_handled_exceptions,
const PVOID pContext, const PVOID pContext,
const PWER_RUNTIME_EXCEPTION_INFORMATION pExceptionInformation); const PWER_RUNTIME_EXCEPTION_INFORMATION pExceptionInformation);

View File

@ -36,14 +36,17 @@ HRESULT OutOfProcessExceptionEventCallback(
PWSTR pwszEventName, PWSTR pwszEventName,
PDWORD pchSize, PDWORD pchSize,
PDWORD pdwSignatureCount) { PDWORD pdwSignatureCount) {
std::vector<DWORD> wanted_exceptions = { DWORD wanted_exceptions[] = {
0xC0000602, // STATUS_FAIL_FAST_EXCEPTION 0xC0000602, // STATUS_FAIL_FAST_EXCEPTION
0xC0000409, // STATUS_STACK_BUFFER_OVERRUN 0xC0000409, // STATUS_STACK_BUFFER_OVERRUN
}; };
// Default to not-claiming as bailing out is easier. // Default to not-claiming as bailing out is easier.
*pbOwnershipClaimed = FALSE; *pbOwnershipClaimed = FALSE;
bool result = crashpad::wer::ExceptionEvent( bool result =
wanted_exceptions, pContext, pExceptionInformation); crashpad::wer::ExceptionEvent(wanted_exceptions,
sizeof(wanted_exceptions) / sizeof(DWORD),
pContext,
pExceptionInformation);
if (result) { if (result) {
*pbOwnershipClaimed = TRUE; *pbOwnershipClaimed = TRUE;