The Pedigree Project  0.1
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MemoryMappedFile Class Reference

#include <MemoryMappedFile.h>

+ Inheritance diagram for MemoryMappedFile:
+ Collaboration diagram for MemoryMappedFile:

Public Member Functions

 MemoryMappedFile (uintptr_t address, size_t length, size_t offset, File *backing, bool bCopyOnWrite, Permissions perms)
 
virtual MemoryMappedObjectclone ()
 
virtual MemoryMappedObjectsplit (uintptr_t at)
 
virtual bool remove (size_t length)
 
virtual void setPermissions (MemoryMappedObject::Permissions perms)
 
virtual void sync (uintptr_t at, bool async)
 
virtual void invalidate (uintptr_t at)
 
virtual void unmap ()
 
virtual bool trap (uintptr_t address, bool bWrite)
 
virtual bool compact ()
 
- Public Member Functions inherited from MemoryMappedObject
 MemoryMappedObject (uintptr_t address, bool bCopyOnWrite, size_t length, Permissions perms)
 
bool matches (uintptr_t address)
 
uintptr_t address () const
 
size_t length () const
 

Private Member Functions

void unmapUnlocked ()
 
void trackMapping (uintptr_t, physical_uintptr_t)
 
void untrackMapping (uintptr_t)
 
physical_uintptr_t getMapping (uintptr_t)
 
size_t getMappingCount ()
 
void clearMappings ()
 

Private Attributes

Filem_pBacking
 
size_t m_Offset
 
Tree< uintptr_t, physical_uintptr_t > m_Mappings
 
Spinlock m_Lock
 

Additional Inherited Members

- Public Types inherited from MemoryMappedObject
typedef int Permissions
 
- Static Public Attributes inherited from MemoryMappedObject
static const int None = 0x0
 
static const int Read = 0x1
 
static const int Write = 0x2
 
static const int Exec = 0x4
 
- Protected Attributes inherited from MemoryMappedObject
bool m_bCopyOnWrite
 
uintptr_t m_Address
 
size_t m_Length
 
Permissions m_Permissions
 

Detailed Description

File map object.

File maps actually provide a backing file for a memory region. These are used for loading binaries or for opening files for reading without the overhead of read/write syscalls (assuming the syscall is more expensive than a page fault).

Definition at line 323 of file MemoryMappedFile.h.

Member Function Documentation

void MemoryMappedFile::clearMappings ( )
private

Clear all mappings.

Definition at line 951 of file MemoryMappedFile.cc.

MemoryMappedObject * MemoryMappedFile::clone ( )
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.

Implements MemoryMappedObject.

Definition at line 359 of file MemoryMappedFile.cc.

References m_Mappings.

bool MemoryMappedFile::compact ( )
virtual

Syncs back all dirty pages to their respective backing store.

Compacting begins by doing a pass to find any pages that can be synced and then unpinned, allowing a future Cache eviction. Should that pass successfully free memory, the compact will be considered successful.

If that pass is not successful, read-only pages are evicted. At this stage, this is done in a linear fashion; there is no LRU or other type of algorithm at play.

Todo:
Improve this.
Returns
true if at least one page was released, false otherwise.

Reimplemented from MemoryMappedObject.

Definition at line 807 of file MemoryMappedFile.cc.

References PhysicalMemoryManager::freePage(), VirtualAddressSpace::getMapping(), PhysicalMemoryManager::getPageSize(), Processor::information(), PhysicalMemoryManager::instance(), VirtualAddressSpace::isMapped(), NOTICE, VirtualAddressSpace::unmap(), and VirtualAddressSpace::Write.

physical_uintptr_t MemoryMappedFile::getMapping ( uintptr_t  addr)
private

Get a specific mapping.

Definition at line 941 of file MemoryMappedFile.cc.

size_t MemoryMappedFile::getMappingCount ( )
private

Get the number of mappings we currently have.

Definition at line 946 of file MemoryMappedFile.cc.

void MemoryMappedFile::invalidate ( uintptr_t  at)
virtual
bool MemoryMappedFile::remove ( size_t  length)
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.

Implements MemoryMappedObject.

Definition at line 423 of file MemoryMappedFile.cc.

References PhysicalMemoryManager::freePage(), VirtualAddressSpace::getMapping(), PhysicalMemoryManager::getPageSize(), Processor::information(), PhysicalMemoryManager::instance(), VirtualAddressSpace::isMapped(), VirtualAddressSpace::unmap(), and VirtualAddressSpace::Write.

void MemoryMappedFile::setPermissions ( MemoryMappedObject::Permissions  perms)
virtual
MemoryMappedObject * MemoryMappedFile::split ( uintptr_t  at)
virtual

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

Implements MemoryMappedObject.

Definition at line 379 of file MemoryMappedFile.cc.

References ERROR, PhysicalMemoryManager::getPageSize(), and trackMapping().

void MemoryMappedFile::sync ( uintptr_t  at,
bool  async 
)
virtual

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

Reimplemented from MemoryMappedObject.

Definition at line 579 of file MemoryMappedFile.cc.

References ERROR, VirtualAddressSpace::getMapping(), Processor::information(), VirtualAddressSpace::isMapped(), and VirtualAddressSpace::Write.

void MemoryMappedFile::trackMapping ( uintptr_t  addr,
physical_uintptr_t  phys 
)
private

Track a new mapping.

Definition at line 931 of file MemoryMappedFile.cc.

Referenced by split().

+ Here is the caller graph for this function:

bool MemoryMappedFile::trap ( uintptr_t  address,
bool  bWrite 
)
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.
Todo:
how to manage this with potentially more traps taking place?

Implements MemoryMappedObject.

Definition at line 683 of file MemoryMappedFile.cc.

References PhysicalMemoryManager::allocatePage(), DEBUG_LOG, ERROR, VirtualAddressSpace::Execute, PhysicalMemoryManager::getPageSize(), Processor::information(), PhysicalMemoryManager::instance(), VirtualAddressSpace::isMapped(), VirtualAddressSpace::map(), NOTICE, VirtualAddressSpace::Shared, VirtualAddressSpace::unmap(), and VirtualAddressSpace::Write.

void MemoryMappedFile::unmap ( )
virtual

Unmaps existing mappings in this object from the address space.

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

Implements MemoryMappedObject.

Definition at line 676 of file MemoryMappedFile.cc.

void MemoryMappedFile::untrackMapping ( uintptr_t  addr)
private

Stop tracking a mapping.

Definition at line 936 of file MemoryMappedFile.cc.

Member Data Documentation

Spinlock MemoryMappedFile::m_Lock
private

Lock for anything to do with the memory mapped file.

Definition at line 390 of file MemoryMappedFile.h.

Tree<uintptr_t, physical_uintptr_t> MemoryMappedFile::m_Mappings
private

List of existing mappings.

Definition at line 387 of file MemoryMappedFile.h.

Referenced by clone().

size_t MemoryMappedFile::m_Offset
private

Offset within the file that this mapping begins at.

Definition at line 384 of file MemoryMappedFile.h.

File* MemoryMappedFile::m_pBacking
private

Backing file.

Definition at line 381 of file MemoryMappedFile.h.


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