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.
Afficher le fichier Open project: sharpos/SharpOS Class Usage Examples

Méthodes publiques

Méthode 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

Méthode 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 méthode

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

Dealloc() public static méthode

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. ///
Résultat void

Dump() public static méthode

public static Dump ( int count ) : void
count int
Résultat void

DumpInfo() public static méthode

public static DumpInfo ( ) : void
Résultat void

DumpStack() public static méthode

public static DumpStack ( uint stack, uint stackptr, int count ) : void
stack uint
stackptr uint
count int
Résultat void

GetPageAttributes() public static méthode

public static GetPageAttributes ( void page, uint granularity, PageAllocator ret_err ) : PageAttributes
page void
granularity uint
ret_err PageAllocator
Résultat PageAttributes

IsPageFree() public static méthode

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
Résultat bool

IsPageReserved() public static méthode

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

MapPage() public static méthode

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. ///
Résultat PageAllocator.Errors

ReservePage() public static méthode

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. ///
Résultat bool

ReservePageRange() public static méthode

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
Résultat bool

SetPageAttributes() public static méthode

public static SetPageAttributes ( void page, uint granularity, PageAttributes attr ) : Errors
page void
granularity uint
attr PageAttributes
Résultat Errors

Setup() public static méthode

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
Résultat void