mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
Use generic VM types in util/process
A step towards making these files usable by non-Linux systems. Bug: crashpad:196 Change-Id: Iaa8bfae1c325735c320e502698a61e4851777649 Reviewed-on: https://chromium-review.googlesource.com/685407 Commit-Queue: Dave Bort <dbort@google.com> Reviewed-by: Mark Mentovai <mark@chromium.org> Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
parent
fe4b16fe88
commit
a99c84b8b4
@ -42,7 +42,7 @@ bool ProcessMemory::Initialize(pid_t pid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProcessMemory::Read(LinuxVMAddress address,
|
||||
bool ProcessMemory::Read(VMAddress address,
|
||||
size_t size,
|
||||
void* buffer) const {
|
||||
DCHECK(mem_fd_.is_valid());
|
||||
@ -67,18 +67,18 @@ bool ProcessMemory::Read(LinuxVMAddress address,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProcessMemory::ReadCString(LinuxVMAddress address,
|
||||
bool ProcessMemory::ReadCString(VMAddress address,
|
||||
std::string* string) const {
|
||||
return ReadCStringInternal(address, false, 0, string);
|
||||
}
|
||||
|
||||
bool ProcessMemory::ReadCStringSizeLimited(LinuxVMAddress address,
|
||||
bool ProcessMemory::ReadCStringSizeLimited(VMAddress address,
|
||||
size_t size,
|
||||
std::string* string) const {
|
||||
return ReadCStringInternal(address, true, size, string);
|
||||
}
|
||||
|
||||
bool ProcessMemory::ReadCStringInternal(LinuxVMAddress address,
|
||||
bool ProcessMemory::ReadCStringInternal(VMAddress address,
|
||||
bool has_size,
|
||||
size_t size,
|
||||
std::string* string) const {
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
#include "base/files/scoped_file.h"
|
||||
#include "base/macros.h"
|
||||
#include "util/linux/address_types.h"
|
||||
#include "util/misc/address_types.h"
|
||||
|
||||
namespace crashpad {
|
||||
|
||||
@ -54,7 +54,7 @@ class ProcessMemory {
|
||||
//!
|
||||
//! \return `true` on success, with \a buffer filled appropriately. `false` on
|
||||
//! failure, with a message logged.
|
||||
bool Read(LinuxVMAddress address, size_t size, void* buffer) const;
|
||||
bool Read(VMAddress address, size_t size, void* buffer) const;
|
||||
|
||||
//! \brief Reads a `NUL`-terminated C string from the target process into a
|
||||
//! string in the current process.
|
||||
@ -69,7 +69,7 @@ class ProcessMemory {
|
||||
//! \return `true` on success, with \a string set appropriately. `false` on
|
||||
//! failure, with a message logged. Failures can occur, for example, when
|
||||
//! encountering unmapped or unreadable pages.
|
||||
bool ReadCString(LinuxVMAddress address, std::string* string) const;
|
||||
bool ReadCString(VMAddress address, std::string* string) const;
|
||||
|
||||
//! \brief Reads a `NUL`-terminated C string from the target process into a
|
||||
//! string in the current process.
|
||||
@ -84,12 +84,12 @@ class ProcessMemory {
|
||||
//! failure, with a message logged. Failures can occur, for example, when
|
||||
//! a `NUL` terminator is not found within \a size bytes, or when
|
||||
//! encountering unmapped or unreadable pages.
|
||||
bool ReadCStringSizeLimited(LinuxVMAddress address,
|
||||
bool ReadCStringSizeLimited(VMAddress address,
|
||||
size_t size,
|
||||
std::string* string) const;
|
||||
|
||||
private:
|
||||
bool ReadCStringInternal(LinuxVMAddress address,
|
||||
bool ReadCStringInternal(VMAddress address,
|
||||
bool has_size,
|
||||
size_t size,
|
||||
std::string* string) const;
|
||||
|
@ -28,8 +28,8 @@ ProcessMemoryRange::~ProcessMemoryRange() {}
|
||||
|
||||
bool ProcessMemoryRange::Initialize(const ProcessMemory* memory,
|
||||
bool is_64_bit,
|
||||
LinuxVMAddress base,
|
||||
LinuxVMSize size) {
|
||||
VMAddress base,
|
||||
VMSize size) {
|
||||
INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
|
||||
memory_ = memory;
|
||||
range_.SetRange(is_64_bit, base, size);
|
||||
@ -43,8 +43,8 @@ bool ProcessMemoryRange::Initialize(const ProcessMemory* memory,
|
||||
|
||||
bool ProcessMemoryRange::Initialize(const ProcessMemory* memory,
|
||||
bool is_64_bit) {
|
||||
LinuxVMSize max = is_64_bit ? std::numeric_limits<uint64_t>::max()
|
||||
: std::numeric_limits<uint32_t>::max();
|
||||
VMSize max = is_64_bit ? std::numeric_limits<uint64_t>::max()
|
||||
: std::numeric_limits<uint32_t>::max();
|
||||
return Initialize(memory, is_64_bit, 0, max);
|
||||
}
|
||||
|
||||
@ -55,9 +55,9 @@ bool ProcessMemoryRange::Initialize(const ProcessMemoryRange& other) {
|
||||
other.range_.Size());
|
||||
}
|
||||
|
||||
bool ProcessMemoryRange::RestrictRange(LinuxVMAddress base, LinuxVMSize size) {
|
||||
bool ProcessMemoryRange::RestrictRange(VMAddress base, VMSize size) {
|
||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
||||
CheckedLinuxAddressRange new_range(range_.Is64Bit(), base, size);
|
||||
CheckedVMAddressRange new_range(range_.Is64Bit(), base, size);
|
||||
if (!new_range.IsValid() || !range_.ContainsRange(new_range)) {
|
||||
LOG(ERROR) << "invalid range";
|
||||
return false;
|
||||
@ -66,11 +66,11 @@ bool ProcessMemoryRange::RestrictRange(LinuxVMAddress base, LinuxVMSize size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProcessMemoryRange::Read(LinuxVMAddress address,
|
||||
bool ProcessMemoryRange::Read(VMAddress address,
|
||||
size_t size,
|
||||
void* buffer) const {
|
||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
||||
CheckedLinuxAddressRange read_range(range_.Is64Bit(), address, size);
|
||||
CheckedVMAddressRange read_range(range_.Is64Bit(), address, size);
|
||||
if (!read_range.IsValid() || !range_.ContainsRange(read_range)) {
|
||||
LOG(ERROR) << "read out of range";
|
||||
return false;
|
||||
@ -78,7 +78,7 @@ bool ProcessMemoryRange::Read(LinuxVMAddress address,
|
||||
return memory_->Read(address, size, buffer);
|
||||
}
|
||||
|
||||
bool ProcessMemoryRange::ReadCStringSizeLimited(LinuxVMAddress address,
|
||||
bool ProcessMemoryRange::ReadCStringSizeLimited(VMAddress address,
|
||||
size_t size,
|
||||
std::string* string) const {
|
||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
||||
@ -86,7 +86,7 @@ bool ProcessMemoryRange::ReadCStringSizeLimited(LinuxVMAddress address,
|
||||
LOG(ERROR) << "read out of range";
|
||||
return false;
|
||||
}
|
||||
size = std::min(static_cast<LinuxVMSize>(size), range_.End() - address);
|
||||
size = std::min(static_cast<VMSize>(size), range_.End() - address);
|
||||
return memory_->ReadCStringSizeLimited(address, size, string);
|
||||
}
|
||||
|
||||
|
@ -20,9 +20,9 @@
|
||||
#include <string>
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "util/linux/address_types.h"
|
||||
#include "util/linux/checked_linux_address_range.h"
|
||||
#include "util/misc/address_types.h"
|
||||
#include "util/misc/initialization_state_dcheck.h"
|
||||
#include "util/numeric/checked_vm_address_range.h"
|
||||
#include "util/process/process_memory.h"
|
||||
|
||||
namespace crashpad {
|
||||
@ -45,8 +45,8 @@ class ProcessMemoryRange {
|
||||
//! \return `true` on success. `false` on failure with a message logged.
|
||||
bool Initialize(const ProcessMemory* memory,
|
||||
bool is_64_bit,
|
||||
LinuxVMAddress base,
|
||||
LinuxVMSize size);
|
||||
VMAddress base,
|
||||
VMSize size);
|
||||
|
||||
//! \brief Initializes this object with the maximum range for the address
|
||||
//! space.
|
||||
@ -71,10 +71,10 @@ class ProcessMemoryRange {
|
||||
bool Is64Bit() const { return range_.Is64Bit(); }
|
||||
|
||||
//! \brief Returns the base address of the range.
|
||||
LinuxVMAddress Base() const { return range_.Base(); }
|
||||
VMAddress Base() const { return range_.Base(); }
|
||||
|
||||
//! \brief Returns the size of the range.
|
||||
LinuxVMSize Size() const { return range_.Size(); }
|
||||
VMSize Size() const { return range_.Size(); }
|
||||
|
||||
//! \brief Shrinks the range to the new base and size.
|
||||
//!
|
||||
@ -83,7 +83,7 @@ class ProcessMemoryRange {
|
||||
//! \param[in] base The new base of the range.
|
||||
//! \param[in] size The new size of the range.
|
||||
//! \return `true` on success. `false` on failure with a message logged.
|
||||
bool RestrictRange(LinuxVMAddress base, LinuxVMSize size);
|
||||
bool RestrictRange(VMAddress base, VMSize size);
|
||||
|
||||
//! \brief Copies memory from the target process into a caller-provided buffer
|
||||
//! in the current process.
|
||||
@ -97,7 +97,7 @@ class ProcessMemoryRange {
|
||||
//!
|
||||
//! \return `true` on success, with \a buffer filled appropriately. `false` on
|
||||
//! failure, with a message logged.
|
||||
bool Read(LinuxVMAddress address, size_t size, void* buffer) const;
|
||||
bool Read(VMAddress address, size_t size, void* buffer) const;
|
||||
|
||||
//! \brief Reads a `NUL`-terminated C string from the target process into a
|
||||
//! string in the current process.
|
||||
@ -112,13 +112,13 @@ class ProcessMemoryRange {
|
||||
//! failure, with a message logged. Failures can occur, for example, when
|
||||
//! a `NUL` terminator is not found within \a size bytes, or when
|
||||
//! encountering unmapped or unreadable pages.
|
||||
bool ReadCStringSizeLimited(LinuxVMAddress address,
|
||||
bool ReadCStringSizeLimited(VMAddress address,
|
||||
size_t size,
|
||||
std::string* string) const;
|
||||
|
||||
private:
|
||||
const ProcessMemory* memory_; // weak
|
||||
CheckedLinuxAddressRange range_;
|
||||
CheckedVMAddressRange range_;
|
||||
InitializationStateDcheck initialized_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ProcessMemoryRange);
|
||||
|
@ -48,7 +48,7 @@ TEST(ProcessMemoryRange, Basic) {
|
||||
EXPECT_EQ(range.Is64Bit(), is_64_bit);
|
||||
|
||||
// Both strings are accessible within the object's range.
|
||||
auto object_addr = FromPointerCast<LinuxVMAddress>(&kTestObject);
|
||||
auto object_addr = FromPointerCast<VMAddress>(&kTestObject);
|
||||
EXPECT_TRUE(range.RestrictRange(object_addr, sizeof(kTestObject)));
|
||||
|
||||
TestObject object;
|
||||
@ -56,8 +56,8 @@ TEST(ProcessMemoryRange, Basic) {
|
||||
EXPECT_EQ(memcmp(&object, &kTestObject, sizeof(object)), 0);
|
||||
|
||||
std::string string;
|
||||
auto string1_addr = FromPointerCast<LinuxVMAddress>(kTestObject.string1);
|
||||
auto string2_addr = FromPointerCast<LinuxVMAddress>(kTestObject.string2);
|
||||
auto string1_addr = FromPointerCast<VMAddress>(kTestObject.string1);
|
||||
auto string2_addr = FromPointerCast<VMAddress>(kTestObject.string2);
|
||||
ASSERT_TRUE(range.ReadCStringSizeLimited(
|
||||
string1_addr, arraysize(kTestObject.string1), &string));
|
||||
EXPECT_STREQ(string.c_str(), kTestObject.string1);
|
||||
|
@ -67,7 +67,7 @@ class ReadTest : public TargetProcessTest {
|
||||
ProcessMemory memory;
|
||||
ASSERT_TRUE(memory.Initialize(pid));
|
||||
|
||||
LinuxVMAddress address = FromPointerCast<LinuxVMAddress>(region_.get());
|
||||
VMAddress address = FromPointerCast<VMAddress>(region_.get());
|
||||
std::unique_ptr<char[]> result(new char[region_size_]);
|
||||
|
||||
// Ensure that the entire region can be read.
|
||||
@ -124,7 +124,7 @@ TEST(ProcessMemory, ReadForked) {
|
||||
bool ReadCString(const ProcessMemory& memory,
|
||||
const char* pointer,
|
||||
std::string* result) {
|
||||
return memory.ReadCString(FromPointerCast<LinuxVMAddress>(pointer), result);
|
||||
return memory.ReadCString(FromPointerCast<VMAddress>(pointer), result);
|
||||
}
|
||||
|
||||
bool ReadCStringSizeLimited(const ProcessMemory& memory,
|
||||
@ -132,7 +132,7 @@ bool ReadCStringSizeLimited(const ProcessMemory& memory,
|
||||
size_t size,
|
||||
std::string* result) {
|
||||
return memory.ReadCStringSizeLimited(
|
||||
FromPointerCast<LinuxVMAddress>(pointer), size, result);
|
||||
FromPointerCast<VMAddress>(pointer), size, result);
|
||||
}
|
||||
|
||||
constexpr char kConstCharEmpty[] = "";
|
||||
@ -261,8 +261,8 @@ class ReadUnmappedTest : public TargetProcessTest {
|
||||
ProcessMemory memory;
|
||||
ASSERT_TRUE(memory.Initialize(pid));
|
||||
|
||||
LinuxVMAddress page_addr1 = pages_.addr_as<LinuxVMAddress>();
|
||||
LinuxVMAddress page_addr2 = page_addr1 + page_size_;
|
||||
VMAddress page_addr1 = pages_.addr_as<VMAddress>();
|
||||
VMAddress page_addr2 = page_addr1 + page_size_;
|
||||
|
||||
EXPECT_TRUE(memory.Read(page_addr1, page_size_, result_.get()));
|
||||
EXPECT_TRUE(memory.Read(page_addr2 - 1, 1, result_.get()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user