mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
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:
parent
3f7d4d7d09
commit
3b9e3aad1b
@ -26,7 +26,6 @@
|
|||||||
#include "snapshot/mac/mach_o_image_reader.h"
|
#include "snapshot/mac/mach_o_image_reader.h"
|
||||||
#include "snapshot/mac/process_reader_mac.h"
|
#include "snapshot/mac/process_reader_mac.h"
|
||||||
#include "snapshot/snapshot_constants.h"
|
#include "snapshot/snapshot_constants.h"
|
||||||
#include "util/mach/task_memory.h"
|
|
||||||
#include "util/stdlib/strnlen.h"
|
#include "util/stdlib/strnlen.h"
|
||||||
|
|
||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "base/strings/stringprintf.h"
|
#include "base/strings/stringprintf.h"
|
||||||
#include "util/mac/checked_mach_address_range.h"
|
#include "util/mac/checked_mach_address_range.h"
|
||||||
#include "util/mach/task_memory.h"
|
#include "util/process/process_memory_mac.h"
|
||||||
|
|
||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ class MachOImageSymbolTableReaderInitializer {
|
|||||||
return false;
|
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) {
|
for (size_t symbol_index = 0; symbol_index < symbol_count; ++symbol_index) {
|
||||||
const process_types::nlist& symbol = symbols[symbol_index];
|
const process_types::nlist& symbol = symbols[symbol_index];
|
||||||
std::string symbol_info = base::StringPrintf(", symbol index %zu%s",
|
std::string symbol_info = base::StringPrintf(", symbol index %zu%s",
|
||||||
|
@ -58,7 +58,7 @@ class MachOImageSymbolTableReader {
|
|||||||
// there aren’t expected to be very many of those that performance would
|
// 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
|
// become a problem. In reality, std::unordered_map does not appear to provide
|
||||||
// a performance advantage. It appears that the memory copies currently done
|
// 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.
|
// operations.
|
||||||
//
|
//
|
||||||
// This is public so that the type is available to
|
// This is public so that the type is available to
|
||||||
|
@ -92,7 +92,7 @@ ProcessReaderMac::ProcessReaderMac()
|
|||||||
threads_(),
|
threads_(),
|
||||||
modules_(),
|
modules_(),
|
||||||
module_readers_(),
|
module_readers_(),
|
||||||
task_memory_(),
|
process_memory_(),
|
||||||
task_(TASK_NULL),
|
task_(TASK_NULL),
|
||||||
initialized_(),
|
initialized_(),
|
||||||
is_64_bit_(false),
|
is_64_bit_(false),
|
||||||
@ -113,7 +113,7 @@ bool ProcessReaderMac::Initialize(task_t task) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!task_memory_.Initialize(task)) {
|
if (!process_memory_.Initialize(task)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -443,7 +443,7 @@ void ProcessReaderMac::InitializeModules() {
|
|||||||
Module module;
|
Module module;
|
||||||
module.timestamp = image_info.imageFileModDate;
|
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";
|
LOG(WARNING) << "could not read dyld_image_info::imageFilePath";
|
||||||
// Proceed anyway with an empty module name.
|
// Proceed anyway with an empty module name.
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,9 @@
|
|||||||
|
|
||||||
#include "base/macros.h"
|
#include "base/macros.h"
|
||||||
#include "build/build_config.h"
|
#include "build/build_config.h"
|
||||||
#include "util/mach/task_memory.h"
|
|
||||||
#include "util/misc/initialization_state_dcheck.h"
|
#include "util/misc/initialization_state_dcheck.h"
|
||||||
#include "util/posix/process_info.h"
|
#include "util/posix/process_info.h"
|
||||||
|
#include "util/process/process_memory_mac.h"
|
||||||
|
|
||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ class ProcessReaderMac {
|
|||||||
bool CPUTimes(timeval* user_time, timeval* system_time) const;
|
bool CPUTimes(timeval* user_time, timeval* system_time) const;
|
||||||
|
|
||||||
//! \return Accesses the memory of the target task.
|
//! \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
|
//! \return The threads that are in the task (process). The first element (at
|
||||||
//! index `0`) corresponds to the main thread.
|
//! index `0`) corresponds to the main thread.
|
||||||
@ -232,7 +232,7 @@ class ProcessReaderMac {
|
|||||||
std::vector<Thread> threads_; // owns send rights
|
std::vector<Thread> threads_; // owns send rights
|
||||||
std::vector<Module> modules_;
|
std::vector<Module> modules_;
|
||||||
std::vector<std::unique_ptr<MachOImageReader>> module_readers_;
|
std::vector<std::unique_ptr<MachOImageReader>> module_readers_;
|
||||||
TaskMemory task_memory_;
|
ProcessMemoryMac process_memory_;
|
||||||
task_t task_; // weak
|
task_t task_; // weak
|
||||||
InitializationStateDcheck initialized_;
|
InitializationStateDcheck initialized_;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "base/macros.h"
|
#include "base/macros.h"
|
||||||
#include "snapshot/mac/process_types/internal.h"
|
#include "snapshot/mac/process_types/internal.h"
|
||||||
#include "util/mach/task_memory.h"
|
#include "util/process/process_memory_mac.h"
|
||||||
|
|
||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "base/numerics/safe_math.h"
|
#include "base/numerics/safe_math.h"
|
||||||
#include "base/strings/stringprintf.h"
|
#include "base/strings/stringprintf.h"
|
||||||
#include "snapshot/mac/process_types/internal.h"
|
#include "snapshot/mac/process_types/internal.h"
|
||||||
#include "util/mach/task_memory.h"
|
#include "util/process/process_memory_mac.h"
|
||||||
|
|
||||||
#if !DOXYGEN
|
#if !DOXYGEN
|
||||||
|
|
||||||
@ -36,13 +36,13 @@ namespace internal {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool ReadIntoAndZero(TaskMemory* task_memory,
|
bool ReadIntoAndZero(ProcessMemoryMac* process_memory,
|
||||||
mach_vm_address_t address,
|
mach_vm_address_t address,
|
||||||
mach_vm_size_t size,
|
mach_vm_size_t size,
|
||||||
T* specific) {
|
T* specific) {
|
||||||
DCHECK_LE(size, sizeof(*specific));
|
DCHECK_LE(size, sizeof(*specific));
|
||||||
|
|
||||||
if (!task_memory->Read(address, size, specific)) {
|
if (!process_memory->Read(address, size, specific)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,14 +84,14 @@ bool ReadIntoVersioned(ProcessReaderMac* process_reader,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskMemory* task_memory = process_reader->Memory();
|
ProcessMemoryMac* process_memory = process_reader->Memory();
|
||||||
decltype(specific->version) version;
|
decltype(specific->version) version;
|
||||||
if (!task_memory->Read(field_address, sizeof(version), &version)) {
|
if (!process_memory->Read(field_address, sizeof(version), &version)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t size = T::ExpectedSizeForVersion(version);
|
const size_t size = T::ExpectedSizeForVersion(version);
|
||||||
return ReadIntoAndZero(task_memory, address, size, specific);
|
return ReadIntoAndZero(process_memory, address, size, specific);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -103,9 +103,9 @@ bool ReadIntoSized(ProcessReaderMac* process_reader,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskMemory* task_memory = process_reader->Memory();
|
ProcessMemoryMac* process_memory = process_reader->Memory();
|
||||||
decltype(specific->size) size;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ bool ReadIntoSized(ProcessReaderMac* process_reader,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size = std::min(static_cast<size_t>(size), sizeof(*specific));
|
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
|
} // namespace
|
||||||
|
@ -244,13 +244,13 @@ static_library("util") {
|
|||||||
"mach/symbolic_constants_mach.h",
|
"mach/symbolic_constants_mach.h",
|
||||||
"mach/task_for_pid.cc",
|
"mach/task_for_pid.cc",
|
||||||
"mach/task_for_pid.h",
|
"mach/task_for_pid.h",
|
||||||
"mach/task_memory.cc",
|
|
||||||
"mach/task_memory.h",
|
|
||||||
"misc/capture_context_mac.S",
|
"misc/capture_context_mac.S",
|
||||||
"misc/clock_mac.cc",
|
"misc/clock_mac.cc",
|
||||||
"misc/paths_mac.cc",
|
"misc/paths_mac.cc",
|
||||||
"net/http_transport_mac.mm",
|
"net/http_transport_mac.mm",
|
||||||
"posix/process_info_mac.cc",
|
"posix/process_info_mac.cc",
|
||||||
|
"process/process_memory_mac.cc",
|
||||||
|
"process/process_memory_mac.h",
|
||||||
"synchronization/semaphore_mac.cc",
|
"synchronization/semaphore_mac.cc",
|
||||||
]
|
]
|
||||||
sources += get_target_outputs(":mig")
|
sources += get_target_outputs(":mig")
|
||||||
@ -605,8 +605,8 @@ source_set("util_test") {
|
|||||||
"mach/notify_server_test.cc",
|
"mach/notify_server_test.cc",
|
||||||
"mach/scoped_task_suspend_test.cc",
|
"mach/scoped_task_suspend_test.cc",
|
||||||
"mach/symbolic_constants_mach_test.cc",
|
"mach/symbolic_constants_mach_test.cc",
|
||||||
"mach/task_memory_test.cc",
|
|
||||||
"misc/capture_context_test_util_mac.cc",
|
"misc/capture_context_test_util_mac.cc",
|
||||||
|
"process/process_memory_mac_test.cc",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "util/mach/task_memory.h"
|
#include "util/process/process_memory_mac.h"
|
||||||
|
|
||||||
#include <mach/mach_vm.h>
|
#include <mach/mach_vm.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -26,11 +26,10 @@
|
|||||||
|
|
||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
|
|
||||||
TaskMemory::MappedMemory::~MappedMemory() {
|
ProcessMemoryMac::MappedMemory::~MappedMemory() {}
|
||||||
}
|
|
||||||
|
|
||||||
bool TaskMemory::MappedMemory::ReadCString(
|
bool ProcessMemoryMac::MappedMemory::ReadCString(size_t offset,
|
||||||
size_t offset, std::string* string) const {
|
std::string* string) const {
|
||||||
if (offset >= user_size_) {
|
if (offset >= user_size_) {
|
||||||
LOG(WARNING) << "offset out of range";
|
LOG(WARNING) << "offset out of range";
|
||||||
return false;
|
return false;
|
||||||
@ -48,10 +47,10 @@ bool TaskMemory::MappedMemory::ReadCString(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskMemory::MappedMemory::MappedMemory(vm_address_t vm_address,
|
ProcessMemoryMac::MappedMemory::MappedMemory(vm_address_t vm_address,
|
||||||
size_t vm_size,
|
size_t vm_size,
|
||||||
size_t user_offset,
|
size_t user_offset,
|
||||||
size_t user_size)
|
size_t user_size)
|
||||||
: vm_(vm_address, vm_size),
|
: vm_(vm_address, vm_size),
|
||||||
data_(reinterpret_cast<const void*>(vm_address + user_offset)),
|
data_(reinterpret_cast<const void*>(vm_address + user_offset)),
|
||||||
user_size_(user_size) {
|
user_size_(user_size) {
|
||||||
@ -64,16 +63,16 @@ TaskMemory::MappedMemory::MappedMemory(vm_address_t vm_address,
|
|||||||
DCHECK_LE(user_end, vm_end);
|
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_);
|
INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
|
||||||
task_ = task;
|
task_ = task;
|
||||||
INITIALIZATION_STATE_SET_VALID(initialized_);
|
INITIALIZATION_STATE_SET_VALID(initialized_);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<TaskMemory::MappedMemory> TaskMemory::ReadMapped(
|
std::unique_ptr<ProcessMemoryMac::MappedMemory> ProcessMemoryMac::ReadMapped(
|
||||||
mach_vm_address_t address,
|
mach_vm_address_t address,
|
||||||
size_t size) const {
|
size_t size) const {
|
||||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
||||||
@ -101,9 +100,9 @@ std::unique_ptr<TaskMemory::MappedMemory> TaskMemory::ReadMapped(
|
|||||||
new MappedMemory(region, region_size, address - region_address, size));
|
new MappedMemory(region, region_size, address - region_address, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t TaskMemory::ReadUpTo(VMAddress address,
|
ssize_t ProcessMemoryMac::ReadUpTo(VMAddress address,
|
||||||
size_t size,
|
size_t size,
|
||||||
void* buffer) const {
|
void* buffer) const {
|
||||||
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
|
||||||
DCHECK_LE(size, (size_t)std::numeric_limits<ssize_t>::max());
|
DCHECK_LE(size, (size_t)std::numeric_limits<ssize_t>::max());
|
||||||
|
|
@ -12,8 +12,8 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#ifndef CRASHPAD_UTIL_MACH_TASK_MEMORY_H_
|
#ifndef CRASHPAD_UTIL_PROCESS_PROCESS_MEMORY_MAC_H_
|
||||||
#define CRASHPAD_UTIL_MACH_TASK_MEMORY_H_
|
#define CRASHPAD_UTIL_PROCESS_PROCESS_MEMORY_MAC_H_
|
||||||
|
|
||||||
#include <mach/mach.h>
|
#include <mach/mach.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -30,7 +30,7 @@
|
|||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
|
|
||||||
//! \brief Accesses the memory of another Mach task.
|
//! \brief Accesses the memory of another Mach task.
|
||||||
class TaskMemory : public ProcessMemory {
|
class ProcessMemoryMac : public ProcessMemory {
|
||||||
public:
|
public:
|
||||||
//! \brief A memory region mapped from another Mach task.
|
//! \brief A memory region mapped from another Mach task.
|
||||||
//!
|
//!
|
||||||
@ -85,13 +85,13 @@ class TaskMemory : public ProcessMemory {
|
|||||||
size_t user_size_;
|
size_t user_size_;
|
||||||
|
|
||||||
// The outer class needs to be able to call this class’ private constructor.
|
// The outer class needs to be able to call this class’ private constructor.
|
||||||
friend class TaskMemory;
|
friend class ProcessMemoryMac;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(MappedMemory);
|
DISALLOW_COPY_AND_ASSIGN(MappedMemory);
|
||||||
};
|
};
|
||||||
|
|
||||||
TaskMemory();
|
ProcessMemoryMac();
|
||||||
~TaskMemory() {}
|
~ProcessMemoryMac() {}
|
||||||
|
|
||||||
//! \brief Initializes this object to read the memory of a task with the
|
//! \brief Initializes this object to read the memory of a task with the
|
||||||
//! provided task port.
|
//! provided task port.
|
||||||
@ -127,9 +127,9 @@ class TaskMemory : public ProcessMemory {
|
|||||||
task_t task_; // weak
|
task_t task_; // weak
|
||||||
InitializationStateDcheck initialized_;
|
InitializationStateDcheck initialized_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(TaskMemory);
|
DISALLOW_COPY_AND_ASSIGN(ProcessMemoryMac);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace crashpad
|
} // namespace crashpad
|
||||||
|
|
||||||
#endif // CRASHPAD_UTIL_MACH_TASK_MEMORY_H_
|
#endif // CRASHPAD_UTIL_PROCESS_PROCESS_MEMORY_MAC_H_
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "util/mach/task_memory.h"
|
#include "util/process/process_memory_mac.h"
|
||||||
|
|
||||||
#include <mach/mach.h>
|
#include <mach/mach.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -31,7 +31,7 @@ namespace crashpad {
|
|||||||
namespace test {
|
namespace test {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST(TaskMemory, ReadMappedSelf) {
|
TEST(ProcessMemoryMac, ReadMappedSelf) {
|
||||||
vm_address_t address = 0;
|
vm_address_t address = 0;
|
||||||
constexpr vm_size_t kSize = 4 * PAGE_SIZE;
|
constexpr vm_size_t kSize = 4 * PAGE_SIZE;
|
||||||
kern_return_t kr =
|
kern_return_t kr =
|
||||||
@ -44,11 +44,11 @@ TEST(TaskMemory, ReadMappedSelf) {
|
|||||||
region[index] = (index % 256) ^ ((index >> 8) % 256);
|
region[index] = (index % 256) ^ ((index >> 8) % 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskMemory memory;
|
ProcessMemoryMac memory;
|
||||||
ASSERT_TRUE(memory.Initialize(mach_task_self()));
|
ASSERT_TRUE(memory.Initialize(mach_task_self()));
|
||||||
|
|
||||||
std::string result(kSize, '\0');
|
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.
|
// Ensure that the entire region can be read.
|
||||||
ASSERT_TRUE((mapped = memory.ReadMapped(address, kSize)));
|
ASSERT_TRUE((mapped = memory.ReadMapped(address, kSize)));
|
||||||
@ -86,7 +86,7 @@ TEST(TaskMemory, ReadMappedSelf) {
|
|||||||
EXPECT_EQ(result[0], 'M');
|
EXPECT_EQ(result[0], 'M');
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TaskMemory, ReadSelfUnmapped) {
|
TEST(ProcessMemoryMac, ReadSelfUnmapped) {
|
||||||
vm_address_t address = 0;
|
vm_address_t address = 0;
|
||||||
constexpr vm_size_t kSize = 2 * PAGE_SIZE;
|
constexpr vm_size_t kSize = 2 * PAGE_SIZE;
|
||||||
kern_return_t kr =
|
kern_return_t kr =
|
||||||
@ -105,7 +105,7 @@ TEST(TaskMemory, ReadSelfUnmapped) {
|
|||||||
mach_task_self(), address + PAGE_SIZE, PAGE_SIZE, FALSE, VM_PROT_NONE);
|
mach_task_self(), address + PAGE_SIZE, PAGE_SIZE, FALSE, VM_PROT_NONE);
|
||||||
ASSERT_EQ(kr, KERN_SUCCESS) << MachErrorMessage(kr, "vm_protect");
|
ASSERT_EQ(kr, KERN_SUCCESS) << MachErrorMessage(kr, "vm_protect");
|
||||||
|
|
||||||
TaskMemory memory;
|
ProcessMemoryMac memory;
|
||||||
ASSERT_TRUE(memory.Initialize(mach_task_self()));
|
ASSERT_TRUE(memory.Initialize(mach_task_self()));
|
||||||
std::string result(kSize, '\0');
|
std::string result(kSize, '\0');
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ TEST(TaskMemory, ReadSelfUnmapped) {
|
|||||||
EXPECT_TRUE(memory.Read(address + PAGE_SIZE - 1, 1, &result[0]));
|
EXPECT_TRUE(memory.Read(address + PAGE_SIZE - 1, 1, &result[0]));
|
||||||
|
|
||||||
// Do the same thing with the ReadMapped() interface.
|
// 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, kSize)));
|
||||||
EXPECT_FALSE((mapped = memory.ReadMapped(address + 1, kSize - 1)));
|
EXPECT_FALSE((mapped = memory.ReadMapped(address + 1, kSize - 1)));
|
||||||
EXPECT_FALSE((mapped = memory.ReadMapped(address + PAGE_SIZE, 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)));
|
EXPECT_TRUE((mapped = memory.ReadMapped(address + PAGE_SIZE - 1, 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TaskMemory, ReadCStringSelfUnmapped) {
|
TEST(ProcessMemoryMac, ReadCStringSelfUnmapped) {
|
||||||
vm_address_t address = 0;
|
vm_address_t address = 0;
|
||||||
constexpr vm_size_t kSize = 2 * PAGE_SIZE;
|
constexpr vm_size_t kSize = 2 * PAGE_SIZE;
|
||||||
kern_return_t kr =
|
kern_return_t kr =
|
||||||
@ -167,7 +167,7 @@ TEST(TaskMemory, ReadCStringSelfUnmapped) {
|
|||||||
mach_task_self(), address + PAGE_SIZE, PAGE_SIZE, FALSE, VM_PROT_NONE);
|
mach_task_self(), address + PAGE_SIZE, PAGE_SIZE, FALSE, VM_PROT_NONE);
|
||||||
ASSERT_EQ(kr, KERN_SUCCESS) << MachErrorMessage(kr, "vm_protect");
|
ASSERT_EQ(kr, KERN_SUCCESS) << MachErrorMessage(kr, "vm_protect");
|
||||||
|
|
||||||
TaskMemory memory;
|
ProcessMemoryMac memory;
|
||||||
ASSERT_TRUE(memory.Initialize(mach_task_self()));
|
ASSERT_TRUE(memory.Initialize(mach_task_self()));
|
||||||
std::string result;
|
std::string result;
|
||||||
EXPECT_FALSE(memory.ReadCString(address, &result));
|
EXPECT_FALSE(memory.ReadCString(address, &result));
|
||||||
@ -232,17 +232,17 @@ bool IsAddressMapped(vm_address_t address) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TaskMemory, MappedMemoryDeallocates) {
|
TEST(ProcessMemoryMac, MappedMemoryDeallocates) {
|
||||||
// This tests that once a TaskMemory::MappedMemory object is destroyed, it
|
// This tests that once a ProcessMemoryMac::MappedMemory object is destroyed,
|
||||||
// releases the mapped memory that it owned. Technically, this test is not
|
// it releases the mapped memory that it owned. Technically, this test is not
|
||||||
// valid because after the mapping is released, something else (on another
|
// valid because after the mapping is released, something else (on another
|
||||||
// thread) might wind up mapped in the same address. In the test environment,
|
// 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
|
// hopefully there are either no other threads or they're all quiescent, so
|
||||||
// nothing else should wind up mapped in the address.
|
// nothing else should wind up mapped in the address.
|
||||||
|
|
||||||
TaskMemory memory;
|
ProcessMemoryMac memory;
|
||||||
ASSERT_TRUE(memory.Initialize(mach_task_self()));
|
ASSERT_TRUE(memory.Initialize(mach_task_self()));
|
||||||
std::unique_ptr<TaskMemory::MappedMemory> mapped;
|
std::unique_ptr<ProcessMemoryMac::MappedMemory> mapped;
|
||||||
|
|
||||||
static constexpr char kTestBuffer[] = "hello!";
|
static constexpr char kTestBuffer[] = "hello!";
|
||||||
mach_vm_address_t test_address =
|
mach_vm_address_t test_address =
|
||||||
@ -276,11 +276,11 @@ TEST(TaskMemory, MappedMemoryDeallocates) {
|
|||||||
EXPECT_FALSE(IsAddressMapped(mapped_last_address));
|
EXPECT_FALSE(IsAddressMapped(mapped_last_address));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TaskMemory, MappedMemoryReadCString) {
|
TEST(ProcessMemoryMac, MappedMemoryReadCString) {
|
||||||
// This tests the behavior of TaskMemory::MappedMemory::ReadCString().
|
// This tests the behavior of ProcessMemoryMac::MappedMemory::ReadCString().
|
||||||
TaskMemory memory;
|
ProcessMemoryMac memory;
|
||||||
ASSERT_TRUE(memory.Initialize(mach_task_self()));
|
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";
|
static constexpr char kTestBuffer[] = "0\0" "2\0" "45\0" "789";
|
||||||
const mach_vm_address_t kTestAddress =
|
const mach_vm_address_t kTestAddress =
|
@ -21,7 +21,7 @@
|
|||||||
#elif defined(OS_WIN)
|
#elif defined(OS_WIN)
|
||||||
#include "util/process/process_memory_win.h"
|
#include "util/process/process_memory_win.h"
|
||||||
#elif defined(OS_MACOSX)
|
#elif defined(OS_MACOSX)
|
||||||
#include "util/mach/task_memory.h"
|
#include "util/process/process_memory_mac.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
@ -34,7 +34,7 @@ using ProcessMemoryNative = ProcessMemoryLinux;
|
|||||||
#elif defined(OS_WIN)
|
#elif defined(OS_WIN)
|
||||||
using ProcessMemoryNative = ProcessMemoryWin;
|
using ProcessMemoryNative = ProcessMemoryWin;
|
||||||
#elif defined(OS_MACOSX)
|
#elif defined(OS_MACOSX)
|
||||||
using ProcessMemoryNative = TaskMemory;
|
using ProcessMemoryNative = ProcessMemoryMac;
|
||||||
#else
|
#else
|
||||||
#error Port.
|
#error Port.
|
||||||
#endif
|
#endif
|
||||||
|
@ -124,8 +124,6 @@
|
|||||||
'mach/symbolic_constants_mach.h',
|
'mach/symbolic_constants_mach.h',
|
||||||
'mach/task_for_pid.cc',
|
'mach/task_for_pid.cc',
|
||||||
'mach/task_for_pid.h',
|
'mach/task_for_pid.h',
|
||||||
'mach/task_memory.cc',
|
|
||||||
'mach/task_memory.h',
|
|
||||||
'misc/address_sanitizer.h',
|
'misc/address_sanitizer.h',
|
||||||
'misc/address_types.h',
|
'misc/address_types.h',
|
||||||
'misc/arraysize_unsafe.h',
|
'misc/arraysize_unsafe.h',
|
||||||
@ -215,6 +213,8 @@
|
|||||||
'process/process_memory.h',
|
'process/process_memory.h',
|
||||||
'process/process_memory_linux.cc',
|
'process/process_memory_linux.cc',
|
||||||
'process/process_memory_linux.h',
|
'process/process_memory_linux.h',
|
||||||
|
'process/process_memory_mac.cc',
|
||||||
|
'process/process_memory_mac.h',
|
||||||
'process/process_memory_native.h',
|
'process/process_memory_native.h',
|
||||||
'process/process_memory_range.cc',
|
'process/process_memory_range.cc',
|
||||||
'process/process_memory_range.h',
|
'process/process_memory_range.h',
|
||||||
|
@ -65,7 +65,6 @@
|
|||||||
'mach/notify_server_test.cc',
|
'mach/notify_server_test.cc',
|
||||||
'mach/scoped_task_suspend_test.cc',
|
'mach/scoped_task_suspend_test.cc',
|
||||||
'mach/symbolic_constants_mach_test.cc',
|
'mach/symbolic_constants_mach_test.cc',
|
||||||
'mach/task_memory_test.cc',
|
|
||||||
'misc/arraysize_unsafe_test.cc',
|
'misc/arraysize_unsafe_test.cc',
|
||||||
'misc/capture_context_test.cc',
|
'misc/capture_context_test.cc',
|
||||||
'misc/capture_context_test_util.h',
|
'misc/capture_context_test_util.h',
|
||||||
@ -98,6 +97,7 @@
|
|||||||
'posix/scoped_mmap_test.cc',
|
'posix/scoped_mmap_test.cc',
|
||||||
'posix/signals_test.cc',
|
'posix/signals_test.cc',
|
||||||
'posix/symbolic_constants_posix_test.cc',
|
'posix/symbolic_constants_posix_test.cc',
|
||||||
|
'process/process_memory_mac_test.cc',
|
||||||
'process/process_memory_range_test.cc',
|
'process/process_memory_range_test.cc',
|
||||||
'process/process_memory_test.cc',
|
'process/process_memory_test.cc',
|
||||||
'stdlib/aligned_allocator_test.cc',
|
'stdlib/aligned_allocator_test.cc',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user