]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/WinNtAutoScanPei/WinNtAutoScan.c
IntelSiliconPkg/IntelSiliconPkg.dsc: Add a driver to build
[mirror_edk2.git] / Nt32Pkg / WinNtAutoScanPei / WinNtAutoScan.c
index 90a97b97676393035c12fcc3151e93d869b3d682..8b68fefcaa341aa447e54dc448761b28921a148c 100644 (file)
@@ -1,6 +1,7 @@
 /**@file\r
 \r
 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -49,6 +50,53 @@ EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {
   { EfiMaxMemoryType,       0      }\r
 };\r
 \r
+/**\r
+   Validate variable data for the MemoryTypeInformation. \r
+\r
+   @param MemoryData       Variable data.\r
+   @param MemoryDataSize   Variable data length.\r
+   \r
+   @return TRUE            The variable data is valid.\r
+   @return FALSE           The variable data is invalid.\r
+\r
+**/\r
+BOOLEAN\r
+ValidateMemoryTypeInfoVariable (\r
+  IN EFI_MEMORY_TYPE_INFORMATION      *MemoryData,\r
+  IN UINTN                            MemoryDataSize\r
+  )\r
+{\r
+  UINTN                       Count;\r
+  UINTN                       Index;\r
+\r
+  // Check the input parameter.\r
+  if (MemoryData == NULL) {\r
+    return FALSE;\r
+  }\r
+\r
+  // Get Count\r
+  Count = MemoryDataSize / sizeof (*MemoryData);\r
+\r
+  // Check Size\r
+  if (Count * sizeof(*MemoryData) != MemoryDataSize) {\r
+    return FALSE;\r
+  }\r
+\r
+  // Check last entry type filed.\r
+  if (MemoryData[Count - 1].Type != EfiMaxMemoryType) {\r
+    return FALSE;\r
+  }\r
+\r
+  // Check the type filed.\r
+  for (Index = 0; Index < Count - 1; Index++) {\r
+    if (MemoryData[Index].Type >= EfiMaxMemoryType) {\r
+      return FALSE;\r
+    }\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
 EFI_STATUS\r
 EFIAPI\r
 PeimInitializeWinNtAutoScan (\r
@@ -129,9 +177,9 @@ Returns:
   } while (!EFI_ERROR (Status));\r
 \r
   //\r
-  // Build the CPU hob with 36-bit addressing and 16-bits of IO space.\r
+  // Build the CPU hob with 52-bit addressing and 16-bits of IO space.\r
   //\r
-  BuildCpuHob (36, 16);\r
+  BuildCpuHob (52, 16);\r
 \r
   //\r
   // Build GUIDed Hob that contains the Memory Type Information array\r
@@ -153,7 +201,7 @@ Returns:
                        &DataSize,\r
                        &MemoryData\r
                        );\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || !ValidateMemoryTypeInfoVariable(MemoryData, DataSize)) {\r
     //\r
     // Create Memory Type Information HOB\r
     //\r