FreeNOS
|
Virtual memory abstract interface. More...
#include <MemoryContext.h>
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 MemoryContext * | getCurrent () |
Get currently active MemoryContext. More... | |
Protected Attributes | |
SplitAllocator * | m_alloc |
Physical memory allocator. More... | |
MemoryMap * | m_map |
Virtual memory layout. More... | |
Callback< MemoryContext, Address > | m_mapRangeSparseCallback |
Callback object for mapRangeSparseCallback function. More... | |
Memory::Range * | m_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 MemoryContext * | m_current = 0 |
The currently active MemoryContext. More... | |
Virtual memory abstract interface.
Definition at line 42 of file MemoryContext.h.
typedef enum MemoryContext::Result MemoryContext::Result |
Result codes.
Result codes.
Enumerator | |
---|---|
Success | |
InvalidAddress | |
InvalidSize | |
AlreadyExists | |
OutOfMemory |
Definition at line 49 of file MemoryContext.h.
MemoryContext::MemoryContext | ( | MemoryMap * | map, |
SplitAllocator * | alloc | ||
) |
Constructor.
map | Pointer to memory map to use. |
alloc | Allocator used to allocate page tables. |
Definition at line 28 of file MemoryContext.cpp.
|
virtual |
Destructor.
Definition at line 37 of file MemoryContext.cpp.
|
pure virtual |
Get Access flags for a virtual address.
virt | Virtual address to get Access flags for. |
access | MemoryAccess object pointer. |
Implemented in IntelPaging, and ARMPaging.
Referenced by ProcessShares::createShare(), and VMCtlHandler().
|
pure virtual |
Activate the MemoryContext.
This function applies this MemoryContext on the hardware MMU.
initializeMMU | If true perform (re)initialization of the MMU |
Implemented in IntelPaging, and ARMPaging.
Referenced by IntelProcess::execute(), and ARMProcess::execute().
|
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.
region | Memory region to search in. |
size | Number of bytes requested to be free. |
virt | Virtual memory address on output. |
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().
|
static |
Get currently active MemoryContext.
Definition at line 41 of file MemoryContext.cpp.
References m_current.
Referenced by IO::map(), and IO::unmap().
|
pure virtual |
Initialize the MemoryContext.
Implemented in IntelPaging, and ARMPaging.
Referenced by IntelProcess::initialize(), and ARMProcess::initialize().
Translate virtual address to physical address.
virt | Virtual address to lookup |
phys | On output contains the translated physical address |
Implemented in IntelPaging, and ARMPaging.
Referenced by ProcessShares::createShare(), findFree(), release(), VMCopyHandler(), and VMCtlHandler().
|
pure virtual |
Map a physical page to a virtual address.
virt | Virtual address. |
phys | Physical address. |
access | Page entry protection flags. |
Implemented in IntelPaging, and ARMPaging.
Referenced by Process::initialize(), IO::map(), mapRangeContiguous(), mapRangeSparseCallback(), and VMCopyHandler().
|
virtual |
Map a range of contiguous physical pages to virtual addresses.
range | Range object describing the range of physical pages. |
Definition at line 46 of file MemoryContext.cpp.
References Memory::Range::access, Allocator::Range::address, Allocator::Range::alignment, SplitAllocator::allocate(), m_alloc, map(), OutOfMemory, PAGESIZE, Memory::Range::phys, Memory::Range::size, Allocator::Range::size, Success, Allocator::Success, and Memory::Range::virt.
Referenced by ProcessShares::createShare(), IntelProcess::initialize(), ARMProcess::initialize(), Process::initialize(), Kernel::loadBootProgram(), and VMCtlHandler().
|
virtual |
Map and allocate a range of sparse (non-contiguous) physical pages to virtual addresses.
range | Range object describing the range of physical pages. |
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().
|
virtual |
Callback to provide intermediate Range object during mapRangeSparse()
phys | Pointer to physical address value of newly allocated page. |
Definition at line 146 of file MemoryContext.cpp.
References Memory::Range::access, assert, m_numSparsePages, m_savedRange, map(), PAGESIZE, Success, and Memory::Range::virt.
|
virtual |
Release a memory page mapping.
virt | Virtual address of the page to release. |
Definition at line 106 of file MemoryContext.cpp.
References lookup(), m_alloc, SplitAllocator::release(), and Success.
|
pure virtual |
Release a range of physical memory by its virtual memory pages.
range | Range object describing the range of physical pages to release. |
Implemented in IntelPaging, and ARMPaging.
Referenced by VMCtlHandler().
|
pure virtual |
Release memory sections.
Deallocate all associated physical memory which resides in the given memory section range.
range | Range of memory sections to release |
tablesOnly | True to only release associated page tables and do not release the actual mapped pages |
Implemented in IntelPaging, and ARMPaging.
Referenced by VMCtlHandler(), and Process::~Process().
Unmap a virtual address.
This function removes a virtual to physical memory mapping without deallocating any physical memory.
virt | Virtual address to unmap. |
Implemented in IntelPaging, and ARMPaging.
Referenced by Process::initialize(), unmapRange(), and VMCopyHandler().
|
virtual |
Unmaps a range of virtual memory.
range | Range object describing the range of virtual addresses. |
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().
|
protected |
Physical memory allocator.
Definition at line 227 of file MemoryContext.h.
Referenced by ARMPaging::access(), IntelPaging::access(), ARMPaging::initialize(), IntelPaging::initialize(), ARMPaging::lookup(), IntelPaging::lookup(), ARMPaging::map(), IntelPaging::map(), mapRangeContiguous(), mapRangeSparse(), release(), ARMPaging::releaseRange(), IntelPaging::releaseRange(), ARMPaging::releaseSection(), IntelPaging::releaseSection(), ARMPaging::unmap(), IntelPaging::unmap(), ARMPaging::~ARMPaging(), and IntelPaging::~IntelPaging().
|
staticprotected |
The currently active MemoryContext.
Definition at line 233 of file MemoryContext.h.
Referenced by ARMPaging::activate(), IntelPaging::activate(), getCurrent(), ARMPaging::map(), IntelPaging::map(), ARMPaging::unmap(), and IntelPaging::unmap().
|
protected |
Virtual memory layout.
Definition at line 230 of file MemoryContext.h.
Referenced by findFree(), ARMPaging::initialize(), and IntelPaging::initialize().
|
protected |
Callback object for mapRangeSparseCallback function.
Definition at line 236 of file MemoryContext.h.
Referenced by mapRangeSparse().
|
protected |
Number of pages allocated via mapRangeSparse Callback.
Definition at line 242 of file MemoryContext.h.
Referenced by mapRangeSparse(), and mapRangeSparseCallback().
|
protected |
Saved range input for use in the mapRangeSparse Callback.
Definition at line 239 of file MemoryContext.h.
Referenced by mapRangeSparse(), and mapRangeSparseCallback().