ptos: mm: Add page allocation helpers
Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
@@ -45,6 +45,10 @@ typedef struct {
|
|||||||
USIZE Length;
|
USIZE Length;
|
||||||
} MM_RANGE;
|
} MM_RANGE;
|
||||||
|
|
||||||
|
/* Obtain a pointer from an &MM_RANGE pointer */
|
||||||
|
#define RANGE_PTR(RANGE_P) \
|
||||||
|
((VOID *)((RANGE_P)->VirtualBase))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unmap a virtual memory range
|
* Unmap a virtual memory range
|
||||||
*
|
*
|
||||||
@@ -67,6 +71,14 @@ PT_STATUS MmMapRange(
|
|||||||
MM_PROT Prot, MMU_PAGESIZE PageSize
|
MM_PROT Prot, MMU_PAGESIZE PageSize
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate one or more pages
|
||||||
|
*
|
||||||
|
* @Count: Number of pages to allocate
|
||||||
|
* @Result: Result is written back here
|
||||||
|
*/
|
||||||
|
PT_STATUS MmAllocatePages(USIZE Count, MM_RANGE *Result);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize virtual memory
|
* Initialize virtual memory
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -39,6 +39,23 @@ static USIZE PageSizeTable[] = {
|
|||||||
static UPTR VallocBump = VALLOC_BASE;
|
static UPTR VallocBump = VALLOC_BASE;
|
||||||
static MM_VAD_TREE VadTree;
|
static MM_VAD_TREE VadTree;
|
||||||
|
|
||||||
|
PT_STATUS
|
||||||
|
MmAllocatePages(USIZE Count, MM_RANGE *Result)
|
||||||
|
{
|
||||||
|
MM_VAD *Vad;
|
||||||
|
|
||||||
|
if (Count == 0 || Result == NULL) {
|
||||||
|
return STATUS_INVALID_PARAM;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vad = MmVadTreeAllocate(&VadTree, Count);
|
||||||
|
if (Vad == NULL) {
|
||||||
|
return STATUS_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
*Result = Vad->Range;
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
PT_STATUS MmUnmapRange(MMU_VAS *Vas, const MM_RANGE *Range, MMU_PAGESIZE PageSize)
|
PT_STATUS MmUnmapRange(MMU_VAS *Vas, const MM_RANGE *Range, MMU_PAGESIZE PageSize)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user