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, Permissions maximumPerms=Read|Write|Exec)
 
virtual MemoryMappedObject * clone ()=0
 
virtual MemoryMappedObject * split (uintptr_t at)=0
 
virtual MemoryMappedObject * stageSlice (uintptr_t source, size_t sourceLength, uintptr_t destination, size_t destinationLength)=0
 
void setMappingOwnership (bool ownsMappings)
 
virtual void releaseDetachedPage (uintptr_t oldAddress, const VirtualAddressSpace::DetachedPage &page)=0
 
virtual void discardRange (VirtualAddressSpace &space, uintptr_t base, size_t length)=0
 
virtual File * backingFile () const
 
virtual bool backingRangeValid (uintptr_t source, size_t length) const
 
virtual bool resident (VirtualAddressSpace &space, uintptr_t address, FileResidencyAccess access, void *credentials)
 
virtual bool remove (size_t length)=0
 
virtual void setPermissions (Permissions perms)=0
 
virtual bool preparePermissions (uintptr_t base, size_t length, Permissions perms)
 
virtual bool sync (uintptr_t at, bool async)
 
virtual bool syncRange (uintptr_t at, size_t length, bool async)
 
virtual void invalidate (uintptr_t at)
 
virtual bool sharedBacking (uintptr_t at, uintptr_t &identity, size_t &offset) const
 
virtual bool usesBacking (uintptr_t identity) const
 
virtual bool beyondBackingEnd (uintptr_t at) const
 
virtual void discardFilePages (VirtualAddressSpace &space, size_t end)
 
virtual void unmap ()=0
 
virtual bool trap (VirtualAddressSpace &space, uintptr_t address, bool bWrite, PopulationStatus *population=nullptr)=0
 
virtual PopulationStatus prepareResidentAccess (VirtualAddressSpace &space, uintptr_t address)
 
PopulationStatus populatePage (VirtualAddressSpace &space, uintptr_t address)
 
MemoryLockMode lockMode () const
 
virtual bool supportsPageOut (VirtualAddressSpace &space, uintptr_t address)
 
virtual SwapStatus pageOutAt (VirtualAddressSpace &space, uintptr_t address, bool &released)
 
virtual bool reclaimAnonymousPage (VirtualAddressSpace &space)
 
virtual SwapStatus restoreSwapPages (VirtualAddressSpace &space)
 
virtual bool compact ()
 
bool matches (uintptr_t address)
 
uintptr_t address () const
 
size_t length () const
 
Permissions permissions () const
 
Permissions maximumPermissions () 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
 
Permissions m_MaximumPermissions
 
SharedPointer< MappingAttachment > m_Attachment
 
Process * m_OwnerProcess
 
bool m_OwnsMappings
 
MemoryLockMode m_LockMode
 

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 138 of file MemoryMappedFile.h.

Member Typedef Documentation

◆ Permissions

Permissions to assign to a mapping when it is created.

Definition at line 147 of file MemoryMappedFile.h.

Constructor & Destructor Documentation

◆ MemoryMappedObject() [1/2]

MemoryMappedObject::MemoryMappedObject ( )
private

Default constructor, don't use.

◆ MemoryMappedObject() [2/2]

MemoryMappedObject::MemoryMappedObject ( uintptr_t  address,
bool  bCopyOnWrite,
size_t  length,
Permissions  perms,
Permissions  maximumPerms = Read | Write | Exec 
)
inline

Constructor - bring up common metadata.

Definition at line 155 of file MemoryMappedFile.h.

◆ ~MemoryMappedObject()

MemoryMappedObject::~MemoryMappedObject ( )
virtual

Definition at line 138 of file MemoryMappedFile.cc.

Member Function Documentation

◆ address()

uintptr_t MemoryMappedObject::address ( ) const
inline

◆ backingFile()

virtual File * MemoryMappedObject::backingFile ( ) const
inlinevirtual

Definition at line 197 of file MemoryMappedFile.h.

◆ backingRangeValid()

virtual bool MemoryMappedObject::backingRangeValid ( uintptr_t  source,
size_t  length 
) const
inlinevirtual

Definition at line 200 of file MemoryMappedFile.h.

◆ beyondBackingEnd()

