]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Gcd/Gcd.c
Add more code robustness check for modules under MdeModulePkg.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Gcd / Gcd.c
index c9aad1ce3a4596713b2fed01acba509d17471bd1..32a56e76604da939ac0443bb3e1fe58504c028bc 100644 (file)
@@ -3,7 +3,7 @@
   The GCD services are used to manage the memory and I/O regions that\r
   are accessible to the CPU that is executing the DXE core.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
+Copyright (c) 2006 - 2010, Intel Corporation. <BR>\r
 All rights reserved. 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
@@ -583,10 +583,11 @@ CoreConvertSpace (
   if ((Operation & GCD_MEMORY_SPACE_OPERATION) != 0) {\r
     CoreAcquireGcdMemoryLock ();\r
     Map = &mGcdMemorySpaceMap;\r
-  }\r
-  if ((Operation & GCD_IO_SPACE_OPERATION) != 0) {\r
+  } else if ((Operation & GCD_IO_SPACE_OPERATION) != 0) {\r
     CoreAcquireGcdIoLock ();\r
     Map = &mGcdIoSpaceMap;\r
+  } else {\r
+    ASSERT (FALSE);\r
   }\r
 \r
   //\r
@@ -598,6 +599,7 @@ CoreConvertSpace (
 \r
     goto Done;\r
   }\r
+  ASSERT (StartLink != NULL && EndLink != NULL);\r
 \r
   //\r
   // Verify that the list of descriptors are unallocated non-existent memory.\r
@@ -683,6 +685,7 @@ CoreConvertSpace (
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
+  ASSERT (TopEntry != NULL && BottomEntry != NULL);\r
 \r
   if (Operation == GCD_SET_ATTRIBUTES_MEMORY_OPERATION) {\r
     //\r
@@ -691,7 +694,7 @@ CoreConvertSpace (
     CpuArchAttributes = ConverToCpuArchAttributes (Attributes);\r
     if ( CpuArchAttributes != INVALID_CPU_ARCH_ATTRIBUTES ) {\r
       Status = CoreLocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&CpuArch);\r
-      if (EFI_ERROR (Status)) {\r
+      if (EFI_ERROR (Status) || CpuArch == NULL) {\r
         Status = EFI_ACCESS_DENIED;\r
         goto Done;\r
       }\r
@@ -893,10 +896,11 @@ CoreAllocateSpace (
   if ((Operation & GCD_MEMORY_SPACE_OPERATION) != 0) {\r
     CoreAcquireGcdMemoryLock ();\r
     Map = &mGcdMemorySpaceMap;\r
-  }\r
-  if ((Operation & GCD_IO_SPACE_OPERATION) != 0) {\r
+  } else if ((Operation & GCD_IO_SPACE_OPERATION) != 0) {\r
     CoreAcquireGcdIoLock ();\r
     Map = &mGcdIoSpaceMap;\r
+  } else {\r
+    ASSERT (FALSE);\r
   }\r
 \r
   Found     = FALSE;\r
@@ -924,6 +928,7 @@ CoreAllocateSpace (
       Status = EFI_NOT_FOUND;\r
       goto Done;\r
     }\r
+    ASSERT (StartLink != NULL && EndLink != NULL);\r
 \r
     //\r
     // Verify that the list of descriptors are unallocated memory matching GcdMemoryType.\r
@@ -1007,6 +1012,7 @@ CoreAllocateSpace (
         Status = EFI_NOT_FOUND;\r
         goto Done;\r
       }\r
+      ASSERT (StartLink != NULL && EndLink != NULL);\r
 \r
       Link = StartLink;\r
       //\r
@@ -1042,6 +1048,7 @@ CoreAllocateSpace (
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
+  ASSERT (TopEntry != NULL && BottomEntry != NULL);\r
 \r
   //\r
   // Convert/Insert the list of descriptors from StartLink to EndLink\r
@@ -1328,6 +1335,7 @@ CoreGetMemorySpaceDescriptor (
   if (EFI_ERROR (Status)) {\r
     Status = EFI_NOT_FOUND;\r
   } else {\r
+    ASSERT (StartLink != NULL && EndLink != NULL);\r
     //\r
     // Copy the contents of the found descriptor into Descriptor\r
     //\r
@@ -1607,6 +1615,7 @@ CoreGetIoSpaceDescriptor (
   if (EFI_ERROR (Status)) {\r
     Status = EFI_NOT_FOUND;\r
   } else {\r
+    ASSERT (StartLink != NULL && EndLink != NULL);\r
     //\r
     // Copy the contents of the found descriptor into Descriptor\r
     //\r
@@ -1763,6 +1772,7 @@ CoreInitializeMemoryServices (
   EFI_PHYSICAL_ADDRESS               HighAddress;\r
   EFI_HOB_RESOURCE_DESCRIPTOR        *MaxResourceHob;\r
   EFI_HOB_GUID_TYPE                  *GuidHob;\r
+  UINT32                              ReservedCodePageNumber;\r
 \r
   //\r
   // Point at the first HOB.  This must be the PHIT HOB.\r
@@ -1793,7 +1803,17 @@ CoreInitializeMemoryServices (
   // Cache the PHIT HOB for later use\r
   //\r
   PhitHob = Hob.HandoffInformationTable;\r
-\r
+  \r
+  if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {\r
+       ReservedCodePageNumber = PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber);\r
+       ReservedCodePageNumber += PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber);\r
+   \r
+       //\r
+       // cache the Top address for loading modules at Fixed Address \r
+       //\r
+    gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress = PhitHob->EfiMemoryTop \r
+                                                                   + EFI_PAGES_TO_SIZE(ReservedCodePageNumber);\r
+  }\r
   //\r
   // See if a Memory Type Information HOB is available\r
   //\r