C# Класс 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.
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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.

Приватные методы

Метод Описание
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

Описание методов

Alloc() публичный статический Метод

Allocates a page of memory. This function returns null when out of memory.
public static Alloc ( ) : void*
Результат void*

Dealloc() публичный статический Метод

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. ///
Результат void

Dump() публичный статический Метод

public static Dump ( int count ) : void
count int
Результат void

DumpInfo() публичный статический Метод

public static DumpInfo ( ) : void
Результат void

DumpStack() публичный статический Метод

public static DumpStack ( uint stack, uint stackptr, int count ) : void
stack uint
stackptr uint
count int
Результат void

GetPageAttributes() публичный статический Метод

public static GetPageAttributes ( void page, uint granularity, PageAllocator ret_err ) : PageAttributes
page void
granularity uint
ret_err PageAllocator
Результат PageAttributes

IsPageFree() публичный статический Метод

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
Результат bool

IsPageReserved() публичный статический Метод

Returns true if the given page is reserved (that is, not available for allocation).
public static IsPageReserved ( void page ) : bool
page void
Результат bool

MapPage() публичный статический Метод

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. ///
Результат PageAllocator.Errors

ReservePage() публичный статический Метод

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. ///
Результат bool

ReservePageRange() публичный статический Метод

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
Результат bool

SetPageAttributes() публичный статический Метод

public static SetPageAttributes ( void page, uint granularity, PageAttributes attr ) : Errors
page void
granularity uint
attr PageAttributes
Результат Errors

Setup() публичный статический Метод

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
Результат void