[BOOT] Add stubs to complete MmPaInitialize()

MmPaInitialize() is now complete
Added BlpMmInitializeConstraints() and MmMdRemoveRegionFromMdlEx()
This commit is contained in:
2024-08-27 13:57:21 -04:00
parent 437b19a0f5
commit 6fc91eb58c
6 changed files with 155 additions and 15 deletions

View File

@@ -79,44 +79,78 @@ Arguments:
Return Value:
STATUS_SUCCESS if successful,
STATUS_INVALID_PARAMETER if regions in MemoryInfo could not be removed.
STATUS_NO_MEMORY if a new descriptor cannot be allocated.
--*/
{
NTSTATUS Status;
PMEMORY_DESCRIPTOR Descriptor, NewDescriptor;
(VOID)MemoryInfo;
DebugPrint(L"Initializing page allocator...\r\n");
//
// Initialize page allocator settings.
//
PapMinimumAllocationCount = MinimumAllocation;
PapMinimumPhysicalPage = 1;
PapMaximumPhysicalPage = MAXULONGLONG >> PAGE_SHIFT;
DebugPrintf(L"Maximum physical page: %x %x\r\n", HIDWORD(PapMaximumPhysicalPage), LODWORD(PapMaximumPhysicalPage));
//
// Initialize MDLs.
//
InitializeMdl(&MmMdlFwAllocationTracker);
InitializeMdl(&MmMdlBadMemory);
InitializeMdl(&MmMdlTruncatedMemory);
InitializeMdl(&MmMdlPersistentMemory);
InitializeMdl(&MmMdlReservedAllocated);;
InitializeMdl(&MmMdlReservedAllocated);
InitializeMdl(&MmMdlMappedAllocated);
InitializeMdl(&MmMdlMappedUnallocated);
InitializeMdl(&MmMdlUnmappedAllocated);
InitializeMdl(&MmMdlUnmappedUnallocated);
//
// Get the firmware memory map.
//
Status = MmFwGetMemoryMap(&MmMdlUnmappedUnallocated, 0x03);
if (!NT_SUCCESS(Status)) {
return Status;
}
//
// Remove regions described in MemoryInfo from the
// MDL the memory manager will use for allocation.
//
Descriptor = (PMEMORY_DESCRIPTOR)((PUCHAR)MemoryInfo + MemoryInfo->MdlOffset);
for (ULONG DescriptorCount = MemoryInfo->DescriptorCount; DescriptorCount > 0; DescriptorCount--) {
//
// Remove from the usable MDL.
//
Status = MmMdRemoveRegionFromMdlEx(&MmMdlUnmappedUnallocated, Descriptor->FirstPage, Descriptor->PageCount, MDL_OPERATION_FLAGS_PHYSICAL, NULL);
if (!NT_SUCCESS(Status)) {
return STATUS_INVALID_PARAMETER;
}
//
// ... and add to the reserved MDL.
//
NewDescriptor = MmMdInitDescriptor(
Descriptor->FirstPage,
Descriptor->MappedFirstPage,
Descriptor->PageCount,
Descriptor->Attributes,
Descriptor->Type
);
if (NewDescriptor == NULL) {
return STATUS_NO_MEMORY;
}
Status = MmMdAddDescriptorToList(&MmMdlReservedAllocated, NewDescriptor, 0x00);
if (!NT_SUCCESS(Status)) {
return Status;
}
Descriptor = (PMEMORY_DESCRIPTOR)((PUCHAR)Descriptor + MemoryInfo->DescriptorSize);
}
Status = BlpMmInitializeConstraints();
if (!NT_SUCCESS(Status)) {
return Status;
}
return STATUS_SUCCESS;
}