Move and rename TaskMemory to ProcessMemoryMac

Bug: crashpad:263
Change-Id: I5efa4fe26f09c8b8a8db6dbcedc416724404b894
Reviewed-on: https://chromium-review.googlesource.com/c/1387884
Commit-Queue: Vlad Tsyrklevich <vtsyrklevich@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Vlad Tsyrklevich 2018-12-20 13:12:55 -08:00 committed by Commit Bot
parent 3f7d4d7d09
commit 3b9e3aad1b
14 changed files with 67 additions and 69 deletions

View File

@ -26,7 +26,6 @@
#include "snapshot/mac/mach_o_image_reader.h"
#include "snapshot/mac/process_reader_mac.h"
#include "snapshot/snapshot_constants.h"
#include "util/mach/task_memory.h"
#include "util/stdlib/strnlen.h"
namespace crashpad {

View File

@ -23,7 +23,7 @@
#include "base/strings/stringprintf.h"
#include "util/mac/checked_mach_address_range.h"
#include "util/mach/task_memory.h"
#include "util/process/process_memory_mac.h"
namespace crashpad {
@ -108,7 +108,7 @@ class MachOImageSymbolTableReaderInitializer {
return false;
}
std::unique_ptr<TaskMemory::MappedMemory> string_table;
std::unique_ptr<ProcessMemoryMac::MappedMemory> string_table;
for (size_t symbol_index = 0; symbol_index < symbol_count; ++symbol_index) {
const process_types::nlist& symbol = symbols[symbol_index];
std::string symbol_info = base::StringPrintf(", symbol index %zu%s",

View File

@ -58,7 +58,7 @@ class MachOImageSymbolTableReader {
// there arent expected to be very many of those that performance would
// become a problem. In reality, std::unordered_map does not appear to provide
// a performance advantage. It appears that the memory copies currently done
// by TaskMemory::Read() have substantially more impact on symbol table
// by ProcessMemoryMac::Read() have substantially more impact on symbol table
// operations.
//
// This is public so that the type is available to

View File

@ -92,7 +92,7 @@ ProcessReaderMac::ProcessReaderMac()
threads_(),
modules_(),
module_readers_(),
task_memory_(),
process_memory_(),
task_(TASK_NULL),
initialized_(),
is_64_bit_(false),
@ -113,7 +113,7 @@ bool ProcessReaderMac::Initialize(task_t task) {
return false;
}
if (!task_memory_.Initialize(task)) {
if (!process_memory_.Initialize(task)) {
return false;
}
@ -443,7 +443,7 @@ void ProcessReaderMac::InitializeModules() {
Module module;
module.timestamp = image_info.imageFileModDate;
if (!task_memory_.ReadCString(image_info.imageFilePath, &module.name)) {
if (!process_memory_.ReadCString(image_info.imageFilePath, &module.name)) {
LOG(WARNING) << "could not read dyld_image_info::imageFilePath";
// Proceed anyway with an empty module name.
}

View File

@ -27,9 +27,9 @@
#include "base/macros.h"
#include "build/build_config.h"
#include "util/mach/task_memory.h"
#include "util/misc/initialization_state_dcheck.h"
#include "util/posix/process_info.h"
#include "util/process/process_memory_mac.h"
namespace crashpad {
@ -138,7 +138,7 @@ class ProcessReaderMac {
bool CPUTimes(timeval* user_time, timeval* system_time) const;
//! \return Accesses the memory of the target task.
TaskMemory* Memory() { return &task_memory_; }
ProcessMemoryMac* Memory() { return &process_memory_; }
//! \return The threads that are in the task (process). The first element (at
//! index `0`) corresponds to the main thread.
@ -232,7 +232,7 @@ class ProcessReaderMac {
std::vector<Thread> threads_; // owns send rights
std::vector<Module> modules_;
std::vector<std::unique_ptr<MachOImageReader>> module_readers_;
TaskMemory task_memory_;
ProcessMemoryMac process_memory_;
task_t task_; // weak
InitializationStateDcheck initialized_;

View File

@ -22,7 +22,7 @@
#include "base/macros.h"
#include "snapshot/mac/process_types/internal.h"
#include "util/mach/task_memory.h"
#include "util/process/process_memory_mac.h"
namespace crashpad {
namespace {

View File

@ -25,7 +25,7 @@
#include "base/numerics/safe_math.h"
#include "base/strings/stringprintf.h"
#include "snapshot/mac/process_types/internal.h"
#include "util/mach/task_memory.h"
#include "util/process/process_memory_mac.h"
#if !DOXYGEN
@ -36,13 +36,13 @@ namespace internal {
namespace {
template <typename T>
bool ReadIntoAndZero(TaskMemory* task_memory,
bool ReadIntoAndZero(ProcessMemoryMac* process_memory,
mach_vm_address_t address,
mach_vm_size_t size,
T* specific) {
DCHECK_LE(size, sizeof(*specific));
if (!task_memory->Read(address, size, specific)) {
if (!process_memory->Read(address, size, specific)) {
return false;
}
@ -84,14 +84,14 @@ bool ReadIntoVersioned(ProcessReaderMac* process_reader,
return false;
}
TaskMemory* task_memory = process_reader->Memory();
ProcessMemoryMac* process_memory = process_reader->Memory();
decltype(specific->version) version;
if (!task_memory->Read(field_address, sizeof(version), &version)) {
if (!process_memory->Read(field_address, sizeof(version), &version)) {
return false;
}
const size_t size = T::ExpectedSizeForVersion(version);
return ReadIntoAndZero(task_memory, address, size, specific);
return ReadIntoAndZero(process_memory, address, size, specific);
}
template <typename T>
@ -103,9 +103,9 @@ bool ReadIntoSized(ProcessReaderMac* process_reader,
return false;
}
TaskMemory* task_memory = process_reader->Memory();
ProcessMemoryMac* process_memory = process_reader->Memory();
decltype(specific->size) size;
if (!task_memory->Read(address + offsetof(T, size), sizeof(size), &size)) {
if (!process_memory->Read(address + offsetof(T, size), sizeof(size), &size)) {
return false;
}
@ -115,7 +115,7 @@ bool ReadIntoSized(ProcessReaderMac* process_reader,
}
size = std::min(static_cast<size_t>(size), sizeof(*specific));
return ReadIntoAndZero(task_memory, address, size, specific);
return ReadIntoAndZero(process_memory, address, size, specific);
}
} // namespace

View File

@ -244,13 +244,13 @@ static_library("util") {
"mach/symbolic_constants_mach.h",
"mach/task_for_pid.cc",
"mach/task_for_pid.h",
"mach/task_memory.cc",
"mach/task_memory.h",
"misc/capture_context_mac.S",
"misc/clock_mac.cc",
"misc/paths_mac.cc",
"net/http_transport_mac.mm",
"posix/process_info_mac.cc",
"process/process_memory_mac.cc",
"process/process_memory_mac.h",
"synchronization/semaphore_mac.cc",
]
sources += get_target_outputs(":mig")
@ -605,8 +605,8 @@ source_set("util_test") {
"mach/notify_server_test.cc",
"mach/scoped_task_suspend_test.cc",
"mach/symbolic_constants_mach_test.cc",
"mach/task_memory_test.cc",
"misc/capture_context_test_util_mac.cc",
"process/process_memory_mac_test.cc",
]
}

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "util/mach/task_memory.h"
#include "util/process/process_memory_mac.h"
#include <mach/mach_vm.h>
#include <string.h>
@ -26,11 +26,10 @@
namespace crashpad {
TaskMemory::MappedMemory::~MappedMemory() {
}
ProcessMemoryMac::MappedMemory::~MappedMemory() {}
bool TaskMemory::MappedMemory::ReadCString(
size_t offset, std::string* string) const {
bool ProcessMemoryMac::MappedMemory::ReadCString(size_t offset,
std::string* string) const {
if (offset >= user_size_) {
LOG(WARNING) << "offset out of range";
return false;
@ -48,7 +47,7 @@ bool TaskMemory::MappedMemory::ReadCString(
return true;
}
TaskMemory::MappedMemory::MappedMemory(vm_address_t vm_address,
ProcessMemoryMac::MappedMemory::MappedMemory(vm_address_t vm_address,
size_t vm_size,
size_t user_offset,
size_t user_size)
@ -64,16 +63,16 @@ TaskMemory::MappedMemory::MappedMemory(vm_address_t vm_address,
DCHECK_LE(user_end, vm_end);
}
TaskMemory::TaskMemory() : task_(TASK_NULL), initialized_() {}
ProcessMemoryMac::ProcessMemoryMac() : task_(TASK_NULL), initialized_() {}
bool TaskMemory::Initialize(task_t task) {
bool ProcessMemoryMac::Initialize(task_t task) {
INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
task_ = task;
INITIALIZATION_STATE_SET_VALID(initialized_);
return true;
}
std::unique_ptr<TaskMemory::MappedMemory> TaskMemory::ReadMapped(
std::unique_ptr<ProcessMemoryMac::MappedMemory> ProcessMemoryMac::ReadMapped(
mach_vm_address_t address,
size_t size) const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
@ -101,7 +100,7 @@ std::unique_ptr<TaskMemory::MappedMemory> TaskMemory::ReadMapped(
new MappedMemory(region, region_size, address - region_address, size));
}
ssize_t TaskMemory::ReadUpTo(VMAddress address,
ssize_t ProcessMemoryMac::ReadUpTo(VMAddress address,
size_t size,
void* buffer) const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CRASHPAD_UTIL_MACH_TASK_MEMORY_H_
#define CRASHPAD_UTIL_MACH_TASK_MEMORY_H_
#ifndef CRASHPAD_UTIL_PROCESS_PROCESS_MEMORY_MAC_H_
#define CRASHPAD_UTIL_PROCESS_PROCESS_MEMORY_MAC_H_
#include <mach/mach.h>
#include <sys/types.h>
@ -30,7 +30,7 @@
namespace crashpad {
//! \brief Accesses the memory of another Mach task.
class TaskMemory : public ProcessMemory {
class ProcessMemoryMac : public ProcessMemory {
public:
//! \brief A memory region mapped from another Mach task.
//!
@ -85,13 +85,13 @@ class TaskMemory : public ProcessMemory {
size_t user_size_;
// The outer class needs to be able to call this class private constructor.
friend class TaskMemory;
friend class ProcessMemoryMac;
DISALLOW_COPY_AND_ASSIGN(MappedMemory);
};
TaskMemory();
~TaskMemory() {}
ProcessMemoryMac();
~ProcessMemoryMac() {}
//! \brief Initializes this object to read the memory of a task with the
//! provided task port.
@ -127,9 +127,9 @@ class TaskMemory : public ProcessMemory {
task_t task_; // weak
InitializationStateDcheck initialized_;
DISALLOW_COPY_AND_ASSIGN(TaskMemory);
DISALLOW_COPY_AND_ASSIGN(ProcessMemoryMac);
};
} // namespace crashpad
#endif // CRASHPAD_UTIL_MACH_TASK_MEMORY_H_
#endif // CRASHPAD_UTIL_PROCESS_PROCESS_MEMORY_MAC_H_

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "util/mach/task_memory.h"
#include "util/process/process_memory_mac.h"
#include <mach/mach.h>
#include <string.h>
@ -31,7 +31,7 @@ namespace crashpad {
namespace test {
namespace {
TEST(TaskMemory, ReadMappedSelf) {
TEST(ProcessMemoryMac, ReadMappedSelf) {
vm_address_t address = 0;
constexpr vm_size_t kSize = 4 * PAGE_SIZE;
kern_return_t kr =
@ -44,11 +44,11 @@ TEST(TaskMemory, ReadMappedSelf) {
region[index] = (index % 256) ^ ((index >> 8) % 256);
}
TaskMemory memory;
ProcessMemoryMac memory;
ASSERT_TRUE(memory.Initialize(mach_task_self()));
std::string result(kSize, '\0');
std::unique_ptr<TaskMemory::MappedMemory> mapped;
std::unique_ptr<ProcessMemoryMac::MappedMemory> mapped;
// Ensure that the entire region can be read.
ASSERT_TRUE((mapped = memory.ReadMapped(address, kSize)));
@ -86,7 +86,7 @@ TEST(TaskMemory, ReadMappedSelf) {
EXPECT_EQ(result[0], 'M');
}
TEST(TaskMemory, ReadSelfUnmapped) {
TEST(ProcessMemoryMac, ReadSelfUnmapped) {
vm_address_t address = 0;
constexpr vm_size_t kSize = 2 * PAGE_SIZE;
kern_return_t kr =
@ -105,7 +105,7 @@ TEST(TaskMemory, ReadSelfUnmapped) {
mach_task_self(), address + PAGE_SIZE, PAGE_SIZE, FALSE, VM_PROT_NONE);
ASSERT_EQ(kr, KERN_SUCCESS) << MachErrorMessage(kr, "vm_protect");
TaskMemory memory;
ProcessMemoryMac memory;
ASSERT_TRUE(memory.Initialize(mach_task_self()));
std::string result(kSize, '\0');
@ -117,7 +117,7 @@ TEST(TaskMemory, ReadSelfUnmapped) {
EXPECT_TRUE(memory.Read(address + PAGE_SIZE - 1, 1, &result[0]));
// Do the same thing with the ReadMapped() interface.
std::unique_ptr<TaskMemory::MappedMemory> mapped;
std::unique_ptr<ProcessMemoryMac::MappedMemory> mapped;
EXPECT_FALSE((mapped = memory.ReadMapped(address, kSize)));
EXPECT_FALSE((mapped = memory.ReadMapped(address + 1, kSize - 1)));
EXPECT_FALSE((mapped = memory.ReadMapped(address + PAGE_SIZE, 1)));
@ -148,7 +148,7 @@ TEST(TaskMemory, ReadSelfUnmapped) {
EXPECT_TRUE((mapped = memory.ReadMapped(address + PAGE_SIZE - 1, 1)));
}
TEST(TaskMemory, ReadCStringSelfUnmapped) {
TEST(ProcessMemoryMac, ReadCStringSelfUnmapped) {
vm_address_t address = 0;
constexpr vm_size_t kSize = 2 * PAGE_SIZE;
kern_return_t kr =
@ -167,7 +167,7 @@ TEST(TaskMemory, ReadCStringSelfUnmapped) {
mach_task_self(), address + PAGE_SIZE, PAGE_SIZE, FALSE, VM_PROT_NONE);
ASSERT_EQ(kr, KERN_SUCCESS) << MachErrorMessage(kr, "vm_protect");
TaskMemory memory;
ProcessMemoryMac memory;
ASSERT_TRUE(memory.Initialize(mach_task_self()));
std::string result;
EXPECT_FALSE(memory.ReadCString(address, &result));
@ -232,17 +232,17 @@ bool IsAddressMapped(vm_address_t address) {
return false;
}
TEST(TaskMemory, MappedMemoryDeallocates) {
// This tests that once a TaskMemory::MappedMemory object is destroyed, it
// releases the mapped memory that it owned. Technically, this test is not
TEST(ProcessMemoryMac, MappedMemoryDeallocates) {
// This tests that once a ProcessMemoryMac::MappedMemory object is destroyed,
// it releases the mapped memory that it owned. Technically, this test is not
// valid because after the mapping is released, something else (on another
// thread) might wind up mapped in the same address. In the test environment,
// hopefully there are either no other threads or they're all quiescent, so
// nothing else should wind up mapped in the address.
TaskMemory memory;
ProcessMemoryMac memory;
ASSERT_TRUE(memory.Initialize(mach_task_self()));
std::unique_ptr<TaskMemory::MappedMemory> mapped;
std::unique_ptr<ProcessMemoryMac::MappedMemory> mapped;
static constexpr char kTestBuffer[] = "hello!";
mach_vm_address_t test_address =
@ -276,11 +276,11 @@ TEST(TaskMemory, MappedMemoryDeallocates) {
EXPECT_FALSE(IsAddressMapped(mapped_last_address));
}
TEST(TaskMemory, MappedMemoryReadCString) {
// This tests the behavior of TaskMemory::MappedMemory::ReadCString().
TaskMemory memory;
TEST(ProcessMemoryMac, MappedMemoryReadCString) {
// This tests the behavior of ProcessMemoryMac::MappedMemory::ReadCString().
ProcessMemoryMac memory;
ASSERT_TRUE(memory.Initialize(mach_task_self()));
std::unique_ptr<TaskMemory::MappedMemory> mapped;
std::unique_ptr<ProcessMemoryMac::MappedMemory> mapped;
static constexpr char kTestBuffer[] = "0\0" "2\0" "45\0" "789";
const mach_vm_address_t kTestAddress =

View File

@ -21,7 +21,7 @@
#elif defined(OS_WIN)
#include "util/process/process_memory_win.h"
#elif defined(OS_MACOSX)
#include "util/mach/task_memory.h"
#include "util/process/process_memory_mac.h"
#endif
namespace crashpad {
@ -34,7 +34,7 @@ using ProcessMemoryNative = ProcessMemoryLinux;
#elif defined(OS_WIN)
using ProcessMemoryNative = ProcessMemoryWin;
#elif defined(OS_MACOSX)
using ProcessMemoryNative = TaskMemory;
using ProcessMemoryNative = ProcessMemoryMac;
#else
#error Port.
#endif

View File

@ -124,8 +124,6 @@
'mach/symbolic_constants_mach.h',
'mach/task_for_pid.cc',
'mach/task_for_pid.h',
'mach/task_memory.cc',
'mach/task_memory.h',
'misc/address_sanitizer.h',
'misc/address_types.h',
'misc/arraysize_unsafe.h',
@ -215,6 +213,8 @@
'process/process_memory.h',
'process/process_memory_linux.cc',
'process/process_memory_linux.h',
'process/process_memory_mac.cc',
'process/process_memory_mac.h',
'process/process_memory_native.h',
'process/process_memory_range.cc',
'process/process_memory_range.h',

View File

@ -65,7 +65,6 @@
'mach/notify_server_test.cc',
'mach/scoped_task_suspend_test.cc',
'mach/symbolic_constants_mach_test.cc',
'mach/task_memory_test.cc',
'misc/arraysize_unsafe_test.cc',
'misc/capture_context_test.cc',
'misc/capture_context_test_util.h',
@ -98,6 +97,7 @@
'posix/scoped_mmap_test.cc',
'posix/signals_test.cc',
'posix/symbolic_constants_posix_test.cc',
'process/process_memory_mac_test.cc',
'process/process_memory_range_test.cc',
'process/process_memory_test.cc',
'stdlib/aligned_allocator_test.cc',