Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update from upstream 2022-10-17 #74

Merged
merged 9 commits into from
Oct 19, 2022
32 changes: 0 additions & 32 deletions .vpython

This file was deleted.

1 change: 1 addition & 0 deletions client/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
}

Expand Down
11 changes: 10 additions & 1 deletion client/crashpad_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
#include <ucontext.h>
#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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions client/crashpad_client_ios.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)()) {
Expand Down Expand Up @@ -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
Expand Down
26 changes: 20 additions & 6 deletions client/ios_handler/in_process_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ InProcessHandler::~InProcessHandler() {
if (cached_writer_) {
cached_writer_->Close();
}
UpdatePruneAndUploadThreads(false);
UpdatePruneAndUploadThreads(false, UploadBehavior::kUploadWhenAppIsActive);
}

bool InProcessHandler::Initialize(
Expand Down Expand Up @@ -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);
});
});
}
Expand Down Expand Up @@ -272,7 +273,8 @@ void InProcessHandler::ProcessIntermediateDump(
}
}

void InProcessHandler::StartProcessingPendingReports() {
void InProcessHandler::StartProcessingPendingReports(
UploadBehavior upload_behavior) {
if (!upload_thread_)
return;

Expand All @@ -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()) {
Expand Down
15 changes: 13 additions & 2 deletions client/ios_handler/in_process_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
33 changes: 33 additions & 0 deletions client/upload_behavior_ios.h
Original file line number Diff line number Diff line change
@@ -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_
1 change: 1 addition & 0 deletions handler/win/wer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ source_set("crashpad_wer_test") {
"../../../client:client",
"../../../test:test",
"../../../third_party/googletest:googletest",
"../../../util:util_registration_protocol",
]
}
28 changes: 25 additions & 3 deletions handler/win/wer/crashpad_wer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -61,16 +73,26 @@ 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) {
// Need to have been given a context.
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<const WER_RUNTIME_EXCEPTION_INFORMATION_19041*>(e_info)
->bIsFatal) {
return false;
}

// Only deal with exceptions that crashpad would not have handled.
bool found = false;
Expand Down Expand Up @@ -171,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) {
Expand Down
7 changes: 4 additions & 3 deletions handler/win/wer/crashpad_wer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -36,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);
Expand Down
12 changes: 6 additions & 6 deletions handler/win/wer/crashpad_wer_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions handler/win/wer/crashpad_wer_module_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,19 @@ 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.
res = wref(nullptr, &wer_ex, &bClaimed, nullptr, nullptr, nullptr);
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(&registration, &wer_ex, &bClaimed, nullptr, nullptr, nullptr);
Expand All @@ -77,7 +81,7 @@ TEST(CrashpadWerModule, Basic) {
res = wref(&registration, &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);
}

Expand Down
6 changes: 3 additions & 3 deletions snapshot/elf/elf_image_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ template <typename PhdrType>
class ElfImageReader::ProgramHeaderTableSpecific
: public ElfImageReader::ProgramHeaderTable {
public:
ProgramHeaderTableSpecific<PhdrType>() {}
ProgramHeaderTableSpecific() {}

ProgramHeaderTableSpecific<PhdrType>(
ProgramHeaderTableSpecific(
const ProgramHeaderTableSpecific<PhdrType>&) = delete;
ProgramHeaderTableSpecific<PhdrType>& operator=(
const ProgramHeaderTableSpecific<PhdrType>&) = delete;

~ProgramHeaderTableSpecific<PhdrType>() {}
~ProgramHeaderTableSpecific() {}

bool Initialize(const ProcessMemoryRange& memory,
VMAddress address,
Expand Down
Loading