Virtual memory works baby! Virtual Heap at 0x80000000 fully enabled. Next up, EFI...
authorAlex Ionescu <aionescu@gmail.com>
Sun, 14 May 2017 16:07:21 +0000 (16:07 +0000)
committerAlex Ionescu <aionescu@gmail.com>
Sun, 14 May 2017 16:07:21 +0000 (16:07 +0000)
[BOOTLIB]: Fix dumb bug in BlMmIsTranslationEnabled which would always return FALSE.
[BOOTLIB]: Fix dumber bug in MmDefInitializeTranslation which was freeing the page directories and self-map pages even in the success path. Causing us to zero out paging structures...
[BOOTLIB]: Cleanup and extend MmMdDbgDumpList for internal use, and add MmMdListPointerToName as another debug function.
[BOOTLIB]: Add a few more checkpoints in unimplemented paths.

svn path=/trunk/; revision=74545

reactos/boot/environ/include/bl.h
reactos/boot/environ/lib/firmware/efi/firmware.c
reactos/boot/environ/lib/mm/descriptor.c
reactos/boot/environ/lib/mm/heapalloc.c
reactos/boot/environ/lib/mm/i386/mmx86.c
reactos/boot/environ/lib/mm/pagealloc.c

index be09dd9..c9542de 100644 (file)
@@ -2023,9 +2023,10 @@ Archx86TransferTo32BitApplicationAsm (
 
 VOID
 MmMdDbgDumpList (
-    _In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList
+    _In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList,
+    _In_opt_ ULONG MaxCount
 );
-    
+
 VOID
 MmMdInitializeList (
     _In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList,
index becd208..129c70d 100644 (file)
@@ -176,6 +176,8 @@ EfiOpenProtocol (
     {
         /* We need complex tracking to make this work */
         //Status = EfiVmOpenProtocol(Handle, Protocol, Interface);
+        EfiPrintf(L"Paging path hit!\r\n");
+        EfiStall(1000000);
         Status = STATUS_NOT_SUPPORTED;
     }
     else
@@ -185,6 +187,8 @@ EfiOpenProtocol (
         if (OldMode != BlRealMode)
         {
             /* FIXME: Not yet implemented */
+            EfiPrintf(L"Paging path hit!\r\n");
+            EfiStall(1000000);
             return STATUS_NOT_IMPLEMENTED;
         }
 
index d11c36f..710b2e0 100644 (file)
@@ -1267,7 +1267,7 @@ MmMdFindSatisfyingRegion (
         /* Don't let the base overflow */
         if (VirtualMin > VirtualMax)
         {
-            return 0;
+            return FALSE;
         }
 
         /* Adjust the base by the alignment delta */
@@ -1277,7 +1277,7 @@ MmMdFindSatisfyingRegion (
         if (((VirtualMin + Pages - 1) < VirtualMin) ||
             ((VirtualMin + Pages - 1) > VirtualMax))
         {
-            return 0;
+            return FALSE;
         }
 
         /* Finally, pick the correct address based on direction */
@@ -1302,7 +1302,7 @@ MmMdFindSatisfyingRegion (
     if ((((Flags & 0xFF) & (Descriptor->Flags & 0xFF)) != (Flags & 0xFF)) ||
         (((Flags & 0xFF00) & (Descriptor->Flags & 0xFF00)) != (Flags & 0xFF00)))
     {
-        EfiPrintf(L"Incorrect memory attributes\r\n");
+        //EfiPrintf(L"Incorrect memory attributes\r\n");
         return FALSE;
     }
 
index d514e66..5b65399 100644 (file)
@@ -155,6 +155,8 @@ MmHapHeapAllocatorExtend (
                                        0);
     if (!NT_SUCCESS(Status))
     {
+        EfiPrintf(L"HEAP ALLOCATION FAILED\r\n");
+        EfiStall(1000000);
         return Status;
     }
 
index c8a6020..38e52df 100644 (file)
@@ -127,7 +127,7 @@ BlMmIsTranslationEnabled (
 {
     /* Return if paging is on */
     return ((CurrentExecutionContext) &&
-            (CurrentExecutionContext->Mode & BL_CONTEXT_PAGING_ON));
+            (CurrentExecutionContext->ContextFlags & BL_CONTEXT_PAGING_ON));
 }
 
 VOID
@@ -327,6 +327,8 @@ MmDefpMapPhysicalAddress (
                                                        0);
             if (!NT_SUCCESS(Status))
             {
+                EfiPrintf(L"PDE alloc failed!\r\n");
+                EfiStall(1000000);
                 return STATUS_NO_MEMORY;
             }
 
@@ -583,6 +585,7 @@ MmMapPhysicalAddress (
     if (!NT_SUCCESS(Status))
     {
         EfiPrintf(L"Failed to map!: %lx\r\n", Status);
+        EfiStall(1000000);
         return Status;
     }
 
@@ -641,30 +644,43 @@ Mmx86MapInitStructure (
 
 VOID
 MmMdDbgDumpList (
-    _In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList
+    _In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList,
+    _In_opt_ ULONG MaxCount
     )
 {
     ULONGLONG EndPage, VirtualEndPage;
     PBL_MEMORY_DESCRIPTOR MemoryDescriptor;
     PLIST_ENTRY NextEntry;
 
+    /* If no maximum was provided, use essentially infinite */
+    if (MaxCount == 0)
+    {
+        MaxCount = 0xFFFFFFFF;
+    }
+
+    /* Loop the list as long as there's entries and max isn't reached */
     NextEntry = DescriptorList->First->Flink;
-    while (NextEntry != DescriptorList->First)
+    while ((NextEntry != DescriptorList->First) && (MaxCount--))
     {
+        /* Get the descriptor */
         MemoryDescriptor = CONTAINING_RECORD(NextEntry,
                                              BL_MEMORY_DESCRIPTOR,
                                              ListEntry);
 
+        /* Get the descriptor end page, and see if it was virtually mapepd */
         EndPage = MemoryDescriptor->BasePage + MemoryDescriptor->PageCount;
-        if (MemoryDescriptor->VirtualPage != 0)
+        if (MemoryDescriptor->VirtualPage)
         {
-            VirtualEndPage = MemoryDescriptor->VirtualPage + MemoryDescriptor->PageCount;
+            /* Get the virtual end page too, then */
+            VirtualEndPage = MemoryDescriptor->VirtualPage +
+                             MemoryDescriptor->PageCount;
         }
         else
         {
             VirtualEndPage = 0;
         }
 
+        /* Print out the descriptor, physical range, virtual range, and type */
         EfiPrintf(L"%p - [%08llx-%08llx @ %08llx-%08llx]:%x\r\n",
                     MemoryDescriptor,
                     MemoryDescriptor->BasePage << PAGE_SHIFT,
@@ -673,6 +689,7 @@ MmMdDbgDumpList (
                     VirtualEndPage ? (VirtualEndPage << PAGE_SHIFT) - 1 : 0,
                     (ULONG)MemoryDescriptor->Type);
 
+        /* Next entry */
         NextEntry = NextEntry->Flink;
     }
 }
@@ -943,7 +960,7 @@ MmDefInitializeTranslation (
     Status = MmPaTruncateMemory(0x100000);
     if (!NT_SUCCESS(Status))
     {
-        goto Quickie;
+        goto Failure;
     }
 
     /* Allocate a page directory */
@@ -957,7 +974,7 @@ MmDefInitializeTranslation (
                                                0);
     if (!NT_SUCCESS(Status))
     {
-        goto Quickie;
+        goto Failure;
     }
 
     /* Zero out the page directory */
@@ -978,7 +995,7 @@ MmDefInitializeTranslation (
                                                0);
     if (!NT_SUCCESS(Status))
     {
-        goto Quickie;
+        goto Failure;
     }
 
     /* Set the reference page */
@@ -993,7 +1010,7 @@ MmDefInitializeTranslation (
                                      (4 * 1024 * 1024) >> PAGE_SHIFT);
     if (!NT_SUCCESS(Status))
     {
-        goto Quickie;
+        goto Failure;
     }
 
     /* Zero them out */
@@ -1020,7 +1037,7 @@ MmDefInitializeTranslation (
                                        0);
     if (!NT_SUCCESS(Status))
     {
-        goto Quickie;
+        goto Failure;
     }
 
     /* Remove HAL_HEAP from free virtual memory */
@@ -1031,22 +1048,25 @@ MmDefInitializeTranslation (
                                        0);
     if (!NT_SUCCESS(Status))
     {
-        goto Quickie;
+        goto Failure;
     }
 
     /* Initialize the virtual->physical memory mappings */
     Status = Mmx86InitializeMemoryMap(1, MemoryData);
     if (!NT_SUCCESS(Status))
     {
-        goto Quickie;
+        goto Failure;
     }
 
     /* Turn on paging with the new CR3 */
     __writecr3((ULONG_PTR)MmPdpt);
     BlpArchEnableTranslation();
-    EfiPrintf(L"Paging... ON\r\n");
+    EfiPrintf(L"Paging... %d\r\n", BlMmIsTranslationEnabled());
+
+    /* Return success */
+    return Status;
 
-Quickie:
+Failure:
     /* Free reference page if we allocated it */
     if (MmArchReferencePage)
     {
index 8f1aafb..f39904d 100644 (file)
@@ -148,6 +148,31 @@ BlpMmInitializeConstraints (
     return ReturnStatus;
 }
 
+PWCHAR
+MmMdListPointerToName (_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList)
+{
+    if (MdList == &MmMdlUnmappedAllocated)
+    {
+        return L"UnmapAlloc";
+    }
+    else if (MdList == &MmMdlUnmappedUnallocated)
+    {
+        return L"UnmapUnalloc";
+    }
+    else if (MdList == &MmMdlMappedAllocated)
+    {
+        return L"MapAlloc";
+    }
+    else if (MdList == &MmMdlMappedUnallocated)
+    {
+        return L"MapUnalloc";
+    }
+    else
+    {
+        return L"Other";
+    }
+}
+
 NTSTATUS
 MmPapAllocateRegionFromMdl (
     _In_ PBL_MEMORY_DESCRIPTOR_LIST NewList,
@@ -207,7 +232,6 @@ MmPapAllocateRegionFromMdl (
                                      Request->Flags,
                                      Request->Alignment))
         {
-            /* It does, get out */
             break;
         }
 
@@ -225,7 +249,6 @@ MmPapAllocateRegionFromMdl (
     /* Check if we exhausted the list */
     if (NextEntry == ListHead)
     {
-        EfiPrintf(L"No matching memory found\r\n");
         return Status;
     }
 
@@ -246,6 +269,7 @@ MmPapAllocateRegionFromMdl (
         if (!NT_SUCCESS(Status))
         {
             EfiPrintf(L"EFI memory allocation failure\r\n");
+            EfiStall(10000000);
             return Status;
         }
 
@@ -392,9 +416,18 @@ MmPaAllocatePages (
     /* Are we failing due to some attributes? */
     if (Request->Flags & BlMemoryValidAllocationAttributeMask)
     {
-        EfiPrintf(L"alloc fail not yet implemented %lx in %S\r\n", Status, __FUNCTION__);
-        EfiStall(1000000);
-        return STATUS_NOT_IMPLEMENTED;
+        if (Request->Flags & BlMemoryLargePages)
+        {
+            EfiPrintf(L"large alloc fail not yet implemented %lx\r\n", Status);
+            EfiStall(1000000);
+            return STATUS_NOT_IMPLEMENTED;
+        }
+        if (Request->Flags & BlMemoryFixed)
+        {
+            EfiPrintf(L"fixed alloc fail not yet implemented %lx\r\n", Status);
+            EfiStall(1000000);
+            return STATUS_NOT_IMPLEMENTED;
+        }
     }
 
     /* Nope, just fail the entire call */
@@ -601,7 +634,7 @@ MmPapPageAllocatorExtend (
                                BlConventionalMemory);
     if (!NT_SUCCESS(Status))
     {
-        EfiPrintf(L"Failed to get unmapped,unallocated memory!\r\n");
+        EfiPrintf(L"Failed to get unmapped, unallocated memory!\r\n");
         EfiStall(10000000);
         return Status;
     }