FreeNOS
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes
MemoryContext Class Referenceabstract

Virtual memory abstract interface. More...

#include <MemoryContext.h>

Inheritance diagram for MemoryContext:
ARMPaging IntelPaging

Public Types

enum  Result {
  Success, InvalidAddress, InvalidSize, AlreadyExists,
  OutOfMemory
}
 Result codes. More...
 
typedef enum MemoryContext::Result Result
 Result codes. More...
 

Public Member Functions

 MemoryContext (MemoryMap *map, SplitAllocator *alloc)
 Constructor. More...
 
virtual ~MemoryContext ()
 Destructor. More...
 
virtual Result initialize ()=0
 Initialize the MemoryContext. More...
 
virtual Result activate (bool initializeMMU=false)=0
 Activate the MemoryContext. More...
 
virtual Result map (Address virt, Address phys, Memory::Access access)=0
 Map a physical page to a virtual address. More...
 
virtual Result unmap (Address virt)=0
 Unmap a virtual address. More...
 
virtual Result lookup (Address virt, Address *phys) const =0
 Translate virtual address to physical address. More...
 
virtual Result access (Address virt, Memory::Access *access) const =0
 Get Access flags for a virtual address. More...
 
virtual Result mapRangeContiguous (Memory::Range *range)
 Map a range of contiguous physical pages to virtual addresses. More...
 
virtual Result mapRangeSparse (Memory::Range *range)
 Map and allocate a range of sparse (non-contiguous) physical pages to virtual addresses. More...
 
virtual Result unmapRange (Memory::Range *range)
 Unmaps a range of virtual memory. More...
 
virtual Result release (Address virt)
 Release a memory page mapping. More...
 
virtual Result releaseRange (Memory::Range *range)=0
 Release a range of physical memory by its virtual memory pages. More...
 
virtual Result releaseSection (const Memory::Range &range, const bool tablesOnly=false)=0
 Release memory sections. More...
 
virtual Result findFree (Size size, MemoryMap::Region region, Address *virt) const
 Find unused memory. More...
 
virtual void mapRangeSparseCallback (Address *phys)
 Callback to provide intermediate Range object during mapRangeSparse() More...
 

Static Public Member Functions

static MemoryContextgetCurrent ()
 Get currently active MemoryContext. More...
 

Protected Attributes

SplitAllocatorm_alloc
 Physical memory allocator. More...
 
MemoryMapm_map
 Virtual memory layout. More...
 
Callback< MemoryContext, Addressm_mapRangeSparseCallback
 Callback object for mapRangeSparseCallback function. More...
 
Memory::Rangem_savedRange
 Saved range input for use in the mapRangeSparse Callback. More...
 
Size m_numSparsePages
 Number of pages allocated via mapRangeSparse Callback. More...
 

Static Protected Attributes

static MemoryContextm_current = 0
 The currently active MemoryContext. More...
 

Detailed Description

Virtual memory abstract interface.

Definition at line 42 of file MemoryContext.h.

Member Typedef Documentation

◆ Result

Result codes.

Member Enumeration Documentation

◆ Result

Result codes.

Enumerator
Success 
InvalidAddress 
InvalidSize 
AlreadyExists 
OutOfMemory 

Definition at line 49 of file MemoryContext.h.

Constructor & Destructor Documentation

◆ MemoryContext()

MemoryContext::MemoryContext ( MemoryMap map,
SplitAllocator alloc 
)

Constructor.

Parameters
mapPointer to memory map to use.
allocAllocator used to allocate page tables.

Definition at line 28 of file MemoryContext.cpp.

◆ ~MemoryContext()

MemoryContext::~MemoryContext ( )
virtual

Destructor.

Definition at line 37 of file MemoryContext.cpp.

Member Function Documentation

◆ access()

virtual Result MemoryContext::access ( Address  virt,
Memory::Access access 
) const
pure virtual

Get Access flags for a virtual address.

Parameters
virtVirtual address to get Access flags for.
accessMemoryAccess object pointer.
Returns
Result code.

Implemented in IntelPaging, and ARMPaging.

Referenced by ProcessShares::createShare(), and VMCtlHandler().

◆ activate()

virtual Result MemoryContext::activate ( bool  initializeMMU = false)
pure virtual

Activate the MemoryContext.

This function applies this MemoryContext on the hardware MMU.

Parameters
initializeMMUIf true perform (re)initialization of the MMU
Returns
Result code.

Implemented in IntelPaging, and ARMPaging.

Referenced by IntelProcess::execute(), and ARMProcess::execute().

◆ findFree()

MemoryContext::Result MemoryContext::findFree ( Size  size,
MemoryMap::Region  region,
Address virt 
) const
virtual

Find unused memory.

This function finds a contigeous block of a given size of virtual memory which is unused and then returns the virtual address of the first page in the block.

Parameters
regionMemory region to search in.
sizeNumber of bytes requested to be free.
virtVirtual memory address on output.
Returns
Result code

Definition at line 117 of file MemoryContext.cpp.

References InvalidAddress, lookup(), m_map, OutOfMemory, PAGESIZE, MemoryMap::range(), Memory::Range::size, Success, and Memory::Range::virt.

Referenced by ProcessShares::createShare(), Process::initialize(), IO::map(), VMCopyHandler(), and VMCtlHandler().

◆ getCurrent()

MemoryContext * MemoryContext::getCurrent ( )
static

Get currently active MemoryContext.

Returns
MemoryContext object pointer or NULL.

Definition at line 41 of file MemoryContext.cpp.

References m_current.

Referenced by IO::map(), and IO::unmap().

◆ initialize()

