Crashpad
Classes | Public Member Functions | List of all members
crashpad::TaskMemory Class Reference

Accesses the memory of another Mach task. More...

#include "util/mach/task_memory.h"

Classes

class  MappedMemory
 A memory region mapped from another Mach task. More...
 

Public Member Functions

 TaskMemory (task_t task)
 
bool Read (mach_vm_address_t address, size_t size, void *buffer)
 Copies memory from the target task into a caller-provided buffer in the current task. More...
 
std::unique_ptr< MappedMemoryReadMapped (mach_vm_address_t address, size_t size)
 Maps memory from the target task into the current task. More...
 
bool ReadCString (mach_vm_address_t address, std::string *string)
 Reads a NUL-terminated C string from the target task into a string in the current task. More...
 
bool ReadCStringSizeLimited (mach_vm_address_t address, mach_vm_size_t size, std::string *string)
 Reads a NUL-terminated C string from the target task into a string in the current task. More...
 

Detailed Description

Accesses the memory of another Mach task.

Constructor & Destructor Documentation

◆ TaskMemory()

crashpad::TaskMemory::TaskMemory ( task_t  task)
explicit
Parameters
[in]taskA send right to the target task’s task port. This object does not take ownership of the send right.

Member Function Documentation

◆ Read()

bool crashpad::TaskMemory::Read ( mach_vm_address_t  address,
size_t  size,
void *  buffer 
)

Copies memory from the target task into a caller-provided buffer in the current task.

Parameters
[in]addressThe address, in the target task’s address space, of the memory region to copy.
[in]sizeThe size, in bytes, of the memory region to copy. buffer must be at least this size.
[out]bufferThe buffer into which the contents of the other task’s memory will be copied.
Returns
true on success, with buffer filled appropriately. false on failure, with a warning logged. Failures can occur, for example, when encountering unmapped or unreadable pages.
See also
ReadMapped()

◆ ReadCString()

bool crashpad::TaskMemory::ReadCString ( mach_vm_address_t  address,
std::string *  string 
)

Reads a NUL-terminated C string from the target task into a string in the current task.

The length of the string need not be known ahead of time. This method will read contiguous memory until a NUL terminator is found.

Parameters
[in]addressThe address, in the target task’s address space, of the string to copy.
[out]stringThe string read from the other task.
Returns
true on success, with string set appropriately. false on failure, with a warning logged. Failures can occur, for example, when encountering unmapped or unreadable pages.
See also
MappedMemory::ReadCString()

◆ ReadCStringSizeLimited()

bool crashpad::TaskMemory::ReadCStringSizeLimited ( mach_vm_address_t  address,
mach_vm_size_t  size,
std::string *  string 
)

Reads a NUL-terminated C string from the target task into a string in the current task.

Parameters
[in]addressThe address, in the target task’s address space, of the string to copy.
[in]sizeThe maximum number of bytes to read. The string is required to be NUL-terminated within this many bytes.
[out]stringThe string read from the other task.
Returns
true on success, with string set appropriately. false on failure, with a warning logged. Failures can occur, for example, when a NUL terminator is not found within size bytes, or when encountering unmapped or unreadable pages.
See also
MappedMemory::ReadCString()

◆ ReadMapped()

std::unique_ptr< TaskMemory::MappedMemory > crashpad::TaskMemory::ReadMapped ( mach_vm_address_t  address,
size_t  size 
)

Maps memory from the target task into the current task.

This interface is an alternative to Read() that does not require the caller to provide a buffer to fill. This avoids copying memory, which can offer a performance improvement.

Parameters
[in]addressThe address, in the target task’s address space, of the memory region to map.
[in]sizeThe size, in bytes, of the memory region to map.
Returns
On success, a MappedMemory object that provides access to the data requested. On faliure, nullptr, with a warning logged. Failures can occur, for example, when encountering unmapped or unreadable pages.

The documentation for this class was generated from the following files: