The Pedigree Project  0.1
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
MemoryMapManager Class Reference

#include <MemoryMappedFile.h>

+ Inheritance diagram for MemoryMapManager:
+ Collaboration diagram for MemoryMapManager:

Public Member Functions

MemoryMappedObjectmapFile (File *pFile, uintptr_t &address, size_t length, MemoryMappedObject::Permissions perms, size_t offset=0, bool bCopyOnWrite=true)
 
MemoryMappedObjectmapAnon (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 MemoryMapManagerinstance ()
 

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
 

Detailed Description

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.

Constructor & Destructor Documentation

MemoryMapManager::MemoryMapManager ( )
private

Member Function Documentation

bool MemoryMapManager::acquireLock ( )
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.

Parameters
pTargetThe 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().

bool MemoryMapManager::compact ( )
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 
)
static MemoryMapManager& MemoryMapManager::instance ( )
inlinestatic
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().

+ Here is the caller graph for this function:

MemoryMappedObject * MemoryMapManager::mapFile ( File pFile,
uintptr_t &  address,
size_t  length,
MemoryMappedObject::Permissions  perms,
size_t  offset = 0,
bool  bCopyOnWrite = true 
)
void MemoryMapManager::releaseLock ( )
protected

Release the manager's lock.

Definition at line 1675 of file MemoryMappedFile.cc.

References m_Lock, and Spinlock::release().

Referenced by PosixSubsystem::~PosixSubsystem().

+ Here is the caller graph for this function:

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.

Returns
number of objects affected by this call.

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().

bool MemoryMapManager::sanitiseAddress ( uintptr_t &  address,
size_t  length 
)
private
Todo:
rework APIs a lot.
Todo:
allocateSpecific in the dynamic space allocator if address is within that range.

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().

+ Here is the caller graph for this function:

size_t MemoryMapManager::setPermissions ( uintptr_t  base,
size_t  length,
MemoryMappedObject::Permissions  perms 
)

Adjusts permissions across the given range, crossing object boundaries if necessary.

Returns
number of objects affected by this call.

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().

+ Here is the caller graph for this function:

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.

bool MemoryMapManager::trap ( InterruptState &  state,
uintptr_t  address,
bool  bIsWrite 
)
virtual
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().

+ Here is the caller graph for this function:

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().

+ Here is the caller graph for this function:

void MemoryMapManager::unmapAllUnlocked ( )
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().

+ Here is the caller graph for this function:

Member Data Documentation

MemoryMapManager MemoryMapManager::m_Instance
staticprivate

Singleton instance.

Definition at line 536 of file MemoryMappedFile.h.

Spinlock MemoryMapManager::m_Lock
private
Tree<VirtualAddressSpace *, MmObjectList *> MemoryMapManager::m_MmObjectLists
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().


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