mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
Use best-effort allocation in ProcessInfo::BuildHandleVector.
BUG=crashpad:158 Change-Id: If8666140a7fc5315eeb791d0998226de89a22cc3 Reviewed-on: https://chromium-review.googlesource.com/438791 Reviewed-by: Mark Mentovai <mark@chromium.org> Reviewed-by: Scott Graham <scottmg@chromium.org>
This commit is contained in:
parent
88442dd578
commit
6af23a933a
2
DEPS
2
DEPS
@ -38,7 +38,7 @@ deps = {
|
|||||||
|
|
||||||
'crashpad/third_party/mini_chromium/mini_chromium':
|
'crashpad/third_party/mini_chromium/mini_chromium':
|
||||||
Var('chromium_git') + '/chromium/mini_chromium@' +
|
Var('chromium_git') + '/chromium/mini_chromium@' +
|
||||||
'4f3cfc8e7c2b7d77f94f41a32c3ec84a6920f05d',
|
'f65519e442d23498937251e680a3b113927613b0',
|
||||||
}
|
}
|
||||||
|
|
||||||
hooks = [
|
hooks = [
|
||||||
|
@ -19,9 +19,12 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <new>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
|
#include "base/memory/free_deleter.h"
|
||||||
|
#include "base/process/memory.h"
|
||||||
#include "base/strings/stringprintf.h"
|
#include "base/strings/stringprintf.h"
|
||||||
#include "build/build_config.h"
|
#include "build/build_config.h"
|
||||||
#include "util/numeric/safe_assignment.h"
|
#include "util/numeric/safe_assignment.h"
|
||||||
@ -36,6 +39,16 @@ namespace crashpad {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using UniqueMallocPtr = std::unique_ptr<uint8_t[], base::FreeDeleter>;
|
||||||
|
|
||||||
|
UniqueMallocPtr UncheckedAllocate(size_t size) {
|
||||||
|
void* raw_ptr = nullptr;
|
||||||
|
if (!base::UncheckedMalloc(size, &raw_ptr))
|
||||||
|
return UniqueMallocPtr();
|
||||||
|
|
||||||
|
return UniqueMallocPtr(new (raw_ptr) uint8_t[size]);
|
||||||
|
}
|
||||||
|
|
||||||
NTSTATUS NtQueryInformationProcess(HANDLE process_handle,
|
NTSTATUS NtQueryInformationProcess(HANDLE process_handle,
|
||||||
PROCESSINFOCLASS process_information_class,
|
PROCESSINFOCLASS process_information_class,
|
||||||
PVOID process_information,
|
PVOID process_information,
|
||||||
@ -347,14 +360,20 @@ bool ReadMemoryInfo(HANDLE process, bool is_64_bit, ProcessInfo* process_info) {
|
|||||||
std::vector<ProcessInfo::Handle> ProcessInfo::BuildHandleVector(
|
std::vector<ProcessInfo::Handle> ProcessInfo::BuildHandleVector(
|
||||||
HANDLE process) const {
|
HANDLE process) const {
|
||||||
ULONG buffer_size = 2 * 1024 * 1024;
|
ULONG buffer_size = 2 * 1024 * 1024;
|
||||||
std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]);
|
|
||||||
|
|
||||||
// Typically if the buffer were too small, STATUS_INFO_LENGTH_MISMATCH would
|
// Typically if the buffer were too small, STATUS_INFO_LENGTH_MISMATCH would
|
||||||
// return the correct size in the final argument, but it does not for
|
// return the correct size in the final argument, but it does not for
|
||||||
// SystemExtendedHandleInformation, so we loop and attempt larger sizes.
|
// SystemExtendedHandleInformation, so we loop and attempt larger sizes.
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
ULONG returned_length;
|
ULONG returned_length;
|
||||||
|
UniqueMallocPtr buffer;
|
||||||
for (int tries = 0; tries < 5; ++tries) {
|
for (int tries = 0; tries < 5; ++tries) {
|
||||||
|
buffer.reset();
|
||||||
|
buffer = UncheckedAllocate(buffer_size);
|
||||||
|
if (!buffer) {
|
||||||
|
LOG(ERROR) << "UncheckedAllocate";
|
||||||
|
return std::vector<Handle>();
|
||||||
|
}
|
||||||
|
|
||||||
status = crashpad::NtQuerySystemInformation(
|
status = crashpad::NtQuerySystemInformation(
|
||||||
static_cast<SYSTEM_INFORMATION_CLASS>(SystemExtendedHandleInformation),
|
static_cast<SYSTEM_INFORMATION_CLASS>(SystemExtendedHandleInformation),
|
||||||
buffer.get(),
|
buffer.get(),
|
||||||
@ -364,8 +383,6 @@ std::vector<ProcessInfo::Handle> ProcessInfo::BuildHandleVector(
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
buffer_size *= 2;
|
buffer_size *= 2;
|
||||||
buffer.reset();
|
|
||||||
buffer.reset(new uint8_t[buffer_size]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NT_SUCCESS(status)) {
|
if (!NT_SUCCESS(status)) {
|
||||||
|
@ -170,6 +170,7 @@ class ProcessInfo {
|
|||||||
bool is_64_bit,
|
bool is_64_bit,
|
||||||
ProcessInfo* process_info);
|
ProcessInfo* process_info);
|
||||||
|
|
||||||
|
// This function is best-effort under low memory conditions.
|
||||||
std::vector<Handle> BuildHandleVector(HANDLE process) const;
|
std::vector<Handle> BuildHandleVector(HANDLE process) const;
|
||||||
|
|
||||||
pid_t process_id_;
|
pid_t process_id_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user