The Pedigree Project
0.1
|
#include <MemoryMappedFile.h>
Public Member Functions | |
MemoryMappedFile (uintptr_t address, size_t length, size_t offset, File *backing, bool bCopyOnWrite, Permissions perms) | |
virtual MemoryMappedObject * | clone () |
virtual MemoryMappedObject * | split (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 | |
File * | m_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 |
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.
|
private |
Clear all mappings.
Definition at line 951 of file MemoryMappedFile.cc.
|
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.
|
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.
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.
|
private |
Get a specific mapping.
Definition at line 941 of file MemoryMappedFile.cc.
|
private |
Get the number of mappings we currently have.
Definition at line 946 of file MemoryMappedFile.cc.
|
virtual |
If the given page is dirty (and this is a CoW mapping), restore it to the file's actual content.
Reimplemented from MemoryMappedObject.
Definition at line 616 of file MemoryMappedFile.cc.
References ERROR, VirtualAddressSpace::Execute, PhysicalMemoryManager::freePage(), Processor::information(), PhysicalMemoryManager::instance(), VirtualAddressSpace::isMapped(), VirtualAddressSpace::map(), VirtualAddressSpace::Shared, and VirtualAddressSpace::unmap().
|
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).
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.
|
virtual |
Sets permissions on this object.
This may trigger unmaps if the new permissions.
Implements MemoryMappedObject.
Definition at line 483 of file MemoryMappedFile.cc.
References Spinlock::acquire(), ERROR, VirtualAddressSpace::Execute, VirtualAddressSpace::getMapping(), File::getName(), PhysicalMemoryManager::getPageSize(), File::getPhysicalPage(), Processor::information(), VirtualAddressSpace::isMapped(), File::read(), Spinlock::release(), VirtualAddressSpace::setFlags(), VirtualAddressSpace::Shared, and VirtualAddressSpace::Write.
|
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().
|
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.
|
private |
Track a new mapping.
Definition at line 931 of file MemoryMappedFile.cc.
Referenced by split().
|
virtual |
Trap entry
Implement this in your implementation to actually perform the mapping of memory into the address space.
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.
|
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.
|
private |
Stop tracking a mapping.
Definition at line 936 of file MemoryMappedFile.cc.
|
private |
Lock for anything to do with the memory mapped file.
Definition at line 390 of file MemoryMappedFile.h.
|
private |
List of existing mappings.
Definition at line 387 of file MemoryMappedFile.h.
Referenced by clone().
|
private |
Offset within the file that this mapping begins at.
Definition at line 384 of file MemoryMappedFile.h.
|
private |
Backing file.
Definition at line 381 of file MemoryMappedFile.h.