diff --git a/service/ptos/head/mm/vm.h b/service/ptos/head/mm/vm.h index 198ea0b..9c740a1 100644 --- a/service/ptos/head/mm/vm.h +++ b/service/ptos/head/mm/vm.h @@ -45,6 +45,10 @@ typedef struct { USIZE Length; } MM_RANGE; +/* Obtain a pointer from an &MM_RANGE pointer */ +#define RANGE_PTR(RANGE_P) \ + ((VOID *)((RANGE_P)->VirtualBase)) + /* * Unmap a virtual memory range * @@ -67,6 +71,14 @@ PT_STATUS MmMapRange( 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 */ diff --git a/service/ptos/mm/vm.c b/service/ptos/mm/vm.c index bc0f289..2c3132e 100644 --- a/service/ptos/mm/vm.c +++ b/service/ptos/mm/vm.c @@ -39,6 +39,23 @@ static USIZE PageSizeTable[] = { static UPTR VallocBump = VALLOC_BASE; 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) {