virtual Result MemoryContext::initialize ( )
pure virtual

Initialize the MemoryContext.

Returns
Result code

Implemented in IntelPaging, and ARMPaging.

Referenced by IntelProcess::initialize(), and ARMProcess::initialize().

◆ lookup()

virtual Result MemoryContext::lookup ( Address  virt,
Address phys 
) const
pure virtual

Translate virtual address to physical address.

Parameters
virtVirtual address to lookup
physOn output contains the translated physical address
Returns
Result code

Implemented in IntelPaging, and ARMPaging.

Referenced by ProcessShares::createShare(), findFree(), release(), VMCopyHandler(), and VMCtlHandler().

◆ map()

virtual Result MemoryContext::map ( Address  virt,
Address  phys,
Memory::Access  access 
)
pure virtual

Map a physical page to a virtual address.

Parameters
virtVirtual address.
physPhysical address.
accessPage entry protection flags.
Returns
Result code.

Implemented in IntelPaging, and ARMPaging.

Referenced by Process::initialize(), IO::map(), mapRangeContiguous(), mapRangeSparseCallback(), and VMCopyHandler().

◆ mapRangeContiguous()

MemoryContext::Result MemoryContext::mapRangeContiguous ( Memory::Range range)
virtual

◆ mapRangeSparse()

MemoryContext::Result MemoryContext::mapRangeSparse ( Memory::Range range)
virtual

Map and allocate a range of sparse (non-contiguous) physical pages to virtual addresses.

Parameters
rangeRange object describing the range of physical pages.
Returns
Result code.

Definition at line 76 of file MemoryContext.cpp.

References Allocator::Range::address, Allocator::Range::alignment, SplitAllocator::allocateSparse(), m_alloc, m_mapRangeSparseCallback, m_numSparsePages, m_savedRange, OutOfMemory, Memory::Range::size, Allocator::Range::size, Success, and Allocator::Success.

Referenced by VMCtlHandler().

◆ mapRangeSparseCallback()

void MemoryContext::mapRangeSparseCallback ( Address phys)
virtual

Callback to provide intermediate Range object during mapRangeSparse()

Parameters
physPointer to physical address value of newly allocated page.
See also
mapRangeSparse

Definition at line 146 of file MemoryContext.cpp.

References Memory::Range::access, assert, m_numSparsePages, m_savedRange, map(), PAGESIZE, Success, and Memory::Range::virt.

◆ release()

MemoryContext::Result MemoryContext::release ( Address  virt)
virtual

Release a memory page mapping.

Parameters
virtVirtual address of the page to release.
Returns
Result code

Definition at line 106 of file MemoryContext.cpp.

References lookup(), m_alloc, SplitAllocator::release(), and Success.

◆ releaseRange()

virtual Result MemoryContext::releaseRange ( Memory::Range range)
pure virtual

Release a range of physical memory by its virtual memory pages.

Parameters
rangeRange object describing the range of physical pages to release.
Returns
Result code

Implemented in IntelPaging, and ARMPaging.

Referenced by VMCtlHandler().

◆ releaseSection()

virtual Result MemoryContext::releaseSection ( const Memory::Range range,
const bool  tablesOnly = false 
)
pure virtual

Release memory sections.

Deallocate all associated physical memory which resides in the given memory section range.

Parameters
rangeRange of memory sections to release
tablesOnlyTrue to only release associated page tables and do not release the actual mapped pages
Returns
Result code

Implemented in IntelPaging, and ARMPaging.

Referenced by VMCtlHandler(), and Process::~Process().

◆ unmap()

virtual Result MemoryContext::unmap ( Address  virt)
pure virtual

Unmap a virtual address.

This function removes a virtual to physical memory mapping without deallocating any physical memory.

Parameters
virtVirtual address to unmap.
Returns
Result code

Implemented in IntelPaging, and ARMPaging.

Referenced by Process::initialize(), unmapRange(), and VMCopyHandler().

◆ unmapRange()

MemoryContext::Result MemoryContext::unmapRange ( Memory::Range range)
virtual

Unmaps a range of virtual memory.

Parameters
rangeRange object describing the range of virtual addresses.
Returns
Result code

Definition at line 95 of file MemoryContext.cpp.

References PAGESIZE, Memory::Range::size, Success, unmap(), and Memory::Range::virt.

Referenced by ProcessShares::releaseShare(), IO::unmap(), and VMCtlHandler().

Field Documentation

◆ m_alloc

SplitAllocator* MemoryContext::m_alloc
protected

◆ m_current

MemoryContext * MemoryContext::m_current = 0
staticprotected

◆ m_map

MemoryMap* MemoryContext::m_map
protected

Virtual memory layout.

Definition at line 230 of file MemoryContext.h.

Referenced by findFree(), ARMPaging::initialize(), and IntelPaging::initialize().

◆ m_mapRangeSparseCallback

Callback<MemoryContext, Address> MemoryContext::m_mapRangeSparseCallback
protected

Callback object for mapRangeSparseCallback function.

Definition at line 236 of file MemoryContext.h.

Referenced by mapRangeSparse().

◆ m_numSparsePages

Size MemoryContext::m_numSparsePages
protected

Number of pages allocated via mapRangeSparse Callback.

Definition at line 242 of file MemoryContext.h.

Referenced by mapRangeSparse(), and mapRangeSparseCallback().

◆ m_savedRange

Memory::Range* MemoryContext::m_savedRange
protected

Saved range input for use in the mapRangeSparse Callback.

Definition at line 239 of file MemoryContext.h.

Referenced by mapRangeSparse(), and mapRangeSparseCallback().


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