From 7bc39e5dae855f8283715a76ce0f17c6ba331f86 Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sun, 6 Sep 2015 15:44:56 +0000 Subject: [PATCH] [BOOTMGFW] - Start implementing MmMdRemoveRegionFromMdlEx. The 3 cases are detected and print right now. svn path=/trunk/; revision=69057 --- reactos/boot/environ/lib/bootlib.c | 2 +- reactos/boot/environ/lib/mm/descriptor.c | 121 ++++++++++++++++++++++- reactos/boot/environ/lib/mm/pagealloc.c | 2 +- 3 files changed, 122 insertions(+), 3 deletions(-) diff --git a/reactos/boot/environ/lib/bootlib.c b/reactos/boot/environ/lib/bootlib.c index e15da5ce33f..93ede145377 100644 --- a/reactos/boot/environ/lib/bootlib.c +++ b/reactos/boot/environ/lib/bootlib.c @@ -37,7 +37,7 @@ EarlyPrint(_In_ PWCHAR Format, ...) g_SystemTable->ConOut->OutputString(g_SystemTable->ConOut, L"\r"); g_SystemTable->ConOut->OutputString(g_SystemTable->ConOut, buffer); - g_SystemTable->BootServices->Stall(1000000); + g_SystemTable->BootServices->Stall(200000); va_end(args); } diff --git a/reactos/boot/environ/lib/mm/descriptor.c b/reactos/boot/environ/lib/mm/descriptor.c index d23e96e4c97..b58f8a1ae00 100644 --- a/reactos/boot/environ/lib/mm/descriptor.c +++ b/reactos/boot/environ/lib/mm/descriptor.c @@ -476,6 +476,14 @@ MmMdAddDescriptorToList ( } } +typedef enum _BL_MEMORY_DESCRIPTOR_TYPE +{ + BlMdPhysical, + BlMdVirtual, +} BL_MEMORY_DESCRIPTOR_TYPE; + +#define BL_MM_REMOVE_VIRTUAL_REGION_FLAG 0x80000000 + NTSTATUS MmMdRemoveRegionFromMdlEx ( __in PBL_MEMORY_DESCRIPTOR_LIST MdList, @@ -485,7 +493,118 @@ MmMdRemoveRegionFromMdlEx ( __in PBL_MEMORY_DESCRIPTOR_LIST NewMdList ) { - return STATUS_NOT_IMPLEMENTED; + BOOLEAN HaveNewList, UseVirtualPage; + NTSTATUS Status; + PLIST_ENTRY ListHead, NextEntry; + PBL_MEMORY_DESCRIPTOR Descriptor; + BL_MEMORY_DESCRIPTOR NewDescriptor; + ULONGLONG FoundBasePage, FoundEndPage, FoundPageCount, EndPage; + + /* Check if removed descriptors should go into a new list */ + if (NewMdList != NULL) + { + /* Initialize it */ + MmMdInitializeListHead(NewMdList); + NewMdList->Type = MdList->Type; + + /* Remember for later */ + HaveNewList = TRUE; + } + else + { + /* For later */ + HaveNewList = FALSE; + } + + /* Is the region being removed physical? */ + UseVirtualPage = FALSE; + if (!(Flags & BL_MM_REMOVE_VIRTUAL_REGION_FLAG)) + { + /* Is this a list of virtual descriptors? */ + if (MdList->Type == BlMdVirtual) + { + /* Request is nonsensical, fail */ + Status = STATUS_INVALID_PARAMETER; + goto Quickie; + } + } + else + { + /* Is this a list of physical descriptors? */ + if (MdList->Type == BlMdPhysical) + { + /* We'll have to use the virtual page instead */ + UseVirtualPage = TRUE; + } + } + + /* Loop the list*/ + ListHead = MdList->First; + NextEntry = ListHead->Flink; + while (NextEntry != ListHead) + { + /* Get the descriptor */ + Descriptor = CONTAINING_RECORD(NextEntry, BL_MEMORY_DESCRIPTOR, ListEntry); + + /* Extract range details */ + FoundBasePage = UseVirtualPage ? Descriptor->VirtualPage : Descriptor->BasePage; + FoundPageCount = Descriptor->PageCount; + FoundEndPage = FoundBasePage + FoundPageCount; + EndPage = PageCount + BasePage; + EarlyPrint(L"Looking for Region 0x%08I64X-0x%08I64X in 0x%08I64X-0x%08I64X\n", BasePage, EndPage, FoundBasePage, FoundEndPage); + + /* Make a copy of the original descriptor */ + RtlCopyMemory(&NewDescriptor, NextEntry, sizeof(NewDescriptor)); + + /* Check if the region to be removed starts after the found region starts */ + if ((BasePage > FoundBasePage) || (FoundBasePage >= EndPage)) + { + /* Check if the region ends after the found region */ + if ((BasePage >= FoundEndPage) || (FoundEndPage > EndPage)) + { + /* Check if the found region starts after the region or ends before the region */ + if ((FoundBasePage >= BasePage) || (EndPage >= FoundEndPage)) + { + /* This descriptor doesn't cover any part of the range */ + EarlyPrint(L"No part of this descriptor contains the region\n"); + } + else + { + /* This descriptor covers the head of the allocation */ + EarlyPrint(L"Descriptor covers the head of the region\n"); + } + } + else + { + /* This descriptor contains the entire allocation */ + EarlyPrint(L"Descriptor contains the entire region\n"); + } + } + else + { + /* This descriptor covers the end of the allocation */ + EarlyPrint(L"Descriptor covers the end of the region\n"); + } + + /* Keep going */ + NextEntry = NextEntry->Flink; + } + +Quickie: + /* Check for failure cleanup */ + if (!NT_SUCCESS(Status)) + { + /* Did we have to build a new list? */ + if (HaveNewList) + { + /* Free and re-initialize it */ + MmMdFreeList(NewMdList); + MmMdInitializeListHead(NewMdList); + NewMdList->Type = MdList->Type; + } + } + + return Status; } VOID diff --git a/reactos/boot/environ/lib/mm/pagealloc.c b/reactos/boot/environ/lib/mm/pagealloc.c index f81dbbb4d2a..295a0e44fcc 100644 --- a/reactos/boot/environ/lib/mm/pagealloc.c +++ b/reactos/boot/environ/lib/mm/pagealloc.c @@ -85,7 +85,7 @@ MmPaInitialize ( { Descriptor = CONTAINING_RECORD(nextEntry, BL_MEMORY_DESCRIPTOR, ListEntry); - EarlyPrint(L"Type: %lX Flags: %lX Start: 0x%I64X End: 0x%I64X\n", + EarlyPrint(L"Type: %08lX Flags: %08lX Base: 0x%016I64X End: 0x%016I64X\n", Descriptor->Type, Descriptor->Flags, Descriptor->BasePage << PAGE_SHIFT,