virtual bool MemoryMappedObject::beyondBackingEnd ( uintptr_t  at) const
inlinevirtual

Definition at line 248 of file MemoryMappedFile.h.

◆ clone()

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 AnonymousMemoryMap, and MemoryMappedFile.

Referenced by MemoryMapManager::clone().

+ Here is the caller graph for this function:

◆ compact()

virtual bool MemoryMappedObject::compact ( )
inlinevirtual

Reimplemented in MemoryMappedFile.

Definition at line 295 of file MemoryMappedFile.h.

◆ discardFilePages()

virtual void MemoryMappedObject::discardFilePages ( VirtualAddressSpace &  space,
size_t  end 
)
inlinevirtual

Definition at line 251 of file MemoryMappedFile.h.

◆ invalidate()

virtual void MemoryMappedObject::invalidate ( uintptr_t  at)
inlinevirtual

Invalidate cached state without discarding private modifications.

Reimplemented in MemoryMappedFile.

Definition at line 239 of file MemoryMappedFile.h.

◆ length()

size_t MemoryMappedObject::length ( ) const
inline

◆ lockMode()

MemoryLockMode MemoryMappedObject::lockMode ( ) const
inline

Definition at line 274 of file MemoryMappedFile.h.

◆ matches()

bool MemoryMappedObject::matches ( uintptr_t  address)
inline

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

Definition at line 302 of file MemoryMappedFile.h.

References address(), m_Address, and m_Length.

Referenced by MemoryMapManager::contains().

+ Here is the caller graph for this function:

◆ maximumPermissions()

Permissions MemoryMappedObject::maximumPermissions ( ) const
inline

Definition at line 325 of file MemoryMappedFile.h.

◆ pageOutAt()

virtual SwapStatus MemoryMappedObject::pageOutAt ( VirtualAddressSpace &  space,
uintptr_t  address,
bool &  released 
)
inlinevirtual

Definition at line 286 of file MemoryMappedFile.h.

◆ permissions()

Permissions MemoryMappedObject::permissions ( ) const
inline

Permissions granted to this mapping.

Definition at line 321 of file MemoryMappedFile.h.

References m_Permissions.

Referenced by MemoryMapManager::allows(), and AnonymousMemoryMap::setPermissions().

+ Here is the caller graph for this function:

◆ populatePage()

PopulationStatus MemoryMappedObject::populatePage ( VirtualAddressSpace &  space,
uintptr_t  address 
)

Definition at line 73 of file MemoryMappedFile-lock.cc.

◆ preparePermissions()

virtual bool MemoryMappedObject::preparePermissions ( uintptr_t  base,
size_t  length,
Permissions  perms 
)
inlinevirtual

Definition at line 224 of file MemoryMappedFile.h.

◆ prepareResidentAccess()

virtual PopulationStatus MemoryMappedObject::prepareResidentAccess ( VirtualAddressSpace &  space,
uintptr_t  address 
)
inlinevirtual

Definition at line 270 of file MemoryMappedFile.h.

◆ reclaimAnonymousPage()

virtual bool MemoryMappedObject::reclaimAnonymousPage ( VirtualAddressSpace &  space)
inlinevirtual

Definition at line 289 of file MemoryMappedFile.h.

◆ remove()

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 AnonymousMemoryMap, and MemoryMappedFile.

◆ resident()

bool MemoryMappedObject::resident ( VirtualAddressSpace &  space,
uintptr_t  address,
FileResidencyAccess  access,
void *  credentials 
)
virtual

Definition at line 12 of file MemoryMappedFile-advice.cc.

◆ restoreSwapPages()

virtual SwapStatus MemoryMappedObject::restoreSwapPages ( VirtualAddressSpace &  space)
inlinevirtual

Definition at line 292 of file MemoryMappedFile.h.

◆ setMappingOwnership()

void MemoryMappedObject::setMappingOwnership ( bool  ownsMappings)
inline

Definition at line 191 of file MemoryMappedFile.h.

◆ setPermissions()

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

Sets permissions on this object.

Resident pages retain their contents and ownership.

Implemented in AnonymousMemoryMap, and MemoryMappedFile.

◆ sharedBacking()

virtual bool MemoryMappedObject::sharedBacking ( uintptr_t  at,
uintptr_t &  identity,
size_t &  offset 
) const
inlinevirtual

