diff --git a/snapshot/mac/mach_o_image_annotations_reader.cc b/snapshot/mac/mach_o_image_annotations_reader.cc index b02acaea..e730b511 100644 --- a/snapshot/mac/mach_o_image_annotations_reader.cc +++ b/snapshot/mac/mach_o_image_annotations_reader.cc @@ -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 { diff --git a/snapshot/mac/mach_o_image_symbol_table_reader.cc b/snapshot/mac/mach_o_image_symbol_table_reader.cc index 361253ce..cbdac402 100644 --- a/snapshot/mac/mach_o_image_symbol_table_reader.cc +++ b/snapshot/mac/mach_o_image_symbol_table_reader.cc @@ -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 string_table; + std::unique_ptr 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", diff --git a/snapshot/mac/mach_o_image_symbol_table_reader.h b/snapshot/mac/mach_o_image_symbol_table_reader.h index 841b479a..b1bcc3a2 100644 --- a/snapshot/mac/mach_o_image_symbol_table_reader.h +++ b/snapshot/mac/mach_o_image_symbol_table_reader.h @@ -58,7 +58,7 @@ class MachOImageSymbolTableReader { // there aren’t 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 diff --git a/snapshot/mac/process_reader_mac.cc b/snapshot/mac/process_reader_mac.cc index 4850bbab..61dc3a1f 100644 --- a/snapshot/mac/process_reader_mac.cc +++ b/snapshot/mac/process_reader_mac.cc @@ -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. } diff --git a/snapshot/mac/process_reader_mac.h b/snapshot/mac/process_reader_mac.h index 8a5b2c80..9435b057 100644 --- a/snapshot/mac/process_reader_mac.h +++ b/snapshot/mac/process_reader_mac.h @@ -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 threads_; // owns send rights std::vector modules_; std::vector> module_readers_; - TaskMemory task_memory_; + ProcessMemoryMac process_memory_; task_t task_; // weak InitializationStateDcheck initialized_; diff --git a/snapshot/mac/process_types.cc b/snapshot/mac/process_types.cc index 65c39ea5..cbb114d7 100644 --- a/snapshot/mac/process_types.cc +++ b/snapshot/mac/process_types.cc @@ -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 { diff --git a/snapshot/mac/process_types/custom.cc b/snapshot/mac/process_types/custom.cc index 7c7b172a..7a207e98 100644 --- a/snapshot/mac/process_types/custom.cc +++ b/snapshot/mac/process_types/custom.cc @@ -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 -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 @@ -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), sizeof(*specific)); - return ReadIntoAndZero(task_memory, address, size, specific); + return ReadIntoAndZero(process_memory, address, size, specific); } } // namespace diff --git a/util/BUILD.gn b/util/BUILD.gn index e43c42f0..c7c6837b 100644 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -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", ] } diff --git a/util/mach/task_memory.cc b/util/process/process_memory_mac.cc similarity index 79% rename from util/mach/task_memory.cc rename to util/process/process_memory_mac.cc index eb8b1f57..eba1f201 100644 --- a/util/mach/task_memory.cc +++ b/util/process/process_memory_mac.cc @@ -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 #include @@ -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,10 +47,10 @@ bool TaskMemory::MappedMemory::ReadCString( return true; } -TaskMemory::MappedMemory::MappedMemory(vm_address_t vm_address, - size_t vm_size, - size_t user_offset, - size_t user_size) +ProcessMemoryMac::MappedMemory::MappedMemory(vm_address_t vm_address, + size_t vm_size, + size_t user_offset, + size_t user_size) : vm_(vm_address, vm_size), data_(reinterpret_cast(vm_address + user_offset)), user_size_(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::ReadMapped( +std::unique_ptr ProcessMemoryMac::ReadMapped( mach_vm_address_t address, size_t size) const { INITIALIZATION_STATE_DCHECK_VALID(initialized_); @@ -101,9 +100,9 @@ std::unique_ptr TaskMemory::ReadMapped( new MappedMemory(region, region_size, address - region_address, size)); } -ssize_t TaskMemory::ReadUpTo(VMAddress address, - size_t size, - void* buffer) const { +ssize_t ProcessMemoryMac::ReadUpTo(VMAddress address, + size_t size, + void* buffer) const { INITIALIZATION_STATE_DCHECK_VALID(initialized_); DCHECK_LE(size, (size_t)std::numeric_limits::max()); diff --git a/util/mach/task_memory.h b/util/process/process_memory_mac.h similarity index 93% rename from util/mach/task_memory.h rename to util/process/process_memory_mac.h index 8fc217a6..214e4890 100644 --- a/util/mach/task_memory.h +++ b/util/process/process_memory_mac.h @@ -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 #include @@ -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_ diff --git a/util/mach/task_memory_test.cc b/util/process/process_memory_mac_test.cc similarity index 93% rename from util/mach/task_memory_test.cc rename to util/process/process_memory_mac_test.cc index 019cec21..d801bb14 100644 --- a/util/mach/task_memory_test.cc +++ b/util/process/process_memory_mac_test.cc @@ -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 #include @@ -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 mapped; + std::unique_ptr 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 mapped; + std::unique_ptr 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 mapped; + std::unique_ptr 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 mapped; + std::unique_ptr mapped; static constexpr char kTestBuffer[] = "0\0" "2\0" "45\0" "789"; const mach_vm_address_t kTestAddress = diff --git a/util/process/process_memory_native.h b/util/process/process_memory_native.h index 79cf1e1d..39bfc893 100644 --- a/util/process/process_memory_native.h +++ b/util/process/process_memory_native.h @@ -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 diff --git a/util/util.gyp b/util/util.gyp index 60e91304..dc82287e 100644 --- a/util/util.gyp +++ b/util/util.gyp @@ -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', diff --git a/util/util_test.gyp b/util/util_test.gyp index 485ed663..b3c8d419 100644 --- a/util/util_test.gyp +++ b/util/util_test.gyp @@ -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',