]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmLib: Correct Error Handling in AArch64
authorOlivier Martin <olivier.martin@arm.com>
Wed, 26 Mar 2014 19:34:32 +0000 (19:34 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 26 Mar 2014 19:34:32 +0000 (19:34 +0000)
There are several instances of asserts which do not also handle
the error condition in Release builds.
Because these functions are called in different location of the
code and their parameters might change during the execution, it
is safer to handle the error.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15399 6f19259b-4bc3-4df7-8a09-765794883524

ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c

index 9bc984f0bfee6b1f794caef6e7ccbb09096b7126..bababab880cb806c2cb0725ef531e3c94f1fc02c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 *  File managing the MMU for ARMv8 architecture\r
 *\r
-*  Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r
+*  Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
 *\r
 *  This program and the accompanying materials\r
 *  are licensed and made available under the terms and conditions of the BSD License\r
@@ -264,13 +264,22 @@ GetBlockEntryListFromAddress (
   BlockEntry = NULL;\r
 \r
   // Ensure the parameters are valid\r
-  ASSERT (TableLevel && BlockEntrySize && LastBlockEntry);\r
+  if (!(TableLevel && BlockEntrySize && LastBlockEntry)) {\r
+    ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);\r
+    return NULL;\r
+  }\r
 \r
   // Ensure the Region is aligned on 4KB boundary\r
-  ASSERT ((RegionStart & (SIZE_4KB - 1)) == 0);\r
+  if ((RegionStart & (SIZE_4KB - 1)) != 0) {\r
+    ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);\r
+    return NULL;\r
+  }\r
 \r
   // Ensure the required size is aligned on 4KB boundary\r
-  ASSERT ((*BlockEntrySize & (SIZE_4KB - 1)) == 0);\r
+  if ((*BlockEntrySize & (SIZE_4KB - 1)) != 0) {\r
+    ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);\r
+    return NULL;\r
+  }\r
 \r
   //\r
   // Calculate LastBlockEntry from T0SZ - this is the last block entry of the root Translation table\r
@@ -427,7 +436,10 @@ FillTranslationTable (
   UINTN   TableLevel;\r
 \r
   // Ensure the Length is aligned on 4KB boundary\r
-  ASSERT ((MemoryRegion->Length > 0) && ((MemoryRegion->Length & (SIZE_4KB - 1)) == 0));\r
+  if ((MemoryRegion->Length == 0) || ((MemoryRegion->Length & (SIZE_4KB - 1)) != 0)) {\r
+    ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
 \r
   // Variable initialization\r
   Attributes = ArmMemoryAttributeToPageAttribute (MemoryRegion->Attributes) | TT_AF;\r
@@ -519,7 +531,11 @@ ArmConfigureMmu (
   UINT64                        TCR;\r
   RETURN_STATUS                 Status;\r
 \r
-  ASSERT (MemoryTable != NULL);\r
+  if(MemoryTable == NULL)\r
+  {\r
+    ASSERT (MemoryTable != NULL);\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
 \r
   // Identify the highest address of the memory table\r
   MaxAddress = MemoryTable->PhysicalBase + MemoryTable->Length - 1;\r