The Pedigree Project  0.1
Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | Private Member Functions | Friends | List of all members
MemoryMappedObject Class Referenceabstract

#include <MemoryMappedFile.h>

+ Inheritance diagram for MemoryMappedObject:
+ Collaboration diagram for MemoryMappedObject:

Public Types

typedef int Permissions
 

Public Member Functions

 MemoryMappedObject (uintptr_t address, bool bCopyOnWrite, size_t length, Permissions perms)
 
virtual MemoryMappedObjectclone ()=0
 
virtual MemoryMappedObjectsplit (uintptr_t at)=0
 
virtual bool remove (size_t length)=0
 
virtual void setPermissions (Permissions perms)=0
 
virtual void sync (uintptr_t at, bool async)
 
virtual void invalidate (uintptr_t at)
 
virtual void unmap ()=0
 
virtual bool trap (uintptr_t address, bool bWrite)=0
 
virtual bool compact ()
 
bool matches (uintptr_t address)
 
uintptr_t address () const
 
size_t length () const
 

Static Public Attributes

static const int None = 0x0
 
static const int Read = 0x1
 
static const int Write = 0x2
 
static const int Exec = 0x4
 

Protected Attributes

bool m_bCopyOnWrite
 
uintptr_t m_Address
 
size_t m_Length
 
Permissions m_Permissions
 

Private Member Functions

 MemoryMappedObject ()
 

Friends

class MemoryMapManager
 

Detailed Description

Generic base for a memory mapped file or object.

Provides the interface for implementation, while centralising common functionality (such as extents, CoW flags, shared state, etc)

Definition at line 108 of file MemoryMappedFile.h.

Member Typedef Documentation

Permissions to assign to a mapping when it is created.

Definition at line 118 of file MemoryMappedFile.h.

Constructor & Destructor Documentation

MemoryMappedObject::MemoryMappedObject ( )
private

Default constructor, don't use.

MemoryMappedObject::MemoryMappedObject ( uintptr_t  address,
bool  bCopyOnWrite,
size_t  length,
Permissions  perms 
)
inline

Constructor - bring up common metadata.

Definition at line 126 of file MemoryMappedFile.h.

References clone(), length(), setPermissions(), and split().

Member Function Documentation

uintptr_t MemoryMappedObject::address ( ) const
inline

Getter for base address.

Definition at line 225 of file MemoryMappedFile.h.

References m_Address.

Referenced by MemoryMapManager::instance(), invalidate(), MemoryMapManager::remove(), and MemoryMapManager::setPermissions().

+ Here is the caller graph for this function:

virtual MemoryMappedObject* MemoryMappedObject::clone ( )
pure virtual

Clones the existing metadata of this object into another.

Returns a MemoryMappedObject that exactly matches this one, but which can be used for reference in a new address space. Used for address space clones.

Note that mappings are automatically cloned - only clone metadata in this method.

Implemented in MemoryMappedFile, and AnonymousMemoryMap.

Referenced by MemoryMapManager::clone(), MemoryMapManager::instance(), and MemoryMappedObject().

+ Here is the caller graph for this function:

virtual bool MemoryMappedObject::compact ( )
inlinevirtual

Release memory that can be released.

Default implementation returns 'no pages released'.

Reimplemented in MemoryMappedFile.

Definition at line 209 of file MemoryMappedFile.h.

Referenced by MemoryMapManager::instance().

+ Here is the caller graph for this function:

virtual void MemoryMappedObject::invalidate ( uintptr_t  at)
inlinevirtual

If the given page is dirty (and this is a CoW mapping), restore it to the file's actual content.

Reimplemented in MemoryMappedFile.

Definition at line 183 of file MemoryMappedFile.h.

References address(), trap(), and unmap().

Referenced by MemoryMapManager::contains(), and MemoryMapManager::instance().

+ Here is the caller graph for this function:

size_t MemoryMappedObject::length ( ) const
inline

Getter for length.

Definition at line 233 of file MemoryMappedFile.h.

References m_Length.

Referenced by MemoryMapManager::instance(), MemoryMappedObject(), MemoryMapManager::remove(), and MemoryMapManager::setPermissions().

