[BOOT:BOOTLIB] Parse BCD GUID to application entry
This commit is contained in:
@@ -13,6 +13,9 @@ Abstract:
|
||||
|
||||
--*/
|
||||
|
||||
#include <ntrtl.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include "bootmgr.h"
|
||||
#include "efi.h"
|
||||
|
||||
@@ -30,7 +33,7 @@ EfiInitpCreateApplicationEntry (
|
||||
IN PWCHAR LoadOptions,
|
||||
IN ULONG LoadOptionsSize,
|
||||
OUT PULONG BufferUsed,
|
||||
OUT PBOOT_DEVICE *Device
|
||||
OUT PBOOT_DEVICE *BootDevice
|
||||
)
|
||||
|
||||
/*++
|
||||
@@ -57,7 +60,7 @@ Arguments:
|
||||
|
||||
BufferUsed - Returns the amount of buffer space used by the routine.
|
||||
|
||||
Device - Returns a pointer to the device the application was loaded from.
|
||||
BootDevice - Returns a pointer to the device the application was loaded from.
|
||||
|
||||
Return Value:
|
||||
|
||||
@@ -66,19 +69,49 @@ Return Value:
|
||||
--*/
|
||||
|
||||
{
|
||||
PWCHAR BcdOptionString;
|
||||
BOOLEAN BcdIdentifierSet;
|
||||
UNICODE_STRING UnicodeString;
|
||||
|
||||
*BufferUsed = 0;
|
||||
*BootDevice = NULL;
|
||||
BcdIdentifierSet = FALSE;
|
||||
|
||||
//
|
||||
// Require enough space for the application entry.
|
||||
//
|
||||
if (BufferSize < sizeof(BOOT_APPLICATION_ENTRY)) {
|
||||
*BufferUsed = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Terminate load options string.
|
||||
//
|
||||
LoadOptionsSize /= sizeof(WCHAR);
|
||||
if (LoadOptionsSize != 0 && wcsnlen(LoadOptions, LoadOptionsSize) == LoadOptionsSize) {
|
||||
LoadOptions[LoadOptionsSize - 1] = L'\0';
|
||||
}
|
||||
|
||||
//
|
||||
// Set up application entry structure.
|
||||
//
|
||||
RtlZeroMemory(Entry, sizeof(BOOT_APPLICATION_ENTRY));
|
||||
Entry->Signature = BOOT_APPLICATION_ENTRY_SIGNATURE;
|
||||
*BufferUsed = sizeof(BOOT_APPLICATION_ENTRY);
|
||||
|
||||
//
|
||||
// Parse BCD GUID if present.
|
||||
//
|
||||
if (LoadOptions != NULL && (BcdOptionString = wcsstr(LoadOptions, L"BCDOBJECT=")) != NULL) {
|
||||
RtlInitUnicodeString(&UnicodeString, (PWCHAR)((PUCHAR)BcdOptionString + sizeof(L"BCDOBJECT=") - sizeof(UNICODE_NULL)));
|
||||
if (NT_SUCCESS(RtlGUIDFromString(&UnicodeString, &Entry->BcdIdentifier))) {
|
||||
BcdIdentifierSet = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!BcdIdentifierSet) {
|
||||
Entry->Attributes |= BOOT_APPLICATION_ENTRY_BCD_IDENTIFIER_NOT_SET;
|
||||
}
|
||||
|
||||
//
|
||||
// TODO: This routine is not fully implemented.
|
||||
@@ -86,10 +119,6 @@ Return Value:
|
||||
(VOID)SystemTable;
|
||||
(VOID)DevicePath;
|
||||
(VOID)FilePath;
|
||||
(VOID)LoadOptions;
|
||||
(VOID)LoadOptionsSize;
|
||||
(VOID)Device;
|
||||
*BufferUsed = sizeof(BOOT_APPLICATION_ENTRY);
|
||||
}
|
||||
|
||||
PBOOT_INPUT_PARAMETERS
|
||||
@@ -192,7 +221,7 @@ Return Value:
|
||||
ScratchUsed += sizeof(BOOT_MEMORY_DESCRIPTOR);
|
||||
MemoryDescriptor->BasePage = (UINTN)InputParameters->ImageBase >> PAGE_SHIFT;
|
||||
MemoryDescriptor->Pages = ALIGN_UP(InputParameters->ImageSize, PAGE_SIZE) >> PAGE_SHIFT;
|
||||
MemoryDescriptor->Flags = MEMORY_FLAG_CACHE_WB;
|
||||
MemoryDescriptor->Attributes = MEMORY_ATTRIBUTE_CACHE_WB;
|
||||
MemoryDescriptor->Type = MEMORY_TYPE_BOOT_APPLICATION;
|
||||
|
||||
//
|
||||
@@ -243,6 +272,13 @@ Return Value:
|
||||
ScratchUsed += sizeof(BOOT_RETURN_DATA);
|
||||
ReturnData->Version = BOOT_RETURN_DATA_VERSION;
|
||||
|
||||
//
|
||||
// Set and validate total size.
|
||||
//
|
||||
InputParameters->Size = ScratchUsed;
|
||||
if (InputParameters->Size > sizeof(EfiInitScratch)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return InputParameters;
|
||||
}
|
||||
|
Reference in New Issue
Block a user