Definition at line 241 of file MemoryMappedFile.h.

◆ split()

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 AnonymousMemoryMap, and MemoryMappedFile.

◆ stageSlice()

virtual MemoryMappedObject * MemoryMappedObject::stageSlice ( uintptr_t  source,
size_t  sourceLength,
uintptr_t  destination,
size_t  destinationLength 
)
pure virtual

Prepared slices transfer existing page ownership only after publication.

Implemented in AnonymousMemoryMap, and MemoryMappedFile.

◆ supportsPageOut()

virtual bool MemoryMappedObject::supportsPageOut ( VirtualAddressSpace &  space,
uintptr_t  address 
)
inlinevirtual

Release memory that can be released.

Default implementation returns 'no pages released'.

Reimplemented in AnonymousMemoryMap.

Definition at line 283 of file MemoryMappedFile.h.

◆ sync()

virtual bool 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 231 of file MemoryMappedFile.h.

Referenced by syncRange().

+ Here is the caller graph for this function:

◆ syncRange()

bool MemoryMappedObject::syncRange ( uintptr_t  at,
size_t  length,
bool  async 
)
virtual

Synchronise a contiguous mapping range without imposing a barrier per page.

Reimplemented in MemoryMappedFile.

Definition at line 470 of file MemoryMappedFile.cc.

References PhysicalMemoryManager::getPageSize(), length(), and sync().

◆ trap()

virtual bool MemoryMappedObject::trap ( VirtualAddressSpace &  space,
uintptr_t  address,
bool  bWrite,
PopulationStatus *  population = nullptr 
)
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 AnonymousMemoryMap, and MemoryMappedFile.

◆ unmap()

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 AnonymousMemoryMap, and MemoryMappedFile.

◆ usesBacking()

virtual bool MemoryMappedObject::usesBacking ( uintptr_t  identity) const
inlinevirtual

Definition at line 245 of file MemoryMappedFile.h.

Friends And Related Symbol Documentation

◆ MemoryMapManager

friend class MemoryMapManager
friend

Definition at line 139 of file MemoryMappedFile.h.

Member Data Documentation

◆ Exec

const int MemoryMappedObject::Exec = 0x4
static

Definition at line 152 of file MemoryMappedFile.h.

◆ m_Address

uintptr_t MemoryMappedObject::m_Address
protected

◆ m_Attachment

SharedPointer<MappingAttachment> MemoryMappedObject::m_Attachment
protected

Definition at line 366 of file MemoryMappedFile.h.

◆ m_bCopyOnWrite

bool MemoryMappedObject::m_bCopyOnWrite
protected

◆ m_Length

size_t MemoryMappedObject::m_Length
protected

◆ m_LockMode

MemoryLockMode MemoryMappedObject::m_LockMode
protected

Definition at line 371 of file MemoryMappedFile.h.

◆ m_MaximumPermissions

Permissions MemoryMappedObject::m_MaximumPermissions
protected

Definition at line 365 of file MemoryMappedFile.h.

◆ m_OwnerProcess

Process* MemoryMappedObject::m_OwnerProcess
protected

Definition at line 369 of file MemoryMappedFile.h.

◆ m_OwnsMappings

bool MemoryMappedObject::m_OwnsMappings
protected

Definition at line 370 of file MemoryMappedFile.h.

◆ m_Permissions

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 364 of file MemoryMappedFile.h.

Referenced by AnonymousMemoryMap::clone(), MemoryMappedFile::clone(), permissions(), AnonymousMemoryMap::setPermissions(), MemoryMappedFile::setPermissions(), MemoryMappedFile::split(), AnonymousMemoryMap::stageSlice(), MemoryMappedFile::stageSlice(), AnonymousMemoryMap::trap(), and MemoryMappedFile::trap().

◆ None

const int MemoryMappedObject::None = 0x0
static

Definition at line 149 of file MemoryMappedFile.h.

◆ Read

const int MemoryMappedObject::Read = 0x1
static

Definition at line 150 of file MemoryMappedFile.h.

◆ Write

const int MemoryMappedObject::Write = 0x2
static

Definition at line 151 of file MemoryMappedFile.h.


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