C# Class SharpOS.Kernel.Memory.PageAllocator

The PageAllocator class handles physical memory page allocation and provides the OS an interface for memory paging/mapping. The PageAllocator class is portable, making use of the SharpOS.ADC.Pager class to implement platform- specific paging mechanisms.
Mostrar archivo Open project: sharpos/SharpOS Class Usage Examples

Public Methods

Method Description
Alloc ( ) : void*

Allocates a page of memory. This function returns null when out of memory.

Dealloc ( void page ) : void

Deallocates the memory page pointed to by page.

Dump ( int count ) : void
DumpInfo ( ) : void
DumpStack ( uint stack, uint stackptr, int count ) : void
GetPageAttributes ( void page, uint granularity, PageAllocator ret_err ) : PageAttributes
IsPageFree ( void page ) : bool

Checks if a given page is allocated. If the page is allocated, the method returns true. This function starts from the current stack pointer and goes backward.

IsPageReserved ( void page ) : bool

Returns true if the given page is reserved (that is, not available for allocation).

MapPage ( void page, void physPage, uint granularity, PageAttributes attr ) : PageAllocator.Errors

Modifies the virtual memory mapping of the given super-page to point to the given physical super page. Both pointers must be aligned along the platform's native super-page boundaries.

This function is only available on platforms which can provide super-page mapping. The Intel 386 and later processors support this using the 'page directory', which maps large 4MB sections of memory at a time (via redirection to page tables which contain 4KB blocks).

ReservePage ( void page ) : bool

Reserves a memory page so that it cannot be allocated using M:Alloc() or M:RangeAlloc(uint count).

ReservePageRange ( void firstPage, uint pages, string name ) : bool

Reserves a range of memory pages so that they cannot be allocated using M:Alloc() or M:RangeAlloc(uint count).

SetPageAttributes ( void page, uint granularity, PageAttributes attr ) : Errors
Setup ( byte kernelOffset, uint _kernelSize, uint totalKbMem ) : void

Initializes page management and paging. Using Alloc and related management functions before calling this function results in a kernel panic. After this function is called, the ReservePage and ReservePageRange functions can be used to reserve memory that should not be allocated. You should ensure that no memory allocations have happened between calling this function and reserving memory.

Private Methods

Method Description
DumpReservedStack ( ReservedPages pageStack, uint stackPtr, int count ) : void
GetReservedPage ( ) : ReservedPages*
PopFreePage ( ) : void*

Pops the free page from the free page stack

PrintError ( Errors error ) : void
PtrToPage ( void ptr ) : void*

Gets the page address of a given pointer.

PushFreePage ( void page ) : void

Pushes the free page to the free page stack

Method Details

Alloc() public static method

Allocates a page of memory. This function returns null when out of memory.
public static Alloc ( ) : void*
return void*

Dealloc() public static method

Deallocates the memory page pointed to by page.
public static Dealloc ( void page ) : void
page void /// A pointer which is aligned along the platform's native page boundaries. ///
return void

Dump() public static method

public static Dump ( int count ) : void
count int
return void

DumpInfo() public static method

public static DumpInfo ( ) : void
return void

DumpStack() public static method

public static DumpStack ( uint stack, uint stackptr, int count ) : void
stack uint
stackptr uint
count int
return void

GetPageAttributes() public static method

public static GetPageAttributes ( void page, uint granularity, PageAllocator ret_err ) : PageAttributes
page void
granularity uint
ret_err PageAllocator
return PageAttributes

IsPageFree() public static method

Checks if a given page is allocated. If the page is allocated, the method returns true. This function starts from the current stack pointer and goes backward.
public static IsPageFree ( void page ) : bool
page void
return bool

IsPageReserved() public static method

Returns true if the given page is reserved (that is, not available for allocation).
public static IsPageReserved ( void page ) : bool
page void
return bool

MapPage() public static method

Modifies the virtual memory mapping of the given super-page to point to the given physical super page. Both pointers must be aligned along the platform's native super-page boundaries.
This function is only available on platforms which can provide super-page mapping. The Intel 386 and later processors support this using the 'page directory', which maps large 4MB sections of memory at a time (via redirection to page tables which contain 4KB blocks).
public static MapPage ( void page, void physPage, uint granularity, PageAttributes attr ) : PageAllocator.Errors
page void
physPage void
granularity uint
attr PageAttributes /// The attributes to apply to the paging table entry for this super-page. If /// one or more flags given in this parameter are not supported by the current /// platform, the call will fail, returning false. ///
return PageAllocator.Errors

ReservePage() public static method

Reserves a memory page so that it cannot be allocated using M:Alloc() or M:RangeAlloc(uint count).
public static ReservePage ( void page ) : bool
page void /// A pointer which is aligned along the platform's native page boundaries. ///
return bool

ReservePageRange() public static method

Reserves a range of memory pages so that they cannot be allocated using M:Alloc() or M:RangeAlloc(uint count).
public static ReservePageRange ( void firstPage, uint pages, string name ) : bool
firstPage void
pages uint /// The amount of pages to reserve. ///
name string
return bool

SetPageAttributes() public static method

public static SetPageAttributes ( void page, uint granularity, PageAttributes attr ) : Errors
page void
granularity uint
attr PageAttributes
return Errors

Setup() public static method

Initializes page management and paging. Using Alloc and related management functions before calling this function results in a kernel panic. After this function is called, the ReservePage and ReservePageRange functions can be used to reserve memory that should not be allocated. You should ensure that no memory allocations have happened between calling this function and reserving memory.
public static Setup ( byte kernelOffset, uint _kernelSize, uint totalKbMem ) : void
kernelOffset byte
_kernelSize uint
totalKbMem uint
return void