[BOOTLIB]: Fix from hermes for BlReplaceBootOptions
authorAlex Ionescu <aionescu@gmail.com>
Sun, 5 Feb 2017 00:05:19 +0000 (00:05 +0000)
committerAlex Ionescu <aionescu@gmail.com>
Sun, 5 Feb 2017 00:05:19 +0000 (00:05 +0000)
[BOOTLIB]: More WIP transfer code.

svn path=/trunk/; revision=73689

reactos/boot/environ/include/bl.h
reactos/boot/environ/lib/misc/bcdopt.c
reactos/boot/environ/lib/misc/image.c
reactos/boot/environ/lib/misc/util.c

index d7dd2df..d140b2e 100644 (file)
@@ -93,6 +93,16 @@ DEFINE_GUID(BadMemoryGuid, 0x54B8275B, 0xD431, 0x473F, 0xAC, 0xFB, 0xE5, 0x36, 0
 #define BL_MM_ADD_DESCRIPTOR_NEVER_TRUNCATE_FLAG        0x20
 #define BL_MM_ADD_DESCRIPTOR_UPDATE_LIST_POINTER_FLAG   0x2000
 
 #define BL_MM_ADD_DESCRIPTOR_NEVER_TRUNCATE_FLAG        0x20
 #define BL_MM_ADD_DESCRIPTOR_UPDATE_LIST_POINTER_FLAG   0x2000
 
+#define BL_MM_INCLUDE_MAPPED_ALLOCATED                  0x01
+#define BL_MM_INCLUDE_MAPPED_UNALLOCATED                0x02
+#define BL_MM_INCLUDE_UNMAPPED_ALLOCATED                0x04
+#define BL_MM_INCLUDE_UNMAPPED_UNALLOCATED              0x08
+#define BL_MM_INCLUDE_RESERVED_ALLOCATED                0x10
+#define BL_MM_INCLUDE_BAD_MEMORY                        0x20
+#define BL_MM_INCLUDE_FIRMWARE_MEMORY                   0x40
+#define BL_MM_INCLUDE_TRUNCATED_MEMORY                  0x80
+#define BL_MM_INCLUDE_PERSISTEND_MEMORY                 0x100
+
 #define BL_MM_REQUEST_DEFAULT_TYPE                      1
 #define BL_MM_REQUEST_TOP_DOWN_TYPE                     2
 
 #define BL_MM_REQUEST_DEFAULT_TYPE                      1
 #define BL_MM_REQUEST_TOP_DOWN_TYPE                     2
 
index 75a0545..0b4f82e 100644 (file)
@@ -821,14 +821,15 @@ BlRemoveBootOption (
 NTSTATUS
 BlReplaceBootOptions (
     _In_ PBL_LOADED_APPLICATION_ENTRY AppEntry,
 NTSTATUS
 BlReplaceBootOptions (
     _In_ PBL_LOADED_APPLICATION_ENTRY AppEntry,
-    _In_ PBL_BCD_OPTION NewOptions
+    _In_ PBL_BCD_OPTION OldOptions
     )
 {
     NTSTATUS Status;
     )
 {
     NTSTATUS Status;
-    ULONG Size;
+    ULONG OptionSize;
+    PBL_BCD_OPTION NewOptions;
 
     /* Make sure there's something to replace with */
 
     /* Make sure there's something to replace with */
-    if (!NewOptions)
+    if (!OldOptions)
     {
         return STATUS_INVALID_PARAMETER;
     }
     {
         return STATUS_INVALID_PARAMETER;
     }
@@ -849,17 +850,17 @@ BlReplaceBootOptions (
     AppEntry->BcdData = NULL;
 
     /* Get the size of the new list of options */
     AppEntry->BcdData = NULL;
 
     /* Get the size of the new list of options */
-    Size = BlGetBootOptionListSize(NewOptions);
+    OptionSize = BlGetBootOptionListSize(OldOptions);
 
     /* Allocate a copy of the new list */
 
     /* Allocate a copy of the new list */
-    NewOptions = BlMmAllocateHeap(Size);
+    NewOptions = BlMmAllocateHeap(OptionSize);
     if (!NewOptions)
     {
         return STATUS_NO_MEMORY;
     }
 
     /* Copy it in */
     if (!NewOptions)
     {
         return STATUS_NO_MEMORY;
     }
 
     /* Copy it in */
-    RtlCopyMemory(NewOptions, NewOptions, Size);
+    RtlCopyMemory(NewOptions, OldOptions, OptionSize);
 
     /* Set it as the new set of options and return */
     AppEntry->Flags |= BL_APPLICATION_ENTRY_BCD_OPTIONS_INTERNAL;
 
     /* Set it as the new set of options and return */
     AppEntry->Flags |= BL_APPLICATION_ENTRY_BCD_OPTIONS_INTERNAL;
index d8dec2f..5af7931 100644 (file)
@@ -1604,6 +1604,17 @@ BlpPdParseReturnArguments (
     return STATUS_NOT_IMPLEMENTED;
 }
 
     return STATUS_NOT_IMPLEMENTED;
 }
 
+NTSTATUS
+BlMmGetMemoryMap (
+    _In_ PLIST_ENTRY MemoryMap,
+    _In_ PBL_IMAGE_PARAMETERS ImageParameters,
+    _In_ ULONG WhichTypes,
+    _In_ ULONG Flags
+    )
+{
+    return STATUS_SUCCESS;
+}
+
 NTSTATUS
 ImgpInitializeBootApplicationParameters (
     _In_ PBL_IMAGE_PARAMETERS ImageParameters,
 NTSTATUS
 ImgpInitializeBootApplicationParameters (
     _In_ PBL_IMAGE_PARAMETERS ImageParameters,
@@ -1612,6 +1623,32 @@ ImgpInitializeBootApplicationParameters (
     _In_ ULONG ImageSize
     )
 {
     _In_ ULONG ImageSize
     )
 {
+    NTSTATUS Status;
+    PIMAGE_NT_HEADERS NtHeaders;
+    BL_IMAGE_PARAMETERS MemoryParameters;
+    LIST_ENTRY MemoryList;
+
+    Status = RtlImageNtHeaderEx(0, ImageBase, ImageSize, &NtHeaders);
+    if (!NT_SUCCESS(Status))
+    {
+        return Status;
+    }
+
+    MemoryParameters.BufferSize = 0;
+
+    Status = BlMmGetMemoryMap(&MemoryList,
+                              &MemoryParameters,
+                              BL_MM_INCLUDE_FIRMWARE_MEMORY |
+                              BL_MM_INCLUDE_MAPPED_ALLOCATED |
+                              BL_MM_INCLUDE_MAPPED_UNALLOCATED |
+                              BL_MM_INCLUDE_UNMAPPED_ALLOCATED |
+                              BL_MM_INCLUDE_RESERVED_ALLOCATED,
+                              0);
+    if ((Status != STATUS_BUFFER_TOO_SMALL) && (Status != STATUS_SUCCESS))
+    {
+        return Status;
+    }
+
     return STATUS_SUCCESS;
 }
 
     return STATUS_SUCCESS;
 }
 
@@ -1649,28 +1686,34 @@ ImgArchEfiStartBootApplication (
         goto Quickie;
     }
 
         goto Quickie;
     }
 
+    /* Zero the boot data */
     RtlZeroMemory(BootData, BootSizeNeeded);
 
     RtlZeroMemory(BootData, BootSizeNeeded);
 
+    /* Set the new stack, GDT and IDT */
     NewStack = (PVOID)((ULONG_PTR)BootData + (24 * PAGE_SIZE) - 8);
     NewGdt = (PVOID)((ULONG_PTR)BootData + (24 * PAGE_SIZE));
     NewIdt = (PVOID)((ULONG_PTR)BootData + (24 * PAGE_SIZE) + Gdt.Limit + 1);
 
     NewStack = (PVOID)((ULONG_PTR)BootData + (24 * PAGE_SIZE) - 8);
     NewGdt = (PVOID)((ULONG_PTR)BootData + (24 * PAGE_SIZE));
     NewIdt = (PVOID)((ULONG_PTR)BootData + (24 * PAGE_SIZE) + Gdt.Limit + 1);
 
+    /* Copy the current (firmware) GDT and IDT */
     RtlCopyMemory(NewGdt, (PVOID)Gdt.Base, Gdt.Limit + 1);
     RtlCopyMemory(NewIdt, (PVOID)Idt.Base, Idt.Limit + 1);
 
     RtlCopyMemory(NewGdt, (PVOID)Gdt.Base, Gdt.Limit + 1);
     RtlCopyMemory(NewIdt, (PVOID)Idt.Base, Idt.Limit + 1);
 
+    /* Read the NT headers so that we can get the entrypoint later on */
     RtlImageNtHeaderEx(0, ImageBase, ImageSize, &NtHeaders);
 
     RtlImageNtHeaderEx(0, ImageBase, ImageSize, &NtHeaders);
 
+    /* Prepare the application parameters */
     RtlZeroMemory(&Parameters, sizeof(Parameters));
     RtlZeroMemory(&Parameters, sizeof(Parameters));
-
     Status = ImgpInitializeBootApplicationParameters(&Parameters,
                                                      AppEntry,
                                                      ImageBase,
                                                      ImageSize);
     if (NT_SUCCESS(Status))
     {
     Status = ImgpInitializeBootApplicationParameters(&Parameters,
                                                      AppEntry,
                                                      ImageBase,
                                                      ImageSize);
     if (NT_SUCCESS(Status))
     {
+        /* Set the firmware GDT/IDT as the one the application will use */
         BootAppGdtRegister = Gdt;
         BootAppIdtRegister = Idt;
 
         BootAppGdtRegister = Gdt;
         BootAppIdtRegister = Idt;
 
+        /* Set the entrypoint, parameters, and stack */
         BootApp32EntryRoutine = (PVOID)((ULONG_PTR)ImageBase +
                                         NtHeaders->OptionalHeader.
                                         AddressOfEntryPoint);
         BootApp32EntryRoutine = (PVOID)((ULONG_PTR)ImageBase +
                                         NtHeaders->OptionalHeader.
                                         AddressOfEntryPoint);
@@ -1678,11 +1721,11 @@ ImgArchEfiStartBootApplication (
         BootApp32Stack = NewStack;
 
 #if BL_KD_SUPPORT
         BootApp32Stack = NewStack;
 
 #if BL_KD_SUPPORT
+        /* Disable the kernel debugger */
         BlBdStop();
 #endif
         /* Not yet implemented. This is the last step! */
         EfiPrintf(L"EFI APPLICATION START!!!\r\n");
         BlBdStop();
 #endif
         /* Not yet implemented. This is the last step! */
         EfiPrintf(L"EFI APPLICATION START!!!\r\n");
-        EfiStall(100000000);
 
         /* Make it so */
         Archx86TransferTo32BitApplicationAsm();
 
         /* Make it so */
         Archx86TransferTo32BitApplicationAsm();
@@ -1690,17 +1733,22 @@ ImgArchEfiStartBootApplication (
         /* Not yet implemented. This is the last step! */
         EfiPrintf(L"EFI APPLICATION RETURNED!!!\r\n");
         EfiStall(100000000);
         /* Not yet implemented. This is the last step! */
         EfiPrintf(L"EFI APPLICATION RETURNED!!!\r\n");
         EfiStall(100000000);
+
 #if BL_KD_SUPPORT
 #if BL_KD_SUPPORT
+        /* Re-enable the kernel debugger */
         BlBdStart();
 #endif
     }
 
 Quickie:
         BlBdStart();
 #endif
     }
 
 Quickie:
+    /* Check if we had boot data allocated */
     if (BootData)
     {
     if (BootData)
     {
+        /* Free it */
         //MmPapFreePages(bootData, TRUE);
     }
 
         //MmPapFreePages(bootData, TRUE);
     }
 
+    /* All done */
     return STATUS_NOT_IMPLEMENTED;
 }
 
     return STATUS_NOT_IMPLEMENTED;
 }
 
index f6fcd99..9abe95d 100644 (file)
@@ -28,8 +28,6 @@ ULONG UtlNextUpdatePercentage;
 BOOLEAN UtlProgressNeedsInfoUpdate;
 PVOID UtlProgressInfo;
 
 BOOLEAN UtlProgressNeedsInfoUpdate;
 PVOID UtlProgressInfo;
 
-
-
 /* FUNCTIONS *****************************************************************/
 
 NTSTATUS
 /* FUNCTIONS *****************************************************************/
 
 NTSTATUS