The Pedigree Project
0.1
|
#include <MemoryMappedFile.h>
Public Member Functions | |
MemoryMappedObject * | mapFile (File *pFile, uintptr_t &address, size_t length, MemoryMappedObject::Permissions perms, size_t offset=0, bool bCopyOnWrite=true) |
MemoryMappedObject * | mapAnon (uintptr_t &address, size_t length, MemoryMappedObject::Permissions perms) |
void | clone (Process *pTarget) |
size_t | remove (uintptr_t base, size_t length) |
size_t | setPermissions (uintptr_t base, size_t length, MemoryMappedObject::Permissions perms) |
bool | contains (uintptr_t base, size_t length) |
void | sync (uintptr_t base, size_t length, bool async) |
void | invalidate (uintptr_t base, size_t length) |
void | unmap (MemoryMappedObject *pObj) |
void | unmapAll () |
virtual bool | trap (InterruptState &state, uintptr_t address, bool bIsWrite) |
virtual bool | compact () |
virtual const String | getMemoryPressureDescription () |
Static Public Member Functions | |
static MemoryMapManager & | instance () |
Protected Member Functions | |
void | unmapAllUnlocked () |
bool | acquireLock () |
void | releaseLock () |
Private Types | |
enum | Ops { Sync, Invalidate } |
typedef List< MemoryMappedObject * > | MmObjectList |
Private Member Functions | |
MemoryMapManager () | |
bool | sanitiseAddress (uintptr_t &address, size_t length) |
void | op (Ops what, uintptr_t base, size_t length, bool async) |
Private Attributes | |
Tree< VirtualAddressSpace *, MmObjectList * > | m_MmObjectLists |
Spinlock | m_Lock |
Static Private Attributes | |
static MemoryMapManager | m_Instance |
Friends | |
class | PosixSubsystem |
This class is a multiplexing trap handler, to handle traps for MemoryMappedObjects, dispatching them to the right place.
Definition at line 397 of file MemoryMappedFile.h.
|
private |
Default and only constructor. Registers with PageFaultHandler.
Definition at line 956 of file MemoryMappedFile.cc.
References PageFaultHandler::instance(), PageFaultHandler::registerHandler(), MemoryPressureManager::registerHandler(), and MemoryPressureManager::removeHandler().
|
protected |
Acquire the manager's lock.
Take this to be able to call unmapAllUnlocked; this could be used for cases where a caller cannot be rescheduled but needs to be able to unmap all mappings. That caller could acquire this lock, then become un-scheduleable, then perform the needed actions. Without this, the caller could fail if the manager's lock is taken already.
Definition at line 1670 of file MemoryMappedFile.cc.
References Spinlock::acquire(), and m_Lock.
void MemoryMapManager::clone | ( | Process * | pTarget | ) |
Registers the current address space's mappings with the target process.
pTarget | The process to clone into. |
Definition at line 1059 of file MemoryMappedFile.cc.
References List< T, nodePoolSize >::begin(), MemoryMappedObject::clone(), List< T, nodePoolSize >::end(), Process::getAddressSpace(), Processor::information(), m_Lock, m_MmObjectLists, and List< T, nodePoolSize >::pushBack().
|
virtual |
Trigger a compact in all address spaces.
This may switch in and out of several address spaces.
Implements MemoryPressureHandler.
Definition at line 1606 of file MemoryMappedFile.cc.
References Processor::information(), m_MmObjectLists, NOTICE, and Processor::switchAddressSpace().
bool MemoryMapManager::contains | ( | uintptr_t | base, |
size_t | length | ||
) |
Returns true if at least one memory mapped object is in the range given, false otherwise.
Definition at line 1396 of file MemoryMappedFile.cc.
References Spinlock::acquire(), List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), PhysicalMemoryManager::getPageSize(), Processor::information(), MemoryMappedObject::invalidate(), m_Lock, m_MmObjectLists, MemoryMappedObject::matches(), Spinlock::release(), MemoryMappedObject::sync(), and WARNING.
|
inlinestatic |
Singleton instance
Definition at line 404 of file MemoryMappedFile.h.
References MemoryMappedObject::address(), MemoryMappedObject::clone(), MemoryMappedObject::compact(), MemoryMappedObject::invalidate(), MemoryMappedObject::length(), MemoryMappedObject::setPermissions(), MemoryMappedObject::sync(), MemoryMappedObject::trap(), and MemoryMappedObject::unmap().
Referenced by PosixSubsystem::checkAddress(), PosixSubsystem::exit(), PosixSubsystem::invoke(), PosixSubsystem::loadElf(), DynamicLinker::loadObject(), DynamicLinker::loadProgram(), and PosixSubsystem::~PosixSubsystem().
void MemoryMapManager::invalidate | ( | uintptr_t | base, |
size_t | length | ||
) |
Takes any pages that differ from the backing file (ie, copied on write) and restores them to point to the backing file.
Definition at line 1471 of file MemoryMappedFile.cc.
MemoryMappedObject * MemoryMapManager::mapAnon | ( | uintptr_t & | address, |
size_t | length, | ||
MemoryMappedObject::Permissions | perms | ||
) |
Create a new anonymous memory mapping.
Definition at line 1016 of file MemoryMappedFile.cc.
References PhysicalMemoryManager::getPageSize(), Processor::information(), m_Lock, m_MmObjectLists, NOTICE, List< T, nodePoolSize >::pushBack(), and sanitiseAddress().
Referenced by PosixSubsystem::invoke(), and PosixSubsystem::loadElf().
MemoryMappedObject * MemoryMapManager::mapFile | ( | File * | pFile, |
uintptr_t & | address, | ||
size_t | length, | ||
MemoryMappedObject::Permissions | perms, | ||
size_t | offset = 0 , |
||
bool | bCopyOnWrite = true |
||
) |
Map in the given File.
Definition at line 968 of file MemoryMappedFile.cc.
References File::getName(), PhysicalMemoryManager::getPageSize(), Processor::information(), m_Lock, m_MmObjectLists, NOTICE, List< T, nodePoolSize >::pushBack(), and sanitiseAddress().
Referenced by PosixSubsystem::invoke(), PosixSubsystem::loadElf(), DynamicLinker::loadObject(), and DynamicLinker::loadProgram().
|
protected |
Release the manager's lock.
Definition at line 1675 of file MemoryMappedFile.cc.
References m_Lock, and Spinlock::release().
Referenced by PosixSubsystem::~PosixSubsystem().
size_t MemoryMapManager::remove | ( | uintptr_t | base, |
size_t | length | ||
) |
Removes the given range from whatever objects might own them, and will cross object boundaries if necessary.
If this will result in a MemoryMappedObject being completely unmapped, it will be removed.
Definition at line 1086 of file MemoryMappedFile.cc.
References Spinlock::acquire(), MemoryMappedObject::address(), List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), List< T, nodePoolSize >::erase(), PhysicalMemoryManager::getPageSize(), Processor::information(), MemoryMappedObject::length(), m_Lock, m_MmObjectLists, NOTICE, List< T, nodePoolSize >::pushBack(), Spinlock::release(), MemoryMappedObject::remove(), MemoryMappedObject::split(), and MemoryMappedObject::unmap().
|
private |
Definition at line 1574 of file MemoryMappedFile.cc.
References RangeList< T, Reversed >::allocate(), RangeList< T, Reversed >::allocateSpecific(), Process::getDynamicSpaceAllocator(), PhysicalMemoryManager::getPageSize(), Process::getSpaceAllocator(), and Processor::information().
Referenced by mapAnon(), and mapFile().
size_t MemoryMapManager::setPermissions | ( | uintptr_t | base, |
size_t | length, | ||
MemoryMappedObject::Permissions | perms | ||
) |
Adjusts permissions across the given range, crossing object boundaries if necessary.
Definition at line 1247 of file MemoryMappedFile.cc.
References Spinlock::acquire(), MemoryMappedObject::address(), List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), PhysicalMemoryManager::getPageSize(), Processor::information(), MemoryMappedObject::length(), m_Lock, m_MmObjectLists, NOTICE, List< T, nodePoolSize >::pushBack(), Spinlock::release(), MemoryMappedObject::setPermissions(), and MemoryMappedObject::split().
Referenced by PosixSubsystem::invoke().
void MemoryMapManager::sync | ( | uintptr_t | base, |
size_t | length, | ||
bool | async | ||
) |
Syncs memory mapped objects within the given range back to their backing store, if they have one.
Definition at line 1466 of file MemoryMappedFile.cc.
|
virtual |
Trap handler, called when a fault takes place.
Implements MemoryTrapHandler.
Definition at line 1507 of file MemoryMappedFile.cc.
References Spinlock::acquire(), List< T, nodePoolSize >::begin(), Dec, List< T, nodePoolSize >::end(), ERROR, PhysicalMemoryManager::getPageSize(), Hex, Processor::information(), m_Lock, m_MmObjectLists, MemoryMappedObject::matches(), NOTICE, Spinlock::release(), and MemoryMappedObject::trap().
void MemoryMapManager::unmap | ( | MemoryMappedObject * | pObj | ) |
Removes the mappings for the given object from the address space.
Definition at line 1476 of file MemoryMappedFile.cc.
References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), List< T, nodePoolSize >::erase(), Processor::information(), m_Lock, and m_MmObjectLists.
Referenced by PosixSubsystem::invoke(), and DynamicLinker::loadProgram().
void MemoryMapManager::unmapAll | ( | ) |
Removes all mappings from this address space.
Definition at line 1500 of file MemoryMappedFile.cc.
References m_Lock, and unmapAllUnlocked().
Referenced by PosixSubsystem::exit(), and PosixSubsystem::invoke().
|
protected |
Removes all mappings from the address space, unlocked.
Requires callers to have acquired the lock by other means.
Definition at line 1643 of file MemoryMappedFile.cc.
References List< T, nodePoolSize >::begin(), List< T, nodePoolSize >::end(), List< T, nodePoolSize >::erase(), FATAL, Processor::information(), m_Lock, and m_MmObjectLists.
Referenced by unmapAll(), and PosixSubsystem::~PosixSubsystem().
|
staticprivate |
Singleton instance.
Definition at line 536 of file MemoryMappedFile.h.
|
private |
Lock for the cache.
Definition at line 544 of file MemoryMappedFile.h.
Referenced by acquireLock(), clone(), contains(), mapAnon(), mapFile(), releaseLock(), remove(), setPermissions(), trap(), unmap(), unmapAll(), and unmapAllUnlocked().
|
private |
Cache of virtual address spaces -> MmObjectLists.
Definition at line 541 of file MemoryMappedFile.h.
Referenced by clone(), compact(), contains(), mapAnon(), mapFile(), remove(), setPermissions(), trap(), unmap(), and unmapAllUnlocked().