]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MemoryAllocationLib: For boundary case: “AllocationSize + OverAllocationSize >= 4G”
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 25 May 2006 10:13:26 +0000 (10:13 +0000)
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 25 May 2006 10:13:26 +0000 (10:13 +0000)
DxeMemoryAllocationLib: Change the behavior from returning NULL to ASSERT ()
PeiMemoryAllocationLib: Add ASSERT ()
I also add ASSERT () in Pei Service AllocatePool () to catch if allocation size > 64K
DebugLib:
Header file (DebugLib.h): Fix an issue in ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid).
In contrast with LocateProtocol (), the first & second parameter type of HandleProtocol () is EFI_HANDLE & EFI_GUID respectively.
UefiLib:
For UnicodeStringDisplayLength (CONST CHAR8 *String), return 0 if String is NULL.
BasePrintLib:
Add missing “EFIAPI” to UnicodeValueToString() and AsciiValueToString() and move their definitions from PrintLibInternal.c to PrintLib.c.
Fix the comments error(Maximum Length TIME”)

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@275 6f19259b-4bc3-4df7-8a09-765794883524

EdkModulePkg/Core/Pei/Memory/MemoryServices.c
MdePkg/Include/Library/DebugLib.h
MdePkg/Include/Library/PrintLib.h
MdePkg/Library/BasePrintLib/PrintLib.c
MdePkg/Library/BasePrintLib/PrintLibInternal.c
MdePkg/Library/BasePrintLib/PrintLibInternal.h
MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c
MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
MdePkg/Library/UefiLib/Console.c

index 48b2b3818cd65bd4b38e62a4020f298484ca05c2..eb99a8040db68771a1ed8df34685c3bb0c89413b 100644 (file)
@@ -301,8 +301,12 @@ Returns:
   EFI_STATUS               Status;\r
   EFI_HOB_MEMORY_POOL      *Hob;\r
 \r
