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);
}
bool ProcessException(std::vector<DWORD>& 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<DWORD>& 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<DWORD>& handled_exceptions,
} // namespace
bool ExceptionEvent(
std::vector<DWORD>& 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

View File

@ -15,8 +15,6 @@
#ifndef CRASHPAD_HANDLER_WIN_WER_CRASHPAD_WER_H_
#define CRASHPAD_HANDLER_WIN_WER_CRASHPAD_WER_H_
#include <vector>
#include <Windows.h>
#include <werapi.h>
@ -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<DWORD>& handled_exceptions,
DWORD* handled_exceptions,
size_t num_handled_exceptions,
const PVOID pContext,
const PWER_RUNTIME_EXCEPTION_INFORMATION pExceptionInformation);

View File

@ -36,14 +36,17 @@ HRESULT OutOfProcessExceptionEventCallback(
PWSTR pwszEventName,
PDWORD pchSize,
PDWORD pdwSignatureCount) {
std::vector<DWORD> 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;