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

Maintains a memory-mapped region created by mmap(). More...

#include "util/posix/scoped_mmap.h"

Public Member Functions

bool Reset ()
 Releases the memory-mapped region by calling munmap(). More...
 
bool ResetAddrLen (void *addr, size_t len)
 Releases any existing memory-mapped region and sets the object to maintain an already-established mapping. More...
 
bool ResetMmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
 Releases any existing memory-mapped region and establishes a new one by calling mmap(). More...
 
bool Mprotect (int prot)
 Sets the protection of the memory-mapped region by calling mprotect(). More...
 
bool is_valid () const
 
void * addr () const
 Returns the base address of the memory-mapped region.
 
template<typename T >
addr_as () const
 Returns the base address of the memory-mapped region, casted to a type of the caller’s choosing.
 
size_t len () const
 Returns the size of the memory-mapped region. More...
 

Detailed Description

Maintains a memory-mapped region created by mmap().

On destruction, any memory-mapped region managed by an object of this class will be released by calling munmap().

Member Function Documentation

◆ is_valid()

bool crashpad::ScopedMmap::is_valid ( ) const
inline
Returns
Whether this object is managing a valid memory-mapped region.

◆ len()

size_t crashpad::ScopedMmap::len ( ) const
inline

Returns the size of the memory-mapped region.

This is the value originally passed to ResetAddrLen() or ResetMmap(), or after Reset(), 0. It may not be a round number of pages. Providing the passed-in value is intended to ease tracking the intended lengths of memory-mapped regions backed by files whose sizes are not whole pages.

◆ Mprotect()

bool crashpad::ScopedMmap::Mprotect ( int  prot)

Sets the protection of the memory-mapped region by calling mprotect().

prot is passed directly to mprotect().

Returns
true on success. false on failure, with a message logged.

◆ Reset()

bool crashpad::ScopedMmap::Reset ( )

Releases the memory-mapped region by calling munmap().

Returns
true on success. false on failure, with a message logged.

◆ ResetAddrLen()

bool crashpad::ScopedMmap::ResetAddrLen ( void *  addr,
size_t  len 
)

Releases any existing memory-mapped region and sets the object to maintain an already-established mapping.

If addr and len indicate a region that overlaps with the existing memory-mapped region, only the portion of the existing memory-mapped region that does not overlap the new region, if any, will be released.

Parameters
[in]addrThe base address of the existing memory-mapped region to maintain.
[in]lenThe size of the existing memory-mapped region to maintain.
Returns
true on success. false on failure, with a message logged.

◆ ResetMmap()

bool crashpad::ScopedMmap::ResetMmap ( void *  addr,
size_t  len,
int  prot,
int  flags,
int  fd,
off_t  offset 
)

Releases any existing memory-mapped region and establishes a new one by calling mmap().

The parameters to this method are passed directly to mmap().

Returns
true on success. false on failure, with a message logged. A message will also be logged on failure to release any existing memory-mapped region, but this will not preclude mmap() from being called or a new mapping from being established, and if such a call to mmap() is successful, this method will return true.

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