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
EFI_STATUS Status;\r
EFI_HOB_MEMORY_POOL *Hob;\r
\r
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
EFI_HOB_TYPE_PEI_MEMORY_POOL,\r
(UINT16)(sizeof (EFI_HOB_MEMORY_POOL) + Size),\r
(VOID **)&Hob\r
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
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
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
DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while\r
processing another DebugAssert(), then DebugAssert() must return immediately.\r
\r
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
- 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
\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
\r
If Buffer is NULL, then ASSERT().\r
\r
\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
\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
_ASSERT (Guid already installed in database); \\r
} \\r
} else { \\r
_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
_ASSERT (Guid already installed on Handle); \\r
} \\r
} \\r
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
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
\r
If the data type specified by TYPE does not contain the field specified by Field, \r
then the module will not compile.\r
UnicodeValueToString (\r
IN OUT CHAR16 *Buffer,\r
IN UINTN Flags,\r
UnicodeValueToString (\r
IN OUT CHAR16 *Buffer,\r
IN UINTN Flags,\r
AsciiValueToString (\r
IN OUT CHAR8 *Buffer,\r
IN UINTN Flags,\r
AsciiValueToString (\r
IN OUT CHAR8 *Buffer,\r
IN UINTN Flags,\r
VA_START (Marker, FormatString);\r
return AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
}\r
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
\r
return ((Buffer - OriginalBuffer) / Increment);\r
}\r
\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
/// 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 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
///\r
#define MAXIMUM_VALUE_CHARACTERS 38\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
//\r
AlignmentMask = Alignment - 1;\r
RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment);\r
//\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
Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory);\r
if (EFI_ERROR (Status)) {\r
return NULL;\r
//\r
OverAllocationSize = sizeof (RawAddress) + AlignmentMask;\r
RealAllocationSize = AllocationSize + OverAllocationSize;\r
//\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
RawAddress = InternalAllocatePool (PoolType, RealAllocationSize);\r
if (RawAddress == NULL) {\r
return NULL;\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
// We would rather waste some memory to save PEI code size.\r
//\r
Memory = InternalAllocatePages (MemoryType, Pages + EFI_SIZE_TO_PAGES (Alignment));\r
} else {\r
AlignmentMask = Alignment - 1;\r
}\r
} 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
\r
RawAddress = InternalAllocatePool (PoolType, AllocationSize + AlignmentMask);\r
\r
AlignmentMask = Alignment - 1;\r
}\r
\r
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
RawAddress = AllocatePool (AllocationSize + AlignmentMask);\r
\r
AlignedAddress = ((UINTN) RawAddress + AlignmentMask) & ~AlignmentMask;\r
UINTN Length;\r
UINTN Width;\r
\r
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
Length = 0;\r
while (*String != 0) {\r
Width = GetGlyphWidth (*String);\r