-\r
-  Status = PeiCoreCreateHob (\r
+ //\r
+ // If some ¡°post-memory¡± PEIM wishes to allocate larger pool,\r
+ // it should use AllocatePages service instead.\r
+ //\r
+ ASSERT (Size < 0x10000 - sizeof (EFI_HOB_MEMORY_POOL));\r
+ Status = PeiCoreCreateHob (\r
              EFI_HOB_TYPE_PEI_MEMORY_POOL,\r
              (UINT16)(sizeof (EFI_HOB_MEMORY_POOL) + Size),\r
              (VOID **)&Hob\r
index 82f9e6fdbac5f5cb0c241bef143d0c441631b08c..5efb30401649fb55903ec0a3997cf02ebacd8d32 100644 (file)
@@ -72,7 +72,7 @@ DebugPrint (
   Prints an assert message containing a filename, line number, and description.  \r
   This may be followed by a breakpoint or a dead loop.\r
 \r
-  Print a message of the form \93ASSERT <FileName>(<LineNumber>): <Description>\n\94 \r
+  Print a message of the form \93ASSERT <FileName>(<LineNumber>): <Description>\n?\r
   to the debug output device.  If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of \r
   PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if \r
   DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then \r
@@ -81,9 +81,9 @@ DebugPrint (
   DebugAssert() must actively prevent recusrsion.  If DebugAssert() is called while\r
   processing another DebugAssert(), then DebugAssert() must return immediately.\r
 \r
-  If FileName is NULL, then a <FileName> string of \93(NULL) Filename\94 is printed.\r
+  If FileName is NULL, then a <FileName> string of ?NULL) Filename?is printed.\r
 \r
-  If Description is NULL, then a <Description> string of \93(NULL) Description\94 is printed.\r
+  If Description is NULL, then a <Description> string of ?NULL) Description?is printed.\r
 \r
   @param  FileName     Pointer to the name of the source file that generated the assert condition.\r
   @param  LineNumber   The line number in the source file that generated the assert condition\r
@@ -108,7 +108,7 @@ DebugAssert (
 \r
   If Buffer is NULL, then ASSERT().\r
 \r
-  If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT(). \r
+  If Length is greater than (MAX_ADDRESS ?Buffer + 1), then ASSERT(). \r
 \r
   @param   Buffer  Pointer to the target buffer to fill with PcdDebugClearMemoryValue.\r
   @param   Length  Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. \r
@@ -321,7 +321,7 @@ DebugClearMemoryEnabled (
           _ASSERT (Guid already installed in database);                    \\r
         }                                                                  \\r
       } else {                                                             \\r
-        if (!EFI_ERROR (gBS->HandleProtocol (Guid, Handle, &Instance))) {  \\r
+        if (!EFI_ERROR (gBS->HandleProtocol (Handle, Guid, &Instance))) {  \\r
           _ASSERT (Guid already installed on Handle);                      \\r
         }                                                                  \\r
       }                                                                    \\r
@@ -411,7 +411,7 @@ DebugClearMemoryEnabled (
   by TYPE is compared to TestSignature.  If the signatures match, then a pointer \r
   to the pointer to a data structure of the type specified by TYPE is returned.  \r
   If the signatures do not match, then DebugAssert() is called with a description \r
-  of \93CR has a bad signature\94 and Record is returned.  \r
+  of \93CR has a bad signature?and Record is returned.  \r
 \r
   If the data type specified by TYPE does not contain the field specified by Field, \r
   then the module will not compile.\r
index c84b7c36aafd2ce08959e0fe449eff359568cff9..3eb84f311b51aa31cd315ad3020faaa7009ed211 100644 (file)
@@ -98,6 +98,7 @@ AsciiSPrintUnicodeFormat (
   );\r
 \r
 UINTN\r
+EFIAPI\r
 UnicodeValueToString (\r
   IN OUT CHAR16  *Buffer,\r
   IN UINTN       Flags,\r
@@ -106,6 +107,7 @@ UnicodeValueToString (
   );\r
 \r
 UINTN\r
+EFIAPI\r
 AsciiValueToString (\r
   IN OUT CHAR8  *Buffer,\r
   IN UINTN      Flags,\r
index 816c887088589d02fa8327d964b8d64895febcf8..bbd08201067689e93609b0aa9ade6b8913ccf14f 100644 (file)
@@ -637,3 +637,27 @@ AsciiSPrintUnicodeFormat (
   VA_START (Marker, FormatString);\r
   return AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
 }\r
+\r
+UINTN\r
+EFIAPI\r
+UnicodeValueToString (\r
+  IN OUT CHAR16  *Buffer,\r
+  IN UINTN       Flags,\r
+  IN INT64       Value,\r
+  IN UINTN       Width\r
+  )\r
+{\r
+  return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 2);\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+AsciiValueToString (\r
+  IN OUT CHAR8  *Buffer,\r
+  IN UINTN      Flags,\r
+  IN INT64      Value,\r
+  IN UINTN      Width\r
+  )\r
+{\r
+  return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 1);\r
+}\r
index 24d8b56598c55937334165ec2d6549e58a1ae0e8..56d357525c147caca99dce7962d95ea4d0dc53f2 100644 (file)
@@ -128,26 +128,3 @@ BasePrintLibConvertValueToString (
 \r
   return ((Buffer - OriginalBuffer) / Increment);\r
 }\r
-\r
-\r
-UINTN\r
-UnicodeValueToString (\r
-  IN OUT CHAR16  *Buffer,\r
-  IN UINTN       Flags,\r
-  IN INT64       Value,\r
-  IN UINTN       Width\r
-  )\r
-{\r
-  return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 2);\r
-}\r
-\r
-UINTN\r
-AsciiValueToString (\r
-  IN OUT CHAR8  *Buffer,\r
-  IN UINTN      Flags,\r
-  IN INT64      Value,\r
-  IN UINTN      Width\r
-  )\r
-{\r
-  return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 1);\r
-}\r
index de08f0edfc8a19b4fb2c43ce7af283c6d6873aae..c7fecfd34c5644b980057cd6b680e85cb97cf816 100644 (file)
@@ -39,7 +39,7 @@
 ///   Maximum Length Decimal String     = 28    "-9,223,372,036,854,775,808"\r
 ///   Maximum Length Hexidecimal String = 17    "FFFFFFFFFFFFFFFF"\r
 ///   Maximum Length GUID               = 37    "00000000-0000-0000-0000-000000000000"\r
-///   Maximum Length TIME               = 17    "12/12/2006  12:12"\r
+///   Maximum Length TIME               = 18    "12/12/2006  12:12"\r
 ///\r
 #define MAXIMUM_VALUE_CHARACTERS  38\r
 \r
@@ -85,3 +85,11 @@ BasePrintLibValueToString (
   IN UINTN      Radix\r
   );\r
 \r
+UINTN\r
+BasePrintLibConvertValueToString (\r
+  IN OUT CHAR8   *Buffer,\r
+  IN UINTN       Flags,\r
+  IN INT64       Value,\r
+  IN UINTN       Width,\r
+  IN UINTN       Increment\r
+  );\r
index ef643eed4296d2252506098a5bc5b18922425dc6..088a10bb5623f5f27bb67084f979226909a91c18 100644 (file)
@@ -168,13 +168,11 @@ InternalAllocateAlignedPages (
     //\r
     AlignmentMask  = Alignment - 1;\r
     RealPages      = Pages + EFI_SIZE_TO_PAGES (Alignment);\r
-    if (RealPages <= Pages) {\r
-      //\r
-      // This extra checking is to make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow. \r
-      //\r
-      return NULL;\r
-    }\r
-\r
+    //\r
+    // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.\r
+    //\r
+    ASSERT (RealPages > Pages);\r
\r
     Status         = gBS->AllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory);\r
     if (EFI_ERROR (Status)) {\r
       return NULL;\r
@@ -601,12 +599,11 @@ InternalAllocateAlignedPool (
   //\r
   OverAllocationSize  = sizeof (RawAddress) + AlignmentMask;\r
   RealAllocationSize  = AllocationSize + OverAllocationSize;\r
-  if (RealAllocationSize <= AllocationSize ) {\r
-    //\r
-    // This extra checking is to make sure that AllocationSize plus OverAllocationSize does not overflow. \r
-    //\r
-    return NULL;\r
-  }\r
+  //\r
+  // Make sure that AllocationSize plus OverAllocationSize does not overflow. \r
+  //\r
+  ASSERT (RealAllocationSize > AllocationSize); \r
+\r
   RawAddress = InternalAllocatePool (PoolType, RealAllocationSize);\r
   if (RawAddress == NULL) {\r
     return NULL;\r
index 63641569ffe65d2450d59ee6c6e25ae8994faee9..274287cf035e216cc537f3c6aff59750efcac32a 100644 (file)
@@ -158,6 +158,10 @@ InternalAllocateAlignedPages (
     return NULL;\r
   }\r
   //\r
+  // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.\r
+  //\r
+  ASSERT (Pages <= (MAX_ADDRESS - EFI_SIZE_TO_PAGES (Alignment)));\r
+  //\r
   // We would rather waste some memory to save PEI code size.\r
   //\r
   Memory = InternalAllocatePages (MemoryType, Pages + EFI_SIZE_TO_PAGES (Alignment));\r
@@ -569,6 +573,10 @@ InternalAllocateAlignedPool (
   } else {\r
     AlignmentMask = Alignment - 1;\r
   }\r
+  //\r
+  // Make sure that AllocationSize plus AlignmentMask does not overflow.\r
+  //\r
+  ASSERT (AllocationSize <= (MAX_ADDRESS - AlignmentMask));\r
 \r
   RawAddress      = InternalAllocatePool (PoolType, AllocationSize + AlignmentMask);\r
   \r
@@ -609,6 +617,11 @@ AllocateAlignedPool (
     AlignmentMask = Alignment - 1;\r
   }\r
 \r
+  //\r
+  // Make sure that AllocationSize plus AlignmentMask does not overflow.\r
+  //\r
+  ASSERT (AllocationSize <= (MAX_ADDRESS - AlignmentMask));\r
+\r
   RawAddress      = AllocatePool (AllocationSize + AlignmentMask);\r
   \r
   AlignedAddress  = ((UINTN) RawAddress + AlignmentMask) & ~AlignmentMask;\r
index d06b0a932dee45ceae2d5f0bdba2bd462f3513b9..4fbdef73504daa5d0eb6097437e3487a9a47fcce 100644 (file)
@@ -263,6 +263,10 @@ UnicodeStringDisplayLength (
   UINTN      Length;\r
   UINTN      Width;\r
 \r
+  if (String == NULL) {\r
+    return 0;\r
+  }\r
+\r
   Length = 0;\r
   while (*String != 0) {\r
     Width = GetGlyphWidth (*String);\r