FreeNOS
Public Member Functions | Private Attributes
SplitAllocator Class Reference

Allocator which separates kernel mapped memory at virtual and physical addresses. More...

#include <SplitAllocator.h>

Inheritance diagram for SplitAllocator:
Allocator

Public Member Functions

 SplitAllocator (const Range physRange, const Range virtRange, const Size pageSize)
 Class constructor. More...
 
virtual Size available () const
 Get memory available. More...
 
virtual Result allocate (Range &args)
 Allocate physical memory. More...
 
Result allocateSparse (const Range &range, CallbackFunction *function)
 Allocate sparse (non-contiguous) physical memory. More...
 
Result allocate (Range &phys, Range &virt)
 Allocate physical/virtual memory. More...
 
Result allocate (const Address addr)
 Allocate one physical memory page. More...
 
virtual Result release (const Address addr)
 Release memory page. More...
 
Address toVirtual (const Address phys) const
 Convert Address to virtual pointer. More...
 
Address toPhysical (const Address virt) const
 Convert Address to physical pointer. More...
 
bool isAllocated (const Address page) const
 Check if a physical page is allocated. More...
 
- Public Member Functions inherited from Allocator
 Allocator ()
 Default class constructor. More...
 
 Allocator (const Range range)
 Class constructor with Range input. More...
 
virtual ~Allocator ()
 Class destructor. More...
 
void setParent (Allocator *parent)
 Set parent allocator. More...
 
Allocatorparent ()
 Get parent Allocator. More...
 
Address base () const
 Get memory base address for allocations. More...
 
Size alignment () const
 Get memory alignment in bytes for allocations. More...
 
virtual Size size () const
 Get memory size. More...
 

Private Attributes

BitAllocator m_alloc
 Physical memory allocator. More...
 
const Range m_virtRange
 Virtual memory range to manage. More...
 
const Size m_pageSize
 Size of a memory page. More...
 

Additional Inherited Members

- Public Types inherited from Allocator
enum  Result {
  Success = 0, InvalidAddress, InvalidSize, InvalidAlignment,
  OutOfMemory
}
 Allocation results. More...
 
typedef struct Allocator::Range Range
 Describes a range of memory. More...
 
- Static Public Member Functions inherited from Allocator
static void setDefault (Allocator *alloc)
 Makes the given Allocator the default. More...
 
static AllocatorgetDefault ()
 Retrieve the currently default Allocator. More...
 
- Protected Member Functions inherited from Allocator
Address aligned (const Address addr, const Size boundary) const
 Align memory address. More...
 

Detailed Description

Allocator which separates kernel mapped memory at virtual and physical addresses.

Definition at line 37 of file SplitAllocator.h.

Constructor & Destructor Documentation

◆ SplitAllocator()

SplitAllocator::SplitAllocator ( const Range  physRange,
const Range  virtRange,
const Size  pageSize 
)

Class constructor.

Parameters
physRangeBlock of physical continguous memory to be managed.
virtRangeSame block of memory in the virtual address space.
pageSizeSize of a single memory page.

Definition at line 20 of file SplitAllocator.cpp.

Member Function Documentation

◆ allocate() [1/3]

Allocator::Result SplitAllocator::allocate ( const Address  addr)

Allocate one physical memory page.

Parameters
addrPhysical memory page address
Returns
Result code

Definition at line 84 of file SplitAllocator.cpp.

References BitAllocator::allocateAt(), and m_alloc.

◆ allocate() [2/3]

Allocator::Result SplitAllocator::allocate ( Allocator::Range args)
virtual

Allocate physical memory.

Parameters
argsContains the requested size and alignment on input. The alignment value must be a multiple of the pageSize. On output, contains the actual allocated address.
Returns
Result value.

Reimplemented from Allocator.

Definition at line 35 of file SplitAllocator.cpp.

References BitAllocator::allocate(), and m_alloc.

Referenced by allocateSparse(), ARMKernel::ARMKernel(), ARMPaging::initialize(), IntelPaging::initialize(), IntelKernel::IntelKernel(), Kernel::Kernel(), Kernel::loadBootProgram(), ARMFirstTable::map(), IntelPageDirectory::map(), MemoryContext::mapRangeContiguous(), SunxiKernel::SunxiKernel(), and VMCtlHandler().