+ Here is the caller graph for this function:

bool MemoryMappedObject::matches ( uintptr_t  address)
inline

Determines if the given address is within this object's mapping.

Definition at line 217 of file MemoryMappedFile.h.

References m_Address, and m_Length.

Referenced by MemoryMapManager::contains(), and MemoryMapManager::trap().

+ Here is the caller graph for this function:

virtual bool MemoryMappedObject::remove ( size_t  length)
pure virtual

Removes pages from the start of this MemoryMappedObject.

To remove pages from the middle or end of a MemoryMappedObject, use split() and then remove()/unmap() on the returned object).

Returns
true if the remove() has effectively removed the entire MemoryMappedObject, false otherwise.

Implemented in MemoryMappedFile, and AnonymousMemoryMap.

Referenced by MemoryMapManager::remove().

+ Here is the caller graph for this function:

virtual void MemoryMappedObject::setPermissions ( Permissions  perms)
pure virtual

Sets permissions on this object.

This may trigger unmaps if the new permissions.

Implemented in MemoryMappedFile, and AnonymousMemoryMap.

Referenced by MemoryMapManager::instance(), MemoryMappedObject(), and MemoryMapManager::setPermissions().

+ Here is the caller graph for this function:

virtual MemoryMappedObject* MemoryMappedObject::split ( uintptr_t  at)
pure virtual

Splits the metadata of this object at the given address and creates a new MemoryMappedObject that begins at the page of the split.

Implemented in MemoryMappedFile, and AnonymousMemoryMap.

Referenced by MemoryMappedObject(), MemoryMapManager::remove(), and MemoryMapManager::setPermissions().

+ Here is the caller graph for this function:

virtual void MemoryMappedObject::sync ( uintptr_t  at,
bool  async 
)
inlinevirtual

Sync back the given page to a backing store, if one exists.

Reimplemented in MemoryMappedFile.

Definition at line 175 of file MemoryMappedFile.h.

Referenced by MemoryMapManager::contains(), and MemoryMapManager::instance().

+ Here is the caller graph for this function:

virtual bool MemoryMappedObject::trap ( uintptr_t  address,
bool  bWrite 
)
pure virtual

Trap entry

Implement this in your implementation to actually perform the mapping of memory into the address space.

Returns
true if the trap was successful, false otherwise.

Implemented in MemoryMappedFile, and AnonymousMemoryMap.

Referenced by MemoryMapManager::instance(), invalidate(), and MemoryMapManager::trap().

+ Here is the caller graph for this function:

virtual void MemoryMappedObject::unmap ( )
pure virtual

Unmaps existing mappings in this object from the address space.

Implementations are expected to track these as necessary for the implementation.

Implemented in MemoryMappedFile, and AnonymousMemoryMap.

Referenced by MemoryMapManager::instance(), invalidate(), and MemoryMapManager::remove().

+ Here is the caller graph for this function:

Member Data Documentation

uintptr_t MemoryMappedObject::m_Address
protected

Base address of this mapping.

The region from base -> base+length will trap into this object when an access attempt is made that faults.

Definition at line 254 of file MemoryMappedFile.h.

Referenced by address(), and matches().

bool MemoryMappedObject::m_bCopyOnWrite
protected

Is this a Copy-on-Write mapping?

A non-copy-on-write mapping will cause writes to hit the backing store directly. This makes sense for some types of mapping and not for others.

Definition at line 246 of file MemoryMappedFile.h.

size_t MemoryMappedObject::m_Length
protected

Size of the object.

To clarify, this is the size of the mapping itself, not of the entire backing object.

Definition at line 262 of file MemoryMappedFile.h.

Referenced by length(), and matches().

Permissions MemoryMappedObject::m_Permissions
protected

Permissions for mappings created by this object.

For example, 'None' would mean that a trap will NEVER succeed, and that no premapping will be done. 'Read' might mean that writes will never magically map in a page for writing to.

'Exec' only works on systems that support this (eg, x86_64).

Definition at line 273 of file MemoryMappedFile.h.


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