|
The Pedigree Project 0.1
|
#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, Permissions maximumPerms=Read|Write|Exec, const SharedPointer< MappingAttachment > &attachment=SharedPointer< MappingAttachment >(), const FileMappingOrigin &origin={}, bool executableUse=false) | |
| virtual MemoryMappedObject * | clone () override |
| virtual MemoryMappedObject * | split (uintptr_t at) override |
| MemoryMappedObject * | stageSlice (uintptr_t source, size_t sourceLength, uintptr_t destination, size_t destinationLength) override |
| void | releaseDetachedPage (uintptr_t oldAddress, const VirtualAddressSpace::DetachedPage &page) override |
| void | discardRange (VirtualAddressSpace &space, uintptr_t base, size_t length) override |
| File * | backingFile () const override |
| bool | backingRangeValid (uintptr_t source, size_t length) const override |
| bool | resident (VirtualAddressSpace &space, uintptr_t address, FileResidencyAccess access, void *credentials) override |
| virtual bool | remove (size_t length) override |
| virtual void | setPermissions (MemoryMappedObject::Permissions perms) override |
| virtual bool | sync (uintptr_t at, bool async) override |
| bool | syncRange (uintptr_t at, size_t length, bool async) override |
| virtual void | invalidate (uintptr_t at) override |
| virtual bool | sharedBacking (uintptr_t at, uintptr_t &identity, size_t &offset) const override |
| virtual bool | usesBacking (uintptr_t identity) const override |
| virtual bool | beyondBackingEnd (uintptr_t at) const override |
| virtual void | discardFilePages (VirtualAddressSpace &space, size_t end) override |
| virtual bool | preparePermissions (uintptr_t base, size_t length, Permissions perms) override |
| virtual void | unmap () override |
| virtual bool | trap (VirtualAddressSpace &space, uintptr_t address, bool bWrite, PopulationStatus *population=nullptr) override |
| virtual bool | compact () override |
Public Member Functions inherited from MemoryMappedObject | |
| MemoryMappedObject (uintptr_t address, bool bCopyOnWrite, size_t length, Permissions perms, Permissions maximumPerms=Read|Write|Exec) | |
| void | setMappingOwnership (bool ownsMappings) |
| 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) |
| bool | matches (uintptr_t address) |
| uintptr_t | address () const |
| size_t | length () const |
| Permissions | permissions () const |
| Permissions | maximumPermissions () const |
Private Member Functions | |
| void | unmapUnlocked () |
| physical_uintptr_t | getBackingPage (size_t fileOffset, size_t mappingBytes) |
| void | releaseDetachedPageUnlocked (uintptr_t oldAddress, const VirtualAddressSpace::DetachedPage &page) |
| 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 |
| size_t | m_ReadAheadEnd = ~size_t{0} |
| size_t | m_ReadAheadPages = 4 |
| Tree< uintptr_t, physical_uintptr_t > | m_Mappings |
| FileMappingOrigin | m_Origin |
| Mutex | m_Lock |
| bool | m_bVfsLease |
| bool | m_ExecutableUse |
| bool | m_SharedWriteUse |
| bool | m_UseAdmitted |
| bool | m_MountAdmitted |
Friends | |
| class | MemoryMapManager |
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 |
| Permissions | m_MaximumPermissions |
| SharedPointer< MappingAttachment > | m_Attachment |
| Process * | m_OwnerProcess |
| bool | m_OwnsMappings |
| MemoryLockMode | m_LockMode |
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 443 of file MemoryMappedFile.h.
| MemoryMappedFile::MemoryMappedFile | ( | uintptr_t | address, |
| size_t | length, | ||
| size_t | offset, | ||
| File * | backing, | ||
| bool | bCopyOnWrite, | ||
| MemoryMappedObject::Permissions | perms, | ||
| MemoryMappedObject::Permissions | maximumPerms = Read | Write | Exec, |
||
| const SharedPointer< MappingAttachment > & | attachment = SharedPointer<MappingAttachment>(), |
||
| const FileMappingOrigin & | origin = {}, |
||
| bool | executableUse = false |
||
| ) |
Definition at line 177 of file MemoryMappedFile.cc.
|
overridevirtual |
Definition at line 199 of file MemoryMappedFile.cc.
|
inlineoverridevirtual |
Reimplemented from MemoryMappedObject.
Definition at line 462 of file MemoryMappedFile.h.
|
overridevirtual |
Reimplemented from MemoryMappedObject.
Definition at line 13 of file MemoryMappedFile-remap.cc.
|
overridevirtual |
Reimplemented from MemoryMappedObject.
Definition at line 387 of file MemoryMappedFile.cc.
|
private |
Clear all mappings.
Definition at line 786 of file MemoryMappedFile.cc.
References Tree< K, E >::clear(), and m_Mappings.
|
overridevirtual |
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 213 of file MemoryMappedFile.cc.
References Tree< K, E >::begin(), Tree< K, E >::end(), File::getPhysicalPage(), MemoryMappedObject::m_Address, MemoryMappedObject::m_bCopyOnWrite, MemoryMappedObject::m_Length, m_Lock, m_Mappings, m_Offset, m_pBacking, and MemoryMappedObject::m_Permissions.
|
overridevirtual |
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 696 of file MemoryMappedFile.cc.
References MemoryMappedObject::address(), VirtualAddressSpace::detachMapping(), getMapping(), PhysicalMemoryManager::getPageSize(), ProcessorBase::information(), MemoryMappedObject::m_Address, MemoryMappedObject::m_bCopyOnWrite, MemoryMappedObject::m_Length, m_Lock, m_Offset, m_pBacking, Semaphore::release(), File::returnPhysicalPage(), File::sync(), Semaphore::tryAcquire(), File::tryBeginMappingRelease(), and untrackMapping().
|
overridevirtual |
Reimplemented from MemoryMappedObject.
Definition at line 395 of file MemoryMappedFile.cc.
|
overridevirtual |
Implements MemoryMappedObject.
Definition at line 57 of file MemoryMappedFile-advice.cc.
|
private |
Definition at line 428 of file MemoryMappedFile.cc.
|
private |
Get a specific mapping.
Definition at line 778 of file MemoryMappedFile.cc.
References Tree< K, E >::lookup(), and m_Mappings.
Referenced by compact(), remove(), split(), sync(), and syncRange().
Here is the caller graph for this function:
|
private |
Get the number of mappings we currently have.
Definition at line 782 of file MemoryMappedFile.cc.
References Tree< K, E >::count(), and m_Mappings.
|
overridevirtual |
Invalidate cached state without discarding private modifications.
Reimplemented from MemoryMappedObject.
Definition at line 522 of file MemoryMappedFile.cc.
|
overridevirtual |
Reimplemented from MemoryMappedObject.
Definition at line 359 of file MemoryMappedFile.cc.
|
overridevirtual |
Implements MemoryMappedObject.
Definition at line 51 of file MemoryMappedFile-advice.cc.
|
private |
Definition at line 35 of file MemoryMappedFile-advice.cc.
|
overridevirtual |
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 278 of file MemoryMappedFile.cc.
References PhysicalMemoryManager::freePage(), getMapping(), VirtualAddressSpace::getMapping(), PhysicalMemoryManager::getPageSize(), ProcessorBase::information(), PhysicalMemoryManager::instance(), VirtualAddressSpace::isMapped(), MemoryMappedObject::length(), MemoryMappedObject::m_Address, MemoryMappedObject::m_bCopyOnWrite, MemoryMappedObject::m_Length, m_Lock, m_Offset, m_pBacking, File::returnPhysicalPage(), File::syncAndReturnPhysicalPage(), VirtualAddressSpace::unmap(), and untrackMapping().
|
overridevirtual |
Reimplemented from MemoryMappedObject.
Definition at line 17 of file MemoryMappedFile-advice.cc.
|
overridevirtual |
Sets permissions on this object.
Resident pages retain their contents and ownership.
Implements MemoryMappedObject.
Definition at line 331 of file MemoryMappedFile.cc.
References File::acquireMappingUse(), MemoryMappedObject::address(), Tree< K, E >::begin(), Tree< K, E >::end(), VirtualAddressSpace::getMapping(), ProcessorBase::information(), VirtualAddressSpace::isMapped(), MemoryMappedObject::m_Address, MemoryMappedObject::m_bCopyOnWrite, m_Lock, m_Mappings, m_Offset, m_pBacking, MemoryMappedObject::m_Permissions, File::markPageExternallyWritable(), VirtualAddressSpace::setFlags(), and VirtualAddressSpace::Write.
|
overridevirtual |
Reimplemented from MemoryMappedObject.
Definition at line 374 of file MemoryMappedFile.cc.
|
overridevirtual |
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 234 of file MemoryMappedFile.cc.
References Tree< K, E >::contains(), getMapping(), PhysicalMemoryManager::getPageSize(), MemoryMappedObject::m_Address, MemoryMappedObject::m_bCopyOnWrite, MemoryMappedObject::m_Length, m_Lock, m_Mappings, m_Offset, m_pBacking, MemoryMappedObject::m_Permissions, trackMapping(), and untrackMapping().
|
overridevirtual |
Prepared slices transfer existing page ownership only after publication.
Implements MemoryMappedObject.
Definition at line 18 of file MemoryMappedFile-remap.cc.
References Tree< K, E >::begin(), Tree< K, E >::count(), Tree< K, E >::end(), MemoryMappedObject::m_Address, MemoryMappedObject::m_bCopyOnWrite, MemoryMappedObject::m_Length, m_Mappings, m_Offset, m_pBacking, and MemoryMappedObject::m_Permissions.
|
overridevirtual |
Sync back the given page to a backing store, if one exists.
Reimplemented from MemoryMappedObject.
Definition at line 512 of file MemoryMappedFile.cc.
References getMapping(), MemoryMappedObject::m_Address, MemoryMappedObject::m_bCopyOnWrite, MemoryMappedObject::m_Length, m_Lock, m_Offset, m_pBacking, and File::sync().
|
overridevirtual |
Synchronise a contiguous mapping range without imposing a barrier per page.
Reimplemented from MemoryMappedObject.
Definition at line 478 of file MemoryMappedFile.cc.
References MemoryMappedObject::address(), getMapping(), PhysicalMemoryManager::getPageSize(), MemoryMappedObject::length(), MemoryMappedObject::m_Address, MemoryMappedObject::m_bCopyOnWrite, MemoryMappedObject::m_Length, m_Lock, m_Offset, m_pBacking, File::sync(), and File::syncPages().
|
private |
Track a new mapping.
Definition at line 770 of file MemoryMappedFile.cc.
References Tree< K, E >::insert(), and m_Mappings.
Referenced by split().
Here is the caller graph for this function:
|
overridevirtual |
Trap entry
Implement this in your implementation to actually perform the mapping of memory into the address space.
Implements MemoryMappedObject.
Definition at line 534 of file MemoryMappedFile.cc.
References MemoryMappedObject::address(), PhysicalMemoryManager::allocatePage(), VirtualAddressSpace::Borrowed, VirtualAddressSpace::CacheDisable, EMIT_IF, VirtualAddressSpace::Execute, PhysicalMemoryManager::freePage(), PhysicalMemoryManager::getPageSize(), ProcessorBase::information(), PhysicalMemoryManager::instance(), VirtualAddressSpace::isMapped(), MemoryMappedObject::m_Address, MemoryMappedObject::m_bCopyOnWrite, MemoryMappedObject::m_Length, m_Lock, m_Mappings, m_Offset, m_pBacking, MemoryMappedObject::m_Permissions, VirtualAddressSpace::map(), File::markPageExternallyWritable(), File::prepareSharedMapping(), File::read(), File::returnPhysicalPage(), VirtualAddressSpace::Shared, Tree< K, E >::tryInsert(), VirtualAddressSpace::unmap(), untrackMapping(), VirtualAddressSpace::Write, VirtualAddressSpace::WriteCombine, and VirtualAddressSpace::WriteThrough.
|
overridevirtual |
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 527 of file MemoryMappedFile.cc.
References m_Lock.
|
private |
Definition at line 734 of file MemoryMappedFile.cc.
|
private |
Stop tracking a mapping.
Definition at line 774 of file MemoryMappedFile.cc.
References m_Mappings, and Tree< K, E >::remove().
Referenced by compact(), remove(), split(), and trap().
Here is the caller graph for this function:
|
overridevirtual |
Reimplemented from MemoryMappedObject.
Definition at line 383 of file MemoryMappedFile.cc.
|
friend |
Definition at line 444 of file MemoryMappedFile.h.
|
private |
Whether this mapping retained an established VFS File owner.
Definition at line 548 of file MemoryMappedFile.h.
|
private |
Definition at line 549 of file MemoryMappedFile.h.
|
private |
Lock for anything to do with the memory mapped file.
Backing-file reads and synchronisation may block, so this must be a sleeping lock rather than a Spinlock.
Definition at line 545 of file MemoryMappedFile.h.
Referenced by clone(), compact(), remove(), setPermissions(), split(), sync(), syncRange(), trap(), and unmap().
|
private |
List of existing mappings.
Definition at line 536 of file MemoryMappedFile.h.
Referenced by clearMappings(), clone(), getMapping(), getMappingCount(), setPermissions(), split(), stageSlice(), trackMapping(), trap(), and untrackMapping().
|
private |
Definition at line 552 of file MemoryMappedFile.h.
|
private |
Offset within the file that this mapping begins at.
Definition at line 530 of file MemoryMappedFile.h.
Referenced by clone(), compact(), remove(), setPermissions(), split(), stageSlice(), sync(), syncRange(), and trap().
|
private |
Definition at line 537 of file MemoryMappedFile.h.
|
private |
Backing file.
Definition at line 527 of file MemoryMappedFile.h.
Referenced by clone(), compact(), remove(), setPermissions(), split(), stageSlice(), sync(), syncRange(), and trap().
|
private |
Definition at line 532 of file MemoryMappedFile.h.
|
private |
Definition at line 533 of file MemoryMappedFile.h.
|
private |
Definition at line 550 of file MemoryMappedFile.h.
|
private |
Definition at line 551 of file MemoryMappedFile.h.