◆ allocate() [3/3]

Allocator::Result SplitAllocator::allocate ( Allocator::Range phys,
Allocator::Range virt 
)

Allocate physical/virtual memory.

Parameters
physContains the requested size and alignment on input. The alignment value must be a multiple of the pageSize. On output, contains the actual allocated physical address.
virtContains the allocated memory translated for virtual addressing.
Returns
Result code

Definition at line 69 of file SplitAllocator.cpp.

References Allocator::Range::address, Allocator::Range::alignment, BitAllocator::allocate(), m_alloc, Allocator::Range::size, Allocator::Success, and toVirtual().

◆ allocateSparse()

Allocator::Result SplitAllocator::allocateSparse ( const Range range,
CallbackFunction function 
)

Allocate sparse (non-contiguous) physical memory.

Parameters
rangeContains the requested size on input. The alignment and address values are unused.
functionCalled for each successful allocation of a page.
Returns
Result value.

Definition at line 40 of file SplitAllocator.cpp.

References Allocator::Range::address, Allocator::Range::alignment, allocate(), BitAllocator::available(), CallbackFunction::execute(), Allocator::InvalidSize, m_alloc, m_pageSize, Allocator::OutOfMemory, Allocator::Range::size, Allocator::Success, and ZERO.

Referenced by MemoryContext::mapRangeSparse().

◆ available()

Size SplitAllocator::available ( ) const
virtual

Get memory available.

Returns
Size of memory available by the Allocator.

Reimplemented from Allocator.

Definition at line 30 of file SplitAllocator.cpp.

References BitAllocator::available(), and m_alloc.

Referenced by SystemInfoHandler().

◆ isAllocated()

bool SplitAllocator::isAllocated ( const Address  page) const

Check if a physical page is allocated.

Returns
True if allocated, false otherwise.

Definition at line 106 of file SplitAllocator.cpp.

References BitAllocator::isAllocated(), and m_alloc.

Referenced by IntelPageDirectory::releasePhysical(), ARMFirstTable::releasePhysical(), and VMCtlHandler().

◆ release()

Allocator::Result SplitAllocator::release ( const Address  addr)
virtual

Release memory page.

Parameters
addrPhysical memory address of page to release.
Returns
Result value.
See also
allocate

Reimplemented from Allocator.

Definition at line 89 of file SplitAllocator.cpp.

References m_alloc, and BitAllocator::release().

Referenced by MemoryContext::release(), IntelPageDirectory::releasePhysical(), ARMFirstTable::releasePhysical(), IntelPageDirectory::releaseSection(), ARMFirstTable::releaseSection(), ARMPaging::~ARMPaging(), IntelPaging::~IntelPaging(), and IntelProcess::~IntelProcess().

◆ toPhysical()

Address SplitAllocator::toPhysical ( const Address  virt) const

Convert Address to physical pointer.

Parameters
virtVirtual address
Returns
Physical address

Definition at line 100 of file SplitAllocator.cpp.

References Allocator::Range::address, Allocator::base(), and m_virtRange.

Referenced by Kernel::Kernel(), and IntelProcess::~IntelProcess().

◆ toVirtual()

Address SplitAllocator::toVirtual ( const Address  phys) const

Convert Address to virtual pointer.

Parameters
physPhysical address
Returns
Virtual address

Definition at line 94 of file SplitAllocator.cpp.

References Allocator::Range::address, Allocator::base(), and m_virtRange.

Referenced by allocate(), IntelPageDirectory::getPageTable(), ARMFirstTable::getSecondTable(), IntelPaging::initialize(), Kernel::loadBootImage(), and Kernel::loadBootProgram().

Field Documentation

◆ m_alloc

BitAllocator SplitAllocator::m_alloc
private

Physical memory allocator.

Definition at line 141 of file SplitAllocator.h.

Referenced by allocate(), allocateSparse(), available(), isAllocated(), and release().

◆ m_pageSize

const Size SplitAllocator::m_pageSize
private

Size of a memory page.

Definition at line 147 of file SplitAllocator.h.

Referenced by allocateSparse().

◆ m_virtRange

const Range SplitAllocator::m_virtRange
private

Virtual memory range to manage.

Definition at line 144 of file SplitAllocator.h.

Referenced by toPhysical(), and toVirtual().


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